Add lvm vg and pv properties for lvm2app.
cover Add lvm vg and pv properties for lvm2app.
This patchset is a repost and add onto the previous patchset posted to lvm-devel on 9/15/2010. It continues that patchset and adds pv properties and addresses comments made on the vg patchset.
Notable changes:
1. Refactor parts of metadata.[ch] into {pv|vg|lv}.ch.
2. Added 'const' to 'get' object functions
3. Improve type safety on vg_get_property() and pv_get_property()
4. Add "_dup" suffix to helper functions that allocate/dup strings.
All vg and pv properties may now be queried with this patchset. The refactoring of metadata.[ch] into specific files was only done for functions related to report field calculations. In the future, further functionality may be moved to these specific files, and common functions will remain inside metadata.[ch].
PATCH 1/20 Refactor metadata.[ch] into vg.[ch] for vg functions.
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.
--- 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
include/.symlinks.in +1 -0
@@ -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
lib/Makefile.in +1 -0
@@ -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 \
lib/metadata/metadata-exported.h +2 -97
141 lines not on this page · raw message
lib/metadata/metadata.c +0 -418
448 lines not on this page · raw message
lib/metadata/metadata.h +0 -7
@@ -378,11 +378,6 @@ int remove_seg_from_segs_using_this_lv(struct logical_volume *lv, struct lv_segmstruct 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
lib/metadata/vg.c new file +436 -0
436 lines not on this page · raw message
lib/metadata/vg.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
1.7.2.2
PATCH 2/20 Refactor metadata.[ch] into pv.[ch] for pv functions.
In reply to Dave WysochanskiThe 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.
--- 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
include/.symlinks.in +1 -0
@@ -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
lib/Makefile.in +1 -0
@@ -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 \
lib/metadata/metadata-exported.h +1 -51
82 lines not on this page · raw message
lib/metadata/metadata.c +0 -206
230 lines not on this page · raw message
lib/metadata/pv.c new file +223 -0
223 lines not on this page · raw message
lib/metadata/pv.h new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
1.7.2.2
PATCH 3/20 Refactor metadata.[ch] into lv.[ch] for lv functions.
In reply to Dave WysochanskiThis 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.
--- 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
include/.symlinks.in +1 -0
@@ -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
lib/Makefile.in +1 -0
@@ -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 \
lib/metadata/lv.c new file +21 -0
@@ -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; +}
lib/metadata/lv.h new file +52 -0
52 lines not on this page · raw message
lib/metadata/metadata-exported.h +1 -28
@@ -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)
lib/metadata/metadata.c +0 -5
@@ -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
Signature · 1 line
1.7.2.2
PATCH 4/20 Add {pv|vg|lv}_attr_dup() functions and refactor 'disp' functions.
In reply to Dave WysochanskiMove 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().
--- 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(-)
lib/metadata/lv.c +118 -0
@@ -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; +}
lib/metadata/lv.h +1 -0
@@ -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
lib/metadata/metadata.c +16 -0
@@ -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
lib/metadata/metadata.h +1 -0
@@ -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
lib/metadata/pv.c +21 -0
@@ -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;
lib/metadata/pv.h +1 -0
@@ -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);
lib/metadata/vg.c +37 -0
@@ -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; +}
lib/metadata/vg.h +1 -0
@@ -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
lib/report/columns.h +1 -1
@@ -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 )
lib/report/report.c +5 -169
211 lines not on this page · raw message
Signature · 1 line
1.7.2.2
PATCH 5/20 Simplify logic to create 'attr' strings.
In reply to Dave WysochanskiThis 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.
--- lib/metadata/lv.c | 30 ++++++------------------------ lib/metadata/pv.c | 11 ++--------- lib/metadata/vg.c | 30 +++++------------------------- 3 files changed, 13 insertions(+), 58 deletions(-)
lib/metadata/lv.c +6 -24
@@ -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 ] ='-' ;
lib/metadata/pv.c +2 -9
@@ -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; }
lib/metadata/vg.c +5 -25
@@ -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; }
Signature · 1 line
1.7.2.2
PATCH 6/20 Add id_format_and_copy() common function and call from _uuid_disp.
In reply to Dave WysochanskiAdd supporting uuid function to allocate memory and call id_write_format. Call id_format_and_copy from _uuid_disp.
--- lib/report/report.c | 7 +------ lib/uuid/uuid.c | 15 +++++++++++++++ lib/uuid/uuid.h | 2 ++ 3 files changed, 18 insertions(+), 6 deletions(-)
lib/report/report.c +1 -6
@@ -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 );
lib/uuid/uuid.c +15 -0
@@ -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; +}
lib/uuid/uuid.h +2 -0
@@ -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
Signature · 1 line
1.7.2.2
PATCH 7/20 Add pv_uuid_dup, vg_uuid_dup, and lv_uuid_dup, and call id_format_and_copy.
In reply to Dave WysochanskiAdd 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.
--- 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(-)
lib/metadata/lv.c +5 -0
@@ -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;
lib/metadata/lv.h +1 -0
@@ -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
lib/metadata/pv.c +5 -0
@@ -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);
lib/metadata/pv.h +1 -0
@@ -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);
lib/metadata/vg.c +5 -0
@@ -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;
lib/metadata/vg.h +1 -0
@@ -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
liblvm/lvm_lv.c +2 -8
@@ -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)
liblvm/lvm_pv.c +2 -8
@@ -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)
liblvm/lvm_vg.c +1 -7
@@ -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)
Signature · 1 line
1.7.2.2
PATCH 8/20 Add tags_format_and_copy() common function and call from _tags_disp.
In reply to Dave WysochanskiAdd a common function to allocate memory and format a string of tags.
Call tags_format_and_copy() from _tags_disp().
--- lib/metadata/metadata.c | 24 ++++++++++++++++++++++++ lib/metadata/metadata.h | 1 + lib/report/report.c | 21 +++------------------ 3 files changed, 28 insertions(+), 18 deletions(-)
lib/metadata/metadata.c +24 -0
@@ -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
lib/metadata/metadata.h +1 -0
@@ -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
lib/report/report.c +3 -18
@@ -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 ; }
Signature · 1 line
1.7.2.2
PATCH 9/20 Add pv_tags_dup, vg_tags_dup, lv_tags_dup functions that call tags_format_and_copy.
In reply to Dave Wysochanski--- 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(-)
lib/metadata/lv.c +5 -0
@@ -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;
lib/metadata/lv.h +1 -0
@@ -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
lib/metadata/pv.c +5 -0
@@ -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);
lib/metadata/pv.h +1 -0
@@ -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);
lib/metadata/vg.c +5 -0
@@ -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;
lib/metadata/vg.h +1 -0
@@ -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
Signature · 1 line
1.7.2.2
PATCH 10/20 Add supporting functions vg_name_dup, vg_fmt_dup, vg_system_id_dup.
In reply to Dave WysochanskiAdd 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.
--- lib/metadata/vg.c | 17 +++++++++++++++++ lib/metadata/vg.h | 3 +++ 2 files changed, 20 insertions(+), 0 deletions(-)
lib/metadata/vg.c +17 -0
@@ -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);
lib/metadata/vg.h +3 -0
@@ -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);
Signature · 1 line
1.7.2.2
PATCH 11/20 Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv.
In reply to Dave WysochanskiWill 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.
--- lib/report/properties.c | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-)
lib/report/properties.c +23 -2
@@ -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) {
Signature · 1 line
1.7.2.2
PATCH 11/20 Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv.
Dne 22.9.2010 23:06, Dave Wysochanski napsal(a):
Quoted 13 lines
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 <[email protected]>--- lib/report/properties.c | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-)lib/report/properties.c +0
-0
lib/report/properties.c line 26
Quoted 9 lines
lib/report/properties.c +2
-2@@ -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
PATCH 11/20 Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv.
Quoted 28 lines · Zdenek Kabelac
Dne 22.9.2010 23:06, Dave Wysochanski napsal(a):
Quoted 13 lines
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 <[email protected]>--- lib/report/properties.c | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-)lib/report/properties.c +0
-0lib/report/properties.c line 26
Quoted 9 lines
lib/report/properties.c +2
-2@@ -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
Quoted 2 lines
looks weird... isn't there something better?
"struct TYPE *VAR" ?
PATCH 12/20 Add 'get' functions for vg fields.
In reply to Dave WysochanskiAdd '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.
--- lib/report/properties.c | 44 ++++++++++++++++++++++---------------------- 1 files changed, 22 insertions(+), 22 deletions(-)
lib/report/properties.c +22 -22
@@ -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 */
Signature · 1 line
1.7.2.2
PATCH 13/20 Add lvm_vg_get_property() generic vg property function.
In reply to Dave WysochanskiAdd a generic VG property function to lvm2app. Call the internal library vg_get_property() function. Strings are dup'd internally.
--- liblvm/lvm2app.h | 42 ++++++++++++++++++++++++++++++++++++++++++ liblvm/lvm_vg.c | 19 +++++++++++++++++++ 2 files changed, 61 insertions(+), 0 deletions(-)
liblvm/lvm2app.h +42 -0
@@ -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 *************************/ /**
liblvm/lvm_vg.c +19 -0
@@ -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 );
Signature · 1 line
1.7.2.2
PATCH 14/20 Add tests for lvm_vg_get_property().
In reply to Dave Wysochanski--- test/api/test.c | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
test/api/test.c +33 -0
@@ -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" )) {
Signature · 1 line
1.7.2.2
PATCH 15/20 Add pv_mda_size, pv_mda_free, and pv_used functions, call from 'disp' functions.
In reply to Dave Wysochanski--- lib/metadata/pv.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/metadata/pv.h | 3 +++ lib/report/report.c | 34 +++++++++------------------------- 3 files changed, 56 insertions(+), 25 deletions(-)
lib/metadata/pv.c +44 -0
@@ -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;
lib/metadata/pv.h +3 -0
@@ -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);
lib/report/report.c +9 -25
@@ -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); }
Signature · 1 line
1.7.2.2
PATCH 16/20 Add pv_name_dup() and pv_fmt_dup() helper functions.
In reply to Dave Wysochanski--- lib/metadata/pv.c | 12 ++++++++++++ lib/metadata/pv.h | 2 ++ 2 files changed, 14 insertions(+), 0 deletions(-)
lib/metadata/pv.c +12 -0
@@ -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 */
lib/metadata/pv.h +2 -0
@@ -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);
Signature · 1 line
1.7.2.2
PATCH 17/20 Add pv 'get' functions for all pv properties.
In reply to Dave WysochanskiAdd '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.
--- lib/report/properties.c | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-)
lib/report/properties.c +16 -16
@@ -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 */
Signature · 1 line
1.7.2.2
PATCH 18/20 Add pv_get_property and create generic internal _get_property function.
In reply to Dave WysochanskiWe 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.
--- lib/report/properties.c | 266 +++++++++++++++++++++++++--------------------- lib/report/properties.h | 9 ++- 2 files changed, 152 insertions(+), 123 deletions(-)
lib/report/properties.c +145 -121
@@ -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 ); +}
lib/report/properties.h +7 -2
@@ -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_LENstruct 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
Signature · 1 line
1.7.2.2
PATCH 19/20 Add lvm_pv_get_property() generic function to obtain value of any pv property.
In reply to Dave Wysochanski--- liblvm/lvm2app.h | 26 ++++++++++++++++++++++++++ liblvm/lvm_pv.c | 18 ++++++++++++++++++ 2 files changed, 44 insertions(+), 0 deletions(-)
liblvm/lvm2app.h +26 -0
@@ -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
liblvm/lvm_pv.c +18 -0
@@ -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 */
Signature · 1 line
1.7.2.2
PATCH 20/20 Add pv_get_property to interactive test.
In reply to Dave Wysochanski--- test/api/test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 51 insertions(+), 1 deletions(-)
test/api/test.c +51 -1
@@ -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" )) {
Signature · 1 line
1.7.2.2