|
|
7b12b5 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
7b12b5 |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
7b12b5 |
Date: Tue, 23 Jun 2020 22:17:31 -0500
|
|
|
7b12b5 |
Subject: [PATCH] libmultipath: make dm_get_map/status return codes symbolic
|
|
|
7b12b5 |
|
|
|
7b12b5 |
dm_get_map() and dm_get_status() now use symbolic return codes. They
|
|
|
7b12b5 |
also differentiate between failing to get information from device-mapper
|
|
|
7b12b5 |
and not finding the requested device. These symboilc return codes are
|
|
|
7b12b5 |
also used by update_multipath_* functions.
|
|
|
7b12b5 |
|
|
|
7b12b5 |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
7b12b5 |
---
|
|
|
7b12b5 |
libmultipath/devmapper.c | 51 +++++++++++++++++++++++++-------------
|
|
|
7b12b5 |
libmultipath/devmapper.h | 6 +++++
|
|
|
7b12b5 |
libmultipath/structs_vec.c | 45 +++++++++++++++++++--------------
|
|
|
7b12b5 |
multipathd/main.c | 12 ++++-----
|
|
|
7b12b5 |
4 files changed, 72 insertions(+), 42 deletions(-)
|
|
|
7b12b5 |
|
|
|
7b12b5 |
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
|
|
|
96a22b |
index 13a1cf53..f6204e5f 100644
|
|
|
7b12b5 |
--- a/libmultipath/devmapper.c
|
|
|
7b12b5 |
+++ b/libmultipath/devmapper.c
|
|
|
96a22b |
@@ -525,36 +525,43 @@ int dm_map_present(const char * str)
|
|
|
7b12b5 |
|
|
|
7b12b5 |
int dm_get_map(const char *name, unsigned long long *size, char *outparams)
|
|
|
7b12b5 |
{
|
|
|
7b12b5 |
- int r = 1;
|
|
|
7b12b5 |
+ int r = DMP_ERR;
|
|
|
7b12b5 |
struct dm_task *dmt;
|
|
|
7b12b5 |
uint64_t start, length;
|
|
|
7b12b5 |
char *target_type = NULL;
|
|
|
7b12b5 |
char *params = NULL;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE)))
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!dm_task_set_name(dmt, name))
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
dm_task_no_open_count(dmt);
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (!dm_task_run(dmt))
|
|
|
7b12b5 |
+ errno = 0;
|
|
|
7b12b5 |
+ if (!dm_task_run(dmt)) {
|
|
|
7b12b5 |
+ if (dm_task_get_errno(dmt) == ENXIO)
|
|
|
7b12b5 |
+ r = DMP_NOT_FOUND;
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
+ }
|
|
|
7b12b5 |
|
|
|
7b12b5 |
+ r = DMP_NOT_FOUND;
|
|
|
7b12b5 |
/* Fetch 1st target */
|
|
|
7b12b5 |
- dm_get_next_target(dmt, NULL, &start, &length,
|
|
|
7b12b5 |
- &target_type, ¶ms);
|
|
|
7b12b5 |
+ if (dm_get_next_target(dmt, NULL, &start, &length,
|
|
|
7b12b5 |
+ &target_type, ¶ms) != NULL)
|
|
|
7b12b5 |
+ /* more than one target */
|
|
|
7b12b5 |
+ goto out;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (size)
|
|
|
7b12b5 |
*size = length;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!outparams) {
|
|
|
7b12b5 |
- r = 0;
|
|
|
7b12b5 |
+ r = DMP_OK;
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
if (snprintf(outparams, PARAMS_SIZE, "%s", params) <= PARAMS_SIZE)
|
|
|
7b12b5 |
- r = 0;
|
|
|
7b12b5 |
+ r = DMP_OK;
|
|
|
7b12b5 |
out:
|
|
|
7b12b5 |
dm_task_destroy(dmt);
|
|
|
7b12b5 |
return r;
|
|
|
96a22b |
@@ -628,35 +635,45 @@ is_mpath_part(const char *part_name, const char *map_name)
|
|
|
7b12b5 |
|
|
|
7b12b5 |
int dm_get_status(const char *name, char *outstatus)
|
|
|
7b12b5 |
{
|
|
|
7b12b5 |
- int r = 1;
|
|
|
7b12b5 |
+ int r = DMP_ERR;
|
|
|
7b12b5 |
struct dm_task *dmt;
|
|
|
7b12b5 |
uint64_t start, length;
|
|
|
7b12b5 |
char *target_type = NULL;
|
|
|
7b12b5 |
char *status = NULL;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!(dmt = libmp_dm_task_create(DM_DEVICE_STATUS)))
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!dm_task_set_name(dmt, name))
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
dm_task_no_open_count(dmt);
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (!dm_task_run(dmt))
|
|
|
7b12b5 |
+ errno = 0;
|
|
|
7b12b5 |
+ if (!dm_task_run(dmt)) {
|
|
|
7b12b5 |
+ if (dm_task_get_errno(dmt) == ENXIO)
|
|
|
7b12b5 |
+ r = DMP_NOT_FOUND;
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
+ }
|
|
|
7b12b5 |
|
|
|
7b12b5 |
+ r = DMP_NOT_FOUND;
|
|
|
7b12b5 |
/* Fetch 1st target */
|
|
|
7b12b5 |
- dm_get_next_target(dmt, NULL, &start, &length,
|
|
|
7b12b5 |
- &target_type, &status);
|
|
|
7b12b5 |
+ if (dm_get_next_target(dmt, NULL, &start, &length,
|
|
|
7b12b5 |
+ &target_type, &status) != NULL)
|
|
|
7b12b5 |
+ goto out;
|
|
|
7b12b5 |
+
|
|
|
7b12b5 |
+ if (!target_type || strcmp(target_type, TGT_MPATH) != 0)
|
|
|
7b12b5 |
+ goto out;
|
|
|
7b12b5 |
+
|
|
|
7b12b5 |
if (!status) {
|
|
|
7b12b5 |
condlog(2, "get null status.");
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (snprintf(outstatus, PARAMS_SIZE, "%s", status) <= PARAMS_SIZE)
|
|
|
7b12b5 |
- r = 0;
|
|
|
7b12b5 |
+ r = DMP_OK;
|
|
|
7b12b5 |
out:
|
|
|
7b12b5 |
- if (r)
|
|
|
7b12b5 |
+ if (r != DMP_OK)
|
|
|
7b12b5 |
condlog(0, "%s: error getting map status string", name);
|
|
|
7b12b5 |
|
|
|
7b12b5 |
dm_task_destroy(dmt);
|
|
|
96a22b |
@@ -866,7 +883,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,
|
|
|
7b12b5 |
return 1;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (need_suspend &&
|
|
|
7b12b5 |
- !dm_get_map(mapname, &mapsize, params) &&
|
|
|
7b12b5 |
+ dm_get_map(mapname, &mapsize, params) == DMP_OK &&
|
|
|
7b12b5 |
strstr(params, "queue_if_no_path")) {
|
|
|
7b12b5 |
if (!dm_queue_if_no_path(mapname, 0))
|
|
|
7b12b5 |
queue_if_no_path = 1;
|
|
|
96a22b |
@@ -1075,7 +1092,7 @@ struct multipath *dm_get_multipath(const char *name)
|
|
|
7b12b5 |
if (!mpp->alias)
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (dm_get_map(name, &mpp->size, NULL))
|
|
|
7b12b5 |
+ if (dm_get_map(name, &mpp->size, NULL) != DMP_OK)
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
dm_get_uuid(name, mpp->wwid, WWID_SIZE);
|
|
|
96a22b |
@@ -1259,7 +1276,7 @@ do_foreach_partmaps (const char * mapname,
|
|
|
7b12b5 |
/*
|
|
|
7b12b5 |
* and we can fetch the map table from the kernel
|
|
|
7b12b5 |
*/
|
|
|
7b12b5 |
- !dm_get_map(names->name, &size, ¶ms[0]) &&
|
|
|
7b12b5 |
+ dm_get_map(names->name, &size, ¶ms[0]) == DMP_OK &&
|
|
|
7b12b5 |
|
|
|
7b12b5 |
/*
|
|
|
7b12b5 |
* and the table maps over the multipath map
|
|
|
7b12b5 |
diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h
|
|
|
7b12b5 |
index 7557a86b..adb55000 100644
|
|
|
7b12b5 |
--- a/libmultipath/devmapper.h
|
|
|
7b12b5 |
+++ b/libmultipath/devmapper.h
|
|
|
7b12b5 |
@@ -27,6 +27,12 @@
|
|
|
7b12b5 |
#define UUID_PREFIX "mpath-"
|
|
|
7b12b5 |
#define UUID_PREFIX_LEN (sizeof(UUID_PREFIX) - 1)
|
|
|
7b12b5 |
|
|
|
7b12b5 |
+enum {
|
|
|
7b12b5 |
+ DMP_ERR,
|
|
|
7b12b5 |
+ DMP_OK,
|
|
|
7b12b5 |
+ DMP_NOT_FOUND,
|
|
|
7b12b5 |
+};
|
|
|
7b12b5 |
+
|
|
|
7b12b5 |
void dm_init(int verbosity);
|
|
|
7b12b5 |
void libmp_dm_init(void);
|
|
|
7b12b5 |
void libmp_udev_set_sync_support(int on);
|
|
|
7b12b5 |
diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c
|
|
|
96a22b |
index 077f2e42..8137ea21 100644
|
|
|
7b12b5 |
--- a/libmultipath/structs_vec.c
|
|
|
7b12b5 |
+++ b/libmultipath/structs_vec.c
|
|
|
7b12b5 |
@@ -196,43 +196,47 @@ extract_hwe_from_path(struct multipath * mpp)
|
|
|
7b12b5 |
int
|
|
|
7b12b5 |
update_multipath_table (struct multipath *mpp, vector pathvec, int is_daemon)
|
|
|
7b12b5 |
{
|
|
|
7b12b5 |
+ int r = DMP_ERR;
|
|
|
7b12b5 |
char params[PARAMS_SIZE] = {0};
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!mpp)
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (dm_get_map(mpp->alias, &mpp->size, params)) {
|
|
|
7b12b5 |
- condlog(3, "%s: cannot get map", mpp->alias);
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ r = dm_get_map(mpp->alias, &mpp->size, params);
|
|
|
7b12b5 |
+ if (r != DMP_OK) {
|
|
|
7b12b5 |
+ condlog(3, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting table" : "map not present");
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (disassemble_map(pathvec, params, mpp, is_daemon)) {
|
|
|
7b12b5 |
condlog(3, "%s: cannot disassemble map", mpp->alias);
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ return DMP_ERR;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- return 0;
|
|
|
7b12b5 |
+ return DMP_OK;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
7b12b5 |
int
|
|
|
7b12b5 |
update_multipath_status (struct multipath *mpp)
|
|
|
7b12b5 |
{
|
|
|
7b12b5 |
+ int r = DMP_ERR;
|
|
|
7b12b5 |
char status[PARAMS_SIZE] = {0};
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!mpp)
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (dm_get_status(mpp->alias, status)) {
|
|
|
7b12b5 |
- condlog(3, "%s: cannot get status", mpp->alias);
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ r = dm_get_status(mpp->alias, status);
|
|
|
7b12b5 |
+ if (r != DMP_OK) {
|
|
|
7b12b5 |
+ condlog(3, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting status" : "map not present");
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (disassemble_status(status, mpp)) {
|
|
|
7b12b5 |
condlog(3, "%s: cannot disassemble status", mpp->alias);
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ return DMP_ERR;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- return 0;
|
|
|
7b12b5 |
+ return DMP_OK;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
7b12b5 |
void sync_paths(struct multipath *mpp, vector pathvec)
|
|
|
7b12b5 |
@@ -264,10 +268,10 @@ int
|
|
|
7b12b5 |
update_multipath_strings(struct multipath *mpp, vector pathvec, int is_daemon)
|
|
|
7b12b5 |
{
|
|
|
7b12b5 |
struct pathgroup *pgp;
|
|
|
7b12b5 |
- int i;
|
|
|
7b12b5 |
+ int i, r = DMP_ERR;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!mpp)
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
update_mpp_paths(mpp, pathvec);
|
|
|
7b12b5 |
condlog(4, "%s: %s", mpp->alias, __FUNCTION__);
|
|
|
7b12b5 |
@@ -276,18 +280,21 @@ update_multipath_strings(struct multipath *mpp, vector pathvec, int is_daemon)
|
|
|
7b12b5 |
free_pgvec(mpp->pg, KEEP_PATHS);
|
|
|
7b12b5 |
mpp->pg = NULL;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (update_multipath_table(mpp, pathvec, is_daemon))
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ r = update_multipath_table(mpp, pathvec, is_daemon);
|
|
|
7b12b5 |
+ if (r != DMP_OK)
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
+
|
|
|
7b12b5 |
sync_paths(mpp, pathvec);
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (update_multipath_status(mpp))
|
|
|
7b12b5 |
- return 1;
|
|
|
7b12b5 |
+ r = update_multipath_status(mpp);
|
|
|
7b12b5 |
+ if (r != DMP_OK)
|
|
|
7b12b5 |
+ return r;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
vector_foreach_slot(mpp->pg, pgp, i)
|
|
|
7b12b5 |
if (pgp->paths)
|
|
|
7b12b5 |
path_group_prio_update(pgp);
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- return 0;
|
|
|
7b12b5 |
+ return DMP_OK;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
96a22b |
static void enter_recovery_mode(struct multipath *mpp)
|
|
|
7b12b5 |
diff --git a/multipathd/main.c b/multipathd/main.c
|
|
|
96a22b |
index 6b7db2c0..e3427d3d 100644
|
|
|
7b12b5 |
--- a/multipathd/main.c
|
|
|
7b12b5 |
+++ b/multipathd/main.c
|
|
|
96a22b |
@@ -414,7 +414,7 @@ int __setup_multipath(struct vectors *vecs, struct multipath *mpp,
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
}
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (update_multipath_strings(mpp, vecs->pathvec, 1)) {
|
|
|
7b12b5 |
+ if (update_multipath_strings(mpp, vecs->pathvec, 1) != DMP_OK) {
|
|
|
7b12b5 |
condlog(0, "%s: failed to setup multipath", mpp->alias);
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
}
|
|
|
96a22b |
@@ -553,9 +553,9 @@ add_map_without_path (struct vectors *vecs, const char *alias)
|
|
|
7b12b5 |
mpp->mpe = find_mpe(conf->mptable, mpp->wwid);
|
|
|
7b12b5 |
put_multipath_config(conf);
|
|
|
7b12b5 |
|
|
|
7b12b5 |
- if (update_multipath_table(mpp, vecs->pathvec, 1))
|
|
|
7b12b5 |
+ if (update_multipath_table(mpp, vecs->pathvec, 1) != DMP_OK)
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
- if (update_multipath_status(mpp))
|
|
|
7b12b5 |
+ if (update_multipath_status(mpp) != DMP_OK)
|
|
|
7b12b5 |
goto out;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
if (!vector_alloc_slot(vecs->mpvec))
|
|
|
96a22b |
@@ -1346,8 +1346,8 @@ map_discovery (struct vectors * vecs)
|
|
|
7b12b5 |
return 1;
|
|
|
7b12b5 |
|
|
|
7b12b5 |
vector_foreach_slot (vecs->mpvec, mpp, i)
|
|
|
7b12b5 |
- if (update_multipath_table(mpp, vecs->pathvec, 1) ||
|
|
|
7b12b5 |
- update_multipath_status(mpp)) {
|
|
|
7b12b5 |
+ if (update_multipath_table(mpp, vecs->pathvec, 1) != DMP_OK ||
|
|
|
7b12b5 |
+ update_multipath_status(mpp) != DMP_OK) {
|
|
|
7b12b5 |
remove_map(mpp, vecs, 1);
|
|
|
7b12b5 |
i--;
|
|
|
7b12b5 |
}
|
|
|
96a22b |
@@ -2087,7 +2087,7 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks)
|
|
|
7b12b5 |
/*
|
|
|
7b12b5 |
* Synchronize with kernel state
|
|
|
7b12b5 |
*/
|
|
|
7b12b5 |
- if (update_multipath_strings(pp->mpp, vecs->pathvec, 1)) {
|
|
|
7b12b5 |
+ if (update_multipath_strings(pp->mpp, vecs->pathvec, 1) != DMP_OK) {
|
|
|
7b12b5 |
condlog(1, "%s: Could not synchronize with kernel state",
|
|
|
7b12b5 |
pp->dev);
|
|
|
7b12b5 |
pp->dmstate = PSTATE_UNDEF;
|
|
|
7b12b5 |
--
|
|
|
7b12b5 |
2.17.2
|
|
|
7b12b5 |
|