master - toollib: Rewrite process_each_pv.
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f1a000a477558e157532d5f2cd2f9c9139d4f87c Commit: f1a000a477558e157532d5f2cd2f9c9139d4f87c Parent: aeb4d3b740434ed04993e9e7ef74f6e3462efb50 Author: David Teigland <[email protected]> AuthorDate: Tue Oct 7 00:34:04 2014 +0100 Committer: Alasdair G Kergon <[email protected]> CommitterDate: Tue Oct 7 01:15:43 2014 +0100
toollib: Rewrite process_each_pv.
Process PVs by iterating through VGs, then iterating through devices if the command needs to process non-PV devices. The process_single function can always use the VG and PV args.
[Committed by agk with cosmetic changes and tweaks.]
--- lib/metadata/pv_manip.c | 22 -- lib/report/report.c | 8 +- tools/pvdisplay.c | 59 +++---- tools/pvresize.c | 2 +- tools/reporter.c | 83 +++------ tools/toollib.c | 505 ++++++++++++++++++++++++++++++----------------- tools/toollib.h | 6 +- tools/vgdisplay.c | 2 +- tools/vgreduce.c | 2 +- 9 files changed, 379 insertions(+), 310 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/report/report.c +6 -2
@@ -272,7 +272,7 @@ static int _vgfmt_disp(struct dm_report *rh, struct dm_pool *mem, {const struct volume_group *vg = (const struct volume_group *) data; -if (vg->fid) +if (vg->fid && vg->fid->fmt)return _string_disp (rh, mem, field, &vg->fid->fmt->name, private);return _field_set_value (field,"" ,NULL );
@@ -1880,8 +1880,12 @@ int report_object(void *handle, struct volume_group *vg, obj.label = &dummy_label; } +/* Never report orphan VGs. */ +if (vg &&is_orphan_vg (vg->name)) + obj.vg =NULL ; +/* The two format fields might as well match. */ -if (!vg && pv) +if (!obj.vg && 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 +319 -186
635 lines not on this page · raw message
tools/toollib.h +2 -4
@@ -50,8 +50,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);
@@ -72,8 +71,7 @@ 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,
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); }