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
))
59 lvmcache_seed_infos_from_lvmetad(cmd
); /* need to check for UUID dups */
62 if (arg_count(cmd
, restorefile_ARG
)) {
63 pp
->restorefile
= arg_str_value(cmd
, restorefile_ARG
, "");
64 /* The uuid won't already exist */
65 if (!(vg
= backup_read_vg(cmd
, NULL
, pp
->restorefile
))) {
66 log_error("Unable to read volume group from %s",
70 if (!(existing_pvl
= find_pv_in_vg_by_uuid(vg
, pp
->idp
))) {
71 log_error("Can't find uuid %s in backup file %s",
72 uuid
, pp
->restorefile
);
75 pp
->pe_start
= pv_pe_start(existing_pvl
->pv
);
76 pp
->extent_size
= pv_pe_size(existing_pvl
->pv
);
77 pp
->extent_count
= pv_pe_count(existing_pvl
->pv
);
81 if (arg_sign_value(cmd
, physicalvolumesize_ARG
, SIGN_NONE
) == SIGN_MINUS
) {
82 log_error("Physical volume size may not be negative");
85 pp
->size
= arg_uint64_value(cmd
, physicalvolumesize_ARG
, UINT64_C(0));
87 if (arg_count(cmd
, restorefile_ARG
) || arg_count(cmd
, uuidstr_ARG
))
92 int pvcreate(struct cmd_context
*cmd
, int argc
, char **argv
)
95 int ret
= ECMD_PROCESSED
;
96 struct pvcreate_params pp
;
97 struct physical_volume
*pv
;
99 pvcreate_params_set_defaults(&pp
);
101 if (!pvcreate_restore_params_validate(cmd
, argc
, argv
, &pp
)) {
102 return EINVALID_CMD_LINE
;
104 if (!pvcreate_params_validate(cmd
, argc
, argv
, &pp
)) {
105 return EINVALID_CMD_LINE
;
108 for (i
= 0; i
< argc
; i
++) {
109 if (!lock_vol(cmd
, VG_ORPHANS
, LCK_VG_WRITE
)) {
110 log_error("Can't get lock for orphan PVs");
114 dm_unescape_colons_and_at_signs(argv
[i
], NULL
, NULL
);
116 if (!(pv
= pvcreate_single(cmd
, argv
[i
], &pp
, 1))) {
121 unlock_vg(cmd
, VG_ORPHANS
);