]> sourceware.org Git - lvm2.git/blob - tools/vgextend.c
pre-release
[lvm2.git] / tools / vgextend.c
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
18 static int _restore_pv(struct volume_group *vg, char *pv_name)
19 {
20 struct pv_list *pvl = NULL;
21 pvl = find_pv_in_vg(vg, pv_name);
22 if (!pvl) {
23 log_warn("WARNING: PV %s not found in VG %s", pv_name, vg->name);
24 return 0;
25 }
26
27 if (!(pvl->pv->status & MISSING_PV)) {
28 log_warn("WARNING: PV %s was not missing in VG %s", pv_name, vg->name);
29 return 0;
30 }
31
32 if (!pvl->pv->dev) {
33 log_warn("WARNING: The PV %s is still missing.", pv_name);
34 return 0;
35 }
36
37 pvl->pv->status &= ~MISSING_PV;
38 return 1;
39 }
40
41 int vgextend(struct cmd_context *cmd, int argc, char **argv)
42 {
43 const char *vg_name;
44 struct volume_group *vg = NULL;
45 int r = ECMD_FAILED;
46 struct pvcreate_params pp;
47 int fixed = 0, i = 0;
48
49 if (!argc) {
50 log_error("Please enter volume group name and "
51 "physical volume(s)");
52 return EINVALID_CMD_LINE;
53 }
54
55 vg_name = skip_dev_dir(cmd, argv[0], NULL);
56 argc--;
57 argv++;
58
59 if (arg_count(cmd, metadatacopies_ARG)) {
60 log_error("Invalid option --metadatacopies, "
61 "use --pvmetadatacopies instead.");
62 return EINVALID_CMD_LINE;
63 }
64 pvcreate_params_set_defaults(&pp);
65 if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
66 return EINVALID_CMD_LINE;
67 }
68
69 if (arg_count(cmd, restoremissing_ARG))
70 cmd->handles_missing_pvs = 1;
71
72 log_verbose("Checking for volume group \"%s\"", vg_name);
73 vg = vg_read_for_update(cmd, vg_name, NULL, 0);
74 if (vg_read_error(vg)) {
75 release_vg(vg);
76 stack;
77 return ECMD_FAILED;
78 }
79
80 if (!archive(vg))
81 goto_bad;
82
83 if (arg_count(cmd, restoremissing_ARG)) {
84 for (i = 0; i < argc; ++i) {
85 if (_restore_pv(vg, argv[i]))
86 ++ fixed;
87 }
88 if (!fixed) {
89 log_error("No PV has been restored.");
90 goto_bad;
91 }
92 } else { /* no --restore, normal vgextend */
93 if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
94 log_error("Can't get lock for orphan PVs");
95 unlock_and_release_vg(cmd, vg, vg_name);
96 return ECMD_FAILED;
97 }
98
99 if (arg_count(cmd, metadataignore_ARG) &&
100 (vg_mda_copies(vg) != VGMETADATACOPIES_UNMANAGED) &&
101 (pp.force == PROMPT) &&
102 yes_no_prompt("Override preferred number of copies "
103 "of VG %s metadata? [y/n]: ",
104 vg_name) == 'n') {
105 log_error("Volume group %s not changed", vg_name);
106 goto_bad;
107 }
108
109 /* extend vg */
110 if (!vg_extend(vg, argc, (const char* const*)argv, &pp))
111 goto_bad;
112
113 if (arg_count(cmd, metadataignore_ARG) &&
114 (vg_mda_copies(vg) != VGMETADATACOPIES_UNMANAGED) &&
115 (vg_mda_copies(vg) != vg_mda_used_count(vg))) {
116 log_warn("WARNING: Changing preferred number of copies of VG %s "
117 "metadata from %"PRIu32" to %"PRIu32, vg_name,
118 vg_mda_copies(vg), vg_mda_used_count(vg));
119 vg_set_mda_copies(vg, vg_mda_used_count(vg));
120 }
121
122 /* ret > 0 */
123 log_verbose("Volume group \"%s\" will be extended by %d new "
124 "physical volumes", vg_name, argc);
125 }
126
127 /* store vg on disk(s) */
128 if (!vg_write(vg) || !vg_commit(vg))
129 goto_bad;
130
131 backup(vg);
132 log_print("Volume group \"%s\" successfully extended", vg_name);
133 r = ECMD_PROCESSED;
134
135 bad:
136 if (!arg_count(cmd, restoremissing_ARG))
137 unlock_vg(cmd, VG_ORPHANS);
138 unlock_and_release_vg(cmd, vg, vg_name);
139 return r;
140 }
This page took 0.036528 seconds and 5 git commands to generate.