* [PATCH] mdadm/Detail: show correct state for cluster-md array
@ 2020-07-17 18:09 Zhao Heming
2020-07-20 0:17 ` NeilBrown
0 siblings, 1 reply; 4+ messages in thread
From: Zhao Heming @ 2020-07-17 18:09 UTC (permalink / raw)
To: linux-raid; +Cc: Zhao Heming, neilb, jes
After kernel md module commit 480523feae581, in md-cluster 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>
---
Detail.c | 21 ++++++++++++++++++++-
bitmap.c | 27 +++++++++++++++++++++++++++
mdadm.h | 1 +
3 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/Detail.c b/Detail.c
index 24eeba0..fd580a3 100644
--- a/Detail.c
+++ b/Detail.c
@@ -495,8 +495,27 @@ int Detail(char *dev, struct context *c)
sra->array_state);
else
arrayst = "clean";
- } else
+ } else {
arrayst = "active";
+ if (array.state & (1<<MD_SB_CLUSTERED)) {
+ int dirty = 0;
+ for (d = 0; d < max_disks * 2; d++) {
+ char *dv;
+ mdu_disk_info_t disk = disks[d];
+
+ if (d >= array.raid_disks * 2 &&
+ disk.major == 0 && disk.minor == 0)
+ continue;
+ if ((d & 1) && disk.major == 0 && disk.minor == 0)
+ continue;
+ dv = map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
+ if (dv != NULL)
+ if ((dirty = IsBitmapDirty(dv))) break;
+ }
+ if (dirty == 0)
+ arrayst = "clean";
+ }
+ }
printf(" State : %s%s%s%s%s%s%s \n",
arrayst, st,
diff --git a/bitmap.c b/bitmap.c
index e38cb96..90ad932 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -368,6 +368,33 @@ free_info:
return rv;
}
+int IsBitmapDirty(char *filename)
+{
+ /*
+ * Read the bitmap file
+ * return: 1(dirty), 0 (clean), -1(error)
+ */
+
+ struct supertype *st = NULL;
+ bitmap_info_t *info;
+ int fd = -1, rv = -1;
+
+ fd = bitmap_file_open(filename, &st, 0);
+ if (fd < 0)
+ return rv;
+
+ info = bitmap_fd_read(fd, 0);
+ if (!info) {
+ goto out;
+ }
+ rv = info->dirty_bits ? 1 : 0;
+ free(info);
+out:
+ close(fd);
+ free(st);
+ return rv;
+}
+
int CreateBitmap(char *filename, int force, char uuid[16],
unsigned long chunksize, unsigned long daemon_sleep,
unsigned long write_behind,
diff --git a/mdadm.h b/mdadm.h
index 399478b..ba8ba91 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.25.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mdadm/Detail: show correct state for cluster-md array
2020-07-17 18:09 [PATCH] mdadm/Detail: show correct state for cluster-md array Zhao Heming
@ 2020-07-20 0:17 ` NeilBrown
0 siblings, 0 replies; 4+ messages in thread
From: NeilBrown @ 2020-07-20 0:17 UTC (permalink / raw)
To: linux-raid; +Cc: Zhao Heming, neilb, jes
[-- Attachment #1: Type: text/plain, Size: 3357 bytes --]
On Sat, Jul 18 2020, Zhao Heming wrote:
> After kernel md module commit 480523feae581, in md-cluster 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>
> ---
> Detail.c | 21 ++++++++++++++++++++-
> bitmap.c | 27 +++++++++++++++++++++++++++
> mdadm.h | 1 +
> 3 files changed, 48 insertions(+), 1 deletion(-)
>
> diff --git a/Detail.c b/Detail.c
> index 24eeba0..fd580a3 100644
> --- a/Detail.c
> +++ b/Detail.c
> @@ -495,8 +495,27 @@ int Detail(char *dev, struct context *c)
> sra->array_state);
> else
> arrayst = "clean";
> - } else
> + } else {
> arrayst = "active";
> + if (array.state & (1<<MD_SB_CLUSTERED)) {
> + int dirty = 0;
> + for (d = 0; d < max_disks * 2; d++) {
> + char *dv;
> + mdu_disk_info_t disk = disks[d];
> +
> + if (d >= array.raid_disks * 2 &&
> + disk.major == 0 && disk.minor == 0)
> + continue;
> + if ((d & 1) && disk.major == 0 && disk.minor == 0)
> + continue;
> + dv = map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
> + if (dv != NULL)
> + if ((dirty = IsBitmapDirty(dv))) break;
You don't need to read the bitmap from every device - they should all be
the same. Just reading one is sufficient.
However ....
> + }
> + if (dirty == 0)
> + arrayst = "clean";
> + }
> + }
>
> printf(" State : %s%s%s%s%s%s%s \n",
> arrayst, st,
> diff --git a/bitmap.c b/bitmap.c
> index e38cb96..90ad932 100644
> --- a/bitmap.c
> +++ b/bitmap.c
> @@ -368,6 +368,33 @@ free_info:
> return rv;
> }
>
> +int IsBitmapDirty(char *filename)
> +{
> + /*
> + * Read the bitmap file
> + * return: 1(dirty), 0 (clean), -1(error)
> + */
> +
> + struct supertype *st = NULL;
> + bitmap_info_t *info;
> + int fd = -1, rv = -1;
> +
> + fd = bitmap_file_open(filename, &st, 0);
> + if (fd < 0)
> + return rv;
> +
> + info = bitmap_fd_read(fd, 0);
This only examines the first bitmap. For a cluster-array there is a
separate bitmap for each node in the cluster.
See the
for (i = 0; i < (int)sb->nodes; i++) {
loop in ExamineBitmap(). You need to check for active bits in every
bitmap on the selected device.
NeilBrown
> + if (!info) {
> + goto out;
> + }
> + rv = info->dirty_bits ? 1 : 0;
> + free(info);
> +out:
> + close(fd);
> + free(st);
> + return rv;
> +}
> +
> int CreateBitmap(char *filename, int force, char uuid[16],
> unsigned long chunksize, unsigned long daemon_sleep,
> unsigned long write_behind,
> diff --git a/mdadm.h b/mdadm.h
> index 399478b..ba8ba91 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.25.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mdadm/Detail: show correct state for cluster-md array
2020-07-17 17:51 Zhao Heming
@ 2020-07-17 17:55 ` heming.zhao
0 siblings, 0 replies; 4+ messages in thread
From: heming.zhao @ 2020-07-17 17:55 UTC (permalink / raw)
To: linux-raid; +Cc: neilb, jes
I am very sorry, this patch contains bug.
please ignore this mail.
I will resend this patch very soon.
On 7/18/20 1:51 AM, Zhao Heming wrote:
> After kernel md module commit 480523feae581, in md-cluster 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>
> ---
> Detail.c | 21 ++++++++++++++++++++-
> bitmap.c | 22 ++++++++++++++++++++++
> mdadm.h | 1 +
> 3 files changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/Detail.c b/Detail.c
> index 24eeba0..fd580a3 100644
> --- a/Detail.c
> +++ b/Detail.c
> @@ -495,8 +495,27 @@ int Detail(char *dev, struct context *c)
> sra->array_state);
> else
> arrayst = "clean";
> - } else
> + } else {
> arrayst = "active";
> + if (array.state & (1<<MD_SB_CLUSTERED)) {
> + int dirty = 0;
> + for (d = 0; d < max_disks * 2; d++) {
> + char *dv;
> + mdu_disk_info_t disk = disks[d];
> +
> + if (d >= array.raid_disks * 2 &&
> + disk.major == 0 && disk.minor == 0)
> + continue;
> + if ((d & 1) && disk.major == 0 && disk.minor == 0)
> + continue;
> + dv = map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
> + if (dv != NULL)
> + if ((dirty = IsBitmapDirty(dv))) break;
> + }
> + if (dirty == 0)
> + arrayst = "clean";
> + }
> + }
>
> printf(" State : %s%s%s%s%s%s%s \n",
> arrayst, st,
> diff --git a/bitmap.c b/bitmap.c
> index e38cb96..10c2045 100644
> --- a/bitmap.c
> +++ b/bitmap.c
> @@ -368,6 +368,28 @@ free_info:
> return rv;
> }
>
> +int IsBitmapDirty(char *filename)
> +{
> + /*
> + * Read the bitmap file
> + * return: 1(dirty), 0 (clean), -1(error)
> + */
> +
> + struct supertype *st = NULL;
> + bitmap_info_t *info;
> + int fd = -1, rv = -1;
> +
> + fd = bitmap_file_open(filename, &st, 0);
> + if (fd < 0)
> + return rv;
> +
> + info = bitmap_fd_read(fd, 0);
> + if (!info)
> + return rv;
> + close(fd);
> + return info->dirty_bits ? 1 : 0;
> +}
> +
> int CreateBitmap(char *filename, int force, char uuid[16],
> unsigned long chunksize, unsigned long daemon_sleep,
> unsigned long write_behind,
> diff --git a/mdadm.h b/mdadm.h
> index 399478b..ba8ba91 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);
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] mdadm/Detail: show correct state for cluster-md array
@ 2020-07-17 17:51 Zhao Heming
2020-07-17 17:55 ` heming.zhao
0 siblings, 1 reply; 4+ messages in thread
From: Zhao Heming @ 2020-07-17 17:51 UTC (permalink / raw)
To: linux-raid; +Cc: Zhao Heming, neilb, jes
After kernel md module commit 480523feae581, in md-cluster 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>
---
Detail.c | 21 ++++++++++++++++++++-
bitmap.c | 22 ++++++++++++++++++++++
mdadm.h | 1 +
3 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/Detail.c b/Detail.c
index 24eeba0..fd580a3 100644
--- a/Detail.c
+++ b/Detail.c
@@ -495,8 +495,27 @@ int Detail(char *dev, struct context *c)
sra->array_state);
else
arrayst = "clean";
- } else
+ } else {
arrayst = "active";
+ if (array.state & (1<<MD_SB_CLUSTERED)) {
+ int dirty = 0;
+ for (d = 0; d < max_disks * 2; d++) {
+ char *dv;
+ mdu_disk_info_t disk = disks[d];
+
+ if (d >= array.raid_disks * 2 &&
+ disk.major == 0 && disk.minor == 0)
+ continue;
+ if ((d & 1) && disk.major == 0 && disk.minor == 0)
+ continue;
+ dv = map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
+ if (dv != NULL)
+ if ((dirty = IsBitmapDirty(dv))) break;
+ }
+ if (dirty == 0)
+ arrayst = "clean";
+ }
+ }
printf(" State : %s%s%s%s%s%s%s \n",
arrayst, st,
diff --git a/bitmap.c b/bitmap.c
index e38cb96..10c2045 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -368,6 +368,28 @@ free_info:
return rv;
}
+int IsBitmapDirty(char *filename)
+{
+ /*
+ * Read the bitmap file
+ * return: 1(dirty), 0 (clean), -1(error)
+ */
+
+ struct supertype *st = NULL;
+ bitmap_info_t *info;
+ int fd = -1, rv = -1;
+
+ fd = bitmap_file_open(filename, &st, 0);
+ if (fd < 0)
+ return rv;
+
+ info = bitmap_fd_read(fd, 0);
+ if (!info)
+ return rv;
+ close(fd);
+ return info->dirty_bits ? 1 : 0;
+}
+
int CreateBitmap(char *filename, int force, char uuid[16],
unsigned long chunksize, unsigned long daemon_sleep,
unsigned long write_behind,
diff --git a/mdadm.h b/mdadm.h
index 399478b..ba8ba91 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.25.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-20 0:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 18:09 [PATCH] mdadm/Detail: show correct state for cluster-md array Zhao Heming
2020-07-20 0:17 ` NeilBrown
-- strict thread matches above, loose matches on Subject: below --
2020-07-17 17:51 Zhao Heming
2020-07-17 17:55 ` heming.zhao
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.