Skip to content

Commit

Permalink
nbd: adjust 'max_part' according to part_shift
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Namhyung Kim authored and Jens Axboe committed May 28, 2011
1 parent 3b27108 commit 5988ce2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,20 @@ static int __init nbd_init(void)
return -ENOMEM;

part_shift = 0;
if (max_part > 0)
if (max_part > 0) {
part_shift = fls(max_part);

/*
* Adjust max_part according to part_shift as it is exported
* to user space so that user can know the max number of
* partition kernel should be able to manage.
*
* Note that -1 is required because partition 0 is reserved
* for the whole disk.
*/
max_part = (1UL << part_shift) - 1;
}

if ((1UL << part_shift) > DISK_MAX_PARTS)
return -EINVAL;

Expand Down

0 comments on commit 5988ce2

Please sign in to comment.