Re: [PATCH] block: Do not reread partition table on exclusively open device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, Jan and Christoph

在 2022/12/01 1:56, Jan Kara 写道:
Since commit 10c70d95c0f2 ("block: remove the bd_openers checks in
blk_drop_partitions") we allow rereading of partition table although
there are users of the block device. This has an undesirable consequence
that e.g. if sda and sdb are assembled to a RAID1 device md0 with
partitions, BLKRRPART ioctl on sda will rescan partition table and
create sda1 device. This partition device under a raid device confuses
some programs (such as libstorage-ng used for initial partitioning for
distribution installation) leading to failures.

Fix the problem refusing to rescan partitions if there is another user
that has the block device exclusively open.

Still by code review, I just found another race that cound cause disk
can't scan partition while creating:

t1: create device	t2: open device exclusively
device_add_disk()
 bdev_add
  insert_inode_hash
                        ...
                        bd_finish_claiming
                         bdev->bd_holder = holder
disk_scan_partitions
// check holder and failed

This race is artificial and unlikely to happend in practice, but this
is easy to fix by following:

diff --git a/block/genhd.c b/block/genhd.c
index 09f2ac548832..23e87753313b 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -497,6 +497,11 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
                if (ret)
                        goto out_unregister_bdi;

+               /*
+                * In case user open device before disk_scan_partitions(),
+ * set state here, so that blkdev_open() can scan partitions.
+                */
+               set_bit(GD_NEED_PART_SCAN, &disk->state);
                bdev_add(disk->part0, ddev->devt);
                if (get_capacity(disk))
                        disk_scan_partitions(disk, FMODE_READ, NULL);




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux