1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

Fix restart of clvmd using -S switch

- 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
This commit is contained in:
Milan Broz 2010-06-04 12:59:30 +00:00
parent 850fa8233f
commit 8d6e0c9562
3 changed files with 40 additions and 16 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.67 - 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. Fix clvmd initscript restart command to start clvmd if not yet running.
Use absolute paths for clvmd restart. Use absolute paths for clvmd restart.
Require partial option in lvchange --refresh for partial LVs. Require partial option in lvchange --refresh for partial LVs.

View File

@ -361,33 +361,51 @@ void cmd_client_cleanup(struct local_client *client)
static int restart_clvmd(void) static int restart_clvmd(void)
{ {
char *argv[1024]; char **argv = NULL;
int argc = 1; char *debug_arg = NULL, *lv_name;
int i, argc = 0, max_locks = 0;
struct dm_hash_node *hn = NULL; struct dm_hash_node *hn = NULL;
char *lv_name;
DEBUGLOG("clvmd restart requested\n"); 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 * Build the command-line
*/ */
/* FIXME missing strdup error checks */ argv[argc++] = strdup("clvmd");
argv[0] = strdup("clvmd"); if (!argv[0])
goto_out;
/* Propogate debug options */ /* Propogate debug options */
if (debug) { if (debug) {
char debug_level[16]; if (!(debug_arg = malloc(16)) ||
snprintf(debug_arg, 16, "-d%d", (int)debug) < 0)
sprintf(debug_level, "-d%d", debug); goto_out;
argv[argc++] = strdup(debug_level); argv[argc++] = debug_arg;
} }
/* Now add the exclusively-open LVs */ /* Now add the exclusively-open LVs */
do { do {
hn = get_next_excl_lock(hn, &lv_name); hn = get_next_excl_lock(hn, &lv_name);
if (lv_name) { if (lv_name) {
argv[argc++] = strdup("-E"); argv[argc] = strdup("-E");
argv[argc++] = strdup(lv_name); if (!argv[argc++])
goto_out;
argv[argc] = strdup(lv_name);
if (!argv[argc++])
goto_out;
DEBUGLOG("excl lock: %s\n", lv_name); DEBUGLOG("excl lock: %s\n", lv_name);
hn = get_next_excl_lock(hn, &lv_name); hn = get_next_excl_lock(hn, &lv_name);
@ -395,13 +413,16 @@ static int restart_clvmd(void)
} while (hn && *lv_name); } while (hn && *lv_name);
argv[argc++] = NULL; argv[argc++] = NULL;
/* Tidy up */
destroy_lvm();
/* Exec new clvmd */ /* Exec new clvmd */
/* NOTE: This will fail when downgrading! */ /* NOTE: This will fail when downgrading! */
execve(CLVMD_PATH, argv, NULL); execve(CLVMD_PATH, argv, NULL);
out:
/* We failed */ /* We failed */
DEBUGLOG("Restart of clvmd failed.\n");
for (i = 0; i < argc && argv[i]; i++)
free(argv[i]);
free(argv);
return 0; return 0;
} }

View File

@ -898,6 +898,8 @@ struct dm_hash_node *get_next_excl_lock(struct dm_hash_node *v, char **name)
v = dm_hash_get_next(lv_hash, v); v = dm_hash_get_next(lv_hash, v);
} }
} while (v && !*name); } while (v && !*name);
if (*name)
DEBUGLOG("returning EXclusive UUID %s\n", *name); DEBUGLOG("returning EXclusive UUID %s\n", *name);
return v; return v;
} }