]> sourceware.org Git - lvm2.git/commitdiff
Fix restart of clvmd using -S switch
authorMilan Broz <mbroz@redhat.com>
Fri, 4 Jun 2010 12:59:30 +0000 (12:59 +0000)
committerMilan Broz <mbroz@redhat.com>
Fri, 4 Jun 2010 12:59:30 +0000 (12:59 +0000)
 - allocate environment dynamically (still missing some limit?)
 - try to recover, if destroy failed (do not destroy lvm here) and free memory
 - check strdup() return codes
 - report failure to log
 - do not print NULL in exclusive lock loop

WHATS_NEW
daemons/clvmd/clvmd-command.c
daemons/clvmd/lvm-functions.c

index e767e0eb133f20a6b3d840e6244f394d0e98d9e7..593d562266b299a434fc4fbfd9d0ee3dd8eb0212 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.67 -
 ===============================
+  Handle failed restart of clvmd using -S switch properly.
   Fix clvmd initscript restart command to start clvmd if not yet running.
   Use absolute paths for clvmd restart.
   Require partial option in lvchange --refresh for partial LVs.
index 180f8091cf7cb432961cd666fce0a6aefce3d1d6..83d03ef7252604641df39adc18a8efa4fc2880c3 100644 (file)
@@ -361,33 +361,51 @@ void cmd_client_cleanup(struct local_client *client)
 
 static int restart_clvmd(void)
 {
-       char *argv[1024];
-       int argc = 1;
+       char **argv = NULL;
+       char *debug_arg = NULL, *lv_name;
+       int i, argc = 0, max_locks = 0;
        struct dm_hash_node *hn = NULL;
-       char *lv_name;
 
        DEBUGLOG("clvmd restart requested\n");
 
+       /* Count exclusively-open LVs */
+       hn = NULL;
+       do {
+               hn = get_next_excl_lock(hn, &lv_name);
+               if (lv_name)
+                       max_locks++;
+       } while (hn && *lv_name);
+
+       /* clvmd + locks (-E uuid) + debug (-d X) + NULL */
+       argv = malloc((max_locks * 2 + 4) * sizeof(*argv));
+       if (!argv)
+               goto_out;
+
        /*
         * Build the command-line
         */
-       /* FIXME missing strdup error checks */
-       argv[0] = strdup("clvmd");
+       argv[argc++] = strdup("clvmd");
+       if (!argv[0])
+               goto_out;
 
        /* Propogate debug options */
        if (debug) {
-               char debug_level[16];
-
-               sprintf(debug_level, "-d%d", debug);
-               argv[argc++] = strdup(debug_level);
+               if (!(debug_arg = malloc(16)) ||
+                   snprintf(debug_arg, 16, "-d%d", (int)debug) < 0)
+                       goto_out;
+               argv[argc++] = debug_arg;
        }
 
        /* Now add the exclusively-open LVs */
        do {
                hn = get_next_excl_lock(hn, &lv_name);
                if (lv_name) {
-                       argv[argc++] = strdup("-E");
-                       argv[argc++] = strdup(lv_name);
+                       argv[argc] = strdup("-E");
+                       if (!argv[argc++])
+                               goto_out;
+                       argv[argc] = strdup(lv_name);
+                       if (!argv[argc++])
+                               goto_out;
 
                        DEBUGLOG("excl lock: %s\n", lv_name);
                        hn = get_next_excl_lock(hn, &lv_name);
@@ -395,13 +413,16 @@ static int restart_clvmd(void)
        } while (hn && *lv_name);
        argv[argc++] = NULL;
 
-       /* Tidy up */
-       destroy_lvm();
-
        /* Exec new clvmd */
        /* NOTE: This will fail when downgrading! */
        execve(CLVMD_PATH, argv, NULL);
-
+out:
        /* We failed */
+       DEBUGLOG("Restart of clvmd failed.\n");
+
+       for (i = 0; i < argc && argv[i]; i++)
+               free(argv[i]);
+       free(argv);
+
        return 0;
 }
index 3a0b3c183d87f2561162581049c769746e7815f2..5877a31ac8ab1662d6771c487ba8d8987e9a9e4c 100644 (file)
@@ -898,7 +898,9 @@ struct dm_hash_node *get_next_excl_lock(struct dm_hash_node *v, char **name)
                        v = dm_hash_get_next(lv_hash, v);
                }
        } while (v && !*name);
-       DEBUGLOG("returning EXclusive UUID %s\n", *name);
+
+       if (*name)
+               DEBUGLOG("returning EXclusive UUID %s\n", *name);
        return v;
 }
 
This page took 0.041276 seconds and 5 git commands to generate.