From b1b38215ba6d9c45f2db4bbfc707064831b36c91 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 13 Jan 2011 14:51:32 +0000 Subject: [PATCH] Add exec_cmd paramater sync_needed As sync_local_dev_names() cannot be called within activation context, add new parametr which allows to select if the sync call is needed before executing new command. --- WHATS_NEW | 1 + lib/activate/activate.c | 2 +- lib/misc/lvm-exec.c | 15 +++++++++------ lib/misc/lvm-exec.h | 20 ++++++++++++++++++-- tools/lvresize.c | 2 +- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index d28f9709e..b4d63142d 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.81 - =================================== + Extend exec_cmd params to specify, when device sync is needed. Replace fs_unlock by sync_local_dev_names to notify local clvmd. (2.02.80) Introduce sync_local_dev_names and CLVMD_CMD_SYNC_NAMES to issue fs_unlock. Accept fusion fio in device type filter. diff --git a/lib/activate/activate.c b/lib/activate/activate.c index e199fbbdf..3670ea4a5 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -424,7 +424,7 @@ int module_present(struct cmd_context *cmd, const char *target_name) argv[1] = module; argv[2] = NULL; - ret = exec_cmd(cmd, argv, NULL); + ret = exec_cmd(cmd, argv, NULL, 0); #endif return ret; } diff --git a/lib/misc/lvm-exec.c b/lib/misc/lvm-exec.c index 79291259d..775b801f6 100644 --- a/lib/misc/lvm-exec.c +++ b/lib/misc/lvm-exec.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. - * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * @@ -47,7 +47,8 @@ static char *_verbose_args(const char *const argv[], char *buf, size_t sz) /* * Execute and wait for external command */ -int exec_cmd(struct cmd_context *cmd, const char *const argv[], int *rstatus) +int exec_cmd(struct cmd_context *cmd, const char *const argv[], + int *rstatus, int sync_needed) { pid_t pid; int status; @@ -55,7 +56,12 @@ int exec_cmd(struct cmd_context *cmd, const char *const argv[], int *rstatus) log_verbose("Executing: %s", _verbose_args(argv, buf, sizeof(buf))); - sync_local_dev_names(cmd); /* Flush ops and reset dm cookie */ + if (rstatus) + *rstatus = -1; + + if (sync_needed) + if (!sync_local_dev_names(cmd)) /* Flush ops and reset dm cookie */ + return_0; if ((pid = fork()) == -1) { log_error("fork failed: %s", strerror(errno)); @@ -74,9 +80,6 @@ int exec_cmd(struct cmd_context *cmd, const char *const argv[], int *rstatus) _exit(errno); } - if (rstatus) - *rstatus = -1; - /* Parent */ if (wait4(pid, &status, 0, NULL) != pid) { log_error("wait4 child process %u failed: %s", pid, diff --git a/lib/misc/lvm-exec.h b/lib/misc/lvm-exec.h index 6d984f846..c91ffafe4 100644 --- a/lib/misc/lvm-exec.h +++ b/lib/misc/lvm-exec.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. - * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * @@ -19,6 +19,22 @@ #include "lib.h" struct cmd_context; -int exec_cmd(struct cmd_context *cmd, const char *const argv[], int *rstatus); + +/** + * Execute command with paramaters and return status + * + * \param rstatus + * Returns command's exit status code. + * + * \param sync_needed + * Bool specifying whether local devices needs to be synchronized + * before executing command. + * Note: You cannot synchronize devices within activation context. + * + * \return + * 0 (success) or -1 (failure). + */ +int exec_cmd(struct cmd_context *cmd, const char *const argv[], + int *rstatus, int sync_needed); #endif diff --git a/tools/lvresize.c b/tools/lvresize.c index c970f3f53..225c4465b 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -179,7 +179,7 @@ static int _fsadm_cmd(struct cmd_context *cmd, argv[i] = NULL; - return exec_cmd(cmd, argv, status); + return exec_cmd(cmd, argv, status, 1); } static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,