]> sourceware.org Git - lvm2.git/blob - tools/vgimport.c
d94b113144a5a76270bce48f1bbd8ad46b44a50c
[lvm2.git] / tools / vgimport.c
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14 */
15
16 #include "tools.h"
17 #include "lib/label/hints.h"
18
19 static int _vgimport_single(struct cmd_context *cmd,
20 const char *vg_name,
21 struct volume_group *vg,
22 struct processing_handle *handle __attribute__((unused)))
23 {
24 struct pv_list *pvl;
25 struct physical_volume *pv;
26
27 if (!vg_is_exported(vg)) {
28 log_error("Volume group \"%s\" is not exported", vg_name);
29 goto bad;
30 }
31
32 if (vg_status(vg) & PARTIAL_VG) {
33 log_error("Volume group \"%s\" is partially missing", vg_name);
34 goto bad;
35 }
36
37 vg->status &= ~EXPORTED_VG;
38
39 if (!vg_is_shared(vg))
40 vg->system_id = cmd->system_id ? dm_pool_strdup(vg->vgmem, cmd->system_id) : NULL;
41
42 dm_list_iterate_items(pvl, &vg->pvs) {
43 pv = pvl->pv;
44 pv->status &= ~EXPORTED_VG;
45 }
46
47 if (!vg_write(vg) || !vg_commit(vg))
48 goto_bad;
49
50 log_print_unless_silent("Volume group \"%s\" successfully imported", vg->name);
51
52 /*
53 * This is not necessary for any normal, known cases, but it could be
54 * associated with some unconventional method of sharing disks. Hints
55 * should be disabled when sharing disks, but this might help.
56 */
57 invalidate_hints(cmd);
58
59 return ECMD_PROCESSED;
60
61 bad:
62 return ECMD_FAILED;
63 }
64
65 int vgimport(struct cmd_context *cmd, int argc, char **argv)
66 {
67 if (!argc && !arg_is_set(cmd, all_ARG) && !arg_is_set(cmd, select_ARG)) {
68 log_error("Please supply volume groups or -S for selection or use -a for all.");
69 return EINVALID_CMD_LINE;
70 }
71
72 if (arg_is_set(cmd, all_ARG) && (argc || arg_is_set(cmd, select_ARG))) {
73 log_error("No arguments permitted when using -a for all.");
74 return EINVALID_CMD_LINE;
75 }
76
77 if (arg_is_set(cmd, force_ARG)) {
78 /*
79 * The volume group cannot be repaired unless it is first
80 * imported. If we don't allow the user a way to import the
81 * VG while it is 'partial', then we will have created a
82 * circular dependency.
83 *
84 * The reason we don't just simply set 'handles_missing_pvs'
85 * by default is that we want to guard against the case
86 * where the user simply forgot to move one or more disks in
87 * the VG before running 'vgimport'.
88 */
89 log_warn("WARNING: Volume groups with missing PVs will be imported with --force.");
90 cmd->handles_missing_pvs = 1;
91 }
92
93 return process_each_vg(cmd, argc, argv, NULL, NULL, READ_FOR_UPDATE,
94 0, NULL, &_vgimport_single);
95 }
This page took 0.046646 seconds and 6 git commands to generate.