libmultipath: get rid of selector "hack" in print.c
authorMartin Wilck <mwilck@suse.com>
Mon, 5 Mar 2018 23:14:47 +0000 (00:14 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 7 Mar 2018 09:38:59 +0000 (10:38 +0100)
By properly linking the path groups with their parent multipath,
we don't need this "hack" any more.

Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
libmultipath/dmparser.c
libmultipath/pgpolicies.c
libmultipath/print.c
libmultipath/structs.c
libmultipath/structs.h

index 027ae98..783c934 100644 (file)
@@ -267,7 +267,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,
                if (!pgp)
                        goto out;
 
-               if (store_pathgroup(mpp->pg, pgp))
+               if (add_pathgroup(mpp, pgp))
                        goto out;
 
                p += get_word(p, &word);
index 4ae4afb..ac2596a 100644 (file)
@@ -120,7 +120,7 @@ int group_by_node_name(struct multipath * mp)
                if (!pgp)
                        goto out1;
 
-               if (store_pathgroup(mp->pg, pgp))
+               if (add_pathgroup(mp, pgp))
                        goto out2;
 
                /* feed the first path */
@@ -196,7 +196,7 @@ int group_by_serial(struct multipath * mp)
                if (!pgp)
                        goto out1;
 
-               if (store_pathgroup(mp->pg, pgp))
+               if (add_pathgroup(mp, pgp))
                        goto out2;
 
                /* feed the first path */
@@ -254,7 +254,7 @@ int one_path_per_group(struct multipath *mp)
                if (!pgp)
                        goto out;
 
-               if (store_pathgroup(mp->pg, pgp))
+               if (add_pathgroup(mp, pgp))
                        goto out1;
 
                if (store_path(pgp->paths, pp))
@@ -293,7 +293,7 @@ int one_group(struct multipath *mp) /* aka multibus */
 
                vector_free(pgp->paths);
 
-               if (store_pathgroup(mp->pg, pgp))
+               if (add_pathgroup(mp, pgp))
                        goto out1;
 
                pgp->paths = mp->paths;
@@ -367,8 +367,9 @@ int group_by_prio(struct multipath *mp)
                if (i < VECTOR_SIZE(mp->pg)) {
                        if (!vector_insert_slot(mp->pg, i, pgp))
                                goto out2;
+                       pgp->mpp = mp;
                } else {
-                       if (store_pathgroup(mp->pg, pgp))
+                       if (add_pathgroup(mp, pgp))
                                goto out2;
                }
 
index 27636c3..8fb5c50 100644 (file)
@@ -476,7 +476,9 @@ snprint_pri (char * buff, size_t len, struct path * pp)
 static int
 snprint_pg_selector (char * buff, size_t len, struct pathgroup * pgp)
 {
-       return snprint_str(buff, len, pgp->selector);
+       const char *s = pgp->mpp->selector;
+
+       return snprint_str(buff, len, s ? s : "");
 }
 
 static int
@@ -1030,7 +1032,6 @@ int snprint_multipath_topology(char *buff, int len, struct multipath *mpp,
 
        vector_foreach_slot (mpp->pg, pgp, j) {
                f=fmt;
-               pgp->selector = mpp->selector; /* hack */
                if (j + 1 < VECTOR_SIZE(mpp->pg)) {
                        strcpy(f, "|-+- " PRINT_PG_INDENT);
                } else
@@ -1122,7 +1123,6 @@ snprint_multipath_fields_json (char * buff, int len,
 
        vector_foreach_slot (mpp->pg, pgp, i) {
 
-               pgp->selector = mpp->selector;
                fwd += snprint_pathgroup(buff + fwd, len - fwd, PRINT_JSON_GROUP, pgp);
                if (fwd >= len)
                        return fwd;
index 4caad2a..1ade1a6 100644 (file)
@@ -318,6 +318,16 @@ store_pathgroup (vector pgvec, struct pathgroup * pgp)
        return 0;
 }
 
+int add_pathgroup(struct multipath *mpp, struct pathgroup *pgp)
+{
+       int ret = store_pathgroup(mpp->pg, pgp);
+
+       if (ret)
+               return ret;
+       pgp->mpp = mpp;
+       return 0;
+}
+
 int
 store_hostgroup(vector hostgroupvec, struct host_group * hgp)
 {
index b951c7b..71b37cc 100644 (file)
@@ -340,7 +340,7 @@ struct pathgroup {
        int priority;
        int enabled_paths;
        vector paths;
-       char * selector;
+       struct multipath *mpp;
 };
 
 struct adapter_group {
@@ -379,6 +379,7 @@ 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 (vector mp, const char * alias);
 struct multipath * find_mp_by_wwid (vector mp, char * wwid);