: take2 - Implement vg_create() and 4 required vg_set*() APIs
cover : take2 - Implement vg_create() and 4 required vg_set*() APIs
This is a second iteration of the vg_create() patchset sent earlier. I believe all comments so far have been addressed and I've broken the patches up a bit more.
Passes testsuite and applies cleanly on:
commit e6901382a6fc4bb2c6dcb263b77ebcf61316cdac
Author: Dave Wysochanski <[email protected]> Date: Thu Jul 9 05:40:59 2009 +0000
Fix memory leak in vgsplit when re-reading the VG.
PATCH 1/9 Change behavior of tools to make setting the same value return success.
Internally the tools were inconsistent. Some would use log_error() and then exit with a success code. However most would use log_error() and exit with an error code if a user tried to set the value of something that was already stored. I believe this is wrong because it is not what a user would expect normally. A user (or an application calling liblvm), would normally expect to get a pass/fail to a set/change request. He would not expect to get a failure if the value was in fact set. It is much easier to write shell or application code this way instead of checking for the special case where the value did indeed get set, but it just so happened it was already stored - most applications will not care.
To this end, I've modified all the tools to be consistent in this regard. We now should always use log_print() and exit with a success code if a user sets a value already stored.
--- lib/metadata/metadata.c | 5 ----- tools/lvchange.c | 22 +++++++++++----------- tools/lvrename.c | 4 ++-- tools/vgchange.c | 24 ++++++++++++------------ tools/vgrename.c | 5 +++++ 5 files changed, 30 insertions(+), 30 deletions(-)
lib/metadata/metadata.c +0 -5
@@ -309,11 +309,6 @@ int validate_vg_rename_params(struct cmd_context *cmd,return 0 ; } -if (!strcmp (vg_name_old, vg_name_new)) { -log_error ("Old and new volume group names must differ" ); -return 0 ; - } -return 1 ; }
tools/lvchange.c +11 -11
@@ -25,15 +25,15 @@ static int lvchange_permission(struct cmd_context *cmd, lv_access =arg_uint_value (cmd, permission_ARG,0 );if ((lv_access &LVM_WRITE ) && (lv->status &LVM_WRITE )) { -log_error ("Logical volume \"%s\" is already writable" , +log_print ("Logical volume \"%s\" is already writable" , lv->name); -return 0 ; +return 1 ; }if (!(lv_access &LVM_WRITE ) && !(lv->status &LVM_WRITE )) { -log_error ("Logical volume \"%s\" is already read only" , +log_print ("Logical volume \"%s\" is already read only" , lv->name); -return 0 ; +return 1 ; } if ((lv->status & MIRRORED) && (vg_is_clustered(lv->vg)) &&
@@ -329,9 +329,9 @@ static int lvchange_alloc(struct cmd_context *cmd, struct logical_volume *lv) alloc =arg_uint_value (cmd, alloc_ARG, alloc);if (alloc == lv->alloc) { -log_error ("Allocation policy of logical volume \"%s\" is " +log_print ("Allocation policy of logical volume \"%s\" is " "already %s" , lv->name,get_alloc_string (alloc)); -return 0 ; +return 1 ; } lv->alloc = alloc;
@@ -380,11 +380,11 @@ static int lvchange_readahead(struct cmd_context *cmd,if (lv->read_ahead == read_ahead) {if (read_ahead ==DM_READ_AHEAD_AUTO ) -log_error ("Read ahead is already auto for \"%s\"" , lv->name); +log_print ("Read ahead is already auto for \"%s\"" , lv->name);else -log_error ("Read ahead is already %u for \"%s\"" , +log_print ("Read ahead is already %u for \"%s\"" , read_ahead, lv->name); -return 0 ; +return 1 ; } lv->read_ahead = read_ahead;
@@ -427,9 +427,9 @@ static int lvchange_persistent(struct cmd_context *cmd,if (!strcmp (arg_str_value (cmd, persistent_ARG,"n" ),"n" )) {if (!(lv->status &FIXED_MINOR )) { -log_error ("Minor number is already not persistent " +log_print ("Minor number is already not persistent " "for \"%s\"" , lv->name); -return 0 ; +return 1 ; } lv->status &= ~FIXED_MINOR ; lv->minor =-1 ;
tools/lvrename.c +2 -2
@@ -97,8 +97,8 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv) }if (!strcmp (lv_name_old, lv_name_new)) { -log_error ("Old and new logical volume names must differ" ); -return EINVALID_CMD_LINE ; +log_print ("Logical volume name already \"%s\"" , lv_name_new); +return ECMD_PROCESSED ; }log_verbose ("Checking for existing volume group \"%s\"" , vg_name);
tools/vgchange.c +12 -12
@@ -186,9 +186,9 @@ static int _vgchange_alloc(struct cmd_context *cmd, struct volume_group *vg) }if (alloc == vg->alloc) { -log_error ("Volume group allocation policy is already %s" , +log_print ("Volume group allocation policy is already %s" ,get_alloc_string (vg->alloc)); -return ECMD_FAILED ; +return ECMD_PROCESSED ; }if (!archive (vg))
@@ -212,15 +212,15 @@ static int _vgchange_resizeable(struct cmd_context *cmd,int resizeable = !strcmp (arg_str_value (cmd, resizeable_ARG,"n" ),"y" );if (resizeable && (vg_status (vg) &RESIZEABLE_VG )) { -log_error ("Volume group \"%s\" is already resizeable" , +log_print ("Volume group \"%s\" is already resizeable" , vg->name); -return ECMD_FAILED ; +return ECMD_PROCESSED ; }if (!resizeable && !(vg_status (vg) &RESIZEABLE_VG )) { -log_error ("Volume group \"%s\" is already not resizeable" , +log_print ("Volume group \"%s\" is already not resizeable" , vg->name); -return ECMD_FAILED ; +return ECMD_PROCESSED ; }if (!archive (vg))
@@ -248,15 +248,15 @@ static int _vgchange_clustered(struct cmd_context *cmd,struct lv_list *lvl;if (clustered && (vg_is_clustered (vg))) { -log_error ("Volume group \"%s\" is already clustered" , +log_print ("Volume group \"%s\" is already clustered" , vg->name); -return ECMD_FAILED ; +return ECMD_PROCESSED ; }if (!clustered && !(vg_is_clustered (vg))) { -log_error ("Volume group \"%s\" is already not clustered" , +log_print ("Volume group \"%s\" is already not clustered" , vg->name); -return ECMD_FAILED ; +return ECMD_PROCESSED ; }if (clustered) {
@@ -399,7 +399,7 @@ static int _vgchange_pesize(struct cmd_context *cmd, struct volume_group *vg) }if (extent_size == vg->extent_size) { -log_error ("Physical extent size of VG %s is already %s" , +log_print ("Physical extent size of VG %s is already %s" , vg->name,display_size (cmd, (uint64_t ) extent_size));return ECMD_PROCESSED ; }
@@ -516,7 +516,7 @@ static int _vgchange_refresh(struct cmd_context *cmd, struct volume_group *vg)if (!vg_refresh_visible (cmd, vg))return ECMD_FAILED ; - +return ECMD_PROCESSED ; }
tools/vgrename.c +5 -0
@@ -38,6 +38,11 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,if (!validate_vg_rename_params (cmd, vg_name_old, vg_name_new))return 0 ; +if (!strcmp (vg_name_old, vg_name_new)) { +log_print ("Volume group name is already \"%s\"" , vg_name_new); +return 1 ; + } +log_verbose ("Checking for existing volume group \"%s\"" , vg_name_old);/* Avoid duplicates */
Signature · 1 line
1.6.0.6
PATCH 2/9 Add defines for default vgcreate parameters.
--- lib/config/defaults.h | 8 ++++++-- tools/vgcreate.c | 8 ++++---- tools/vgsplit.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-)
lib/config/defaults.h +6 -2
@@ -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. *
@@ -66,6 +66,10 @@#define DEFAULT_LABELSECTOR UINT64_C(1)#define DEFAULT_READ_AHEAD "auto"#define DEFAULT_EXTENT_SIZE 4096/* In KB */ +#define DEFAULT_MAX_PV 0 +#define DEFAULT_MAX_LV 0 +#define DEFAULT_ALLOC_POLICY ALLOC_NORMAL +#define DEFAULT_CLUSTERED 0#define DEFAULT_MSG_PREFIX " "#define DEFAULT_CMD_NAME 0
tools/vgcreate.c +4 -4
@@ -36,10 +36,10 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv) vp_def.vg_name =NULL ; vp_def.extent_size =DEFAULT_EXTENT_SIZE *2 ; - vp_def.max_pv =0 ; - vp_def.max_lv =0 ; - vp_def.alloc =ALLOC_NORMAL ; - vp_def.clustered =0 ; + vp_def.max_pv =DEFAULT_MAX_PV ; + vp_def.max_lv =DEFAULT_MAX_LV ; + vp_def.alloc =DEFAULT_ALLOC_POLICY ; + vp_def.clustered =DEFAULT_CLUSTERED ;if (fill_vg_create_params (cmd, argv[0 ], &vp_new, &vp_def))return EINVALID_CMD_LINE ;
tools/vgsplit.c +1 -1
@@ -368,7 +368,7 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv) vp_def.max_pv = vg_from->max_pv; vp_def.max_lv = vg_from->max_lv; vp_def.alloc = vg_from->alloc; - vp_def.clustered =0 ; + vp_def.clustered =DEFAULT_CLUSTERED ;if (fill_vg_create_params (cmd, vg_name_to, &vp_new, &vp_def)) { r =EINVALID_CMD_LINE ;
Signature · 1 line
1.6.0.6
PATCH 3/9 Update vg_change_pesize() to contain all validity checks.
It would be nice to have one function that does all the validation and setting of the VG's pesize. However, currently some checks are in the higher-level function _vgchange_pesize(), and some checks are in the lower function vg_change_pesize(). This patch moves most of the higher-level checks inside vg_change_pesize. In one case a failure return code is changed from ECMD_FAILED to EINVALID_CMD_LINE.
--- lib/metadata/metadata.c | 30 ++++++++++++++++++++++++++++++ tools/vgchange.c | 27 ++------------------------- 2 files changed, 32 insertions(+), 25 deletions(-)
lib/metadata/metadata.c +30 -0
@@ -631,6 +631,36 @@ int vg_change_pesize(struct cmd_context *cmd __attribute((unused)),struct pv_segment *pvseg;uint32_t s; +if (!(vg_status (vg) &RESIZEABLE_VG )) { +log_error ("Volume group \"%s\" must be resizeable " +"to change PE size" , vg->name); +return 0 ; + } + +if (!new_size) { +log_error ("Physical extent size may not be zero" ); +return 0 ; + } + +if (new_size == vg->extent_size) { +log_print ("Physical extent size of VG %s is already %s" , + vg->name,display_size (vg->cmd, (uint64_t ) new_size)); +return 1 ; + } + +if (new_size & (new_size -1 )) { +log_error ("Physical extent size must be a power of 2." ); +return 0 ; + } + +if (new_size > vg->extent_size) { +if ((uint64_t ) vg->extent_size * vg->extent_count % new_size) { +/* FIXME Adjust used PV sizes instead */ +log_error ("New extent size is not a perfect fit" ); +return 0 ; + } + } + vg->extent_size = new_size; if (vg->fid->fmt->ops->vg_setup &&
tools/vgchange.c +2 -25
@@ -381,48 +381,25 @@ static int _vgchange_pesize(struct cmd_context *cmd, struct volume_group *vg) {uint32_t extent_size; -if (!(vg_status (vg) &RESIZEABLE_VG )) { -log_error ("Volume group \"%s\" must be resizeable " -"to change PE size" , vg->name); -return ECMD_FAILED ; - } -if (arg_sign_value (cmd, physicalextentsize_ARG,0 ) ==SIGN_MINUS ) {log_error ("Physical extent size may not be negative" );return EINVALID_CMD_LINE ; } extent_size =arg_uint_value (cmd, physicalextentsize_ARG,0 ); -if (!extent_size) { -log_error ("Physical extent size may not be zero" ); -return EINVALID_CMD_LINE ; - } - +/* FIXME: remove check - redundant with vg_change_pesize */ if (extent_size == vg->extent_size) {log_print ("Physical extent size of VG %s is already %s" , vg->name,display_size (cmd, (uint64_t ) extent_size));return ECMD_PROCESSED ; } -if (extent_size & (extent_size -1 )) { -log_error ("Physical extent size must be a power of 2." ); -return EINVALID_CMD_LINE ; - } - -if (extent_size > vg->extent_size) { -if ((uint64_t ) vg->extent_size * vg->extent_count % extent_size) { -/* FIXME Adjust used PV sizes instead */ -log_error ("New extent size is not a perfect fit" ); -return EINVALID_CMD_LINE ; - } - } -if (!archive (vg))return ECMD_FAILED ;if (!vg_change_pesize (cmd, vg, extent_size)) { stack; -return ECMD_FAILED ; +return EINVALID_CMD_LINE ; }if (!vg_write (vg) || !vg_commit (vg))
Signature · 1 line
1.6.0.6
PATCH 4/9 Remove unused 'cmd' from vg_change_pesize().
Remove unused 'cmd' from vg_change_pesize().
--- lib/metadata/metadata-exported.h | 3 +-- lib/metadata/metadata.c | 3 +-- tools/vgchange.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-)
lib/metadata/metadata-exported.h +1 -2
@@ -434,8 +434,7 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name,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); -int vg_change_pesize (struct cmd_context *cmd,struct volume_group *vg, -uint32_t new_extent_size); +int vg_change_pesize (struct volume_group *vg,uint32_t new_extent_size);int vg_split_mdas (struct cmd_context *cmd,struct volume_group *vg_from,struct volume_group *vg_to);
lib/metadata/metadata.c +1 -2
@@ -619,8 +619,7 @@ static int _recalc_extents(uint32_t *extents, const char *desc1,return 1 ; } -int vg_change_pesize (struct cmd_context *cmd __attribute((unused)), -struct volume_group *vg,uint32_t new_size) +int vg_change_pesize (struct volume_group *vg,uint32_t new_size) {uint32_t old_size = vg->extent_size;struct pv_list *pvl;
tools/vgchange.c +1 -1
@@ -397,7 +397,7 @@ static int _vgchange_pesize(struct cmd_context *cmd, struct volume_group *vg)if (!archive (vg))return ECMD_FAILED ; -if (!vg_change_pesize (cmd, vg, extent_size)) { +if (!vg_change_pesize (vg, extent_size)) { stack;return EINVALID_CMD_LINE ; }
Signature · 1 line
1.6.0.6
PATCH 5/9 Rename vg_change_pesize to vg_set_extent_size and use vg_t.
Rename vg_change_pesize to vg_set_extent_size and use vg_t. In liblvm, we will reserve the word 'change' to mean an API that both sets one or more values, and commits to disk. This will be consistent with the LVM commandline. The existing vg_change_pesize() function does not commit to disk, but just changes the extent_size and ensures all internal structures are updated. This logic should be contained in a function that sets the value.
--- lib/metadata/metadata-exported.h | 2 +- lib/metadata/metadata.c | 2 +- tools/vgchange.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
lib/metadata/metadata-exported.h +1 -1
@@ -434,7 +434,7 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name,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); -int vg_change_pesize (struct volume_group *vg,uint32_t new_extent_size); +int vg_set_extent_size (vg_t *vg,uint32_t new_extent_size);int vg_split_mdas (struct cmd_context *cmd,struct volume_group *vg_from,struct volume_group *vg_to);
lib/metadata/metadata.c +1 -1
@@ -619,7 +619,7 @@ static int _recalc_extents(uint32_t *extents, const char *desc1,return 1 ; } -int vg_change_pesize (struct volume_group *vg,uint32_t new_size) +int vg_set_extent_size (vg_t *vg,uint32_t new_size) {uint32_t old_size = vg->extent_size;struct pv_list *pvl;
tools/vgchange.c +1 -1
@@ -397,7 +397,7 @@ static int _vgchange_pesize(struct cmd_context *cmd, struct volume_group *vg)if (!archive (vg))return ECMD_FAILED ; -if (!vg_change_pesize (vg, extent_size)) { +if (!vg_set_extent_size (vg, extent_size)) { stack;return EINVALID_CMD_LINE ; }
Signature · 1 line
1.6.0.6
PATCH 6/9 Add vg_set_max_lv() liblvm function and move vgchange logic inside.
Add vg_set_max_lv() liblvm function and move vgchange logic inside.
--- lib/metadata/metadata-exported.h | 1 + lib/metadata/metadata.c | 28 ++++++++++++++++++++++++++++ tools/vgchange.c | 25 ++----------------------- 3 files changed, 31 insertions(+), 23 deletions(-)
lib/metadata/metadata-exported.h +1 -0
@@ -435,6 +435,7 @@ 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);int vg_set_extent_size (vg_t *vg,uint32_t new_extent_size); +int vg_set_max_lv (vg_t *vg,uint32_t max_lv);int vg_split_mdas (struct cmd_context *cmd,struct volume_group *vg_from,struct volume_group *vg_to);
lib/metadata/metadata.c +28 -0
@@ -769,6 +769,34 @@ int vg_set_extent_size(vg_t *vg, uint32_t new_size)return 1 ; } +int vg_set_max_lv (vg_t *vg,uint32_t max_lv) +{ +if (!(vg_status (vg) &RESIZEABLE_VG )) { +log_error ("Volume group \"%s\" must be resizeable " +"to change MaxLogicalVolume" , vg->name); +return 0 ; + } + +if (!(vg->fid->fmt->features &FMT_UNLIMITED_VOLS )) { +if (!max_lv) + max_lv =255 ; +else if (max_lv >255 ) { +log_error ("MaxLogicalVolume limit is 255" ); +return 0 ; + } + } + +if (max_lv && max_lv <vg_visible_lvs (vg)) { +log_error ("MaxLogicalVolume is less than the current number " +"%d of LVs for %s" ,vg_visible_lvs (vg), + vg->name); +return 0 ; + } + vg->max_lv = max_lv; + +return 1 ; +} +/* * Separate metadata areas after splitting a VG. * Also accepts orphan VG as destination (for vgreduce).
tools/vgchange.c +2 -23
@@ -293,32 +293,11 @@ static int _vgchange_logicalvolume(struct cmd_context *cmd, {uint32_t max_lv =arg_uint_value (cmd, logicalvolume_ARG,0 ); -if (!(vg_status (vg) &RESIZEABLE_VG )) { -log_error ("Volume group \"%s\" must be resizeable " -"to change MaxLogicalVolume" , vg->name); -return ECMD_FAILED ; - } - -if (!(vg->fid->fmt->features &FMT_UNLIMITED_VOLS )) { -if (!max_lv) - max_lv =255 ; -else if (max_lv >255 ) { -log_error ("MaxLogicalVolume limit is 255" ); -return ECMD_FAILED ; - } - } - -if (max_lv && max_lv <vg_visible_lvs (vg)) { -log_error ("MaxLogicalVolume is less than the current number " -"%d of LVs for %s" ,vg_visible_lvs (vg), - vg->name); -return ECMD_FAILED ; - } -if (!archive (vg))return ECMD_FAILED ; - vg->max_lv = max_lv; +if (!vg_set_max_lv (vg, max_lv)) +return ECMD_FAILED ;if (!vg_write (vg) || !vg_commit (vg))return ECMD_FAILED ;
Signature · 1 line
1.6.0.6
PATCH 7/9 Add vg_set_max_pv() liblvm function and move vgchange logic inside.
Add vg_set_max_pv() liblvm function and move vgchange logic inside.
--- lib/metadata/metadata-exported.h | 1 + lib/metadata/metadata.c | 27 +++++++++++++++++++++++++++ tools/vgchange.c | 25 ++----------------------- 3 files changed, 30 insertions(+), 23 deletions(-)
lib/metadata/metadata-exported.h +1 -0
@@ -436,6 +436,7 @@ int vg_rename(struct cmd_context *cmd, struct volume_group *vg,int vg_extend (struct volume_group *vg,int pv_count,char **pv_names);int vg_set_extent_size (vg_t *vg,uint32_t new_extent_size);int vg_set_max_lv (vg_t *vg,uint32_t max_lv); +int vg_set_max_pv (vg_t *vg,uint32_t max_pv);int vg_split_mdas (struct cmd_context *cmd,struct volume_group *vg_from,struct volume_group *vg_to);
lib/metadata/metadata.c +27 -0
@@ -797,6 +797,33 @@ int vg_set_max_lv(vg_t *vg, uint32_t max_lv)return 1 ; } +int vg_set_max_pv (vg_t *vg,uint32_t max_pv) +{ +if (!(vg_status (vg) &RESIZEABLE_VG )) { +log_error ("Volume group \"%s\" must be resizeable " +"to change MaxPhysicalVolumes" , vg->name); +return 0 ; + } + +if (!(vg->fid->fmt->features &FMT_UNLIMITED_VOLS )) { +if (!max_pv) + max_pv =255 ; +else if (max_pv >255 ) { +log_error ("MaxPhysicalVolume limit is 255" ); +return 0 ; + } + } + +if (max_pv && max_pv < vg->pv_count) { +log_error ("MaxPhysicalVolumes is less than the current number " +"%d of PVs for \"%s\"" , vg->pv_count, + vg->name); +return 0 ; + } + vg->max_pv = max_pv; +return 1 ; +} +/* * Separate metadata areas after splitting a VG. * Also accepts orphan VG as destination (for vgreduce).
tools/vgchange.c +2 -23
@@ -314,37 +314,16 @@ static int _vgchange_physicalvolumes(struct cmd_context *cmd, {uint32_t max_pv =arg_uint_value (cmd, maxphysicalvolumes_ARG,0 ); -if (!(vg_status (vg) &RESIZEABLE_VG )) { -log_error ("Volume group \"%s\" must be resizeable " -"to change MaxPhysicalVolumes" , vg->name); -return ECMD_FAILED ; - } -if (arg_sign_value (cmd, maxphysicalvolumes_ARG,0 ) ==SIGN_MINUS ) {log_error ("MaxPhysicalVolumes may not be negative" );return EINVALID_CMD_LINE ; } -if (!(vg->fid->fmt->features &FMT_UNLIMITED_VOLS )) { -if (!max_pv) - max_pv =255 ; -else if (max_pv >255 ) { -log_error ("MaxPhysicalVolume limit is 255" ); -return ECMD_FAILED ; - } - } - -if (max_pv && max_pv < vg->pv_count) { -log_error ("MaxPhysicalVolumes is less than the current number " -"%d of PVs for \"%s\"" , vg->pv_count, - vg->name); -return ECMD_FAILED ; - } -if (!archive (vg))return ECMD_FAILED ; - vg->max_pv = max_pv; +if (!vg_set_max_pv (vg, max_pv)) +return ECMD_FAILED ;if (!vg_write (vg) || !vg_commit (vg))return ECMD_FAILED ;
Signature · 1 line
1.6.0.6
PATCH 8/9 Add vg_set_alloc_policy() liblvm function and move vgchange logic inside.
Add vg_set_alloc_policy() liblvm function and move vgchange logic inside.
--- lib/metadata/metadata-exported.h | 1 + lib/metadata/metadata.c | 18 ++++++++++++++++++ tools/vgchange.c | 15 ++------------- 3 files changed, 21 insertions(+), 13 deletions(-)
lib/metadata/metadata-exported.h +1 -0
@@ -437,6 +437,7 @@ int vg_extend(struct volume_group *vg, int pv_count, char **pv_names);int vg_set_extent_size (vg_t *vg,uint32_t new_extent_size);int vg_set_max_lv (vg_t *vg,uint32_t max_lv);int vg_set_max_pv (vg_t *vg,uint32_t max_pv); +int vg_set_alloc_policy (vg_t *vg,alloc_policy_t alloc);int vg_split_mdas (struct cmd_context *cmd,struct volume_group *vg_from,struct volume_group *vg_to);
lib/metadata/metadata.c +18 -0
@@ -824,6 +824,24 @@ int vg_set_max_pv(vg_t *vg, uint32_t max_pv)return 1 ; } +int vg_set_alloc_policy (vg_t *vg,alloc_policy_t alloc) +{ +if (alloc ==ALLOC_INHERIT ) { +log_error ("Volume Group allocation policy cannot inherit " +"from anything" ); +return 0 ; + } + +if (alloc == vg->alloc) { +log_print ("Volume group allocation policy is already %s" , +get_alloc_string (vg->alloc)); +return 1 ; + } + vg->alloc = alloc; +return 1 ; +} + +/* * Separate metadata areas after splitting a VG. * Also accepts orphan VG as destination (for vgreduce).
tools/vgchange.c +2 -13
@@ -179,22 +179,11 @@ static int _vgchange_alloc(struct cmd_context *cmd, struct volume_group *vg) alloc =arg_uint_value (cmd, alloc_ARG,ALLOC_NORMAL ); -if (alloc ==ALLOC_INHERIT ) { -log_error ("Volume Group allocation policy cannot inherit " -"from anything" ); -return EINVALID_CMD_LINE ; - } - -if (alloc == vg->alloc) { -log_print ("Volume group allocation policy is already %s" , -get_alloc_string (vg->alloc)); -return ECMD_PROCESSED ; - } -if (!archive (vg))return ECMD_FAILED ; - vg->alloc = alloc; +if (!vg_set_alloc_policy (vg, alloc)) +return ECMD_FAILED ;if (!vg_write (vg) || !vg_commit (vg))return ECMD_FAILED ;
Signature · 1 line
1.6.0.6
PATCH 9/9 Change vg_create() to take only minimal parameters and obtain a lock.
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name); This is the first step towards the API called to create a VG. Call vg_lock_newname() inside this function. Use _vg_make_handle() where possible.
Now we have 2 ways to construct a volume group:
1) vg_read: Used when constructing an existing VG from disks
2) vg_create: Used when constructing a new VG
Both of these interfaces obtain a lock, and return a vg_t *. The usage of _vg_make_handle() inside vg_create() doesn't fit perfectly but it's ok for now. Needs some cleanup though and I've noted "FIXME" in the code.
Add the new vg_create() plus vg 'set' functions for non-default VG parameters in the following tools:
- vgcreate: Fairly straightforward refactoring. We just moved vg_lock_newname inside vg_create so we check the return via vg_read_error.
- vgsplit: The refactoring here is a bit more tricky. Originally we called vg_lock_newname and depending on the error code, we either read the existing vg or created the new one. Now vg_create() calls vg_lock_newname, so we first try to create the VG. If this fails with FAILED_EXIST, we can then do the vg_read. If the create succeeds, we check the input parameters and set any new values on the VG.
TODO in future patches:
1. The VG_ORPHAN lock needs some thought. We may want to treat this as any other VG, and require the application to obtain a handle and pass it to other API calls (for example, vg_extend). Or, we may find that hiding the VG_ORPHAN lock inside other APIs is the way to go. I thought of placing the VG_ORPHAN lock inside vg_create() and tying it to the vg handle, but was not certain this was the right approach.
2. Cleanup error paths. Integrate vg_read_error() with vg_create and vg_read* error codes and/or the new error APIs.
--- lib/metadata/metadata-exported.h | 5 +-- lib/metadata/metadata.c | 63 ++++++++++++++++++++++++------------- tools/vgcreate.c | 24 ++++++++------ tools/vgsplit.c | 36 ++++++++++++--------- 4 files changed, 77 insertions(+), 51 deletions(-)
lib/metadata/metadata-exported.h +1 -4
@@ -423,10 +423,7 @@ int pv_analyze(struct cmd_context *cmd, const char *pv_name,/* FIXME: move internal to library */ uint32_t pv_list_extents_free (const struct dm_list *pvh); -struct volume_group *vg_create (struct cmd_context *cmd,const char *name, -uint32_t extent_size,uint32_t max_pv, -uint32_t max_lv,alloc_policy_t alloc, -int pv_count,char **pv_names); +vg_t *vg_create (struct cmd_context *cmd,const char *vg_name);int vg_remove (struct volume_group *vg); int vg_remove_single(struct cmd_context *cmd, const char *vg_name, struct volume_group *vg,
lib/metadata/metadata.c +41 -22
106 lines not on this page · raw message
tools/vgcreate.c +14 -10
@@ -46,22 +46,26 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)if (validate_vg_create_params (cmd, &vp_new))return EINVALID_CMD_LINE ; +/* FIXME: orphan lock needs tied to vg handle or inside library call */ if (!lock_vol (cmd,VG_ORPHANS ,LCK_VG_WRITE )) {log_error ("Can't get lock for orphan PVs" );return ECMD_FAILED ; } -if (vg_lock_newname (cmd, vp_new.vg_name) !=SUCCESS ) { -log_error ("Can't get lock for %s" , vp_new.vg_name); -unlock_vg (cmd,VG_ORPHANS ); -return ECMD_FAILED ; - } -/* Create the new VG */ -if (!(vg =vg_create (cmd, vp_new.vg_name, vp_new.extent_size, - vp_new.max_pv, vp_new.max_lv, vp_new.alloc, - argc -1 , argv +1 ))) - goto bad; + vg =vg_create (cmd, vp_new.vg_name); +if (vg_read_error (vg)) + goto_bad; + +if (!vg_set_extent_size (vg, vp_new.extent_size) || + !vg_set_max_lv (vg, vp_new.max_lv) || + !vg_set_max_pv (vg, vp_new.max_pv) || + !vg_set_alloc_policy (vg, vp_new.alloc)) + goto_bad; + +/* attach the pv's */ +if (!vg_extend (vg, argc -1 , argv +1 )) + goto_bad;if (vp_new.max_lv != vg->max_lv) log_warn("WARNING: Setting maxlogicalvolumes to %d "
tools/vgsplit.c +21 -15
@@ -284,7 +284,6 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)int existing_vg =0 ;int r =ECMD_FAILED ;const char *lv_name; -uint32_t rc;if ((arg_count (cmd, name_ARG) + argc) <3 ) { log_error("Existing VG, new VG and either physical volumes "
@@ -322,24 +321,34 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)return ECMD_FAILED ; } +/* +* Set metadata format of original VG. +* NOTE: We must set the format before calling vg_create() +* since vg_create() calls the per-format constructor. +*/ + cmd->fmt = vg_from->fid->fmt; +log_verbose ("Checking for new volume group \"%s\"" , vg_name_to);/* -* Try to lock the name of the new VG. If we cannot reserve it, -* then we assume it exists, and we will not be holding a lock. -* We then try to read it - the vgsplit will be into an existing VG. +* First try to create a new VG. If we cannot create it, +* and we get FAILED_EXIST (we will not be holding a lock), +* a VG must already exist with this name. We then try to +* read the existing VG - the vgsplit will be into an existing VG. * * Otherwise, if the lock was successful, it must be the case that * we obtained a WRITE lock and could not find the vgname in the * system. Thus, the split will be into a new VG. */ - rc =vg_lock_newname (cmd, vg_name_to); -if (rc ==FAILED_LOCKING ) { + vg_to =vg_create (cmd, vg_name_to); +if (vg_read_error (vg_to) ==FAILED_LOCKING ) {log_error ("Can't get lock for %s" , vg_name_to); +vg_release (vg_to);unlock_and_release_vg (cmd, vg_from, vg_name_from);return ECMD_FAILED ; } -if (rc ==FAILED_EXIST ) { +if (vg_read_error (vg_to) ==FAILED_EXIST ) { existing_vg =1 ; +vg_release (vg_to); vg_to =vg_read_for_update (cmd, vg_name_to,NULL ,READ_REQUIRE_RESIZEABLE );
@@ -356,13 +365,9 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv) }if (!vgs_are_compatible (cmd, vg_from,vg_to)) goto_bad; - }else if (rc ==SUCCESS ) { + }else if (vg_read_error (vg_to) ==SUCCESS ) { existing_vg =0 ; -/* Set metadata format of original VG */ -/* FIXME: need some common logic */ - cmd->fmt = vg_from->fid->fmt; - vp_def.vg_name =NULL ; vp_def.extent_size = vg_from->extent_size; vp_def.max_pv = vg_from->max_pv;
@@ -380,9 +385,10 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv) goto bad; } -if (!(vg_to =vg_create (cmd, vg_name_to, vp_new.extent_size, - vp_new.max_pv, vp_new.max_lv, - vp_new.alloc,0 ,NULL ))) +if (!vg_set_extent_size (vg_to, vp_new.extent_size) || + !vg_set_max_lv (vg_to, vp_new.max_lv) || + !vg_set_max_pv (vg_to, vp_new.max_pv) || + !vg_set_alloc_policy (vg_to, vp_new.alloc)) goto_bad;if (vg_is_clustered (vg_from))
Signature · 1 line
1.6.0.6