1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

This patchset refactors some reporting code and completes the remaining

lvseg properties for lvm2app, 'devices' and 'seg_pe_ranges'.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Reviewed-by: Petr Rockai <prockai@redhat.com>
This commit is contained in:
Petr Rockai 2011-04-12 12:24:29 +00:00
parent c67d2b4dd4
commit db22d9b978
5 changed files with 105 additions and 79 deletions

View File

@ -21,6 +21,88 @@
#include "segtype.h" #include "segtype.h"
#include "str_list.h" #include "str_list.h"
static char *_format_pvsegs(struct dm_pool *mem, const struct lv_segment *seg,
int range_format)
{
unsigned int s;
const char *name = NULL;
uint32_t extent = 0;
char extent_str[32];
if (!dm_pool_begin_object(mem, 256)) {
log_error("dm_pool_begin_object failed");
return NULL;
}
for (s = 0; s < seg->area_count; s++) {
switch (seg_type(seg, s)) {
case AREA_LV:
name = seg_lv(seg, s)->name;
extent = seg_le(seg, s);
break;
case AREA_PV:
name = dev_name(seg_dev(seg, s));
extent = seg_pe(seg, s);
break;
case AREA_UNASSIGNED:
name = "unassigned";
extent = 0;
}
if (!dm_pool_grow_object(mem, name, strlen(name))) {
log_error("dm_pool_grow_object failed");
return NULL;
}
if (dm_snprintf(extent_str, sizeof(extent_str),
"%s%" PRIu32 "%s",
range_format ? ":" : "(", extent,
range_format ? "-" : ")") < 0) {
log_error("Extent number dm_snprintf failed");
return NULL;
}
if (!dm_pool_grow_object(mem, extent_str, strlen(extent_str))) {
log_error("dm_pool_grow_object failed");
return NULL;
}
if (range_format) {
if (dm_snprintf(extent_str, sizeof(extent_str),
"%" PRIu32, extent + seg->area_len - 1) < 0) {
log_error("Extent number dm_snprintf failed");
return NULL;
}
if (!dm_pool_grow_object(mem, extent_str, strlen(extent_str))) {
log_error("dm_pool_grow_object failed");
return NULL;
}
}
if ((s != seg->area_count - 1) &&
!dm_pool_grow_object(mem, range_format ? " " : ",", 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);
}
char *lvseg_devices(struct dm_pool *mem, const struct lv_segment *seg)
{
return _format_pvsegs(mem, seg, 0);
}
char *lvseg_seg_pe_ranges(struct dm_pool *mem, const struct lv_segment *seg)
{
return _format_pvsegs(mem, seg, 1);
}
char *lvseg_tags_dup(const struct lv_segment *seg) char *lvseg_tags_dup(const struct lv_segment *seg)
{ {
return tags_format_and_copy(seg->lv->vg->vgmem, &seg->tags); return tags_format_and_copy(seg->lv->vg->vgmem, &seg->tags);

View File

@ -68,5 +68,7 @@ uint64_t lvseg_size(const struct lv_segment *seg);
uint64_t lvseg_chunksize(const struct lv_segment *seg); uint64_t lvseg_chunksize(const struct lv_segment *seg);
char *lvseg_segtype_dup(struct dm_pool *mem, const struct lv_segment *seg); char *lvseg_segtype_dup(struct dm_pool *mem, const struct lv_segment *seg);
char *lvseg_tags_dup(const struct lv_segment *seg); char *lvseg_tags_dup(const struct lv_segment *seg);
char *lvseg_devices(struct dm_pool *mem, const struct lv_segment *seg);
char *lvseg_seg_pe_ranges(struct dm_pool *mem, const struct lv_segment *seg);
#endif /* _LVM_LV_H */ #endif /* _LVM_LV_H */

View File

@ -249,9 +249,10 @@ GET_LVSEG_NUM_PROPERTY_FN(seg_size, (SECTOR_SIZE * lvseg_size(lvseg)))
#define _seg_size_set _not_implemented_set #define _seg_size_set _not_implemented_set
GET_LVSEG_STR_PROPERTY_FN(seg_tags, lvseg_tags_dup(lvseg)) GET_LVSEG_STR_PROPERTY_FN(seg_tags, lvseg_tags_dup(lvseg))
#define _seg_tags_set _not_implemented_set #define _seg_tags_set _not_implemented_set
#define _seg_pe_ranges_get _not_implemented_get GET_LVSEG_STR_PROPERTY_FN(seg_pe_ranges,
lvseg_seg_pe_ranges(lvseg->lv->vg->vgmem, lvseg))
#define _seg_pe_ranges_set _not_implemented_set #define _seg_pe_ranges_set _not_implemented_set
#define _devices_get _not_implemented_get GET_LVSEG_STR_PROPERTY_FN(devices, lvseg_devices(lvseg->lv->vg->vgmem, lvseg))
#define _devices_set _not_implemented_set #define _devices_set _not_implemented_set

View File

@ -56,93 +56,30 @@ static int _dev_name_disp(struct dm_report *rh, struct dm_pool *mem __attribute_
return dm_report_field_string(rh, field, &name); return dm_report_field_string(rh, field, &name);
} }
static int _format_pvsegs(struct dm_pool *mem, struct dm_report_field *field,
const void *data, int range_format)
{
const struct lv_segment *seg = (const struct lv_segment *) data;
unsigned int s;
const char *name = NULL;
uint32_t extent = 0;
char extent_str[32];
if (!dm_pool_begin_object(mem, 256)) {
log_error("dm_pool_begin_object failed");
return 0;
}
for (s = 0; s < seg->area_count; s++) {
switch (seg_type(seg, s)) {
case AREA_LV:
name = seg_lv(seg, s)->name;
extent = seg_le(seg, s);
break;
case AREA_PV:
name = dev_name(seg_dev(seg, s));
extent = seg_pe(seg, s);
break;
case AREA_UNASSIGNED:
name = "unassigned";
extent = 0;
}
if (!dm_pool_grow_object(mem, name, strlen(name))) {
log_error("dm_pool_grow_object failed");
return 0;
}
if (dm_snprintf(extent_str, sizeof(extent_str),
"%s%" PRIu32 "%s",
range_format ? ":" : "(", extent,
range_format ? "-" : ")") < 0) {
log_error("Extent number dm_snprintf failed");
return 0;
}
if (!dm_pool_grow_object(mem, extent_str, strlen(extent_str))) {
log_error("dm_pool_grow_object failed");
return 0;
}
if (range_format) {
if (dm_snprintf(extent_str, sizeof(extent_str),
"%" PRIu32, extent + seg->area_len - 1) < 0) {
log_error("Extent number dm_snprintf failed");
return 0;
}
if (!dm_pool_grow_object(mem, extent_str, strlen(extent_str))) {
log_error("dm_pool_grow_object failed");
return 0;
}
}
if ((s != seg->area_count - 1) &&
!dm_pool_grow_object(mem, range_format ? " " : ",", 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");
return 0;
}
dm_report_field_set_value(field, dm_pool_end_object(mem), NULL);
return 1;
}
static int _devices_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem, static int _devices_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
struct dm_report_field *field, struct dm_report_field *field,
const void *data, void *private __attribute__((unused))) const void *data, void *private __attribute__((unused)))
{ {
return _format_pvsegs(mem, field, data, 0); char *str;
if (!(str = lvseg_devices(mem, (const struct lv_segment *) data)))
return 0;
dm_report_field_set_value(field, str, NULL);
return 1;
} }
static int _peranges_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem, static int _peranges_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
struct dm_report_field *field, struct dm_report_field *field,
const void *data, void *private __attribute__((unused))) const void *data, void *private __attribute__((unused)))
{ {
return _format_pvsegs(mem, field, data, 1); char *str;
if (!(str = lvseg_seg_pe_ranges(mem, (const struct lv_segment *) data)))
return 0;
dm_report_field_set_value(field, str, NULL);
return 1;
} }
static int _tags_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem, static int _tags_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,

View File

@ -873,6 +873,10 @@ static void _lvsegs_in_lv(char **argv, int argc)
_print_property_value("seg_start_pe", v); _print_property_value("seg_start_pe", v);
v = lvm_lvseg_get_property(lvl->lvseg, "seg_size"); v = lvm_lvseg_get_property(lvl->lvseg, "seg_size");
_print_property_value("seg_size", v); _print_property_value("seg_size", v);
v = lvm_lvseg_get_property(lvl->lvseg, "devices");
_print_property_value("devices", v);
v = lvm_lvseg_get_property(lvl->lvseg, "seg_pe_ranges");
_print_property_value("seg_pe_ranges", v);
} }
} }