]>
Commit | Line | Data |
---|---|---|
2235e241 | 1 | /* |
67cdbd7e | 2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. |
905240f9 | 3 | * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. |
2235e241 | 4 | * |
6606c3ae | 5 | * This file is part of LVM2. |
2235e241 | 6 | * |
6606c3ae AK |
7 | * This copyrighted material is made available to anyone wishing to use, |
8 | * modify, copy, or redistribute it subject to the terms and conditions | |
be684599 | 9 | * of the GNU Lesser General Public License v.2.1. |
2235e241 | 10 | * |
be684599 | 11 | * You should have received a copy of the GNU Lesser General Public License |
6606c3ae | 12 | * along with this program; if not, write to the Free Software Foundation, |
fcbef05a | 13 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2235e241 AK |
14 | */ |
15 | ||
16 | #include "tools.h" | |
25cb6a04 | 17 | #include "lib/label/hints.h" |
2235e241 | 18 | |
f1cc5b12 AK |
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))) | |
2235e241 | 23 | { |
a5fe5a7c AK |
24 | struct pv_list *pvl; |
25 | struct physical_volume *pv; | |
26 | ||
905240f9 | 27 | if (!vg_is_exported(vg)) { |
08907484 | 28 | log_error("Volume group \"%s\" is not exported", vg_name); |
651ff9b3 | 29 | goto bad; |
2235e241 AK |
30 | } |
31 | ||
69483a8a | 32 | if (vg_status(vg) & PARTIAL_VG) { |
08907484 | 33 | log_error("Volume group \"%s\" is partially missing", vg_name); |
651ff9b3 | 34 | goto bad; |
2235e241 AK |
35 | } |
36 | ||
2235e241 | 37 | vg->status &= ~EXPORTED_VG; |
3da88b89 | 38 | |
b6f0f20d | 39 | if (!vg_is_shared(vg)) |
3da88b89 | 40 | vg->system_id = cmd->system_id ? dm_pool_strdup(vg->vgmem, cmd->system_id) : NULL; |
2235e241 | 41 | |
2c44337b | 42 | dm_list_iterate_items(pvl, &vg->pvs) { |
a5fe5a7c AK |
43 | pv = pvl->pv; |
44 | pv->status &= ~EXPORTED_VG; | |
45 | } | |
46 | ||
914c9723 | 47 | if (!vg_write(vg) || !vg_commit(vg)) |
651ff9b3 | 48 | goto_bad; |
2235e241 | 49 | |
438e0050 | 50 | log_print_unless_silent("Volume group \"%s\" successfully imported", vg->name); |
6fda126d | 51 | |
25cb6a04 DT |
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 | ||
cfb7bfc7 | 59 | return ECMD_PROCESSED; |
7d0e6e80 | 60 | |
651ff9b3 | 61 | bad: |
7d0e6e80 | 62 | return ECMD_FAILED; |
2235e241 | 63 | } |
5a52dca9 AK |
64 | |
65 | int vgimport(struct cmd_context *cmd, int argc, char **argv) | |
66 | { | |
7e671e5d | 67 | if (!argc && !arg_is_set(cmd, all_ARG) && !arg_is_set(cmd, select_ARG)) { |
80cca536 | 68 | log_error("Please supply volume groups or -S for selection or use -a for all."); |
cf29de5d | 69 | return EINVALID_CMD_LINE; |
5a52dca9 AK |
70 | } |
71 | ||
7e671e5d | 72 | if (arg_is_set(cmd, all_ARG) && (argc || arg_is_set(cmd, select_ARG))) { |
5a52dca9 | 73 | log_error("No arguments permitted when using -a for all."); |
cf29de5d | 74 | return EINVALID_CMD_LINE; |
5a52dca9 AK |
75 | } |
76 | ||
7e671e5d | 77 | if (arg_is_set(cmd, force_ARG)) { |
3ab46449 JB |
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 | */ | |
d13e87b9 | 89 | log_warn("WARNING: Volume groups with missing PVs will be imported with --force."); |
3ab46449 JB |
90 | cmd->handles_missing_pvs = 1; |
91 | } | |
92 | ||
b4402bd8 DT |
93 | return process_each_vg(cmd, argc, argv, NULL, NULL, READ_FOR_UPDATE, |
94 | 0, NULL, &_vgimport_single); | |
5a52dca9 | 95 | } |