[lvm-devel] [PATCH 11/13] Add lvm_lv_get_attr_list() and lvm_lv_get_attr_value().
Dave Wysochanski
dwysocha at redhat.com
Mon Feb 2 20:50:07 UTC 2009
Signed-off-by: Dave Wysochanski <dwysocha at redhat.com>
---
lib/lvm2.h | 3 ++
lib/report/report.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/lib/lvm2.h b/lib/lvm2.h
index 25ce12d..2a5dd9e 100644
--- a/lib/lvm2.h
+++ b/lib/lvm2.h
@@ -91,6 +91,9 @@ struct lvm_lv_list {
};
struct dm_list *lvm_lvs_in_vg(vg_t *vg);
+int lvm_lv_get_attr_list(lv_t *lv, struct dm_list *list);
+int lvm_lv_get_attr_value(lv_t *lv, const char *attr_name,
+ struct dm_report_field_value_type *value);
/*
* FIXME: struct lvm_pv_list is not equivalent to struct pv_list, which
* is used in lvm_pvs_in_vg(). Ideally we should not need a new structure.
diff --git a/lib/report/report.c b/lib/report/report.c
index 1216fff..70bc3bd 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -1247,3 +1247,60 @@ int lvm_vg_get_attr_value(vg_t *vg, const char *attr_name,
dm_report_free(rh);
return 1;
}
+
+
+/*
+ * Get a list of attributes for a LV
+ */
+int lvm_lv_get_attr_list(lv_t *lv, struct dm_list *list)
+{
+ void *rh;
+ report_type_t report_type = LVS;
+
+ dm_list_init(list);
+
+ /*
+ * Create a report so we can return the headings.
+ */
+ if (!(rh = report_init(lv->vg->cmd, "all", "", &report_type,
+ " ", 1, 1, 1, 0, 0, 0))) {
+ stack;
+ return 0;
+ }
+
+ if (!dm_report_get_field_ids(rh, report_type, list)) {
+ dm_report_free(rh);
+ return 0;
+ }
+
+ dm_report_free(rh);
+ return 1;
+}
+
+/*
+ * Get the value of the LV attribute 'attr_name'.
+ */
+int lvm_lv_get_attr_value(lv_t *lv, const char *attr_name,
+ struct dm_report_field_value_type *value)
+{
+ void *rh;
+ report_type_t report_type = LVS;
+
+ if (!(rh = report_init(lv->vg->cmd, attr_name, "", &report_type,
+ " ", 1, 1, 1, 0, 0, 0))) {
+ stack;
+ return 0;
+ }
+
+ if (!report_object(rh, NULL, lv, NULL, NULL, NULL)) {
+ stack;
+ return 0;
+ }
+
+ if (!dm_report_get_field_value(rh, value)) {
+ stack;
+ return 0;
+ }
+ dm_report_free(rh);
+ return 1;
+}
--
1.5.5.1
More information about the lvm-devel
mailing list