]> sourceware.org Git - lvm2.git/commitdiff
Add tags_format_and_copy() common function and call from _tags_disp.
authorDave Wysochanski <dwysocha@redhat.com>
Thu, 30 Sep 2010 14:08:07 +0000 (14:08 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Thu, 30 Sep 2010 14:08:07 +0000 (14:08 +0000)
Add a common function to allocate memory and format a string of
tags.
Call tags_format_and_copy() from _tags_disp().

lib/metadata/metadata.c
lib/metadata/metadata.h
lib/report/report.c

index 806bc30415a124985729dfa216517280a65652df..7153122ebab2639ece23f2dac0a659cce36ae5ea 100644 (file)
@@ -3937,6 +3937,30 @@ char alloc_policy_char(alloc_policy_t alloc)
        }
 }
 
+char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tags)
+{
+       struct str_list *sl;
+
+       if (!dm_pool_begin_object(mem, 256)) {
+               log_error("dm_pool_begin_object failed");
+               return NULL;
+       }
+
+       dm_list_iterate_items(sl, tags) {
+               if (!dm_pool_grow_object(mem, sl->str, strlen(sl->str)) ||
+                   (sl->list.n != tags && !dm_pool_grow_object(mem, ",", 1))) {
+                       log_error("dm_pool_grow_object failed");
+                       return NULL;
+               }
+       }
+
+       if (!dm_pool_grow_object(mem, "\0", 1)) {
+               log_error("dm_pool_grow_object failed");
+               return NULL;
+       }
+       return dm_pool_end_object(mem);
+}
+
 /**
  * pv_by_path - Given a device path return a PV handle if it is a PV
  * @cmd - handle to the LVM command instance
index 70efe9ee8db9dbe60884b630ac4d29fc3963df14..3ebe736288322ba90afc5863b94cfd5fd7f2cbee 100644 (file)
@@ -413,5 +413,6 @@ int is_mirror_image_removable(struct logical_volume *mimage_lv, void *baton);
 
 uint64_t find_min_mda_size(struct dm_list *mdas);
 char alloc_policy_char(alloc_policy_t alloc);
+char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tags);
 
 #endif
index b8c5d1adc5b342cb08b2b917d336807237b38fca..cac4f8beda7b0e29aa64bf41e0a1214c846f0733 100644 (file)
@@ -150,27 +150,12 @@ static int _tags_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
                      const void *data, void *private __attribute__((unused)))
 {
        const struct dm_list *tags = (const struct dm_list *) data;
-       struct str_list *sl;
+       char *tags_str;
 
-       if (!dm_pool_begin_object(mem, 256)) {
-               log_error("dm_pool_begin_object failed");
-               return 0;
-       }
-
-       dm_list_iterate_items(sl, tags) {
-               if (!dm_pool_grow_object(mem, sl->str, strlen(sl->str)) ||
-                   (sl->list.n != tags && !dm_pool_grow_object(mem, ",", 1))) {
-                       log_error("dm_pool_grow_object failed");
-                       return 0;
-               }
-       }
-
-       if (!dm_pool_grow_object(mem, "\0", 1)) {
-               log_error("dm_pool_grow_object failed");
+       if (!(tags_str = tags_format_and_copy(mem, tags)))
                return 0;
-       }
 
-       dm_report_field_set_value(field, dm_pool_end_object(mem), NULL);
+       dm_report_field_set_value(field, tags_str, NULL);
 
        return 1;
 }
This page took 0.049826 seconds and 5 git commands to generate.