From: Dave Wysochanski Date: Mon, 2 Feb 2009 15:50:07 -0500 Subject: [PATCH 11/13] Add lvm_lv_get_attr_list() and lvm_lv_get_attr_value(). In-Reply-To: <1233607809-1087-11-git-send-email-dwysocha@redhat.com> References: <1233607809-1087-1-git-send-email-dwysocha@redhat.com> <1233607809-1087-2-git-send-email-dwysocha@redhat.com> <1233607809-1087-3-git-send-email-dwysocha@redhat.com> <1233607809-1087-4-git-send-email-dwysocha@redhat.com> <1233607809-1087-5-git-send-email-dwysocha@redhat.com> <1233607809-1087-6-git-send-email-dwysocha@redhat.com> <1233607809-1087-7-git-send-email-dwysocha@redhat.com> <1233607809-1087-8-git-send-email-dwysocha@redhat.com> <1233607809-1087-9-git-send-email-dwysocha@redhat.com> <1233607809-1087-10-git-send-email-dwysocha@redhat.com> <1233607809-1087-11-git-send-email-dwysocha@redhat.com> Message-ID: <1233607809-1087-12-git-send-email-dwysocha@redhat.com> List-Id: To: lvm-devel@redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Signed-off-by: Dave Wysochanski --- 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