Add implicit pvcreate to vgcreate and vgextend
cover Add implicit pvcreate to vgcreate and vgextend
The following 8 patches add implicit pvcreate support to vgcreate and vgextend. This series is a rebase + improvements of a prior series submitted last November:
http://www.redhat.com/archives/lvm-devel/2008-November/msg00072.html
This series does not address all the prior feedback but it does work. Addressing the feedback will require further patches and refactoring.
Passes test suite and applies cleanly on top of:
commit 02f858e5c9843996591e87dfa60319d470365589
Author: Dave Wysochanski <[email protected]> Date: Wed Jul 22 03:13:57 2009 +0000
Update test/api/vgtest.c to use lvm_errno and lvm_errmsg.
PATCH 1/8 Remove unneeded pv_create wrapper function.
--- lib/metadata/metadata.c | 73 +++++++++++++++-------------------------------- 1 files changed, 23 insertions(+), 50 deletions(-)
lib/metadata/metadata.c +23 -50
@@ -44,16 +44,6 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd,uint64_t *label_sector, int warnings, int scan_label_only); -static struct physical_volume *_pv_create (const struct format_type *fmt, -struct device *dev, -struct id *id,uint64_t size, -unsigned long data_alignment, -uint64_t pe_start, -uint32_t existing_extent_count, -uint32_t existing_extent_size, -int pvmetadatacopies, -uint64_t pvmetadatasize,struct dm_list *mdas); -static int _pv_write (struct cmd_context *cmd __attribute((unused)),struct physical_volume *pv,struct dm_list *mdas,int64_t label_sector);
@@ -972,44 +962,6 @@ int vg_split_mdas(struct cmd_context *cmd __attribute((unused)),return 1 ; } -/** -* pv_create - initialize a physical volume for use with a volume group -* @fmt: format type -* @dev: PV device to initialize -* @id: PV UUID to use for initialization -* @size: size of the PV in sectors -* @data_alignment: requested alignment of data -* @pe_start: physical extent start -* @existing_extent_count -* @existing_extent_size -* @pvmetadatacopies -* @pvmetadatasize -* @mdas -* -* Returns: -* PV handle - physical volume initialized successfully -* NULL - invalid parameter or problem initializing the physical volume -* -* Note: -* FIXME - liblvm todo - tidy up arguments for external use (fmt, mdas, etc) -*/ -pv_t *pv_create (const struct cmd_context *cmd, -struct device *dev, -struct id *id,uint64_t size, -unsigned long data_alignment, -uint64_t pe_start, -uint32_t existing_extent_count, -uint32_t existing_extent_size, -int pvmetadatacopies, -uint64_t pvmetadatasize,struct dm_list *mdas) -{ -return _pv_create (cmd->fmt, dev, id, size, data_alignment, pe_start, - existing_extent_count, - existing_extent_size, - pvmetadatacopies, - pvmetadatasize, mdas); -} -static void _free_pv (struct dm_pool *mem,struct physical_volume *pv) {dm_pool_free (mem, pv);
@@ -1043,8 +995,28 @@ static struct physical_volume *_alloc_pv(struct dm_pool *mem, struct device *devreturn pv; } -/* Sizes in sectors */ -static struct physical_volume *_pv_create(const struct format_type *fmt, +/** +* pv_create - initialize a physical volume for use with a volume group +* +* @fmt: format type +* @dev: PV device to initialize +* @size: size of the PV in sectors +* @data_alignment: requested alignment of data +* @pe_start: physical extent start +* @existing_extent_count +* @existing_extent_size +* @pvmetadatacopies +* @pvmetadatasize +* @mdas +* +* Returns: +* PV handle - physical volume initialized successfully +* NULL - invalid parameter or problem initializing the physical volume +* +* Note: +* FIXME: shorten argument list and replace with explict 'set' functions +*/ +struct physical_volume *pv_create(const struct cmd_context *cmd, struct device *dev, struct id *id, uint64_t size, unsigned long data_alignment,
@@ -1054,6 +1026,7 @@ static struct physical_volume *_pv_create(const struct format_type *fmt,int pvmetadatacopies, uint64_t pvmetadatasize, struct dm_list *mdas) { + const struct format_type *fmt = cmd->fmt;struct dm_pool *mem = fmt->cmd->mem;struct physical_volume *pv =_alloc_pv (mem, dev);
Signature · 1 line
1.6.0.6
PATCH 2/8 Move bulk of pvcreate logic into library.
In preparation for implicit pvcreate during vgcreate / vgextend, move bulk of pvcreate logic inside library.
--- lib/metadata/metadata-exported.h | 19 +++ lib/metadata/metadata.c | 220 +++++++++++++++++++++++++++++++++++ tools/pvcreate.c | 239 +------------------------------------- 3 files changed, 240 insertions(+), 238 deletions(-)
lib/metadata/metadata-exported.h +19 -0
@@ -337,6 +337,25 @@ struct lv_list {struct logical_volume *lv; }; +struct pvcreate_params { +int zero; +uint64_t size; +uint64_t data_alignment; +int pvmetadatacopies; +uint64_t pvmetadatasize; +int64_t labelsector; +struct id id;/* FIXME: redundant */ +struct id *idp;/* 0 if no --uuid option */ +uint64_t pe_start; +uint32_t extent_count; +uint32_t extent_size; +const char *restorefile;/* 0 if no --restorefile option */ +force_t force; +unsigned yes; +}; + +int pvcreate_single (struct cmd_context *cmd,const char *pv_name,void *handle); +/* * Utility functions */
lib/metadata/metadata.c +220 -0
238 lines not on this page · raw message
tools/pvcreate.c +1 -238
245 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 3/8 Allow pvcreate_single to be called with NULL for default pvcreate params.
Passing NULL for pvcreate parameters gives you default parameters for pvcreate_single.
--- lib/metadata/metadata.c | 27 ++++++++++++++++++++++++++- 1 files changed, 26 insertions(+), 1 deletions(-)
lib/metadata/metadata.c +26 -1
@@ -1097,12 +1097,37 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,return 1 ; } +static void fill_default_pvcreate_params (struct pvcreate_params *pp) +{ +memset (pp,0 ,sizeof (*pp)); + pp->zero =0 ; + pp->size =0 ; + pp->data_alignment =UINT64_C (0 ); + pp->pvmetadatacopies =DEFAULT_PVMETADATACOPIES ; + pp->pvmetadatasize =DEFAULT_PVMETADATASIZE ; + pp->labelsector =DEFAULT_LABELSECTOR ; + pp->idp =0 ; + pp->pe_start =0 ; + pp->extent_count =0 ; + pp->extent_size =0 ; + pp->restorefile =0 ; + pp->force =PROMPT ; + pp->yes =0 ; +} +int pvcreate_single (struct cmd_context *cmd,const char *pv_name,void *handle) { -struct pvcreate_params *pp = (struct pvcreate_params *) handle; +struct pvcreate_params *pp;void *pv;struct device *dev;struct dm_list mdas; +struct pvcreate_params default_pp; + +fill_default_pvcreate_params (&default_pp); +if (!handle) + pp = &default_pp; +else + pp = (struct pvcreate_params *) handle;if (pp->idp) { if ((dev = device_from_pvid(cmd, pp->idp)) &&
Signature · 1 line
1.6.0.6
PATCH 4/8 Change pvcreate_single to return pv_t and update function description.
--- lib/metadata/metadata-exported.h | 3 ++- lib/metadata/metadata.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-)
lib/metadata/metadata-exported.h +2 -1
@@ -354,7 +354,8 @@ struct pvcreate_params {unsigned yes; }; -int pvcreate_single (struct cmd_context *cmd,const char *pv_name,void *handle); +pv_t *pvcreate_single (struct cmd_context *cmd,const char *pv_name, +void *handle);/* * Utility functions
lib/metadata/metadata.c +17 -5
@@ -1115,7 +1115,19 @@ static void fill_default_pvcreate_params(struct pvcreate_params *pp) pp->yes =0 ; } -int pvcreate_single (struct cmd_context *cmd,const char *pv_name,void *handle) +/* +* pvcreate_single() - initialize a device with PV label and metadata +* +* Parameters: +* - pv_name: device path to initialize +* - handle: options to pass to pv_create; NULL indicates use defaults +* +* Returns: +* NULL: error +* pv_t * (non-NULL): handle to physical volume created +*/ +pv_t *pvcreate_single (struct cmd_context *cmd,const char *pv_name, +void *handle) {struct pvcreate_params *pp;void *pv;
@@ -1134,13 +1146,13 @@ int pvcreate_single(struct cmd_context *cmd, const char *pv_name, void *handle) (dev != dev_cache_get(pv_name, cmd->filter))) {log_error ("uuid %s already in use on \"%s\"" , pp->idp->uuid,dev_name (dev)); -return 0 ; +return NULL ; } }if (!lock_vol (cmd,VG_ORPHANS ,LCK_VG_WRITE )) {log_error ("Can't get lock for orphan PVs" ); -return 0 ; +return NULL ; }if (!pvcreate_check (cmd, pv_name, pp))
@@ -1200,11 +1212,11 @@ int pvcreate_single(struct cmd_context *cmd, const char *pv_name, void *handle)log_print ("Physical volume \"%s\" successfully created" , pv_name);unlock_vg (cmd,VG_ORPHANS ); -return 1 ; +return pv; error:unlock_vg (cmd,VG_ORPHANS ); -return 0 ; +return NULL ; }static void _free_pv (struct dm_pool *mem,struct physical_volume *pv)
Signature · 1 line
1.6.0.6
PATCH 5/8 Update vgcreate and vgextend to allow uninitialized devices as input.
Note that this changes the behavior of vgcreate and vgextend when non-PV devices are given. Previously this would result in vgextend or vgcreate printing an error message and exiting. Now these tools will implicitly pvcreate on any devices given on the commandline that are not already PVs. All devices given on the commandline are first checked if they are an existing PV before attempting to initialize, so there should be little/no risk with this change.
Add pvcreate_devices() helper function that loops through a set of device names and runs pvcreate_single on each device if it is not already a PV. Note - pvcreate_devices calls pvcreate_single. Currently the ORPHAN lock must be held prior to calling pvcreate_single. In the future, pvcreate_single should be further refactored but for now we leave this as is.
With this update, the user may opt to skip pvcreate, provided the default values of pvcreate are adequate. If the user wants some non-default value in the PV (e.g. 0 metadatacopies, etc), pvcreate must be used prior to vgcreate/vgextend.
--- lib/metadata/metadata.c | 40 +++++++++++++++++++++++++++++++++------- tools/pvcreate.c | 10 +++++++++- 2 files changed, 42 insertions(+), 8 deletions(-)
lib/metadata/metadata.c +33 -7
@@ -67,6 +67,9 @@ static uint32_t _vg_bad_status_bits(const struct volume_group *vg,const char _really_init[] ="Really INITIALIZE physical volume \"%s\" of volume group \"%s\" [y/n]? " ; +static int pvcreate_devices (struct cmd_context *cmd, +int pv_count,char **pv_names); +unsigned long set_pe_align (struct physical_volume *pv,unsigned long data_alignment) {if (pv->pe_align)
@@ -517,6 +520,9 @@ int vg_extend(struct volume_group *vg, int pv_count, char **pv_names)return 0 ; } +if (!pvcreate_devices (cmd, pv_count, pv_names)) +return 0 ; +/* attach each pv */ for (i =0 ; i < pv_count; i++) {if (!(pv =pv_by_path (vg->fid->fmt->cmd, pv_names[i]))) {
@@ -1097,6 +1103,30 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,return 1 ; } +/* +* Run pvcreate on a set of devices if they are not currently initialized. +*/ +static int pvcreate_devices (struct cmd_context *cmd, +int pv_count,char **pv_names) +{ +int i; +pv_t *pv; + +for (i =0 ; i < pv_count; i++) { +if (!(pv =pv_by_path (cmd, pv_names[i]))) { +log_verbose ("Running pvcreate on %s" , pv_names[i]); +if (!pvcreate_single (cmd, pv_names[i],NULL )) { +log_error ("Failed to setup physical " +"volume \"%s\"" , + pv_names[i]); +return 0 ; + } + } + } + +return 1 ; +} +static void fill_default_pvcreate_params (struct pvcreate_params *pp) {memset (pp,0 ,sizeof (*pp));
@@ -1118,6 +1148,9 @@ static void fill_default_pvcreate_params(struct pvcreate_params *pp)/* * pvcreate_single() - initialize a device with PV label and metadata * +* NOTE: Assumes ORPHAN_LOCK held by caller. +* FIXME: Refactor to do simple pv_create + 'set' calls +* * Parameters: * - pv_name: device path to initialize * - handle: options to pass to pv_create; NULL indicates use defaults
@@ -1150,11 +1183,6 @@ pv_t * pvcreate_single(struct cmd_context *cmd, const char *pv_name, } } -if (!lock_vol (cmd,VG_ORPHANS ,LCK_VG_WRITE )) { -log_error ("Can't get lock for orphan PVs" ); -return NULL ; - } -if (!pvcreate_check (cmd, pv_name, pp)) goto error;
@@ -1211,11 +1239,9 @@ pv_t * pvcreate_single(struct cmd_context *cmd, const char *pv_name,log_print ("Physical volume \"%s\" successfully created" , pv_name); -unlock_vg (cmd,VG_ORPHANS );return pv; error: -unlock_vg (cmd,VG_ORPHANS );return NULL ; }
tools/pvcreate.c +9 -1
@@ -170,13 +170,21 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)return EINVALID_CMD_LINE ; } +if (!lock_vol (cmd,VG_ORPHANS ,LCK_VG_WRITE )) { +log_error ("Can't get lock for orphan PVs" ); +return ECMD_FAILED ; + } +for (i =0 ; i < argc; i++) {if (!pvcreate_single (cmd, argv[i], &pp)) ret =ECMD_FAILED ; -if (sigint_caught ()) +if (sigint_caught ()) { +unlock_vg (cmd,VG_ORPHANS );return ret; + } } +unlock_vg (cmd,VG_ORPHANS );return ret; }
Signature · 1 line
1.6.0.6
PATCH 6/8 Update vgcreate and vgextend man pages to clarify implicit pvcreate.
vgcreate and vgextend now implicitly call pvcreate on devices not currently initialized for LVM use. Previously these commands would fail with an error, so clarify the new behavior in the man page.
--- man/vgcreate.8.in | 14 ++++++++------ man/vgextend.8.in | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-)
man/vgcreate.8.in +8 -6
@@ -21,16 +21,18 @@ vgcreate \- create a volume group .RB [ \-t | \-\-test ] .RB [ \-v | \-\-verbose ] .RB [ \-\-version ] -.I VolumeGroupName PhysicalVolumePath -.RI [ PhysicalVolumePath ...] +.I VolumeGroupName PhysicalDevicePath +.RI [ PhysicalDevicePath ...] .SH DESCRIPTION .B vgcreate creates a new volume group called .I VolumeGroupName -using the block special device -.IR PhysicalVolumePath -previously configured for LVM with -.BR pvcreate (8). +using the block special device \fIPhysicalDevicePath\fP. +If \fIPhysicalDevicePath\fP was not previously configured for LVM with +\fBpvcreate (8)\fP, the device will be initialized with the same +default values used with \fBpvcreate\fP. If non-default +\fPpvcreate\fP values are are desired, \fBpvcreate\fP should be explicitly +called prior to calling \fBvgcreate\fP. .SH OPTIONS See \fBlvm\fP for common options. .TP
man/vgextend.8.in +5 -0
@@ -11,6 +11,11 @@ VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...] vgextend allows you to add one or more initialized physical volumes ( see .B pvcreate(8) ) to an existing volume group to extend it in size. +If \fIPhysicalDevicePath\fP was not previously configured for LVM with +\fBpvcreate (8)\fP, the device will be initialized with the same +default values used with \fBpvcreate\fP. If non-default +\fPpvcreate\fP values are are desired, \fBpvcreate\fP should be explicitly +called prior to calling \fBvgcreate\fP. .SH OPTIONS See \fBlvm\fP for common options. .SH Examples
Signature · 1 line
1.6.0.6
PATCH 7/8 Add metadatatype arg to vgextend.
If any devices need an implicit pvcreate, we must know the metadata type.
--- man/vgextend.8.in | 1 + tools/commands.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletions(-)
man/vgextend.8.in +1 -0
@@ -4,6 +4,7 @@ vgextend \- add physical volumes to a volume group .SH SYNOPSIS .B vgextend [\-A|\-\-autobackup y|n] [\-d|\-\-debug] [\-h|\-?|\-\-help] +[\-M|\-\-metadatatype type] [\-t|\-\-test] [\-v|\-\-verbose] VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
tools/commands.h +2 -1
@@ -800,12 +800,13 @@ xx(vgextend, "\t[-A|--autobackup y|n]\n" "\t[-d|--debug]\n" "\t[-h|--help]\n" + "\t[-M|--metadatatype 1|2]" "\n" "\t[-t|--test]\n" "\t[-v|--verbose]\n" "\t[--version]" "\n" "\tVolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]\n", - autobackup_ARG, test_ARG) + autobackup_ARG, metadatatype_ARG, test_ARG) xx(vgimport, "Register exported volume group with system",
Signature · 1 line
1.6.0.6
PATCH 8/8 Add implicit tests for implicit pvcreate during vgcreate and vgextend.
--- test/t-vgcreate-usage.sh | 4 ++++ test/t-vgextend-usage.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-) create mode 100644 test/t-vgextend-usage.sh
test/t-vgcreate-usage.sh +4 -0
@@ -87,3 +87,7 @@ check_vg_field_ $vg max_lv 0 check_vg_field_ $vg max_pv 0 check_vg_field_ $vg vg_attr "wz--n-" vgremove -ff $vg + +# Test implicit pvcreate +pvremove $dev1 $dev2 +vgcreate $vg $dev1 $dev2
test/t-vgextend-usage.sh new file +34 -0
@@ -0,0 +1,34 @@ +# Copyright (C) 2008 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions +# of the GNU General Public License v.2. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# +# Exercise various vgextend commands +# + +. ./test-utils.sh + +aux prepare_devs 5 + +for mdatype in 1 2 +do + +# Explicit pvcreate +pvcreate -M$mdatype $dev1 $dev2 $dev3 $dev4 $dev5 +vgcreate -M$mdatype $vg1 $dev1 $dev2 +vgextend $vg1 $dev3 $dev4 $dev5 +vgremove -ff $vg1 + +# Implicit pvcreate +pvremove $dev1 $dev2 $dev3 $dev4 $dev5 +vgcreate -M$mdatype $vg1 $dev1 $dev2 +vgextend -M$mdatype $vg1 $dev3 $dev4 $dev5 +vgremove -ff $vg1 +pvremove $dev1 $dev2 $dev3 $dev4 $dev5 +done
Signature · 1 line
1.6.0.6