4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "metadata-exported.h"
22 * Intial sanity checking of recovery-related command-line arguments.
23 * These args are: --restorefile, --uuid, and --physicalvolumesize
26 * pp: structure allocated by caller, fields written / validated here
28 static int pvcreate_restore_params_validate(struct cmd_context
*cmd
,
29 int argc
, char **argv
,
30 struct pvcreate_params
*pp
)
32 const char *uuid
= NULL
;
34 struct volume_group
*vg
;
36 if (arg_count(cmd
, restorefile_ARG
) && !arg_count(cmd
, uuidstr_ARG
)) {
37 log_error("--uuid is required with --restorefile");
41 if (arg_count(cmd
, uuidstr_ARG
) && argc
!= 1) {
42 log_error("Can only set uuid on one volume at once");
46 if (arg_count(cmd
, uuidstr_ARG
)) {
47 uuid
= arg_str_value(cmd
, uuidstr_ARG
, "");
48 if (!id_read_format(&pp
->id
, uuid
))
53 if (arg_count(cmd
, restorefile_ARG
)) {
54 pp
->restorefile
= arg_str_value(cmd
, restorefile_ARG
, "");
55 /* The uuid won't already exist */
56 if (!(vg
= backup_read_vg(cmd
, NULL
, pp
->restorefile
))) {
57 log_error("Unable to read volume group from %s",
61 if (!(existing_pv
= find_pv_in_vg_by_uuid(vg
, pp
->idp
))) {
62 log_error("Can't find uuid %s in backup file %s",
63 uuid
, pp
->restorefile
);
66 pp
->pe_start
= pv_pe_start(existing_pv
);
67 pp
->extent_size
= pv_pe_size(existing_pv
);
68 pp
->extent_count
= pv_pe_count(existing_pv
);
72 if (arg_sign_value(cmd
, physicalvolumesize_ARG
, 0) == SIGN_MINUS
) {
73 log_error("Physical volume size may not be negative");
76 pp
->size
= arg_uint64_value(cmd
, physicalvolumesize_ARG
, UINT64_C(0));
78 if (arg_count(cmd
, restorefile_ARG
) || arg_count(cmd
, uuidstr_ARG
))
83 int pvcreate(struct cmd_context
*cmd
, int argc
, char **argv
)
86 int ret
= ECMD_PROCESSED
;
87 struct pvcreate_params pp
;
89 pvcreate_params_set_defaults(&pp
);
91 if (!pvcreate_restore_params_validate(cmd
, argc
, argv
, &pp
)) {
92 return EINVALID_CMD_LINE
;
94 if (!pvcreate_params_validate(cmd
, argc
, argv
, &pp
)) {
95 return EINVALID_CMD_LINE
;
98 for (i
= 0; i
< argc
; i
++) {
99 if (!lock_vol(cmd
, VG_ORPHANS
, LCK_VG_WRITE
)) {
100 log_error("Can't get lock for orphan PVs");
104 if (!pvcreate_single(cmd
, argv
[i
], &pp
)) {
109 unlock_vg(cmd
, VG_ORPHANS
);