diff options
Diffstat (limited to 'drivers/block/nbd.c')
-rw-r--r-- | drivers/block/nbd.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 8e33de6bea33..a3da198ca429 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c | |||
@@ -56,6 +56,7 @@ static unsigned int debugflags; | |||
56 | 56 | ||
57 | static unsigned int nbds_max = 16; | 57 | static unsigned int nbds_max = 16; |
58 | static struct nbd_device *nbd_dev; | 58 | static struct nbd_device *nbd_dev; |
59 | static int max_part; | ||
59 | 60 | ||
60 | /* | 61 | /* |
61 | * Use just one lock (or at most 1 per NIC). Two arguments for this: | 62 | * Use just one lock (or at most 1 per NIC). Two arguments for this: |
@@ -610,10 +611,13 @@ static int nbd_ioctl(struct inode *inode, struct file *file, | |||
610 | error = -EINVAL; | 611 | error = -EINVAL; |
611 | file = fget(arg); | 612 | file = fget(arg); |
612 | if (file) { | 613 | if (file) { |
614 | struct block_device *bdev = inode->i_bdev; | ||
613 | inode = file->f_path.dentry->d_inode; | 615 | inode = file->f_path.dentry->d_inode; |
614 | if (S_ISSOCK(inode->i_mode)) { | 616 | if (S_ISSOCK(inode->i_mode)) { |
615 | lo->file = file; | 617 | lo->file = file; |
616 | lo->sock = SOCKET_I(inode); | 618 | lo->sock = SOCKET_I(inode); |
619 | if (max_part > 0) | ||
620 | bdev->bd_invalidated = 1; | ||
617 | error = 0; | 621 | error = 0; |
618 | } else { | 622 | } else { |
619 | fput(file); | 623 | fput(file); |
@@ -663,6 +667,8 @@ static int nbd_ioctl(struct inode *inode, struct file *file, | |||
663 | lo->bytesize = 0; | 667 | lo->bytesize = 0; |
664 | inode->i_bdev->bd_inode->i_size = 0; | 668 | inode->i_bdev->bd_inode->i_size = 0; |
665 | set_capacity(lo->disk, 0); | 669 | set_capacity(lo->disk, 0); |
670 | if (max_part > 0) | ||
671 | ioctl_by_bdev(inode->i_bdev, BLKRRPART, 0); | ||
666 | return lo->harderror; | 672 | return lo->harderror; |
667 | case NBD_CLEAR_QUE: | 673 | case NBD_CLEAR_QUE: |
668 | /* | 674 | /* |
@@ -696,6 +702,7 @@ static int __init nbd_init(void) | |||
696 | { | 702 | { |
697 | int err = -ENOMEM; | 703 | int err = -ENOMEM; |
698 | int i; | 704 | int i; |
705 | int part_shift; | ||
699 | 706 | ||
700 | BUILD_BUG_ON(sizeof(struct nbd_request) != 28); | 707 | BUILD_BUG_ON(sizeof(struct nbd_request) != 28); |
701 | 708 | ||
@@ -703,8 +710,17 @@ static int __init nbd_init(void) | |||
703 | if (!nbd_dev) | 710 | if (!nbd_dev) |
704 | return -ENOMEM; | 711 | return -ENOMEM; |
705 | 712 | ||
713 | if (max_part < 0) { | ||
714 | printk(KERN_CRIT "nbd: max_part must be >= 0\n"); | ||
715 | return -EINVAL; | ||
716 | } | ||
717 | |||
718 | part_shift = 0; | ||
719 | if (max_part > 0) | ||
720 | part_shift = fls(max_part); | ||
721 | |||
706 | for (i = 0; i < nbds_max; i++) { | 722 | for (i = 0; i < nbds_max; i++) { |
707 | struct gendisk *disk = alloc_disk(1); | 723 | struct gendisk *disk = alloc_disk(1 << part_shift); |
708 | elevator_t *old_e; | 724 | elevator_t *old_e; |
709 | if (!disk) | 725 | if (!disk) |
710 | goto out; | 726 | goto out; |
@@ -748,10 +764,9 @@ static int __init nbd_init(void) | |||
748 | nbd_dev[i].blksize = 1024; | 764 | nbd_dev[i].blksize = 1024; |
749 | nbd_dev[i].bytesize = 0; | 765 | nbd_dev[i].bytesize = 0; |
750 | disk->major = NBD_MAJOR; | 766 | disk->major = NBD_MAJOR; |
751 | disk->first_minor = i; | 767 | disk->first_minor = i << part_shift; |
752 | disk->fops = &nbd_fops; | 768 | disk->fops = &nbd_fops; |
753 | disk->private_data = &nbd_dev[i]; | 769 | disk->private_data = &nbd_dev[i]; |
754 | disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; | ||
755 | sprintf(disk->disk_name, "nbd%d", i); | 770 | sprintf(disk->disk_name, "nbd%d", i); |
756 | set_capacity(disk, 0); | 771 | set_capacity(disk, 0); |
757 | add_disk(disk); | 772 | add_disk(disk); |
@@ -789,7 +804,9 @@ MODULE_DESCRIPTION("Network Block Device"); | |||
789 | MODULE_LICENSE("GPL"); | 804 | MODULE_LICENSE("GPL"); |
790 | 805 | ||
791 | module_param(nbds_max, int, 0444); | 806 | module_param(nbds_max, int, 0444); |
792 | MODULE_PARM_DESC(nbds_max, "How many network block devices to initialize."); | 807 | MODULE_PARM_DESC(nbds_max, "number of network block devices to initialize (default: 16)"); |
808 | module_param(max_part, int, 0444); | ||
809 | MODULE_PARM_DESC(max_part, "number of partitions per device (default: 0)"); | ||
793 | #ifndef NDEBUG | 810 | #ifndef NDEBUG |
794 | module_param(debugflags, int, 0644); | 811 | module_param(debugflags, int, 0644); |
795 | MODULE_PARM_DESC(debugflags, "flags for controlling debug output"); | 812 | MODULE_PARM_DESC(debugflags, "flags for controlling debug output"); |