Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / tools / vgextend.c
blob316c8a0c774947e7201a4f170780702506407fc6
1 /* $NetBSD$ */
3 /*
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
18 #include "tools.h"
20 int vgextend(struct cmd_context *cmd, int argc, char **argv)
22 char *vg_name;
23 struct volume_group *vg = NULL;
24 int r = ECMD_FAILED;
25 struct pvcreate_params pp;
27 if (!argc) {
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);
34 argc--;
35 argv++;
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)) {
50 vg_release(vg);
51 stack;
52 return ECMD_FAILED;
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);
58 return ECMD_FAILED;
61 if (!archive(vg))
62 goto_bad;
64 /* extend vg */
65 if (!vg_extend(vg, argc, argv, &pp))
66 goto_bad;
68 /* ret > 0 */
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))
74 goto_bad;
76 backup(vg);
77 log_print("Volume group \"%s\" successfully extended", vg_name);
78 r = ECMD_PROCESSED;
80 bad:
81 unlock_vg(cmd, VG_ORPHANS);
82 unlock_and_release_vg(cmd, vg, vg_name);
83 return r;