[PATCH v2 1/3] md-cluster: fix error handling and superblock update in update_size revert

[email protected]
Newsgroups gmane.linux.kernel.stable,gmane.linux.raid,gmane.linux.kernel
Message-ID <[email protected]>
From: Cao Guanghui <[email protected]>

In update_size(), when cluster_check_sync_size() detects that not all
nodes have updated their sync_size, the initiator reverts the array
size via pers->resize().  Two issues exist in this revert path:

1. The return value of resize() is immediately overwritten by
   __sendmsg(), so a resize failure is silently lost.  The array
   remains at the new size while other nodes have not confirmed the
   change, with no error logged.

2. The on-disk superblock still retains the new size written by the
   earlier md_update_sb() call.  Other nodes that receive the
   METADATA_UPDATED message will re-read the on-disk superblock and
   adopt the new size, while the initiator runs with the reverted old
   size, causing a cluster-wide metadata inconsistency.

Fix by checking the resize() return value and logging an error, then
calling md_update_sb() so the on-disk superblock matches the in-memory
array size before broadcasting the message.

Fixes: 818da59f97d6 ("md-cluster: add the support for resize")
Cc: [email protected]
Signed-off-by: Cao Guanghui <[email protected]>
---

Changes in v2:
  - Fold in the md_update_sb() fix (was a separate patch in v1)
  - Combine error check and superblock update into one coherent fix

 drivers/md/md-cluster.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1349,7 +1349,11 @@ static void update_size(struct mddev *mddev, sector_t old_dev_sectors)
 	} else {
 		/* revert to previous sectors */
 		ret = mddev->pers->resize(mddev, old_dev_sectors);
+		if (ret)
+			pr_err("%s:%d: failed to revert array size\n",
+			       __func__, __LINE__);
+		md_update_sb(mddev, 1);
 		ret = __sendmsg(cinfo, &cmsg);
 		if (ret)
 			pr_err("%s:%d: failed to send METADATA_UPDATED msg\n",
 			       __func__, __LINE__);
 	}
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.