1 /* $NetBSD: vgextend.c,v 1.1.1.2 2009/12/02 00:25:57 haad Exp $ */
2
3 /*
4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
6 *
7 * This file is part of LVM2.
8 *
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.
12 *
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
16 */
17
18 #include "tools.h"
19
vgextend(struct cmd_context * cmd,int argc,char ** argv)20 int vgextend(struct cmd_context *cmd, int argc, char **argv)
21 {
22 char *vg_name;
23 struct volume_group *vg = NULL;
24 int r = ECMD_FAILED;
25 struct pvcreate_params pp;
26
27 if (!argc) {
28 log_error("Please enter volume group name and "
29 "physical volume(s)");
30 return EINVALID_CMD_LINE;
31 }
32
33 vg_name = skip_dev_dir(cmd, argv[0], NULL);
34 argc--;
35 argv++;
36
37 if (arg_count(cmd, metadatacopies_ARG)) {
38 log_error("Invalid option --metadatacopies, "
39 "use --pvmetadatacopies instead.");
40 return EINVALID_CMD_LINE;
41 }
42 pvcreate_params_set_defaults(&pp);
43 if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
44 return EINVALID_CMD_LINE;
45 }
46
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;
53 }
54
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;
59 }
60
61 if (!archive(vg))
62 goto_bad;
63
64 /* extend vg */
65 if (!vg_extend(vg, argc, argv, &pp))
66 goto_bad;
67
68 /* ret > 0 */
69 log_verbose("Volume group \"%s\" will be extended by %d new "
70 "physical volumes", vg_name, argc);
71
72 /* store vg on disk(s) */
73 if (!vg_write(vg) || !vg_commit(vg))
74 goto_bad;
75
76 backup(vg);
77 log_print("Volume group \"%s\" successfully extended", vg_name);
78 r = ECMD_PROCESSED;
79
80 bad:
81 unlock_vg(cmd, VG_ORPHANS);
82 unlock_and_release_vg(cmd, vg, vg_name);
83 return r;
84 }
85