* [PATCH v5] mdadm/Detail: show correct state for clustered array
@ 2020-10-24 9:43 Zhao Heming
2020-11-25 23:20 ` Jes Sorensen
0 siblings, 1 reply; 2+ messages in thread
From: Zhao Heming @ 2020-10-24 9:43 UTC (permalink / raw)
To: linux-raid, jes; +Cc: Zhao Heming, neilb
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.
Signed-off-by: Zhao Heming <heming.zhao@suse.com>
---
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(-)
diff --git a/Detail.c b/Detail.c
index b6587c8..14cb7f2 100644
--- a/Detail.c
+++ b/Detail.c
@@ -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,
diff --git a/bitmap.c b/bitmap.c
index e38cb96..9a7ffe3 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -180,13 +180,14 @@ out:
}
static int
-bitmap_file_open(char *filename, struct supertype **stp, int node_num)
+bitmap_file_open(char *filename, struct supertype **stp, int node_num, int fd)
{
- int fd;
struct stat stb;
struct supertype *st = *stp;
- fd = open(filename, O_RDONLY|O_DIRECT);
+ /* won't re-open filename when (fd >= 0) */
+ if (fd < 0)
+ fd = open(filename, O_RDONLY|O_DIRECT);
if (fd < 0) {
pr_err("failed to open bitmap file %s: %s\n",
filename, strerror(errno));
@@ -249,7 +250,7 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
int fd, i;
__u32 uuid32[4];
- fd = bitmap_file_open(filename, &st, 0);
+ fd = bitmap_file_open(filename, &st, 0, -1);
if (fd < 0)
return rv;
@@ -263,7 +264,6 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
pr_err("Reporting bitmap that would be used if this array were used\n");
pr_err("as a member of some other array\n");
}
- close(fd);
printf(" Filename : %s\n", filename);
printf(" Magic : %08x\n", sb->magic);
if (sb->magic != BITMAP_MAGIC) {
@@ -332,15 +332,13 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
for (i = 0; i < (int)sb->nodes; i++) {
st = NULL;
free(info);
- fd = bitmap_file_open(filename, &st, i);
+ fd = bitmap_file_open(filename, &st, i, fd);
if (fd < 0) {
printf(" Unable to open bitmap file on node: %i\n", i);
-
continue;
}
info = bitmap_fd_read(fd, brief);
if (!info) {
- close(fd);
printf(" Unable to read bitmap on node: %i\n", i);
continue;
}
@@ -359,13 +357,72 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
printf(" Bitmap : %llu bits (chunks), %llu dirty (%2.1f%%)\n",
info->total_bits, info->dirty_bits,
100.0 * info->dirty_bits / (info->total_bits?:1));
- close(fd);
}
}
free_info:
+ close(fd);
+ free(info);
+ return rv;
+}
+
+int IsBitmapDirty(char *filename)
+{
+ /*
+ * Read the bitmap file
+ * It will break reading bitmap action immediately when meeting any error.
+ *
+ * Return: 1(dirty), 0 (clean), -1(error)
+ */
+
+ int fd = -1, rv = 0, i;
+ struct supertype *st = NULL;
+ bitmap_info_t *info = NULL;
+ bitmap_super_t *sb = NULL;
+
+ fd = bitmap_file_open(filename, &st, 0, fd);
+ free(st);
+ if (fd < 0)
+ goto out;
+
+ info = bitmap_fd_read(fd, 0);
+ if (!info) {
+ close(fd);
+ goto out;
+ }
+
+ sb = &info->sb;
+ for (i = 0; i < (int)sb->nodes; i++) {
+ st = NULL;
+ free(info);
+ info = NULL;
+
+ fd = bitmap_file_open(filename, &st, i, fd);
+ free(st);
+ if (fd < 0)
+ goto out;
+
+ info = bitmap_fd_read(fd, 0);
+ if (!info) {
+ close(fd);
+ goto out;
+ }
+
+ sb = &info->sb;
+ if (sb->magic != BITMAP_MAGIC) { /* invalid bitmap magic */
+ free(info);
+ close(fd);
+ goto out;
+ }
+
+ if (info->dirty_bits)
+ rv = 1;
+ }
+ close(fd);
free(info);
return rv;
+out:
+ return -1;
}
int CreateBitmap(char *filename, int force, char uuid[16],
diff --git a/mdadm.h b/mdadm.h
index 4961c0f..21aa547 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -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);
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v5] mdadm/Detail: show correct state for clustered array
2020-10-24 9:43 [PATCH v5] mdadm/Detail: show correct state for clustered array Zhao Heming
@ 2020-11-25 23:20 ` Jes Sorensen
0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2020-11-25 23:20 UTC (permalink / raw)
To: Zhao Heming, linux-raid; +Cc: neilb
On 10/24/20 5:43 AM, Zhao Heming wrote:
> 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.
>
> Signed-off-by: Zhao Heming <heming.zhao@suse.com>
> ---
> 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(-)
Applied!
Thanks,
Jes
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-25 23:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-24 9:43 [PATCH v5] mdadm/Detail: show correct state for clustered array Zhao Heming
2020-11-25 23:20 ` Jes Sorensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).