1 /* $NetBSD: vgextend.c,v 1.1.1.2 2009/12/02 00:25:57 haad Exp $ */
4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 int vgextend(struct cmd_context *cmd, int argc, char **argv)
23 struct volume_group *vg = NULL;
25 struct pvcreate_params pp;
28 log_error("Please enter volume group name and "
29 "physical volume(s)");
30 return EINVALID_CMD_LINE;
33 vg_name = skip_dev_dir(cmd, argv[0], NULL);
37 if (arg_count(cmd, metadatacopies_ARG)) {
38 log_error("Invalid option --metadatacopies, "
39 "use --pvmetadatacopies instead.");
40 return EINVALID_CMD_LINE;
42 pvcreate_params_set_defaults(&pp);
43 if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
44 return EINVALID_CMD_LINE;
47 log_verbose("Checking for volume group \"%s\"", vg_name);
48 vg = vg_read_for_update(cmd, vg_name, NULL, 0);
49 if (vg_read_error(vg)) {
55 if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
56 log_error("Can't get lock for orphan PVs");
57 unlock_and_release_vg(cmd, vg, vg_name);
65 if (!vg_extend(vg, argc, argv, &pp))
69 log_verbose("Volume group \"%s\" will be extended by %d new "
70 "physical volumes", vg_name, argc);
72 /* store vg on disk(s) */
73 if (!vg_write(vg) || !vg_commit(vg))
77 log_print("Volume group \"%s\" successfully extended", vg_name);
81 unlock_vg(cmd, VG_ORPHANS);
82 unlock_and_release_vg(cmd, vg, vg_name);