]>
Commit | Line | Data |
---|---|---|
f53c6aa6 | 1 | /* |
67cdbd7e | 2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. |
be684599 | 3 | * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. |
f53c6aa6 | 4 | * |
6606c3ae | 5 | * This file is part of LVM2. |
f53c6aa6 | 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. |
f53c6aa6 | 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 | |
f53c6aa6 AK |
14 | */ |
15 | ||
16 | #include "tools.h" | |
17 | ||
08f1ddea | 18 | static int vgexport_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))) |
f53c6aa6 | 22 | { |
a5fe5a7c AK |
23 | struct pv_list *pvl; |
24 | struct physical_volume *pv; | |
25 | ||
f53c6aa6 | 26 | if (lvs_in_vg_activated(vg)) { |
6fda126d | 27 | log_error("Volume group \"%s\" has active logical volumes", |
f53c6aa6 | 28 | vg_name); |
651ff9b3 | 29 | goto bad; |
f53c6aa6 AK |
30 | } |
31 | ||
32 | if (!archive(vg)) | |
651ff9b3 | 33 | goto_bad; |
f53c6aa6 AK |
34 | |
35 | vg->status |= EXPORTED_VG; | |
36 | ||
2c44337b | 37 | dm_list_iterate_items(pvl, &vg->pvs) { |
a5fe5a7c AK |
38 | pv = pvl->pv; |
39 | pv->status |= EXPORTED_VG; | |
40 | } | |
41 | ||
914c9723 | 42 | if (!vg_write(vg) || !vg_commit(vg)) |
651ff9b3 | 43 | goto_bad; |
f53c6aa6 AK |
44 | |
45 | backup(vg); | |
46 | ||
08907484 | 47 | log_print("Volume group \"%s\" successfully exported", vg->name); |
6fda126d | 48 | |
cfb7bfc7 | 49 | return ECMD_PROCESSED; |
7d0e6e80 | 50 | |
651ff9b3 | 51 | bad: |
7d0e6e80 | 52 | return ECMD_FAILED; |
f53c6aa6 | 53 | } |
5a52dca9 AK |
54 | |
55 | int vgexport(struct cmd_context *cmd, int argc, char **argv) | |
56 | { | |
57 | if (!argc && !arg_count(cmd, all_ARG)) { | |
58 | log_error("Please supply volume groups or use -a for all."); | |
59 | return ECMD_FAILED; | |
60 | } | |
61 | ||
62 | if (argc && arg_count(cmd, all_ARG)) { | |
63 | log_error("No arguments permitted when using -a for all."); | |
64 | return ECMD_FAILED; | |
65 | } | |
66 | ||
13e8c7e4 | 67 | return process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL, |
5a52dca9 AK |
68 | &vgexport_single); |
69 | } |