public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
From: wysochanski@sourceware.org
To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org
Subject: LVM2/tools pvcreate.c
Date: Mon, 21 Jul 2008 19:27:00 -0000	[thread overview]
Message-ID: <20080721192722.15094.qmail@sourceware.org> (raw)

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)


             reply	other threads:[~2008-07-21 19:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-21 19:27 wysochanski [this message]
  -- 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080721192722.15094.qmail@sourceware.org \
    --to=wysochanski@sourceware.org \
    --cc=lvm-devel@redhat.com \
    --cc=lvm2-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).