Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nbd: adjust 'max_part' according to part_shift

The 'max_part' parameter determines how many partitions are supported
on each nbd device. However the actual number can be changed to the
power of 2 minus 1 form during the module initialization as
alloc_disk() is called with (1 << part_shift) for some reason.

So adjust 'max_part' also at least for consistency with loop and brd.
It is exported via sysfs already, and a user should check this value
after module loading if [s]he wants to use that number correctly
(i.e. fdisk or something).

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Cc: Laurent Vivier <Laurent.Vivier@bull.net>
Cc: Paul Clements <Paul.Clements@steeleye.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>

authored by

Namhyung Kim and committed by
Jens Axboe
5988ce23 3b271082

+12 -1
+12 -1
drivers/block/nbd.c
··· 754 754 return -ENOMEM; 755 755 756 756 part_shift = 0; 757 - if (max_part > 0) 757 + if (max_part > 0) { 758 758 part_shift = fls(max_part); 759 + 760 + /* 761 + * Adjust max_part according to part_shift as it is exported 762 + * to user space so that user can know the max number of 763 + * partition kernel should be able to manage. 764 + * 765 + * Note that -1 is required because partition 0 is reserved 766 + * for the whole disk. 767 + */ 768 + max_part = (1UL << part_shift) - 1; 769 + } 759 770 760 771 if ((1UL << part_shift) > DISK_MAX_PARTS) 761 772 return -EINVAL;