diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2015-08-17 14:53:42 +0200 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2016-02-04 16:20:32 +0100 |
commit | 0ee2c8a3336359440f6143e0262eebdd479e1884 (patch) | |
tree | 6dcba473cd0e8fe7aaf0184ae61d671f3ea6a359 | |
parent | 3ff56cce74e80e0a8d53d1f535d4e6d4064961e5 (diff) | |
download | lvm2-0ee2c8a3336359440f6143e0262eebdd479e1884.tar.gz |
report: report dead LV names with '-' prefix
All names for dead LVs are prefixed with '-' character to make a clear
difference between live and dead LVs. The '-' can't be set by users as
LV names directly hence we never get into a conflict with the names that
user defines for live LVs.
For example:
$ lvs -r -o name,name_removed,lv_attr vg/-rlvol0
LV RLV Attr
-lvol2 -rlvol0 ----r-----
-rw-r--r-- | lib/report/report.c | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/lib/report/report.c b/lib/report/report.c index 2b0045f1d..8211bf3aa 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -1663,33 +1663,47 @@ static int _segtype_disp(struct dm_report *rh __attribute__((unused)), return _field_set_value(field, name, NULL); } -static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem, - struct dm_report_field *field, - const void *data, void *private) +static int _do_lvname_disp(struct dm_report *rh, struct dm_pool *mem, + struct dm_report_field *field, + const void *data, void *private, + int prefer_dname) { struct cmd_context *cmd = (struct cmd_context *) private; const struct logical_volume *lv = (const struct logical_volume *) data; + int is_dead = lv_is_dead(lv); + const char *tmp_lvname; char *repstr, *lvname; size_t len; - if (lv_is_dead(lv)) - return _string_disp(rh, mem, field, &lv->this_glv->dead->name, private); - - if (lv_is_visible(lv) || !cmd->report_mark_hidden_devices) + if (!is_dead && (lv_is_visible(lv) || !cmd->report_mark_hidden_devices)) return _string_disp(rh, mem, field, &lv->name, private); - len = strlen(lv->name) + 3; + if (is_dead) + tmp_lvname = prefer_dname ? lv->this_glv->dead->dname + : lv->this_glv->dead->name; + else + tmp_lvname = lv->name; + + if (is_dead) + len = strlen(tmp_lvname) + strlen(DEAD_LV_PREFIX) + 1; + else + len = strlen(tmp_lvname) + 3; if (!(repstr = dm_pool_zalloc(mem, len))) { log_error("dm_pool_alloc failed"); return 0; } - if (dm_snprintf(repstr, len, "[%s]", lv->name) < 0) { + if (dm_snprintf(repstr, len, "%s%s%s", + is_dead ? DEAD_LV_PREFIX : "[", + tmp_lvname, + is_dead ? "" : "]") < 0) { log_error("lvname snprintf failed"); return 0; } - if (!(lvname = dm_pool_strdup(mem, lv->name))) { + if (is_dead) + lvname = repstr; + else if (!(lvname = dm_pool_strdup(mem, tmp_lvname))) { log_error("dm_pool_strdup failed"); return 0; } @@ -1697,6 +1711,20 @@ static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem, return _field_set_value(field, repstr, lvname); } +static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem, + struct dm_report_field *field, + const void *data, void *private) +{ + return _do_lvname_disp(rh, mem, field, data, private, 0); +} + +static int _lvrname_disp(struct dm_report *rh, struct dm_pool *mem, + struct dm_report_field *field, + const void *data, void *private) +{ + return _do_lvname_disp(rh, mem, field, data, private, 1); +} + static int _do_loglv_disp(struct dm_report *rh, struct dm_pool *mem, struct dm_report_field *field, const void *data, void *private, @@ -1738,7 +1766,7 @@ static int _lvnameremoved_disp(struct dm_report *rh, struct dm_pool *mem, if (!lv_is_dead(lv)) return _string_disp(rh, mem, field, &blank_name, private); - return _lvname_disp(rh, mem, field, &lv->this_glv->dead->dname, private); + return _lvrname_disp(rh, mem, field, lv, private); } static int _lvfullname_disp(struct dm_report *rh, struct dm_pool *mem, |