... and rename it to dm_map_present_by_wwid().

Signed-off-by: Martin Wilck <[email protected]>
---
 libmultipath/devmapper.c | 47 ++++++----------------------------------
 libmultipath/devmapper.h |  2 +-
 libmultipath/valid.c     |  2 +-
 tests/valid.c            | 10 ++++-----
 4 files changed, 14 insertions(+), 47 deletions(-)

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index caa8385..8a0578e 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -1013,49 +1013,16 @@ out:
        return r;
 }
 
-/*
- * Return
- *   1 : map with uuid exists
- *   0 : map with uuid doesn't exist
- *  -1 : error
- */
-int
-dm_map_present_by_uuid(const char *uuid)
+int dm_map_present_by_wwid(const char *wwid)
 {
-       struct dm_task *dmt;
-       struct dm_info info;
-       char prefixed_uuid[WWID_SIZE + UUID_PREFIX_LEN];
-       int r = -1;
+       char tmp[DM_UUID_LEN];
 
-       if (!uuid || uuid[0] == '\0')
-               return 0;
+       if (safe_sprintf(tmp, UUID_PREFIX "%s", wwid))
+               return DMP_ERR;
 
-       if (safe_sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid))
-               goto out;
-
-       if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO)))
-               goto out;
-
-       if (!dm_task_set_uuid(dmt, prefixed_uuid))
-               goto out_task;
-
-       if (!libmp_dm_task_run(dmt)) {
-               dm_log_error(3, DM_DEVICE_INFO, dmt);
-               goto out_task;
-       }
-
-       if (!dm_task_get_info(dmt, &info))
-               goto out_task;
-
-       r = !!info.exists;
-
-out_task:
-       dm_task_destroy(dmt);
-out:
-       if (r < 0)
-               condlog(3, "%s: dm command failed in %s: %s", uuid,
-                       __FUNCTION__, strerror(errno));
-       return r;
+       return libmp_mapinfo(DM_MAP_BY_UUID,
+                            (mapid_t) { .str = tmp },
+                            (mapinfo_t) { .name = NULL });
 }
 
 static int dm_dev_t (const char *mapname, char *dev_t, int len)
diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h
index 0043812..db5c5fd 100644
--- a/libmultipath/devmapper.h
+++ b/libmultipath/devmapper.h
@@ -122,7 +122,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_uuid(const char *uuid);
+int dm_map_present_by_wwid(const char *uuid);
 int dm_get_map(const char *name, unsigned long long *size, char **outparams);
 int dm_get_status(const char *name, char **outstatus);
 
diff --git a/libmultipath/valid.c b/libmultipath/valid.c
index f223778..9267cef 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_uuid(pp->wwid) == 1)
+       if (dm_map_present_by_wwid(pp->wwid) == 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 18a5a7b..a93bbe5 100644
--- a/tests/valid.c
+++ b/tests/valid.c
@@ -189,7 +189,7 @@ int __wrap_check_wwids_file(char *wwid, int write_wwid)
                return -1;
 }
 
-int __wrap_dm_map_present_by_uuid(const char *uuid)
+int __wrap_dm_map_present_by_wwid(const char *uuid)
 {
        int ret = mock_type(int);
        assert_string_equal(uuid, mock_ptr_type(char *));
@@ -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_uuid, 0);
-       will_return(__wrap_dm_map_present_by_uuid, wwid);
+       will_return(__wrap_dm_map_present_by_wwid, 0);
+       will_return(__wrap_dm_map_present_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_uuid, 1);
-       will_return(__wrap_dm_map_present_by_uuid, wwid);
+       will_return(__wrap_dm_map_present_by_wwid, 1);
+       will_return(__wrap_dm_map_present_by_wwid, wwid);
        assert_int_equal(is_path_valid(name, &conf, &pp, true),
                         PATH_IS_VALID);
        assert_string_equal(pp.dev, name);
-- 
2.45.2


Reply via email to