From dbb48de5078b00aed7f6f77453d435e8b6e45c49 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 9 Sep 2011 00:54:49 +0000 Subject: [PATCH] Add a new 'thin_pool' output field to 'lvs. A gentle reminder that anyone relying on the output of reporting commands like lvs in scripts must use -o to guarantee they get the fields they expect. The default sequence of fields can change from release to release. Equally, the 'attr' fields can have new values introduced and/or characters appended to them. --- lib/config/defaults.h | 4 ++-- lib/metadata/lv.c | 12 ++++++++++++ lib/metadata/lv.h | 1 + lib/report/columns.h | 1 + lib/report/properties.c | 2 ++ lib/report/report.c | 13 +++++++++++++ man/lvs.8.in | 2 +- 7 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/config/defaults.h b/lib/config/defaults.h index 8b8e09b9b..a5179432d 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -139,13 +139,13 @@ #define DEFAULT_REP_QUOTED 1 #define DEFAULT_REP_SEPARATOR " " -#define DEFAULT_LVS_COLS "lv_name,vg_name,lv_attr,lv_size,origin,snap_percent,move_pv,mirror_log,copy_percent,convert_lv" +#define DEFAULT_LVS_COLS "lv_name,vg_name,lv_attr,lv_size,thin_pool,origin,snap_percent,move_pv,mirror_log,copy_percent,convert_lv" #define DEFAULT_VGS_COLS "vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free" #define DEFAULT_PVS_COLS "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free" #define DEFAULT_SEGS_COLS "lv_name,vg_name,lv_attr,stripes,segtype,seg_size" #define DEFAULT_PVSEGS_COLS "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free,pvseg_start,pvseg_size" -#define DEFAULT_LVS_COLS_VERB "lv_name,vg_name,seg_count,lv_attr,lv_size,lv_major,lv_minor,lv_kernel_major,lv_kernel_minor,origin,snap_percent,move_pv,copy_percent,mirror_log,convert_lv,lv_uuid" +#define DEFAULT_LVS_COLS_VERB "lv_name,vg_name,seg_count,lv_attr,lv_size,lv_major,lv_minor,lv_kernel_major,lv_kernel_minor,thin_pool,origin,snap_percent,move_pv,copy_percent,mirror_log,convert_lv,lv_uuid" #define DEFAULT_VGS_COLS_VERB "vg_name,vg_attr,vg_extent_size,pv_count,lv_count,snap_count,vg_size,vg_free,vg_uuid" #define DEFAULT_PVS_COLS_VERB "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free,dev_size,pv_uuid" #define DEFAULT_SEGS_COLS_VERB "lv_name,vg_name,lv_attr,seg_start,seg_size,stripes,segtype,stripesize,chunksize" diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c index cfcae48d3..322727ebf 100644 --- a/lib/metadata/lv.c +++ b/lib/metadata/lv.c @@ -185,6 +185,18 @@ char *lv_mirror_log_dup(struct dm_pool *mem, const struct logical_volume *lv) return NULL; } +char *lv_pool_lv_dup(struct dm_pool *mem, const struct logical_volume *lv) +{ + struct lv_segment *seg; + + dm_list_iterate_items(seg, &lv->segments) { + if (!seg_is_thin_volume(seg) || !seg->pool_lv) + continue; + return dm_pool_strdup(mem, seg->pool_lv->name); + } + return NULL; +} + int lv_kernel_minor(const struct logical_volume *lv) { struct lvinfo info; diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h index 490658278..a54745f15 100644 --- a/lib/metadata/lv.h +++ b/lib/metadata/lv.h @@ -59,6 +59,7 @@ char *lv_convert_lv_dup(struct dm_pool *mem, const struct logical_volume *lv); int lv_kernel_major(const struct logical_volume *lv); int lv_kernel_minor(const struct logical_volume *lv); char *lv_mirror_log_dup(struct dm_pool *mem, const struct logical_volume *lv); +char *lv_pool_lv_dup(struct dm_pool *mem, const struct logical_volume *lv); char *lv_modules_dup(struct dm_pool *mem, const struct logical_volume *lv); char *lv_name_dup(struct dm_pool *mem, const struct logical_volume *lv); char *lv_origin_dup(struct dm_pool *mem, const struct logical_volume *lv); diff --git a/lib/report/columns.h b/lib/report/columns.h index acc232f28..f7f22e2ca 100644 --- a/lib/report/columns.h +++ b/lib/report/columns.h @@ -80,6 +80,7 @@ FIELD(LVS, lv, STR, "Move", lvid, 4, movepv, move_pv, "For pvmove, Source PV of FIELD(LVS, lv, STR, "Convert", lvid, 7, convertlv, convert_lv, "For lvconvert, Name of temporary LV created by lvconvert.", 0) FIELD(LVS, lv, STR, "LV Tags", tags, 7, tags, lv_tags, "Tags, if any.", 0) FIELD(LVS, lv, STR, "Log", lvid, 3, loglv, mirror_log, "For mirrors, the LV holding the synchronisation log.", 0) +FIELD(LVS, lv, STR, "Pool", lvid, 3, poollv, thin_pool, "For thinly-provisioned devices, the pool LV holding the data.", 0) FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, modules, "Kernel device-mapper modules required for this LV.", 0) FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, pv_fmt, "Type of metadata.", 0) diff --git a/lib/report/properties.c b/lib/report/properties.c index 62c39d564..8b93bd51d 100644 --- a/lib/report/properties.c +++ b/lib/report/properties.c @@ -175,6 +175,8 @@ GET_LV_STR_PROPERTY_FN(lv_tags, lv_tags_dup(lv)) #define _lv_tags_set _not_implemented_set GET_LV_STR_PROPERTY_FN(mirror_log, lv_mirror_log_dup(lv->vg->vgmem, lv)) #define _mirror_log_set _not_implemented_set +GET_LV_STR_PROPERTY_FN(thin_pool, lv_pool_lv_dup(lv->vg->vgmem, lv)) +#define _thin_pool_set _not_implemented_set GET_LV_STR_PROPERTY_FN(modules, lv_modules_dup(lv->vg->vgmem, lv)) #define _modules_set _not_implemented_set diff --git a/lib/report/report.c b/lib/report/report.c index e572797a1..4781f3a87 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -240,6 +240,19 @@ static int _loglv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(( return 1; } +static int _poollv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)), + struct dm_report_field *field, + const void *data, void *private __attribute__((unused))) +{ + const struct logical_volume *lv = (const struct logical_volume *) data; + const char *name; + + if ((name = lv_pool_lv_dup(mem, lv))) + return dm_report_field_string(rh, field, &name); + + dm_report_field_set_value(field, "", NULL); + return 1; +} static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem, struct dm_report_field *field, const void *data, void *private __attribute__((unused))) diff --git a/man/lvs.8.in b/man/lvs.8.in index 70a874620..7ed72703b 100644 --- a/man/lvs.8.in +++ b/man/lvs.8.in @@ -57,7 +57,7 @@ Use \fb-o help\fP to view the full list of columns available. Column names include: lv_uuid, lv_name, lv_path, lv_attr, lv_major, lv_minor, lv_read_ahead, lv_kernel_major, lv_kernel_minor, lv_kernel_read_ahead, lv_size, seg_count, origin, origin_size, -snap_percent, copy_percent, move_pv, convert_lv, lv_tags, mirror_log, modules, +snap_percent, copy_percent, move_pv, convert_lv, lv_tags, mirror_log, thin_pool, modules, segtype, stripes, stripesize, regionsize, chunksize, seg_start, seg_start_pe, seg_size, seg_tags, seg_pe_ranges, devices. .IP -- 2.43.5