Skip to content

Commit

Permalink
block: add GENHD_FL_NO_PART_SCAN
Browse files Browse the repository at this point in the history
There are cases where suppressing partition scan is useful - e.g. for
lo devices and pseudo SATA devices which advertise to be a disk but
get upset on partition scan (some port multiplier control devices show
such behavior).

This patch adds GENHD_FL_NO_PART_SCAN which suppresses partition scan
regardless of the number of possible partitions.  disk_partitionable()
is renamed to disk_part_scan_enabled() as suppressing partition scan
doesn't imply the device can't be partitioned using
BLKPG_ADD/DEL_PARTITION calls from userland.  show_partition() now
directly tests disk_max_parts() to maintain backward-compatibility.

-v2: Updated to make it clear that only partition scan is suppressed
     not partitioning itself as suggested by Kay Sievers.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
  • Loading branch information
Tejun Heo authored and Jens Axboe committed Aug 23, 2011
1 parent 322a8b0 commit d27769e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ void register_disk(struct gendisk *disk)
disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);

/* No minors to use for partitions */
if (!disk_partitionable(disk))
if (!disk_part_scan_enabled(disk))
goto exit;

/* No such device (e.g., media were just removed) */
Expand Down Expand Up @@ -841,7 +841,7 @@ static int show_partition(struct seq_file *seqf, void *v)
char buf[BDEVNAME_SIZE];

/* Don't show non-partitionable removeable devices or empty devices */
if (!get_capacity(sgp) || (!disk_partitionable(sgp) &&
if (!get_capacity(sgp) || (!disk_max_parts(sgp) &&
(sgp->flags & GENHD_FL_REMOVABLE)))
return 0;
if (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)
Expand Down
2 changes: 1 addition & 1 deletion block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int blkdev_reread_part(struct block_device *bdev)
struct gendisk *disk = bdev->bd_disk;
int res;

if (!disk_partitionable(disk) || bdev != bdev->bd_contains)
if (!disk_part_scan_enabled(disk) || bdev != bdev->bd_contains)
return -EINVAL;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
Expand Down
2 changes: 1 addition & 1 deletion fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)

if (!bdev->bd_disk)
return;
if (disk_partitionable(bdev->bd_disk))
if (disk_part_scan_enabled(bdev->bd_disk))
bdev->bd_invalidated = 1;
}

Expand Down
6 changes: 4 additions & 2 deletions include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ struct hd_struct {
#define GENHD_FL_EXT_DEVT 64 /* allow extended devt */
#define GENHD_FL_NATIVE_CAPACITY 128
#define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 256
#define GENHD_FL_NO_PART_SCAN 512

enum {
DISK_EVENT_MEDIA_CHANGE = 1 << 0, /* media changed */
Expand Down Expand Up @@ -234,9 +235,10 @@ static inline int disk_max_parts(struct gendisk *disk)
return disk->minors;
}

static inline bool disk_partitionable(struct gendisk *disk)
static inline bool disk_part_scan_enabled(struct gendisk *disk)
{
return disk_max_parts(disk) > 1;
return disk_max_parts(disk) > 1 &&
!(disk->flags & GENHD_FL_NO_PART_SCAN);
}

static inline dev_t disk_devt(struct gendisk *disk)
Expand Down

0 comments on commit d27769e

Please sign in to comment.