: Change semantics of lvm_vg_remove and rename vg_remove fns
cover : Change semantics of lvm_vg_remove and rename vg_remove fns
This patchset changes the semantics of lvm_vg_remove to be more consistent with lvm_vg_create, and renames some of the internal lvm library vg_remove functions.
For liblvm, we would like a consistent API that allows modification of LVM objects in memory before committing to disk. The commit to disk is normally done in a single call, lvm_vg_write(). Currently, not all liblvm functions behave this way, and lvm_vg_remove is one of them, as it commits to disk after completion and does not require lvm_vg_write. This is inconsistent with lvm_vg_create, which requires lvm_vg_write to commit to disk. This patchset changes the semantic of lvm_vg_remove to require lvm_vg_write to commit to disk and make it consistent with lvm_vg_create and other functions. Along the way, there are a few renames and minor refactorings to the internal vg_remove functions.
Further cleanup should probably consolidate the various areas where devices are removed from VGs as there is currently a bit of duplicated code. I've avoided such changes in this patchset though to keep it as simple and low risk.
Testsuite ok and applies cleanly on:
commit 597986b711175bd90d234e0a6ac001f165aa1274
Author: Dave Wysochanski <[email protected]> Date: Mon Aug 10 17:23:04 2009 +0000
Update man pages to clarify usage of PE ranges.
PATCH 1/4 Split vg_remove_single into 2 functions - the second part commits to disk.
Split vg_remove_single into vg_remove_check (mandatory checks before vgremove) and vg_remove_ondisk (do actual remove by committing to disk). The choice of the last word in these functions probably can be improved but greps out ok in the tree.
In liblvm, we'd like to provide an consistent API that allows multiple changes in memory, then let lvm_vg_write() control the commit to disk. In some cases (for example, lvresize calls fsadm) this may not be possible. However, since we are using an object model and dividing things into small operations, the most logical model seems to be the lvm_vg_write model, and handling the special cases as they arrive. So as best as possible we move towards this end.
A possible optimization would be to consolidate vg_remove_ondisk code with vgreduce code. A second possible optimization is making vgreduce of the last device equivalent to vgremove. Today, lvm_vg_reduce fails if vgreduce is called with the last device, but from an object model perspective, we could view this as equivalent to vgremove and allow it. My gut feel is we do not want to do this though.
--- lib/metadata/metadata-exported.h | 3 ++- lib/metadata/metadata.c | 14 ++++++++++---- liblvm/lvm_vg.c | 5 ++++- tools/vgremove.c | 5 ++++- 4 files changed, 20 insertions(+), 7 deletions(-)
lib/metadata/metadata-exported.h +2 -1
@@ -442,7 +442,8 @@ uint32_t pv_list_extents_free(const struct dm_list *pvh);struct volume_group *vg_create (struct cmd_context *cmd,const char *vg_name);int vg_remove (struct volume_group *vg); -int vg_remove_single (struct volume_group *vg); +int vg_remove_check (struct volume_group *vg); +int vg_remove_ondisk (struct volume_group *vg);int vg_rename (struct cmd_context *cmd,struct volume_group *vg,const char *new_name);int vg_extend (struct volume_group *vg,int pv_count,char **pv_names);
lib/metadata/metadata.c +10 -4
@@ -468,12 +468,9 @@ int remove_lvs_in_vg(struct cmd_context *cmd,return 1 ; } -int vg_remove_single (struct volume_group *vg) +int vg_remove_check (struct volume_group *vg) { -struct physical_volume *pv; -struct pv_list *pvl;unsigned lv_count; -int ret =1 ;if (vg_read_error (vg) ||vg_missing_pv_count (vg)) { log_error("Volume group \"%s\" not found, is inconsistent "
@@ -497,6 +494,15 @@ int vg_remove_single(struct volume_group *vg)if (!archive (vg))return 0 ; +return 1 ; +} + +int vg_remove_ondisk (struct volume_group *vg) +{ +struct physical_volume *pv; +struct pv_list *pvl; +int ret =1 ; +if (!lock_vol (vg->cmd,VG_ORPHANS ,LCK_VG_WRITE )) {log_error ("Can't get lock for orphan PVs" );return 0 ;
liblvm/lvm_vg.c +4 -1
@@ -153,7 +153,10 @@ int lvm_vg_remove(vg_t *vg)if (!vg_check_write_mode (vg))return -1 ; -if (!vg_remove_single (vg)) +if (!vg_remove_check (vg)) +return -1 ; + +if (!vg_remove_ondisk (vg))return -1 ;return 0 ; }
tools/vgremove.c +4 -1
@@ -44,7 +44,10 @@ static int vgremove_single(struct cmd_context *cmd, const char *vg_name,return ECMD_FAILED ; } -if (!vg_remove_single (vg)) +if (!vg_remove_check (vg)) +return ECMD_FAILED ; + +if (!vg_remove_ondisk (vg))return ECMD_FAILED ;return ECMD_PROCESSED ;
Signature · 1 line
1.6.0.6
PATCH 2/4 Update vg_remove_single_* functions to use the removed_pvs list.
Now that we've split vg_remove_single into two routines, in the first routine that only manipulates memory, we move the PVs from the vg->pvs list to the vg->removed_pvs list. Then later, we iterate through this list to write the removed PVs to disk, which removes them from the volume group and places them into the internal ORPHAN VG.
--- lib/metadata/metadata.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
lib/metadata/metadata.c +6 -1
@@ -471,6 +471,7 @@ int remove_lvs_in_vg(struct cmd_context *cmd,int vg_remove_check (struct volume_group *vg) {unsigned lv_count; +struct pv_list *pvl, *tpvl;if (vg_read_error (vg) ||vg_missing_pv_count (vg)) { log_error("Volume group \"%s\" not found, is inconsistent "
@@ -494,6 +495,10 @@ int vg_remove_check(struct volume_group *vg)if (!archive (vg))return 0 ; + dm_list_iterate_items_safe(pvl, tpvl, &vg->pvs) { +dm_list_del (&pvl->list); +dm_list_add (&vg->removed_pvs, &pvl->list); + }return 1 ; }
@@ -515,7 +520,7 @@ int vg_remove_ondisk(struct volume_group *vg) }/* init physical volumes */ - dm_list_iterate_items(pvl, &vg->pvs) { + dm_list_iterate_items(pvl, &vg->removed_pvs) { pv = pvl->pv;log_verbose ("Removing physical volume \"%s\" from " "volume group \"%s\"" ,pv_dev_name (pv), vg->name);
Signature · 1 line
1.6.0.6
PATCH 3/4 Update lvm_vg_write() to handle the deferred commit of lvm_vg_write().
Now that we've refactored the internal library functions that do the vg_remove, we can handle the deferred commit of a lvm_vg_remove() inside lvm_vg_write(). This makes the VG create/remove API more consistent in terms of disk commits - they now both require an lvm_vg_write() to commit the create or remove to disk.
--- liblvm/lvm2app.h | 4 ++-- liblvm/lvm_vg.c | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-)
liblvm/lvm2app.h +2 -2
@@ -394,8 +394,8 @@ int lvm_vg_write(vg_t *vg);/** * Remove a VG from the system. * -* This function commits the change to disk and does not require calling -* lvm_vg_write. +* This function removes a Volume Group object in memory, and requires +* calling lvm_vg_write to commit the removal to disk. * * \param vg * VG handle obtained from lvm_vg_create or lvm_vg_open.
liblvm/lvm_vg.c +3 -5
@@ -106,9 +106,9 @@ int lvm_vg_write(vg_t *vg)return -1 ;if (dm_list_empty (&vg->pvs)) { -log_error ("Volume group %s does not contain any " -"physical volumes." , vg->name); -return -1 ; +if (!vg_remove_ondisk (vg)) +return -1 ; +return 0 ; }if (!dm_list_empty (&vg->removed_pvs)) {
@@ -156,8 +156,6 @@ int lvm_vg_remove(vg_t *vg)if (!vg_remove_check (vg))return -1 ; -if (!vg_remove_ondisk (vg)) -return -1 ;return 0 ; }
Signature · 1 line
1.6.0.6
PATCH 4/4 Rename internal library function vg_remove to vg_remove_mdas.
Later patches should consolidate the vgremove / vgreduce functions but for now let's clarify what vg_remove actually does by changing the name.
--- lib/metadata/metadata-exported.h | 6 +++--- lib/metadata/metadata.c | 6 +++--- tools/vgconvert.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)
lib/metadata/metadata-exported.h +3 -3
@@ -1,6 +1,6 @@/* -* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. -* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. +* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. +* Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. *
@@ -441,7 +441,7 @@ int pv_analyze(struct cmd_context *cmd, const char *pv_name,uint32_t pv_list_extents_free (const struct dm_list *pvh);struct volume_group *vg_create (struct cmd_context *cmd,const char *vg_name); -int vg_remove (struct volume_group *vg); +int vg_remove_mdas (struct volume_group *vg);int vg_remove_check (struct volume_group *vg);int vg_remove_ondisk (struct volume_group *vg); int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
lib/metadata/metadata.c +3 -3
@@ -513,8 +513,8 @@ int vg_remove_ondisk(struct volume_group *vg)return 0 ; } -if (!vg_remove (vg)) { -log_error ("vg_remove %s failed" , vg->name); +if (!vg_remove_mdas (vg)) { +log_error ("vg_remove_mdas %s failed" , vg->name);unlock_vg (vg->cmd,VG_ORPHANS );return 0 ; }
@@ -1683,7 +1683,7 @@ struct pv_segment *find_peg_by_pe(const struct physical_volume *pv, uint32_t pe)return NULL ; } -int vg_remove (struct volume_group *vg) +int vg_remove_mdas (struct volume_group *vg) {struct metadata_area *mda;
tools/vgconvert.c +1 -1
@@ -167,7 +167,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name, }log_verbose ("Deleting existing metadata for VG %s" , vg_name); -if (!vg_remove (vg)) { +if (!vg_remove_mdas (vg)) {log_error ("Removal of existing metadata for %s failed." , vg_name); log_error("Use pvcreate and vgcfgrestore to repair "
Signature · 1 line
1.6.0.6