2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include "metadata-exported.h"
20 * Intial sanity checking of recovery-related command-line arguments.
21 * These args are: --restorefile, --uuid, and --physicalvolumesize
24 * pp: structure allocated by caller, fields written / validated here
26 static int pvcreate_restore_params_validate(struct cmd_context *cmd,
27 int argc, char **argv,
28 struct pvcreate_params *pp)
30 const char *uuid = NULL;
31 struct volume_group *vg;
32 struct pv_list *existing_pvl;
34 if (arg_count(cmd, restorefile_ARG) && !arg_count(cmd, uuidstr_ARG)) {
35 log_error("--uuid is required with --restorefile");
39 if (!arg_count(cmd, restorefile_ARG) && arg_count(cmd, uuidstr_ARG)) {
40 if (!arg_count(cmd, norestorefile_ARG) &&
41 find_config_tree_bool(cmd,
42 "devices/require_restorefile_with_uuid",
43 DEFAULT_REQUIRE_RESTOREFILE_WITH_UUID)) {
44 log_error("--restorefile is required with --uuid");
49 if (arg_count(cmd, uuidstr_ARG) && argc != 1) {
50 log_error("Can only set uuid on one volume at once");
54 if (arg_count(cmd, uuidstr_ARG)) {
55 uuid = arg_str_value(cmd, uuidstr_ARG, "");
56 if (!id_read_format(&pp->id, uuid))
61 if (arg_count(cmd, restorefile_ARG)) {
62 pp->restorefile = arg_str_value(cmd, restorefile_ARG, "");
63 /* The uuid won't already exist */
64 if (!(vg = backup_read_vg(cmd, NULL, pp->restorefile))) {
65 log_error("Unable to read volume group from %s",
69 if (!(existing_pvl = find_pv_in_vg_by_uuid(vg, pp->idp))) {
70 log_error("Can't find uuid %s in backup file %s",
71 uuid, pp->restorefile);
74 pp->pe_start = pv_pe_start(existing_pvl->pv);
75 pp->extent_size = pv_pe_size(existing_pvl->pv);
76 pp->extent_count = pv_pe_count(existing_pvl->pv);
80 if (arg_sign_value(cmd, physicalvolumesize_ARG, 0) == SIGN_MINUS) {
81 log_error("Physical volume size may not be negative");
84 pp->size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0));
86 if (arg_count(cmd, restorefile_ARG) || arg_count(cmd, uuidstr_ARG))
91 int pvcreate(struct cmd_context *cmd, int argc, char **argv)
94 int ret = ECMD_PROCESSED;
95 struct pvcreate_params pp;
97 pvcreate_params_set_defaults(&pp);
99 if (!pvcreate_restore_params_validate(cmd, argc, argv, &pp)) {
100 return EINVALID_CMD_LINE;
102 if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
103 return EINVALID_CMD_LINE;
106 for (i = 0; i < argc; i++) {
107 if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
108 log_error("Can't get lock for orphan PVs");
112 unescape_colons_and_at_signs(argv[i], NULL, NULL);
114 if (!pvcreate_single(cmd, argv[i], &pp)) {
119 unlock_vg(cmd, VG_ORPHANS);