Skip to content

Commit

Permalink
libmultipath: check DM UUID earlier in libmp_mapinfo__
Browse files Browse the repository at this point in the history
Before checking the target details, first check that the device has a
"mpath-" dm uuid prefix. If it doesn't then we can just ignore the
device. This keeps multipath from printing error messages for
non-multipath devices with multiple targets for instance.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
  • Loading branch information
bmarzins authored and mwilck committed Nov 13, 2024
1 parent 9a641bb commit 8c772d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
20 changes: 11 additions & 9 deletions libmultipath/devmapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,16 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma
return DMP_NOT_FOUND;
}

if ((info.name && !(name = dm_task_get_name(dmt)))
|| ((info.uuid || flags & MAPINFO_CHECK_UUID)
&& !(uuid = dm_task_get_uuid(dmt))))
return DMP_ERR;

if (flags & MAPINFO_CHECK_UUID && !is_mpath_uuid(uuid)) {
condlog(3, "%s: UUID mismatch: %s", fname__, uuid);
return DMP_NO_MATCH;
}

if (info.target || info.status || info.size || flags & MAPINFO_TGT_TYPE__) {
if (dm_get_next_target(dmt, NULL, &start, &length,
&target_type, &params) != NULL) {
Expand All @@ -740,18 +750,10 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma
* Check possible error conditions.
* If error is returned, don't touch any output parameters.
*/
if ((info.name && !(name = dm_task_get_name(dmt)))
|| ((info.uuid || flags & MAPINFO_CHECK_UUID)
&& !(uuid = dm_task_get_uuid(dmt)))
|| (info.status && !(tmp_status = strdup(params)))
if ((info.status && !(tmp_status = strdup(params)))
|| (info.target && !tmp_target && !(tmp_target = strdup(params))))
return DMP_ERR;

if (flags & MAPINFO_CHECK_UUID && !is_mpath_uuid(uuid)) {
condlog(3, "%s: UUID mismatch: %s", fname__, uuid);
return DMP_NO_MATCH;
}

if (info.name) {
strlcpy(info.name, name, WWID_SIZE);
condlog(4, "%s: %s: name: \"%s\"", fname__, map_id, info.name);
Expand Down
15 changes: 11 additions & 4 deletions tests/mapinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ static const struct dm_info __attribute__((unused)) MPATH_DMI_01 = {
.minor = 123,
};

static const struct dm_info __attribute__((unused)) MPATH_DMI_02 = {
.exists = 1,
.live_table = 0,
.open_count = 1,
.target_count = 1,
.major = 254,
.minor = 123,
};

static const char MPATH_NAME_01[] = "mpathx";
static const char MPATH_UUID_01[] = "mpath-3600a098038302d414b2b4d4453474f62";
static const char MPATH_TARGET_01[] =
Expand Down Expand Up @@ -928,6 +937,8 @@ static void test_mapinfo_bad_target_type_03(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
will_return(__wrap_dm_task_get_name, MPATH_NAME_01);
will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01);
mock_dm_get_next_target(12345, TGT_PART, MPATH_STATUS_01, NULL);
rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY,
(mapid_t) { .str = "foo", },
Expand Down Expand Up @@ -1090,7 +1101,6 @@ static void test_mapinfo_bad_get_name_01(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL);
will_return(__wrap_dm_task_get_name, NULL);
rc = libmp_mapinfo(DM_MAP_BY_NAME,
(mapid_t) { .str = "foo", },
Expand All @@ -1112,7 +1122,6 @@ static void test_mapinfo_bad_get_uuid_01(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL);
will_return(__wrap_dm_task_get_name, MPATH_NAME_01);
will_return(__wrap_dm_task_get_uuid, NULL);
rc = libmp_mapinfo(DM_MAP_BY_NAME,
Expand Down Expand Up @@ -1162,7 +1171,6 @@ static void test_mapinfo_bad_get_name_02(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL);
will_return(__wrap_dm_task_get_name, NULL);

rc = libmp_mapinfo(DM_MAP_BY_NAME,
Expand Down Expand Up @@ -1195,7 +1203,6 @@ static void test_mapinfo_bad_get_uuid_02(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL);
will_return(__wrap_dm_task_get_name, MPATH_NAME_01);
will_return(__wrap_dm_task_get_uuid, NULL);

Expand Down

0 comments on commit 8c772d3

Please sign in to comment.