]> sourceware.org Git - lvm2.git/commitdiff
lv: add common lv_mirror_log_lv for use in report and dup, use brackets for invisible...
authorPeter Rajnoha <prajnoha@redhat.com>
Tue, 12 Jan 2016 10:05:16 +0000 (11:05 +0100)
committerPeter Rajnoha <prajnoha@redhat.com>
Wed, 13 Jan 2016 10:19:51 +0000 (11:19 +0100)
The common lv_mirror_log_lv fn avoids code duplication and also
the reporting part now uses _lvname_disp and _uuid_disp to display
name and uuid respectively, including brackets for the name if the
dev is invisible.

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

index a190ae0b4c0085820d019c305f69404f95df80eb..ab8a7c4180582ab6476b7039e45d2a7c2499def1 100644 (file)
@@ -334,23 +334,32 @@ char *lv_modules_dup(struct dm_pool *mem, const struct logical_volume *lv)
        return tags_format_and_copy(mem, modules);
 }
 
-static char *_do_lv_mirror_log_dup(struct dm_pool *mem, const struct logical_volume *lv,
-                                  int uuid)
+struct logical_volume *lv_mirror_log_lv(const struct logical_volume *lv)
 {
        struct lv_segment *seg;
 
        dm_list_iterate_items(seg, &lv->segments) {
-               if (seg_is_mirrored(seg) && seg->log_lv) {
-                       if (uuid)
-                               return lv_uuid_dup(mem, seg->log_lv);
-                       else
-                               return lv_name_dup(mem, seg->log_lv);
-               }
+               if (seg_is_mirrored(seg) && seg->log_lv)
+                       return seg->log_lv;
        }
 
        return NULL;
 }
 
+static char *_do_lv_mirror_log_dup(struct dm_pool *mem, const struct logical_volume *lv,
+                                  int uuid)
+{
+       struct logical_volume *mirror_log_lv = lv_mirror_log_lv(lv);
+
+       if (!mirror_log_lv)
+               return NULL;
+
+       if (uuid)
+               return lv_uuid_dup(mem, mirror_log_lv);
+       else
+               return lv_name_dup(mem, mirror_log_lv);
+}
+
 char *lv_mirror_log_dup(struct dm_pool *mem, const struct logical_volume *lv)
 {
        return _do_lv_mirror_log_dup(mem, lv, 0);
index e346059e52042d75b5ce0dff98b71b44b3171496..b37cc4e7d114c65b9c9fce40c153293b766b752b 100644 (file)
@@ -88,6 +88,7 @@ char *lv_fullname_dup(struct dm_pool *mem, const struct logical_volume *lv);
 struct logical_volume *lv_parent(const struct logical_volume *lv);
 struct logical_volume *lv_convert_lv(const struct logical_volume *lv);
 struct logical_volume *lv_origin_lv(const struct logical_volume *lv);
+struct logical_volume *lv_mirror_log_lv(const struct logical_volume *lv);
 char *lv_parent_dup(struct dm_pool *mem, const struct logical_volume *lv);
 char *lv_origin_dup(struct dm_pool *mem, const struct logical_volume *lv);
 char *lv_origin_uuid_dup(struct dm_pool *mem, const struct logical_volume *lv);
index 9ffaf73321209ff2081d1699154d848002e5f335..80896b3b4b320310788a8aaa67b05cc53ba2bee2 100644 (file)
@@ -1577,39 +1577,6 @@ static int _segtype_disp(struct dm_report *rh __attribute__((unused)),
        return _field_set_value(field, name, NULL);
 }
 
-static int _do_loglv_disp(struct dm_report *rh, struct dm_pool *mem,
-                         struct dm_report_field *field,
-                         const void *data, void *private,
-                         int uuid)
-{
-       const struct logical_volume *lv = (const struct logical_volume *) data;
-       const char *repstr = NULL;
-
-       if (uuid)
-               repstr = lv_mirror_log_uuid_dup(mem, lv);
-       else
-               repstr = lv_mirror_log_dup(mem, lv);
-
-       if (repstr)
-               return _string_disp(rh, mem, field, &repstr, private);
-
-       return _field_set_value(field, "", NULL);
-}
-
-static int _loglv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
-                      struct dm_report_field *field,
-                      const void *data, void *private __attribute__((unused)))
-{
-       return _do_loglv_disp(rh, mem, field, data, private, 0);
-}
-
-static int _loglvuuid_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
-                          struct dm_report_field *field,
-                          const void *data, void *private __attribute__((unused)))
-{
-       return _do_loglv_disp(rh, mem, field, data, private, 1);
-}
-
 static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem,
                        struct dm_report_field *field,
                        const void *data, void *private)
@@ -1640,6 +1607,37 @@ static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem,
        return _field_set_value(field, repstr, lvname);
 }
 
+static int _do_loglv_disp(struct dm_report *rh, struct dm_pool *mem,
+                         struct dm_report_field *field,
+                         const void *data, void *private,
+                         int uuid)
+{
+       const struct logical_volume *lv = (const struct logical_volume *) data;
+       struct logical_volume *mirror_log_lv = lv_mirror_log_lv(lv);
+
+       if (!mirror_log_lv)
+               return _field_set_value(field, "", NULL);
+
+       if (uuid)
+               return _uuid_disp(rh, mem, field, &mirror_log_lv->lvid.id[1], private);
+       else
+               return _lvname_disp(rh, mem, field, mirror_log_lv, private);
+}
+
+static int _loglv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
+                      struct dm_report_field *field,
+                      const void *data, void *private __attribute__((unused)))
+{
+       return _do_loglv_disp(rh, mem, field, data, private, 0);
+}
+
+static int _loglvuuid_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
+                          struct dm_report_field *field,
+                          const void *data, void *private __attribute__((unused)))
+{
+       return _do_loglv_disp(rh, mem, field, data, private, 1);
+}
+
 static int _lvfullname_disp(struct dm_report *rh, struct dm_pool *mem,
                            struct dm_report_field *field,
                            const void *data, void *private __attribute__((unused)))
This page took 0.042297 seconds and 5 git commands to generate.