add arguments to dm_map_present_by_wwid() to allow optionally fetching
the device name and minor number for the devices found by WWID.  These
will be used by a later patch. Since it can now also be used to get the
name and minor number of a device from its WWID, rename it to
dm_find_map_by_wwid()

Signed-off-by: Benjamin Marzinski <[email protected]>
---
 libmultipath/devmapper.c | 16 ++++++++++++----
 libmultipath/devmapper.h |  2 +-
 libmultipath/valid.c     |  2 +-
 tests/valid.c            | 12 ++++++------
 4 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index bbbadeee..60d786c6 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -872,16 +872,24 @@ int dm_is_mpath(const char *name)
        }
 }
 
-int dm_map_present_by_wwid(const char *wwid)
+/* if name is non-NULL, it must point to an array of WWID_SIZE bytes */
+int dm_find_map_by_wwid(const char *wwid, char *name, int *minor)
 {
        char tmp[DM_UUID_LEN];
+       struct dm_info dmi;
+       int rc;
 
        if (safe_sprintf(tmp, UUID_PREFIX "%s", wwid))
                return DMP_ERR;
 
-       return libmp_mapinfo(DM_MAP_BY_UUID,
-                            (mapid_t) { .str = tmp },
-                            (mapinfo_t) { .name = NULL });
+       rc = libmp_mapinfo(DM_MAP_BY_UUID,
+                          (mapid_t) { .str = tmp },
+                          (mapinfo_t) { .name = name,
+                                        .dmi = minor ? &dmi : NULL });
+       if (rc == DMP_OK && minor)
+               *minor = dmi.minor;
+
+       return rc;
 }
 
 static int dm_dev_t (const char *mapname, char *dev_t, int len)
diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h
index c28991fb..1de694c9 100644
--- a/libmultipath/devmapper.h
+++ b/libmultipath/devmapper.h
@@ -132,7 +132,7 @@ int dm_simplecmd_flush (int task, const char *name, 
uint16_t udev_flags);
 int dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags);
 int dm_addmap_create (struct multipath *mpp, char *params);
 int dm_addmap_reload (struct multipath *mpp, char *params, int flush);
-int dm_map_present_by_wwid(const char *uuid);
+int dm_find_map_by_wwid(const char *wwid, char *name, int *minor);
 
 enum {
        DM_IS_MPATH_NO,
diff --git a/libmultipath/valid.c b/libmultipath/valid.c
index 9267cef9..b7e0cc9b 100644
--- a/libmultipath/valid.c
+++ b/libmultipath/valid.c
@@ -360,7 +360,7 @@ is_path_valid(const char *name, struct config *conf, struct 
path *pp,
        if (check_wwids_file(pp->wwid, 0) == 0)
                return PATH_IS_VALID_NO_CHECK;
 
-       if (dm_map_present_by_wwid(pp->wwid) == DMP_OK)
+       if (dm_find_map_by_wwid(pp->wwid, NULL, NULL) == DMP_OK)
                return PATH_IS_VALID;
 
        /* all these act like FIND_MULTIPATHS_STRICT for finding if a
diff --git a/tests/valid.c b/tests/valid.c
index a93bbe50..d9325f8b 100644
--- a/tests/valid.c
+++ b/tests/valid.c
@@ -189,10 +189,10 @@ int __wrap_check_wwids_file(char *wwid, int write_wwid)
                return -1;
 }
 
-int __wrap_dm_map_present_by_wwid(const char *uuid)
+int __wrap_dm_find_map_by_wwid(const char *wwid, char *name, int *minor)
 {
        int ret = mock_type(int);
-       assert_string_equal(uuid, mock_ptr_type(char *));
+       assert_string_equal(wwid, mock_ptr_type(char *));
        return ret;
 }
 
@@ -271,8 +271,8 @@ static void setup_passing(char *name, char *wwid, unsigned 
int check_multipathd,
        will_return(__wrap_check_wwids_file, wwid);
        if (stage == STAGE_CHECK_WWIDS)
                return;
-       will_return(__wrap_dm_map_present_by_wwid, 0);
-       will_return(__wrap_dm_map_present_by_wwid, wwid);
+       will_return(__wrap_dm_find_map_by_wwid, 0);
+       will_return(__wrap_dm_find_map_by_wwid, wwid);
 }
 
 static void test_bad_arguments(void **state)
@@ -516,8 +516,8 @@ static void test_check_uuid_present(void **state)
        memset(&pp, 0, sizeof(pp));
        conf.find_multipaths = FIND_MULTIPATHS_STRICT;
        setup_passing(name, wwid, CHECK_MPATHD_RUNNING, STAGE_CHECK_WWIDS);
-       will_return(__wrap_dm_map_present_by_wwid, 1);
-       will_return(__wrap_dm_map_present_by_wwid, wwid);
+       will_return(__wrap_dm_find_map_by_wwid, 1);
+       will_return(__wrap_dm_find_map_by_wwid, wwid);
        assert_int_equal(is_path_valid(name, &conf, &pp, true),
                         PATH_IS_VALID);
        assert_string_equal(pp.dev, name);
-- 
2.45.0


Reply via email to