Add generic property fns for lvm2app, return struct, v2.
cover Add generic property fns for lvm2app, return struct, v2.
This is the modified patchset based on Petr's suggestion of changing the return value from 'int' to struct lvm_property_value:
http://www.redhat.com/archives/lvm-devel/2010-October/msg00068.html
Returning the struct seems like the approach things are moving, but a few details probably still worth considering, especially the exact layout of the exported struct lvm_property_value (ABI implications). Final submission might be best left to Petr.
Patchset adds the lvm2app 'get' functions for vg, pv, and lv, and interactive tests to exercise the interface.
Changes since last patchset:
1. Added 'is_integer' bit/flag, similar to 'is_string'
2. Updated comments describing new APIs in lvm2app.h
3. Simplified the common code in lvm2app into a local 'get_property' function which allows for a single-line implementation of lvm_{pv|vg|lv}_get_property
The only two lv properties not included now are still the float/percent based properties, snap_percent and copy_percent. These should be refactored carefully and I did not want to delay these patches further.
All vg and pv properties and most lv properties may now be queried with this patchset.
PATCH 1/5 Add 'is_integer' flag into internal lvm_property_type.
Add 'is_integer' flag similar to 'is_string'.
Suggested in review by Petr Rockai.
--- lib/report/properties.c | 4 ++-- lib/report/properties.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
lib/report/properties.c +2 -2
@@ -227,11 +227,11 @@ GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg)))#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, settable) \ - { type, #id, settable, sorttype == STR, { .integer = 0 }, _ ## id ## _get, _ ## id ## _set }, + { type, #id, settable, sorttype == STR, sorttype == NUM, { .integer = 0 }, _ ## id ## _get, _ ## id ## _set },struct lvm_property_type _properties[] = { #include "columns.h" - {0 ,"" ,0 ,0 , { .integer =0 }, _not_implemented_get, _not_implemented_set }, + {0 ,"" ,0 ,0 ,0 , { .integer =0 }, _not_implemented_get, _not_implemented_set }, };#undef STR
lib/report/properties.h +1 -0
@@ -24,6 +24,7 @@ struct lvm_property_type {const char *id; unsigned is_settable:1; unsigned is_string:1; + unsigned is_integer:1;union {char *string;uint64_t integer;
Signature · 1 line
1.7.2.2
PATCH 2/5 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. Rework lvm_vg_get_property to return lvm_property_value and require caller to check 'is_valid' flag. If !is_valid, the caller can check lvm_errno() for the specific error.
Create a 'get_property' function, local to lvm2app, that factors out most of the common code that copies the components of lvm_property_type into lvm_property_value. This allows for a 1-line function for each of the generic property functions exported by lvm2app.
--- liblvm/lvm2app.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++- liblvm/lvm_misc.c | 35 +++++++++++++++++++++++++++++ liblvm/lvm_misc.h | 2 + liblvm/lvm_vg.c | 6 +++++ 4 files changed, 106 insertions(+), 1 deletions(-)
liblvm/lvm2app.h +63 -1
@@ -139,7 +139,7 @@ typedef struct physical_volume *pv_t;/** * Logical Volume object list. * -* Lists of these structures are returned by lvm_vg_list_pvs(). +* Lists of these structures are returned by lvm_vg_list_lvs(). */ typedef struct lvm_lv_list { struct dm_list list;
@@ -168,6 +168,29 @@ 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(). +* +* is_settable: indicates whether a 'set' function exists for this property +* is_string: indicates whether this property is a string (1) or not (0) +* is_integer: indicates whether this property is an integer (1) or not (0) +* is_valid: indicates whether 'value' is valid (1) or not (0) +*/ +typedef struct lvm_property_value { +unsigned is_settable:1 ; +unsigned is_string:1 ; +unsigned is_integer:1 ; +unsigned is_valid:1 ; +union { +const char *string; +uint64_t integer; + } value; +}lvm_property_value_t ; +/*************************** generic lvm handling ***************************/ /** * Create a LVM handle.
@@ -848,6 +871,45 @@ 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 +* +* \param vg +* VG handle obtained from lvm_vg_create() or lvm_vg_open(). +* +* \param name +* Name of property to query. See vgs man page for full list of properties +* that may be queried. +* +* 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 v; +* char *prop_name = "vg_mda_count"; +* +* v = lvm_vg_get_property(vg, prop_name); +* if (!v.is_valid) { +* printf("Invalid property name or unable to query" +* "'%s', errno = %d.\n", prop_name, lvm_errno(libh)); +* return; +* } +* if (v.is_string) +* printf(", value = %s\n", v.value.string); +* if (v.is_integer) +* printf(", value = %"PRIu64"\n", v.value.integer); +* +* +* \return +* lvm_property_value structure that will contain the current +* value of the property. Caller should check 'is_valid' flag before using +* the value. If 'is_valid' is not set, caller should check lvm_errno() +* for specific error. +*/ +struct lvm_property_value lvm_vg_get_property (const vg_t vg,const char *name); +/************************** logical volume handling *************************/ /**
liblvm/lvm_misc.c +35 -0
@@ -15,6 +15,7 @@#include "lvm2app.h" #include "lvm_misc.h" #include "lib.h" +#include "properties.h" struct dm_list *tag_list_copy (struct dm_pool *p,struct dm_list *tag_list) {
@@ -43,3 +44,37 @@ struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list) }return list; } + +struct lvm_property_value get_property (const pv_t pv,const vg_t vg, +const lv_t lv,const char *name) +{ +struct lvm_property_type prop; +struct lvm_property_value v; + + prop.id = name; +if (pv) { +if (!pv_get_property (pv, &prop)) { + v.is_valid =0 ; +return v; + } + }else if (vg) { +if (!vg_get_property (vg, &prop)) { + v.is_valid =0 ; +return v; + } + }else if (lv) { +if (!lv_get_property (lv, &prop)) { + v.is_valid =0 ; +return v; + } + } + v.is_settable = prop.is_settable; + v.is_string = prop.is_string; + v.is_integer = prop.is_integer; +if (v.is_string) + v.value.string = prop.value.string; +if (v.is_integer) + v.value.integer = prop.value.integer; + v.is_valid =1 ; +return v; +}
liblvm/lvm_misc.h +2 -0
@@ -17,5 +17,7 @@#include "libdevmapper.h" struct dm_list *tag_list_copy (struct dm_pool *p,struct dm_list *tag_list); +struct lvm_property_value get_property (const pv_t pv,const vg_t vg, +const lv_t lv,const char *name);#endif
liblvm/lvm_vg.c +6 -0
@@ -335,6 +335,12 @@ const char *lvm_vg_get_name(const vg_t vg)return dm_pool_strndup (vg->vgmem, (const char *)vg->name,NAME_LEN +1 ); } + +struct lvm_property_value lvm_vg_get_property (const vg_t vg,const char *name) +{ +return get_property (NULL , vg,NULL , name); +} +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 3/5 Add lvm_pv_get_property() generic function to obtain value of any pv property.
In reply to Dave WysochanskiAdd a generic PV property function to lvm2app, similar to VG function. Return lvm_property_value and require caller to check 'is_valid' flag before using the value. If 'is_valid' is not set, then lvm_errno() should be used to obtain the specific error.
--- liblvm/lvm2app.h | 38 ++++++++++++++++++++++++++++++++++++++ liblvm/lvm_pv.c | 6 ++++++ 2 files changed, 44 insertions(+), 0 deletions(-)
liblvm/lvm2app.h +38 -0
@@ -1242,6 +1242,44 @@ 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 +* +* \param pv +* Physical volume handle. +* +* \param name +* Name of property to query. See pvs man page for full list of properties +* that may be queried. +* +* 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; +* char *prop_name = "pv_mda_count"; +* +* v = lvm_pv_get_property(pv, prop_name); +* if (!v.is_valid) { +* printf("Invalid property name or unable to query" +* "'%s', errno = %d.\n", prop_name, lvm_errno(libh)); +* return; +* } +* if (v.is_string) +* printf(", value = %s\n", v.value.string); +* if (v.is_integer) +* printf(", value = %"PRIu64"\n", v.value.integer); +* +* \return +* lvm_property_value structure that will contain the current +* value of the property. Caller should check 'is_valid' flag before using +* the value. If 'is_valid' is not set, caller should check lvm_errno() +* for specific error. +*/ +struct lvm_property_value lvm_pv_get_property (const pv_t pv,const char *name); + +/** * Resize physical volume to new_size bytes. * * \memberof pv_t
liblvm/lvm_pv.c +6 -0
@@ -16,6 +16,7 @@#include "lvm2app.h" #include "metadata.h" #include "lvm-string.h" +#include "lvm_misc.h" const char *lvm_pv_get_uuid (const pv_t pv) {
@@ -48,6 +49,11 @@ uint64_t lvm_pv_get_free(const pv_t pv)return (uint64_t )SECTOR_SIZE *pv_free (pv); } +struct lvm_property_value lvm_pv_get_property (const pv_t pv,const char *name) +{ +return get_property (pv,NULL ,NULL , name); +} +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 4/5 Add lvm_lv_get_property() generic function to obtain value of any lv propert
In reply to Dave WysochanskiAdd a generic LV property function to lvm2app, similar to VG function. Return lvm_property_value and require caller to check 'is_valid' flag and lvm_errno() for API error.
--- liblvm/lvm2app.h | 38 ++++++++++++++++++++++++++++++++++++++ liblvm/lvm_lv.c | 5 +++++ 2 files changed, 43 insertions(+), 0 deletions(-)
liblvm/lvm2app.h +38 -0
@@ -1032,6 +1032,44 @@ const char *lvm_lv_get_name(const lv_t lv);uint64_t lvm_lv_get_size (const lv_t lv);/** +* Get the value of a LV property +* +* \memberof lv_t +* +* \param lv +* Logical volume handle. +* +* \param name +* Name of property to query. See lvs man page for full list of properties +* that may be queried. +* +* 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 v; +* char *prop_name = "seg_count"; +* +* v = lvm_lv_get_property(lv, prop_name); +* if (!v.is_valid) { +* printf("Invalid property name or unable to query" +* "'%s', errno = %d.\n", prop_name, lvm_errno(libh)); +* return; +* } +* if (v.is_string) +* printf(", value = %s\n", v.value.string); +* if (v.is_integer) +* printf(", value = %"PRIu64"\n", v.value.integer); +* +* \return +* lvm_property_value structure that will contain the current +* value of the property. Caller should check 'is_valid' flag before using +* the value. If 'is_valid' is not set, caller should check lvm_errno() +* for specific error. +*/ +struct lvm_property_value lvm_lv_get_property (const lv_t lv,const char *name); + +/** * Get the current activation state of a logical volume. * * \memberof lv_t
liblvm/lvm_lv.c +5 -0
@@ -48,6 +48,11 @@ const char *lvm_lv_get_name(const lv_t lv) NAME_LEN+1); } +struct lvm_property_value lvm_lv_get_property (const lv_t lv,const char *name) +{ +return get_property (NULL ,NULL , lv, name); +} +uint64_t lvm_lv_is_active (const lv_t lv) {struct lvinfo info;
Signature · 1 line
1.7.2.2
PATCH 5/5 Add interactive tests for lvm_{pv|vg|lv}_get_property().
In reply to Dave Wysochanski--- test/api/test.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 112 insertions(+), 0 deletions(-)
test/api/test.c +112 -0
@@ -91,6 +91,12 @@ 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 ("'lv_get_property vgname lvname property_name': " +"Display the value of LV property\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': "
@@ -180,6 +186,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;
@@ -546,6 +569,89 @@ static void _vg_tag(char **argv, int argc, int add) add ? "adding":"removing", argv[2], argv[1]); } +static void _print_property_value (struct lvm_property_value value) +{ +if (value.is_string) +printf (", value = %s\n" , value.value.string); +else +printf (", value = %" PRIu64"\n" , value.value.integer); +} + +static void _pv_get_property (char **argv,int argc) +{ +pv_t pv; +struct lvm_property_value v; + +if (argc <3 ) { +printf ("Please enter pvname, field_id\n" ); +return ; + } +if (!(pv =_lookup_pv_by_name (argv, argc))) +return ; + v =lvm_pv_get_property (pv, argv[2 ]); +if (!v.is_valid) +printf ("Error " ); +else +printf ("Success " ); +printf ("obtaining value of property %s in PV %s" , + argv[2 ], argv[1 ]); +if (!v.is_valid) { +printf ("\n" ); +return ; + } +_print_property_value (v); +} + +static void _vg_get_property (char **argv,int argc) +{ +vg_t vg; +struct lvm_property_value v; + +if (argc <3 ) { +printf ("Please enter vgname, field_id\n" ); +return ; + } +if (!(vg =_lookup_vg_by_name (argv, argc))) +return ; + v =lvm_vg_get_property (vg, argv[2 ]); +if (!v.is_valid) +printf ("Error " ); +else +printf ("Success " ); +printf ("obtaining value of property %s in VG %s" , + argv[2 ], argv[1 ]); +if (!v.is_valid) { +printf ("\n" ); +return ; + } +_print_property_value (v); +} + +static void _lv_get_property (char **argv,int argc) +{ +lv_t lv; +struct lvm_property_value v; + +if (argc <4 ) { +printf ("Please enter vgname, lvname, field_id\n" ); +return ; + } +if (!(lv =_lookup_lv_by_name (argv[2 ]))) +return ; + v =lvm_lv_get_property (lv, argv[3 ]); +if (!v.is_valid) +printf ("Error " ); +else +printf ("Success " ); +printf ("obtaining value of property %s in LV %s" , + argv[3 ], argv[2 ]); +if (!v.is_valid) { +printf ("\n" ); +return ; + } +_print_property_value (v); +} +static void _lv_get_tags (char **argv,int argc) {lv_t lv;
@@ -796,6 +902,12 @@ 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 ],"lv_get_property" )) { +_lv_get_property (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
cover Add generic property fns for lvm2app, return struct, v2.
In reply to Dave WysochanskiHi,
Quoted 8 lines · Dave Wysochanski
This is the modified patchset based on Petr's suggestion of changing the return value from 'int' to struct
lvm_property_value:
http://www.redhat.com/archives/lvm-devel/2010-October/msg00068.htmlReturning the struct seems like the approach things are moving, but a few details probably still worth considering, especially the exact layout of the exported struct
lvm_property_value(ABI implications). Final submission might be best left to Petr.
I think I almost prefer to have this in tree now and tweak the layouts etc. afterwards. I think that all that needs to be done is to pad the bit-field, the union is already 64b wide so we shouldn't need anything else. I'll have a closer look next week.
Quoted 6 lines
Patchset adds the lvm2app 'get' functions for vg, pv, and lv, and interactive tests to exercise the interface.
The only two lv properties not included now are still the float/percent based properties,
snap_percentandcopy_percent. These should be refactored carefully and I did not want to delay these patches further.
I will sort these out myself as well.
I went through the individual patches and I don't have any specific comments. So I think all five can go in now, and I'll look at finishing the two above items and will look into test coverage that we already have and maybe extend it. Therefore,
Yours,
Petr.
cover Add generic property fns for lvm2app, return struct, v2.
Quoted 22 lines · Petr Rockai
Hi,
Quoted 8 lines · Dave Wysochanski
This is the modified patchset based on Petr's suggestion of changing the return value from 'int' to struct
lvm_property_value:
http://www.redhat.com/archives/lvm-devel/2010-October/msg00068.htmlReturning the struct seems like the approach things are moving, but a few details probably still worth considering, especially the exact layout of the exported struct
lvm_property_value(ABI implications). Final submission might be best left to Petr.I think I almost prefer to have this in tree now and tweak the layouts etc. afterwards. I think that all that needs to be done is to pad the bit-field, the union is already 64b wide so we shouldn't need anything else. I'll have a closer look next week.
Quoted 6 lines
Patchset adds the lvm2app 'get' functions for vg, pv, and lv, and interactive tests to exercise the interface.
The only two lv properties not included now are still the float/percent based properties,
snap_percentandcopy_percent. These should be refactored carefully and I did not want to delay these patches further.
Quoted 7 lines
I will sort these out myself as well.
I went through the individual patches and I don't have any specific comments. So I think all five can go in now, and I'll look at finishing the two above items and will look into test coverage that we already have and maybe extend it. Therefore,
Very good. As you wish Petr - will check them in!
Quoted 2 lines
Reviewed-by Petr Rockai <[email protected]>