toollib: rework process_each_pv
PATCH 7/8 toollib: rework process_each_pv
Split up process_each_pv, matching the previous renovation to process_each_vg,lv.
The VG_GLOBAL lock is now taken by the two callers that had wanted it.
Two new flags passed to process_each_pv control which pvs should be processed when command args contain no pv names or tags:
ENABLE_ALL_VGNAMES
Scan for all vgs, including orphan vgs, and process each pv in them.
ENABLE_ALL_DEVS
Scan for all devices, including non-pvs, and process each.
process_single_pv is always passed the vg when the pv is not an orphan. If the pv is an orphan (or has no mda and is not otherwise identified as belonging to a vg), vg is NULL.
Previously, process_single_pv would not receive the vg in what was the ENABLE_ALL_DEVS case, and had to read the vg itself. This case is now removed from instances of process_single_pv.
--- lib/metadata/metadata-exported.h | 1 + tools/pvdisplay.c | 74 ++-- tools/pvresize.c | 37 +- tools/reporter.c | 94 ++--- tools/toollib.c | 855 ++++++++++++++++++++++++++++----------- tools/toollib.h | 3 +- tools/vgdisplay.c | 2 +- 7 files changed, 697 insertions(+), 369 deletions(-)
lib/metadata/metadata-exported.h +1 -0
@@ -122,6 +122,7 @@/* meta-flags, useful with toollib for_each_* functions. */ #define READ_FOR_UPDATE 0x00100000U#define ENABLE_ALL_VGNAMES 0x00200000U/* run cmd on all vg names if none are named */ +#define ENABLE_ALL_DEVS 0x00400000U/* run cmd on all devs if none are named */ /* vg's "read_status" field */ #define FAILED_INCONSISTENT 0x00000001U
tools/pvdisplay.c +36 -38
101 lines not on this page · raw message
tools/pvresize.c +14 -23
@@ -29,12 +29,10 @@ static 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 (pv); -struct volume_group *old_vg = vg;int vg_needs_pv_write =0 ;if (is_orphan_vg (vg_name)) {
@@ -48,26 +46,19 @@ static int _pv_resize_single(struct cmd_context *cmd,log_error ("Unable to read PV \"%s\"" , pv_name);return 0 ; } - }else { - 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; + }else if (vg) { +/* +* READ_FOR_UPDATE is passed to process_each_pv below, +* and process_each_pv uses that flag in vg_read, so +* reading the vg again here appears to be unnecessary. +*/ if (!archive (vg)) goto out; + }else { +/* should not happen */ +log_error ("pv is not orphan or in a vg" ); +return ECMD_FAILED ; }if (!(pv->fmt->features &FMT_RESIZE_PV )) {
@@ -125,11 +116,11 @@ out:if (!r && vg_needs_pv_write)log_error ("Use pvcreate and vgcfgrestore " "to repair from archived metadata." ); -unlock_vg (cmd, vg_name); -if (is_orphan_vg (vg_name)) + +if (is_orphan_vg (vg_name)) { +unlock_vg (cmd, vg_name);free_pv_fid (pv); -if (!old_vg) -release_vg (vg); + }return r; }
tools/reporter.c +35 -59
149 lines not on this page · raw message
tools/toollib.c +609 -246
936 lines not on this page · raw message
tools/toollib.h +1 -2
@@ -70,8 +70,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 *tags,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
@@ -41,7 +41,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); }
Signature · 1 line
1.8.1.rc1.5.g7e0651a