dev-dct-process-latest - toollib: rewrite process_each_pv
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7c88ae037e5e1e860cd58e873a90dc3e3cd0bbe1 Commit: 7c88ae037e5e1e860cd58e873a90dc3e3cd0bbe1 Parent: 84b51035909394ad52010a4f7aaa5f9da22b0faa Author: David Teigland <[email protected]> AuthorDate: Thu Aug 29 16:32:46 2013 -0500 Committer: David Teigland <[email protected]> CommitterDate: Mon Sep 22 10:32:23 2014 -0500
toollib: rewrite process_each_pv
Process pvs by iterating through vgs, then iterating through devs if the command wants to process non-pv devices. The process_single function can always use the vg and pv args.
--- lib/metadata/pv_manip.c | 22 -- lib/metadata/vg.c | 1 + lib/report/columns.h | 4 +- lib/report/report.c | 37 +++- tools/pvdisplay.c | 59 ++--- tools/pvresize.c | 2 +- tools/reporter.c | 83 ++----- tools/toollib.c | 614 ++++++++++++++++++++++++++++------------------- tools/toollib.h | 8 +- tools/vgdisplay.c | 2 +- tools/vgreduce.c | 2 +- 11 files changed, 460 insertions(+), 374 deletions(-)
lib/metadata/pv_manip.c +0 -22
@@ -615,31 +615,12 @@ int pv_resize_single(struct cmd_context *cmd,struct physical_volume *pv, const uint64_t new_size) { - struct pv_list *pvl; uint64_t size = 0;int r =0 ;const char *pv_name =pv_dev_name (pv);const char *vg_name = pv->vg_name; -struct volume_group *old_vg = vg;int vg_needs_pv_write =0 ; - vg =vg_read_for_update (cmd, vg_name,NULL ,0 ); - -if (vg_read_error (vg)) { -release_vg (vg); -log_error ("Unable to read volume group \"%s\"." , - vg_name); -return 0 ; - } - -if (!(pvl =find_pv_in_vg (vg, pv_name))) { -log_error ("Unable to find \"%s\" in volume group \"%s\"" , - pv_name, vg->name); - goto out; - } - - pv = pvl->pv; -if (!archive (vg)) goto out;
@@ -698,9 +679,6 @@ out:if (!r && vg_needs_pv_write)log_error ("Use pvcreate and vgcfgrestore " "to repair from archived metadata." ); -unlock_vg (cmd, vg_name); -if (!old_vg) -release_vg (vg);return r; }
lib/metadata/vg.c +1 -0
@@ -44,6 +44,7 @@ struct volume_group *alloc_vg(const char *pool_name, struct cmd_context *cmd, vg->cmd = cmd; vg->vgmem = vgmem; vg->alloc =ALLOC_NORMAL ; + vg->system_id = (char *)"" ;if (!(vg->hostnames =dm_hash_create (16 ))) {log_error ("Failed to allocate VG hostname hashtable." );
lib/report/columns.h +2 -2
@@ -120,7 +120,7 @@ FIELD(PVS, pv, SIZ, "BA size", ba_size, 7, size64, pv_ba_size, "Size of PV Bootl FIELD(VGS, vg, STR, "Fmt", cmd, 3, vgfmt, vg_fmt, "Type of metadata.", 0) FIELD(VGS, vg, STR, "VG UUID", id, 38, uuid, vg_uuid, "Unique identifier.", 0) -FIELD(VGS, vg, STR, "VG", name, 4, string, vg_name, "Name.", 0) +FIELD(VGS, vg, STR, "VG", cmd, 4, vgname, vg_name, "Name.", 0) FIELD(VGS, vg, STR, "Attr", cmd, 5, vgstatus, vg_attr, "Various attributes - see man page.", 0) FIELD(VGS, vg, STR, "VPerms", cmd, 10, vgpermissions, vg_permissions, "VG permissions.", 0)FIELD (VGS , vg,BIN ,"Extendable" , cmd,10 , vgextendable, vg_extendable,"Set if VG is extendable." ,0 )
@@ -130,7 +130,7 @@ FIELD(VGS, vg, STR, "AllocPol", cmd, 10, vgallocationpolicy, vg_allocation_polic FIELD(VGS, vg, BIN, "Clustered", cmd, 10, vgclustered, vg_clustered, "Set if VG is clustered.", 0) FIELD(VGS, vg, SIZ, "VSize", cmd, 5, vgsize, vg_size, "Total size of VG in current units.", 0) FIELD(VGS, vg, NUM, "VFree", cmd, 5, vgfree, vg_free, "Total amount of free space in current units.", 0) -FIELD(VGS, vg, STR, "SYS ID", system_id, 6, string, vg_sysid, "System ID indicating when and where it was created.", 0) +FIELD(VGS, vg, STR, "SYS ID", cmd, 6, vgsysid, vg_sysid, "System ID indicating when and where it was created.", 0) FIELD(VGS, vg, SIZ, "Ext", extent_size, 3, size32, vg_extent_size, "Size of Physical Extents in current units.", 0) FIELD(VGS, vg, NUM, "#Ext", extent_count, 4, uint32, vg_extent_count, "Total number of Physical Extents.", 0)FIELD (VGS , vg,NUM ,"Free" , free_count,4 , uint32, vg_free_count,"Total number of unallocated Physical Extents." ,0 )
lib/report/report.c +35 -2
@@ -386,6 +386,36 @@ static int _loglv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((return _field_set_value (field,"" ,NULL ); } +static int _vgname_disp (struct dm_report *rh,struct dm_pool *mem, +struct dm_report_field *field, +const void *data,void *private) +{ +const struct volume_group *vg = (const struct volume_group *) data; + +if (!is_orphan_vg (vg->name)) +return dm_report_field_string (rh, field, &vg->name); + +return _field_set_value (field,"" ,NULL ); +} + +static int _vgsysid_disp (struct dm_report *rh,struct dm_pool *mem, +struct dm_report_field *field, +const void *data,void *private) +{ +const struct volume_group *vg = (const struct volume_group *) data; +const char *sysid; + +if (!vg->system_id) +return _field_set_value (field,"" ,NULL ); + +if (!(sysid =dm_pool_strdup (mem, vg->system_id))) { +log_error ("dm_pool_strdup failed" ); +return 0 ; + } + +return dm_report_field_string (rh, field, &sysid); +} +static int _lvname_disp (struct dm_report *rh,struct dm_pool *mem,struct dm_report_field *field,const void *data,void *private __attribute__((unused)))
@@ -1695,7 +1725,10 @@ static void *_obj_get_vg(void *obj) {struct volume_group *vg = ((struct lvm_report_object *)obj)->vg; -return vg ? vg : &_dummy_vg; +if (!vg ||is_orphan_vg (vg->name)) +return &_dummy_vg; + +return vg; }static void *_obj_get_lv (void *obj)
@@ -1863,7 +1896,7 @@ int report_object(void *handle, struct volume_group *vg, }/* The two format fields might as well match. */ -if (!vg && pv) +if ((!vg ||is_orphan_vg (vg->name)) && pv) _dummy_fid.fmt = pv->fmt;return dm_report_object (handle, &obj);
tools/pvdisplay.c +24 -35
82 lines not on this page · raw message
tools/pvresize.c +1 -1
@@ -61,7 +61,7 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv) params.done =0 ; params.total =0 ; - ret =process_each_pv (cmd, argc, argv,NULL ,READ_FOR_UPDATE ,0 , ¶ms, + ret =process_each_pv (cmd, argc, argv,NULL ,READ_FOR_UPDATE , ¶ms, _pvresize_single); log_print_unless_silent("%d physical volume(s) resized / %d physical volume(s) "
tools/reporter.c +25 -58
132 lines not on this page · raw message
tools/toollib.c +367 -247
647 lines not on this page · raw message
tools/toollib.h +3 -5
@@ -58,8 +58,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,int process_each_pv (struct cmd_context *cmd,int argc,char **argv,struct volume_group *vg,uint32_t lock_type, -int scan_label_only,void *handle, -process_single_pv_fn_t process_single_pv); +void *handle,process_single_pv_fn_t process_single_pv);int process_each_label (struct cmd_context *cmd,int argc,char **argv,void *handle,process_single_label_fn_t process_single_label);
@@ -80,13 +79,12 @@ int process_each_segment_in_lv(struct cmd_context *cmd, process_single_seg_fn_t process_single_seg);int process_each_pv_in_vg (struct cmd_context *cmd,struct volume_group *vg, -const struct dm_list *tagsl,void *handle, -process_single_pv_fn_t process_single_pv); +void *handle,process_single_pv_fn_t process_single_pv);int process_each_lv_in_vg (struct cmd_context *cmd,struct volume_group *vg, -const struct dm_list *arg_lvnames, +struct dm_list *arg_lvnames,const struct dm_list *tagsl,void *handle,process_single_lv_fn_t process_single_lv);
tools/vgdisplay.c +1 -1
@@ -43,7 +43,7 @@ static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name, (process_single_lv_fn_t)lvdisplay_full);log_print ("--- Physical volumes ---" ); -process_each_pv_in_vg (cmd, vg,NULL ,NULL , +process_each_pv_in_vg (cmd, vg,NULL , (process_single_pv_fn_t )pvdisplay_short); }
tools/vgreduce.c +1 -1
@@ -249,7 +249,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)/* FIXME: Pass private struct through to all these functions */ /* and update in batch here? */ - ret =process_each_pv (cmd, argc, argv, vg,READ_FOR_UPDATE ,0 ,NULL , + ret =process_each_pv (cmd, argc, argv, vg,READ_FOR_UPDATE ,NULL , _vgreduce_single); }