master - toollib: avoid repeated lvmetad vg_lookup
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8e509b5dd50bff30e5017f572e54f4f384830a58 Commit: 8e509b5dd50bff30e5017f572e54f4f384830a58 Parent: f25132b354b110994b9da8dc3edf39cf4db37657 Author: David Teigland <[email protected]> AuthorDate: Tue May 5 16:24:50 2015 -0500 Committer: David Teigland <[email protected]> CommitterDate: Fri May 8 11:44:55 2015 -0500
toollib: avoid repeated lvmetad vg_lookup
In process_each_{vg,lv,pv} when no vgname args are given, the first step is to get a list of all vgid/vgname on the system. This is exactly what lvmetad returns from a vg_list request. The current code is doing a vg_lookup on each VG after the vg_list and populating lvmcache with the info for each VG. These preliminary vg_lookup's are unnecessary, because they will be done again when the processing functions call vg_read. This patch eliminates the initial round of vg_lookup's, which can roughly cut in half the number of lvmetad requests and save a lot of extra work.
--- lib/cache/lvmcache.c | 31 +++++++++++++ lib/cache/lvmcache.h | 3 + lib/cache/lvmetad.c | 50 +++++++++++++++++++++ lib/cache/lvmetad.h | 6 +++ lib/metadata/metadata-exported.h | 8 +++ lib/metadata/metadata.c | 48 ++++++++++++++++++++ tools/toollib.c | 91 +++++++------------------------------- 7 files changed, 162 insertions(+), 75 deletions(-)
lib/cache/lvmcache.c +31 -0
@@ -905,6 +905,37 @@ int lvmcache_vginfo_holders_dec_and_test_for_zero(struct lvmcache_vginfo *vginfo }// #endif +int lvmcache_get_vgnameids (struct cmd_context *cmd,int include_internal, +struct dm_list *vgnameids) +{ +struct vgnameid_list *vgnl; +struct lvmcache_vginfo *vginfo; + +lvmcache_label_scan (cmd,0 ); + + dm_list_iterate_items(vginfo, &_vginfos) { +if (!include_internal &&is_orphan_vg (vginfo->vgname)) +continue ; + +if (!(vgnl =dm_pool_alloc (cmd->mem,sizeof (*vgnl)))) { +log_error ("vgnameid_list allocation failed." ); +return 0 ; + } + + vgnl->vgid =dm_pool_strdup (cmd->mem, vginfo->vgid); + vgnl->vg_name =dm_pool_strdup (cmd->mem, vginfo->vgname); + +if (!vgnl->vgid || !vgnl->vg_name) { +log_error ("vgnameid_list member allocation failed." ); +return 0 ; + } + +dm_list_add (vgnameids, &vgnl->list); + } + +return 1 ; +} +struct dm_list *lvmcache_get_vgids (struct cmd_context *cmd,int include_internal) {
lib/cache/lvmcache.h +3 -0
@@ -107,6 +107,9 @@ struct dm_list *lvmcache_get_vgnames(struct cmd_context *cmd,struct dm_list *lvmcache_get_vgids (struct cmd_context *cmd,int include_internal); +int lvmcache_get_vgnameids (struct cmd_context *cmd,int include_internal, +struct dm_list *vgnameids); +/* Returns list of struct dm_str_list containing pool-allocated copy of pvids */ struct dm_list *lvmcache_get_pvids (struct cmd_context *cmd,const char *vgname,const char *vgid);
lib/cache/lvmetad.c +50 -0
56 lines not on this page · raw message
lib/cache/lvmetad.h +6 -0
@@ -143,6 +143,12 @@ int lvmetad_pv_lookup_by_dev(struct cmd_context *cmd, struct device *dev, int *fint lvmetad_vg_list_to_lvmcache (struct cmd_context *cmd);/* +* Request a list of vgid/vgname pairs for all VGs known to lvmetad. +* Does not do vg_lookup's on each VG, and does not populate lvmcache. +*/ +int lvmetad_get_vgnameids (struct cmd_context *cmd,struct dm_list *vgnameids); + +/* * Find a VG by its ID or its name in the lvmetad cache. Gives NULL if the VG is * not found. */
lib/metadata/metadata-exported.h +8 -0
@@ -494,6 +494,12 @@ struct vg_list {struct volume_group *vg; }; +struct vgnameid_list { +struct dm_list list; +const char *vg_name; +const char *vgid; +}; +#define PV_PE_START_CALC ((uint64_t) -1)/* Calculate pe_start value */ struct pvcreate_restorable_params {
@@ -606,6 +612,8 @@ void lv_set_hidden(struct logical_volume *lv);struct dm_list *get_vgnames (struct cmd_context *cmd,int include_internal);struct dm_list *get_vgids (struct cmd_context *cmd,int include_internal); +int get_vgnameids (struct cmd_context *cmd,struct dm_list *vgnameids, +const char *only_this_vgname,int include_internal);int scan_vgs_for_pvs (struct cmd_context *cmd,uint32_t warn_flags);int pv_write (struct cmd_context *cmd,struct physical_volume *pv,int allow_non_orphan);
lib/metadata/metadata.c +48 -0
54 lines not on this page · raw message
tools/toollib.c +16 -75
130 lines not on this page · raw message