Skip to content

Commit d27769e

Browse files
htejunJens Axboe
authored andcommitted
block: add GENHD_FL_NO_PART_SCAN
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 <[email protected]> Cc: Kay Sievers <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 322a8b0 commit d27769e

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

block/genhd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ void register_disk(struct gendisk *disk)
536536
disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
537537

538538
/* No minors to use for partitions */
539-
if (!disk_partitionable(disk))
539+
if (!disk_part_scan_enabled(disk))
540540
goto exit;
541541

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

843843
/* Don't show non-partitionable removeable devices or empty devices */
844-
if (!get_capacity(sgp) || (!disk_partitionable(sgp) &&
844+
if (!get_capacity(sgp) || (!disk_max_parts(sgp) &&
845845
(sgp->flags & GENHD_FL_REMOVABLE)))
846846
return 0;
847847
if (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)

block/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int blkdev_reread_part(struct block_device *bdev)
101101
struct gendisk *disk = bdev->bd_disk;
102102
int res;
103103

104-
if (!disk_partitionable(disk) || bdev != bdev->bd_contains)
104+
if (!disk_part_scan_enabled(disk) || bdev != bdev->bd_contains)
105105
return -EINVAL;
106106
if (!capable(CAP_SYS_ADMIN))
107107
return -EACCES;

fs/block_dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)
971971

972972
if (!bdev->bd_disk)
973973
return;
974-
if (disk_partitionable(bdev->bd_disk))
974+
if (disk_part_scan_enabled(bdev->bd_disk))
975975
bdev->bd_invalidated = 1;
976976
}
977977

include/linux/genhd.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ struct hd_struct {
128128
#define GENHD_FL_EXT_DEVT 64 /* allow extended devt */
129129
#define GENHD_FL_NATIVE_CAPACITY 128
130130
#define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 256
131+
#define GENHD_FL_NO_PART_SCAN 512
131132

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

237-
static inline bool disk_partitionable(struct gendisk *disk)
238+
static inline bool disk_part_scan_enabled(struct gendisk *disk)
238239
{
239-
return disk_max_parts(disk) > 1;
240+
return disk_max_parts(disk) > 1 &&
241+
!(disk->flags & GENHD_FL_NO_PART_SCAN);
240242
}
241243

242244
static inline dev_t disk_devt(struct gendisk *disk)

0 commit comments

Comments
 (0)