From: Dave Wysochanski <dwysocha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 01/12] Add vg_attr() and lv_attr() functions.
Date: Thu, 9 Sep 2010 16:12:58 -0400 [thread overview]
Message-ID: <1284063189-4908-2-git-send-email-dwysocha@redhat.com> (raw)
In-Reply-To: <1284063189-4908-1-git-send-email-dwysocha@redhat.com>
Move the creating of the 'attr' strings into a common function so
they can be called from the 'disp' functions as well as the new
'get' property functions.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/metadata.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++
lib/metadata/metadata.h | 2 +
lib/report/report.c | 157 +------------------------------------------
3 files changed, 175 insertions(+), 155 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index d14c33c..094ffc1 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4544,6 +4544,177 @@ uint32_t vg_mda_used_count(const struct volume_group *vg)
return used_count;
}
+static char _alloc_policy_char(alloc_policy_t alloc)
+{
+ switch (alloc) {
+ case ALLOC_CONTIGUOUS:
+ return 'c';
+ case ALLOC_CLING:
+ return 'l';
+ case ALLOC_NORMAL:
+ return 'n';
+ case ALLOC_ANYWHERE:
+ return 'a';
+ default:
+ return 'i';
+ }
+}
+
+char *vg_attr(struct dm_pool *mem, const struct volume_group *vg)
+{
+ char *repstr;
+
+ if (!(repstr = dm_pool_zalloc(mem, 7))) {
+ log_error("dm_pool_alloc failed");
+ return NULL;
+ }
+
+ if (vg->status & LVM_WRITE)
+ repstr[0] = 'w';
+ else
+ repstr[0] = 'r';
+
+ if (vg_is_resizeable(vg))
+ repstr[1] = 'z';
+ else
+ repstr[1] = '-';
+
+ if (vg_is_exported(vg))
+ repstr[2] = 'x';
+ else
+ repstr[2] = '-';
+
+ if (vg_missing_pv_count(vg))
+ repstr[3] = 'p';
+ else
+ repstr[3] = '-';
+
+ repstr[4] = _alloc_policy_char(vg->alloc);
+
+ if (vg_is_clustered(vg))
+ repstr[5] = 'c';
+ else
+ repstr[5] = '-';
+ return repstr;
+}
+
+static int _lv_mimage_in_sync(const struct logical_volume *lv)
+{
+ float percent;
+ percent_range_t percent_range;
+ struct lv_segment *mirror_seg = find_mirror_seg(first_seg(lv));
+
+ if (!(lv->status & MIRROR_IMAGE) || !mirror_seg)
+ return_0;
+
+ if (!lv_mirror_percent(lv->vg->cmd, mirror_seg->lv, 0, &percent,
+ &percent_range, NULL))
+ return_0;
+
+ return (percent_range == PERCENT_100) ? 1 : 0;
+}
+
+char *lv_attr(struct dm_pool *mem, const struct logical_volume *lv)
+{
+ float snap_percent;
+ percent_range_t percent_range;
+ struct lvinfo info;
+ char *repstr;
+
+ if (!(repstr = dm_pool_zalloc(mem, 7))) {
+ log_error("dm_pool_alloc failed");
+ return 0;
+ }
+
+ /* Blank if this is a "free space" LV. */
+ if (!*lv->name)
+ goto out;
+
+ if (lv->status & PVMOVE)
+ repstr[0] = 'p';
+ else if (lv->status & CONVERTING)
+ repstr[0] = 'c';
+ else if (lv->status & VIRTUAL)
+ repstr[0] = 'v';
+ /* Origin takes precedence over Mirror */
+ else if (lv_is_origin(lv)) {
+ if (lv_is_merging_origin(lv))
+ repstr[0] = 'O';
+ else
+ repstr[0] = 'o';
+ }
+ else if (lv->status & MIRRORED) {
+ if (lv->status & MIRROR_NOTSYNCED)
+ repstr[0] = 'M';
+ else
+ repstr[0] = 'm';
+ }else if (lv->status & MIRROR_IMAGE)
+ if (_lv_mimage_in_sync(lv))
+ repstr[0] = 'i';
+ else
+ repstr[0] = 'I';
+ else if (lv->status & MIRROR_LOG)
+ repstr[0] = 'l';
+ else if (lv_is_cow(lv)) {
+ if (lv_is_merging_cow(lv))
+ repstr[0] = 'S';
+ else
+ repstr[0] = 's';
+ } else
+ repstr[0] = '-';
+
+ if (lv->status & PVMOVE)
+ repstr[1] = '-';
+ else if (lv->status & LVM_WRITE)
+ repstr[1] = 'w';
+ else if (lv->status & LVM_READ)
+ repstr[1] = 'r';
+ else
+ repstr[1] = '-';
+
+ repstr[2] = _alloc_policy_char(lv->alloc);
+
+ if (lv->status & LOCKED)
+ repstr[2] = toupper(repstr[2]);
+
+ if (lv->status & FIXED_MINOR)
+ repstr[3] = 'm'; /* Fixed Minor */
+ else
+ repstr[3] = '-';
+
+ if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) && info.exists) {
+ if (info.suspended)
+ repstr[4] = 's'; /* Suspended */
+ else if (info.live_table)
+ repstr[4] = 'a'; /* Active */
+ else if (info.inactive_table)
+ repstr[4] = 'i'; /* Inactive with table */
+ else
+ repstr[4] = 'd'; /* Inactive without table */
+
+ /* Snapshot dropped? */
+ if (info.live_table && lv_is_cow(lv) &&
+ (!lv_snapshot_percent(lv, &snap_percent, &percent_range) ||
+ percent_range == PERCENT_INVALID)) {
+ repstr[0] = toupper(repstr[0]);
+ if (info.suspended)
+ repstr[4] = 'S'; /* Susp Inv snapshot */
+ else
+ repstr[4] = 'I'; /* Invalid snapshot */
+ }
+
+ if (info.open_count)
+ repstr[5] = 'o'; /* Open */
+ else
+ repstr[5] = '-';
+ } else {
+ repstr[4] = '-';
+ repstr[5] = '-';
+ }
+out:
+ return repstr;
+}
+
uint64_t lv_size(const struct logical_volume *lv)
{
return lv->size;
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index b570cee..f3e268c 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -419,5 +419,7 @@ int is_mirror_image_removable(struct logical_volume *mimage_lv, void *baton);
uint64_t find_min_mda_size(struct dm_list *mdas);
uint64_t vg_mda_size(const struct volume_group *vg);
uint64_t vg_mda_free(const struct volume_group *vg);
+char *vg_attr(struct dm_pool *mem, const struct volume_group *vg);
+char *lv_attr(struct dm_pool *mem, const struct logical_volume *lv);
#endif
diff --git a/lib/report/report.c b/lib/report/report.c
index 703060b..2de78a1 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -34,22 +34,6 @@ struct lvm_report_object {
struct pv_segment *pvseg;
};
-static char _alloc_policy_char(alloc_policy_t alloc)
-{
- switch (alloc) {
- case ALLOC_CONTIGUOUS:
- return 'c';
- case ALLOC_CLING:
- return 'l';
- case ALLOC_NORMAL:
- return 'n';
- case ALLOC_ANYWHERE:
- return 'a';
- default:
- return 'i';
- }
-}
-
static const uint64_t _minusone64 = UINT64_C(-1);
static const int32_t _minusone32 = INT32_C(-1);
@@ -264,124 +248,16 @@ static int _lvkmin_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
return dm_report_field_int32(rh, field, &_minusone32);
}
-static int _lv_mimage_in_sync(const struct logical_volume *lv)
-{
- float percent;
- percent_range_t percent_range;
- struct lv_segment *mirror_seg = find_mirror_seg(first_seg(lv));
-
- if (!(lv->status & MIRROR_IMAGE) || !mirror_seg)
- return_0;
-
- if (!lv_mirror_percent(lv->vg->cmd, mirror_seg->lv, 0, &percent,
- &percent_range, NULL))
- return_0;
-
- return (percent_range == PERCENT_100) ? 1 : 0;
-}
-
static int _lvstatus_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 logical_volume *lv = (const struct logical_volume *) data;
- struct lvinfo info;
char *repstr;
- float snap_percent;
- percent_range_t percent_range;
- if (!(repstr = dm_pool_zalloc(mem, 7))) {
- log_error("dm_pool_alloc failed");
+ if (!(repstr = lv_attr(mem, lv)))
return 0;
- }
-
- /* Blank if this is a "free space" LV. */
- if (!*lv->name)
- goto out;
-
- if (lv->status & PVMOVE)
- repstr[0] = 'p';
- else if (lv->status & CONVERTING)
- repstr[0] = 'c';
- else if (lv->status & VIRTUAL)
- repstr[0] = 'v';
- /* Origin takes precedence over Mirror */
- else if (lv_is_origin(lv)) {
- if (lv_is_merging_origin(lv))
- repstr[0] = 'O';
- else
- repstr[0] = 'o';
- }
- else if (lv->status & MIRRORED) {
- if (lv->status & MIRROR_NOTSYNCED)
- repstr[0] = 'M';
- else
- repstr[0] = 'm';
- }else if (lv->status & MIRROR_IMAGE)
- if (_lv_mimage_in_sync(lv))
- repstr[0] = 'i';
- else
- repstr[0] = 'I';
- else if (lv->status & MIRROR_LOG)
- repstr[0] = 'l';
- else if (lv_is_cow(lv)) {
- if (lv_is_merging_cow(lv))
- repstr[0] = 'S';
- else
- repstr[0] = 's';
- } else
- repstr[0] = '-';
- if (lv->status & PVMOVE)
- repstr[1] = '-';
- else if (lv->status & LVM_WRITE)
- repstr[1] = 'w';
- else if (lv->status & LVM_READ)
- repstr[1] = 'r';
- else
- repstr[1] = '-';
-
- repstr[2] = _alloc_policy_char(lv->alloc);
-
- if (lv->status & LOCKED)
- repstr[2] = toupper(repstr[2]);
-
- if (lv->status & FIXED_MINOR)
- repstr[3] = 'm'; /* Fixed Minor */
- else
- repstr[3] = '-';
-
- if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) && info.exists) {
- if (info.suspended)
- repstr[4] = 's'; /* Suspended */
- else if (info.live_table)
- repstr[4] = 'a'; /* Active */
- else if (info.inactive_table)
- repstr[4] = 'i'; /* Inactive with table */
- else
- repstr[4] = 'd'; /* Inactive without table */
-
- /* Snapshot dropped? */
- if (info.live_table && lv_is_cow(lv) &&
- (!lv_snapshot_percent(lv, &snap_percent, &percent_range) ||
- percent_range == PERCENT_INVALID)) {
- repstr[0] = toupper(repstr[0]);
- if (info.suspended)
- repstr[4] = 'S'; /* Susp Inv snapshot */
- else
- repstr[4] = 'I'; /* Invalid snapshot */
- }
-
- if (info.open_count)
- repstr[5] = 'o'; /* Open */
- else
- repstr[5] = '-';
- } else {
- repstr[4] = '-';
- repstr[5] = '-';
- }
-
-out:
dm_report_field_set_value(field, repstr, NULL);
return 1;
}
@@ -419,37 +295,8 @@ static int _vgstatus_disp(struct dm_report *rh __attribute__((unused)), struct d
const struct volume_group *vg = (const struct volume_group *) data;
char *repstr;
- if (!(repstr = dm_pool_zalloc(mem, 7))) {
- log_error("dm_pool_alloc failed");
+ if (!(repstr = vg_attr(mem, vg)))
return 0;
- }
-
- if (vg->status & LVM_WRITE)
- repstr[0] = 'w';
- else
- repstr[0] = 'r';
-
- if (vg_is_resizeable(vg))
- repstr[1] = 'z';
- else
- repstr[1] = '-';
-
- if (vg_is_exported(vg))
- repstr[2] = 'x';
- else
- repstr[2] = '-';
-
- if (vg_missing_pv_count(vg))
- repstr[3] = 'p';
- else
- repstr[3] = '-';
-
- repstr[4] = _alloc_policy_char(vg->alloc);
-
- if (vg_is_clustered(vg))
- repstr[5] = 'c';
- else
- repstr[5] = '-';
dm_report_field_set_value(field, repstr, NULL);
return 1;
--
1.7.2.1
next prev parent reply other threads:[~2010-09-09 20:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-09 20:12 [PATCH 00/12] Add lvm vg properties for lvm2app Dave Wysochanski
2010-09-09 20:12 ` Dave Wysochanski [this message]
2010-09-10 9:28 ` [PATCH 01/12] Add vg_attr() and lv_attr() functions Zdenek Kabelac
2010-09-10 16:54 ` [PATCH] Simplify logic to create 'attr' strings Dave Wysochanski
2010-09-09 20:12 ` [PATCH 02/12] Refactor pvstatus_disp to take pv argument and call common pv_attr function Dave Wysochanski
2010-09-09 20:13 ` [PATCH 03/12] Add id_format_and_copy() uuid function to allocate and format a uuid Dave Wysochanski
2010-09-10 9:30 ` Zdenek Kabelac
2010-09-10 16:56 ` Dave Wysochanski
2010-09-09 20:13 ` [PATCH 04/12] Call id_format_and_copy from _uuid_disp Dave Wysochanski
2010-09-09 20:13 ` [PATCH 05/12] Add pv_uuid, vg_uuid, and lv_uuid, and call id_format_and_copy Dave Wysochanski
2010-09-10 9:38 ` Zdenek Kabelac
2010-09-10 17:25 ` Dave Wysochanski
2010-09-09 20:13 ` [PATCH 06/12] Add tags_format_and_copy() common function to format tags strings Dave Wysochanski
2010-09-09 20:13 ` [PATCH 07/12] Add pv_tags, vg_tags, lv_tags functions that call tags_format_and_copy Dave Wysochanski
2010-09-09 20:13 ` [PATCH 08/12] Add GET_STR_PROPERTY_FN macro Dave Wysochanski
2010-09-09 20:13 ` [PATCH 09/12] Add 'get' functions for a few vg string fields, vg_name, vg_fmt, vg_sysid Dave Wysochanski
2010-09-09 20:13 ` [PATCH 10/12] Add vg_uuid, vg_attr, vg_tags 'get' functions Dave Wysochanski
2010-09-09 20:13 ` [PATCH 11/12] Add lvm_vg_get_property() generic vg property function Dave Wysochanski
2010-09-09 20:13 ` [PATCH 12/12] Add tests for lvm_vg_get_property() Dave Wysochanski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1284063189-4908-2-git-send-email-dwysocha@redhat.com \
--to=dwysocha@redhat.com \
--cc=lvm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.