public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/tools pvcreate.c
@ 2008-07-21 19:27 wysochanski
  0 siblings, 0 replies; 7+ messages in thread
From: wysochanski @ 2008-07-21 19:27 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2008-07-21 19:27:22

Modified files:
	tools          : pvcreate.c 

Log message:
	Refactor pvcreate - divide parameter parsing & validation from create logic.
	
	Move size (setphysicalvolumesize option), metadatacopies and metadatasize
	validation.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.64&r2=1.65

--- LVM2/tools/pvcreate.c	2008/07/21 19:26:33	1.64
+++ LVM2/tools/pvcreate.c	2008/07/21 19:27:22	1.65
@@ -18,6 +18,9 @@
 
 struct pvcreate_params {
 	int zero;
+	uint64_t size;
+	int pvmetadatacopies;
+	uint64_t pvmetadatasize;
 };
 
 const char _really_init[] =
@@ -142,11 +145,8 @@
 	void *existing_pv;
 	struct id id, *idp = NULL;
 	const char *uuid = NULL;
-	uint64_t size = 0;
 	struct device *dev;
 	struct list mdas;
-	int pvmetadatacopies;
-	uint64_t pvmetadatasize;
 	struct volume_group *vg;
 	const char *restorefile;
 	uint64_t pe_start = 0;
@@ -196,28 +196,6 @@
 	if (sigint_caught())
 		goto error;
 
-	if (arg_sign_value(cmd, physicalvolumesize_ARG, 0) == SIGN_MINUS) {
-		log_error("Physical volume size may not be negative");
-		goto error;
-	}
-	size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0));
-
-	if (arg_sign_value(cmd, metadatasize_ARG, 0) == SIGN_MINUS) {
-		log_error("Metadata size may not be negative");
-		goto error;
-	}
-	pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0));
-	if (!pvmetadatasize)
-		pvmetadatasize = find_config_tree_int(cmd,
-						 "metadata/pvmetadatasize",
-						 DEFAULT_PVMETADATASIZE);
-
-	pvmetadatacopies = arg_int_value(cmd, metadatacopies_ARG, -1);
-	if (pvmetadatacopies < 0)
-		pvmetadatacopies = find_config_tree_int(cmd,
-						   "metadata/pvmetadatacopies",
-						   DEFAULT_PVMETADATACOPIES);
-
 	if (!(dev = dev_cache_get(pv_name, cmd->filter))) {
 		log_error("%s: Couldn't find device.  Check your filters?",
 			  pv_name);
@@ -225,9 +203,9 @@
 	}
 
 	list_init(&mdas);
-	if (!(pv = pv_create(cmd, dev, idp, size, pe_start,
-			     extent_count, extent_size,
-			     pvmetadatacopies, pvmetadatasize, &mdas))) {
+	if (!(pv = pv_create(cmd, dev, idp, pp->size, pe_start,
+			     extent_count, extent_size, pp->pvmetadatacopies,
+			     pp->pvmetadatasize,&mdas))) {
 		log_error("Failed to setup physical volume \"%s\"", pv_name);
 		goto error;
 	}
@@ -276,13 +254,17 @@
 }
 
 /*
- * Intial sanity checking of command-line arguments and fill in parameters
- * for pvcreate command.  More comprehensive validation is done in
- * pvcreate_validate_params().
+ * Intial sanity checking of command-line arguments and fill in 'pp' fields.
+ *
+ * Input arguments:
+ * cmd, argc, argv
+ *
+ * Output arguments:
+ * pp: structure allocated by caller, fields written / validated here
  */
-static int pvcreate_fill_params(struct cmd_context *cmd,
-				int argc, char **argv,
-				struct pvcreate_params *pp)
+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");
@@ -330,30 +312,43 @@
 	else
 		pp->zero = 1;
 
-	return 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, metadatasize_ARG, 0) == SIGN_MINUS) {
+		log_error("Metadata size may not be negative");
+		return 0;
+	}
+
+	pp->pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0));
+	if (!pp->pvmetadatasize)
+		pp->pvmetadatasize = find_config_tree_int(cmd,
+						 "metadata/pvmetadatasize",
+						 DEFAULT_PVMETADATASIZE);
+
+	pp->pvmetadatacopies = arg_int_value(cmd, metadatacopies_ARG, -1);
+	if (pp->pvmetadatacopies < 0)
+		pp->pvmetadatacopies = find_config_tree_int(cmd,
+						   "metadata/pvmetadatacopies",
+						   DEFAULT_PVMETADATACOPIES);
 
-static int pvcreate_validate_params(struct cmd_context *cmd,
-				    struct pvcreate_params *pp)
-{
 	return 1;
 }
 
+
 int pvcreate(struct cmd_context *cmd, int argc, char **argv)
 {
 	int i, r;
 	int ret = ECMD_PROCESSED;
 	struct pvcreate_params pp;
 
-	if (!pvcreate_fill_params(cmd, argc, argv, &pp)) {
+	if (!pvcreate_validate_params(cmd, argc, argv, &pp)) {
 		return EINVALID_CMD_LINE;
 	}
 
-	if (!pvcreate_validate_params(cmd, &pp)) {
-		    return EINVALID_CMD_LINE;
-	}
-
 	for (i = 0; i < argc; i++) {
 		r = pvcreate_single(cmd, argv[i], &pp);
 		if (r > ret)


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

* LVM2/tools pvcreate.c
@ 2010-03-16 15:48 agk
  0 siblings, 0 replies; 7+ messages in thread
From: agk @ 2010-03-16 15:48 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2010-03-16 15:48:28

Modified files:
	tools          : pvcreate.c 

Log message:
	replace existing_pv with existing_pvl

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.89&r2=1.90

--- LVM2/tools/pvcreate.c	2010/03/16 15:30:49	1.89
+++ LVM2/tools/pvcreate.c	2010/03/16 15:48:27	1.90
@@ -28,8 +28,8 @@
 					    struct pvcreate_params *pp)
 {
 	const char *uuid = NULL;
-	void *existing_pv;
 	struct volume_group *vg;
+	struct pv_list *existing_pvl;
 
 	if (arg_count(cmd, restorefile_ARG) && !arg_count(cmd, uuidstr_ARG)) {
 		log_error("--uuid is required with --restorefile");
@@ -56,14 +56,14 @@
 				  pp->restorefile);
 			return 0;
 		}
-		if (!(existing_pv = find_pv_in_vg_by_uuid(vg, pp->idp)->pv)) {
+		if (!(existing_pvl = find_pv_in_vg_by_uuid(vg, pp->idp))) {
 			log_error("Can't find uuid %s in backup file %s",
 				  uuid, pp->restorefile);
 			return 0;
 		}
-		pp->pe_start = pv_pe_start(existing_pv);
-		pp->extent_size = pv_pe_size(existing_pv);
-		pp->extent_count = pv_pe_count(existing_pv);
+		pp->pe_start = pv_pe_start(existing_pvl->pv);
+		pp->extent_size = pv_pe_size(existing_pvl->pv);
+		pp->extent_count = pv_pe_count(existing_pvl->pv);
 		vg_release(vg);
 	}
 


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

* LVM2/tools pvcreate.c
@ 2009-03-17 14:01 mornfall
  0 siblings, 0 replies; 7+ messages in thread
From: mornfall @ 2009-03-17 14:01 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2009-03-17 14:01:01

Modified files:
	tools          : pvcreate.c 

Log message:
	Some extra (paranoid) checks on dev_is_{md,swap} result.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.79&r2=1.80

--- LVM2/tools/pvcreate.c	2009/03/17 13:59:57	1.79
+++ LVM2/tools/pvcreate.c	2009/03/17 14:00:58	1.80
@@ -46,6 +46,7 @@
 	struct physical_volume *pv;
 	struct device *dev;
 	uint64_t md_superblock, swap_signature;
+	int wipe_md, wipe_swap;
 
 	/* FIXME Check partition type is LVM unless --force is given */
 
@@ -117,7 +118,7 @@
 	}
 
 	/* Wipe superblock? */
-	if (dev_is_md(dev, &md_superblock) &&
+	if ((wipe_md = dev_is_md(dev, &md_superblock)) == 1 &&
 	    ((!pp->idp && !pp->restorefile) || pp->yes ||
 	     (yes_no_prompt("Software RAID md superblock "
 			    "detected on %s. Wipe it? [y/n] ", name) == 'y'))) {
@@ -129,7 +130,13 @@
 		}
 	}
 
-	if (dev_is_swap(dev, &swap_signature) &&
+	if (wipe_md == -1) {
+		log_error("Fatal error while trying to detect software "
+			  "RAID md superblock on %s", name);
+		return 0;
+	}
+
+	if ((wipe_swap = dev_is_swap(dev, &swap_signature)) == 1 &&
 	    ((!pp->idp && !pp->restorefile) || pp->yes ||
 	     (yes_no_prompt("Swap signature detected on %s. Wipe it? [y/n] ",
 			    name) == 'y'))) {
@@ -140,6 +147,12 @@
 		}
 	}
 
+	if (wipe_swap == -1) {
+		log_error("Fatal error while trying to detect swap "
+			  "signature on %s", name);
+		return 0;
+	}
+
 	if (sigint_caught())
 		return 0;
 


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

* LVM2/tools pvcreate.c
@ 2008-07-25 14:45 wysochanski
  0 siblings, 0 replies; 7+ messages in thread
From: wysochanski @ 2008-07-25 14:45 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2008-07-25 14:45:25

Modified files:
	tools          : pvcreate.c 

Log message:
	Refactor pvcreate - --yes argument

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.71&r2=1.72

--- LVM2/tools/pvcreate.c	2008/07/25 14:36:55	1.71
+++ LVM2/tools/pvcreate.c	2008/07/25 14:45:24	1.72
@@ -29,6 +29,7 @@
 	uint32_t extent_size;
 	const char *restorefile; /* 0 if no --restorefile option */
 	force_t force;
+	unsigned yes;
 };
 
 const char _really_init[] =
@@ -72,7 +73,7 @@
 	}
 
 	/* prompt */
-	if (pv && !is_orphan(pv) && !arg_count(cmd, yes_ARG) &&
+	if (pv && !is_orphan(pv) && !pp->yes &&
 	    yes_no_prompt(_really_init, name, pv_vg_name(pv)) == 'n') {
 		log_print("%s: physical volume not initialized", name);
 		return 0;
@@ -114,9 +115,7 @@
 
 	/* Wipe superblock? */
 	if (dev_is_md(dev, &md_superblock) &&
-	    ((!pp->idp &&
-	      !pp->restorefile) ||
-	     arg_count(cmd, yes_ARG) ||
+	    ((!pp->idp && !pp->restorefile) || pp->yes ||
 	     (yes_no_prompt("Software RAID md superblock "
 			    "detected on %s. Wipe it? [y/n] ", name) == 'y'))) {
 		log_print("Wiping software RAID md superblock on %s", name);
@@ -292,6 +291,7 @@
 		return 0;
 	}
 
+	pp->yes = arg_count(cmd, yes_ARG);
 	pp->force = arg_count(cmd, force_ARG);
 
 	if (arg_int_value(cmd, labelsector_ARG, 0) >= LABEL_SCAN_SECTORS) {


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

* LVM2/tools pvcreate.c
@ 2008-07-25 14:12 wysochanski
  0 siblings, 0 replies; 7+ messages in thread
From: wysochanski @ 2008-07-25 14:12 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2008-07-25 14:12:30

Modified files:
	tools          : pvcreate.c 

Log message:
	Refactor pvcreate - use '0' for no --uuid or --restorefile options.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.69&r2=1.70

--- LVM2/tools/pvcreate.c	2008/07/25 00:30:57	1.69
+++ LVM2/tools/pvcreate.c	2008/07/25 14:12:29	1.70
@@ -23,11 +23,11 @@
 	uint64_t pvmetadatasize;
 	int64_t labelsector;
 	struct id id; /* FIXME: redundant */
-	struct id *idp;
+	struct id *idp; /* 0 if no --uuid option */
 	uint64_t pe_start;
 	uint32_t extent_count;
 	uint32_t extent_size;
-	const char *restorefile;
+	const char *restorefile; /* 0 if no --restorefile option */
 };
 
 const char _really_init[] =
@@ -37,7 +37,8 @@
  * See if we may pvcreate on this device.
  * 0 indicates we may not.
  */
-static int pvcreate_check(struct cmd_context *cmd, const char *name)
+static int pvcreate_check(struct cmd_context *cmd, const char *name,
+			  struct pvcreate_params *pp)
 {
 	struct physical_volume *pv;
 	struct device *dev;
@@ -112,8 +113,8 @@
 
 	/* Wipe superblock? */
 	if (dev_is_md(dev, &md_superblock) &&
-	    ((!arg_count(cmd, uuidstr_ARG) &&
-	      !arg_count(cmd, restorefile_ARG)) ||
+	    ((!pp->idp &&
+	      !pp->restorefile) ||
 	     arg_count(cmd, yes_ARG) ||
 	     (yes_no_prompt("Software RAID md superblock "
 			    "detected on %s. Wipe it? [y/n] ", name) == 'y'))) {
@@ -161,7 +162,7 @@
 		return ECMD_FAILED;
 	}
 
-	if (!pvcreate_check(cmd, pv_name))
+	if (!pvcreate_check(cmd, pv_name, pp))
 		goto error;
 
 	if (sigint_caught())


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

* LVM2/tools pvcreate.c
@ 2008-07-23 19:29 wysochanski
  0 siblings, 0 replies; 7+ messages in thread
From: wysochanski @ 2008-07-23 19:29 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2008-07-23 19:29:59

Modified files:
	tools          : pvcreate.c 

Log message:
	Refactor pvcreate - move labelsector parameter parsing & validation.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.65&r2=1.66

--- LVM2/tools/pvcreate.c	2008/07/21 19:27:22	1.65
+++ LVM2/tools/pvcreate.c	2008/07/23 19:29:58	1.66
@@ -21,6 +21,7 @@
 	uint64_t size;
 	int pvmetadatacopies;
 	uint64_t pvmetadatasize;
+	int64_t labelsector;
 };
 
 const char _really_init[] =
@@ -237,8 +238,7 @@
 	log_very_verbose("Writing physical volume data to disk \"%s\"",
 			 pv_name);
 	if (!(pv_write(cmd, (struct physical_volume *)pv, &mdas,
-		       arg_int64_value(cmd, labelsector_ARG,
-						       DEFAULT_LABELSECTOR)))) {
+		       pp->labelsector))) {
 		log_error("Failed to write physical volume \"%s\"", pv_name);
 		goto error;
 	}
@@ -290,6 +290,9 @@
 		log_error("labelsector must be less than %lu",
 			  LABEL_SCAN_SECTORS);
 		return 0;
+	} else {
+		pp->labelsector = arg_int64_value(cmd, labelsector_ARG,
+						  DEFAULT_LABELSECTOR);
 	}
 
 	if (!(cmd->fmt->features & FMT_MDAS) &&


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

* LVM2/tools pvcreate.c
@ 2004-11-19 19:32 agk
  0 siblings, 0 replies; 7+ messages in thread
From: agk @ 2004-11-19 19:32 UTC (permalink / raw)
  To: lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2004-11-19 19:32:09

Modified files:
	tools          : pvcreate.c 

Log message:
	Only wipe signature bytes when destroying md superblock, so process
	is reversible.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.40&r2=1.41


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

end of thread, other threads:[~2010-03-16 15:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-21 19:27 LVM2/tools pvcreate.c wysochanski
  -- strict thread matches above, loose matches on Subject: below --
2010-03-16 15:48 agk
2009-03-17 14:01 mornfall
2008-07-25 14:45 wysochanski
2008-07-25 14:12 wysochanski
2008-07-23 19:29 wysochanski
2004-11-19 19:32 agk

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).