diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2015-05-06 13:19:21 +0200 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2015-05-08 09:57:08 +0200 |
commit | 513cb596f3e2ec4fb7e0e8d2f5a09630f80beede (patch) | |
tree | 8067764480be1fcc0816bbad99619859e41d17c3 | |
parent | 87578b5d94a733b4b57b353c2430df32497a87a4 (diff) | |
download | lvm2-513cb596f3e2ec4fb7e0e8d2f5a09630f80beede.tar.gz |
refactor: rename read_tags fn to _read_str_list and use it for string lists in general
-rw-r--r-- | lib/format_text/import-export.h | 1 | ||||
-rw-r--r-- | lib/format_text/import_vsn1.c | 29 | ||||
-rw-r--r-- | lib/format_text/tags.c | 20 |
3 files changed, 25 insertions, 25 deletions
diff --git a/lib/format_text/import-export.h b/lib/format_text/import-export.h index 1ee647ba5..78938b744 100644 --- a/lib/format_text/import-export.h +++ b/lib/format_text/import-export.h @@ -61,7 +61,6 @@ int print_flags(uint64_t status, int type, char *buffer, size_t size); int read_flags(uint64_t *status, int type, const struct dm_config_value *cv); char *alloc_printed_tags(struct dm_list *tags); -int read_tags(struct dm_pool *mem, struct dm_list *tags, const struct dm_config_value *cv); int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp); size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf); diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index 5e8e049b2..96d10e456 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -25,6 +25,7 @@ #include "segtype.h" #include "text_import.h" #include "defaults.h" +#include "str_list.h" typedef int (*section_fn) (struct format_instance * fid, struct volume_group * vg, const struct dm_config_node * pvn, @@ -153,6 +154,26 @@ static int _read_flag_config(const struct dm_config_node *n, uint64_t *status, i return 1; } +static int _read_str_list(struct dm_pool *mem, struct dm_list *list, const struct dm_config_value *cv) +{ + if (cv->type == DM_CFG_EMPTY_ARRAY) + return 1; + + while (cv) { + if (cv->type != DM_CFG_STRING) { + log_error("Found an item that is not a string"); + return 0; + } + + if (!str_list_add(mem, list, dm_pool_strdup(mem, cv->v.str))) + return_0; + + cv = cv->next; + } + + return 1; +} + static int _read_pv(struct format_instance *fid, struct volume_group *vg, const struct dm_config_node *pvn, const struct dm_config_node *vgn __attribute__((unused)), @@ -267,7 +288,7 @@ static int _read_pv(struct format_instance *fid, /* Optional tags */ if (dm_config_get_list(pvn, "tags", &cv) && - !(read_tags(mem, &pv->tags, cv))) { + !(_read_str_list(mem, &pv->tags, cv))) { log_error("Couldn't read tags for physical volume %s in %s.", pv_dev_name(pv), vg->name); return 0; @@ -375,7 +396,7 @@ static int _read_segment(struct logical_volume *lv, const struct dm_config_node /* Optional tags */ if (dm_config_get_list(sn_child, "tags", &cv) && - !(read_tags(mem, &seg->tags, cv))) { + !(_read_str_list(mem, &seg->tags, cv))) { log_error("Couldn't read tags for a segment of %s/%s.", lv->vg->name, lv->name); return 0; @@ -611,7 +632,7 @@ static int _read_lvnames(struct format_instance *fid __attribute__((unused)), /* Optional tags */ if (dm_config_get_list(lvn, "tags", &cv) && - !(read_tags(mem, &lv->tags, cv))) { + !(_read_str_list(mem, &lv->tags, cv))) { log_error("Couldn't read tags for logical volume %s/%s.", vg->name, lv->name); return 0; @@ -879,7 +900,7 @@ static struct volume_group *_read_vg(struct format_instance *fid, /* Optional tags */ if (dm_config_get_list(vgn, "tags", &cv) && - !(read_tags(vg->vgmem, &vg->tags, cv))) { + !(_read_str_list(vg->vgmem, &vg->tags, cv))) { log_error("Couldn't read tags for volume group %s.", vg->name); goto bad; } diff --git a/lib/format_text/tags.c b/lib/format_text/tags.c index dc138d140..c081167c3 100644 --- a/lib/format_text/tags.c +++ b/lib/format_text/tags.c @@ -60,23 +60,3 @@ bad: dm_free(buffer); return_NULL; } - -int read_tags(struct dm_pool *mem, struct dm_list *tagsl, const struct dm_config_value *cv) -{ - if (cv->type == DM_CFG_EMPTY_ARRAY) - return 1; - - while (cv) { - if (cv->type != DM_CFG_STRING) { - log_error("Found a tag that is not a string"); - return 0; - } - - if (!str_list_add(mem, tagsl, dm_pool_strdup(mem, cv->v.str))) - return_0; - - cv = cv->next; - } - - return 1; -} |