Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 : : * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
4 : : *
5 : : * This file is part of LVM2.
6 : : *
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.
10 : : *
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
14 : : */
15 : :
16 : : #include "tools.h"
17 : :
18 : 0 : int vgextend(struct cmd_context *cmd, int argc, char **argv)
19 : : {
20 : : char *vg_name;
21 : 0 : struct volume_group *vg = NULL;
22 : 0 : int r = ECMD_FAILED;
23 : : struct pvcreate_params pp;
24 : :
25 [ # # ]: 0 : if (!argc) {
26 : 0 : log_error("Please enter volume group name and "
27 : : "physical volume(s)");
28 : 0 : return EINVALID_CMD_LINE;
29 : : }
30 : :
31 : 0 : vg_name = skip_dev_dir(cmd, argv[0], NULL);
32 : 0 : argc--;
33 : 0 : argv++;
34 : :
35 [ # # ]: 0 : if (arg_count(cmd, metadatacopies_ARG)) {
36 : 0 : log_error("Invalid option --metadatacopies, "
37 : : "use --pvmetadatacopies instead.");
38 : 0 : return EINVALID_CMD_LINE;
39 : : }
40 : 0 : pvcreate_params_set_defaults(&pp);
41 [ # # ]: 0 : if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
42 : 0 : return EINVALID_CMD_LINE;
43 : : }
44 : :
45 : 0 : log_verbose("Checking for volume group \"%s\"", vg_name);
46 : 0 : vg = vg_read_for_update(cmd, vg_name, NULL, 0);
47 [ # # ]: 0 : if (vg_read_error(vg)) {
48 : 0 : vg_release(vg);
49 : 0 : stack;
50 : 0 : return ECMD_FAILED;
51 : : }
52 : :
53 [ # # ]: 0 : if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
54 : 0 : log_error("Can't get lock for orphan PVs");
55 : 0 : unlock_and_release_vg(cmd, vg, vg_name);
56 : 0 : return ECMD_FAILED;
57 : : }
58 : :
59 [ # # ]: 0 : if (!archive(vg))
60 : 0 : goto_bad;
61 : :
62 : : /* extend vg */
63 [ # # ]: 0 : if (!vg_extend(vg, argc, argv, &pp))
64 : 0 : goto_bad;
65 : :
66 : : /* ret > 0 */
67 : 0 : log_verbose("Volume group \"%s\" will be extended by %d new "
68 : : "physical volumes", vg_name, argc);
69 : :
70 : : /* store vg on disk(s) */
71 [ # # # # ]: 0 : if (!vg_write(vg) || !vg_commit(vg))
72 : 0 : goto_bad;
73 : :
74 : 0 : backup(vg);
75 : 0 : log_print("Volume group \"%s\" successfully extended", vg_name);
76 : 0 : r = ECMD_PROCESSED;
77 : :
78 : : bad:
79 : 0 : unlock_vg(cmd, VG_ORPHANS);
80 : 0 : unlock_and_release_vg(cmd, vg, vg_name);
81 : 0 : return r;
82 : : }
|