2b0cd7cceb
Rebased on top of Martin Wilck's queue of ACKed upstream commits * https://github.com/openSUSE/multipath-tools/tree/upstream-queue * All previous patches have been reordered, with the exception of 0011-libdmmp-Add-support-for-upcoming-json-c-0.14.0.patch which has been replaced with 0029-fix-boolean-value-with-json-c-0.14.patch Modify 0054-RH-add-mpathconf.patch * remove default enable_foreign and property blacklist_exceptions settings, and deal with the builtin default change from 0031-libmultipath-set-enable_foreign-to-NONE-by-default.patch. Fixes bz #1853668 Add 0048-Makefile.inc-trim-extra-information-from-systemd-ver.patch Add 0049-kpartx-fix-Wsign-compare-error.patch * The above two patches have been submitted upstream
109 lines
3.6 KiB
Diff
109 lines
3.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
Date: Tue, 19 May 2020 12:08:41 -0500
|
|
Subject: [PATCH] libmultipath: make sysfs_is_multipathed able to return wwid
|
|
|
|
sysfs_is_multipathed reads the wwid of the dm device holding a path to
|
|
check if its a multipath device. Add code to optinally set pp->wwid to
|
|
that wwid. This will be used by a future patch.
|
|
|
|
Reviewed-by: Martin Wilck <mwilck@suse.com>
|
|
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
---
|
|
libmultipath/sysfs.c | 24 +++++++++++++++++++-----
|
|
libmultipath/sysfs.h | 2 +-
|
|
multipath/main.c | 7 ++++---
|
|
3 files changed, 24 insertions(+), 9 deletions(-)
|
|
|
|
diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
|
|
index 62ec2ed7..12a82d95 100644
|
|
--- a/libmultipath/sysfs.c
|
|
+++ b/libmultipath/sysfs.c
|
|
@@ -295,7 +295,7 @@ static int select_dm_devs(const struct dirent *di)
|
|
return fnmatch("dm-*", di->d_name, FNM_FILE_NAME) == 0;
|
|
}
|
|
|
|
-bool sysfs_is_multipathed(const struct path *pp)
|
|
+bool sysfs_is_multipathed(struct path *pp, bool set_wwid)
|
|
{
|
|
char pathbuf[PATH_MAX];
|
|
struct scandir_result sr;
|
|
@@ -325,7 +325,7 @@ bool sysfs_is_multipathed(const struct path *pp)
|
|
for (i = 0; i < r && !found; i++) {
|
|
long fd;
|
|
int nr;
|
|
- char uuid[6];
|
|
+ char uuid[WWID_SIZE + UUID_PREFIX_LEN];
|
|
|
|
if (safe_snprintf(pathbuf + n, sizeof(pathbuf) - n,
|
|
"/%s/dm/uuid", di[i]->d_name))
|
|
@@ -339,12 +339,26 @@ bool sysfs_is_multipathed(const struct path *pp)
|
|
|
|
pthread_cleanup_push(close_fd, (void *)fd);
|
|
nr = read(fd, uuid, sizeof(uuid));
|
|
- if (nr == sizeof(uuid) && !memcmp(uuid, "mpath-", sizeof(uuid)))
|
|
+ if (nr > (int)UUID_PREFIX_LEN &&
|
|
+ !memcmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN))
|
|
found = true;
|
|
else if (nr < 0) {
|
|
- condlog(1, "%s: error reading from %s: %s",
|
|
- __func__, pathbuf, strerror(errno));
|
|
+ condlog(1, "%s: error reading from %s: %m",
|
|
+ __func__, pathbuf);
|
|
}
|
|
+ if (found && set_wwid) {
|
|
+ nr -= UUID_PREFIX_LEN;
|
|
+ memcpy(pp->wwid, uuid + UUID_PREFIX_LEN, nr);
|
|
+ if (nr == WWID_SIZE) {
|
|
+ condlog(4, "%s: overflow while reading from %s",
|
|
+ __func__, pathbuf);
|
|
+ pp->wwid[0] = '\0';
|
|
+ } else {
|
|
+ pp->wwid[nr] = '\0';
|
|
+ strchop(pp->wwid);
|
|
+ }
|
|
+ }
|
|
+
|
|
pthread_cleanup_pop(1);
|
|
}
|
|
pthread_cleanup_pop(1);
|
|
diff --git a/libmultipath/sysfs.h b/libmultipath/sysfs.h
|
|
index 9ae30b39..72b39ab2 100644
|
|
--- a/libmultipath/sysfs.h
|
|
+++ b/libmultipath/sysfs.h
|
|
@@ -14,5 +14,5 @@ ssize_t sysfs_bin_attr_get_value(struct udev_device *dev, const char *attr_name,
|
|
unsigned char * value, size_t value_len);
|
|
int sysfs_get_size (struct path *pp, unsigned long long * size);
|
|
int sysfs_check_holders(char * check_devt, char * new_devt);
|
|
-bool sysfs_is_multipathed(const struct path *pp);
|
|
+bool sysfs_is_multipathed(struct path *pp, bool set_wwid);
|
|
#endif
|
|
diff --git a/multipath/main.c b/multipath/main.c
|
|
index cf9d2a28..545ead87 100644
|
|
--- a/multipath/main.c
|
|
+++ b/multipath/main.c
|
|
@@ -638,7 +638,8 @@ configure (struct config *conf, enum mpath_cmds cmd,
|
|
* Shortcut for find_multipaths smart:
|
|
* Quick check if path is already multipathed.
|
|
*/
|
|
- if (sysfs_is_multipathed(VECTOR_SLOT(pathvec, 0))) {
|
|
+ if (sysfs_is_multipathed(VECTOR_SLOT(pathvec, 0),
|
|
+ false)) {
|
|
r = RTVL_YES;
|
|
goto print_valid;
|
|
}
|
|
@@ -747,8 +748,8 @@ configure (struct config *conf, enum mpath_cmds cmd,
|
|
/*
|
|
* Check if we raced with multipathd
|
|
*/
|
|
- r = sysfs_is_multipathed(VECTOR_SLOT(pathvec, 0)) ?
|
|
- RTVL_YES : RTVL_NO;
|
|
+ r = sysfs_is_multipathed(VECTOR_SLOT(pathvec, 0),
|
|
+ false) ? RTVL_YES : RTVL_NO;
|
|
}
|
|
goto print_valid;
|
|
}
|
|
--
|
|
2.17.2
|
|
|