summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Wysochanski <dwysocha@redhat.com>2009-09-02 21:27:22 +0000
committerDave Wysochanski <dwysocha@redhat.com>2009-09-02 21:27:22 +0000
commiteb7c87e90d410c523d09ac597ecfa4123005db8c (patch)
tree81695d5c733018b029ab7a74f3c65539cf7fb81f
parent392b1851732cfcbb79eaae8e0c6359b95f1cd139 (diff)
downloadlvm2-eb7c87e90d410c523d09ac597ecfa4123005db8c.tar.gz
lvm2-eb7c87e90d410c523d09ac597ecfa4123005db8c.tar.xz
lvm2-eb7c87e90d410c523d09ac597ecfa4123005db8c.zip
Refactor vgsplit - reorder _vgsplit_from and _vgsplit_to based on flag.
Slight functional change. If we open the destination first, we cannot know the 'fmt'. In this case we use the default metadata type unless the user has specified -M on the cmdline. If not, in most cases this is fine since we use the LVM2 default metadata type. However, if the user is specifying a non-default metadata type (e.g. lvm1) and the order of the names is such that we have to open the destination (vg_to) first, we have a problem. So in this case, we require the use of -M and vgsplit will fail with an error if not. I've updated the man page to recommend the usage of -M in this case. Author: Dave Wysochanski <dwysocha@redhat.com>
-rw-r--r--man/vgsplit.8.in4
-rw-r--r--tools/vgsplit.c48
2 files changed, 34 insertions, 18 deletions
diff --git a/man/vgsplit.8.in b/man/vgsplit.8.in
index 1f084deb..d44f8664 100644
--- a/man/vgsplit.8.in
+++ b/man/vgsplit.8.in
@@ -39,7 +39,9 @@ for the new volume group can be specified with \fB\-\-alloc\fR,
and \fB\-\-maxphysicalvolumes\fR (see \fBvgcreate(8)\fR for a description
of these options). If any of these options are not given, default
attribute(s) are taken from
-.I SourceVolumeGroupName\fP.
+.I SourceVolumeGroupName\fP. If a non-LVM2 metadata type (e.g. lvm1) is
+being used, you should use the -M option to specify the metadata type
+directly.
If
.I DestinationVolumeGroupName
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
index 7fe39e92..d4a7eed1 100644
--- a/tools/vgsplit.c
+++ b/tools/vgsplit.c
@@ -314,26 +314,40 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED;
}
- vg_from = _vgsplit_from(cmd, vg_name_from);
- if (!vg_from) {
- if (!lock_vg_from_first)
+ if (lock_vg_from_first) {
+ vg_from = _vgsplit_from(cmd, vg_name_from);
+ if (!vg_from)
+ 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;
+
+ vg_to = _vgsplit_to(cmd, vg_name_to, &existing_vg);
+ if (!vg_to) {
+ unlock_and_release_vg(cmd, vg_from, vg_name_from);
+ return ECMD_FAILED;
+ }
+ } else {
+ vg_to = _vgsplit_to(cmd, vg_name_to, &existing_vg);
+ if (!vg_to)
+ return ECMD_FAILED;
+ vg_from = _vgsplit_from(cmd, vg_name_from);
+ if (!vg_from) {
unlock_and_release_vg(cmd, vg_to, vg_name_to);
- 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;
+ return ECMD_FAILED;
+ }
- vg_to = _vgsplit_to(cmd, vg_name_to, &existing_vg);
- if (!vg_to) {
- if (lock_vg_from_first)
- unlock_and_release_vg(cmd, vg_from, vg_name_from);
- return ECMD_FAILED;
+ if (cmd->fmt != vg_from->fid->fmt) {
+ /* In this case we don't know the vg_from->fid->fmt */
+ log_error("Unable to set new VG metadata type based on "
+ "source VG format - use -M option.");
+ goto bad;
+ }
}
+
if (existing_vg) {
if (new_vg_option_specified(cmd)) {
log_error("Volume group \"%s\" exists, but new VG "