Skip to contentSkip to conversation

mdadm/Detail: show correct state for clustered array

PATCH Applied Zhao Heming 2 participants 2 messages Oct 24, 2020 – Nov 25, 2020 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 mdadm/Detail: show correct state for clustered array

After kernel md module commit 480523feae581, in clustered env, mddev->in_sync always zero, it will make array.state never set up MD_SB_CLEAN. it causes "mdadm -D /dev/mdX" show state 'active' all the time.

bitmap.c: add a new API IsBitmapDirty() to support inquiry bitmap dirty or clean.

---
v5: (polish code)
- Detail.c: change code logic to only examine valid dev.
- bitmap.c: redesign bitmap_file_open() to support fd reuse. It won't make dev multi-opened in clusterd env.
v4:
- Detail.c: follow Jes comment, split if into 2 lines.
v3:
- Detail.c: fix error logic: v2 code didn't check bitmap when dv is null.
v2:
- Detail.c: follow Neil comments, change to read only one device.
- bitmap.c: follow Neil comments, modify IsBitmapDirty() to check all bitmap on the selected device.

---
 Detail.c | 20 ++++++++++++++-
 bitmap.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 mdadm.h  |  1 +
 3 files changed, 86 insertions(+), 10 deletions(-)
Detail.c +19 -1
index b6587c8..14cb7f2 100644
@@ -498,8 +498,26 @@ int Detail(char *dev, struct context *c)
 							  sra->array_state);
 				else
 					arrayst = "clean";
-			} else
+			} else {
 				arrayst = "active";
+				if (array.state & (1<<MD_SB_CLUSTERED)) {
+					for (d = 0; d < max_disks * 2; d++) {
+						char *dv;
+						mdu_disk_info_t disk = disks[d];
+
+						/* only check first valid disk in cluster env */
+						if ((disk.state & (MD_DISK_SYNC | MD_DISK_ACTIVE))
+							&& (disk.major | disk.minor)) {
+							dv = map_dev_preferred(disk.major, disk.minor, 0,
+									c->prefer);
+							if (!dv)
+								continue;
+							arrayst = IsBitmapDirty(dv) ? "active" : "clean";
+							break;
+						}
+					}
+				}
+			}
 
 			printf("             State : %s%s%s%s%s%s%s \n",
 			       arrayst, st,
bitmap.c +66 -9

121 lines not on this page · raw message

mdadm.h +1 -0
index 4961c0f..21aa547 100644
@@ -1447,6 +1447,7 @@ extern int CreateBitmap(char *filename, int force, char uuid[16],
 			unsigned long long array_size,
 			int major);
 extern int ExamineBitmap(char *filename, int brief, struct supertype *st);
+extern int IsBitmapDirty(char *filename);
 extern int Write_rules(char *rule_name);
 extern int bitmap_update_uuid(int fd, int *uuid, int swap);
 
Signature · 1 line
2.27.0
Applied
#1 lore raw
Quoted 24 lines · Zhao Heming

After kernel md module commit 480523feae581, in clustered env, mddev->in_sync always zero, it will make array.state never set up MD_SB_CLEAN. it causes "mdadm -D /dev/mdX" show state 'active' all the time.

bitmap.c: add a new API IsBitmapDirty() to support inquiry bitmap dirty or clean.

---
v5: (polish code)
- Detail.c: change code logic to only examine valid dev.
- bitmap.c: redesign bitmap_file_open() to support fd reuse. It won't make dev multi-opened in clusterd env.
v4:
- Detail.c: follow Jes comment, split if into 2 lines.
v3:
- Detail.c: fix error logic: v2 code didn't check bitmap when dv is null.
v2:
- Detail.c: follow Neil comments, change to read only one device.
- bitmap.c: follow Neil comments, modify IsBitmapDirty() to check all bitmap on the selected device.

Quoted 5 lines
---
 Detail.c | 20 ++++++++++++++-
 bitmap.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 mdadm.h  |  1 +
 3 files changed, 86 insertions(+), 10 deletions(-)

Applied!

Thanks,
Jes