lvseg properties for lvm2app, 'devices' and 'seg_pe_ranges'.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Reviewed-by: Petr Rockai <prockai@redhat.com>
#include "segtype.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)
{
return tags_format_and_copy(seg->lv->vg->vgmem, &seg->tags);
uint64_t lvseg_chunksize(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_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 */
#define _seg_size_set _not_implemented_set
GET_LVSEG_STR_PROPERTY_FN(seg_tags, lvseg_tags_dup(lvseg))
#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 _devices_get _not_implemented_get
+GET_LVSEG_STR_PROPERTY_FN(devices, lvseg_devices(lvseg->lv->vg->vgmem, lvseg))
#define _devices_set _not_implemented_set
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)
+static int _devices_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private __attribute__((unused)))
{
- 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");
+ char *str;
+ if (!(str = lvseg_devices(mem, (const struct lv_segment *) data)))
return 0;
- }
- dm_report_field_set_value(field, dm_pool_end_object(mem), NULL);
+ dm_report_field_set_value(field, str, NULL);
return 1;
}
-static int _devices_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
- struct dm_report_field *field,
- const void *data, void *private __attribute__((unused)))
-{
- return _format_pvsegs(mem, field, data, 0);
-}
-
static int _peranges_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
struct dm_report_field *field,
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,
_print_property_value("seg_start_pe", v);
v = lvm_lvseg_get_property(lvl->lvseg, "seg_size");
_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);
}
}