From: Benjamin Gilbert Date: Wed, 16 Apr 2014 13:35:56 +0000 (-0400) Subject: lvm: Ignore virtual volumes X-Git-Tag: collectd-5.5.0~232^2~5 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ce0fa035d80b482c00baf602f73bc0560991b6fb;p=collectd.git lvm: Ignore virtual volumes The sum of the sizes reported by a volume group should equal the size of the volume group. Virtual volumes do not directly correspond to allocated storage (and, in fact, may be larger than the entire volume group), so must be ignored. --- diff --git a/src/lvm.c b/src/lvm.c index 606acc70..1677f056 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -49,12 +49,31 @@ static void vg_read(vg_t vg, char const *vg_name) { struct dm_list *lvs; struct lvm_lv_list *lvl; + char const *attrs; lvm_submit (vg_name, "free", lvm_vg_get_free_size(vg)); lvs = lvm_vg_list_lvs(vg); dm_list_iterate_items(lvl, lvs) { - lvm_submit(vg_name, lvm_lv_get_name(lvl->lv), lvm_lv_get_size(lvl->lv)); + attrs = lvm_lv_get_attr(lvl->lv); + if (attrs == NULL) + continue; + /* Condition on volume type. We want the reported sizes in the + volume group to sum to the size of the volume group, so we ignore + virtual volumes. */ + switch (attrs[0]) { + case 't': + /* Thin pool virtual volume. We report the underlying data + and metadata volumes, not this one. Ignore. */ + continue; + case 'v': + /* Virtual volume. Ignore. */ + continue; + case 'V': + /* Thin volume or thin snapshot. Ignore. */ + continue; + } + lvm_submit(vg_name, lvm_lv_get_name(lvl->lv), lvm_lv_get_size(lvl->lv)); } }