]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/block/nbd.c
nbd: do not allow two clients at the same time
[linux-2.6-omap-h63xx.git] / drivers / block / nbd.c
index d3a91cacee8c6aff410bc9a8567ce89cb1ae477f..34f80fa6fed16d379733e3db018f765831e09778 100644 (file)
@@ -406,6 +406,7 @@ static int nbd_do_it(struct nbd_device *lo)
        ret = sysfs_create_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr);
        if (ret) {
                printk(KERN_ERR "nbd: sysfs_create_file failed!");
+               lo->pid = 0;
                return ret;
        }
 
@@ -413,6 +414,7 @@ static int nbd_do_it(struct nbd_device *lo)
                nbd_end_request(req);
 
        sysfs_remove_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr);
+       lo->pid = 0;
        return 0;
 }
 
@@ -648,6 +650,8 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
                set_capacity(lo->disk, lo->bytesize >> 9);
                return 0;
        case NBD_DO_IT:
+               if (lo->pid)
+                       return -EBUSY;
                if (!lo->file)
                        return -EINVAL;
                thread = kthread_create(nbd_thread, lo, lo->disk->disk_name);
@@ -722,7 +726,6 @@ static int __init nbd_init(void)
 
        for (i = 0; i < nbds_max; i++) {
                struct gendisk *disk = alloc_disk(1 << part_shift);
-               elevator_t *old_e;
                if (!disk)
                        goto out;
                nbd_dev[i].disk = disk;
@@ -736,11 +739,10 @@ static int __init nbd_init(void)
                        put_disk(disk);
                        goto out;
                }
-               old_e = disk->queue->elevator;
-               if (elevator_init(disk->queue, "deadline") == 0 ||
-                       elevator_init(disk->queue, "noop") == 0) {
-                               elevator_exit(old_e);
-               }
+               /*
+                * Tell the block layer that we are not a rotational device
+                */
+               queue_flag_set_unlocked(QUEUE_FLAG_NONROT, disk->queue);
        }
 
        if (register_blkdev(NBD_MAJOR, "nbd")) {