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
18 static int _restore_pv(struct volume_group
*vg
, char *pv_name
)
20 struct pv_list
*pvl
= NULL
;
21 pvl
= find_pv_in_vg(vg
, pv_name
);
23 log_warn("WARNING: PV %s not found in VG %s", pv_name
, vg
->name
);
27 if (!(pvl
->pv
->status
& MISSING_PV
)) {
28 log_warn("WARNING: PV %s was not missing in VG %s", pv_name
, vg
->name
);
33 log_warn("WARNING: The PV %s is still missing.", pv_name
);
37 pvl
->pv
->status
&= ~MISSING_PV
;
41 int vgextend(struct cmd_context
*cmd
, int argc
, char **argv
)
44 struct volume_group
*vg
= NULL
;
46 struct pvcreate_params pp
;
50 log_error("Please enter volume group name and "
51 "physical volume(s)");
52 return EINVALID_CMD_LINE
;
55 vg_name
= skip_dev_dir(cmd
, argv
[0], NULL
);
59 if (arg_count(cmd
, metadatacopies_ARG
)) {
60 log_error("Invalid option --metadatacopies, "
61 "use --pvmetadatacopies instead.");
62 return EINVALID_CMD_LINE
;
64 pvcreate_params_set_defaults(&pp
);
65 if (!pvcreate_params_validate(cmd
, argc
, argv
, &pp
)) {
66 return EINVALID_CMD_LINE
;
69 if (arg_count(cmd
, restoremissing_ARG
))
70 cmd
->handles_missing_pvs
= 1;
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
)) {
83 if (arg_count(cmd
, restoremissing_ARG
)) {
84 for (i
= 0; i
< argc
; ++i
) {
85 if (_restore_pv(vg
, argv
[i
]))
89 log_error("No PV has been restored.");
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
);
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]: ",
105 log_error("Volume group %s not changed", vg_name
);
110 if (!vg_extend(vg
, argc
, (const char* const*)argv
, &pp
))
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
));
123 log_verbose("Volume group \"%s\" will be extended by %d new "
124 "physical volumes", vg_name
, argc
);
127 /* store vg on disk(s) */
128 if (!vg_write(vg
) || !vg_commit(vg
))
132 log_print("Volume group \"%s\" successfully extended", vg_name
);
136 if (!arg_count(cmd
, restoremissing_ARG
))
137 unlock_vg(cmd
, VG_ORPHANS
);
138 unlock_and_release_vg(cmd
, vg
, vg_name
);