md: destroy partitions and notify udev when md array is stopped.
authorNeilBrown <neilb@suse.de>
Tue, 28 Oct 2008 06:01:23 +0000 (17:01 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 28 Oct 2008 06:01:23 +0000 (17:01 +1100)
md arrays are not currently destroyed when they are stopped - they
remain in /sys/block.  Last time I tried this I tripped over locking
too much.

A consequence of this is that udev doesn't remove anything from /dev.
This is rather ugly.

As an interim measure until proper device removal can be achieved,
make sure all partitions are removed using the BLKRRPART ioctl, and
send a KOBJ_CHANGE when an md array is stopped.

Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/md.c

index b4162f6..9abf6ed 100644 (file)
@@ -3884,6 +3884,7 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
        if (mode == 0) {
                mdk_rdev_t *rdev;
                struct list_head *tmp;
+               struct block_device *bdev;
 
                printk(KERN_INFO "md: %s stopped.\n", mdname(mddev));
 
@@ -3940,6 +3941,12 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
                mddev->degraded = 0;
                mddev->barriers_work = 0;
                mddev->safemode = 0;
+               bdev = bdget_disk(mddev->gendisk, 0);
+               if (bdev) {
+                       blkdev_ioctl(bdev, 0, BLKRRPART, 0);
+                       bdput(bdev);
+               }
+               kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
 
        } else if (mddev->pers)
                printk(KERN_INFO "md: %s switched to read-only mode.\n",