]> sourceware.org Git - lvm2.git/blame - tools/vgimport.c
pre-release
[lvm2.git] / tools / vgimport.c
CommitLineData
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
AK
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
2235e241
AK
14 */
15
16#include "tools.h"
17
08f1ddea 18static int vgimport_single(struct cmd_context *cmd __attribute__((unused)),
72b2cb61 19 const char *vg_name,
13e8c7e4 20 struct volume_group *vg,
08f1ddea 21 void *handle __attribute__((unused)))
2235e241 22{
a5fe5a7c
AK
23 struct pv_list *pvl;
24 struct physical_volume *pv;
25
905240f9 26 if (!vg_is_exported(vg)) {
08907484 27 log_error("Volume group \"%s\" is not exported", vg_name);
651ff9b3 28 goto bad;
2235e241
AK
29 }
30
69483a8a 31 if (vg_status(vg) & PARTIAL_VG) {
08907484 32 log_error("Volume group \"%s\" is partially missing", vg_name);
651ff9b3 33 goto bad;
2235e241
AK
34 }
35
36 if (!archive(vg))
651ff9b3 37 goto_bad;
2235e241
AK
38
39 vg->status &= ~EXPORTED_VG;
40
2c44337b 41 dm_list_iterate_items(pvl, &vg->pvs) {
a5fe5a7c
AK
42 pv = pvl->pv;
43 pv->status &= ~EXPORTED_VG;
44 }
45
914c9723 46 if (!vg_write(vg) || !vg_commit(vg))
651ff9b3 47 goto_bad;
2235e241
AK
48
49 backup(vg);
50
08907484 51 log_print("Volume group \"%s\" successfully imported", vg->name);
6fda126d 52
cfb7bfc7 53 return ECMD_PROCESSED;
7d0e6e80 54
651ff9b3 55bad:
7d0e6e80 56 return ECMD_FAILED;
2235e241 57}
5a52dca9
AK
58
59int vgimport(struct cmd_context *cmd, int argc, char **argv)
60{
61 if (!argc && !arg_count(cmd, all_ARG)) {
62 log_error("Please supply volume groups or use -a for all.");
63 return ECMD_FAILED;
64 }
65
66 if (argc && arg_count(cmd, all_ARG)) {
67 log_error("No arguments permitted when using -a for all.");
68 return ECMD_FAILED;
69 }
70
13e8c7e4
DW
71 return process_each_vg(cmd, argc, argv,
72 READ_FOR_UPDATE | READ_ALLOW_EXPORTED,
73 NULL,
5a52dca9
AK
74 &vgimport_single);
75}
This page took 0.09482 seconds and 5 git commands to generate.