Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / tools / vgcreate.c
blob69547f888b36eed81ebcbdef1b2e68d6b79315d4
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 vgcreate(struct cmd_context *cmd, int argc, char **argv)
22 struct vgcreate_params vp_new;
23 struct vgcreate_params vp_def;
24 struct volume_group *vg;
25 const char *tag;
26 const char *clustered_message = "";
27 char *vg_name;
28 struct pvcreate_params pp;
30 if (!argc) {
31 log_error("Please provide volume group name and "
32 "physical volumes");
33 return EINVALID_CMD_LINE;
36 vg_name = argv[0];
37 argc--;
38 argv++;
40 if (arg_count(cmd, metadatacopies_ARG)) {
41 log_error("Invalid option --metadatacopies, "
42 "use --pvmetadatacopies instead.");
43 return EINVALID_CMD_LINE;
45 pvcreate_params_set_defaults(&pp);
46 if (!pvcreate_params_validate(cmd, argc, argv, &pp)) {
47 return EINVALID_CMD_LINE;
50 vgcreate_params_set_defaults(&vp_def, NULL);
51 vp_def.vg_name = vg_name;
52 if (vgcreate_params_set_from_args(cmd, &vp_new, &vp_def))
53 return EINVALID_CMD_LINE;
55 if (vgcreate_params_validate(cmd, &vp_new))
56 return EINVALID_CMD_LINE;
58 /* Create the new VG */
59 vg = vg_create(cmd, vp_new.vg_name);
60 if (vg_read_error(vg))
61 goto_bad;
63 if (!vg_set_extent_size(vg, vp_new.extent_size) ||
64 !vg_set_max_lv(vg, vp_new.max_lv) ||
65 !vg_set_max_pv(vg, vp_new.max_pv) ||
66 !vg_set_alloc_policy(vg, vp_new.alloc) ||
67 !vg_set_clustered(vg, vp_new.clustered))
68 goto_bad;
70 if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
71 log_error("Can't get lock for orphan PVs");
72 goto bad_orphan;
75 /* attach the pv's */
76 if (!vg_extend(vg, argc, argv, &pp))
77 goto_bad;
79 if (vp_new.max_lv != vg->max_lv)
80 log_warn("WARNING: Setting maxlogicalvolumes to %d "
81 "(0 means unlimited)", vg->max_lv);
83 if (vp_new.max_pv != vg->max_pv)
84 log_warn("WARNING: Setting maxphysicalvolumes to %d "
85 "(0 means unlimited)", vg->max_pv);
87 if (arg_count(cmd, addtag_ARG)) {
88 if (!(tag = arg_str_value(cmd, addtag_ARG, NULL))) {
89 log_error("Failed to get tag");
90 goto bad;
93 if (!(vg->fid->fmt->features & FMT_TAGS)) {
94 log_error("Volume group format does not support tags");
95 goto bad;
98 if (!str_list_add(cmd->mem, &vg->tags, tag)) {
99 log_error("Failed to add tag %s to volume group %s",
100 tag, vp_new.vg_name);
101 goto bad;
105 if (vg_is_clustered(vg)) {
106 clustered_message = "Clustered ";
107 } else {
108 if (locking_is_clustered())
109 clustered_message = "Non-clustered ";
112 if (!archive(vg))
113 goto_bad;
115 /* Store VG on disk(s) */
116 if (!vg_write(vg) || !vg_commit(vg))
117 goto_bad;
119 unlock_vg(cmd, VG_ORPHANS);
120 unlock_vg(cmd, vp_new.vg_name);
122 backup(vg);
124 log_print("%s%colume group \"%s\" successfully created",
125 clustered_message, *clustered_message ? 'v' : 'V', vg->name);
127 vg_release(vg);
128 return ECMD_PROCESSED;
130 bad:
131 unlock_vg(cmd, VG_ORPHANS);
132 bad_orphan:
133 vg_release(vg);
134 unlock_vg(cmd, vp_new.vg_name);
135 return ECMD_FAILED;