xref: /dragonfly/contrib/lvm2/dist/tools/vgremove.c (revision ef2b2b9d)
1 /*	$NetBSD: vgremove.c,v 1.1.1.2 2009/12/02 00:25:58 haad Exp $	*/
2 
3 /*
4  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5  * Copyright (C) 2004-2009 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 
20 static int vgremove_single(struct cmd_context *cmd, const char *vg_name,
21 			   struct volume_group *vg,
22 			   void *handle __attribute((unused)))
23 {
24 	unsigned lv_count;
25 	force_t force;
26 
27 	if (!vg_check_status(vg, EXPORTED_VG)) {
28 		stack;
29 		return ECMD_FAILED;
30 	}
31 
32 	lv_count = vg_visible_lvs(vg);
33 
34 	force = arg_count(cmd, force_ARG);
35 	if (lv_count) {
36 		if ((force == PROMPT) &&
37 		    (yes_no_prompt("Do you really want to remove volume "
38 				   "group \"%s\" containing %u "
39 				   "logical volumes? [y/n]: ",
40 				   vg_name, lv_count) == 'n')) {
41 			log_print("Volume group \"%s\" not removed", vg_name);
42 			return ECMD_FAILED;
43 		}
44 		if (!remove_lvs_in_vg(cmd, vg, force)) {
45 			stack;
46 			return ECMD_FAILED;
47 		}
48 	}
49 
50 	if (!vg_remove_check(vg)) {
51 		stack;
52 		return ECMD_FAILED;
53 	}
54 
55 	if (!vg_remove(vg)) {
56 		stack;
57 		return ECMD_FAILED;
58 	}
59 
60 	return ECMD_PROCESSED;
61 }
62 
63 int vgremove(struct cmd_context *cmd, int argc, char **argv)
64 {
65 	int ret;
66 
67 	if (!argc) {
68 		log_error("Please enter one or more volume group paths");
69 		return EINVALID_CMD_LINE;
70 	}
71 
72 	ret = process_each_vg(cmd, argc, argv,
73 			      READ_FOR_UPDATE,
74 			      NULL, &vgremove_single);
75 
76 	return ret;
77 }
78