block: do not pass disk names as format strings
[pandora-kernel.git] / drivers / block / nbd.c
index 1b8e09f..4d62fe0 100644 (file)
@@ -127,8 +127,7 @@ static void sock_shutdown(struct nbd_device *lo, int lock)
        if (lock)
                mutex_lock(&lo->tx_lock);
        if (lo->sock) {
-               printk(KERN_WARNING "%s: shutting down socket\n",
-                       lo->disk->disk_name);
+               dev_warn(disk_to_dev(lo->disk), "shutting down socket\n");
                kernel_sock_shutdown(lo->sock, SHUT_RDWR);
                lo->sock = NULL;
        }
@@ -446,6 +445,14 @@ static void nbd_clear_que(struct nbd_device *lo)
                req->errors++;
                nbd_end_request(req);
        }
+
+       while (!list_empty(&lo->waiting_queue)) {
+               req = list_entry(lo->waiting_queue.next, struct request,
+                                queuelist);
+               list_del_init(&req->queuelist);
+               req->errors++;
+               nbd_end_request(req);
+       }
 }
 
 
@@ -576,13 +583,21 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
        case NBD_DISCONNECT: {
                struct request sreq;
 
-               printk(KERN_INFO "%s: NBD_DISCONNECT\n", lo->disk->disk_name);
+               dev_info(disk_to_dev(lo->disk), "NBD_DISCONNECT\n");
+               if (!lo->sock)
+                       return -EINVAL;
 
+               mutex_unlock(&lo->tx_lock);
+               fsync_bdev(bdev);
+               mutex_lock(&lo->tx_lock);
                blk_rq_init(NULL, &sreq);
                sreq.cmd_type = REQ_TYPE_SPECIAL;
                nbd_cmd(&sreq) = NBD_CMD_DISC;
+
+               /* Check again after getting mutex back.  */
                if (!lo->sock)
                        return -EINVAL;
+
                nbd_send_req(lo, &sreq);
                 return 0;
        }
@@ -595,6 +610,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
                lo->file = NULL;
                nbd_clear_que(lo);
                BUG_ON(!list_empty(&lo->queue_head));
+               BUG_ON(!list_empty(&lo->waiting_queue));
+               kill_bdev(bdev);
                if (file)
                        fput(file);
                return 0;
@@ -658,7 +675,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
 
                mutex_unlock(&lo->tx_lock);
 
-               thread = kthread_create(nbd_thread, lo, lo->disk->disk_name);
+               thread = kthread_create(nbd_thread, lo, "%s",
+                                       lo->disk->disk_name);
                if (IS_ERR(thread)) {
                        mutex_lock(&lo->tx_lock);
                        return PTR_ERR(thread);
@@ -674,7 +692,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
                file = lo->file;
                lo->file = NULL;
                nbd_clear_que(lo);
-               printk(KERN_WARNING "%s: queue cleared\n", lo->disk->disk_name);
+               dev_warn(disk_to_dev(lo->disk), "queue cleared\n");
+               kill_bdev(bdev);
                if (file)
                        fput(file);
                lo->bytesize = 0;
@@ -694,8 +713,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
                return 0;
 
        case NBD_PRINT_DEBUG:
-               printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n",
-                       bdev->bd_disk->disk_name,
+               dev_info(disk_to_dev(lo->disk),
+                       "next = %p, prev = %p, head = %p\n",
                        lo->queue_head.next, lo->queue_head.prev,
                        &lo->queue_head);
                return 0;
@@ -745,7 +764,7 @@ static int __init nbd_init(void)
        BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
 
        if (max_part < 0) {
-               printk(KERN_CRIT "nbd: max_part must be >= 0\n");
+               printk(KERN_ERR "nbd: max_part must be >= 0\n");
                return -EINVAL;
        }