/*
* 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.
*
#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;
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;
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");
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;
}