~ubuntu-branches/debian/sid/lvm2/sid

1 by Patrick Caulfield
Import upstream version 2.00.25
1
/*
2
 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
1.1.7 by Bastian Blank
Import upstream version 2.02.54
3
 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
1 by Patrick Caulfield
Import upstream version 2.00.25
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
1.1.3 by Bastian Blank
Import upstream version 2.02.44
9
 * of the GNU Lesser General Public License v.2.1.
1 by Patrick Caulfield
Import upstream version 2.00.25
10
 *
1.1.3 by Bastian Blank
Import upstream version 2.02.44
11
 * You should have received a copy of the GNU Lesser General Public License
1 by Patrick Caulfield
Import upstream version 2.00.25
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
1.1.3 by Bastian Blank
Import upstream version 2.02.44
18
/*
1.1.7 by Bastian Blank
Import upstream version 2.02.54
19
 * Intial sanity checking of recovery-related command-line arguments.
20
 * These args are: --restorefile, --uuid, and --physicalvolumesize
1.1.3 by Bastian Blank
Import upstream version 2.02.44
21
 *
22
 * Output arguments:
23
 * pp: structure allocated by caller, fields written / validated here
24
 */
1.1.8 by Bastian Blank
Import upstream version 2.02.62
25
static int pvcreate_restore_params_validate(struct cmd_context *cmd,
1.1.7 by Bastian Blank
Import upstream version 2.02.54
26
					    int argc, char **argv,
27
					    struct pvcreate_params *pp)
1 by Patrick Caulfield
Import upstream version 2.00.25
28
{
1.1.3 by Bastian Blank
Import upstream version 2.02.44
29
	const char *uuid = NULL;
30
	struct volume_group *vg;
1.1.9 by Bastian Blank
Import upstream version 2.02.64
31
	struct pv_list *existing_pvl;
1.1.3 by Bastian Blank
Import upstream version 2.02.44
32
1 by Patrick Caulfield
Import upstream version 2.00.25
33
	if (arg_count(cmd, restorefile_ARG) && !arg_count(cmd, uuidstr_ARG)) {
34
		log_error("--uuid is required with --restorefile");
1.1.3 by Bastian Blank
Import upstream version 2.02.44
35
		return 0;
1 by Patrick Caulfield
Import upstream version 2.00.25
36
	}
37
1.1.11 by Bastian Blank
Import upstream version 2.02.84
38
	if (!arg_count(cmd, restorefile_ARG) && arg_count(cmd, uuidstr_ARG)) {
39
		if (!arg_count(cmd, norestorefile_ARG) &&
1.1.16 by Bastian Blank
Import upstream version 2.02.104
40
		    find_config_tree_bool(cmd, devices_require_restorefile_with_uuid_CFG, NULL)) {
1.1.11 by Bastian Blank
Import upstream version 2.02.84
41
			log_error("--restorefile is required with --uuid");
42
			return 0;
43
		}
44
	}
45
1 by Patrick Caulfield
Import upstream version 2.00.25
46
	if (arg_count(cmd, uuidstr_ARG) && argc != 1) {
47
		log_error("Can only set uuid on one volume at once");
1.1.3 by Bastian Blank
Import upstream version 2.02.44
48
		return 0;
49
	}
50
51
 	if (arg_count(cmd, uuidstr_ARG)) {
52
		uuid = arg_str_value(cmd, uuidstr_ARG, "");
1.1.16 by Bastian Blank
Import upstream version 2.02.104
53
		if (!id_read_format(&pp->rp.id, uuid))
1.1.3 by Bastian Blank
Import upstream version 2.02.44
54
			return 0;
1.1.16 by Bastian Blank
Import upstream version 2.02.104
55
		pp->rp.idp = &pp->rp.id;
1.1.14 by Bastian Blank
Import upstream version 2.02.95
56
		lvmcache_seed_infos_from_lvmetad(cmd); /* need to check for UUID dups */
1.1.3 by Bastian Blank
Import upstream version 2.02.44
57
	}
58
59
	if (arg_count(cmd, restorefile_ARG)) {
1.1.16 by Bastian Blank
Import upstream version 2.02.104
60
		pp->rp.restorefile = arg_str_value(cmd, restorefile_ARG, "");
1.1.3 by Bastian Blank
Import upstream version 2.02.44
61
		/* The uuid won't already exist */
1.1.16 by Bastian Blank
Import upstream version 2.02.104
62
		if (!(vg = backup_read_vg(cmd, NULL, pp->rp.restorefile))) {
1.1.3 by Bastian Blank
Import upstream version 2.02.44
63
			log_error("Unable to read volume group from %s",
1.1.16 by Bastian Blank
Import upstream version 2.02.104
64
				  pp->rp.restorefile);
1.1.3 by Bastian Blank
Import upstream version 2.02.44
65
			return 0;
66
		}
1.1.16 by Bastian Blank
Import upstream version 2.02.104
67
		if (!(existing_pvl = find_pv_in_vg_by_uuid(vg, pp->rp.idp))) {
68
			release_vg(vg);
1.1.3 by Bastian Blank
Import upstream version 2.02.44
69
			log_error("Can't find uuid %s in backup file %s",
1.1.16 by Bastian Blank
Import upstream version 2.02.104
70
				  uuid, pp->rp.restorefile);
1.1.3 by Bastian Blank
Import upstream version 2.02.44
71
			return 0;
72
		}
1.1.16 by Bastian Blank
Import upstream version 2.02.104
73
		pp->rp.ba_start = pv_ba_start(existing_pvl->pv);
74
		pp->rp.ba_size = pv_ba_size(existing_pvl->pv);
75
		pp->rp.pe_start = pv_pe_start(existing_pvl->pv);
76
		pp->rp.extent_size = pv_pe_size(existing_pvl->pv);
77
		pp->rp.extent_count = pv_pe_count(existing_pvl->pv);
78
1.1.13 by Bastian Blank
Import upstream version 2.02.88
79
		release_vg(vg);
1 by Patrick Caulfield
Import upstream version 2.00.25
80
	}
81
1.1.14 by Bastian Blank
Import upstream version 2.02.95
82
	if (arg_sign_value(cmd, physicalvolumesize_ARG, SIGN_NONE) == SIGN_MINUS) {
1.1.3 by Bastian Blank
Import upstream version 2.02.44
83
		log_error("Physical volume size may not be negative");
84
		return 0;
85
	}
86
	pp->size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0));
87
1.1.7 by Bastian Blank
Import upstream version 2.02.54
88
	if (arg_count(cmd, restorefile_ARG) || arg_count(cmd, uuidstr_ARG))
89
		pp->zero = 0;
1.1.3 by Bastian Blank
Import upstream version 2.02.44
90
	return 1;
91
}
92
93
int pvcreate(struct cmd_context *cmd, int argc, char **argv)
94
{
95
	int i;
96
	int ret = ECMD_PROCESSED;
97
	struct pvcreate_params pp;
98
1.1.21 by Bastian Blank
Import upstream version 2.02.126
99
	/* Needed to change the set of orphan PVs. */
100
	if (!lockd_gl(cmd, "ex", 0))
101
		return_ECMD_FAILED;
102
1.1.8 by Bastian Blank
Import upstream version 2.02.62
103
	pvcreate_params_set_defaults(&pp);
1.1.7 by Bastian Blank
Import upstream version 2.02.54
104
1.1.8 by Bastian Blank
Import upstream version 2.02.62
105
	if (!pvcreate_restore_params_validate(cmd, argc, argv, &pp)) {
1.1.7 by Bastian Blank
Import upstream version 2.02.54
106
		return EINVALID_CMD_LINE;
107
	}
1.1.20 by Bastian Blank
Import upstream version 2.02.122
108
	if (!pvcreate_params_validate(cmd, argc, &pp)) {
1.1.3 by Bastian Blank
Import upstream version 2.02.44
109
		return EINVALID_CMD_LINE;
110
	}
1.1.2 by Andres Salomon
Import upstream version 2.01.04
111
1 by Patrick Caulfield
Import upstream version 2.00.25
112
	for (i = 0; i < argc; i++) {
1.1.16 by Bastian Blank
Import upstream version 2.02.104
113
		if (sigint_caught())
114
			return_ECMD_FAILED;
1.1.4 by Bastian Blank
Import upstream version 2.02.51
115
1.1.14 by Bastian Blank
Import upstream version 2.02.95
116
		dm_unescape_colons_and_at_signs(argv[i], NULL, NULL);
1.1.11 by Bastian Blank
Import upstream version 2.02.84
117
1.1.16 by Bastian Blank
Import upstream version 2.02.104
118
		if (!pvcreate_single(cmd, argv[i], &pp))
1.1.3 by Bastian Blank
Import upstream version 2.02.44
119
			ret = ECMD_FAILED;
1 by Patrick Caulfield
Import upstream version 2.00.25
120
	}
121
122
	return ret;
123
}