mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
str_list: do not support str lists without mempools
Do not support str lists without mempools. Instead, create temporary mempool where necessary (currently only _get_report_options fn).
This commit is contained in:
parent
b8779e706e
commit
1e729c47d2
@ -20,8 +20,7 @@ struct dm_list *str_list_create(struct dm_pool *mem)
|
|||||||
{
|
{
|
||||||
struct dm_list *sl;
|
struct dm_list *sl;
|
||||||
|
|
||||||
if (!(sl = mem ? dm_pool_alloc(mem, sizeof(struct dm_list))
|
if (!(sl = dm_pool_alloc(mem, sizeof(struct dm_list)))) {
|
||||||
: dm_malloc(sizeof(struct dm_list)))) {
|
|
||||||
log_errno(ENOMEM, "str_list allocation failed");
|
log_errno(ENOMEM, "str_list allocation failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -38,8 +37,7 @@ static int _str_list_add_no_dup_check(struct dm_pool *mem, struct dm_list *sll,
|
|||||||
if (!str)
|
if (!str)
|
||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
if (!(sln = mem ? dm_pool_alloc(mem, sizeof(*sln))
|
if (!(sln = dm_pool_alloc(mem, sizeof(*sln))))
|
||||||
: dm_malloc(sizeof(*sln))))
|
|
||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
sln->str = str;
|
sln->str = str;
|
||||||
@ -176,7 +174,7 @@ char *str_list_to_str(struct dm_pool *mem, const struct dm_list *list,
|
|||||||
if (list_size > 1)
|
if (list_size > 1)
|
||||||
len += ((list_size - 1) * delim_len);
|
len += ((list_size - 1) * delim_len);
|
||||||
|
|
||||||
str = mem ? dm_pool_alloc(mem, len+1) : dm_malloc(len+1);
|
str = dm_pool_alloc(mem, len+1);
|
||||||
if (!str) {
|
if (!str) {
|
||||||
log_error("str_list_to_str: string allocation failed.");
|
log_error("str_list_to_str: string allocation failed.");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -220,7 +218,7 @@ struct dm_list *str_to_str_list(struct dm_pool *mem, const char *str,
|
|||||||
next = p2 + delim_len;
|
next = p2 + delim_len;
|
||||||
|
|
||||||
len = p2 - p1;
|
len = p2 - p1;
|
||||||
str_item = mem ? dm_pool_alloc(mem, len+1) : dm_malloc(len+1);
|
str_item = dm_pool_alloc(mem, len+1);
|
||||||
if (!str_item) {
|
if (!str_item) {
|
||||||
log_error("str_to_str_list: string list item allocation failed.");
|
log_error("str_to_str_list: string list item allocation failed.");
|
||||||
goto bad;
|
goto bad;
|
||||||
@ -245,16 +243,3 @@ bad:
|
|||||||
dm_pool_free(mem, list);
|
dm_pool_free(mem, list);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void str_list_destroy(struct dm_list *list, int deallocate_strings)
|
|
||||||
{
|
|
||||||
struct dm_str_list *sl, *tmp_sl;
|
|
||||||
|
|
||||||
dm_list_iterate_items_safe(sl, tmp_sl, list) {
|
|
||||||
dm_list_del(&sl->list);
|
|
||||||
if (deallocate_strings)
|
|
||||||
dm_free((char *)sl->str);
|
|
||||||
dm_free(sl);
|
|
||||||
}
|
|
||||||
dm_free(list);
|
|
||||||
}
|
|
||||||
|
@ -32,7 +32,5 @@ int str_list_dup(struct dm_pool *mem, struct dm_list *sllnew,
|
|||||||
const struct dm_list *sllold);
|
const struct dm_list *sllold);
|
||||||
char *str_list_to_str(struct dm_pool *mem, const struct dm_list *list, const char *delim);
|
char *str_list_to_str(struct dm_pool *mem, const struct dm_list *list, const char *delim);
|
||||||
struct dm_list *str_to_str_list(struct dm_pool *mem, const char *str, const char *delim, int ignore_multiple_delim);
|
struct dm_list *str_to_str_list(struct dm_pool *mem, const char *str, const char *delim, int ignore_multiple_delim);
|
||||||
/* Only for lists which were *not* allocated from the mem pool! */
|
|
||||||
void str_list_destroy(struct dm_list *list, int deallocate_strings);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -651,13 +651,18 @@ static int _get_report_options(struct cmd_context *cmd,
|
|||||||
struct dm_list *final_opts_list;
|
struct dm_list *final_opts_list;
|
||||||
struct dm_list *final_compact_list = NULL;
|
struct dm_list *final_compact_list = NULL;
|
||||||
struct dm_list *opts_list = NULL;
|
struct dm_list *opts_list = NULL;
|
||||||
int opts_list_destroy = 1;
|
|
||||||
struct dm_str_list *sl;
|
struct dm_str_list *sl;
|
||||||
const char *opts;
|
const char *opts;
|
||||||
|
struct dm_pool *mem;
|
||||||
int r = ECMD_PROCESSED;
|
int r = ECMD_PROCESSED;
|
||||||
|
|
||||||
|
if (!(mem = dm_pool_create("report_options", 128))) {
|
||||||
|
r = ECMD_FAILED;
|
||||||
|
log_error("Failed to create temporary mempool to process report options.");
|
||||||
|
goto_out;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(final_opts_list = str_to_str_list(NULL, *options, ",", 1))) {
|
if (!(final_opts_list = str_to_str_list(mem, *options, ",", 1))) {
|
||||||
r = ECMD_FAILED;
|
r = ECMD_FAILED;
|
||||||
goto_out;
|
goto_out;
|
||||||
}
|
}
|
||||||
@ -679,7 +684,7 @@ static int _get_report_options(struct cmd_context *cmd,
|
|||||||
case '-':
|
case '-':
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case '#':
|
case '#':
|
||||||
if (!(opts_list = str_to_str_list(NULL, opts + 1, ",", 1))) {
|
if (!(opts_list = str_to_str_list(mem, opts + 1, ",", 1))) {
|
||||||
r = ECMD_FAILED;
|
r = ECMD_FAILED;
|
||||||
goto_out;
|
goto_out;
|
||||||
}
|
}
|
||||||
@ -690,21 +695,14 @@ static int _get_report_options(struct cmd_context *cmd,
|
|||||||
_del_option_from_list(final_opts_list, prefix,
|
_del_option_from_list(final_opts_list, prefix,
|
||||||
prefix_len, sl->str);
|
prefix_len, sl->str);
|
||||||
} else if (*opts == '#') {
|
} else if (*opts == '#') {
|
||||||
if (!final_compact_list) {
|
if (!final_compact_list)
|
||||||
final_compact_list = opts_list;
|
final_compact_list = opts_list;
|
||||||
opts_list_destroy = 0;
|
else
|
||||||
} else
|
|
||||||
dm_list_splice(final_compact_list, opts_list);
|
dm_list_splice(final_compact_list, opts_list);
|
||||||
}
|
}
|
||||||
if (opts_list_destroy)
|
|
||||||
str_list_destroy(opts_list, 1);
|
|
||||||
else
|
|
||||||
opts_list_destroy = 1;
|
|
||||||
opts_list = NULL;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
str_list_destroy(final_opts_list, 1);
|
if (!(final_opts_list = str_to_str_list(mem, opts, ",", 1))) {
|
||||||
if (!(final_opts_list = str_to_str_list(NULL, opts, ",", 1))) {
|
|
||||||
r = ECMD_FAILED;
|
r = ECMD_FAILED;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -722,12 +720,8 @@ static int _get_report_options(struct cmd_context *cmd,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
if (opts_list)
|
if (mem)
|
||||||
str_list_destroy(final_opts_list, 1);
|
dm_pool_destroy(mem);
|
||||||
if (final_compact_list)
|
|
||||||
str_list_destroy(final_compact_list, 1);
|
|
||||||
if (final_opts_list)
|
|
||||||
str_list_destroy(final_opts_list, 1);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user