diff mbox series

[v2,2/3] md: factor out a helper mddev_sync_blockdev() to sync mddev

Message ID 20240117093707.2767209-3-linan666@huaweicloud.com (mailing list archive)
State Superseded, archived
Headers show
Series md: Don't clear MD_CLOSING when the raid is about to stop | expand

Commit Message

Li Nan Jan. 17, 2024, 9:37 a.m. UTC
From: Li Nan <linan122@huawei.com>

There are no functional changes, prepare to sync mddev in
array_state_store().

Signed-off-by: Li Nan <linan122@huawei.com>
---
 drivers/md/md.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

Comments

Mariusz Tkaczyk Jan. 18, 2024, 8:08 a.m. UTC | #1
On Wed, 17 Jan 2024 17:37:06 +0800
linan666@huaweicloud.com wrote:

> From: Li Nan <linan122@huawei.com>
> 
> There are no functional changes, prepare to sync mddev in
> array_state_store().
> 
> Signed-off-by: Li Nan <linan122@huawei.com>
> ---
>  drivers/md/md.c | 31 +++++++++++++++++++------------
>  1 file changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 4bf821b89415..2c793992a604 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -529,6 +529,23 @@ void mddev_resume(struct mddev *mddev)
>  }
>  EXPORT_SYMBOL_GPL(mddev_resume);
>  
> +/* sync bdev before setting device to readonly or stopping raid*/
> +static int mddev_sync_blockdev(struct mddev *mddev) {

Please add something about MD_CLOSING to the function name. Comment is good but
you need open function to get it. Something like:
mddev_set_closing_and_sync_blockdev() is more reader friendly.

Anyway, LGTM.
Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>

Thanks,
Mariusz
Li Nan Jan. 22, 2024, 2:15 a.m. UTC | #2
在 2024/1/18 16:08, Mariusz Tkaczyk 写道:
> On Wed, 17 Jan 2024 17:37:06 +0800
> linan666@huaweicloud.com wrote:
> 
>> From: Li Nan <linan122@huawei.com>
>>
>> There are no functional changes, prepare to sync mddev in
>> array_state_store().
>>
>> Signed-off-by: Li Nan <linan122@huawei.com>
>> ---
>>   drivers/md/md.c | 31 +++++++++++++++++++------------
>>   1 file changed, 19 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index 4bf821b89415..2c793992a604 100644
>> --- a/drivers/md/md.c
>> +++ b/drivers/md/md.c
>> @@ -529,6 +529,23 @@ void mddev_resume(struct mddev *mddev)
>>   }
>>   EXPORT_SYMBOL_GPL(mddev_resume);
>>   
>> +/* sync bdev before setting device to readonly or stopping raid*/
>> +static int mddev_sync_blockdev(struct mddev *mddev) {
> 
> Please add something about MD_CLOSING to the function name. Comment is good but
> you need open function to get it. Something like:
> mddev_set_closing_and_sync_blockdev() is more reader friendly.
> 

I agree. Let me improve this.

> Anyway, LGTM.
> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
> 
> Thanks,
> Mariusz
> 
> .
diff mbox series

Patch

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 4bf821b89415..2c793992a604 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -529,6 +529,23 @@  void mddev_resume(struct mddev *mddev)
 }
 EXPORT_SYMBOL_GPL(mddev_resume);
 
+/* sync bdev before setting device to readonly or stopping raid*/
+static int mddev_sync_blockdev(struct mddev *mddev) {
+	mutex_lock(&mddev->open_mutex);
+	if (mddev->pers && atomic_read(&mddev->openers) > 1) {
+		mutex_unlock(&mddev->open_mutex);
+		return -EBUSY;
+	}
+	if (test_and_set_bit(MD_CLOSING, &mddev->flags)) {
+		mutex_unlock(&mddev->open_mutex);
+		return -EBUSY;
+	}
+	mutex_unlock(&mddev->open_mutex);
+
+	sync_blockdev(mddev->gendisk->part0);
+	return 0;
+}
+
 /*
  * Generic flush handling for md
  */
@@ -7681,20 +7698,10 @@  static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
 		/* Need to flush page cache, and ensure no-one else opens
 		 * and writes
 		 */
-		mutex_lock(&mddev->open_mutex);
-		if (mddev->pers && atomic_read(&mddev->openers) > 1) {
-			mutex_unlock(&mddev->open_mutex);
-			err = -EBUSY;
-			goto out;
-		}
-		if (test_and_set_bit(MD_CLOSING, &mddev->flags)) {
-			mutex_unlock(&mddev->open_mutex);
-			err = -EBUSY;
+		err = mddev_sync_blockdev(mddev);
+		if (err)
 			goto out;
-		}
 		did_set_md_closing = true;
-		mutex_unlock(&mddev->open_mutex);
-		sync_blockdev(bdev);
 	}
 
 	if (!md_is_rdwr(mddev))