Skip to contentSkip to conversation

mdadm: Fix some errors for regression tests and building

PATCH In review Xiao Ni 4 participants 17 messages Sep 27, 2023 – Oct 26, 2023

Subsystems (2)
lore
Share & tools
lore

Xiao Ni

author
#0 lore raw

cover mdadm: Fix some errors for regression tests and building

The first two patches are for test cases.
The thrid is a fix for building error.
The forth fixes an output problem.

Xiao Ni (4):
Fix regular expression failure
mdadm/tests: Don't run mknod before losetup
Avoid array bounds check of gcc
Print version to stdout

 Makefile      | 2 +-
 mdadm.c       | 2 +-
 tests/06name  | 4 ++--
 tests/func.sh | 1 -
 4 files changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.32.0 (Apple Git-132)
author
#1 lore raw

PATCH v2 1/4 mdadm/tests: Fix regular expression failure

The test fails because of the regular expression.

---
 tests/06name | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/06name +2 -2
index 4d5e824d3e0e..86eaab69e3a1 100644
@@ -3,8 +3,8 @@ set -x
 # create an array with a name
 
 mdadm -CR $md0 -l0 -n2 --metadata=1 --name="Fred" $dev0 $dev1
-mdadm -E $dev0 | grep 'Name : [^:]*:Fred ' > /dev/null || exit 1
-mdadm -D $md0 | grep 'Name : [^:]*:Fred ' > /dev/null || exit 1
+mdadm -E $dev0 | grep 'Name : Fred' > /dev/null || exit 1
+mdadm -D $md0 | grep 'Name : Fred' > /dev/null || exit 1
 mdadm -S $md0
 
 mdadm -A $md0 --name="Fred" $devlist
Signature · 1 line
2.32.0 (Apple Git-132)
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH 1/4 v2] mdadm/tests: Fix regular expression failure

Quoted 12 lines · On Wed, 27 Sep 2023 10:52:16 +0800 Xiao Ni <[email protected]> wrote:

The test fails because of the regular expression.

---
 tests/06name | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/06name +0 -0
index 4d5e824d3e0e..86eaab69e3a1 100644

tests/06name set -x · line 10

Quoted 10 lines
tests/06name +2 -2
@@ -3,8 +3,8 @@ set -x
 # create an array with a name
 
 mdadm -CR $md0 -l0 -n2 --metadata=1 --name="Fred" $dev0 $dev1
-mdadm -E $dev0 | grep 'Name : [^:]*:Fred ' > /dev/null || exit 1
-mdadm -D $md0 | grep 'Name : [^:]*:Fred ' > /dev/null || exit 1
+mdadm -E $dev0 | grep 'Name : Fred' > /dev/null || exit 1
+mdadm -D $md0 | grep 'Name : Fred' > /dev/null || exit 1
 mdadm -S $md0
 
 mdadm -A $md0 --name="Fred" $devlist

Hello Xiao,
I can see that it is not sent first time. Previous version was moved by me to the "awaiting_upstream" state on patchwork but I forgot to answer. You don't need to send it again. I'm ignoring this one. Anyway, here my approval:

https://patchwork.kernel.org/project/linux-raid/patch/[email protected]/

Thanks,
Mariusz

author
#3 lore raw

Re: [PATCH 1/4 v2] mdadm/tests: Fix regular expression failure

Quoted 33 lines · Mariusz Tkaczyk
Quoted 12 lines · On Wed, 27 Sep 2023 10:52:16 +0800 Xiao Ni <[email protected]> wrote:

The test fails because of the regular expression.

---
 tests/06name | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/06name +0 -0
index 4d5e824d3e0e..86eaab69e3a1 100644

tests/06name set -x · line 10

Quoted 10 lines
tests/06name +2 -2
@@ -3,8 +3,8 @@ set -x
 # create an array with a name
 
 mdadm -CR $md0 -l0 -n2 --metadata=1 --name="Fred" $dev0 $dev1
-mdadm -E $dev0 | grep 'Name : [^:]*:Fred ' > /dev/null || exit 1
-mdadm -D $md0 | grep 'Name : [^:]*:Fred ' > /dev/null || exit 1
+mdadm -E $dev0 | grep 'Name : Fred' > /dev/null || exit 1
+mdadm -D $md0 | grep 'Name : Fred' > /dev/null || exit 1
 mdadm -S $md0
 
 mdadm -A $md0 --name="Fred" $devlist

Hello Xiao,
I can see that it is not sent first time. Previous version was moved by me to the "awaiting_upstream" state on patchwork but I forgot to answer. You don't need to send it again. I'm ignoring this one. Anyway, here my approval:

Quoted 3 lines

https://patchwork.kernel.org/project/linux-raid/patch/[email protected]/

Thanks for the information :)

Regards
Xiao

Quoted 4 lines

Thanks,
Mariusz

Applied
#4 lore raw

Re: [PATCH 1/4 v2] mdadm/tests: Fix regular expression failure

Quoted 35 lines · Xiao Ni
Quoted 33 lines · Mariusz Tkaczyk
Quoted 12 lines · On Wed, 27 Sep 2023 10:52:16 +0800 Xiao Ni <[email protected]> wrote:

The test fails because of the regular expression.

---
 tests/06name | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/06name +0 -0
index 4d5e824d3e0e..86eaab69e3a1 100644

tests/06name set -x · line 10

Quoted 10 lines
tests/06name +2 -2
@@ -3,8 +3,8 @@ set -x
 # create an array with a name
 
 mdadm -CR $md0 -l0 -n2 --metadata=1 --name="Fred" $dev0 $dev1
-mdadm -E $dev0 | grep 'Name : [^:]*:Fred ' > /dev/null || exit 1
-mdadm -D $md0 | grep 'Name : [^:]*:Fred ' > /dev/null || exit 1
+mdadm -E $dev0 | grep 'Name : Fred' > /dev/null || exit 1
+mdadm -D $md0 | grep 'Name : Fred' > /dev/null || exit 1
 mdadm -S $md0
 
 mdadm -A $md0 --name="Fred" $devlist

Hello Xiao,
I can see that it is not sent first time. Previous version was moved by me to the "awaiting_upstream" state on patchwork but I forgot to answer. You don't need to send it again. I'm ignoring this one. Anyway, here my approval:

Quoted 6 lines
Quoted 3 lines

https://patchwork.kernel.org/project/linux-raid/patch/[email protected]/

Thanks for the information :)

Applied!

Thanks,
Jes

author
#5 lore raw

PATCH 3/4 mdadm: Avoid array bounds check of gcc

In reply to Xiao Ni

With gcc version 13.2.1 20230918 (Red Hat 13.2.1-3) (GCC), it reports error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’ [-Werror=array-bounds=]
The subscrit is defined as int type. And it can be smaller than 0. To avoid this error, add -Wno-array-bounds flag in Makefile.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 5eac1a4e9690..47da883a9fb9 100644
@@ -50,7 +50,7 @@ ifeq ($(origin CC),default)
 CC := $(CROSS_COMPILE)gcc
 endif
 CXFLAGS ?= -ggdb
-CWFLAGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter
+CWFLAGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter -Wno-array-bounds
 ifdef WARN_UNUSED
 CWFLAGS += -Wp,-D_FORTIFY_SOURCE=2 -O3
 endif
Signature · 1 line
2.32.0 (Apple Git-132)
#6 lore raw

Re: [PATCH 3/4] mdadm: Avoid array bounds check of gcc

Dear Xiao,

Thank you for your patch.

Am 27.09.23 um 04:52 schrieb Xiao Ni:

Quoted 3 lines

With gcc version 13.2.1 20230918 (Red Hat 13.2.1-3) (GCC), it reports error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’ [-Werror=array-bounds=]

I wouldn’t wrap pasted lines.

Quoted 1 line

The subscrit is defined as int type. And it can be smaller than 0.

subscript?

Quoted 1 line

To avoid this error, add -Wno-array-bounds flag in Makefile.

Wouldn’t it be better to fix the error and not work around it by disabling the warning?

Kind regards,

Paul

Quoted 18 lines
---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 5eac1a4e9690..47da883a9fb9 100644
@@ -50,7 +50,7 @@ ifeq ($(origin CC),default)
  CC := $(CROSS_COMPILE)gcc
  endif
  CXFLAGS ?= -ggdb
-CWFLAGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter
+CWFLAGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter -Wno-array-bounds
  ifdef WARN_UNUSED
  CWFLAGS += -Wp,-D_FORTIFY_SOURCE=2 -O3
  endif
author
#7 lore raw

Re: [PATCH 3/4] mdadm: Avoid array bounds check of gcc

Quoted 4 lines · Paul Menzel

Dear Xiao,

Quoted 8 lines

Thank you for your patch.

Am 27.09.23 um 04:52 schrieb Xiao Ni:

Quoted 3 lines

With gcc version 13.2.1 20230918 (Red Hat 13.2.1-3) (GCC), it reports error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’ [-Werror=array-bounds=]

I wouldn’t wrap pasted lines.

Hi Paul

I thought it exceeds the max character limit which is used for kernel patch rule. I'll change it back.

Quoted 4 lines
Quoted 2 lines

The subscrit is defined as int type. And it can be smaller than 0.

subscript?

yes

Quoted 5 lines
Quoted 2 lines

To avoid this error, add -Wno-array-bounds flag in Makefile.

Wouldn’t it be better to fix the error and not work around it by disabling the warning?

I want to do this first. But the logic bellow indeed checks if the subscript is lower than 0.
It's the reason I add -Wno-array-bounds.

                info->data_offset = be64_to_cpu(ddf->phys->
                                                  entries[info->disk.raid_disk].
                                                  config_size);
                info->component_size = ddf->dlist->size - info->data_offset;
                if (info->disk.raid_disk >= 0)
                        pde = ddf->phys->entries + info->disk.raid_disk;

Do you have any suggestions for this?

Best Regards
Xiao

Quoted 26 lines

Kind regards,

Paul

Quoted 18 lines
---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 5eac1a4e9690..47da883a9fb9 100644
@@ -50,7 +50,7 @@ ifeq ($(origin CC),default)
  CC := $(CROSS_COMPILE)gcc
  endif
  CXFLAGS ?= -ggdb
-CWFLAGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter
+CWFLAGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter -Wno-array-bounds
  ifdef WARN_UNUSED
  CWFLAGS += -Wp,-D_FORTIFY_SOURCE=2 -O3
  endif
#8 lore raw

Re: [PATCH 3/4] mdadm: Avoid array bounds check of gcc

In reply to Xiao Ni
Quoted 4 lines · On Wed, 27 Sep 2023 10:52:18 +0800 Xiao Ni <[email protected]> wrote:

With gcc version 13.2.1 20230918 (Red Hat 13.2.1-3) (GCC), it reports error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’ [-Werror=array-bounds=]
The subscrit is defined as int type. And it can be smaller than 0.

If it can be smaller that 0 then it is something we need to fix. I think that it comes from here:

		info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);
		info->data_offset = be64_to_cpu(ddf->phys->
						  entries[info->disk.raid_disk].
						  config_size);

find_phys can return -1.
It is handled few lines bellow. I don't see reason why we cannot handle it here too.

		if (info->disk.raid_disk >= 0)
			pde = ddf->phys->entries + info->disk.raid_disk;

I think that it will be fair to abort because metadata seems to be corrupted. We are referring to info->disk.raid_disk from many places. We cannot return error because it is void, we can just return.

Quoted 1 line

To avoid this error, add -Wno-array-bounds flag in Makefile.

If you want do it this way please provide strong justification. We are disabling check in all code to hide particular case. It will not prevent us from similar mistakes during development in the future.

Thanks,
Mariusz

author
#9 lore raw

Re: [PATCH 3/4] mdadm: Avoid array bounds check of gcc

Quoted 20 lines · Mariusz Tkaczyk
Quoted 4 lines · On Wed, 27 Sep 2023 10:52:18 +0800 Xiao Ni <[email protected]> wrote:

With gcc version 13.2.1 20230918 (Red Hat 13.2.1-3) (GCC), it reports error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’ [-Werror=array-bounds=]
The subscrit is defined as int type. And it can be smaller than 0.

If it can be smaller that 0 then it is something we need to fix. I think that it comes from here:

                info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);
                info->data_offset = be64_to_cpu(ddf->phys->
                                                  entries[info->disk.raid_disk].
                                                  config_size);

find_phys can return -1.
It is handled few lines bellow. I don't see reason why we cannot handle it here too.

Quoted 6 lines
                if (info->disk.raid_disk >= 0)
                        pde = ddf->phys->entries + info->disk.raid_disk;

I think that it will be fair to abort because metadata seems to be corrupted. We are referring to info->disk.raid_disk from many places. We cannot return error because it is void, we can just return.

Hi Mariusz

You mean something like this?

super-ddf.c +0 -0
index 7213284e0a59..b6e514042055 100644
@@ -1984,6 +1984,9 @@ static void getinfo_super_ddf(struct supertype

*st, struct mdinfo *info, char *m

                info->disk.number = be32_to_cpu(ddf->dlist->disk.refnum);
                info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);

+ if (info->disk.raid_disk < 0)
+ return;
+

                info->data_offset = be64_to_cpu(ddf->phys->
                                                  entries[info->disk.raid_disk].
                                                  config_size);
Quoted 6 lines
Quoted 2 lines

To avoid this error, add -Wno-array-bounds flag in Makefile.

If you want do it this way please provide strong justification. We are disabling check in all code to hide particular case. It will not prevent us from similar mistakes during development in the future.

As Paul and you suggested, I'll not choose this way

Regards
Xiao

Quoted 4 lines

Thanks,
Mariusz

#10 lore raw

Re: [PATCH 3/4] mdadm: Avoid array bounds check of gcc

Quoted 47 lines · On Sat, 7 Oct 2023 21:26:22 +0800 Xiao Ni <[email protected]> wrote:
Quoted 20 lines · Mariusz Tkaczyk
Quoted 4 lines · On Wed, 27 Sep 2023 10:52:18 +0800 Xiao Ni <[email protected]> wrote:

With gcc version 13.2.1 20230918 (Red Hat 13.2.1-3) (GCC), it reports
error: super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’ [-Werror=array-bounds=] The subscrit is defined as int type. And it can be smaller than 0.

If it can be smaller that 0 then it is something we need to fix. I think that it comes from here:

                info->disk.raid_disk = find_phys(ddf,
ddf->dlist->disk.refnum); info->data_offset = be64_to_cpu(ddf->phys->
                                                  entries[info->disk.raid_disk].
                                                  config_size);

find_phys can return -1.
It is handled few lines bellow. I don't see reason why we cannot handle it here too.

Quoted 6 lines
                if (info->disk.raid_disk >= 0)
                        pde = ddf->phys->entries + info->disk.raid_disk;

I think that it will be fair to abort because metadata seems to be corrupted. We are referring to info->disk.raid_disk from many places. We cannot return error because it is void, we can just return.

Hi Mariusz

You mean something like this?

super-ddf.c +3 -0
index 7213284e0a59..b6e514042055 100644
@@ -1984,6 +1984,9 @@ static void getinfo_super_ddf(struct supertype
 *st, struct mdinfo *info, char *m
                info->disk.number = be32_to_cpu(ddf->dlist->disk.refnum);
                info->disk.raid_disk = find_phys(ddf,
 ddf->dlist->disk.refnum);
 
+               if (info->disk.raid_disk < 0)
+                       return;
+
                info->data_offset = be64_to_cpu(ddf->phys->
Quoted 3 lines
                                                  entries[info->disk.raid_disk].
                                                  config_size);

Yes, LGTM!

Mariusz

author
#11 lore raw

PATCH 4/4 mdadm: Print version to stdout

In reply to Xiao Ni

The version information is not error information. Print it to stdout.

---
 mdadm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mdadm.c +1 -1
index 076b45e030b3..0b8854baf1aa 100644
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
 			continue;
 
 		case 'V':
-			fputs(Version, stderr);
+			fputs(Version, stdout);
 			exit(0);
 
 		case 'v': c.verbose++;
Signature · 1 line
2.32.0 (Apple Git-132)
Reviewed-by on v1 4/4
#12 lore raw

Re: [PATCH 4/4] mdadm: Print version to stdout

Quoted 13 lines · On Wed, 27 Sep 2023 10:52:19 +0800 Xiao Ni <[email protected]> wrote:

The version information is not error information. Print it to stdout.

---
 mdadm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mdadm.c +0 -0
index 076b45e030b3..0b8854baf1aa 100644

mdadm.c int main(int argc, char *argv[]) · line 134

Quoted 8 lines
mdadm.c +1 -1
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
 			continue;
 
 		case 'V':
-			fputs(Version, stderr);
+			fputs(Version, stdout);
 			exit(0);
 
 		case 'v': c.verbose++;

I agree with this change but...
This one is risky for users. I can realize that some users may check that from stderr because it is how we implemented it many years ago.

I remember that I removed calls to mdam --help from dracut in the past:
https://github.com/mtkaczyk/dracut/commit/d3d37003dcecdf01f6ae0f4764d74cd035aade73#diff-f2466410e3aff8aeba95038d29b1652581c97d8d7d9feb4011d7b8bc103de1b0L64

And I can see that it does redirection "2>&1". I think that in general this kind of problem is handled this way, so overall I ready to take the risk of changing it to stdout by default.

Thanks,
Mariusz

author
#13 lore raw

Re: [PATCH 4/4] mdadm: Print version to stdout

Quoted 33 lines · Mariusz Tkaczyk
Quoted 13 lines · On Wed, 27 Sep 2023 10:52:19 +0800 Xiao Ni <[email protected]> wrote:

The version information is not error information. Print it to stdout.

---
 mdadm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mdadm.c +0 -0
index 076b45e030b3..0b8854baf1aa 100644

mdadm.c int main(int argc, char *argv[]) · line 134

Quoted 8 lines
mdadm.c +1 -1
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
                      continue;
 
              case 'V':
-                     fputs(Version, stderr);
+                     fputs(Version, stdout);
                      exit(0);
 
              case 'v': c.verbose++;

I agree with this change but...
This one is risky for users. I can realize that some users may check that from stderr because it is how we implemented it many years ago.

I remember that I removed calls to mdam --help from dracut in the past:
https://github.com/mtkaczyk/dracut/commit/d3d37003dcecdf01f6ae0f4764d74cd035aade73#diff-f2466410e3aff8aeba95038d29b1652581c97d8d7d9feb4011d7b8bc103de1b0L64

Quoted 9 lines

And I can see that it does redirection "2>&1". I think that in general this kind of problem is handled this way, so overall I ready to take the risk of changing it to stdout by default.

Thanks,
Mariusz

Hi Mariusz

Sorry for being late to respond. I just came back from holiday. Thanks for the suggestion. It's right that it's risky to do so. I'll drop it in the next version.

Regards
Xiao

author
#14 lore raw

PATCH v2 2/4 mdadm/tests: Don't run mknod before losetup

In reply to Xiao Ni

Sometimes it can fail:
losetup: /var/tmp/mdtest0: failed to set up loop device: No such device or address /dev/loop0 and /var/tmp/mdtest0 are already created before losetup.

Because losetup can create device node by itself. So remove mknod.

---
 tests/func.sh | 1 -
 1 file changed, 1 deletion(-)
tests/func.sh +0 -1
index 9710a53b8a73..5053b0121f1d 100644
@@ -170,7 +170,6 @@ do_setup() {
 				dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
 			# make sure udev doesn't touch
 			mdadm --zero $targetdir/mdtest$d 2> /dev/null
-			[ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
 			if [ $d -eq 7 ]
 			then
 				losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
Signature · 1 line
2.32.0 (Apple Git-132)
Reviewed-by on v2 2/4
#15 lore raw

Re: [PATCH 2/4 v2] mdadm/tests: Don't run mknod before losetup

Quoted 23 lines · On Wed, 27 Sep 2023 10:52:17 +0800 Xiao Ni <[email protected]> wrote:

Sometimes it can fail:
losetup: /var/tmp/mdtest0: failed to set up loop device: No such device or address /dev/loop0 and /var/tmp/mdtest0 are already created before losetup.

Because losetup can create device node by itself. So remove mknod.

---
 tests/func.sh | 1 -
 1 file changed, 1 deletion(-)
tests/func.sh +0 -0
index 9710a53b8a73..5053b0121f1d 100644
@@ -170,7 +170,6 @@ do_setup() {
 				dd if=/dev/zero of=$targetdir/mdtest$d

count=$sz bs=1K > /dev/null 2>&1 # make sure udev doesn't touch

tests/func.sh +0 -1
 			mdadm --zero $targetdir/mdtest$d 2> /dev/null
-			[ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
 			if [ $d -eq 7 ]
 			then
 				losetup /dev/loop$d $targetdir/mdtest6 # for
Quoted 1 line

multipath use

Hello,
Same as in previous case, it is waiting for Jes:
https://patchwork.kernel.org/project/linux-raid/patch/[email protected]/

I'm ignoring this one.

Thanks,
Mariusz

Applied
#16 lore raw

Re: [PATCH 2/4 v2] mdadm/tests: Don't run mknod before losetup

Quoted 11 lines · Mariusz Tkaczyk
Quoted 8 lines · On Wed, 27 Sep 2023 10:52:17 +0800 Xiao Ni <[email protected]> wrote:

Sometimes it can fail:
losetup: /var/tmp/mdtest0: failed to set up loop device: No such device or address /dev/loop0 and /var/tmp/mdtest0 are already created before losetup.

Because losetup can create device node by itself. So remove mknod.

---

Applied!

Thanks,
Jes