device-mapper-multipath/0004-libmultipath-add-wrapper-function-around-pgpolicyfn.patch
Benjamin Marzinski 942c9b6ed8 device-mapper-multipath-0.8.2-1
Update Source to upstream version 0.8.2
  * Previoud patches 0001-0017 & 0027 are included in this commit
Rename files
  * Previous patches 0018-0026 & 0028 are not patches 0021-0030
Add 0001-libmultipath-make-vector_foreach_slot_backwards-work.patch
Add 0002-libmultipath-add-marginal-paths-and-groups-infrastru.patch
Add 0003-tests-add-path-grouping-policy-unit-tests.patch
Add 0004-libmultipath-add-wrapper-function-around-pgpolicyfn.patch
Add 0005-tests-update-pgpolicy-tests-to-work-with-group_paths.patch
Add 0006-libmultipath-fix-double-free-in-pgpolicyfn-error-pat.patch
Add 0007-libmultipath-consolidate-group_by_-functions.patch
Add 0008-libmultipath-make-pgpolicyfn-take-a-paths-vector.patch
Add 0009-libmultipath-make-group_paths-handle-marginal-paths.patch
Add 0010-tests-add-tests-for-grouping-marginal-paths.patch
Add 0011-libmultipath-add-marginal_pathgroups-config-option.patch
Add 0012-libmutipath-deprecate-delay_-_checks.patch
Add 0013-multipathd-use-marginal_pathgroups.patch
Add 0014-multipath-update-man-pages.patch
  * The above 13 patches add the marinal_pathgroups option
Add 0015-multipath.conf-add-enable_foreign-parameter.patch
Add 0016-multipath.conf.5-document-foreign-library-support.patch
  * The above 2 patches add the enable_foreign option
Add 0017-mpathpersist-remove-broken-unused-code.patch
Add 0018-libmultipath-EMC-PowerMax-NVMe-device-config.patch
Add 0019-mpathpersist-fix-leaks.patch
Add 0020-libmultipath-fix-mpcontext-initialization.patch
  * The above 20 patches have been submitted upstream
2019-09-11 17:06:10 -05:00

261 lines
6.4 KiB
Diff

From cc1f4c53100ae50e0fba379c40ac8e1fe72c1fb1 Mon Sep 17 00:00:00 2001
From: Benjamin Marzinski <bmarzins@redhat.com>
Date: Tue, 2 Jul 2019 16:28:16 -0500
Subject: [PATCH] libmultipath: add wrapper function around pgpolicyfn
group_paths() is a wrapper around the pgpolicy functions, that pulls out
the common code from the beginning and the end. For this to work,
one_group() needs to change how it sets up the pathgroups vector to work
like the other pgpolicy functions. This does means that the pathgroups
in group_by_prio are now needlessly sorted afterwards. That will be
dealt with in a later patch. Also, since store_pathgroup() is only
called by add_pathgroup(), it doesn't need to exist as a seperate
function.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/configure.c | 2 +-
libmultipath/pgpolicies.c | 83 ++++++++++++++-------------------------
libmultipath/pgpolicies.h | 2 +-
libmultipath/structs.c | 16 ++------
libmultipath/structs.h | 1 -
5 files changed, 35 insertions(+), 69 deletions(-)
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
index b09ef529..3c309d64 100644
--- a/libmultipath/configure.c
+++ b/libmultipath/configure.c
@@ -387,7 +387,7 @@ int setup_map(struct multipath *mpp, char *params, int params_size,
vector_free(mpp->pg);
mpp->pg = NULL;
}
- if (mpp->pgpolicyfn && mpp->pgpolicyfn(mpp))
+ if (group_paths(mpp))
return 1;
/*
diff --git a/libmultipath/pgpolicies.c b/libmultipath/pgpolicies.c
index 660768a4..1b59485c 100644
--- a/libmultipath/pgpolicies.c
+++ b/libmultipath/pgpolicies.c
@@ -84,6 +84,26 @@ sort_pathgroups (struct multipath *mp) {
}
+int group_paths(struct multipath *mp)
+{
+ if (!mp->pg)
+ mp->pg = vector_alloc();
+ if (!mp->pg)
+ return 1;
+
+ if (VECTOR_SIZE(mp->paths) > 0 &&
+ (!mp->pgpolicyfn || mp->pgpolicyfn(mp))) {
+ vector_free(mp->pg);
+ mp->pg = NULL;
+ return 1;
+ }
+
+ sort_pathgroups(mp);
+ vector_free(mp->paths);
+ mp->paths = NULL;
+ return 0;
+}
+
/*
* One path group per unique tgt_node_name present in the path vector
*/
@@ -95,12 +115,6 @@ int group_by_node_name(struct multipath * mp)
struct pathgroup * pgp;
struct path * pp2;
- if (!mp->pg)
- mp->pg = vector_alloc();
-
- if (!mp->pg)
- return 1;
-
/* init the bitmap */
bitmap = (int *)MALLOC(VECTOR_SIZE(mp->paths) * sizeof (int));
@@ -146,9 +160,6 @@ int group_by_node_name(struct multipath * mp)
}
}
FREE(bitmap);
- sort_pathgroups(mp);
- free_pathvec(mp->paths, KEEP_PATHS);
- mp->paths = NULL;
return 0;
out2:
free_pathgroup(pgp, KEEP_PATHS);
@@ -171,12 +182,6 @@ int group_by_serial(struct multipath * mp)
struct pathgroup * pgp;
struct path * pp2;
- if (!mp->pg)
- mp->pg = vector_alloc();
-
- if (!mp->pg)
- return 1;
-
/* init the bitmap */
bitmap = (int *)MALLOC(VECTOR_SIZE(mp->paths) * sizeof (int));
@@ -221,9 +226,6 @@ int group_by_serial(struct multipath * mp)
}
}
FREE(bitmap);
- sort_pathgroups(mp);
- free_pathvec(mp->paths, KEEP_PATHS);
- mp->paths = NULL;
return 0;
out2:
free_pathgroup(pgp, KEEP_PATHS);
@@ -241,12 +243,6 @@ int one_path_per_group(struct multipath *mp)
struct path * pp;
struct pathgroup * pgp;
- if (!mp->pg)
- mp->pg = vector_alloc();
-
- if (!mp->pg)
- return 1;
-
for (i = 0; i < VECTOR_SIZE(mp->paths); i++) {
pp = VECTOR_SLOT(mp->paths, i);
pgp = alloc_pathgroup();
@@ -260,9 +256,6 @@ int one_path_per_group(struct multipath *mp)
if (store_path(pgp->paths, pp))
goto out1;
}
- sort_pathgroups(mp);
- free_pathvec(mp->paths, KEEP_PATHS);
- mp->paths = NULL;
return 0;
out1:
free_pathgroup(pgp, KEEP_PATHS);
@@ -274,32 +267,24 @@ out:
int one_group(struct multipath *mp) /* aka multibus */
{
+ int i;
+ struct path * pp;
struct pathgroup * pgp;
- if (VECTOR_SIZE(mp->paths) < 0)
- return 0;
+ pgp = alloc_pathgroup();
- if (!mp->pg)
- mp->pg = vector_alloc();
+ if (!pgp)
+ goto out;
- if (!mp->pg)
- return 1;
+ if (add_pathgroup(mp, pgp))
+ goto out1;
- if (VECTOR_SIZE(mp->paths) > 0) {
- pgp = alloc_pathgroup();
+ for (i = 0; i < VECTOR_SIZE(mp->paths); i++) {
+ pp = VECTOR_SLOT(mp->paths, i);
- if (!pgp)
+ if (store_path(pgp->paths, pp))
goto out;
-
- vector_free(pgp->paths);
-
- if (add_pathgroup(mp, pgp))
- goto out1;
-
- pgp->paths = mp->paths;
- mp->paths = NULL;
}
-
return 0;
out1:
free_pathgroup(pgp, KEEP_PATHS);
@@ -317,12 +302,6 @@ int group_by_prio(struct multipath *mp)
struct pathgroup * pgp;
vector pathvec = NULL;
- if (!mp->pg)
- mp->pg = vector_alloc();
-
- if (!mp->pg)
- return 1;
-
pathvec = vector_alloc();
if (!pathvec)
goto out;
@@ -387,8 +366,6 @@ int group_by_prio(struct multipath *mp)
}
}
free_pathvec(pathvec, KEEP_PATHS);
- free_pathvec(mp->paths, KEEP_PATHS);
- mp->paths = NULL;
return 0;
out2:
free_pathgroup(pgp, KEEP_PATHS);
diff --git a/libmultipath/pgpolicies.h b/libmultipath/pgpolicies.h
index c0eaa7f4..11834011 100644
--- a/libmultipath/pgpolicies.h
+++ b/libmultipath/pgpolicies.h
@@ -21,7 +21,7 @@ enum iopolicies {
int get_pgpolicy_id(char *);
int get_pgpolicy_name (char *, int, int);
-
+int group_paths(struct multipath *);
/*
* policies
*/
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
index fee899bd..bf7fdd73 100644
--- a/libmultipath/structs.c
+++ b/libmultipath/structs.c
@@ -318,23 +318,13 @@ store_path (vector pathvec, struct path * pp)
return 0;
}
-int
-store_pathgroup (vector pgvec, struct pathgroup * pgp)
+int add_pathgroup(struct multipath *mpp, struct pathgroup *pgp)
{
- if (!vector_alloc_slot(pgvec))
+ if (!vector_alloc_slot(mpp->pg))
return 1;
- vector_set_slot(pgvec, pgp);
-
- return 0;
-}
-
-int add_pathgroup(struct multipath *mpp, struct pathgroup *pgp)
-{
- int ret = store_pathgroup(mpp->pg, pgp);
+ vector_set_slot(mpp->pg, pgp);
- if (ret)
- return ret;
pgp->mpp = mpp;
return 0;
}
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
index 1a3d827b..893074eb 100644
--- a/libmultipath/structs.h
+++ b/libmultipath/structs.h
@@ -445,7 +445,6 @@ int store_adaptergroup(vector adapters, struct adapter_group *agp);
int store_hostgroup(vector hostgroupvec, struct host_group *hgp);
int store_path (vector pathvec, struct path * pp);
-int store_pathgroup (vector pgvec, struct pathgroup * pgp);
int add_pathgroup(struct multipath*, struct pathgroup *);
struct multipath * find_mp_by_alias (const struct _vector *mp, const char *alias);
--
2.17.2