master - pvscan: use process_each_pv
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=83d475626a4d9ecaa2084f349cb2cee4f0f3a719 Commit: 83d475626a4d9ecaa2084f349cb2cee4f0f3a719 Parent: 1ea7e2634d67a7628508a677668a00f748aee0b0 Author: David Teigland <[email protected]> AuthorDate: Mon Oct 19 13:58:43 2015 -0500 Committer: David Teigland <[email protected]> CommitterDate: Mon Oct 19 16:15:51 2015 -0500
pvscan: use process_each_pv
The old code made two loops through the PVs: in the first loop it found the max PV and VG name lengths, and in the second loop it printed each PV using the name lengths as field widths for aligning columns.
The new code uses process_each_pv() which makes one loop through the PVs. In the *first* call to pvscan_single(), the max name lengths are found by looping through the lvmcache entries which have been populated by the generic process_each code prior to calling any _single functions. Subsequent calls to pvscan_single() reuse the max lengths that were found by the first call.
--- lib/cache/lvmcache.c | 24 +++++++ lib/cache/lvmcache.h | 4 + tools/pvscan.c | 178 ++++++++++++++++++++++---------------------------- 3 files changed, 107 insertions(+), 99 deletions(-)
lib/cache/lvmcache.c +24 -0
@@ -2358,3 +2358,27 @@ int lvmcache_contains_lock_type_sanlock(struct cmd_context *cmd)return 0 ; } +void lvmcache_get_max_name_lengths (struct cmd_context *cmd, +unsigned *pv_max_name_len, +unsigned *vg_max_name_len) +{ +struct lvmcache_vginfo *vginfo; +struct lvmcache_info *info; +unsigned len; + + *vg_max_name_len =0 ; + *pv_max_name_len =0 ; + + dm_list_iterate_items(vginfo, &_vginfos) { + len =strlen (vginfo->vgname); +if (*vg_max_name_len < len) + *vg_max_name_len = len; + + dm_list_iterate_items(info, &vginfo->infos) { + len =strlen (dev_name (info->dev)); +if (*pv_max_name_len < len) + *pv_max_name_len = len; + } + } +} +
lib/cache/lvmcache.h +4 -0
@@ -190,4 +190,8 @@ void lvmcache_set_preferred_duplicates(const char *vgid);int lvmcache_contains_lock_type_sanlock (struct cmd_context *cmd); +void lvmcache_get_max_name_lengths (struct cmd_context *cmd, +unsigned *pv_max_name_len,unsigned *vg_max_name_len); + +#endif
tools/pvscan.c +79 -99
241 lines not on this page · raw message