[libmultipath] renaming a map triggers its partitions renames
authorChristophe Varoqui <root@xa-s05.(none)>
Tue, 17 Jan 2006 13:52:11 +0000 (14:52 +0100)
committerChristophe Varoqui <root@xa-s05.(none)>
Tue, 17 Jan 2006 13:52:11 +0000 (14:52 +0100)
libmultipath/devmapper.c

index 7726898..13ad5d2 100644 (file)
@@ -846,11 +846,88 @@ out:
 }
 
 int
+dm_rename_partmaps (char * old, char * new)
+{
+       struct dm_task *dmt;
+       struct dm_names *names;
+       unsigned next = 0;
+       char buff[PARAMS_SIZE];
+       unsigned long long size;
+       char dev_t[32];
+       int r = 1;
+
+       if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
+               return 1;
+
+       dm_task_no_open_count(dmt);
+
+       if (!dm_task_run(dmt))
+               goto out;
+
+       if (!(names = dm_task_get_names(dmt)))
+               goto out;
+
+       if (!names->dev) {
+               r = 0; /* this is perfectly valid */
+               goto out;
+       }
+
+       if (dm_dev_t(old, &dev_t[0], 32))
+               goto out;
+
+       do {
+               if (
+                   /*
+                    * if devmap target is "linear"
+                    */
+                   (dm_type(names->name, "linear") > 0) &&
+
+                   /*
+                    * and the multipath mapname and the part mapname start
+                    * the same
+                    */
+                   !strncmp(names->name, old, strlen(old)) &&
+
+                   /*
+                    * and we can fetch the map table from the kernel
+                    */
+                   !dm_get_map(names->name, &size, &buff[0]) &&
+
+                   /*
+                    * and the table maps over the multipath map
+                    */
+                   strstr(buff, dev_t)
+                  ) {
+                               /*
+                                * then it's a kpartx generated partition.
+                                * Rename it.
+                                */
+                               snprintf(buff, PARAMS_SIZE, "%s%s",
+                                        new, names->name + strlen(old));
+                               dm_rename(names->name, buff);
+                               condlog(4, "partition map %s renamed",
+                                       names->name);
+                  }
+
+               next = names->next;
+               names = (void *) names + next;
+       } while (next);
+
+       r = 0;
+out:
+       dm_task_destroy (dmt);
+       return r;
+}
+
+int
 dm_rename (char * old, char * new)
 {
        int r = 0;
        struct dm_task *dmt;
 
+       if (dm_rename_partmaps(old, new))
+               return r;
+
        if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
                return r;