xref: /dragonfly/contrib/lvm2/dist/tools/vgexport.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1 /*        $NetBSD: vgexport.c,v 1.1.1.2 2009/12/02 00:25:57 haad Exp $          */
2 
3 /*
4  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5  * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
6  *
7  * This file is part of LVM2.
8  *
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.
12  *
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
16  */
17 
18 #include "tools.h"
19 
vgexport_single(struct cmd_context * cmd __attribute ((unused)),const char * vg_name,struct volume_group * vg,void * handle __attribute ((unused)))20 static int vgexport_single(struct cmd_context *cmd __attribute((unused)),
21                                  const char *vg_name,
22                                  struct volume_group *vg,
23                                  void *handle __attribute((unused)))
24 {
25           struct pv_list *pvl;
26           struct physical_volume *pv;
27 
28           if (lvs_in_vg_activated(vg)) {
29                     log_error("Volume group \"%s\" has active logical volumes",
30                                 vg_name);
31                     goto bad;
32           }
33 
34           if (!archive(vg))
35                     goto_bad;
36 
37           vg->status |= EXPORTED_VG;
38 
39           dm_list_iterate_items(pvl, &vg->pvs) {
40                     pv = pvl->pv;
41                     pv->status |= EXPORTED_VG;
42           }
43 
44           if (!vg_write(vg) || !vg_commit(vg))
45                     goto_bad;
46 
47           backup(vg);
48 
49           log_print("Volume group \"%s\" successfully exported", vg->name);
50 
51           return ECMD_PROCESSED;
52 
53 bad:
54           return ECMD_FAILED;
55 }
56 
vgexport(struct cmd_context * cmd,int argc,char ** argv)57 int vgexport(struct cmd_context *cmd, int argc, char **argv)
58 {
59           if (!argc && !arg_count(cmd, all_ARG)) {
60                     log_error("Please supply volume groups or use -a for all.");
61                     return ECMD_FAILED;
62           }
63 
64           if (argc && arg_count(cmd, all_ARG)) {
65                     log_error("No arguments permitted when using -a for all.");
66                     return ECMD_FAILED;
67           }
68 
69           return process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL,
70                                      &vgexport_single);
71 }
72