Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 : : * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
4 : : *
5 : : * This file is part of LVM2.
6 : : *
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.
10 : : *
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
14 : : */
15 : :
16 : : #include "tools.h"
17 : : #include "metadata-exported.h"
18 : :
19 : : /*
20 : : * Intial sanity checking of recovery-related command-line arguments.
21 : : * These args are: --restorefile, --uuid, and --physicalvolumesize
22 : : *
23 : : * Output arguments:
24 : : * pp: structure allocated by caller, fields written / validated here
25 : : */
26 : 0 : static int pvcreate_restore_params_validate(struct cmd_context *cmd,
27 : : int argc, char **argv,
28 : : struct pvcreate_params *pp)
29 : : {
30 : 0 : const char *uuid = NULL;
31 : : struct volume_group *vg;
32 : : struct pv_list *existing_pvl;
33 : :
34 [ # # ][ # # ]: 0 : if (arg_count(cmd, restorefile_ARG) && !arg_count(cmd, uuidstr_ARG)) {
35 : 0 : log_error("--uuid is required with --restorefile");
36 : 0 : return 0;
37 : : }
38 : :
39 [ # # ][ # # ]: 0 : if (arg_count(cmd, uuidstr_ARG) && argc != 1) {
40 : 0 : log_error("Can only set uuid on one volume at once");
41 : 0 : return 0;
42 : : }
43 : :
44 [ # # ]: 0 : if (arg_count(cmd, uuidstr_ARG)) {
45 : 0 : uuid = arg_str_value(cmd, uuidstr_ARG, "");
46 [ # # ]: 0 : if (!id_read_format(&pp->id, uuid))
47 : 0 : return 0;
48 : 0 : pp->idp = &pp->id;
49 : : }
50 : :
51 [ # # ]: 0 : if (arg_count(cmd, restorefile_ARG)) {
52 : 0 : pp->restorefile = arg_str_value(cmd, restorefile_ARG, "");
53 : : /* The uuid won't already exist */
54 [ # # ]: 0 : if (!(vg = backup_read_vg(cmd, NULL, pp->restorefile))) {
55 : 0 : log_error("Unable to read volume group from %s",
56 : : pp->restorefile);
57 : 0 : return 0;
58 : : }
59 [ # # ]: 0 : if (!(existing_pvl = find_pv_in_vg_by_uuid(vg, pp->idp))) {
60 : 0 : log_error("Can't find uuid %s in backup file %s",
61 : : uuid, pp->restorefile);
62 : 0 : return 0;
63 : : }
64 : 0 : pp->pe_start = pv_pe_start(existing_pvl->pv);
65 : 0 : pp->extent_size = pv_pe_size(existing_pvl->pv);
66 : 0 : pp->extent_count = pv_pe_count(existing_pvl->pv);
67 : 0 : vg_release(vg);
68 : : }
69 : :
70 [ # # ]: 0 : if (arg_sign_value(cmd, physicalvolumesize_ARG, 0) == SIGN_MINUS) {
71 : 0 : log_error("Physical volume size may not be negative");
72 : 0 : return 0;
73 : : }
74 : 0 : pp->size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0));
75 : :
76 [ # # # # ]: 0 : if (arg_count(cmd, restorefile_ARG) || arg_count(cmd, uuidstr_ARG))
77 : 0 : pp->zero = 0;
78 : 0 : return 1;
79 : : }
80 : :
81 : 0 : int pvcreate(struct cmd_context *cmd, int argc, char **argv)
82 : : {
83 : : int i;
84 : 0 : int ret = ECMD_PROCESSED;
85 : : struct pvcreate_params pp;
86 : :
87 : 0 : pvcreate_params_set_defaults(&pp);
88 : :
89 [ # # ]: 0 : if (!pvcreate_restore_params_validate(cmd, argc, argv, &pp)) {
90 : 0 : return EINVALID_CMD_LINE;
91 : : }
92 [ # # ]: 0 : if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
93 : 0 : return EINVALID_CMD_LINE;
94 : : }
95 : :
96 [ # # ]: 0 : for (i = 0; i < argc; i++) {
97 [ # # ]: 0 : if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
98 : 0 : log_error("Can't get lock for orphan PVs");
99 : 0 : return ECMD_FAILED;
100 : : }
101 : :
102 [ # # ]: 0 : if (!pvcreate_single(cmd, argv[i], &pp)) {
103 : 0 : stack;
104 : 0 : ret = ECMD_FAILED;
105 : : }
106 : :
107 : 0 : unlock_vg(cmd, VG_ORPHANS);
108 [ # # ]: 0 : if (sigint_caught())
109 : 0 : return ret;
110 : : }
111 : :
112 : 0 : return ret;
113 : : }
|