[multipath] consider the presence of conflicting empty maps
authorChristophe Varoqui <root@xa-s05.(none)>
Mon, 10 Oct 2005 13:28:15 +0000 (15:28 +0200)
committerChristophe Varoqui <root@xa-s05.(none)>
Mon, 10 Oct 2005 13:28:15 +0000 (15:28 +0200)
Drop the conflicting map, then create the new one.
The daemon catchs up through its uevent handlers.

libmultipath/devmapper.c
multipath/main.c

index d941e22..ca2d25d 100644 (file)
@@ -278,7 +278,9 @@ dm_type(char * name, char * type)
        next = dm_get_next_target(dmt, next, &start, &length,
                                  &target_type, &params);
 
-       if (target_type && !strcmp(target_type, type))
+       if (!target_type)
+               r = -1;
+       else if (!strcmp(target_type, type))
                r = 1;
 
 out:
@@ -373,7 +375,7 @@ dm_flush_map (char * mapname, char * type)
        if (!dm_map_present(mapname))
                return 0;
 
-       if (!dm_type(mapname, type))
+       if (type && dm_type(mapname, type) <= 0)
                return 1;
 
        if (dm_remove_partmaps(mapname))
@@ -586,6 +588,7 @@ dm_get_maps (vector mp, char * type)
 {
        struct multipath * mpp;
        int r = 1;
+       int info;
        struct dm_task *dmt;
        struct dm_names *names;
        unsigned next = 0;
@@ -610,12 +613,22 @@ dm_get_maps (vector mp, char * type)
        }
 
        do {
-               if (dm_type(names->name, type)) {
-                       mpp = alloc_multipath();
+               info = dm_type(names->name, type);
 
-                       if (!mpp)
-                               goto out;
+               if (!info)
+                       goto next;
 
+               mpp = alloc_multipath();
+
+               if (!mpp)
+                       goto out;
+
+               mpp->alias = STRDUP(names->name);
+
+               if (!mpp->alias)
+                       goto out1;
+
+               if (info > 0) {
                        if (dm_get_map(names->name, &mpp->size, mpp->params))
                                goto out1;
 
@@ -623,20 +636,14 @@ dm_get_maps (vector mp, char * type)
                                goto out1;
 
                        dm_get_uuid(names->name, mpp->wwid);
+               }
 
-                       mpp->alias = MALLOC(strlen(names->name) + 1);
-
-                       if (!mpp->alias)
-                               goto out1;
-
-                       strncat(mpp->alias, names->name, strlen(names->name));
+               if (!vector_alloc_slot(mp))
+                       goto out1;
 
-                       if (!vector_alloc_slot(mp))
-                               goto out1;
-                       
-                       vector_set_slot(mp, mpp);
-                       mpp = NULL;
-               }
+               vector_set_slot(mp, mpp);
+               mpp = NULL;
+next:
                 next = names->next;
                 names = (void *) names + next;
        } while (next);
index 652025a..8708668 100644 (file)
@@ -506,6 +506,15 @@ select_action (struct multipath * mpp, vector curmp)
                mpp->action = ACT_CREATE;
                return;
        }
+
+       if (!find_mp_by_wwid(curmp, mpp->wwid)) {
+               dm_flush_map(mpp->alias, NULL);
+               strncat(cmpp->wwid, mpp->wwid, WWID_SIZE);
+               drop_multipath(curmp, cmpp->wwid, KEEP_PATHS);
+               mpp->action = ACT_CREATE;
+               return;
+       }
+               
        if (pathcount(mpp, PATH_UP) == 0) {
                condlog(3, "no good path");
                mpp->action = ACT_NOTHING;
@@ -560,7 +569,13 @@ reinstate_paths (struct multipath * mpp)
        struct pathgroup * pgp;
        struct path * pp;
 
+       if (!mpp->pg)
+               return 0;
+
        vector_foreach_slot (mpp->pg, pgp, i) {
+               if (!pgp->paths)
+                       continue;
+
                vector_foreach_slot (pgp->paths, pp, j) {
                        if (pp->state != PATH_UP &&
                            (pgp->status == PGSTATE_DISABLED ||
@@ -635,10 +650,17 @@ deadmap (struct multipath * mpp)
        struct pathgroup * pgp;
        struct path * pp;
 
-       vector_foreach_slot (mpp->pg, pgp, i)
+       if (!mpp->pg)
+               return 1;
+
+       vector_foreach_slot (mpp->pg, pgp, i) {
+               if (!pgp->paths)
+                       continue;
+
                vector_foreach_slot (pgp->paths, pp, j)
                        if (strlen(pp->dev))
                                return 0; /* alive */
+       }
        
        return 1; /* dead */
 }
@@ -788,7 +810,13 @@ update_paths (struct multipath * mpp)
        struct pathgroup * pgp;
        struct path * pp;
 
+       if (!mpp->pg)
+               return 0;
+
        vector_foreach_slot (mpp->pg, pgp, i) {
+               if (!pgp->paths)
+                       continue;
+
                vector_foreach_slot (pgp->paths, pp, j) {
                        if (!strlen(pp->dev)) {
                                if (devt2devname(pp->dev_t, pp->dev)) {