LVM2 lib/config/defaults.h lib/metadata/metada ...
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski at sourceware.org 2008-01-14 21:07:58
Modified files:
lib/config : defaults.h lib/metadata : metadata-exported.h metadata.c man : vgsplit.8 test : lvm-utils.sh t-vgcreate-usage.sh
t-vgsplit-operation.sh
tools : commands.h toollib.c toollib.h vgcreate.c
vgsplit.c
Log message:
Allow vgcreate options as input to vgsplit when new vg is split destination.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/config/defaults.h.diff?cvsroot=lvm2&r1=1.37&r2=1.38
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.31&r2=1.32
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.146&r2=1.147
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/man/vgsplit.8.diff?cvsroot=lvm2&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/lvm-utils.sh.diff?cvsroot=lvm2&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/t-vgcreate-usage.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/t-vgsplit-operation.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/commands.h.diff?cvsroot=lvm2&r1=1.105&r2=1.106
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.c.diff?cvsroot=lvm2&r1=1.123&r2=1.124
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.h.diff?cvsroot=lvm2&r1=1.54&r2=1.55
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgcreate.c.diff?cvsroot=lvm2&r1=1.53&r2=1.54
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgsplit.c.diff?cvsroot=lvm2&r1=1.43&r2=1.44
lib/config/defaults.h +2 -0
@@ -64,6 +64,8 @@#define DEFAULT_PVMETADATACOPIES 1#define DEFAULT_LABELSECTOR UINT64_C(1)#define DEFAULT_READ_AHEAD "auto" +#define DEFAULT_PE_SIZE 4096/* In KB */ +#define DEFAULT_MSG_PREFIX " "#define DEFAULT_CMD_NAME 0
lib/metadata/metadata-exported.h +12 -0
@@ -528,4 +528,16 @@uint32_t vg_status (const vg_t *vg); +struct vgcreate_params { +char *vg_name; +uint32_t extent_size; +size_t max_pv; +size_t max_lv; +alloc_policy_t alloc; +int clustered;/* FIXME: put this into a 'status' variable instead? */ +}; + +int validate_vg_create_params (struct cmd_context *cmd, +struct vgcreate_params *vp); +#endif
lib/metadata/metadata.c +39 -0
@@ -378,6 +378,45 @@return vg_name; } +/* +* Validate parameters to vg_create() before calling. +* FIXME: move this inside the library, maybe inside vg_create +* - TODO: resolve error codes +*/ +int validate_vg_create_params (struct cmd_context *cmd, +struct vgcreate_params *vp) +{ +if (!validate_new_vg_name (cmd, vp->vg_name)) { +log_error ("New volume group name \"%s\" is invalid" , + vp->vg_name); +return 1 ; + } + +if (vp->alloc ==ALLOC_INHERIT ) { +log_error ("Volume Group allocation policy cannot inherit " +"from anything" ); +return 1 ; + } + +if (!vp->extent_size) { +log_error ("Physical extent size may not be zero" ); +return 1 ; + } + +if (!(cmd->fmt->features &FMT_UNLIMITED_VOLS )) { +if (!vp->max_lv) + vp->max_lv =255 ; +if (!vp->max_pv) + vp->max_pv =255 ; +if (vp->max_lv >255 || vp->max_pv >255 ) { +log_error ("Number of volumes may not exceed 255" ); +return 1 ; + } + } + +return 0 ; +} + struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name, uint32_t extent_size, uint32_t max_pv, uint32_t max_lv, alloc_policy_t alloc,
man/vgsplit.8 +17 -7
@@ -3,13 +3,23 @@ vgsplit \- split a volume group into two .SH SYNOPSIS .B vgsplit -[\-A/\-\-autobackup y/n] -[\-d/\-\-debug] -[\-h/\-?/\-\-help] -[\-l/\-\-list] -[\-M/\-\-metadatatype 1/2] -[\-t/\-\-test] -[\-v/\-\-verbose] +.RB [ \-\-alloc +.IR AllocationPolicy ] +.RB [ \-A | \-\-autobackup " {" y | n }] +.RB [ \-c | \-\-clustered " {" y | n }] +.RB [ \-d | \-\-debug ] +.RB [ \-h | \-\-help ] +.RB [ \-l | \-\-list ] +.RB [ \-\-maxlogicalvolumes +.IR MaxLogicalVolumes ] +.RB [ -M | \-\-metadatatype +.IR type ] +.RB [ -p | \-\-maxphysicalvolumes +.IR MaxPhysicalVolumes ] +.RB [ \-s | \-\-physicalextentsize +.IR PhysicalExtentSize [ \fBkKmMgGtT\fR ]] +.RB [ \-t | \-\-test ] +.RB [ \-v | \-\-verbose ] SourceVolumeGroupName DestinationVolumeGroupName PhysicalVolumePath [PhysicalVolumePath...] .SH DESCRIPTION
test/lvm-utils.sh +5 -0
@@ -50,6 +50,11 @@ return 0; } +check_vg_field_() +{ + return $(test $(vgs --noheadings -o $2 $1) == $3) +} + check_pv_size_() { return $(test $(pvs --noheadings -o pv_free $1) == $2)
test/t-vgcreate-usage.sh +23 -5
@@ -31,6 +31,24 @@ lv=vgcreate-usage-$$ test_expect_success \ + 'vgcreate accepts 8.00M physicalextentsize for VG' \ + 'vgcreate $vg --physicalextentsize 8.00M $d1 $d2 && + check_vg_field_ $vg vg_extent_size 8.00M && + vgremove $vg' + +test_expect_success \ + 'vgcreate accepts smaller (128) maxlogicalvolumes for VG' \ + 'vgcreate $vg --maxlogicalvolumes 128 $d1 $d2 && + check_vg_field_ $vg max_lv 128 && + vgremove $vg' + +test_expect_success \ + 'vgcreate accepts smaller (128) maxphysicalvolumes for VG' \ + 'vgcreate $vg --maxphysicalvolumes 128 $d1 $d2 && + check_vg_field_ $vg max_pv 128 && + vgremove $vg' + +test_expect_success \ 'vgcreate rejects a zero physical extent size' \ 'vgcreate --physicalextentsize 0 $vg $d1 $d2 2>err; status=$?; echo status=$?; test $status = 3 &&
@@ -50,14 +68,14 @@ test_expect_success \ 'vgcreate rejects vgname greater than 128 characters' \ - 'vg=thisnameisridiculouslylongtotestvalidationcodecheckingmaximumsizethisiswhathappenswhenprogrammersgetboredandorarenotcreativedonttrythisathome; - vgcreate $vg $d1 $d2 2>err; + 'vginvalid=thisnameisridiculouslylongtotestvalidationcodecheckingmaximumsizethisiswhathappenswhenprogrammersgetboredandorarenotcreativedonttrythisathome; + vgcreate $vginvalid $d1 $d2 2>err; status=$?; echo status=$?; test $status = 3 && - grep "New volume group name \"$vg\" is invalid\$" err' + grep "New volume group name \"$vginvalid\" is invalid\$" err' test_expect_success \ - 'vgcreate rejects already existing vgname "/dev/fd0"' \ - 'vg=/dev/fd0; vgcreate $vg $d1 $d2 2>err; + 'vgcreate rejects already existing vgname "/tmp/$vg"' \ + 'touch /tmp/$vg; vgcreate $vg $d1 $d2 2>err; status=$?; echo status=$?; test $status = 3 && grep "New volume group name \"$vg\" is invalid\$" err'
test/t-vgsplit-operation.sh +30 -0
@@ -48,6 +48,36 @@ vgremove $vg1 && vgremove $vg2' +#test_expect_success \ +# 'vgcreate accepts 8.00M physicalextentsize for VG' \ +# 'vgcreate $vg --physicalextentsize 8.00M $d1 $d2 && +# check_vg_field_ $vg vg_extent_size 8.00M && +# vgremove $vg' + +test_expect_success \ + 'vgsplit accepts 8.00M physicalextentsize for new VG' \ + 'vgcreate $vg1 $d1 $d2 && + vgsplit --physicalextentsize 8.00M $vg1 $vg2 $d1 && + check_vg_field_ $vg2 vg_extent_size 8.00M && + vgremove $vg1 && + vgremove $vg2' + +test_expect_success \ + 'vgsplit accepts --maxphysicalvolumes 128 on new VG' \ + 'vgcreate $vg1 $d1 $d2 && + vgsplit --maxphysicalvolumes 128 $vg1 $vg2 $d1 && + check_vg_field_ $vg2 max_pv 128 && + vgremove $vg1 && + vgremove $vg2' + +test_expect_success \ + 'vgsplit accepts --maxlogicalvolumes 128 on new VG' \ + 'vgcreate $vg1 $d1 $d2 && + vgsplit --maxlogicalvolumes 128 $vg1 $vg2 $d1 && + check_vg_field_ $vg2 max_lv 128 && + vgremove $vg1 && + vgremove $vg2' + test_done # Local Variables: # indent-tabs-mode: nil
tools/commands.h +9 -2
@@ -874,17 +874,24 @@"Move physical volumes into a new volume group" ,"vgsplit " "\n" "\t[-A|--autobackup {y|n}] " "\n" +"\t[--alloc AllocationPolicy] " "\n" +"\t[-c|--clustered {y|n}] " "\n" "\t[-d|--debug] " "\n" "\t[-h|--help] " "\n" "\t[-l|--list]" "\n" +"\t[-l|--maxlogicalvolumes MaxLogicalVolumes]" "\n" "\t[-M|--metadatatype 1|2] " "\n" +"\t[-p|--maxphysicalvolumes MaxPhysicalVolumes] " "\n" +"\t[-s|--physicalextentsize PhysicalExtentSize[kKmMgGtTpPeE]] " "\n" "\t[-t|--test] " "\n" "\t[-v|--verbose] " "\n" "\t[--version]" "\n" - "\tExistingVolumeGroupName NewVolumeGroupName" "\n" +"\tSourceVolumeGroupName DestinationVolumeGroupName" "\n" "\tPhysicalVolumePath [PhysicalVolumePath...]\n" , - autobackup_ARG, list_ARG, metadatatype_ARG, test_ARG) + alloc_ARG, autobackup_ARG, clustered_ARG, list_ARG, + maxlogicalvolumes_ARG, maxphysicalvolumes_ARG, + metadatatype_ARG, physicalextentsize_ARG, test_ARG) xx(version, "Display software and driver version information",
tools/toollib.c +46 -0
49 lines not on this page · raw message
tools/toollib.h +2 -0
@@ -98,4 +98,6 @@int validate_new_vg_name (struct cmd_context *cmd,const char *vg_name); +int fill_vg_create_params (struct cmd_context *cmd, +char *vg_name,struct vgcreate_params *vp);#endif
tools/vgcreate.c +15 -84
157 lines not on this page · raw message
tools/vgsplit.c +11 -3
@@ -212,6 +212,7 @@int vgsplit (struct cmd_context *cmd,int argc,char **argv) { +struct vgcreate_params vp;char *vg_name_from, *vg_name_to;struct volume_group *vg_to, *vg_from;int opt;
@@ -259,11 +260,18 @@/* FIXME: need some common logic */ cmd->fmt = vg_from->fid->fmt; +/* FIXME: original code took defaults from vg_from */ +if (fill_vg_create_params (cmd, vg_name_to, &vp)) +return EINVALID_CMD_LINE ; + +if (validate_vg_create_params (cmd, &vp)) +return EINVALID_CMD_LINE ; +/* Create new VG structure */ /* FIXME: allow user input same params as to vgcreate tool */ -if (!(vg_to =vg_create (cmd, vg_name_to, vg_from->extent_size, - vg_from->max_pv, vg_from->max_lv, - vg_from->alloc,0 ,NULL ))) +if (!(vg_to =vg_create (cmd, vg_name_to, vp.extent_size, + vp.max_pv, vp.max_lv, + vp.alloc,0 ,NULL ))) goto error;if (vg_from->status &CLUSTERED )