Skip to contentSkip to conversation

Fix build issues

PATCH Applied Guoqing Jiang 2 participants 5 messages May 18, 2020 – May 19, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover Fix build issues

Hi Jes,

A new version per your comment, let me know if I still missed something.

V3 Change:
1. check the return value of lseek

V2 Changes:
1. copy the whole license from util.c to uuid.c
2. check the return value of read correctly

Thanks,
Guoqing

Guoqing Jiang (2):
uuid.c: split uuid stuffs from util.c
restripe: fix ignoring return value of ‘read’ and lseek

 Makefile   |   6 +--
 restripe.c |  12 +++++-
 util.c     |  87 -----------------------------------------
 uuid.c     | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 125 insertions(+), 92 deletions(-)
 create mode 100644 uuid.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/2 uuid.c: split uuid stuffs from util.c

Currently, 'make raid6check' is build broken since commit b06815989 ("mdadm: load default sysfs attributes after assemblation").

/usr/bin/ld: sysfs.o: in function `sysfsline':
sysfs.c:(.text+0x2707): undefined reference to parse_uuid' /usr/bin/ld: sysfs.c:(.text+0x271a): undefined reference to uuid_zero' /usr/bin/ld: sysfs.c:(.text+0x2721): undefined reference to `uuid_zero'

Apparently, the compile of mdadm or raid6check are coupled with uuid functions inside util.c. However, we can't just add util.o to CHECK_OBJS which raid6check is needed, because it caused other worse problems.

So, let's introduce a uuid.c file which is indenpended file to fix the problem, all the contents are splitted from util.c.

---
 Makefile |   6 +--
 util.c   |  87 ------------------------------------------
 uuid.c   | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 90 deletions(-)
 create mode 100644 uuid.c
Makefile +3 -3
index a33319a..d13030c 100644
@@ -139,7 +139,7 @@ else
 	ECHO=:
 endif
 
-OBJS =  mdadm.o config.o policy.o mdstat.o  ReadMe.o util.o maps.o lib.o \
+OBJS =  mdadm.o config.o policy.o mdstat.o  ReadMe.o uuid.o util.o maps.o lib.o \
 	Manage.o Assemble.o Build.o \
 	Create.o Detail.o Examine.o Grow.o Monitor.o dlink.o Kill.o Query.o \
 	Incremental.o Dump.o \
@@ -148,13 +148,13 @@ OBJS =  mdadm.o config.o policy.o mdstat.o  ReadMe.o util.o maps.o lib.o \
 	restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o xmalloc.o \
 	platform-intel.o probe_roms.o crc32c.o
 
-CHECK_OBJS = restripe.o sysfs.o maps.o lib.o xmalloc.o dlink.o
+CHECK_OBJS = restripe.o uuid.o sysfs.o maps.o lib.o xmalloc.o dlink.o
 
 SRCS =  $(patsubst %.o,%.c,$(OBJS))
 
 INCL = mdadm.h part.h bitmap.h
 
-MON_OBJS = mdmon.o monitor.o managemon.o util.o maps.o mdstat.o sysfs.o \
+MON_OBJS = mdmon.o monitor.o managemon.o uuid.o util.o maps.o mdstat.o sysfs.o \
 	policy.o lib.o \
 	Kill.o sg_io.o dlink.o ReadMe.o super-intel.o \
 	super-mbr.o super-gpt.o \
util.c +0 -87

99 lines not on this page · raw message

uuid.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.17.1
Applied
#2 lore raw

Re: [PATCH V3 1/2] uuid.c: split uuid stuffs from util.c

Quoted 15 lines · Guoqing Jiang

Currently, 'make raid6check' is build broken since commit b06815989 ("mdadm: load default sysfs attributes after assemblation").

/usr/bin/ld: sysfs.o: in function `sysfsline':
sysfs.c:(.text+0x2707): undefined reference to parse_uuid' /usr/bin/ld: sysfs.c:(.text+0x271a): undefined reference to uuid_zero' /usr/bin/ld: sysfs.c:(.text+0x2721): undefined reference to `uuid_zero'

Apparently, the compile of mdadm or raid6check are coupled with uuid functions inside util.c. However, we can't just add util.o to CHECK_OBJS which raid6check is needed, because it caused other worse problems.

So, let's introduce a uuid.c file which is indenpended file to fix the problem, all the contents are splitted from util.c.

Quoted 7 lines
---
 Makefile |   6 +--
 util.c   |  87 ------------------------------------------
 uuid.c   | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 90 deletions(-)
 create mode 100644 uuid.c

Applied!

Thanks,
Jes

#3 lore raw

PATCH v3 2/2 restripe: fix ignoring return value of ‘read’ and lseek

In reply to Guoqing Jiang

Got below error when run "make everything".

restripe.c: In function ‘test_stripes’:
restripe.c:870:4: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]

    read(source[i], stripes[i], chunk_size);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix it by check the return value of ‘read’, and free memory in the failure case.

And check the return value of lseek as well per Jes's comment.

---
 restripe.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
restripe.c +10 -2
index 31b07e8..86e1d00 100644
@@ -866,8 +866,16 @@ int test_stripes(int *source, unsigned long long *offsets,
 		int disk;
 
 		for (i = 0 ; i < raid_disks ; i++) {
-			lseek64(source[i], offsets[i]+start, 0);
-			read(source[i], stripes[i], chunk_size);
+			if ((lseek64(source[i], offsets[i]+start, 0) < 0) ||
+			    (read(source[i], stripes[i], chunk_size) !=
+			     chunk_size)) {
+				free(q);
+				free(p);
+				free(blocks);
+				free(stripes);
+				free(stripe_buf);
+				return -1;
+			}
 		}
 		for (i = 0 ; i < data_disks ; i++) {
 			int disk = geo_map(i, start/chunk_size, raid_disks,
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH V3 2/2] restripe: fix ignoring return value of ‘read’ and lseek

Quoted 31 lines · Guoqing Jiang

Got below error when run "make everything".

restripe.c: In function ‘test_stripes’:
restripe.c:870:4: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]

    read(source[i], stripes[i], chunk_size);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix it by check the return value of ‘read’, and free memory in the failure case.

And check the return value of lseek as well per Jes's comment.

---
 restripe.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
restripe.c +3 -2
index 31b07e8..86e1d00 100644
@@ -866,8 +866,16 @@ int test_stripes(int *source, unsigned long long *offsets,
 		int disk;
 
 		for (i = 0 ; i < raid_disks ; i++) {
-			lseek64(source[i], offsets[i]+start, 0);
-			read(source[i], stripes[i], chunk_size);
+			if ((lseek64(source[i], offsets[i]+start, 0) < 0) ||
+			    (read(source[i], stripes[i], chunk_size) !=
+			     chunk_size)) {

restripe.c int test_stripes(int *source, unsigned long long *offsets, · line 881

Quoted 10 lines
restripe.c +7 -0
+				free(q);
+				free(p);
+				free(blocks);
+				free(stripes);
+				free(stripe_buf);
+				return -1;
+			}
 		}
 		for (i = 0 ; i < data_disks ; i++) {
 			int disk = geo_map(i, start/chunk_size, raid_disks,

This is not the prettiest solution, would have been nicer to introduce a cleanup handler at the end and just jumping to it.

That said, I have applied it since restripe.c is pretty ugly across the board.

Thanks,
Jes