public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2 lib/metadata/metadata.c tools/pvcreate.c
@ 2009-07-26  1:54 wysochanski
  0 siblings, 0 replies; 2+ messages in thread
From: wysochanski @ 2009-07-26  1:54 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2009-07-26 01:54:20

Modified files:
	lib/metadata   : metadata.c 
	tools          : pvcreate.c 

Log message:
	Move ORPHAN_VG lock outside pvcreate_single.
	
	The implicit pvcreate require either moving the ORPHAN_VG lock outside
	pvcreate_single or somehow having the function know or detect whether
	the ORPHAN_VG lock is already held.
	
	Author: Dave Wysochanski <dwysocha@redhat.com>

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.264&r2=1.265
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.82&r2=1.83

--- LVM2/lib/metadata/metadata.c	2009/07/26 01:53:57	1.264
+++ LVM2/lib/metadata/metadata.c	2009/07/26 01:54:20	1.265
@@ -1142,11 +1142,6 @@
 		}
 	}
 
-	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;
 
@@ -1203,11 +1198,9 @@
 
 	log_print("Physical volume \"%s\" successfully created", pv_name);
 
-	unlock_vg(cmd, VG_ORPHANS);
 	return pv;
 
       error:
-	unlock_vg(cmd, VG_ORPHANS);
 	return NULL;
 }
 
--- LVM2/tools/pvcreate.c	2009/07/26 01:53:09	1.82
+++ LVM2/tools/pvcreate.c	2009/07/26 01:54:20	1.83
@@ -171,9 +171,15 @@
 	}
 
 	for (i = 0; i < argc; i++) {
+		if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
+			log_error("Can't get lock for orphan PVs");
+			return ECMD_FAILED;
+		}
+
 		if (!pvcreate_single(cmd, argv[i], &pp))
 			ret = ECMD_FAILED;
 
+		unlock_vg(cmd, VG_ORPHANS);
 		if (sigint_caught())
 			return ret;
 	}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* LVM2 lib/metadata/metadata.c tools/pvcreate.c
@ 2009-10-05 20:03 wysochanski
  0 siblings, 0 replies; 2+ messages in thread
From: wysochanski @ 2009-10-05 20:03 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2009-10-05 20:03:25

Modified files:
	lib/metadata   : metadata.c 
	tools          : pvcreate.c 

Log message:
	Refactor pvcreate - split pvcreate_validate_params into recovery/non-recovery.
	
	Split pvcreate_validate_params into recovery and non-recovery parameters.
	This is necessary so we can call the non-recovery validate function from
	vgextend / vgcreate.  Note in the pvcreate tool case, we must call the
	recovery validation function first (see treatment of pe_start and --zero),
	and that we add a call to fill_default_pvcreate_params before the validation
	functions.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.288&r2=1.289
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.85&r2=1.86

--- LVM2/lib/metadata/metadata.c	2009/10/05 20:03:08	1.288
+++ LVM2/lib/metadata/metadata.c	2009/10/05 20:03:25	1.289
@@ -1275,7 +1275,7 @@
 void fill_default_pvcreate_params(struct pvcreate_params *pp)
 {
 	memset(pp, 0, sizeof(*pp));
-	pp->zero = 0;
+	pp->zero = 1;
 	pp->size = 0;
 	pp->data_alignment = UINT64_C(0);
 	pp->data_alignment_offset = UINT64_C(0);
--- LVM2/tools/pvcreate.c	2009/09/14 22:47:49	1.85
+++ LVM2/tools/pvcreate.c	2009/10/05 20:03:25	1.86
@@ -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) 2004-2009 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
@@ -17,29 +17,20 @@
 #include "metadata-exported.h"
 
 /*
- * Intial sanity checking of command-line arguments and fill in 'pp' fields.
- *
- * Input arguments:
- * cmd, argc, argv
+ * Intial sanity checking of recovery-related command-line arguments.
+ * These args are: --restorefile, --uuid, and --physicalvolumesize
  *
  * Output arguments:
  * pp: structure allocated by caller, fields written / validated here
  */
-static int pvcreate_validate_params(struct cmd_context *cmd,
-				    int argc, char **argv,
-				    struct pvcreate_params *pp)
+static int pvcreate_validate_restore_params(struct cmd_context *cmd,
+					    int argc, char **argv,
+					    struct pvcreate_params *pp)
 {
 	const char *uuid = NULL;
 	void *existing_pv;
 	struct volume_group *vg;
 
-	memset(pp, 0, sizeof(*pp));
-
-	if (!argc) {
-		log_error("Please enter a physical volume path");
-		return 0;
-	}
-
 	if (arg_count(cmd, restorefile_ARG) && !arg_count(cmd, uuidstr_ARG)) {
 		log_error("--uuid is required with --restorefile");
 		return 0;
@@ -76,6 +67,32 @@
 		vg_release(vg);
 	}
 
+	if (arg_sign_value(cmd, physicalvolumesize_ARG, 0) == SIGN_MINUS) {
+		log_error("Physical volume size may not be negative");
+		return 0;
+	}
+	pp->size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0));
+
+	if (arg_count(cmd, restorefile_ARG) || arg_count(cmd, uuidstr_ARG))
+		pp->zero = 0;
+	return 1;
+}
+
+/*
+ * Intial sanity checking of non-recovery related command-line arguments.
+ *
+ * Output arguments:
+ * pp: structure allocated by caller, fields written / validated here
+ */
+static int pvcreate_validate_params(struct cmd_context *cmd,
+				    int argc, char **argv,
+				    struct pvcreate_params *pp)
+{
+	if (!argc) {
+		log_error("Please enter a physical volume path");
+		return 0;
+	}
+
 	if (arg_count(cmd, yes_ARG) && !arg_count(cmd, force_ARG)) {
 		log_error("Option y can only be given with option f");
 		return 0;
@@ -111,16 +128,6 @@
 
 	if (arg_count(cmd, zero_ARG))
 		pp->zero = strcmp(arg_str_value(cmd, zero_ARG, "y"), "n");
-	else if (arg_count(cmd, restorefile_ARG) || arg_count(cmd, uuidstr_ARG))
-		pp->zero = 0;
-	else
-		pp->zero = 1;
-
-	if (arg_sign_value(cmd, physicalvolumesize_ARG, 0) == SIGN_MINUS) {
-		log_error("Physical volume size may not be negative");
-		return 0;
-	}
-	pp->size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0));
 
 	if (arg_sign_value(cmd, dataalignment_ARG, 0) == SIGN_MINUS) {
 		log_error("Physical volume data alignment may not be negative");
@@ -185,6 +192,11 @@
 	int ret = ECMD_PROCESSED;
 	struct pvcreate_params pp;
 
+	fill_default_pvcreate_params(&pp);
+
+	if (!pvcreate_validate_restore_params(cmd, argc, argv, &pp)) {
+		return EINVALID_CMD_LINE;
+	}
 	if (!pvcreate_validate_params(cmd, argc, argv, &pp)) {
 		return EINVALID_CMD_LINE;
 	}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-05 20:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-26  1:54 LVM2 lib/metadata/metadata.c tools/pvcreate.c wysochanski
2009-10-05 20:03 wysochanski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).