dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/0079-uuid.c-split-uuid-stuffs-from-util.c.patch

790dca
From f4c8a605d2467c0ed25fcba5d27dd56540660e55 Mon Sep 17 00:00:00 2001
790dca
From: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
790dca
Date: Mon, 18 May 2020 23:53:35 +0200
790dca
Subject: [PATCH 079/108] uuid.c: split uuid stuffs from util.c
790dca
790dca
Currently, 'make raid6check' is build broken since commit b06815989
790dca
("mdadm: load default sysfs attributes after assemblation").
790dca
790dca
/usr/bin/ld: sysfs.o: in function `sysfsline':
790dca
sysfs.c:(.text+0x2707): undefined reference to `parse_uuid'
790dca
/usr/bin/ld: sysfs.c:(.text+0x271a): undefined reference to `uuid_zero'
790dca
/usr/bin/ld: sysfs.c:(.text+0x2721): undefined reference to `uuid_zero'
790dca
790dca
Apparently, the compile of mdadm or raid6check are coupled with uuid
790dca
functions inside util.c. However, we can't just add util.o to CHECK_OBJS
790dca
which raid6check is needed, because it caused other worse problems.
790dca
790dca
So, let's introduce a uuid.c file which is indenpended file to fix the
790dca
problem, all the contents are splitted from util.c.
790dca
790dca
Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
790dca
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
790dca
---
790dca
 Makefile |   6 ++--
790dca
 util.c   |  87 -------------------------------------------------
790dca
 uuid.c   | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
790dca
 3 files changed, 115 insertions(+), 90 deletions(-)
790dca
 create mode 100644 uuid.c
790dca
790dca
diff --git a/Makefile b/Makefile
790dca
index 0a20b75..15d05d1 100644
790dca
--- a/Makefile
790dca
+++ b/Makefile
790dca
@@ -140,7 +140,7 @@ else
790dca
 	ECHO=:
790dca
 endif
790dca
 
790dca
-OBJS =  mdadm.o config.o policy.o mdstat.o  ReadMe.o util.o maps.o lib.o \
790dca
+OBJS =  mdadm.o config.o policy.o mdstat.o  ReadMe.o uuid.o util.o maps.o lib.o \
790dca
 	Manage.o Assemble.o Build.o \
790dca
 	Create.o Detail.o Examine.o Grow.o Monitor.o dlink.o Kill.o Query.o \
790dca
 	Incremental.o Dump.o \
790dca
@@ -149,13 +149,13 @@ OBJS =  mdadm.o config.o policy.o mdstat.o  ReadMe.o util.o maps.o lib.o \
790dca
 	restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o xmalloc.o \
790dca
 	platform-intel.o probe_roms.o crc32c.o
790dca
 
790dca
-CHECK_OBJS = restripe.o sysfs.o maps.o lib.o xmalloc.o dlink.o
790dca
+CHECK_OBJS = restripe.o uuid.o sysfs.o maps.o lib.o xmalloc.o dlink.o
790dca
 
790dca
 SRCS =  $(patsubst %.o,%.c,$(OBJS))
790dca
 
790dca
 INCL = mdadm.h part.h bitmap.h
790dca
 
790dca
-MON_OBJS = mdmon.o monitor.o managemon.o util.o maps.o mdstat.o sysfs.o \
790dca
+MON_OBJS = mdmon.o monitor.o managemon.o uuid.o util.o maps.o mdstat.o sysfs.o \
790dca
 	policy.o lib.o \
790dca
 	Kill.o sg_io.o dlink.o ReadMe.o super-intel.o \
790dca
 	super-mbr.o super-gpt.o \
790dca
diff --git a/util.c b/util.c
790dca
index 07f9dc3..579dd42 100644
790dca
--- a/util.c
790dca
+++ b/util.c
790dca
@@ -306,43 +306,6 @@ int md_get_disk_info(int fd, struct mdu_disk_info_s *disk)
790dca
 	return ioctl(fd, GET_DISK_INFO, disk);
790dca
 }
790dca
 
790dca
-/*
790dca
- * Parse a 128 bit uuid in 4 integers
790dca
- * format is 32 hexx nibbles with options :.<space> separator
790dca
- * If not exactly 32 hex digits are found, return 0
790dca
- * else return 1
790dca
- */
790dca
-int parse_uuid(char *str, int uuid[4])
790dca
-{
790dca
-	int hit = 0; /* number of Hex digIT */
790dca
-	int i;
790dca
-	char c;
790dca
-	for (i = 0; i < 4; i++)
790dca
-		uuid[i] = 0;
790dca
-
790dca
-	while ((c = *str++) != 0) {
790dca
-		int n;
790dca
-		if (c >= '0' && c <= '9')
790dca
-			n = c-'0';
790dca
-		else if (c >= 'a' && c <= 'f')
790dca
-			n = 10 + c - 'a';
790dca
-		else if (c >= 'A' && c <= 'F')
790dca
-			n = 10 + c - 'A';
790dca
-		else if (strchr(":. -", c))
790dca
-			continue;
790dca
-		else return 0;
790dca
-
790dca
-		if (hit<32) {
790dca
-			uuid[hit/8] <<= 4;
790dca
-			uuid[hit/8] += n;
790dca
-		}
790dca
-		hit++;
790dca
-	}
790dca
-	if (hit == 32)
790dca
-		return 1;
790dca
-	return 0;
790dca
-}
790dca
-
790dca
 int get_linux_version()
790dca
 {
790dca
 	struct utsname name;
790dca
@@ -611,56 +574,6 @@ int enough(int level, int raid_disks, int layout, int clean, char *avail)
790dca
 	}
790dca
 }
790dca
 
790dca
-const int uuid_zero[4] = { 0, 0, 0, 0 };
790dca
-
790dca
-int same_uuid(int a[4], int b[4], int swapuuid)
790dca
-{
790dca
-	if (swapuuid) {
790dca
-		/* parse uuids are hostendian.
790dca
-		 * uuid's from some superblocks are big-ending
790dca
-		 * if there is a difference, we need to swap..
790dca
-		 */
790dca
-		unsigned char *ac = (unsigned char *)a;
790dca
-		unsigned char *bc = (unsigned char *)b;
790dca
-		int i;
790dca
-		for (i = 0; i < 16; i += 4) {
790dca
-			if (ac[i+0] != bc[i+3] ||
790dca
-			    ac[i+1] != bc[i+2] ||
790dca
-			    ac[i+2] != bc[i+1] ||
790dca
-			    ac[i+3] != bc[i+0])
790dca
-				return 0;
790dca
-		}
790dca
-		return 1;
790dca
-	} else {
790dca
-		if (a[0]==b[0] &&
790dca
-		    a[1]==b[1] &&
790dca
-		    a[2]==b[2] &&
790dca
-		    a[3]==b[3])
790dca
-			return 1;
790dca
-		return 0;
790dca
-	}
790dca
-}
790dca
-
790dca
-void copy_uuid(void *a, int b[4], int swapuuid)
790dca
-{
790dca
-	if (swapuuid) {
790dca
-		/* parse uuids are hostendian.
790dca
-		 * uuid's from some superblocks are big-ending
790dca
-		 * if there is a difference, we need to swap..
790dca
-		 */
790dca
-		unsigned char *ac = (unsigned char *)a;
790dca
-		unsigned char *bc = (unsigned char *)b;
790dca
-		int i;
790dca
-		for (i = 0; i < 16; i += 4) {
790dca
-			ac[i+0] = bc[i+3];
790dca
-			ac[i+1] = bc[i+2];
790dca
-			ac[i+2] = bc[i+1];
790dca
-			ac[i+3] = bc[i+0];
790dca
-		}
790dca
-	} else
790dca
-		memcpy(a, b, 16);
790dca
-}
790dca
-
790dca
 char *__fname_from_uuid(int id[4], int swap, char *buf, char sep)
790dca
 {
790dca
 	int i, j;
790dca
diff --git a/uuid.c b/uuid.c
790dca
new file mode 100644
790dca
index 0000000..94b5abd
790dca
--- /dev/null
790dca
+++ b/uuid.c
790dca
@@ -0,0 +1,112 @@
790dca
+/*
790dca
+ * mdadm - manage Linux "md" devices aka RAID arrays.
790dca
+ *
790dca
+ * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de>
790dca
+ *
790dca
+ *
790dca
+ *    This program is free software; you can redistribute it and/or modify
790dca
+ *    it under the terms of the GNU General Public License as published by
790dca
+ *    the Free Software Foundation; either version 2 of the License, or
790dca
+ *    (at your option) any later version.
790dca
+ *
790dca
+ *    This program is distributed in the hope that it will be useful,
790dca
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
790dca
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
790dca
+ *    GNU General Public License for more details.
790dca
+ *
790dca
+ *    You should have received a copy of the GNU General Public License
790dca
+ *    along with this program; if not, write to the Free Software
790dca
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
790dca
+ *
790dca
+ *    Author: Neil Brown
790dca
+ *    Email: <neilb@suse.de>
790dca
+ */
790dca
+
790dca
+#include	<string.h>
790dca
+
790dca
+const int uuid_zero[4] = { 0, 0, 0, 0 };
790dca
+
790dca
+int same_uuid(int a[4], int b[4], int swapuuid)
790dca
+{
790dca
+	if (swapuuid) {
790dca
+		/* parse uuids are hostendian.
790dca
+		 * uuid's from some superblocks are big-ending
790dca
+		 * if there is a difference, we need to swap..
790dca
+		 */
790dca
+		unsigned char *ac = (unsigned char *)a;
790dca
+		unsigned char *bc = (unsigned char *)b;
790dca
+		int i;
790dca
+		for (i = 0; i < 16; i += 4) {
790dca
+			if (ac[i+0] != bc[i+3] ||
790dca
+			    ac[i+1] != bc[i+2] ||
790dca
+			    ac[i+2] != bc[i+1] ||
790dca
+			    ac[i+3] != bc[i+0])
790dca
+				return 0;
790dca
+		}
790dca
+		return 1;
790dca
+	} else {
790dca
+		if (a[0]==b[0] &&
790dca
+		    a[1]==b[1] &&
790dca
+		    a[2]==b[2] &&
790dca
+		    a[3]==b[3])
790dca
+			return 1;
790dca
+		return 0;
790dca
+	}
790dca
+}
790dca
+
790dca
+void copy_uuid(void *a, int b[4], int swapuuid)
790dca
+{
790dca
+	if (swapuuid) {
790dca
+		/* parse uuids are hostendian.
790dca
+		 * uuid's from some superblocks are big-ending
790dca
+		 * if there is a difference, we need to swap..
790dca
+		 */
790dca
+		unsigned char *ac = (unsigned char *)a;
790dca
+		unsigned char *bc = (unsigned char *)b;
790dca
+		int i;
790dca
+		for (i = 0; i < 16; i += 4) {
790dca
+			ac[i+0] = bc[i+3];
790dca
+			ac[i+1] = bc[i+2];
790dca
+			ac[i+2] = bc[i+1];
790dca
+			ac[i+3] = bc[i+0];
790dca
+		}
790dca
+	} else
790dca
+		memcpy(a, b, 16);
790dca
+}
790dca
+
790dca
+/*
790dca
+ * Parse a 128 bit uuid in 4 integers
790dca
+ * format is 32 hexx nibbles with options :.<space> separator
790dca
+ * If not exactly 32 hex digits are found, return 0
790dca
+ * else return 1
790dca
+ */
790dca
+int parse_uuid(char *str, int uuid[4])
790dca
+{
790dca
+	int hit = 0; /* number of Hex digIT */
790dca
+	int i;
790dca
+	char c;
790dca
+	for (i = 0; i < 4; i++)
790dca
+		uuid[i] = 0;
790dca
+
790dca
+	while ((c = *str++) != 0) {
790dca
+		int n;
790dca
+		if (c >= '0' && c <= '9')
790dca
+			n = c-'0';
790dca
+		else if (c >= 'a' && c <= 'f')
790dca
+			n = 10 + c - 'a';
790dca
+		else if (c >= 'A' && c <= 'F')
790dca
+			n = 10 + c - 'A';
790dca
+		else if (strchr(":. -", c))
790dca
+			continue;
790dca
+		else return 0;
790dca
+
790dca
+		if (hit<32) {
790dca
+			uuid[hit/8] <<= 4;
790dca
+			uuid[hit/8] += n;
790dca
+		}
790dca
+		hit++;
790dca
+	}
790dca
+	if (hit == 32)
790dca
+		return 1;
790dca
+	return 0;
790dca
+}
790dca
-- 
790dca
2.7.5
790dca