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