[dm-devel] [RFC PATCH v2 2/3] libmultipath: make sysfs_is_multipathed able to return wwid
Martin Wilck
Martin.Wilck at suse.com
Tue Apr 28 19:21:33 UTC 2020
On Fri, 2020-04-03 at 01:50 -0500, Benjamin Marzinski wrote:
> 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.
>
> Signed-off-by: Benjamin Marzinski <bmarzins at 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);
I would have checked this condition before calling memcpy(), but that's
just a nit.
Reviewed-by: Martin Wilck <mwilck at suse.com>
--
Dr. Martin Wilck <mwilck at suse.com>, Tel. +49 (0)911 74053 2107
SUSE Software Solutions Germany GmbH
HRB 36809, AG Nürnberg GF: Felix
Imendörffer
More information about the dm-devel
mailing list