Add generic VG 'set' property function for lvm2app.
cover Add generic VG 'set' property function for lvm2app.
This small patchset implements a 'set' property function for lvm2app. The 'set' function is only defined for certain 'settable' properties. Initially, we only define it for vg_mda_copies, but future patches can define a 'set' function for any property in one of the {pv|vg|lv}change lvm functions. In this way, we do not need separate lvm2app functions for pvchange, lvchange, and vgchange, but can just allow the application to 'get' and then 'set' the property.
Just cleaning out my remaining in-progress patches. Petr feel free to take or leave as you wish.
PATCH 1/3 Add generic 'set' property function to internal library.
Add generic infrastructure to internal library to 'set' a property. Similar to 'get' property internal functions.
Add specific 'set' function for vg_mda_copies.
--- lib/report/columns.h | 2 +- lib/report/properties.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++- lib/report/properties.h | 6 ++++ 3 files changed, 77 insertions(+), 2 deletions(-)
lib/report/columns.h +1 -1
@@ -121,7 +121,7 @@ FIELD(VGS, vg, NUM, "#VMda", cmd, 5, vgmdas, vg_mda_count, "Number of metadata a FIELD(VGS, vg, NUM, "#VMdaUse", cmd, 8, vgmdasused, vg_mda_used_count, "Number of metadata areas in use on this VG.", 0) FIELD(VGS, vg, NUM, "VMdaFree", cmd, 9, vgmdafree, vg_mda_free, "Free metadata area space for this VG in current units.", 0) FIELD(VGS, vg, NUM, "VMdaSize", cmd, 9, vgmdasize, vg_mda_size, "Size of smallest metadata area for this VG in current units.", 0) -FIELD(VGS, vg, NUM, "#VMdaCps", cmd, 8, vgmdacopies, vg_mda_copies, "Target number of in use metadata areas in the VG.", 0) +FIELD(VGS, vg, NUM, "#VMdaCps", cmd, 8, vgmdacopies, vg_mda_copies, "Target number of in use metadata areas in the VG.", 1) FIELD(SEGS, seg, STR, "Type", list, 4, segtype, segtype, "Type of LV segment.", 0)FIELD (SEGS , seg,NUM ,"#Str" , area_count,4 , uint32, stripes,"Number of stripes or mirror legs." ,0 )
lib/report/properties.c +70 -1
92 lines not on this page · raw message
lib/report/properties.h +6 -0
@@ -39,5 +39,11 @@ 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); +int lv_set_property (struct logical_volume *lv, +struct lvm_property_type *prop); +int vg_set_property (struct volume_group *vg, +struct lvm_property_type *prop); +int pv_set_property (struct physical_volume *pv, +struct lvm_property_type *prop);#endif
Signature · 1 line
1.7.2.2
PATCH 2/3 Add lvm_vg_set_property() function.
In reply to Dave WysochanskiImplement lvm_vg_set_property() by calling internal 'set' property function.
--- liblvm/lvm2app.h | 30 ++++++++++++++++++++++++++++++ liblvm/lvm_misc.c | 30 ++++++++++++++++++++++++++++++ liblvm/lvm_misc.h | 2 ++ liblvm/lvm_vg.c | 6 ++++++ 4 files changed, 68 insertions(+), 0 deletions(-)
liblvm/lvm2app.h +30 -0
@@ -911,6 +911,36 @@ struct dm_list *lvm_vg_get_tags(const vg_t vg);*/ struct lvm_property_value lvm_vg_get_property (const vg_t vg,const char *name); +/** +* Set the value of a VG property. Note that the property must be +* a 'settable' property, as evidenced by the 'is_settable' flag +* when querying the 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 (integer): +* lvm_property_value copies; +* +* if (lvm_vg_get_property(vg, "vg_mda_copies", &copies) < 0) { +* // Error - unable to query property +* } +* if (!copies.is_settable) { +* // Error - property not settable +* } +* copies.value.integer = 2; +* if (lvm_vg_set_property(vg, "vg_mda_copies", &copies) < 0) { +* // handle error +* } +* +* \return +* 0 (success) or -1 (failure). +*/ +int lvm_vg_set_property (const vg_t vg,const char *name, +struct lvm_property_value *value); +/************************** logical volume handling *************************/ /**
liblvm/lvm_misc.c +30 -0
@@ -78,3 +78,33 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg, v.is_valid =1 ;return v; } + + +int set_property (const pv_t pv,const vg_t vg,const lv_t lv, +const char *name,struct lvm_property_value *v) +{ +struct lvm_property_type prop; + + prop.id = name; +if (v->is_string) + prop.value.string = v->value.string; +else + prop.value.integer = v->value.integer; +if (pv) { +if (!pv_set_property (pv, &prop)) { + v->is_valid =0 ; +return -1 ; + } + }else if (vg) { +if (!vg_set_property (vg, &prop)) { + v->is_valid =0 ; +return -1 ; + } + }else if (lv) { +if (!lv_set_property (lv, &prop)) { + v->is_valid =0 ; +return -1 ; + } + } +return 0 ; +}
liblvm/lvm_misc.h +2 -0
@@ -19,5 +19,7 @@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); +int set_property (const pv_t pv,const vg_t vg,const lv_t lv, +const char *name,struct lvm_property_value *value);#endif
liblvm/lvm_vg.c +6 -0
@@ -341,6 +341,12 @@ struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name)return get_property (NULL , vg,NULL , name); } +int lvm_vg_set_property (const vg_t vg,const char *name, +struct lvm_property_value *value) +{ +return set_property (NULL , vg,NULL , name, value); +} +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/3 Add tests for vg 'set' property function.
In reply to Dave Wysochanski--- test/api/test.c | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
test/api/test.c +34 -0
@@ -97,6 +97,8 @@ static void _show_help(void) "Display the value of VG property\n");printf ("'pv_get_property pvname property_name': " "Display the value of PV property\n" ); +printf ("'vg_set_property vgname property_name': " +"Set 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': "
@@ -652,6 +654,36 @@ static void _lv_get_property(char **argv, int argc)_print_property_value (v); } +static void _vg_set_property (char **argv,int argc) +{ +vg_t vg; +struct lvm_property_value value; +int rc; + +if (argc <4 ) { +printf ("Please enter vgname, field_id, value\n" ); +return ; + } +if (!(vg =_lookup_vg_by_name (argv, argc))) +return ; + value =lvm_vg_get_property (vg, argv[2 ]); +if (!value.is_valid) { +printf ("Error obtaining property value\n" ); +return ; + } +if (value.is_string) + value.value.string = argv[3 ]; +else + value.value.integer =atoi (argv[3 ]); + rc =lvm_vg_set_property (vg, argv[2 ], &value); +if (rc) +printf ("Error " ); +else +printf ("Success " ); +printf ("setting value of property %s in VG %s\n" , + argv[2 ], argv[1 ]); +} +static void _lv_get_tags (char **argv,int argc) {lv_t lv;
@@ -908,6 +940,8 @@ static int lvmapi_test_shell(lvm_t libh)_vg_get_property (argv, argc); }else if (!strcmp (argv[0 ],"pv_get_property" )) {_pv_get_property (argv, argc); + }else if (!strcmp (argv[0 ],"vg_set_property" )) { +_vg_set_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