add arguments to dm_map_present_by_wwid() to allow optionally fetching the device name and dm info 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 dm info of a device from its WWID, rename it to dm_find_map_by_wwid() Signed-off-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> --- libmultipath/devmapper.c | 5 +++-- libmultipath/devmapper.h | 2 +- libmultipath/valid.c | 2 +- tests/valid.c | 13 +++++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3d256d38..9af0a80e 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -874,7 +874,8 @@ 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, struct dm_info *dmi) { char tmp[DM_UUID_LEN]; @@ -883,7 +884,7 @@ int dm_map_present_by_wwid(const char *wwid) return libmp_mapinfo(DM_MAP_BY_UUID, (mapid_t) { .str = tmp }, - (mapinfo_t) { .name = NULL }); + (mapinfo_t) { .name = name, .dmi = dmi }); } static int dm_dev_t (const char *mapname, char *dev_t, int len) diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index f6d0017e..a26dc1e5 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, struct dm_info *dmi); 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..ecaeb467 100644 --- a/tests/valid.c +++ b/tests/valid.c @@ -189,10 +189,11 @@ 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, + struct dm_info *dmi) { 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 +272,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 +517,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