* [PATCH 01/20] Refactor metadata.[ch] into vg.[ch] for vg functions.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 02/20] Refactor metadata.[ch] into pv.[ch] for pv functions Dave Wysochanski
` (18 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
The metadata.[ch] files are very large. This patch makes a first
attempt at separating out vg functions and data, particularly
related to the reporting fields calculations.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
include/.symlinks.in | 1 +
lib/Makefile.in | 1 +
lib/metadata/metadata-exported.h | 99 +---------
lib/metadata/metadata.c | 418 ------------------------------------
lib/metadata/metadata.h | 7 -
lib/metadata/vg.c | 436 ++++++++++++++++++++++++++++++++++++++
lib/metadata/vg.h | 127 +++++++++++
7 files changed, 567 insertions(+), 522 deletions(-)
create mode 100644 lib/metadata/vg.c
create mode 100644 lib/metadata/vg.h
diff --git a/include/.symlinks.in b/include/.symlinks.in
index 2b15844..4dca46f 100644
--- a/include/.symlinks.in
+++ b/include/.symlinks.in
@@ -35,6 +35,7 @@
@top_srcdir@/lib/metadata/metadata-exported.h
@top_srcdir@/lib/metadata/pv_alloc.h
@top_srcdir@/lib/metadata/segtype.h
+ at top_srcdir@/lib/metadata/vg.h
@top_srcdir@/lib/mm/memlock.h
@top_srcdir@/lib/mm/xlate.h
@top_builddir@/lib/misc/configure.h
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 2f31c04..172a0fd 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -82,6 +82,7 @@ SOURCES =\
metadata/replicator_manip.c \
metadata/segtype.c \
metadata/snapshot_manip.c \
+ metadata/vg.c \
misc/crc.c \
misc/lvm-exec.c \
misc/lvm-file.c \
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index a72a6bf..fef6903 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -22,6 +22,7 @@
#define _LVM_METADATA_EXPORTED_H
#include "uuid.h"
+#include "vg.h"
#define MAX_STRIPES 128U
#define SECTOR_SHIFT 9L
@@ -122,15 +123,6 @@
/* Ordered list - see lv_manip.c */
typedef enum {
- ALLOC_INVALID,
- ALLOC_CONTIGUOUS,
- ALLOC_CLING,
- ALLOC_NORMAL,
- ALLOC_ANYWHERE,
- ALLOC_INHERIT
-} alloc_policy_t;
-
-typedef enum {
AREA_UNASSIGNED,
AREA_PV,
AREA_LV
@@ -229,70 +221,6 @@ struct format_instance {
void *private;
};
-struct volume_group {
- struct cmd_context *cmd;
- struct dm_pool *vgmem;
- struct format_instance *fid;
- struct dm_list *cmd_vgs;/* List of wanted/locked and opened VGs */
- uint32_t cmd_missing_vgs;/* Flag marks missing VG */
- uint32_t seqno; /* Metadata sequence number */
-
- alloc_policy_t alloc;
- uint64_t status;
-
- struct id id;
- char *name;
- char *old_name; /* Set during vgrename and vgcfgrestore */
- char *system_id;
-
- uint32_t extent_size;
- uint32_t extent_count;
- uint32_t free_count;
-
- uint32_t max_lv;
- uint32_t max_pv;
-
- /* physical volumes */
- uint32_t pv_count;
- struct dm_list pvs;
-
- /*
- * logical volumes
- * The following relationship should always hold:
- * dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs
- *
- * Snapshots consist of 2 instances of "struct logical_volume":
- * - cow (lv_name is visible to the user)
- * - snapshot (lv_name is 'snapshotN')
- *
- * Mirrors consist of multiple instances of "struct logical_volume":
- * - one for the mirror log
- * - one for each mirror leg
- * - one for the user-visible mirror LV
- */
- struct dm_list lvs;
-
- struct dm_list tags;
-
- /*
- * FIXME: Move the next fields into a different struct?
- */
-
- /*
- * List of removed physical volumes by pvreduce.
- * They have to get cleared on vg_commit.
- */
- struct dm_list removed_pvs;
- uint32_t open_mode; /* FIXME: read or write - check lock type? */
-
- /*
- * Store result of the last vg_read().
- * 0 for success else appropriate FAILURE_* bits set.
- */
- uint32_t read_status;
- uint32_t mda_copies; /* target number of mdas for this VG */
-};
-
/* There will be one area for each stripe */
struct lv_segment_area {
area_type_t type;
@@ -501,6 +429,7 @@ int is_global_vg(const char *vg_name);
int is_orphan_vg(const char *vg_name);
int is_orphan(const struct physical_volume *pv);
int is_missing_pv(const struct physical_volume *pv);
+int vg_missing_pv_count(const struct volume_group *vg);
int vgs_are_compatible(struct cmd_context *cmd,
struct volume_group *vg_from,
struct volume_group *vg_to);
@@ -552,11 +481,6 @@ int vg_extend(struct volume_group *vg, int pv_count, char **pv_names,
struct pvcreate_params *pp);
int vg_reduce(struct volume_group *vg, char *pv_name);
int vg_change_tag(struct volume_group *vg, const char *tag, int add_tag);
-int vg_set_extent_size(struct volume_group *vg, uint32_t new_extent_size);
-int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv);
-int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv);
-int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc);
-int vg_set_clustered(struct volume_group *vg, int clustered);
int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
struct volume_group *vg_to);
/* FIXME: Investigate refactoring these functions to take a pv ISO pv_list */
@@ -746,10 +670,6 @@ int vg_remove_snapshot(struct logical_volume *cow);
int vg_check_status(const struct volume_group *vg, uint64_t status);
-/*
- * Returns visible LV count - number of LVs from user perspective
- */
-unsigned vg_visible_lvs(const struct volume_group *vg);
/*
* Check if the VG reached maximal LVs count (if set)
@@ -876,21 +796,6 @@ int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignore);
uint64_t lv_size(const struct logical_volume *lv);
-int vg_missing_pv_count(const struct volume_group *vg);
-uint32_t vg_seqno(const struct volume_group *vg);
-uint64_t vg_status(const struct volume_group *vg);
-uint64_t vg_size(const struct volume_group *vg);
-uint64_t vg_free(const struct volume_group *vg);
-uint64_t vg_extent_size(const struct volume_group *vg);
-uint64_t vg_extent_count(const struct volume_group *vg);
-uint64_t vg_free_count(const struct volume_group *vg);
-uint64_t vg_pv_count(const struct volume_group *vg);
-uint64_t vg_max_pv(const struct volume_group *vg);
-uint64_t vg_max_lv(const struct volume_group *vg);
-uint32_t vg_mda_count(const struct volume_group *vg);
-uint32_t vg_mda_used_count(const struct volume_group *vg);
-uint32_t vg_mda_copies(const struct volume_group *vg);
-int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies);
int vg_check_write_mode(struct volume_group *vg);
#define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED)
#define vg_is_exported(vg) (vg_status((vg)) & EXPORTED_VG)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index d14c33c..ca741b2 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1020,31 +1020,6 @@ uint64_t extents_from_size(struct cmd_context *cmd, uint64_t size,
return (uint64_t) size / extent_size;
}
-static int _recalc_extents(uint32_t *extents, const char *desc1,
- const char *desc2, uint32_t old_size,
- uint32_t new_size)
-{
- uint64_t size = (uint64_t) old_size * (*extents);
-
- if (size % new_size) {
- log_error("New size %" PRIu64 " for %s%s not an exact number "
- "of new extents.", size, desc1, desc2);
- return 0;
- }
-
- size /= new_size;
-
- if (size > UINT32_MAX) {
- log_error("New extent count %" PRIu64 " for %s%s exceeds "
- "32 bits.", size, desc1, desc2);
- return 0;
- }
-
- *extents = (uint32_t) size;
-
- return 1;
-}
-
static dm_bitset_t _bitset_with_random_bits(struct dm_pool *mem, uint32_t num_bits,
uint32_t num_set_bits, unsigned *seed)
{
@@ -1219,22 +1194,6 @@ static int _vg_adjust_ignored_mdas(struct volume_group *vg)
return 1;
}
-uint32_t vg_mda_copies(const struct volume_group *vg)
-{
- return vg->mda_copies;
-}
-
-int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies)
-{
- vg->mda_copies = mda_copies;
-
- /* FIXME Use log_verbose when this is due to specific cmdline request. */
- log_debug("Setting mda_copies to %"PRIu32" for VG %s",
- mda_copies, vg->name);
-
- return 1;
-}
-
uint64_t find_min_mda_size(struct dm_list *mdas)
{
uint64_t min_mda_size = UINT64_MAX, mda_size;
@@ -1254,285 +1213,6 @@ uint64_t find_min_mda_size(struct dm_list *mdas)
return min_mda_size;
}
-uint64_t vg_mda_size(const struct volume_group *vg)
-{
- return find_min_mda_size(&vg->fid->metadata_areas_in_use);
-}
-
-uint64_t vg_mda_free(const struct volume_group *vg)
-{
- uint64_t freespace = UINT64_MAX, mda_free;
- struct metadata_area *mda;
-
- dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
- if (!mda->ops->mda_free_sectors)
- continue;
- mda_free = mda->ops->mda_free_sectors(mda);
- if (mda_free < freespace)
- freespace = mda_free;
- }
-
- if (freespace == UINT64_MAX)
- freespace = UINT64_C(0);
- return freespace;
-}
-
-int vg_set_extent_size(struct volume_group *vg, uint32_t new_size)
-{
- uint32_t old_size = vg->extent_size;
- struct pv_list *pvl;
- struct lv_list *lvl;
- struct physical_volume *pv;
- struct logical_volume *lv;
- struct lv_segment *seg;
- struct pv_segment *pvseg;
- uint32_t s;
-
- if (!vg_is_resizeable(vg)) {
- log_error("Volume group \"%s\" must be resizeable "
- "to change PE size", vg->name);
- return 0;
- }
-
- if (!new_size) {
- log_error("Physical extent size may not be zero");
- return 0;
- }
-
- if (new_size == vg->extent_size)
- return 1;
-
- if (new_size & (new_size - 1)) {
- log_error("Physical extent size must be a power of 2.");
- return 0;
- }
-
- if (new_size > vg->extent_size) {
- if ((uint64_t) vg_size(vg) % new_size) {
- /* FIXME Adjust used PV sizes instead */
- log_error("New extent size is not a perfect fit");
- return 0;
- }
- }
-
- vg->extent_size = new_size;
-
- if (vg->fid->fmt->ops->vg_setup &&
- !vg->fid->fmt->ops->vg_setup(vg->fid, vg))
- return_0;
-
- if (!_recalc_extents(&vg->extent_count, vg->name, "", old_size,
- new_size))
- return_0;
-
- if (!_recalc_extents(&vg->free_count, vg->name, " free space",
- old_size, new_size))
- return_0;
-
- /* foreach PV */
- dm_list_iterate_items(pvl, &vg->pvs) {
- pv = pvl->pv;
-
- pv->pe_size = new_size;
- if (!_recalc_extents(&pv->pe_count, pv_dev_name(pv), "",
- old_size, new_size))
- return_0;
-
- if (!_recalc_extents(&pv->pe_alloc_count, pv_dev_name(pv),
- " allocated space", old_size, new_size))
- return_0;
-
- /* foreach free PV Segment */
- dm_list_iterate_items(pvseg, &pv->segments) {
- if (pvseg_is_allocated(pvseg))
- continue;
-
- if (!_recalc_extents(&pvseg->pe, pv_dev_name(pv),
- " PV segment start", old_size,
- new_size))
- return_0;
- if (!_recalc_extents(&pvseg->len, pv_dev_name(pv),
- " PV segment length", old_size,
- new_size))
- return_0;
- }
- }
-
- /* foreach LV */
- dm_list_iterate_items(lvl, &vg->lvs) {
- lv = lvl->lv;
-
- if (!_recalc_extents(&lv->le_count, lv->name, "", old_size,
- new_size))
- return_0;
-
- dm_list_iterate_items(seg, &lv->segments) {
- if (!_recalc_extents(&seg->le, lv->name,
- " segment start", old_size,
- new_size))
- return_0;
-
- if (!_recalc_extents(&seg->len, lv->name,
- " segment length", old_size,
- new_size))
- return_0;
-
- if (!_recalc_extents(&seg->area_len, lv->name,
- " area length", old_size,
- new_size))
- return_0;
-
- if (!_recalc_extents(&seg->extents_copied, lv->name,
- " extents moved", old_size,
- new_size))
- return_0;
-
- /* foreach area */
- for (s = 0; s < seg->area_count; s++) {
- switch (seg_type(seg, s)) {
- case AREA_PV:
- if (!_recalc_extents
- (&seg_pe(seg, s),
- lv->name,
- " pvseg start", old_size,
- new_size))
- return_0;
- if (!_recalc_extents
- (&seg_pvseg(seg, s)->len,
- lv->name,
- " pvseg length", old_size,
- new_size))
- return_0;
- break;
- case AREA_LV:
- if (!_recalc_extents
- (&seg_le(seg, s), lv->name,
- " area start", old_size,
- new_size))
- return_0;
- break;
- case AREA_UNASSIGNED:
- log_error("Unassigned area %u found in "
- "segment", s);
- return 0;
- }
- }
- }
-
- }
-
- return 1;
-}
-
-int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv)
-{
- if (!vg_is_resizeable(vg)) {
- log_error("Volume group \"%s\" must be resizeable "
- "to change MaxLogicalVolume", vg->name);
- return 0;
- }
-
- if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) {
- if (!max_lv)
- max_lv = 255;
- else if (max_lv > 255) {
- log_error("MaxLogicalVolume limit is 255");
- return 0;
- }
- }
-
- if (max_lv && max_lv < vg_visible_lvs(vg)) {
- log_error("MaxLogicalVolume is less than the current number "
- "%d of LVs for %s", vg_visible_lvs(vg),
- vg->name);
- return 0;
- }
- vg->max_lv = max_lv;
-
- return 1;
-}
-
-int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv)
-{
- if (!vg_is_resizeable(vg)) {
- log_error("Volume group \"%s\" must be resizeable "
- "to change MaxPhysicalVolumes", vg->name);
- return 0;
- }
-
- if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) {
- if (!max_pv)
- max_pv = 255;
- else if (max_pv > 255) {
- log_error("MaxPhysicalVolume limit is 255");
- return 0;
- }
- }
-
- if (max_pv && max_pv < vg->pv_count) {
- log_error("MaxPhysicalVolumes is less than the current number "
- "%d of PVs for \"%s\"", vg->pv_count,
- vg->name);
- return 0;
- }
- vg->max_pv = max_pv;
- return 1;
-}
-
-int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc)
-{
- if (alloc == ALLOC_INHERIT) {
- log_error("Volume Group allocation policy cannot inherit "
- "from anything");
- return 0;
- }
-
- if (alloc == vg->alloc)
- return 1;
-
- vg->alloc = alloc;
- return 1;
-}
-
-int vg_set_clustered(struct volume_group *vg, int clustered)
-{
- struct lv_list *lvl;
-
- /*
- * We do not currently support switching the cluster attribute
- * on active mirrors or snapshots.
- */
- dm_list_iterate_items(lvl, &vg->lvs) {
- if (lv_is_mirrored(lvl->lv) && lv_is_active(lvl->lv)) {
- log_error("Mirror logical volumes must be inactive "
- "when changing the cluster attribute.");
- return 0;
- }
-
- if (clustered) {
- if (lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) {
- log_error("Volume group %s contains snapshots "
- "that are not yet supported.",
- vg->name);
- return 0;
- }
- }
-
- if ((lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) &&
- lv_is_active(lvl->lv)) {
- log_error("Snapshot logical volumes must be inactive "
- "when changing the cluster attribute.");
- return 0;
- }
- }
-
- if (clustered)
- vg->status |= CLUSTERED;
- else
- vg->status &= ~CLUSTERED;
- return 1;
-}
-
static int _move_mdas(struct volume_group *vg_from, struct volume_group *vg_to,
struct dm_list *mdas_from, struct dm_list *mdas_to)
{
@@ -2167,31 +1847,6 @@ int vg_remove_mdas(struct volume_group *vg)
return 1;
}
-unsigned snapshot_count(const struct volume_group *vg)
-{
- struct lv_list *lvl;
- unsigned num_snapshots = 0;
-
- dm_list_iterate_items(lvl, &vg->lvs)
- if (lv_is_cow(lvl->lv))
- num_snapshots++;
-
- return num_snapshots;
-}
-
-unsigned vg_visible_lvs(const struct volume_group *vg)
-{
- struct lv_list *lvl;
- unsigned lv_count = 0;
-
- dm_list_iterate_items(lvl, &vg->lvs) {
- if (lv_is_visible(lvl->lv))
- lv_count++;
- }
-
- return lv_count;
-}
-
/*
* Determine whether two vgs are compatible for merging.
*/
@@ -4471,79 +4126,6 @@ int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignored)
return 1;
}
-uint32_t vg_seqno(const struct volume_group *vg)
-{
- return vg->seqno;
-}
-
-uint64_t vg_status(const struct volume_group *vg)
-{
- return vg->status;
-}
-
-uint64_t vg_size(const struct volume_group *vg)
-{
- return (uint64_t) vg->extent_count * vg->extent_size;
-}
-
-uint64_t vg_free(const struct volume_group *vg)
-{
- return (uint64_t) vg->free_count * vg->extent_size;
-}
-
-uint64_t vg_extent_size(const struct volume_group *vg)
-{
- return (uint64_t) vg->extent_size;
-}
-
-uint64_t vg_extent_count(const struct volume_group *vg)
-{
- return (uint64_t) vg->extent_count;
-}
-
-uint64_t vg_free_count(const struct volume_group *vg)
-{
- return (uint64_t) vg->free_count;
-}
-
-uint64_t vg_pv_count(const struct volume_group *vg)
-{
- return (uint64_t) vg->pv_count;
-}
-
-uint64_t vg_max_pv(const struct volume_group *vg)
-{
- return (uint64_t) vg->max_pv;
-}
-
-uint64_t vg_max_lv(const struct volume_group *vg)
-{
- return (uint64_t) vg->max_lv;
-}
-
-uint32_t vg_mda_count(const struct volume_group *vg)
-{
- return dm_list_size(&vg->fid->metadata_areas_in_use) +
- dm_list_size(&vg->fid->metadata_areas_ignored);
-}
-
-uint32_t vg_mda_used_count(const struct volume_group *vg)
-{
- uint32_t used_count = 0;
- struct metadata_area *mda;
-
- /*
- * Ignored mdas could be on either list - the reason being the state
- * may have changed from ignored to un-ignored and we need to write
- * the state to disk.
- */
- dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use)
- if (!mda_is_ignored(mda))
- used_count++;
-
- return used_count;
-}
-
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..f0f0732 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -378,11 +378,6 @@ int remove_seg_from_segs_using_this_lv(struct logical_volume *lv, struct lv_segm
struct lv_segment *get_only_segment_using_this_lv(struct logical_volume *lv);
/*
- * Count snapshot LVs.
- */
-unsigned snapshot_count(const struct volume_group *vg);
-
-/*
* Calculate readahead from underlying PV devices
*/
void lv_calculate_readahead(const struct logical_volume *lv, uint32_t *read_ahead);
@@ -417,7 +412,5 @@ int vg_mark_partial_lvs(struct volume_group *vg);
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);
#endif
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
new file mode 100644
index 0000000..40270ec
--- /dev/null
+++ b/lib/metadata/vg.c
@@ -0,0 +1,436 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "lib.h"
+#include "metadata.h"
+#include "activate.h"
+
+uint32_t vg_seqno(const struct volume_group *vg)
+{
+ return vg->seqno;
+}
+
+uint64_t vg_status(const struct volume_group *vg)
+{
+ return vg->status;
+}
+
+uint64_t vg_size(const struct volume_group *vg)
+{
+ return (uint64_t) vg->extent_count * vg->extent_size;
+}
+
+uint64_t vg_free(const struct volume_group *vg)
+{
+ return (uint64_t) vg->free_count * vg->extent_size;
+}
+
+uint64_t vg_extent_size(const struct volume_group *vg)
+{
+ return (uint64_t) vg->extent_size;
+}
+
+uint64_t vg_extent_count(const struct volume_group *vg)
+{
+ return (uint64_t) vg->extent_count;
+}
+
+uint64_t vg_free_count(const struct volume_group *vg)
+{
+ return (uint64_t) vg->free_count;
+}
+
+uint64_t vg_pv_count(const struct volume_group *vg)
+{
+ return (uint64_t) vg->pv_count;
+}
+
+uint64_t vg_max_pv(const struct volume_group *vg)
+{
+ return (uint64_t) vg->max_pv;
+}
+
+uint64_t vg_max_lv(const struct volume_group *vg)
+{
+ return (uint64_t) vg->max_lv;
+}
+
+unsigned snapshot_count(const struct volume_group *vg)
+{
+ struct lv_list *lvl;
+ unsigned num_snapshots = 0;
+
+ dm_list_iterate_items(lvl, &vg->lvs)
+ if (lv_is_cow(lvl->lv))
+ num_snapshots++;
+
+ return num_snapshots;
+}
+
+unsigned vg_visible_lvs(const struct volume_group *vg)
+{
+ struct lv_list *lvl;
+ unsigned lv_count = 0;
+
+ dm_list_iterate_items(lvl, &vg->lvs) {
+ if (lv_is_visible(lvl->lv))
+ lv_count++;
+ }
+
+ return lv_count;
+}
+
+uint32_t vg_mda_count(const struct volume_group *vg)
+{
+ return dm_list_size(&vg->fid->metadata_areas_in_use) +
+ dm_list_size(&vg->fid->metadata_areas_ignored);
+}
+
+uint32_t vg_mda_used_count(const struct volume_group *vg)
+{
+ uint32_t used_count = 0;
+ struct metadata_area *mda;
+
+ /*
+ * Ignored mdas could be on either list - the reason being the state
+ * may have changed from ignored to un-ignored and we need to write
+ * the state to disk.
+ */
+ dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use)
+ if (!mda_is_ignored(mda))
+ used_count++;
+
+ return used_count;
+}
+
+uint32_t vg_mda_copies(const struct volume_group *vg)
+{
+ return vg->mda_copies;
+}
+
+uint64_t vg_mda_size(const struct volume_group *vg)
+{
+ return find_min_mda_size(&vg->fid->metadata_areas_in_use);
+}
+
+uint64_t vg_mda_free(const struct volume_group *vg)
+{
+ uint64_t freespace = UINT64_MAX, mda_free;
+ struct metadata_area *mda;
+
+ dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
+ if (!mda->ops->mda_free_sectors)
+ continue;
+ mda_free = mda->ops->mda_free_sectors(mda);
+ if (mda_free < freespace)
+ freespace = mda_free;
+ }
+
+ if (freespace == UINT64_MAX)
+ freespace = UINT64_C(0);
+ return freespace;
+}
+
+int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies)
+{
+ vg->mda_copies = mda_copies;
+
+ /* FIXME Use log_verbose when this is due to specific cmdline request. */
+ log_debug("Setting mda_copies to %"PRIu32" for VG %s",
+ mda_copies, vg->name);
+
+ return 1;
+}
+
+static int _recalc_extents(uint32_t *extents, const char *desc1,
+ const char *desc2, uint32_t old_size,
+ uint32_t new_size)
+{
+ uint64_t size = (uint64_t) old_size * (*extents);
+
+ if (size % new_size) {
+ log_error("New size %" PRIu64 " for %s%s not an exact number "
+ "of new extents.", size, desc1, desc2);
+ return 0;
+ }
+
+ size /= new_size;
+
+ if (size > UINT32_MAX) {
+ log_error("New extent count %" PRIu64 " for %s%s exceeds "
+ "32 bits.", size, desc1, desc2);
+ return 0;
+ }
+
+ *extents = (uint32_t) size;
+
+ return 1;
+}
+
+int vg_set_extent_size(struct volume_group *vg, uint32_t new_size)
+{
+ uint32_t old_size = vg->extent_size;
+ struct pv_list *pvl;
+ struct lv_list *lvl;
+ struct physical_volume *pv;
+ struct logical_volume *lv;
+ struct lv_segment *seg;
+ struct pv_segment *pvseg;
+ uint32_t s;
+
+ if (!vg_is_resizeable(vg)) {
+ log_error("Volume group \"%s\" must be resizeable "
+ "to change PE size", vg->name);
+ return 0;
+ }
+
+ if (!new_size) {
+ log_error("Physical extent size may not be zero");
+ return 0;
+ }
+
+ if (new_size == vg->extent_size)
+ return 1;
+
+ if (new_size & (new_size - 1)) {
+ log_error("Physical extent size must be a power of 2.");
+ return 0;
+ }
+
+ if (new_size > vg->extent_size) {
+ if ((uint64_t) vg_size(vg) % new_size) {
+ /* FIXME Adjust used PV sizes instead */
+ log_error("New extent size is not a perfect fit");
+ return 0;
+ }
+ }
+
+ vg->extent_size = new_size;
+
+ if (vg->fid->fmt->ops->vg_setup &&
+ !vg->fid->fmt->ops->vg_setup(vg->fid, vg))
+ return_0;
+
+ if (!_recalc_extents(&vg->extent_count, vg->name, "", old_size,
+ new_size))
+ return_0;
+
+ if (!_recalc_extents(&vg->free_count, vg->name, " free space",
+ old_size, new_size))
+ return_0;
+
+ /* foreach PV */
+ dm_list_iterate_items(pvl, &vg->pvs) {
+ pv = pvl->pv;
+
+ pv->pe_size = new_size;
+ if (!_recalc_extents(&pv->pe_count, pv_dev_name(pv), "",
+ old_size, new_size))
+ return_0;
+
+ if (!_recalc_extents(&pv->pe_alloc_count, pv_dev_name(pv),
+ " allocated space", old_size, new_size))
+ return_0;
+
+ /* foreach free PV Segment */
+ dm_list_iterate_items(pvseg, &pv->segments) {
+ if (pvseg_is_allocated(pvseg))
+ continue;
+
+ if (!_recalc_extents(&pvseg->pe, pv_dev_name(pv),
+ " PV segment start", old_size,
+ new_size))
+ return_0;
+ if (!_recalc_extents(&pvseg->len, pv_dev_name(pv),
+ " PV segment length", old_size,
+ new_size))
+ return_0;
+ }
+ }
+
+ /* foreach LV */
+ dm_list_iterate_items(lvl, &vg->lvs) {
+ lv = lvl->lv;
+
+ if (!_recalc_extents(&lv->le_count, lv->name, "", old_size,
+ new_size))
+ return_0;
+
+ dm_list_iterate_items(seg, &lv->segments) {
+ if (!_recalc_extents(&seg->le, lv->name,
+ " segment start", old_size,
+ new_size))
+ return_0;
+
+ if (!_recalc_extents(&seg->len, lv->name,
+ " segment length", old_size,
+ new_size))
+ return_0;
+
+ if (!_recalc_extents(&seg->area_len, lv->name,
+ " area length", old_size,
+ new_size))
+ return_0;
+
+ if (!_recalc_extents(&seg->extents_copied, lv->name,
+ " extents moved", old_size,
+ new_size))
+ return_0;
+
+ /* foreach area */
+ for (s = 0; s < seg->area_count; s++) {
+ switch (seg_type(seg, s)) {
+ case AREA_PV:
+ if (!_recalc_extents
+ (&seg_pe(seg, s),
+ lv->name,
+ " pvseg start", old_size,
+ new_size))
+ return_0;
+ if (!_recalc_extents
+ (&seg_pvseg(seg, s)->len,
+ lv->name,
+ " pvseg length", old_size,
+ new_size))
+ return_0;
+ break;
+ case AREA_LV:
+ if (!_recalc_extents
+ (&seg_le(seg, s), lv->name,
+ " area start", old_size,
+ new_size))
+ return_0;
+ break;
+ case AREA_UNASSIGNED:
+ log_error("Unassigned area %u found in "
+ "segment", s);
+ return 0;
+ }
+ }
+ }
+
+ }
+
+ return 1;
+}
+
+int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv)
+{
+ if (!vg_is_resizeable(vg)) {
+ log_error("Volume group \"%s\" must be resizeable "
+ "to change MaxLogicalVolume", vg->name);
+ return 0;
+ }
+
+ if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) {
+ if (!max_lv)
+ max_lv = 255;
+ else if (max_lv > 255) {
+ log_error("MaxLogicalVolume limit is 255");
+ return 0;
+ }
+ }
+
+ if (max_lv && max_lv < vg_visible_lvs(vg)) {
+ log_error("MaxLogicalVolume is less than the current number "
+ "%d of LVs for %s", vg_visible_lvs(vg),
+ vg->name);
+ return 0;
+ }
+ vg->max_lv = max_lv;
+
+ return 1;
+}
+
+int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv)
+{
+ if (!vg_is_resizeable(vg)) {
+ log_error("Volume group \"%s\" must be resizeable "
+ "to change MaxPhysicalVolumes", vg->name);
+ return 0;
+ }
+
+ if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) {
+ if (!max_pv)
+ max_pv = 255;
+ else if (max_pv > 255) {
+ log_error("MaxPhysicalVolume limit is 255");
+ return 0;
+ }
+ }
+
+ if (max_pv && max_pv < vg->pv_count) {
+ log_error("MaxPhysicalVolumes is less than the current number "
+ "%d of PVs for \"%s\"", vg->pv_count,
+ vg->name);
+ return 0;
+ }
+ vg->max_pv = max_pv;
+ return 1;
+}
+
+int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc)
+{
+ if (alloc == ALLOC_INHERIT) {
+ log_error("Volume Group allocation policy cannot inherit "
+ "from anything");
+ return 0;
+ }
+
+ if (alloc == vg->alloc)
+ return 1;
+
+ vg->alloc = alloc;
+ return 1;
+}
+
+int vg_set_clustered(struct volume_group *vg, int clustered)
+{
+ struct lv_list *lvl;
+
+ /*
+ * We do not currently support switching the cluster attribute
+ * on active mirrors or snapshots.
+ */
+ dm_list_iterate_items(lvl, &vg->lvs) {
+ if (lv_is_mirrored(lvl->lv) && lv_is_active(lvl->lv)) {
+ log_error("Mirror logical volumes must be inactive "
+ "when changing the cluster attribute.");
+ return 0;
+ }
+
+ if (clustered) {
+ if (lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) {
+ log_error("Volume group %s contains snapshots "
+ "that are not yet supported.",
+ vg->name);
+ return 0;
+ }
+ }
+
+ if ((lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) &&
+ lv_is_active(lvl->lv)) {
+ log_error("Snapshot logical volumes must be inactive "
+ "when changing the cluster attribute.");
+ return 0;
+ }
+ }
+
+ if (clustered)
+ vg->status |= CLUSTERED;
+ else
+ vg->status &= ~CLUSTERED;
+ return 1;
+}
+
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
new file mode 100644
index 0000000..1610087
--- /dev/null
+++ b/lib/metadata/vg.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _VG_H
+#define _VG_H
+
+struct cmd_context;
+struct dm_pool;
+struct format_instance;
+struct dm_list;
+struct id;
+
+typedef enum {
+ ALLOC_INVALID,
+ ALLOC_CONTIGUOUS,
+ ALLOC_CLING,
+ ALLOC_NORMAL,
+ ALLOC_ANYWHERE,
+ ALLOC_INHERIT
+} alloc_policy_t;
+
+struct volume_group {
+ struct cmd_context *cmd;
+ struct dm_pool *vgmem;
+ struct format_instance *fid;
+ struct dm_list *cmd_vgs;/* List of wanted/locked and opened VGs */
+ uint32_t cmd_missing_vgs;/* Flag marks missing VG */
+ uint32_t seqno; /* Metadata sequence number */
+
+ alloc_policy_t alloc;
+ uint64_t status;
+
+ struct id id;
+ char *name;
+ char *old_name; /* Set during vgrename and vgcfgrestore */
+ char *system_id;
+
+ uint32_t extent_size;
+ uint32_t extent_count;
+ uint32_t free_count;
+
+ uint32_t max_lv;
+ uint32_t max_pv;
+
+ /* physical volumes */
+ uint32_t pv_count;
+ struct dm_list pvs;
+
+ /*
+ * logical volumes
+ * The following relationship should always hold:
+ * dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs
+ *
+ * Snapshots consist of 2 instances of "struct logical_volume":
+ * - cow (lv_name is visible to the user)
+ * - snapshot (lv_name is 'snapshotN')
+ *
+ * Mirrors consist of multiple instances of "struct logical_volume":
+ * - one for the mirror log
+ * - one for each mirror leg
+ * - one for the user-visible mirror LV
+ */
+ struct dm_list lvs;
+
+ struct dm_list tags;
+
+ /*
+ * FIXME: Move the next fields into a different struct?
+ */
+
+ /*
+ * List of removed physical volumes by pvreduce.
+ * They have to get cleared on vg_commit.
+ */
+ struct dm_list removed_pvs;
+ uint32_t open_mode; /* FIXME: read or write - check lock type? */
+
+ /*
+ * Store result of the last vg_read().
+ * 0 for success else appropriate FAILURE_* bits set.
+ */
+ uint32_t read_status;
+ uint32_t mda_copies; /* target number of mdas for this VG */
+};
+
+uint32_t vg_seqno(const struct volume_group *vg);
+uint64_t vg_status(const struct volume_group *vg);
+int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc);
+int vg_set_clustered(struct volume_group *vg, int clustered);
+uint64_t vg_size(const struct volume_group *vg);
+uint64_t vg_free(const struct volume_group *vg);
+uint64_t vg_extent_size(const struct volume_group *vg);
+int vg_set_extent_size(struct volume_group *vg, uint32_t new_extent_size);
+uint64_t vg_extent_count(const struct volume_group *vg);
+uint64_t vg_free_count(const struct volume_group *vg);
+uint64_t vg_pv_count(const struct volume_group *vg);
+uint64_t vg_max_pv(const struct volume_group *vg);
+int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv);
+uint64_t vg_max_lv(const struct volume_group *vg);
+int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv);
+uint32_t vg_mda_count(const struct volume_group *vg);
+uint32_t vg_mda_used_count(const struct volume_group *vg);
+uint32_t vg_mda_copies(const struct volume_group *vg);
+int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies);
+/*
+ * Returns visible LV count - number of LVs from user perspective
+ */
+unsigned vg_visible_lvs(const struct volume_group *vg);
+/*
+ * Count snapshot LVs.
+ */
+unsigned snapshot_count(const struct volume_group *vg);
+
+uint64_t vg_mda_size(const struct volume_group *vg);
+uint64_t vg_mda_free(const struct volume_group *vg);
+
+#endif
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 02/20] Refactor metadata.[ch] into pv.[ch] for pv functions.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
2010-09-22 21:06 ` [PATCH 01/20] Refactor metadata.[ch] into vg.[ch] for vg functions Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 03/20] Refactor metadata.[ch] into lv.[ch] for lv functions Dave Wysochanski
` (17 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
The metadata.[ch] files are very large. This patch makes a first
attempt at separating out pv functions and data, particularly
related to the reporting fields calculations.
More code could be moved here but for now I'm stopping at reporting
functions 'get' / 'set' functions.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
include/.symlinks.in | 1 +
lib/Makefile.in | 1 +
lib/metadata/metadata-exported.h | 52 +---------
lib/metadata/metadata.c | 206 -----------------------------------
lib/metadata/pv.c | 223 ++++++++++++++++++++++++++++++++++++++
lib/metadata/pv.h | 74 +++++++++++++
6 files changed, 300 insertions(+), 257 deletions(-)
create mode 100644 lib/metadata/pv.c
create mode 100644 lib/metadata/pv.h
diff --git a/include/.symlinks.in b/include/.symlinks.in
index 4dca46f..398e856 100644
--- a/include/.symlinks.in
+++ b/include/.symlinks.in
@@ -33,6 +33,7 @@
@top_srcdir@/lib/metadata/lv_alloc.h
@top_srcdir@/lib/metadata/metadata.h
@top_srcdir@/lib/metadata/metadata-exported.h
+ at top_srcdir@/lib/metadata/pv.h
@top_srcdir@/lib/metadata/pv_alloc.h
@top_srcdir@/lib/metadata/segtype.h
@top_srcdir@/lib/metadata/vg.h
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 172a0fd..2c173b3 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -77,6 +77,7 @@ SOURCES =\
metadata/merge.c \
metadata/metadata.c \
metadata/mirror.c \
+ metadata/pv.c \
metadata/pv_manip.c \
metadata/pv_map.c \
metadata/replicator_manip.c \
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index fef6903..86c90fa 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -22,6 +22,7 @@
#define _LVM_METADATA_EXPORTED_H
#include "uuid.h"
+#include "pv.h"
#include "vg.h"
#define MAX_STRIPES 128U
@@ -175,39 +176,6 @@ struct pv_segment {
#define pvseg_is_allocated(pvseg) ((pvseg)->lvseg)
-struct physical_volume {
- struct id id;
- struct device *dev;
- const struct format_type *fmt;
-
- /*
- * vg_name and vgid are used before the parent VG struct exists.
- * FIXME: Investigate removal/substitution with 'vg' fields.
- */
- const char *vg_name;
- struct id vgid;
-
- /*
- * 'vg' is set and maintained when the PV belongs to a 'pvs'
- * list in a parent VG struct.
- */
- struct volume_group *vg;
-
- uint64_t status;
- uint64_t size;
-
- /* physical extents */
- uint32_t pe_size;
- uint64_t pe_start;
- uint32_t pe_count;
- uint32_t pe_alloc_count;
- unsigned long pe_align;
- unsigned long pe_align_offset;
-
- struct dm_list segments; /* Ordered pv_segments covering complete PV */
- struct dm_list tags;
-};
-
struct format_instance {
const struct format_type *fmt;
/*
@@ -419,7 +387,6 @@ int scan_vgs_for_pvs(struct cmd_context *cmd);
int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
struct dm_list *mdas, int64_t label_sector);
-int is_pv(struct physical_volume *pv);
int move_pv(struct volume_group *vg_from, struct volume_group *vg_to,
const char *pv_name);
int move_pvs_used_by_lv(struct volume_group *vg_from,
@@ -427,8 +394,6 @@ int move_pvs_used_by_lv(struct volume_group *vg_from,
const char *lv_name);
int is_global_vg(const char *vg_name);
int is_orphan_vg(const char *vg_name);
-int is_orphan(const struct physical_volume *pv);
-int is_missing_pv(const struct physical_volume *pv);
int vg_missing_pv_count(const struct volume_group *vg);
int vgs_are_compatible(struct cmd_context *cmd,
struct volume_group *vg_from,
@@ -777,21 +742,6 @@ char *generate_lv_name(struct volume_group *vg, const char *format,
/*
* Begin skeleton for external LVM library
*/
-struct device *pv_dev(const struct physical_volume *pv);
-const char *pv_vg_name(const struct physical_volume *pv);
-const char *pv_dev_name(const struct physical_volume *pv);
-uint64_t pv_size(const struct physical_volume *pv);
-uint64_t pv_size_field(const struct physical_volume *pv);
-uint64_t pv_dev_size(const struct physical_volume *pv);
-uint64_t pv_free(const struct physical_volume *pv);
-uint64_t pv_status(const struct physical_volume *pv);
-uint32_t pv_pe_size(const struct physical_volume *pv);
-uint64_t pv_pe_start(const struct physical_volume *pv);
-uint32_t pv_pe_count(const struct physical_volume *pv);
-uint32_t pv_pe_alloc_count(const struct physical_volume *pv);
-uint32_t pv_mda_count(const struct physical_volume *pv);
-uint32_t pv_mda_used_count(const struct physical_volume *pv);
-unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored);
int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignore);
uint64_t lv_size(const struct logical_volume *lv);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index ca741b2..ac19603 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -34,12 +34,6 @@
#include <math.h>
#include <sys/param.h>
-/*
- * FIXME: Check for valid handle before dereferencing field or log error?
- */
-#define pv_field(handle, field) \
- (((const struct physical_volume *)(handle))->field)
-
static struct physical_volume *_pv_read(struct cmd_context *cmd,
struct dm_pool *pvmem,
const char *pv_name,
@@ -3424,29 +3418,6 @@ int is_orphan_vg(const char *vg_name)
return (vg_name && !strncmp(vg_name, ORPHAN_PREFIX, sizeof(ORPHAN_PREFIX) - 1)) ? 1 : 0;
}
-/**
- * is_orphan - Determine whether a pv is an orphan based on its vg_name
- * @pv: handle to the physical volume
- */
-int is_orphan(const struct physical_volume *pv)
-{
- return is_orphan_vg(pv_field(pv, vg_name));
-}
-
-/**
- * is_pv - Determine whether a pv is a real pv or dummy one
- * @pv: handle to device
- */
-int is_pv(struct physical_volume *pv)
-{
- return (pv_field(pv, vg_name) ? 1 : 0);
-}
-
-int is_missing_pv(const struct physical_volume *pv)
-{
- return pv_field(pv, status) & MISSING_PV ? 1 : 0;
-}
-
/*
* Returns:
* 0 - fail
@@ -3790,101 +3761,6 @@ uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname)
return FAILED_EXIST;
}
-/*
- * Gets/Sets for external LVM library
- */
-struct id pv_id(const struct physical_volume *pv)
-{
- return pv_field(pv, id);
-}
-
-const struct format_type *pv_format_type(const struct physical_volume *pv)
-{
- return pv_field(pv, fmt);
-}
-
-struct id pv_vgid(const struct physical_volume *pv)
-{
- return pv_field(pv, vgid);
-}
-
-struct device *pv_dev(const struct physical_volume *pv)
-{
- return pv_field(pv, dev);
-}
-
-const char *pv_vg_name(const struct physical_volume *pv)
-{
- return pv_field(pv, vg_name);
-}
-
-const char *pv_dev_name(const struct physical_volume *pv)
-{
- return dev_name(pv_dev(pv));
-}
-
-uint64_t pv_size(const struct physical_volume *pv)
-{
- return pv_field(pv, size);
-}
-
-uint64_t pv_dev_size(const struct physical_volume *pv)
-{
- uint64_t size;
-
- if (!dev_get_size(pv->dev, &size))
- size = 0;
- return size;
-}
-
-uint64_t pv_size_field(const struct physical_volume *pv)
-{
- uint64_t size;
-
- if (!pv->pe_count)
- size = pv->size;
- else
- size = (uint64_t) pv->pe_count * pv->pe_size;
- return size;
-}
-
-uint64_t pv_free(const struct physical_volume *pv)
-{
- uint64_t freespace;
-
- if (!pv->pe_count)
- freespace = pv->size;
- else
- freespace = (uint64_t)
- (pv->pe_count - pv->pe_alloc_count) * pv->pe_size;
- return freespace;
-}
-
-uint64_t pv_status(const struct physical_volume *pv)
-{
- return pv_field(pv, status);
-}
-
-uint32_t pv_pe_size(const struct physical_volume *pv)
-{
- return pv_field(pv, pe_size);
-}
-
-uint64_t pv_pe_start(const struct physical_volume *pv)
-{
- return pv_field(pv, pe_start);
-}
-
-uint32_t pv_pe_count(const struct physical_volume *pv)
-{
- return pv_field(pv, pe_count);
-}
-
-uint32_t pv_pe_alloc_count(const struct physical_volume *pv)
-{
- return pv_field(pv, pe_alloc_count);
-}
-
void fid_add_mda(struct format_instance *fid, struct metadata_area *mda)
{
dm_list_add(mda_is_ignored(mda) ? &fid->metadata_areas_ignored :
@@ -3983,88 +3859,6 @@ void mda_set_ignored(struct metadata_area *mda, unsigned mda_ignored)
mda->ops->mda_metadata_locn_offset ? mda->ops->mda_metadata_locn_offset(locn) : UINT64_C(0));
}
-uint32_t pv_mda_count(const struct physical_volume *pv)
-{
- struct lvmcache_info *info;
-
- info = info_from_pvid((const char *)&pv->id.uuid, 0);
- return info ? dm_list_size(&info->mdas) : UINT64_C(0);
-}
-
-uint32_t pv_mda_used_count(const struct physical_volume *pv)
-{
- struct lvmcache_info *info;
- struct metadata_area *mda;
- uint32_t used_count=0;
-
- info = info_from_pvid((const char *)&pv->id.uuid, 0);
- if (!info)
- return 0;
- dm_list_iterate_items(mda, &info->mdas) {
- if (!mda_is_ignored(mda))
- used_count++;
- }
- return used_count;
-}
-
-unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored)
-{
- struct lvmcache_info *info;
- struct metadata_area *mda, *vg_mda, *tmda;
- struct dm_list *vg_mdas_in_use, *vg_mdas_ignored;
-
- if (!(info = info_from_pvid((const char *)&pv->id.uuid, 0)))
- return_0;
-
- if (is_orphan(pv)) {
- dm_list_iterate_items(mda, &info->mdas)
- mda_set_ignored(mda, mda_ignored);
- return 1;
- }
-
- /*
- * Do not allow disabling of the the last PV in a VG.
- */
- if (pv_mda_used_count(pv) == vg_mda_used_count(pv->vg)) {
- log_error("Cannot disable all metadata areas in volume group %s.",
- pv->vg->name);
- return 0;
- }
-
- /*
- * Non-orphan case is more complex.
- * If the PV's mdas are ignored, and we wish to un-ignore,
- * we clear the bit and move them from the ignored mda list to the
- * in_use list, ensuring the new state will get written to disk
- * in the vg_write() path.
- * If the PV's mdas are not ignored, and we are setting
- * them to ignored, we set the bit but leave them on the in_use
- * list, ensuring the new state will get written to disk in the
- * vg_write() path.
- */
- vg_mdas_in_use = &pv->vg->fid->metadata_areas_in_use;
- vg_mdas_ignored = &pv->vg->fid->metadata_areas_ignored;
-
- dm_list_iterate_items(mda, &info->mdas) {
- if (mda_is_ignored(mda) && !mda_ignored)
- /* Changing an ignored mda to one in_use requires moving it */
- dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_ignored)
- if (mda_locns_match(mda, vg_mda)) {
- mda_set_ignored(vg_mda, mda_ignored);
- dm_list_move(vg_mdas_in_use, &vg_mda->list);
- }
-
- dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_in_use)
- if (mda_locns_match(mda, vg_mda))
- /* Don't move mda: needs writing to disk. */
- mda_set_ignored(vg_mda, mda_ignored);
-
- mda_set_ignored(mda, mda_ignored);
- }
-
- return 1;
-}
-
int mdas_empty_or_ignored(struct dm_list *mdas)
{
struct metadata_area *mda;
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
new file mode 100644
index 0000000..dc4a300
--- /dev/null
+++ b/lib/metadata/pv.c
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "lib.h"
+#include "metadata.h"
+#include "lvmcache.h"
+
+/*
+ * FIXME: Check for valid handle before dereferencing field or log error?
+ */
+#define pv_field(handle, field) ((handle)->field)
+
+/*
+ * Gets/Sets for external LVM library
+ */
+struct id pv_id(const struct physical_volume *pv)
+{
+ return pv_field(pv, id);
+}
+
+const struct format_type *pv_format_type(const struct physical_volume *pv)
+{
+ return pv_field(pv, fmt);
+}
+
+struct id pv_vgid(const struct physical_volume *pv)
+{
+ return pv_field(pv, vgid);
+}
+
+struct device *pv_dev(const struct physical_volume *pv)
+{
+ return pv_field(pv, dev);
+}
+
+const char *pv_vg_name(const struct physical_volume *pv)
+{
+ return pv_field(pv, vg_name);
+}
+
+const char *pv_dev_name(const struct physical_volume *pv)
+{
+ return dev_name(pv_dev(pv));
+}
+
+uint64_t pv_size(const struct physical_volume *pv)
+{
+ return pv_field(pv, size);
+}
+
+uint64_t pv_dev_size(const struct physical_volume *pv)
+{
+ uint64_t size;
+
+ if (!dev_get_size(pv->dev, &size))
+ size = 0;
+ return size;
+}
+
+uint64_t pv_size_field(const struct physical_volume *pv)
+{
+ uint64_t size;
+
+ if (!pv->pe_count)
+ size = pv->size;
+ else
+ size = (uint64_t) pv->pe_count * pv->pe_size;
+ return size;
+}
+
+uint64_t pv_free(const struct physical_volume *pv)
+{
+ uint64_t freespace;
+
+ if (!pv->pe_count)
+ freespace = pv->size;
+ else
+ freespace = (uint64_t)
+ (pv->pe_count - pv->pe_alloc_count) * pv->pe_size;
+ return freespace;
+}
+
+uint64_t pv_status(const struct physical_volume *pv)
+{
+ return pv_field(pv, status);
+}
+
+uint32_t pv_pe_size(const struct physical_volume *pv)
+{
+ return pv_field(pv, pe_size);
+}
+
+uint64_t pv_pe_start(const struct physical_volume *pv)
+{
+ return pv_field(pv, pe_start);
+}
+
+uint32_t pv_pe_count(const struct physical_volume *pv)
+{
+ return pv_field(pv, pe_count);
+}
+
+uint32_t pv_pe_alloc_count(const struct physical_volume *pv)
+{
+ return pv_field(pv, pe_alloc_count);
+}
+
+uint32_t pv_mda_count(const struct physical_volume *pv)
+{
+ struct lvmcache_info *info;
+
+ info = info_from_pvid((const char *)&pv->id.uuid, 0);
+ return info ? dm_list_size(&info->mdas) : UINT64_C(0);
+}
+
+uint32_t pv_mda_used_count(const struct physical_volume *pv)
+{
+ struct lvmcache_info *info;
+ struct metadata_area *mda;
+ uint32_t used_count=0;
+
+ info = info_from_pvid((const char *)&pv->id.uuid, 0);
+ if (!info)
+ return 0;
+ dm_list_iterate_items(mda, &info->mdas) {
+ if (!mda_is_ignored(mda))
+ used_count++;
+ }
+ return used_count;
+}
+
+/**
+ * is_orphan - Determine whether a pv is an orphan based on its vg_name
+ * @pv: handle to the physical volume
+ */
+int is_orphan(const struct physical_volume *pv)
+{
+ return is_orphan_vg(pv_field(pv, vg_name));
+}
+
+/**
+ * is_pv - Determine whether a pv is a real pv or dummy one
+ * @pv: handle to device
+ */
+int is_pv(const struct physical_volume *pv)
+{
+ return (pv_field(pv, vg_name) ? 1 : 0);
+}
+
+int is_missing_pv(const struct physical_volume *pv)
+{
+ return pv_field(pv, status) & MISSING_PV ? 1 : 0;
+}
+
+unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored)
+{
+ struct lvmcache_info *info;
+ struct metadata_area *mda, *vg_mda, *tmda;
+ struct dm_list *vg_mdas_in_use, *vg_mdas_ignored;
+
+ if (!(info = info_from_pvid((const char *)&pv->id.uuid, 0)))
+ return_0;
+
+ if (is_orphan(pv)) {
+ dm_list_iterate_items(mda, &info->mdas)
+ mda_set_ignored(mda, mda_ignored);
+ return 1;
+ }
+
+ /*
+ * Do not allow disabling of the the last PV in a VG.
+ */
+ if (pv_mda_used_count(pv) == vg_mda_used_count(pv->vg)) {
+ log_error("Cannot disable all metadata areas in volume group %s.",
+ pv->vg->name);
+ return 0;
+ }
+
+ /*
+ * Non-orphan case is more complex.
+ * If the PV's mdas are ignored, and we wish to un-ignore,
+ * we clear the bit and move them from the ignored mda list to the
+ * in_use list, ensuring the new state will get written to disk
+ * in the vg_write() path.
+ * If the PV's mdas are not ignored, and we are setting
+ * them to ignored, we set the bit but leave them on the in_use
+ * list, ensuring the new state will get written to disk in the
+ * vg_write() path.
+ */
+ vg_mdas_in_use = &pv->vg->fid->metadata_areas_in_use;
+ vg_mdas_ignored = &pv->vg->fid->metadata_areas_ignored;
+
+ dm_list_iterate_items(mda, &info->mdas) {
+ if (mda_is_ignored(mda) && !mda_ignored)
+ /* Changing an ignored mda to one in_use requires moving it */
+ dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_ignored)
+ if (mda_locns_match(mda, vg_mda)) {
+ mda_set_ignored(vg_mda, mda_ignored);
+ dm_list_move(vg_mdas_in_use, &vg_mda->list);
+ }
+
+ dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_in_use)
+ if (mda_locns_match(mda, vg_mda))
+ /* Don't move mda: needs writing to disk. */
+ mda_set_ignored(vg_mda, mda_ignored);
+
+ mda_set_ignored(mda, mda_ignored);
+ }
+
+ return 1;
+}
+
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
new file mode 100644
index 0000000..ba5c4a4
--- /dev/null
+++ b/lib/metadata/pv.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _PV_H
+#define _PV_H
+
+struct id;
+struct device;
+struct format_type;
+struct volume_group;
+
+struct physical_volume {
+ struct id id;
+ struct device *dev;
+ const struct format_type *fmt;
+
+ /*
+ * vg_name and vgid are used before the parent VG struct exists.
+ * FIXME: Investigate removal/substitution with 'vg' fields.
+ */
+ const char *vg_name;
+ struct id vgid;
+
+ /*
+ * 'vg' is set and maintained when the PV belongs to a 'pvs'
+ * list in a parent VG struct.
+ */
+ struct volume_group *vg;
+
+ uint64_t status;
+ uint64_t size;
+
+ /* physical extents */
+ uint32_t pe_size;
+ uint64_t pe_start;
+ uint32_t pe_count;
+ uint32_t pe_alloc_count;
+ unsigned long pe_align;
+ unsigned long pe_align_offset;
+
+ struct dm_list segments; /* Ordered pv_segments covering complete PV */
+ struct dm_list tags;
+};
+
+struct device *pv_dev(const struct physical_volume *pv);
+const char *pv_vg_name(const struct physical_volume *pv);
+const char *pv_dev_name(const struct physical_volume *pv);
+uint64_t pv_size(const struct physical_volume *pv);
+uint64_t pv_size_field(const struct physical_volume *pv);
+uint64_t pv_dev_size(const struct physical_volume *pv);
+uint64_t pv_free(const struct physical_volume *pv);
+uint64_t pv_status(const struct physical_volume *pv);
+uint32_t pv_pe_size(const struct physical_volume *pv);
+uint64_t pv_pe_start(const struct physical_volume *pv);
+uint32_t pv_pe_count(const struct physical_volume *pv);
+uint32_t pv_pe_alloc_count(const struct physical_volume *pv);
+uint32_t pv_mda_count(const struct physical_volume *pv);
+uint32_t pv_mda_used_count(const struct physical_volume *pv);
+unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored);
+int is_orphan(const struct physical_volume *pv);
+int is_missing_pv(const struct physical_volume *pv);
+int is_pv(const struct physical_volume *pv);
+
+#endif
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 03/20] Refactor metadata.[ch] into lv.[ch] for lv functions.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
2010-09-22 21:06 ` [PATCH 01/20] Refactor metadata.[ch] into vg.[ch] for vg functions Dave Wysochanski
2010-09-22 21:06 ` [PATCH 02/20] Refactor metadata.[ch] into pv.[ch] for pv functions Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 04/20] Add {pv|vg|lv}_attr_dup() functions and refactor 'disp' functions Dave Wysochanski
` (16 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
This patch is similar to the other patches for pv and vg
functionality, and separates lv functionality into separate
files, concentrating on reporting fields and simple functions.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
include/.symlinks.in | 1 +
lib/Makefile.in | 1 +
lib/metadata/lv.c | 21 +++++++++++++++
lib/metadata/lv.h | 52 ++++++++++++++++++++++++++++++++++++++
lib/metadata/metadata-exported.h | 29 +--------------------
lib/metadata/metadata.c | 5 ---
6 files changed, 76 insertions(+), 33 deletions(-)
create mode 100644 lib/metadata/lv.c
create mode 100644 lib/metadata/lv.h
diff --git a/include/.symlinks.in b/include/.symlinks.in
index 398e856..7fd6171 100644
--- a/include/.symlinks.in
+++ b/include/.symlinks.in
@@ -30,6 +30,7 @@
@top_srcdir@/lib/locking/locking.h
@top_srcdir@/lib/log/log.h
@top_srcdir@/lib/log/lvm-logging.h
+ at top_srcdir@/lib/metadata/lv.h
@top_srcdir@/lib/metadata/lv_alloc.h
@top_srcdir@/lib/metadata/metadata.h
@top_srcdir@/lib/metadata/metadata-exported.h
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 2c173b3..ab944fa 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -73,6 +73,7 @@ SOURCES =\
locking/locking.c \
locking/no_locking.c \
log/log.c \
+ metadata/lv.c \
metadata/lv_manip.c \
metadata/merge.c \
metadata/metadata.c \
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
new file mode 100644
index 0000000..49f0b3d
--- /dev/null
+++ b/lib/metadata/lv.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "lib.h"
+#include "metadata.h"
+
+uint64_t lv_size(const struct logical_volume *lv)
+{
+ return lv->size;
+}
diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h
new file mode 100644
index 0000000..d3b0d82
--- /dev/null
+++ b/lib/metadata/lv.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _LV_H
+#define _LV_H
+
+union lvid;
+struct volume_group;
+struct dm_list;
+struct lv_segment;
+struct replicator_device;
+
+struct logical_volume {
+ union lvid lvid;
+ char *name;
+
+ struct volume_group *vg;
+
+ uint64_t status;
+ alloc_policy_t alloc;
+ uint32_t read_ahead;
+ int32_t major;
+ int32_t minor;
+
+ uint64_t size; /* Sectors */
+ uint32_t le_count;
+
+ uint32_t origin_count;
+ struct dm_list snapshot_segs;
+ struct lv_segment *snapshot;
+
+ struct replicator_device *rdevice;/* For replicator-devs, rimages, slogs - reference to rdevice */
+ struct dm_list rsites; /* For replicators - all sites */
+
+ struct dm_list segments;
+ struct dm_list tags;
+ struct dm_list segs_using_this_lv;
+};
+
+uint64_t lv_size(const struct logical_volume *lv);
+
+#endif
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 86c90fa..447e4af 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -24,6 +24,7 @@
#include "uuid.h"
#include "pv.h"
#include "vg.h"
+#include "lv.h"
#define MAX_STRIPES 128U
#define SECTOR_SHIFT 9L
@@ -291,33 +292,6 @@ struct lv_segment {
#define seg_pv(seg, s) (seg)->areas[(s)].u.pv.pvseg->pv
#define seg_lv(seg, s) (seg)->areas[(s)].u.lv.lv
-struct logical_volume {
- union lvid lvid;
- char *name;
-
- struct volume_group *vg;
-
- uint64_t status;
- alloc_policy_t alloc;
- uint32_t read_ahead;
- int32_t major;
- int32_t minor;
-
- uint64_t size; /* Sectors */
- uint32_t le_count;
-
- uint32_t origin_count;
- struct dm_list snapshot_segs;
- struct lv_segment *snapshot;
-
- struct replicator_device *rdevice;/* For replicator-devs, rimages, slogs - reference to rdevice */
- struct dm_list rsites; /* For replicators - all sites */
-
- struct dm_list segments;
- struct dm_list tags;
- struct dm_list segs_using_this_lv;
-};
-
struct pe_range {
struct dm_list list;
uint32_t start; /* PEs */
@@ -744,7 +718,6 @@ char *generate_lv_name(struct volume_group *vg, const char *format,
*/
int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignore);
-uint64_t lv_size(const struct logical_volume *lv);
int vg_check_write_mode(struct volume_group *vg);
#define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index ac19603..1251345 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3920,11 +3920,6 @@ int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignored)
return 1;
}
-uint64_t lv_size(const struct logical_volume *lv)
-{
- return lv->size;
-}
-
/**
* pv_by_path - Given a device path return a PV handle if it is a PV
* @cmd - handle to the LVM command instance
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 04/20] Add {pv|vg|lv}_attr_dup() functions and refactor 'disp' functions.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (2 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 03/20] Refactor metadata.[ch] into lv.[ch] for lv functions Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 05/20] Simplify logic to create 'attr' strings Dave Wysochanski
` (15 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
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.
Add "_dup" suffix to indicate memory is allocated.
Refactor pvstatus_disp to take pv argument and call pv_attr_dup().
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/lv.c | 118 ++++++++++++++++++++++++++++++++
lib/metadata/lv.h | 1 +
lib/metadata/metadata.c | 16 ++++
lib/metadata/metadata.h | 1 +
lib/metadata/pv.c | 21 ++++++
lib/metadata/pv.h | 1 +
lib/metadata/vg.c | 37 ++++++++++
lib/metadata/vg.h | 1 +
lib/report/columns.h | 2 +-
lib/report/report.c | 174 ++---------------------------------------------
10 files changed, 202 insertions(+), 170 deletions(-)
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 49f0b3d..0c01c73 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -14,8 +14,126 @@
#include "lib.h"
#include "metadata.h"
+#include "activate.h"
uint64_t lv_size(const struct logical_volume *lv)
{
return lv->size;
}
+
+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_dup(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;
+}
diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h
index d3b0d82..4cf06b2 100644
--- a/lib/metadata/lv.h
+++ b/lib/metadata/lv.h
@@ -48,5 +48,6 @@ struct logical_volume {
};
uint64_t lv_size(const struct logical_volume *lv);
+char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv);
#endif
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 1251345..07f6a90 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3920,6 +3920,22 @@ int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignored)
return 1;
}
+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';
+ }
+}
+
/**
* pv_by_path - Given a device path return a PV handle if it is a PV
* @cmd - handle to the LVM command instance
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index f0f0732..70efe9e 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -412,5 +412,6 @@ int vg_mark_partial_lvs(struct volume_group *vg);
int is_mirror_image_removable(struct logical_volume *mimage_lv, void *baton);
uint64_t find_min_mda_size(struct dm_list *mdas);
+char alloc_policy_char(alloc_policy_t alloc);
#endif
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index dc4a300..7c603e1 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -163,6 +163,27 @@ int is_missing_pv(const struct physical_volume *pv)
return pv_field(pv, status) & MISSING_PV ? 1 : 0;
}
+char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv)
+{
+ char *repstr;
+
+ if (!(repstr = dm_pool_zalloc(mem, 3))) {
+ log_error("dm_pool_alloc failed");
+ return NULL;
+ }
+
+ if (pv->status & ALLOCATABLE_PV)
+ repstr[0] = 'a';
+ else
+ repstr[0] = '-';
+
+ if (pv->status & EXPORTED_VG)
+ repstr[1] = 'x';
+ else
+ repstr[1] = '-';
+ return repstr;
+}
+
unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored)
{
struct lvmcache_info *info;
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index ba5c4a4..9e1c619 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -54,6 +54,7 @@ struct physical_volume {
struct device *pv_dev(const struct physical_volume *pv);
const char *pv_vg_name(const struct physical_volume *pv);
+char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv);
const char *pv_dev_name(const struct physical_volume *pv);
uint64_t pv_size(const struct physical_volume *pv);
uint64_t pv_size_field(const struct physical_volume *pv);
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index 40270ec..3315c7e 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -434,3 +434,40 @@ int vg_set_clustered(struct volume_group *vg, int clustered)
return 1;
}
+char *vg_attr_dup(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;
+}
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
index 1610087..ebb44e0 100644
--- a/lib/metadata/vg.h
+++ b/lib/metadata/vg.h
@@ -123,5 +123,6 @@ unsigned snapshot_count(const struct volume_group *vg);
uint64_t vg_mda_size(const struct volume_group *vg);
uint64_t vg_mda_free(const struct volume_group *vg);
+char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg);
#endif
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 95ad578..689f6a5 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -93,7 +93,7 @@ FIELD(PVS, pv, NUM, "1st PE", pe_start, 7, size64, pe_start, "Offset to the star
FIELD(PVS, pv, NUM, "PSize", id, 5, pvsize, pv_size, "Size of PV in current units.", 0)
FIELD(PVS, pv, NUM, "PFree", id, 5, pvfree, pv_free, "Total amount of unallocated space in current units.", 0)
FIELD(PVS, pv, NUM, "Used", id, 4, pvused, pv_used, "Total amount of allocated space in current units.", 0)
-FIELD(PVS, pv, STR, "Attr", status, 4, pvstatus, pv_attr, "Various attributes - see man page.", 0)
+FIELD(PVS, pv, STR, "Attr", id, 4, pvstatus, pv_attr, "Various attributes - see man page.", 0)
FIELD(PVS, pv, NUM, "PE", pe_count, 3, uint32, pv_pe_count, "Total number of Physical Extents.", 0)
FIELD(PVS, pv, NUM, "Alloc", pe_alloc_count, 5, uint32, pv_pe_alloc_count, "Total number of allocated Physical Extents.", 0)
FIELD(PVS, pv, STR, "PV Tags", tags, 7, tags, pv_tags, "Tags, if any.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index 703060b..d0901a5 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_dup(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;
}
@@ -390,23 +266,12 @@ static int _pvstatus_disp(struct dm_report *rh __attribute__((unused)), struct d
struct dm_report_field *field,
const void *data, void *private __attribute__((unused)))
{
- const uint32_t status = *(const uint32_t *) data;
+ const struct physical_volume *pv =
+ (const struct physical_volume *) data;
char *repstr;
- if (!(repstr = dm_pool_zalloc(mem, 3))) {
- log_error("dm_pool_alloc failed");
+ if (!(repstr = pv_attr_dup(mem, pv)))
return 0;
- }
-
- if (status & ALLOCATABLE_PV)
- repstr[0] = 'a';
- else
- repstr[0] = '-';
-
- if (status & EXPORTED_VG)
- repstr[1] = 'x';
- else
- repstr[1] = '-';
dm_report_field_set_value(field, repstr, NULL);
return 1;
@@ -419,37 +284,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_dup(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.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 05/20] Simplify logic to create 'attr' strings.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (3 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 04/20] Add {pv|vg|lv}_attr_dup() functions and refactor 'disp' functions Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 06/20] Add id_format_and_copy() common function and call from _uuid_disp Dave Wysochanski
` (14 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
This patch addresses code review request to simplify creation of 'attr'
strings. The simplification is done in this separate patch to more
easily review and ensure the simplification is done without error.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/lv.c | 30 ++++++------------------------
lib/metadata/pv.c | 11 ++---------
lib/metadata/vg.c | 30 +++++-------------------------
3 files changed, 13 insertions(+), 58 deletions(-)
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 0c01c73..6abcdab 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -61,28 +61,16 @@ char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv)
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';
+ repstr[0] = (lv_is_merging_origin(lv)) ? 'O' : 'o';
}
else if (lv->status & MIRRORED) {
- if (lv->status & MIRROR_NOTSYNCED)
- repstr[0] = 'M';
- else
- repstr[0] = 'm';
+ repstr[0] = (lv->status & MIRROR_NOTSYNCED) ? 'M' : 'm';
}else if (lv->status & MIRROR_IMAGE)
- if (_lv_mimage_in_sync(lv))
- repstr[0] = 'i';
- else
- repstr[0] = 'I';
+ repstr[0] = (_lv_mimage_in_sync(lv)) ? 'i' : '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';
+ repstr[0] = (lv_is_merging_cow(lv)) ? 'S' : 's';
} else
repstr[0] = '-';
@@ -100,10 +88,7 @@ char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv)
if (lv->status & LOCKED)
repstr[2] = toupper(repstr[2]);
- if (lv->status & FIXED_MINOR)
- repstr[3] = 'm'; /* Fixed Minor */
- else
- repstr[3] = '-';
+ repstr[3] = (lv->status & FIXED_MINOR) ? 'm' : '-';
if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) && info.exists) {
if (info.suspended)
@@ -126,10 +111,7 @@ char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv)
repstr[4] = 'I'; /* Invalid snapshot */
}
- if (info.open_count)
- repstr[5] = 'o'; /* Open */
- else
- repstr[5] = '-';
+ repstr[5] = (info.open_count) ? 'o' : '-';
} else {
repstr[4] = '-';
repstr[5] = '-';
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 7c603e1..a21b7d6 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -172,15 +172,8 @@ char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv)
return NULL;
}
- if (pv->status & ALLOCATABLE_PV)
- repstr[0] = 'a';
- else
- repstr[0] = '-';
-
- if (pv->status & EXPORTED_VG)
- repstr[1] = 'x';
- else
- repstr[1] = '-';
+ repstr[0] = (pv->status & ALLOCATABLE_PV) ? 'a' : '-';
+ repstr[1] = (pv->status & EXPORTED_VG) ? 'x' : '-';
return repstr;
}
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index 3315c7e..07cb60a 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -443,31 +443,11 @@ char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg)
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[0] = (vg->status & LVM_WRITE) ? 'w' : 'r';
+ repstr[1] = (vg_is_resizeable(vg)) ? 'z' : '-';
+ repstr[2] = (vg_is_exported(vg)) ? 'x' : '-';
+ repstr[3] = (vg_missing_pv_count(vg)) ? 'p' : '-';
repstr[4] = alloc_policy_char(vg->alloc);
-
- if (vg_is_clustered(vg))
- repstr[5] = 'c';
- else
- repstr[5] = '-';
+ repstr[5] = (vg_is_clustered(vg)) ? 'c' : '-';
return repstr;
}
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 06/20] Add id_format_and_copy() common function and call from _uuid_disp.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (4 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 05/20] Simplify logic to create 'attr' strings Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 07/20] Add pv_uuid_dup, vg_uuid_dup, and lv_uuid_dup, and call id_format_and_copy Dave Wysochanski
` (13 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Add supporting uuid function to allocate memory and call id_write_format.
Call id_format_and_copy from _uuid_disp.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/report/report.c | 7 +------
lib/uuid/uuid.c | 15 +++++++++++++++
lib/uuid/uuid.h | 2 ++
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index d0901a5..b8c5d1a 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -677,12 +677,7 @@ static int _uuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
{
char *repstr = NULL;
- if (!(repstr = dm_pool_alloc(mem, 40))) {
- log_error("dm_pool_alloc failed");
- return 0;
- }
-
- if (!id_write_format((const struct id *) data, repstr, 40))
+ if (!(repstr = id_format_and_copy(mem, (struct id *)data)))
return_0;
dm_report_field_set_value(field, repstr, NULL);
diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c
index de3f0cd..e85e852 100644
--- a/lib/uuid/uuid.c
+++ b/lib/uuid/uuid.c
@@ -206,3 +206,18 @@ int id_read_format(struct id *id, const char *buffer)
return id_valid(id);
}
+
+char *id_format_and_copy(struct dm_pool *mem, const struct id *id)
+{
+ char *repstr = NULL;
+
+ if (!(repstr = dm_pool_alloc(mem, 40))) {
+ log_error("dm_pool_alloc failed");
+ return NULL;
+ }
+
+ if (!id_write_format(id, repstr, 40))
+ return_NULL;
+
+ return repstr;
+}
diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h
index 0029639..5c8382d 100644
--- a/lib/uuid/uuid.h
+++ b/lib/uuid/uuid.h
@@ -54,4 +54,6 @@ int id_write_format(const struct id *id, char *buffer, size_t size);
*/
int id_read_format(struct id *id, const char *buffer);
+char *id_format_and_copy(struct dm_pool *mem, const struct id *id);
+
#endif
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 07/20] Add pv_uuid_dup, vg_uuid_dup, and lv_uuid_dup, and call id_format_and_copy.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (5 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 06/20] Add id_format_and_copy() common function and call from _uuid_disp Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 08/20] Add tags_format_and_copy() common function and call from _tags_disp Dave Wysochanski
` (12 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Add supporting functions for pv_uuid, vg_uuid, and lv_uuid.
Call new function id_format_and_copy. Use 'const' where appropriate.
Add "_dup" suffix to indicate memory is being allocated.
Call {pv|vg|lv}_uuid_dup from lvm2app uuid functions.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/lv.c | 5 +++++
lib/metadata/lv.h | 1 +
lib/metadata/pv.c | 5 +++++
lib/metadata/pv.h | 1 +
lib/metadata/vg.c | 5 +++++
lib/metadata/vg.h | 1 +
liblvm/lvm_lv.c | 10 ++--------
liblvm/lvm_pv.c | 10 ++--------
liblvm/lvm_vg.c | 8 +-------
9 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 6abcdab..4604653 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -16,6 +16,11 @@
#include "metadata.h"
#include "activate.h"
+char *lv_uuid_dup(const struct logical_volume *lv)
+{
+ return id_format_and_copy(lv->vg->vgmem, &lv->lvid.id[1]);
+}
+
uint64_t lv_size(const struct logical_volume *lv)
{
return lv->size;
diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h
index 4cf06b2..9e8dbe2 100644
--- a/lib/metadata/lv.h
+++ b/lib/metadata/lv.h
@@ -49,5 +49,6 @@ struct logical_volume {
uint64_t lv_size(const struct logical_volume *lv);
char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv);
+char *lv_uuid_dup(const struct logical_volume *lv);
#endif
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index a21b7d6..c60d825 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -29,6 +29,11 @@ struct id pv_id(const struct physical_volume *pv)
return pv_field(pv, id);
}
+char *pv_uuid_dup(const struct physical_volume *pv)
+{
+ return id_format_and_copy(pv->vg->vgmem, &pv->id);
+}
+
const struct format_type *pv_format_type(const struct physical_volume *pv)
{
return pv_field(pv, fmt);
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index 9e1c619..1df4957 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -56,6 +56,7 @@ struct device *pv_dev(const struct physical_volume *pv);
const char *pv_vg_name(const struct physical_volume *pv);
char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv);
const char *pv_dev_name(const struct physical_volume *pv);
+char *pv_uuid_dup(const struct physical_volume *pv);
uint64_t pv_size(const struct physical_volume *pv);
uint64_t pv_size_field(const struct physical_volume *pv);
uint64_t pv_dev_size(const struct physical_volume *pv);
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index 07cb60a..c82eaa4 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -16,6 +16,11 @@
#include "metadata.h"
#include "activate.h"
+char *vg_uuid_dup(const struct volume_group *vg)
+{
+ return id_format_and_copy(vg->vgmem, &vg->id);
+}
+
uint32_t vg_seqno(const struct volume_group *vg)
{
return vg->seqno;
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
index ebb44e0..b090894 100644
--- a/lib/metadata/vg.h
+++ b/lib/metadata/vg.h
@@ -124,5 +124,6 @@ unsigned snapshot_count(const struct volume_group *vg);
uint64_t vg_mda_size(const struct volume_group *vg);
uint64_t vg_mda_free(const struct volume_group *vg);
char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg);
+char *vg_uuid_dup(const struct volume_group *vg);
#endif
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index 4519a7b..7bdafe0 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -14,7 +14,7 @@
#include "lib.h"
#include "lvm2app.h"
-#include "metadata-exported.h"
+#include "metadata.h"
#include "lvm-string.h"
#include "defaults.h"
#include "segtype.h"
@@ -39,13 +39,7 @@ uint64_t lvm_lv_get_size(const lv_t lv)
const char *lvm_lv_get_uuid(const lv_t lv)
{
- char uuid[64] __attribute__((aligned(8)));
-
- if (!id_write_format(&lv->lvid.id[1], uuid, sizeof(uuid))) {
- log_error(INTERNAL_ERROR "unable to convert uuid");
- return NULL;
- }
- return dm_pool_strndup(lv->vg->vgmem, (const char *)uuid, 64);
+ return lv_uuid_dup(lv);
}
const char *lvm_lv_get_name(const lv_t lv)
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index db2383c..0b6b6b1 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -14,18 +14,12 @@
#include "lib.h"
#include "lvm2app.h"
-#include "metadata-exported.h"
+#include "metadata.h"
#include "lvm-string.h"
const char *lvm_pv_get_uuid(const pv_t pv)
{
- char uuid[64] __attribute__((aligned(8)));
-
- if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
- log_error(INTERNAL_ERROR "Unable to convert uuid");
- return NULL;
- }
- return dm_pool_strndup(pv->vg->vgmem, (const char *)uuid, 64);
+ return pv_uuid_dup(pv);
}
const char *lvm_pv_get_name(const pv_t pv)
diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c
index a75652d..a09208a 100644
--- a/liblvm/lvm_vg.c
+++ b/liblvm/lvm_vg.c
@@ -327,13 +327,7 @@ uint64_t lvm_vg_get_max_lv(const vg_t vg)
const char *lvm_vg_get_uuid(const vg_t vg)
{
- char uuid[64] __attribute__((aligned(8)));
-
- if (!id_write_format(&vg->id, uuid, sizeof(uuid))) {
- log_error(INTERNAL_ERROR "Unable to convert uuid");
- return NULL;
- }
- return dm_pool_strndup(vg->vgmem, (const char *)uuid, 64);
+ return vg_uuid_dup(vg);
}
const char *lvm_vg_get_name(const vg_t vg)
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 08/20] Add tags_format_and_copy() common function and call from _tags_disp.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (6 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 07/20] Add pv_uuid_dup, vg_uuid_dup, and lv_uuid_dup, and call id_format_and_copy Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 09/20] Add pv_tags_dup, vg_tags_dup, lv_tags_dup functions that call tags_format_and_copy Dave Wysochanski
` (11 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Add a common function to allocate memory and format a string of
tags.
Call tags_format_and_copy() from _tags_disp().
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/metadata.c | 24 ++++++++++++++++++++++++
lib/metadata/metadata.h | 1 +
lib/report/report.c | 21 +++------------------
3 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 07f6a90..58b5b6e 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3936,6 +3936,30 @@ char alloc_policy_char(alloc_policy_t alloc)
}
}
+char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tags)
+{
+ struct str_list *sl;
+
+ if (!dm_pool_begin_object(mem, 256)) {
+ log_error("dm_pool_begin_object failed");
+ return NULL;
+ }
+
+ dm_list_iterate_items(sl, tags) {
+ if (!dm_pool_grow_object(mem, sl->str, strlen(sl->str)) ||
+ (sl->list.n != tags && !dm_pool_grow_object(mem, ",", 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);
+}
+
/**
* pv_by_path - Given a device path return a PV handle if it is a PV
* @cmd - handle to the LVM command instance
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index 70efe9e..3ebe736 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -413,5 +413,6 @@ int is_mirror_image_removable(struct logical_volume *mimage_lv, void *baton);
uint64_t find_min_mda_size(struct dm_list *mdas);
char alloc_policy_char(alloc_policy_t alloc);
+char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tags);
#endif
diff --git a/lib/report/report.c b/lib/report/report.c
index b8c5d1a..cac4f8b 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -150,27 +150,12 @@ static int _tags_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
const void *data, void *private __attribute__((unused)))
{
const struct dm_list *tags = (const struct dm_list *) data;
- struct str_list *sl;
+ char *tags_str;
- if (!dm_pool_begin_object(mem, 256)) {
- log_error("dm_pool_begin_object failed");
- return 0;
- }
-
- dm_list_iterate_items(sl, tags) {
- if (!dm_pool_grow_object(mem, sl->str, strlen(sl->str)) ||
- (sl->list.n != tags && !dm_pool_grow_object(mem, ",", 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");
+ if (!(tags_str = tags_format_and_copy(mem, tags)))
return 0;
- }
- dm_report_field_set_value(field, dm_pool_end_object(mem), NULL);
+ dm_report_field_set_value(field, tags_str, NULL);
return 1;
}
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 09/20] Add pv_tags_dup, vg_tags_dup, lv_tags_dup functions that call tags_format_and_copy.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (7 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 08/20] Add tags_format_and_copy() common function and call from _tags_disp Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 10/20] Add supporting functions vg_name_dup, vg_fmt_dup, vg_system_id_dup Dave Wysochanski
` (10 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/lv.c | 5 +++++
lib/metadata/lv.h | 1 +
lib/metadata/pv.c | 5 +++++
lib/metadata/pv.h | 1 +
lib/metadata/vg.c | 5 +++++
lib/metadata/vg.h | 1 +
6 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 4604653..8ee7788 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -21,6 +21,11 @@ char *lv_uuid_dup(const struct logical_volume *lv)
return id_format_and_copy(lv->vg->vgmem, &lv->lvid.id[1]);
}
+char *lv_tags_dup(const struct logical_volume *lv)
+{
+ return tags_format_and_copy(lv->vg->vgmem, &lv->tags);
+}
+
uint64_t lv_size(const struct logical_volume *lv)
{
return lv->size;
diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h
index 9e8dbe2..2694c52 100644
--- a/lib/metadata/lv.h
+++ b/lib/metadata/lv.h
@@ -50,5 +50,6 @@ struct logical_volume {
uint64_t lv_size(const struct logical_volume *lv);
char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv);
char *lv_uuid_dup(const struct logical_volume *lv);
+char *lv_tags_dup(const struct logical_volume *lv);
#endif
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index c60d825..5d29693 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -34,6 +34,11 @@ char *pv_uuid_dup(const struct physical_volume *pv)
return id_format_and_copy(pv->vg->vgmem, &pv->id);
}
+char *pv_tags_dup(const struct physical_volume *pv)
+{
+ return tags_format_and_copy(pv->vg->vgmem, &pv->tags);
+}
+
const struct format_type *pv_format_type(const struct physical_volume *pv)
{
return pv_field(pv, fmt);
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index 1df4957..14133c7 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -57,6 +57,7 @@ const char *pv_vg_name(const struct physical_volume *pv);
char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv);
const char *pv_dev_name(const struct physical_volume *pv);
char *pv_uuid_dup(const struct physical_volume *pv);
+char *pv_tags_dup(const struct physical_volume *pv);
uint64_t pv_size(const struct physical_volume *pv);
uint64_t pv_size_field(const struct physical_volume *pv);
uint64_t pv_dev_size(const struct physical_volume *pv);
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index c82eaa4..c79f136 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -21,6 +21,11 @@ char *vg_uuid_dup(const struct volume_group *vg)
return id_format_and_copy(vg->vgmem, &vg->id);
}
+char *vg_tags_dup(const struct volume_group *vg)
+{
+ return tags_format_and_copy(vg->vgmem, &vg->tags);
+}
+
uint32_t vg_seqno(const struct volume_group *vg)
{
return vg->seqno;
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
index b090894..6071ccb 100644
--- a/lib/metadata/vg.h
+++ b/lib/metadata/vg.h
@@ -125,5 +125,6 @@ uint64_t vg_mda_size(const struct volume_group *vg);
uint64_t vg_mda_free(const struct volume_group *vg);
char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg);
char *vg_uuid_dup(const struct volume_group *vg);
+char *vg_tags_dup(const struct volume_group *vg);
#endif
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 10/20] Add supporting functions vg_name_dup, vg_fmt_dup, vg_system_id_dup.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (8 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 09/20] Add pv_tags_dup, vg_tags_dup, lv_tags_dup functions that call tags_format_and_copy Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 11/20] Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv Dave Wysochanski
` (9 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Add supporting functions for vg_name, vg_fmt, vg_system_id.
Append "_dup" to end of supporting functions to make clear the strings
are dup'd and to avoid namespace conflict with vg_name.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/vg.c | 17 +++++++++++++++++
lib/metadata/vg.h | 3 +++
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index c79f136..05477b2 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -16,6 +16,23 @@
#include "metadata.h"
#include "activate.h"
+char *vg_fmt_dup(const struct volume_group *vg)
+{
+ if (!vg->fid || !vg->fid->fmt)
+ return NULL;
+ return dm_pool_strdup(vg->vgmem, vg->fid->fmt->name);
+}
+
+char *vg_name_dup(const struct volume_group *vg)
+{
+ return dm_pool_strdup(vg->vgmem, vg->name);
+}
+
+char *vg_system_id_dup(const struct volume_group *vg)
+{
+ return dm_pool_strdup(vg->vgmem, vg->system_id);
+}
+
char *vg_uuid_dup(const struct volume_group *vg)
{
return id_format_and_copy(vg->vgmem, &vg->id);
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
index 6071ccb..d4e6557 100644
--- a/lib/metadata/vg.h
+++ b/lib/metadata/vg.h
@@ -93,6 +93,9 @@ struct volume_group {
uint32_t mda_copies; /* target number of mdas for this VG */
};
+char *vg_fmt_dup(const struct volume_group *vg);
+char *vg_name_dup(const struct volume_group *vg);
+char *vg_system_id_dup(const struct volume_group *vg);
uint32_t vg_seqno(const struct volume_group *vg);
uint64_t vg_status(const struct volume_group *vg);
int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc);
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 11/20] Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (9 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 10/20] Add supporting functions vg_name_dup, vg_fmt_dup, vg_system_id_dup Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-23 12:36 ` Zdenek Kabelac
2010-09-22 21:06 ` [PATCH 12/20] Add 'get' functions for vg fields Dave Wysochanski
` (8 subsequent siblings)
19 siblings, 1 reply; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Will need similar macros for VG, PV and LV, so define a generic one, and just
pass in the struct name and variable name for the specific macro.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/report/properties.c | 25 +++++++++++++++++++++++--
1 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index 9e3cad3..b39a979 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -20,14 +20,35 @@
#include "lvm-types.h"
#include "metadata.h"
-#define GET_NUM_PROPERTY_FN(NAME, VALUE) \
+#define GET_NUM_PROPERTY_FN(NAME, VALUE, STRUCT, VAR) \
static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \
{ \
- struct volume_group *vg = (struct volume_group *)obj; \
+ struct STRUCT *VAR = (struct STRUCT *)obj; \
\
prop->v.n_val = VALUE; \
return 1; \
}
+#define GET_VG_NUM_PROPERTY_FN(NAME, VALUE) \
+ GET_NUM_PROPERTY_FN(NAME, VALUE, volume_group, vg)
+#define GET_PV_NUM_PROPERTY_FN(NAME, VALUE) \
+ GET_NUM_PROPERTY_FN(NAME, VALUE, physical_volume, pv)
+#define GET_LV_NUM_PROPERTY_FN(NAME, VALUE) \
+ GET_NUM_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
+
+#define GET_STR_PROPERTY_FN(NAME, VALUE, STRUCT, VAR) \
+static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \
+{ \
+ struct STRUCT *VAR = (struct STRUCT *)obj; \
+\
+ prop->v.s_val = (char *)VALUE; \
+ return 1; \
+}
+#define GET_VG_STR_PROPERTY_FN(NAME, VALUE) \
+ GET_STR_PROPERTY_FN(NAME, VALUE, volume_group, vg)
+#define GET_PV_STR_PROPERTY_FN(NAME, VALUE) \
+ GET_STR_PROPERTY_FN(NAME, VALUE, physical_volume, pv)
+#define GET_LV_STR_PROPERTY_FN(NAME, VALUE) \
+ GET_STR_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
static int _not_implemented(void *obj, struct lvm_property_type *prop)
{
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 11/20] Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv.
2010-09-22 21:06 ` [PATCH 11/20] Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv Dave Wysochanski
@ 2010-09-23 12:36 ` Zdenek Kabelac
2010-09-23 2:31 ` Dave Wysochanski
0 siblings, 1 reply; 23+ messages in thread
From: Zdenek Kabelac @ 2010-09-23 12:36 UTC (permalink / raw)
To: lvm-devel
Dne 22.9.2010 23:06, Dave Wysochanski napsal(a):
> Will need similar macros for VG, PV and LV, so define a generic one, and just
> pass in the struct name and variable name for the specific macro.
>
> Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
> ---
> lib/report/properties.c | 25 +++++++++++++++++++++++--
> 1 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/lib/report/properties.c b/lib/report/properties.c
> index 9e3cad3..b39a979 100644
> --- a/lib/report/properties.c
> +++ b/lib/report/properties.c
> @@ -20,14 +20,35 @@
> #include "lvm-types.h"
> #include "metadata.h"
>
> -#define GET_NUM_PROPERTY_FN(NAME, VALUE) \
> +#define GET_NUM_PROPERTY_FN(NAME, VALUE, STRUCT, VAR) \
> static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \
> { \
> - struct volume_group *vg = (struct volume_group *)obj; \
> + struct STRUCT *VAR = (struct STRUCT *)obj; \
struct STRUCT *VAR
looks weird... isn't there something better?
Zdenek
^ permalink raw reply [flat|nested] 23+ messages in thread* [PATCH 11/20] Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv.
2010-09-23 12:36 ` Zdenek Kabelac
@ 2010-09-23 2:31 ` Dave Wysochanski
0 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-23 2:31 UTC (permalink / raw)
To: lvm-devel
On Thu, 2010-09-23 at 14:36 +0200, Zdenek Kabelac wrote:
> Dne 22.9.2010 23:06, Dave Wysochanski napsal(a):
> > Will need similar macros for VG, PV and LV, so define a generic one, and just
> > pass in the struct name and variable name for the specific macro.
> >
> > Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
> > ---
> > lib/report/properties.c | 25 +++++++++++++++++++++++--
> > 1 files changed, 23 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/report/properties.c b/lib/report/properties.c
> > index 9e3cad3..b39a979 100644
> > --- a/lib/report/properties.c
> > +++ b/lib/report/properties.c
> > @@ -20,14 +20,35 @@
> > #include "lvm-types.h"
> > #include "metadata.h"
> >
> > -#define GET_NUM_PROPERTY_FN(NAME, VALUE) \
> > +#define GET_NUM_PROPERTY_FN(NAME, VALUE, STRUCT, VAR) \
> > static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \
> > { \
> > - struct volume_group *vg = (struct volume_group *)obj; \
> > + struct STRUCT *VAR = (struct STRUCT *)obj; \
>
>
> struct STRUCT *VAR
>
>
> looks weird... isn't there something better?
>
"struct TYPE *VAR" ?
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 12/20] Add 'get' functions for vg fields.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (10 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 11/20] Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 13/20] Add lvm_vg_get_property() generic vg property function Dave Wysochanski
` (7 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Add 'get' functions based on generic macros for VG, PV, and LV.
Add 'get' functions for vg string fields, vg_name, vg_fmt, vg_sysid,
vg_uuid, vg_attr, and vg_tags, and all numeric fields.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/report/properties.c | 44 ++++++++++++++++++++++----------------------
1 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index b39a979..89a462b 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -135,49 +135,49 @@ static int _not_implemented(void *obj, struct lvm_property_type *prop)
#define _modules_set _not_implemented
/* VG */
-#define _vg_fmt_get _not_implemented
+GET_VG_STR_PROPERTY_FN(vg_fmt, vg_fmt_dup(vg))
#define _vg_fmt_set _not_implemented
-#define _vg_uuid_get _not_implemented
+GET_VG_STR_PROPERTY_FN(vg_uuid, vg_uuid_dup(vg))
#define _vg_uuid_set _not_implemented
-#define _vg_name_get _not_implemented
+GET_VG_STR_PROPERTY_FN(vg_name, vg_name_dup(vg))
#define _vg_name_set _not_implemented
-#define _vg_attr_get _not_implemented
+GET_VG_STR_PROPERTY_FN(vg_attr, vg_attr_dup(vg->vgmem, vg))
#define _vg_attr_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_size, (SECTOR_SIZE * vg_size(vg)))
+GET_VG_NUM_PROPERTY_FN(vg_size, (SECTOR_SIZE * vg_size(vg)))
#define _vg_size_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_free, (SECTOR_SIZE * vg_free(vg)))
+GET_VG_NUM_PROPERTY_FN(vg_free, (SECTOR_SIZE * vg_free(vg)))
#define _vg_free_set _not_implemented
-#define _vg_sysid_get _not_implemented
+GET_VG_STR_PROPERTY_FN(vg_sysid, vg_system_id_dup(vg))
#define _vg_sysid_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_extent_size, vg->extent_size)
+GET_VG_NUM_PROPERTY_FN(vg_extent_size, vg->extent_size)
#define _vg_extent_size_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_extent_count, vg->extent_count)
+GET_VG_NUM_PROPERTY_FN(vg_extent_count, vg->extent_count)
#define _vg_extent_count_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_free_count, vg->free_count)
+GET_VG_NUM_PROPERTY_FN(vg_free_count, vg->free_count)
#define _vg_free_count_set _not_implemented
-GET_NUM_PROPERTY_FN(max_lv, vg->max_lv)
+GET_VG_NUM_PROPERTY_FN(max_lv, vg->max_lv)
#define _max_lv_set _not_implemented
-GET_NUM_PROPERTY_FN(max_pv, vg->max_pv)
+GET_VG_NUM_PROPERTY_FN(max_pv, vg->max_pv)
#define _max_pv_set _not_implemented
-GET_NUM_PROPERTY_FN(pv_count, vg->pv_count)
+GET_VG_NUM_PROPERTY_FN(pv_count, vg->pv_count)
#define _pv_count_set _not_implemented
-GET_NUM_PROPERTY_FN(lv_count, (vg_visible_lvs(vg)))
+GET_VG_NUM_PROPERTY_FN(lv_count, (vg_visible_lvs(vg)))
#define _lv_count_set _not_implemented
-GET_NUM_PROPERTY_FN(snap_count, (snapshot_count(vg)))
+GET_VG_NUM_PROPERTY_FN(snap_count, (snapshot_count(vg)))
#define _snap_count_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_seqno, vg->seqno)
+GET_VG_NUM_PROPERTY_FN(vg_seqno, vg->seqno)
#define _vg_seqno_set _not_implemented
-#define _vg_tags_get _not_implemented
+GET_VG_STR_PROPERTY_FN(vg_tags, vg_tags_dup(vg))
#define _vg_tags_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_mda_count, (vg_mda_count(vg)))
+GET_VG_NUM_PROPERTY_FN(vg_mda_count, (vg_mda_count(vg)))
#define _vg_mda_count_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_mda_used_count, (vg_mda_used_count(vg)))
+GET_VG_NUM_PROPERTY_FN(vg_mda_used_count, (vg_mda_used_count(vg)))
#define _vg_mda_used_count_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_mda_free, (SECTOR_SIZE * vg_mda_free(vg)))
+GET_VG_NUM_PROPERTY_FN(vg_mda_free, (SECTOR_SIZE * vg_mda_free(vg)))
#define _vg_mda_free_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg)))
+GET_VG_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg)))
#define _vg_mda_size_set _not_implemented
-GET_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg)))
+GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg)))
#define _vg_mda_copies_set _not_implemented
/* LVSEG */
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 13/20] Add lvm_vg_get_property() generic vg property function.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (11 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 12/20] Add 'get' functions for vg fields Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 14/20] Add tests for lvm_vg_get_property() Dave Wysochanski
` (6 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Add a generic VG property function to lvm2app. Call the internal library
vg_get_property() function. Strings are dup'd internally.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
liblvm/lvm2app.h | 42 ++++++++++++++++++++++++++++++++++++++++++
liblvm/lvm_vg.c | 19 +++++++++++++++++++
2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 47d3417..cc839a6 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -168,6 +168,22 @@ typedef struct lvm_str_list {
const char *str;
} lvm_str_list_t;
+/**
+ * Property Value
+ *
+ * This structure defines a single LVM property value for an LVM object.
+ * The structures are returned by functions such as
+ * lvm_vg_get_property() and lvm_vg_set_property().
+ */
+typedef struct lvm_property_value {
+ unsigned is_writeable;
+ unsigned is_string;
+ union {
+ char *s_val;
+ uint64_t n_val;
+ } v;
+} lvm_property_value_t;
+
/*************************** generic lvm handling ***************************/
/**
* Create a LVM handle.
@@ -848,6 +864,32 @@ uint64_t lvm_vg_get_max_lv(const vg_t vg);
*/
struct dm_list *lvm_vg_get_tags(const vg_t vg);
+/**
+ * Get the value of a VG property
+ *
+ * \memberof vg_t
+ *
+ * The memory allocated for a string property value is tied to the vg_t
+ * handle and will be released when lvm_vg_close() is called.
+ *
+ * Example:
+ * lvm_property_value value;
+ *
+ * if (lvm_vg_get_property(vg, "vg_mda_count", &value) < 0) {
+ * // handle error
+ * }
+ * if (value.is_string)
+ * printf(", value = %s\n", value.u.s_val);
+ * else
+ * printf(", value = %"PRIu64"\n", value.u.n_val);
+ *
+ *
+ * \return
+ * 0 (success) or -1 (failure).
+ */
+int lvm_vg_get_property(vg_t vg, const char *name,
+ struct lvm_property_value *value);
+
/************************** logical volume handling *************************/
/**
diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c
index a09208a..6fabe19 100644
--- a/liblvm/lvm_vg.c
+++ b/liblvm/lvm_vg.c
@@ -20,6 +20,7 @@
#include "locking.h"
#include "lvmcache.h"
#include "lvm_misc.h"
+#include "properties.h"
int lvm_vg_add_tag(vg_t vg, const char *tag)
{
@@ -335,6 +336,24 @@ const char *lvm_vg_get_name(const vg_t vg)
return dm_pool_strndup(vg->vgmem, (const char *)vg->name, NAME_LEN+1);
}
+
+int lvm_vg_get_property(vg_t vg, const char *name,
+ struct lvm_property_value *value)
+{
+ struct lvm_property_type prop;
+
+ strncpy(prop.id, name, LVM_PROPERTY_NAME_LEN);
+ if (!vg_get_property(vg, &prop))
+ return -1;
+ value->is_writeable = prop.is_writeable;
+ value->is_string = prop.is_string;
+ if (value->is_string)
+ value->v.s_val = prop.v.s_val;
+ else
+ value->v.n_val = prop.v.n_val;
+ return 0;
+}
+
struct dm_list *lvm_list_vg_names(lvm_t libh)
{
return get_vgnames((struct cmd_context *)libh, 0);
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 14/20] Add tests for lvm_vg_get_property().
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (12 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 13/20] Add lvm_vg_get_property() generic vg property function Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 15/20] Add pv_mda_size, pv_mda_free, and pv_used functions, call from 'disp' functions Dave Wysochanski
` (5 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
test/api/test.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/test/api/test.c b/test/api/test.c
index f89840c..4560655 100644
--- a/test/api/test.c
+++ b/test/api/test.c
@@ -91,6 +91,8 @@ static void _show_help(void)
"Issue a lvm_config_override() with accept device filter\n");
printf("'vg_get_tags vgname': "
"List the tags of a VG\n");
+ printf("'vg_get_property vgname property_name': "
+ "Display the value of VG property\n");
printf("'lv_get_tags vgname lvname': "
"List the tags of a LV\n");
printf("'vg_{add|remove}_tag vgname tag': "
@@ -546,6 +548,35 @@ static void _vg_tag(char **argv, int argc, int add)
add ? "adding":"removing", argv[2], argv[1]);
}
+static void _vg_get_property(char **argv, int argc)
+{
+ vg_t vg;
+ struct lvm_property_value value;
+ int rc;
+
+ if (argc < 3) {
+ printf("Please enter vgname, field_id\n");
+ return;
+ }
+ if (!(vg = _lookup_vg_by_name(argv, argc)))
+ return;
+ rc = lvm_vg_get_property(vg, argv[2], &value);
+ if (rc)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("Obtaining value of property %s in VG %s",
+ argv[2], argv[1]);
+ if (rc) {
+ printf("\n");
+ return;
+ }
+ if (value.is_string)
+ printf(", value = %s\n", value.v.s_val);
+ else
+ printf(", value = %"PRIu64"\n", value.v.n_val);
+}
+
static void _lv_get_tags(char **argv, int argc)
{
lv_t lv;
@@ -796,6 +827,8 @@ static int lvmapi_test_shell(lvm_t libh)
_vg_tag(argv, argc, 0);
} else if (!strcmp(argv[0], "vg_get_tags")) {
_vg_get_tags(argv, argc);
+ } else if (!strcmp(argv[0], "vg_get_property")) {
+ _vg_get_property(argv, argc);
} else if (!strcmp(argv[0], "lv_add_tag")) {
_lv_tag(argv, argc, 1);
} else if (!strcmp(argv[0], "lv_remove_tag")) {
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 15/20] Add pv_mda_size, pv_mda_free, and pv_used functions, call from 'disp' functions.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (13 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 14/20] Add tests for lvm_vg_get_property() Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 16/20] Add pv_name_dup() and pv_fmt_dup() helper functions Dave Wysochanski
` (4 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/pv.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
lib/metadata/pv.h | 3 +++
lib/report/report.c | 34 +++++++++-------------------------
3 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 5d29693..8b4dbf5 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -187,6 +187,50 @@ char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv)
return repstr;
}
+uint64_t pv_mda_size(const struct physical_volume *pv)
+{
+ struct lvmcache_info *info;
+ uint64_t min_mda_size = 0;
+ const char *pvid = (const char *)(&pv->id.uuid);
+
+ /* PVs could have 2 mdas of different sizes (rounding effect) */
+ if ((info = info_from_pvid(pvid, 0)))
+ min_mda_size = find_min_mda_size(&info->mdas);
+ return min_mda_size;
+}
+
+uint64_t pv_mda_free(const struct physical_volume *pv)
+{
+ struct lvmcache_info *info;
+ uint64_t freespace = UINT64_MAX, mda_free;
+ const char *pvid = (const char *)&pv->id.uuid;
+ struct metadata_area *mda;
+
+ if ((info = info_from_pvid(pvid, 0)))
+ dm_list_iterate_items(mda, &info->mdas) {
+ if (!mda->ops->mda_free_sectors)
+ continue;
+ mda_free = mda->ops->mda_free_sectors(mda);
+ if (mda_free < freespace)
+ freespace = mda_free;
+ }
+
+ if (freespace == UINT64_MAX)
+ freespace = UINT64_C(0);
+ return freespace;
+}
+
+uint64_t pv_used(const struct physical_volume *pv)
+{
+ uint64_t used;
+
+ if (!pv->pe_count)
+ used = 0LL;
+ else
+ used = (uint64_t) pv->pe_alloc_count * pv->pe_size;
+ return used;
+}
+
unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored)
{
struct lvmcache_info *info;
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index 14133c7..295f811 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -67,6 +67,9 @@ uint32_t pv_pe_size(const struct physical_volume *pv);
uint64_t pv_pe_start(const struct physical_volume *pv);
uint32_t pv_pe_count(const struct physical_volume *pv);
uint32_t pv_pe_alloc_count(const struct physical_volume *pv);
+uint64_t pv_mda_size(const struct physical_volume *pv);
+uint64_t pv_mda_free(const struct physical_volume *pv);
+uint64_t pv_used(const struct physical_volume *pv);
uint32_t pv_mda_count(const struct physical_volume *pv);
uint32_t pv_mda_used_count(const struct physical_volume *pv);
unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored);
diff --git a/lib/report/report.c b/lib/report/report.c
index cac4f8b..95f4550 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -597,10 +597,7 @@ static int _pvused_disp(struct dm_report *rh, struct dm_pool *mem,
(const struct physical_volume *) data;
uint64_t used;
- if (!pv->pe_count)
- used = 0LL;
- else
- used = (uint64_t) pv->pe_alloc_count * pv->pe_size;
+ used = pv_used(pv);
return _size64_disp(rh, mem, field, &used, private);
}
@@ -754,22 +751,11 @@ static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- struct lvmcache_info *info;
- uint64_t freespace = UINT64_MAX, mda_free;
- const char *pvid = (const char *)(&((const struct id *) data)->uuid);
- struct metadata_area *mda;
-
- if ((info = info_from_pvid(pvid, 0)))
- dm_list_iterate_items(mda, &info->mdas) {
- if (!mda->ops->mda_free_sectors)
- continue;
- mda_free = mda->ops->mda_free_sectors(mda);
- if (mda_free < freespace)
- freespace = mda_free;
- }
+ const struct physical_volume *pv =
+ (const struct physical_volume *) data;
+ uint64_t freespace;
- if (freespace == UINT64_MAX)
- freespace = UINT64_C(0);
+ freespace = pv_mda_free(pv);
return _size64_disp(rh, mem, field, &freespace, private);
}
@@ -778,13 +764,11 @@ static int _pvmdasize_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- struct lvmcache_info *info;
- uint64_t min_mda_size = 0;
- const char *pvid = (const char *)(&((const struct id *) data)->uuid);
+ const struct physical_volume *pv =
+ (const struct physical_volume *) data;
+ uint64_t min_mda_size;
- /* PVs could have 2 mdas of different sizes (rounding effect) */
- if ((info = info_from_pvid(pvid, 0)))
- min_mda_size = find_min_mda_size(&info->mdas);
+ min_mda_size = pv_mda_size(pv);
return _size64_disp(rh, mem, field, &min_mda_size, private);
}
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 16/20] Add pv_name_dup() and pv_fmt_dup() helper functions.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (14 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 15/20] Add pv_mda_size, pv_mda_free, and pv_used functions, call from 'disp' functions Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 17/20] Add pv 'get' functions for all pv properties Dave Wysochanski
` (3 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/metadata/pv.c | 12 ++++++++++++
lib/metadata/pv.h | 2 ++
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 8b4dbf5..e4c73d3 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -21,6 +21,18 @@
*/
#define pv_field(handle, field) ((handle)->field)
+char *pv_fmt_dup(const struct physical_volume *pv)
+{
+ if (!pv->fmt)
+ return NULL;
+ return dm_pool_strdup(pv->vg->vgmem, pv->fmt->name);
+}
+
+char *pv_name_dup(const struct physical_volume *pv)
+{
+ return dm_pool_strdup(pv->vg->vgmem, dev_name(pv->dev));
+}
+
/*
* Gets/Sets for external LVM library
*/
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index 295f811..0be1e23 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -52,6 +52,8 @@ struct physical_volume {
struct dm_list tags;
};
+char *pv_fmt_dup(const struct physical_volume *pv);
+char *pv_name_dup(const struct physical_volume *pv);
struct device *pv_dev(const struct physical_volume *pv);
const char *pv_vg_name(const struct physical_volume *pv);
char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv);
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 17/20] Add pv 'get' functions for all pv properties.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (15 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 16/20] Add pv_name_dup() and pv_fmt_dup() helper functions Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 18/20] Add pv_get_property and create generic internal _get_property function Dave Wysochanski
` (2 subsequent siblings)
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Add 'get' functions for all pv properties.
Multiply by SECTOR_SIZE for pv properties pv_mda_free, pv_mda_size,
pe_start, pv_size, pv_free, pv_used.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/report/properties.c | 32 ++++++++++++++++----------------
1 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index 89a462b..18a5d09 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -57,37 +57,37 @@ static int _not_implemented(void *obj, struct lvm_property_type *prop)
}
/* PV */
-#define _pv_fmt_get _not_implemented
+GET_PV_STR_PROPERTY_FN(pv_fmt, pv_fmt_dup(pv))
#define _pv_fmt_set _not_implemented
-#define _pv_uuid_get _not_implemented
+GET_PV_STR_PROPERTY_FN(pv_uuid, pv_uuid_dup(pv))
#define _pv_uuid_set _not_implemented
-#define _dev_size_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(dev_size, SECTOR_SIZE * pv_dev_size(pv))
#define _dev_size_set _not_implemented
-#define _pv_name_get _not_implemented
+GET_PV_STR_PROPERTY_FN(pv_name, pv_name_dup(pv))
#define _pv_name_set _not_implemented
-#define _pv_mda_free_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_mda_free, SECTOR_SIZE * pv_mda_free(pv))
#define _pv_mda_free_set _not_implemented
-#define _pv_mda_size_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_mda_size, SECTOR_SIZE * pv_mda_size(pv))
#define _pv_mda_size_set _not_implemented
-#define _pe_start_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pe_start, SECTOR_SIZE * pv->pe_start)
#define _pe_start_set _not_implemented
-#define _pv_size_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_size, SECTOR_SIZE * pv_size_field(pv))
#define _pv_size_set _not_implemented
-#define _pv_free_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_free, SECTOR_SIZE * pv_free(pv))
#define _pv_free_set _not_implemented
-#define _pv_used_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_used, SECTOR_SIZE * pv_used(pv))
#define _pv_used_set _not_implemented
-#define _pv_attr_get _not_implemented
+GET_PV_STR_PROPERTY_FN(pv_attr, pv_attr_dup(pv->vg->vgmem, pv))
#define _pv_attr_set _not_implemented
-#define _pv_pe_count_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_pe_count, pv->pe_count)
#define _pv_pe_count_set _not_implemented
-#define _pv_pe_alloc_count_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_pe_alloc_count, pv->pe_alloc_count)
#define _pv_pe_alloc_count_set _not_implemented
-#define _pv_tags_get _not_implemented
+GET_PV_STR_PROPERTY_FN(pv_tags, pv_tags_dup(pv))
#define _pv_tags_set _not_implemented
-#define _pv_mda_count_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_mda_count, pv_mda_count(pv))
#define _pv_mda_count_set _not_implemented
-#define _pv_mda_used_count_get _not_implemented
+GET_PV_NUM_PROPERTY_FN(pv_mda_used_count, pv_mda_used_count(pv))
#define _pv_mda_used_count_set _not_implemented
/* LV */
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 18/20] Add pv_get_property and create generic internal _get_property function.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (16 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 17/20] Add pv 'get' functions for all pv properties Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 19/20] Add lvm_pv_get_property() generic function to obtain value of any pv property Dave Wysochanski
2010-09-22 21:06 ` [PATCH 20/20] Add pv_get_property to interactive test Dave Wysochanski
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
We need to use a similar function for pv and lv properties, so just make
a generic _get_property() function that contains most of the required
functionality. Also, add a check to ensure the field name matches the
object passed in by re-using report_type_t enum. For pv properties,
the report_type might be either PVS or LABEL.
In addition, add 'const' to 'get' functions object parameter, but not
'set' functions. Add _not_implemented_set() and _not_implemented_get()
functions.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
lib/report/properties.c | 266 +++++++++++++++++++++++++---------------------
lib/report/properties.h | 9 ++-
2 files changed, 152 insertions(+), 123 deletions(-)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index 18a5d09..d0c5fdd 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -21,9 +21,9 @@
#include "metadata.h"
#define GET_NUM_PROPERTY_FN(NAME, VALUE, STRUCT, VAR) \
-static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \
+static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
{ \
- struct STRUCT *VAR = (struct STRUCT *)obj; \
+ const struct STRUCT *VAR = (const struct STRUCT *)obj; \
\
prop->v.n_val = VALUE; \
return 1; \
@@ -36,9 +36,9 @@ static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \
GET_NUM_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
#define GET_STR_PROPERTY_FN(NAME, VALUE, STRUCT, VAR) \
-static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \
+static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
{ \
- struct STRUCT *VAR = (struct STRUCT *)obj; \
+ const struct STRUCT *VAR = (const struct STRUCT *)obj; \
\
prop->v.s_val = (char *)VALUE; \
return 1; \
@@ -50,7 +50,13 @@ static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \
#define GET_LV_STR_PROPERTY_FN(NAME, VALUE) \
GET_STR_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
-static int _not_implemented(void *obj, struct lvm_property_type *prop)
+static int _not_implemented_get(const void *obj, struct lvm_property_type *prop)
+{
+ log_errno(ENOSYS, "Function not implemented");
+ return 0;
+}
+
+static int _not_implemented_set(void *obj, struct lvm_property_type *prop)
{
log_errno(ENOSYS, "Function not implemented");
return 0;
@@ -58,174 +64,174 @@ static int _not_implemented(void *obj, struct lvm_property_type *prop)
/* PV */
GET_PV_STR_PROPERTY_FN(pv_fmt, pv_fmt_dup(pv))
-#define _pv_fmt_set _not_implemented
+#define _pv_fmt_set _not_implemented_set
GET_PV_STR_PROPERTY_FN(pv_uuid, pv_uuid_dup(pv))
-#define _pv_uuid_set _not_implemented
+#define _pv_uuid_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(dev_size, SECTOR_SIZE * pv_dev_size(pv))
-#define _dev_size_set _not_implemented
+#define _dev_size_set _not_implemented_set
GET_PV_STR_PROPERTY_FN(pv_name, pv_name_dup(pv))
-#define _pv_name_set _not_implemented
+#define _pv_name_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_mda_free, SECTOR_SIZE * pv_mda_free(pv))
-#define _pv_mda_free_set _not_implemented
+#define _pv_mda_free_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_mda_size, SECTOR_SIZE * pv_mda_size(pv))
-#define _pv_mda_size_set _not_implemented
+#define _pv_mda_size_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pe_start, SECTOR_SIZE * pv->pe_start)
-#define _pe_start_set _not_implemented
+#define _pe_start_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_size, SECTOR_SIZE * pv_size_field(pv))
-#define _pv_size_set _not_implemented
+#define _pv_size_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_free, SECTOR_SIZE * pv_free(pv))
-#define _pv_free_set _not_implemented
+#define _pv_free_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_used, SECTOR_SIZE * pv_used(pv))
-#define _pv_used_set _not_implemented
+#define _pv_used_set _not_implemented_set
GET_PV_STR_PROPERTY_FN(pv_attr, pv_attr_dup(pv->vg->vgmem, pv))
-#define _pv_attr_set _not_implemented
+#define _pv_attr_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_pe_count, pv->pe_count)
-#define _pv_pe_count_set _not_implemented
+#define _pv_pe_count_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_pe_alloc_count, pv->pe_alloc_count)
-#define _pv_pe_alloc_count_set _not_implemented
+#define _pv_pe_alloc_count_set _not_implemented_set
GET_PV_STR_PROPERTY_FN(pv_tags, pv_tags_dup(pv))
-#define _pv_tags_set _not_implemented
+#define _pv_tags_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_mda_count, pv_mda_count(pv))
-#define _pv_mda_count_set _not_implemented
+#define _pv_mda_count_set _not_implemented_set
GET_PV_NUM_PROPERTY_FN(pv_mda_used_count, pv_mda_used_count(pv))
-#define _pv_mda_used_count_set _not_implemented
+#define _pv_mda_used_count_set _not_implemented_set
/* LV */
-#define _lv_uuid_get _not_implemented
-#define _lv_uuid_set _not_implemented
-#define _lv_name_get _not_implemented
-#define _lv_name_set _not_implemented
-#define _lv_path_get _not_implemented
-#define _lv_path_set _not_implemented
-#define _lv_attr_get _not_implemented
-#define _lv_attr_set _not_implemented
-#define _lv_major_get _not_implemented
-#define _lv_major_set _not_implemented
-#define _lv_minor_get _not_implemented
-#define _lv_minor_set _not_implemented
-#define _lv_read_ahead_get _not_implemented
-#define _lv_read_ahead_set _not_implemented
-#define _lv_kernel_major_get _not_implemented
-#define _lv_kernel_major_set _not_implemented
-#define _lv_kernel_minor_get _not_implemented
-#define _lv_kernel_minor_set _not_implemented
-#define _lv_kernel_read_ahead_get _not_implemented
-#define _lv_kernel_read_ahead_set _not_implemented
-#define _lv_size_get _not_implemented
-#define _lv_size_set _not_implemented
-#define _seg_count_get _not_implemented
-#define _seg_count_set _not_implemented
-#define _origin_get _not_implemented
-#define _origin_set _not_implemented
-#define _origin_size_get _not_implemented
-#define _origin_size_set _not_implemented
-#define _snap_percent_get _not_implemented
-#define _snap_percent_set _not_implemented
-#define _copy_percent_get _not_implemented
-#define _copy_percent_set _not_implemented
-#define _move_pv_get _not_implemented
-#define _move_pv_set _not_implemented
-#define _convert_lv_get _not_implemented
-#define _convert_lv_set _not_implemented
-#define _lv_tags_get _not_implemented
-#define _lv_tags_set _not_implemented
-#define _mirror_log_get _not_implemented
-#define _mirror_log_set _not_implemented
-#define _modules_get _not_implemented
-#define _modules_set _not_implemented
+#define _lv_uuid_get _not_implemented_get
+#define _lv_uuid_set _not_implemented_set
+#define _lv_name_get _not_implemented_get
+#define _lv_name_set _not_implemented_set
+#define _lv_path_get _not_implemented_get
+#define _lv_path_set _not_implemented_set
+#define _lv_attr_get _not_implemented_get
+#define _lv_attr_set _not_implemented_set
+#define _lv_major_get _not_implemented_get
+#define _lv_major_set _not_implemented_set
+#define _lv_minor_get _not_implemented_get
+#define _lv_minor_set _not_implemented_set
+#define _lv_read_ahead_get _not_implemented_get
+#define _lv_read_ahead_set _not_implemented_set
+#define _lv_kernel_major_get _not_implemented_get
+#define _lv_kernel_major_set _not_implemented_set
+#define _lv_kernel_minor_get _not_implemented_get
+#define _lv_kernel_minor_set _not_implemented_set
+#define _lv_kernel_read_ahead_get _not_implemented_get
+#define _lv_kernel_read_ahead_set _not_implemented_set
+#define _lv_size_get _not_implemented_get
+#define _lv_size_set _not_implemented_set
+#define _seg_count_get _not_implemented_get
+#define _seg_count_set _not_implemented_set
+#define _origin_get _not_implemented_get
+#define _origin_set _not_implemented_set
+#define _origin_size_get _not_implemented_get
+#define _origin_size_set _not_implemented_set
+#define _snap_percent_get _not_implemented_get
+#define _snap_percent_set _not_implemented_set
+#define _copy_percent_get _not_implemented_get
+#define _copy_percent_set _not_implemented_set
+#define _move_pv_get _not_implemented_get
+#define _move_pv_set _not_implemented_set
+#define _convert_lv_get _not_implemented_get
+#define _convert_lv_set _not_implemented_set
+#define _lv_tags_get _not_implemented_get
+#define _lv_tags_set _not_implemented_set
+#define _mirror_log_get _not_implemented_get
+#define _mirror_log_set _not_implemented_set
+#define _modules_get _not_implemented_get
+#define _modules_set _not_implemented_set
/* VG */
GET_VG_STR_PROPERTY_FN(vg_fmt, vg_fmt_dup(vg))
-#define _vg_fmt_set _not_implemented
+#define _vg_fmt_set _not_implemented_set
GET_VG_STR_PROPERTY_FN(vg_uuid, vg_uuid_dup(vg))
-#define _vg_uuid_set _not_implemented
+#define _vg_uuid_set _not_implemented_set
GET_VG_STR_PROPERTY_FN(vg_name, vg_name_dup(vg))
-#define _vg_name_set _not_implemented
+#define _vg_name_set _not_implemented_set
GET_VG_STR_PROPERTY_FN(vg_attr, vg_attr_dup(vg->vgmem, vg))
-#define _vg_attr_set _not_implemented
+#define _vg_attr_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_size, (SECTOR_SIZE * vg_size(vg)))
-#define _vg_size_set _not_implemented
+#define _vg_size_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_free, (SECTOR_SIZE * vg_free(vg)))
-#define _vg_free_set _not_implemented
+#define _vg_free_set _not_implemented_set
GET_VG_STR_PROPERTY_FN(vg_sysid, vg_system_id_dup(vg))
-#define _vg_sysid_set _not_implemented
+#define _vg_sysid_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_extent_size, vg->extent_size)
-#define _vg_extent_size_set _not_implemented
+#define _vg_extent_size_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_extent_count, vg->extent_count)
-#define _vg_extent_count_set _not_implemented
+#define _vg_extent_count_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_free_count, vg->free_count)
-#define _vg_free_count_set _not_implemented
+#define _vg_free_count_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(max_lv, vg->max_lv)
-#define _max_lv_set _not_implemented
+#define _max_lv_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(max_pv, vg->max_pv)
-#define _max_pv_set _not_implemented
+#define _max_pv_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(pv_count, vg->pv_count)
-#define _pv_count_set _not_implemented
+#define _pv_count_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(lv_count, (vg_visible_lvs(vg)))
-#define _lv_count_set _not_implemented
+#define _lv_count_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(snap_count, (snapshot_count(vg)))
-#define _snap_count_set _not_implemented
+#define _snap_count_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_seqno, vg->seqno)
-#define _vg_seqno_set _not_implemented
+#define _vg_seqno_set _not_implemented_set
GET_VG_STR_PROPERTY_FN(vg_tags, vg_tags_dup(vg))
-#define _vg_tags_set _not_implemented
+#define _vg_tags_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_mda_count, (vg_mda_count(vg)))
-#define _vg_mda_count_set _not_implemented
+#define _vg_mda_count_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_mda_used_count, (vg_mda_used_count(vg)))
-#define _vg_mda_used_count_set _not_implemented
+#define _vg_mda_used_count_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_mda_free, (SECTOR_SIZE * vg_mda_free(vg)))
-#define _vg_mda_free_set _not_implemented
+#define _vg_mda_free_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg)))
-#define _vg_mda_size_set _not_implemented
+#define _vg_mda_size_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg)))
-#define _vg_mda_copies_set _not_implemented
+#define _vg_mda_copies_set _not_implemented_set
/* LVSEG */
-#define _segtype_get _not_implemented
-#define _segtype_set _not_implemented
-#define _stripes_get _not_implemented
-#define _stripes_set _not_implemented
-#define _stripesize_get _not_implemented
-#define _stripesize_set _not_implemented
-#define _stripe_size_get _not_implemented
-#define _stripe_size_set _not_implemented
-#define _regionsize_get _not_implemented
-#define _regionsize_set _not_implemented
-#define _region_size_get _not_implemented
-#define _region_size_set _not_implemented
-#define _chunksize_get _not_implemented
-#define _chunksize_set _not_implemented
-#define _chunk_size_get _not_implemented
-#define _chunk_size_set _not_implemented
-#define _seg_start_get _not_implemented
-#define _seg_start_set _not_implemented
-#define _seg_start_pe_get _not_implemented
-#define _seg_start_pe_set _not_implemented
-#define _seg_size_get _not_implemented
-#define _seg_size_set _not_implemented
-#define _seg_tags_get _not_implemented
-#define _seg_tags_set _not_implemented
-#define _seg_pe_ranges_get _not_implemented
-#define _seg_pe_ranges_set _not_implemented
-#define _devices_get _not_implemented
-#define _devices_set _not_implemented
+#define _segtype_get _not_implemented_get
+#define _segtype_set _not_implemented_set
+#define _stripes_get _not_implemented_get
+#define _stripes_set _not_implemented_set
+#define _stripesize_get _not_implemented_get
+#define _stripesize_set _not_implemented_set
+#define _stripe_size_get _not_implemented_get
+#define _stripe_size_set _not_implemented_set
+#define _regionsize_get _not_implemented_get
+#define _regionsize_set _not_implemented_set
+#define _region_size_get _not_implemented_get
+#define _region_size_set _not_implemented_set
+#define _chunksize_get _not_implemented_get
+#define _chunksize_set _not_implemented_set
+#define _chunk_size_get _not_implemented_get
+#define _chunk_size_set _not_implemented_set
+#define _seg_start_get _not_implemented_get
+#define _seg_start_set _not_implemented_set
+#define _seg_start_pe_get _not_implemented_get
+#define _seg_start_pe_set _not_implemented_set
+#define _seg_size_get _not_implemented_get
+#define _seg_size_set _not_implemented_set
+#define _seg_tags_get _not_implemented_get
+#define _seg_tags_set _not_implemented_set
+#define _seg_pe_ranges_get _not_implemented_get
+#define _seg_pe_ranges_set _not_implemented_set
+#define _devices_get _not_implemented_get
+#define _devices_set _not_implemented_set
/* PVSEG */
-#define _pvseg_start_get _not_implemented
-#define _pvseg_start_set _not_implemented
-#define _pvseg_size_get _not_implemented
-#define _pvseg_size_set _not_implemented
+#define _pvseg_start_get _not_implemented_get
+#define _pvseg_start_set _not_implemented_set
+#define _pvseg_size_get _not_implemented_get
+#define _pvseg_size_set _not_implemented_set
#define STR DM_REPORT_FIELD_TYPE_STRING
#define NUM DM_REPORT_FIELD_TYPE_NUMBER
#define FIELD(type, strct, sorttype, head, field, width, fn, id, desc, writeable) \
- { #id, writeable, sorttype == STR, { .n_val = 0 }, _ ## id ## _get, _ ## id ## _set },
+ { type, #id, writeable, sorttype == STR, { .n_val = 0 }, _ ## id ## _get, _ ## id ## _set },
struct lvm_property_type _properties[] = {
#include "columns.h"
- { "", 0, 0, { .n_val = 0 }, _not_implemented, _not_implemented },
+ { 0, "", 0, 0, { .n_val = 0 }, _not_implemented_get, _not_implemented_set },
};
#undef STR
@@ -233,7 +239,8 @@ struct lvm_property_type _properties[] = {
#undef FIELD
-int vg_get_property(struct volume_group *vg, struct lvm_property_type *prop)
+static int _get_property(const void *obj, struct lvm_property_type *prop,
+ report_type_t type)
{
struct lvm_property_type *p;
@@ -247,10 +254,27 @@ int vg_get_property(struct volume_group *vg, struct lvm_property_type *prop)
log_errno(EINVAL, "Invalid property name %s", prop->id);
return 0;
}
+ if (!(p->type & type)) {
+ log_errno(EINVAL, "Property name %s does not match type %d",
+ prop->id, p->type);
+ return 0;
+ }
*prop = *p;
- if (!p->get((void *)vg, prop)) {
+ if (!p->get(obj, prop)) {
return 0;
}
return 1;
}
+
+int vg_get_property(const struct volume_group *vg,
+ struct lvm_property_type *prop)
+{
+ return _get_property(vg, prop, VGS);
+}
+
+int pv_get_property(const struct physical_volume *pv,
+ struct lvm_property_type *prop)
+{
+ return _get_property(pv, prop, PVS | LABEL);
+}
diff --git a/lib/report/properties.h b/lib/report/properties.h
index 2e1381d..7398f2f 100644
--- a/lib/report/properties.h
+++ b/lib/report/properties.h
@@ -17,10 +17,12 @@
#include "libdevmapper.h"
#include "lvm-types.h"
#include "metadata.h"
+#include "report.h"
#define LVM_PROPERTY_NAME_LEN DM_REPORT_FIELD_TYPE_ID_LEN
struct lvm_property_type {
+ report_type_t type;
char id[LVM_PROPERTY_NAME_LEN];
unsigned is_writeable;
unsigned is_string;
@@ -28,10 +30,13 @@ struct lvm_property_type {
char *s_val;
uint64_t n_val;
} v;
- int (*get) (void *obj, struct lvm_property_type *prop);
+ int (*get) (const void *obj, struct lvm_property_type *prop);
int (*set) (void *obj, struct lvm_property_type *prop);
};
-int vg_get_property(struct volume_group *vg, struct lvm_property_type *prop);
+int vg_get_property(const struct volume_group *vg,
+ struct lvm_property_type *prop);
+int pv_get_property(const struct physical_volume *pv,
+ struct lvm_property_type *prop);
#endif
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 19/20] Add lvm_pv_get_property() generic function to obtain value of any pv property.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (17 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 18/20] Add pv_get_property and create generic internal _get_property function Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
2010-09-22 21:06 ` [PATCH 20/20] Add pv_get_property to interactive test Dave Wysochanski
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
liblvm/lvm2app.h | 26 ++++++++++++++++++++++++++
liblvm/lvm_pv.c | 18 ++++++++++++++++++
2 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index cc839a6..634394a 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -1222,6 +1222,32 @@ uint64_t lvm_pv_get_size(const pv_t pv);
uint64_t lvm_pv_get_free(const pv_t pv);
/**
+ * Get the value of a PV property
+ *
+ * \memberof pv_t
+ *
+ * The memory allocated for a string property value is tied to the vg_t
+ * handle and will be released when lvm_vg_close() is called.
+ *
+ * Example:
+ * lvm_property_value value;
+ *
+ * if (lvm_pv_get_property(pv, "pv_mda_count", &value) < 0) {
+ * // handle error
+ * }
+ * if (value.is_string)
+ * printf(", value = %s\n", value.u.s_val);
+ * else
+ * printf(", value = %"PRIu64"\n", value.u.n_val);
+ *
+ *
+ * \return
+ * 0 (success) or -1 (failure).
+ */
+int lvm_pv_get_property(pv_t pv, const char *name,
+ struct lvm_property_value *value);
+
+/**
* Resize physical volume to new_size bytes.
*
* \memberof pv_t
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index 0b6b6b1..af70710 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -16,6 +16,7 @@
#include "lvm2app.h"
#include "metadata.h"
#include "lvm-string.h"
+#include "properties.h"
const char *lvm_pv_get_uuid(const pv_t pv)
{
@@ -48,6 +49,23 @@ uint64_t lvm_pv_get_free(const pv_t pv)
return (uint64_t) SECTOR_SIZE * pv_free(pv);
}
+int lvm_pv_get_property(pv_t pv, const char *name,
+ struct lvm_property_value *value)
+{
+ struct lvm_property_type prop;
+
+ strncpy(prop.id, name, LVM_PROPERTY_NAME_LEN);
+ if (!pv_get_property(pv, &prop))
+ return -1;
+ value->is_writeable = prop.is_writeable;
+ value->is_string = prop.is_string;
+ if (value->is_string)
+ value->v.s_val = prop.v.s_val;
+ else
+ value->v.n_val = prop.v.n_val;
+ return 0;
+}
+
int lvm_pv_resize(const pv_t pv, uint64_t new_size)
{
/* FIXME: add pv resize code here */
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 20/20] Add pv_get_property to interactive test.
2010-09-22 21:06 [PATCH 00/20] Add lvm vg and pv properties for lvm2app Dave Wysochanski
` (18 preceding siblings ...)
2010-09-22 21:06 ` [PATCH 19/20] Add lvm_pv_get_property() generic function to obtain value of any pv property Dave Wysochanski
@ 2010-09-22 21:06 ` Dave Wysochanski
19 siblings, 0 replies; 23+ messages in thread
From: Dave Wysochanski @ 2010-09-22 21:06 UTC (permalink / raw)
To: lvm-devel
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
test/api/test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 51 insertions(+), 1 deletions(-)
diff --git a/test/api/test.c b/test/api/test.c
index 4560655..2579ff0 100644
--- a/test/api/test.c
+++ b/test/api/test.c
@@ -93,6 +93,8 @@ static void _show_help(void)
"List the tags of a VG\n");
printf("'vg_get_property vgname property_name': "
"Display the value of VG property\n");
+ printf("'pv_get_property pvname property_name': "
+ "Display the value of PV property\n");
printf("'lv_get_tags vgname lvname': "
"List the tags of a LV\n");
printf("'vg_{add|remove}_tag vgname tag': "
@@ -182,6 +184,23 @@ static vg_t _lookup_vg_by_name(char **argv, int argc)
}
return vg;
}
+
+static pv_t _lookup_pv_by_name(char **argv, int argc)
+{
+ pv_t pv;
+
+ if (argc < 2) {
+ printf ("Please enter vg_name\n");
+ return NULL;
+ }
+ if (!(pv = dm_hash_lookup(_pvname_hash, argv[1]))) {
+ printf ("Can't find %s in open PVs - run vg_open first\n",
+ argv[1]);
+ return NULL;
+ }
+ return pv;
+}
+
static void _add_lvs_to_lvname_hash(struct dm_list *lvs)
{
struct lvm_lv_list *lvl;
@@ -548,6 +567,35 @@ static void _vg_tag(char **argv, int argc, int add)
add ? "adding":"removing", argv[2], argv[1]);
}
+static void _pv_get_property(char **argv, int argc)
+{
+ pv_t pv;
+ struct lvm_property_value value;
+ int rc;
+
+ if (argc < 3) {
+ printf("Please enter vgname, field_id\n");
+ return;
+ }
+ if (!(pv = _lookup_pv_by_name(argv, argc)))
+ return;
+ rc = lvm_pv_get_property(pv, argv[2], &value);
+ if (rc)
+ printf("Error ");
+ else
+ printf("Success ");
+ printf("obtaining value of property %s in VG %s",
+ argv[2], argv[1]);
+ if (rc) {
+ printf("\n");
+ return;
+ }
+ if (value.is_string)
+ printf(", value = %s\n", value.v.s_val);
+ else
+ printf(", value = %"PRIu64"\n", value.v.n_val);
+}
+
static void _vg_get_property(char **argv, int argc)
{
vg_t vg;
@@ -565,7 +613,7 @@ static void _vg_get_property(char **argv, int argc)
printf("Error ");
else
printf("Success ");
- printf("Obtaining value of property %s in VG %s",
+ printf("obtaining value of property %s in VG %s",
argv[2], argv[1]);
if (rc) {
printf("\n");
@@ -829,6 +877,8 @@ static int lvmapi_test_shell(lvm_t libh)
_vg_get_tags(argv, argc);
} else if (!strcmp(argv[0], "vg_get_property")) {
_vg_get_property(argv, argc);
+ } else if (!strcmp(argv[0], "pv_get_property")) {
+ _pv_get_property(argv, argc);
} else if (!strcmp(argv[0], "lv_add_tag")) {
_lv_tag(argv, argc, 1);
} else if (!strcmp(argv[0], "lv_remove_tag")) {
--
1.7.2.2
^ permalink raw reply related [flat|nested] 23+ messages in thread