]> sourceware.org Git - lvm2.git/blame - tools/vgextend.c
Reinstate accidentally-deleted line.
[lvm2.git] / tools / vgextend.c
CommitLineData
ffb31621 1/*
67cdbd7e 2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5a820745 3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
ffb31621 4 *
6606c3ae 5 * This file is part of LVM2.
ffb31621 6 *
6606c3ae
AK
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
be684599 9 * of the GNU Lesser General Public License v.2.1.
ffb31621 10 *
be684599 11 * You should have received a copy of the GNU Lesser General Public License
6606c3ae
AK
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
ffb31621
AK
14 */
15
16#include "tools.h"
17
49908a9a
PR
18static 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
60274aba 41int vgextend(struct cmd_context *cmd, int argc, char **argv)
ffb31621 42{
aec21154 43 const char *vg_name;
ffb31621 44 struct volume_group *vg = NULL;
043b1362 45 int r = ECMD_FAILED;
2e201936 46 struct pvcreate_params pp;
49908a9a 47 int fixed = 0, i = 0;
ffb31621
AK
48
49 if (!argc) {
50 log_error("Please enter volume group name and "
6fda126d 51 "physical volume(s)");
ffb31621
AK
52 return EINVALID_CMD_LINE;
53 }
54
9397354a 55 vg_name = skip_dev_dir(cmd, argv[0], NULL);
ffb31621
AK
56 argc--;
57 argv++;
58
0ddb66ef
DW
59 if (arg_count(cmd, metadatacopies_ARG)) {
60 log_error("Invalid option --metadatacopies, "
61 "use --pvmetadatacopies instead.");
62 return EINVALID_CMD_LINE;
63 }
accb1738
DW
64 pvcreate_params_set_defaults(&pp);
65 if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
879624f5
DW
66 return EINVALID_CMD_LINE;
67 }
68
49908a9a
PR
69 if (arg_count(cmd, restoremissing_ARG))
70 cmd->handles_missing_pvs = 1;
71
08907484 72 log_verbose("Checking for volume group \"%s\"", vg_name);
5b57e825 73 vg = vg_read_for_update(cmd, vg_name, NULL, 0);
b8b3508c 74 if (vg_read_error(vg)) {
077a6755 75 release_vg(vg);
651ff9b3 76 stack;
891c3d29 77 return ECMD_FAILED;
b8b3508c 78 }
e6923120 79
acac3613 80 if (!archive(vg))
651ff9b3 81 goto_bad;
acac3613 82
49908a9a
PR
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");
077a6755 95 unlock_and_release_vg(cmd, vg, vg_name);
49908a9a
PR
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 "
69e80c9e 103 "of VG %s metadata? [y/n]: ",
49908a9a
PR
104 vg_name) == 'n') {
105 log_error("Volume group %s not changed", vg_name);
106 goto_bad;
107 }
90b96af6 108
49908a9a 109 /* extend vg */
aec21154 110 if (!vg_extend(vg, argc, (const char* const*)argv, &pp))
49908a9a 111 goto_bad;
ffb31621 112
49908a9a
PR
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 "
7041b476 117 "metadata from %"PRIu32" to %"PRIu32, vg_name,
49908a9a
PR
118 vg_mda_copies(vg), vg_mda_used_count(vg));
119 vg_set_mda_copies(vg, vg_mda_used_count(vg));
120 }
7041b476 121
49908a9a
PR
122 /* ret > 0 */
123 log_verbose("Volume group \"%s\" will be extended by %d new "
124 "physical volumes", vg_name, argc);
125 }
ffb31621 126
6fda126d 127 /* store vg on disk(s) */
914c9723 128 if (!vg_write(vg) || !vg_commit(vg))
651ff9b3 129 goto_bad;
ffb31621 130
197c3f2a 131 backup(vg);
08907484 132 log_print("Volume group \"%s\" successfully extended", vg_name);
043b1362 133 r = ECMD_PROCESSED;
ffb31621 134
651ff9b3 135bad:
123b90ce
PR
136 if (!arg_count(cmd, restoremissing_ARG))
137 unlock_vg(cmd, VG_ORPHANS);
077a6755 138 unlock_and_release_vg(cmd, vg, vg_name);
043b1362 139 return r;
ffb31621 140}
This page took 0.106687 seconds and 5 git commands to generate.