提交 f0b4f7e2 编写于 作者: N NeilBrown

md: Fix - again - partition detection when array becomes active

Revert
    b821eaa5
and
    f3b99be1

When I wrote the first of these I had a wrong idea about the
lifetime of 'struct block_device'.  It can disappear at any time that
the block device is not open if it falls out of the inode cache.

So relying on the 'size' recorded with it to detect when the
device size has changed and so we need to revalidate, is wrong.

Rather, we really do need the 'changed' attribute stored directly in
the mddev and set/tested as appropriate.

Without this patch, a sequence of:
   mknod / open / close / unlink

(which can cause a block_device to be created and then destroyed)
will result in a rescan of the partition table and consequence removal
and addition of partitions.
Several of these in a row can get udev racing to create and unlink and
other code can get confused.

With the patch, the rescan is only performed when needed and so there
are no races.

This is suitable for any stable kernel from 2.6.35.
Reported-by: N"Wojcik, Krzysztof" <krzysztof.wojcik@intel.com>
Signed-off-by: NNeilBrown <neilb@suse.de>
Cc: stable@kernel.org
上级 93b270f7
...@@ -4627,6 +4627,7 @@ static int do_md_run(mddev_t *mddev) ...@@ -4627,6 +4627,7 @@ static int do_md_run(mddev_t *mddev)
} }
set_capacity(mddev->gendisk, mddev->array_sectors); set_capacity(mddev->gendisk, mddev->array_sectors);
revalidate_disk(mddev->gendisk); revalidate_disk(mddev->gendisk);
mddev->changed = 1;
kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
out: out:
return err; return err;
...@@ -4715,6 +4716,7 @@ static void md_clean(mddev_t *mddev) ...@@ -4715,6 +4716,7 @@ static void md_clean(mddev_t *mddev)
mddev->sync_speed_min = mddev->sync_speed_max = 0; mddev->sync_speed_min = mddev->sync_speed_max = 0;
mddev->recovery = 0; mddev->recovery = 0;
mddev->in_sync = 0; mddev->in_sync = 0;
mddev->changed = 0;
mddev->degraded = 0; mddev->degraded = 0;
mddev->safemode = 0; mddev->safemode = 0;
mddev->bitmap_info.offset = 0; mddev->bitmap_info.offset = 0;
...@@ -4830,6 +4832,7 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open) ...@@ -4830,6 +4832,7 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
set_capacity(disk, 0); set_capacity(disk, 0);
mutex_unlock(&mddev->open_mutex); mutex_unlock(&mddev->open_mutex);
mddev->changed = 1;
revalidate_disk(disk); revalidate_disk(disk);
if (mddev->ro) if (mddev->ro)
...@@ -6014,7 +6017,7 @@ static int md_open(struct block_device *bdev, fmode_t mode) ...@@ -6014,7 +6017,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
atomic_inc(&mddev->openers); atomic_inc(&mddev->openers);
mutex_unlock(&mddev->open_mutex); mutex_unlock(&mddev->open_mutex);
check_disk_size_change(mddev->gendisk, bdev); check_disk_change(bdev);
out: out:
return err; return err;
} }
...@@ -6029,6 +6032,21 @@ static int md_release(struct gendisk *disk, fmode_t mode) ...@@ -6029,6 +6032,21 @@ static int md_release(struct gendisk *disk, fmode_t mode)
return 0; return 0;
} }
static int md_media_changed(struct gendisk *disk)
{
mddev_t *mddev = disk->private_data;
return mddev->changed;
}
static int md_revalidate(struct gendisk *disk)
{
mddev_t *mddev = disk->private_data;
mddev->changed = 0;
return 0;
}
static const struct block_device_operations md_fops = static const struct block_device_operations md_fops =
{ {
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -6039,6 +6057,8 @@ static const struct block_device_operations md_fops = ...@@ -6039,6 +6057,8 @@ static const struct block_device_operations md_fops =
.compat_ioctl = md_compat_ioctl, .compat_ioctl = md_compat_ioctl,
#endif #endif
.getgeo = md_getgeo, .getgeo = md_getgeo,
.media_changed = md_media_changed,
.revalidate_disk= md_revalidate,
}; };
static int md_thread(void * arg) static int md_thread(void * arg)
......
...@@ -274,6 +274,8 @@ struct mddev_s ...@@ -274,6 +274,8 @@ struct mddev_s
atomic_t active; /* general refcount */ atomic_t active; /* general refcount */
atomic_t openers; /* number of active opens */ atomic_t openers; /* number of active opens */
int changed; /* True if we might need to
* reread partition info */
int degraded; /* whether md should consider int degraded; /* whether md should consider
* adding a spare * adding a spare
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册