1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

cleanup: poll better check for internal errors

This commit is contained in:
Zdenek Kabelac 2016-02-25 13:31:31 +01:00
parent cdcf4cc794
commit 5c29b54d4d
3 changed files with 51 additions and 67 deletions

View File

@ -722,43 +722,40 @@ static struct poll_functions _lvconvert_thin_merge_fns = {
.finish_copy = lvconvert_merge_finish, .finish_copy = lvconvert_merge_finish,
}; };
static void _destroy_id(struct cmd_context *cmd, struct poll_operation_id *id)
{
if (!id)
return;
dm_pool_free(cmd->mem, (void *)id);
}
static struct poll_operation_id *_create_id(struct cmd_context *cmd, static struct poll_operation_id *_create_id(struct cmd_context *cmd,
const char *vg_name, const char *vg_name,
const char *lv_name, const char *lv_name,
const char *uuid) const char *uuid)
{ {
struct poll_operation_id *id;
char lv_full_name[NAME_LEN]; char lv_full_name[NAME_LEN];
struct poll_operation_id *id = dm_pool_alloc(cmd->mem, sizeof(struct poll_operation_id));
if (!id) { if (!vg_name || !lv_name || !uuid) {
log_error("Poll operation ID allocation failed."); log_error(INTERNAL_ERROR "Wrong params for lvconvert _create_id.");
return NULL; return NULL;
} }
if (dm_snprintf(lv_full_name, sizeof(lv_full_name), "%s/%s", vg_name, lv_name) < 0) { if (dm_snprintf(lv_full_name, sizeof(lv_full_name), "%s/%s", vg_name, lv_name) < 0) {
log_error(INTERNAL_ERROR "Name \"%s/%s\" is too long.", vg_name, lv_name); log_error(INTERNAL_ERROR "Name \"%s/%s\" is too long.", vg_name, lv_name);
_destroy_id(cmd, id);
return NULL; return NULL;
} }
id->display_name = dm_pool_strdup(cmd->mem, lv_full_name); if (!(id = dm_pool_alloc(cmd->mem, sizeof(*id)))) {
id->vg_name = vg_name ? dm_pool_strdup(cmd->mem, vg_name) : NULL; log_error("Poll operation ID allocation failed.");
id->lv_name = id->display_name ? strchr(id->display_name, '/') + 1 : NULL; return NULL;
id->uuid = uuid ? dm_pool_strdup(cmd->mem, uuid) : NULL;
if (!id->vg_name || !id->lv_name || !id->display_name || !id->uuid) {
log_error("Failed to copy one or more poll operation ID members.");
_destroy_id(cmd, id);
id = NULL;
} }
if (!(id->display_name = dm_pool_strdup(cmd->mem, lv_full_name)) ||
!(id->lv_name = strchr(id->display_name, '/')) ||
!(id->vg_name = dm_pool_strdup(cmd->mem, vg_name)) ||
!(id->uuid = dm_pool_strdup(cmd->mem, uuid))) {
log_error("Failed to copy one or more poll operation ID members.");
dm_pool_free(cmd->mem, id);
return NULL;
}
id->lv_name++; /* skip over '/' */
return id; return id;
} }
@ -801,8 +798,6 @@ int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv,
r = _lvconvert_poll_by_id(cmd, id, background, is_merging_origin, is_merging_origin_thin); r = _lvconvert_poll_by_id(cmd, id, background, is_merging_origin, is_merging_origin_thin);
_destroy_id(cmd, id);
return r; return r;
} }

View File

@ -242,22 +242,22 @@ static struct poll_operation_id *copy_poll_operation_id(struct dm_pool *mem,
{ {
struct poll_operation_id *copy; struct poll_operation_id *copy;
if (!id) if (!id || !id->vg_name || !id->lv_name || !id->display_name || !id->uuid) {
return_NULL; log_error(INTERNAL_ERROR "Wrong params for copy_poll_operation_id.");
return NULL;
}
copy = (struct poll_operation_id *) dm_pool_alloc(mem, sizeof(struct poll_operation_id)); if (!(copy = dm_pool_alloc(mem, sizeof(*copy)))) {
if (!copy) {
log_error("Poll operation ID allocation failed."); log_error("Poll operation ID allocation failed.");
return NULL; return NULL;
} }
copy->display_name = id->display_name ? dm_pool_strdup(mem, id->display_name) : NULL; if (!(copy->display_name = dm_pool_strdup(mem, id->display_name)) ||
copy->lv_name = id->lv_name ? dm_pool_strdup(mem, id->lv_name) : NULL; !(copy->lv_name = dm_pool_strdup(mem, id->lv_name)) ||
copy->vg_name = id->vg_name ? dm_pool_strdup(mem, id->vg_name) : NULL; !(copy->vg_name = dm_pool_strdup(mem, id->vg_name)) ||
copy->uuid = id->uuid ? dm_pool_strdup(mem, id->uuid) : NULL; !(copy->uuid = dm_pool_strdup(mem, id->uuid))) {
if (!copy->display_name || !copy->lv_name || !copy->vg_name || !copy->uuid) {
log_error("Failed to copy one or more poll_operation_id members."); log_error("Failed to copy one or more poll_operation_id members.");
dm_pool_free(mem, copy);
return NULL; return NULL;
} }

View File

@ -751,35 +751,31 @@ static struct poll_functions _pvmove_fns = {
.finish_copy = pvmove_finish, .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) struct poll_operation_id *id;
return;
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, if (!(id = dm_pool_alloc(cmd->mem, sizeof(*id)))) {
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) {
log_error("Poll operation ID allocation failed."); log_error("Poll operation ID allocation failed.");
return NULL; return NULL;
} }
id->vg_name = vg_name ? dm_pool_strdup(cmd->mem, vg_name) : NULL; if (!(id->vg_name = dm_pool_strdup(cmd->mem, vg_name)) ||
id->lv_name = lv_name ? dm_pool_strdup(cmd->mem, lv_name) : NULL; !(id->lv_name = dm_pool_strdup(cmd->mem, lv_name)) ||
id->display_name = pv_name ? dm_pool_strdup(cmd->mem, pv_name) : NULL; !(id->display_name = dm_pool_strdup(cmd->mem, pv_name)) ||
id->uuid = uuid ? dm_pool_strdup(cmd->mem, uuid) : NULL; !(id->uuid = dm_pool_strdup(cmd->mem, uuid))) {
if (!id->vg_name || !id->lv_name || !id->display_name || !id->uuid) {
log_error("Failed to copy one or more poll operation ID members."); log_error("Failed to copy one or more poll operation ID members.");
_destroy_id(cmd, id); dm_pool_free(cmd->mem, id);
id = NULL; return NULL;
} }
return id; 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 *uuid, const char *vg_name,
const char *lv_name, unsigned background) const char *lv_name, unsigned background)
{ {
int r;
struct poll_operation_id *id = NULL; struct poll_operation_id *id = NULL;
if (uuid) { if (uuid &&
id = _create_id(cmd, pv_name, vg_name, lv_name, uuid); !(id = _pvmove_create_id(cmd, pv_name, vg_name, lv_name, uuid))) {
if (!id) { log_error("Failed to allocate poll identifier for pvmove.");
log_error("Failed to allocate poll identifier for pvmove."); return ECMD_FAILED;
return ECMD_FAILED;
}
} }
if (test_mode()) if (test_mode())
r = ECMD_PROCESSED; return ECMD_PROCESSED;
else
r = poll_daemon(cmd, background, PVMOVE, &_pvmove_fns, "Moved", id);
_destroy_id(cmd, id); return poll_daemon(cmd, background, PVMOVE, &_pvmove_fns, "Moved", id);
return r;
} }
int pvmove(struct cmd_context *cmd, int argc, char **argv) int pvmove(struct cmd_context *cmd, int argc, char **argv)