Add pv->vg link, v3
cover Add pv->vg link, v3
This is a third revision of the patchset that adds a pv->vg link. This patchset hopefully covers all remaining cases.
There's plenty of room for future cleanup/refactorings but I stop here for now.
Passes testsuite.
PATCH 1/5 Remove unnecessary parameter from import_pool_pvs().
The dm_list * parameter is unnecessary since we are passing in 'vg' and the only caller of import_pool_pvs() passes '&vg->pvs' in the dm_list * parameter. Just use vg->pvs directly in the function.
--- lib/format_pool/disk_rep.h | 2 +- lib/format_pool/format_pool.c | 2 +- lib/format_pool/import_export.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
lib/format_pool/disk_rep.h +1 -1
@@ -141,7 +141,7 @@ int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct dm_listint import_pool_lvs (struct volume_group *vg,struct dm_pool *mem,struct dm_list *pls);int import_pool_pvs (const struct format_type *fmt,struct volume_group *vg, -struct dm_list *pvs,struct dm_pool *mem,struct dm_list *pls); +struct dm_pool *mem,struct dm_list *pls);int import_pool_pv (const struct format_type *fmt,struct dm_pool *mem,struct volume_group *vg,struct physical_volume *pv,struct pool_list *pl);
lib/format_pool/format_pool.c +1 -1
@@ -129,7 +129,7 @@ static struct volume_group *_build_vg_from_pds(struct format_instanceif (!import_pool_vg (vg, smem, pds)) return_NULL; -if (!import_pool_pvs (fid->fmt, vg, &vg->pvs, smem, pds)) +if (!import_pool_pvs (fid->fmt, vg, smem, pds)) return_NULL;if (!import_pool_lvs (vg, smem, pds))
lib/format_pool/import_export.c +2 -2
@@ -100,7 +100,7 @@ int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct dm_list }int import_pool_pvs (const struct format_type *fmt,struct volume_group *vg, -struct dm_list *pvs,struct dm_pool *mem,struct dm_list *pls) +struct dm_pool *mem,struct dm_list *pls) {struct pv_list *pvl;struct pool_list *pl;
@@ -120,7 +120,7 @@ int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg, pl->pv = pvl->pv; pvl->mdas =NULL ; pvl->pe_ranges =NULL ; -dm_list_add (pvs, &pvl->list); +dm_list_add (&vg->pvs, &pvl->list); }return 1 ;
Signature · 1 line
1.6.0.6
PATCH 2/5 Move increment of vg->pv_count from import_pool_vg() to import_pool_pvs().
Move the increment of vg->pv_count next to the place where we add to vg->pvs. It looks safe to do this since the only caller of import_pool_vg() calls import_pool_pvs() immediately afterward, and there is no way import_pool_vg() can fail (always returns 1). However, if there's a memory allocation failure inside import_pool_pvs(), we will end up with a different count in vg->pv_count that with the original code. In any case, vg->pv_count should be as close to dm_list_size(&vg->pvs) as possible, as is the case everywhere else in the code.
--- lib/format_pool/import_export.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
lib/format_pool/import_export.c +1 -1
@@ -37,7 +37,6 @@ int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct dm_list ((pl->pd.pl_blocks) /POOL_PE_SIZE ); vg->free_count = vg->extent_count; - vg->pv_count++;if (vg->name)continue ;
@@ -120,6 +119,7 @@ int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg, pl->pv = pvl->pv; pvl->mdas =NULL ; pvl->pe_ranges =NULL ; + vg->pv_count++;dm_list_add (&vg->pvs, &pvl->list); }
Signature · 1 line
1.6.0.6
PATCH 3/5 Add del_pvl_from_vgs() and move prototypes into metadata-exported.h
Add a delete function to manage the vg->pvs list.
--- lib/metadata/metadata-exported.h | 7 +++++++ lib/metadata/metadata.c | 6 ++++++ lib/metadata/metadata.h | 1 - 3 files changed, 13 insertions(+), 1 deletions(-)
lib/metadata/metadata-exported.h +7 -0
@@ -469,6 +469,13 @@ int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc);int vg_set_clustered (struct volume_group *vg,int clustered);int vg_split_mdas (struct cmd_context *cmd,struct volume_group *vg_from,struct volume_group *vg_to); +/* +* FIXME: These functions should probably take a 'pv' as parameter. To +* accomplish this, add dm_list * to struct physical_volume and refactor all +* the callers. +*/ +void add_pvl_to_vgs (struct volume_group *vg,struct pv_list *pvl); +void del_pvl_from_vgs (struct volume_group *vg,struct pv_list *pvl);/* FIXME: refactor / unexport when lvremove liblvm refactoring dones */ int remove_lvs_in_vg(struct cmd_context *cmd,
lib/metadata/metadata.c +6 -0
@@ -142,6 +142,12 @@ void add_pvl_to_vgs(struct volume_group *vg, struct pv_list *pvl) vg->pv_count++; } +void del_pvl_from_vgs (struct volume_group *vg,struct pv_list *pvl) +{ + vg->pv_count--; +dm_list_del (&pvl->list); +} +/** * add_pv_to_vg - Add a physical volume to a volume group
lib/metadata/metadata.h +0 -1
@@ -377,6 +377,5 @@ struct id pv_vgid(const struct physical_volume *pv);struct physical_volume *pv_by_path (struct cmd_context *cmd,const char *pv_name);int add_pv_to_vg (struct volume_group *vg,const char *pv_name,struct physical_volume *pv); -void add_pvl_to_vgs (struct volume_group *vg,struct pv_list *pvl);#endif
Signature · 1 line
1.6.0.6
PATCH 4/5 Call add_pvl_to_vgs() and del_pvl_from_vgs() from more places.
Now that we have library functions to add/delete a pv from the vg->pvs list, call them from everywhere.
--- lib/format_pool/import_export.c | 3 +-- lib/metadata/metadata.c | 11 ++++------- tools/lvconvert.c | 3 +-- tools/vgmerge.c | 14 +++++--------- tools/vgreduce.c | 4 +--- 5 files changed, 12 insertions(+), 23 deletions(-)
lib/format_pool/import_export.c +1 -2
@@ -119,8 +119,7 @@ int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg, pl->pv = pvl->pv; pvl->mdas =NULL ; pvl->pe_ranges =NULL ; - vg->pv_count++; -dm_list_add (&vg->pvs, &pvl->list); +add_pvl_to_vgs (vg, pvl); }return 1 ;
lib/metadata/metadata.c +4 -7
@@ -338,10 +338,8 @@ int move_pv(struct volume_group *vg_from, struct volume_group *vg_to, _vg_bad_status_bits(vg_to, RESIZEABLE_VG))return 0 ; -dm_list_move (&vg_to->pvs, &pvl->list); - - vg_from->pv_count--; - vg_to->pv_count++; +del_pvl_from_vgs (vg_from, pvl); +add_pvl_to_vgs (vg_to, pvl); pv = pvl->pv;
@@ -508,7 +506,7 @@ int vg_remove_check(struct volume_group *vg)return 0 ; dm_list_iterate_items_safe(pvl, tpvl, &vg->pvs) { -dm_list_del (&pvl->list); +del_pvl_from_vgs (vg, pvl);dm_list_add (&vg->removed_pvs, &pvl->list); }return 1 ;
@@ -2501,8 +2499,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd, goto bad; } pvl->pv = pv; -dm_list_add (&vg->pvs, &pvl->list); - vg->pv_count++; +add_pvl_to_vgs (vg, pvl); }return vg;
tools/lvconvert.c +1 -2
@@ -736,8 +736,7 @@ static void _remove_missing_empty_pv(struct volume_group *vg, struct dm_list *re/* FIXME: duplication of vgreduce code, move this to library */ vg->free_count -= pvl_vg->pv->pe_count; vg->extent_count -= pvl_vg->pv->pe_count; - vg->pv_count--; -dm_list_del (&pvl_vg->list); +del_pvl_from_vgs (vg, pvl_vg); removed++; }
tools/vgmerge.c +5 -9
@@ -31,6 +31,7 @@ static struct volume_group *_vgmerge_vg_read(struct cmd_context *cmd,static int _vgmerge_single (struct cmd_context *cmd,const char *vg_name_to,const char *vg_name_from) { +struct pv_list *pvl, *tpvl;struct volume_group *vg_to, *vg_from;struct lv_list *lvl1, *lvl2;int r =ECMD_FAILED ;
@@ -82,16 +83,11 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,drop_cached_metadata (vg_from);/* Merge volume groups */ -while (!dm_list_empty (&vg_from->pvs)) { -struct dm_list *pvh = vg_from->pvs.n; -struct physical_volume *pv; - -dm_list_move (&vg_to->pvs, pvh); - - pv = dm_list_item(pvh, struct pv_list)->pv; - pv->vg_name =dm_pool_strdup (cmd->mem, vg_to->name); + dm_list_iterate_items_safe(pvl, tpvl, &vg_from->pvs) { +del_pvl_from_vgs (vg_from, pvl); +add_pvl_to_vgs (vg_to, pvl); + pvl->pv->vg_name =dm_pool_strdup (cmd->mem, vg_to->name); } - vg_to->pv_count += vg_from->pv_count;/* Fix up LVIDs */ dm_list_iterate_items(lvl1, &vg_to->lvs) {
tools/vgreduce.c +1 -3
@@ -39,9 +39,7 @@ static int _remove_pv(struct volume_group *vg, struct pv_list *pvl, int silent) vg->free_count -= pvl->pv->pe_count; vg->extent_count -= pvl->pv->pe_count; - vg->pv_count--; - -dm_list_del (&pvl->list); +del_pvl_from_vgs (vg, pvl);return 1 ; }
Signature · 1 line
1.6.0.6
PATCH 5/5 Add pv->vg to solidify link between a pv and a vg.
lvm2app needs a link back to the vg in order to use the vg handle for memory allocations as well as other things. This patch adds the field to struct physical_volume, and sets pv->vg when reading a vg from disk or extending a vg by using the helper function previously added, add_pvl_to_vgs(). Moves and renames are handled with separate code inside move_pv() and vgmerge(). Add pv->vg check to vg_validate().
NOTE: Unfortunately in the case of pv_read() callers, we cannot set this pv->vg field properly, since the vg it belongs to may not be known by just reading a single device, and no VG is in existence at the time of pv_read(). Significant refactorings related to lvmcache, PVs with 0 mdas, etc, are required to set this field for callers of pv_read(). For now we assume that if the field is NULL, the pv is not associated with a complete VG (as returned by vg_read()).
--- lib/metadata/metadata-exported.h | 11 +++++++++++ lib/metadata/metadata.c | 8 ++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
lib/metadata/metadata-exported.h +11 -0
@@ -181,9 +181,20 @@ struct physical_volume {struct id id;struct device *dev;const struct format_type *fmt; + +/* +* vg_name and vgid are used before the parent VG struct exists. +* FIXME: remove these in favor of using 'vg' below. +*/ const char *vg_name;struct id vgid; +/* +* 'vg' is set and maintained when the PV belongs to a 'pvs' +* list in a parent VG struct. +*/ +struct volume_group *vg; +uint64_t status;uint64_t size;
lib/metadata/metadata.c +8 -0
@@ -140,12 +140,14 @@ void add_pvl_to_vgs(struct volume_group *vg, struct pv_list *pvl) {dm_list_add (&vg->pvs, &pvl->list); vg->pv_count++; + pvl->pv->vg = vg; }void del_pvl_from_vgs (struct volume_group *vg,struct pv_list *pvl) { vg->pv_count--;dm_list_del (&pvl->list); + pvl->pv->vg =NULL ; }
@@ -2150,6 +2152,12 @@ int vg_validate(struct volume_group *vg)/* FIXME Dump list structure? */ r =0 ; } +if (pvl->pv->vg != vg) { +log_error (INTERNAL_ERROR "VG %s PV list entry points " +"to different VG %s" , vg->name, + pvl->pv->vg ? pvl->pv->vg->name :"NULL" ); + r =0 ; + } } loop_counter1 = loop_counter2 =0 ;
Signature · 1 line
1.6.0.6
PATCH 1/1 Use del_pvl_from_vgs() in vgreduce paths.
In reply to Dave WysochanskiSomehow these got missed in earlier patches.
--- lib/metadata/metadata.c | 3 +-- tools/vgreduce.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
lib/metadata/metadata.c +1 -2
@@ -667,12 +667,11 @@ int vg_reduce(struct volume_group *vg, char *pv_name) goto bad; } - vg->pv_count--; vg->free_count -=pv_pe_count (pv) -pv_pe_alloc_count (pv); vg->extent_count -=pv_pe_count (pv); +del_pvl_from_vgs (vg, pvl);/* add pv to the remove_pvs list */ -dm_list_del (&pvl->list);dm_list_add (&vg->removed_pvs, &pvl->list);return 1 ;
tools/vgreduce.c +1 -2
@@ -407,7 +407,7 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,log_verbose ("Removing \"%s\" from volume group \"%s\"" , name, vg->name);if (pvl) -dm_list_del (&pvl->list); +del_pvl_from_vgs (vg, pvl); pv->vg_name = vg->fid->fmt->orphan_vg_name; pv->status =ALLOCATABLE_PV ;
@@ -417,7 +417,6 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg, goto bad; } - vg->pv_count--; vg->free_count -=pv_pe_count (pv) -pv_pe_alloc_count (pv); vg->extent_count -=pv_pe_count (pv);
Signature · 1 line
1.6.0.6