summaryrefslogtreecommitdiff
path: root/tools/pvmove.c
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2016-02-25 13:31:31 +0100
committerZdenek Kabelac <zkabelac@redhat.com>2016-02-25 23:30:25 +0100
commit5c29b54d4dbf0a94525172f5526fd5ff7996de48 (patch)
treec95df8f147f5c1df72b59ca512c51c091fb8402f /tools/pvmove.c
parentcdcf4cc794827e61a1babd549f4a0ef4e6439165 (diff)
downloadlvm2-5c29b54d4dbf0a94525172f5526fd5ff7996de48.tar.gz
cleanup: poll better check for internal errors
Diffstat (limited to 'tools/pvmove.c')
-rw-r--r--tools/pvmove.c57
1 files changed, 23 insertions, 34 deletions
diff --git a/tools/pvmove.c b/tools/pvmove.c
index b590745ff..b5df45a1e 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -751,35 +751,31 @@ static struct poll_functions _pvmove_fns = {
.finish_copy = pvmove_finish,
};
-static void _destroy_id(struct cmd_context *cmd, struct poll_operation_id *id)
+static struct poll_operation_id *_pvmove_create_id(struct cmd_context *cmd,
+ const char *pv_name,
+ const char *vg_name,
+ const char *lv_name,
+ const char *uuid)
{
- if (!id)
- return;
+ struct poll_operation_id *id;
- dm_pool_free(cmd->mem, id);
-}
+ if (!vg_name || !lv_name || !pv_name || !uuid) {
+ log_error(INTERNAL_ERROR "Wrong params for _pvmove_create_id.");
+ return NULL;
+ }
-static struct poll_operation_id *_create_id(struct cmd_context *cmd,
- const char *pv_name,
- const char *vg_name,
- const char *lv_name,
- const char *uuid)
-{
- struct poll_operation_id *id = dm_pool_alloc(cmd->mem, sizeof(struct poll_operation_id));
- if (!id) {
+ if (!(id = dm_pool_alloc(cmd->mem, sizeof(*id)))) {
log_error("Poll operation ID allocation failed.");
return NULL;
}
- id->vg_name = vg_name ? dm_pool_strdup(cmd->mem, vg_name) : NULL;
- id->lv_name = lv_name ? dm_pool_strdup(cmd->mem, lv_name) : NULL;
- id->display_name = pv_name ? dm_pool_strdup(cmd->mem, pv_name) : NULL;
- id->uuid = uuid ? dm_pool_strdup(cmd->mem, uuid) : NULL;
-
- if (!id->vg_name || !id->lv_name || !id->display_name || !id->uuid) {
+ if (!(id->vg_name = dm_pool_strdup(cmd->mem, vg_name)) ||
+ !(id->lv_name = dm_pool_strdup(cmd->mem, lv_name)) ||
+ !(id->display_name = dm_pool_strdup(cmd->mem, pv_name)) ||
+ !(id->uuid = dm_pool_strdup(cmd->mem, uuid))) {
log_error("Failed to copy one or more poll operation ID members.");
- _destroy_id(cmd, id);
- id = NULL;
+ dm_pool_free(cmd->mem, id);
+ return NULL;
}
return id;
@@ -789,25 +785,18 @@ int pvmove_poll(struct cmd_context *cmd, const char *pv_name,
const char *uuid, const char *vg_name,
const char *lv_name, unsigned background)
{
- int r;
struct poll_operation_id *id = NULL;
- if (uuid) {
- id = _create_id(cmd, pv_name, vg_name, lv_name, uuid);
- if (!id) {
- log_error("Failed to allocate poll identifier for pvmove.");
- return ECMD_FAILED;
- }
+ if (uuid &&
+ !(id = _pvmove_create_id(cmd, pv_name, vg_name, lv_name, uuid))) {
+ log_error("Failed to allocate poll identifier for pvmove.");
+ return ECMD_FAILED;
}
if (test_mode())
- r = ECMD_PROCESSED;
- else
- r = poll_daemon(cmd, background, PVMOVE, &_pvmove_fns, "Moved", id);
-
- _destroy_id(cmd, id);
+ return ECMD_PROCESSED;
- return r;
+ return poll_daemon(cmd, background, PVMOVE, &_pvmove_fns, "Moved", id);
}
int pvmove(struct cmd_context *cmd, int argc, char **argv)