xref: /netbsd-src/external/gpl2/lvm2/dist/tools/vgremove.c (revision 7c604eea85b4f330dc75ffe65e947f4d73758aa0)
1*7c604eeaShaad /*	$NetBSD: vgremove.c,v 1.1.1.2 2009/12/02 00:25:58 haad Exp $	*/
256a34939Shaad 
356a34939Shaad /*
456a34939Shaad  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5*7c604eeaShaad  * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
656a34939Shaad  *
756a34939Shaad  * This file is part of LVM2.
856a34939Shaad  *
956a34939Shaad  * This copyrighted material is made available to anyone wishing to use,
1056a34939Shaad  * modify, copy, or redistribute it subject to the terms and conditions
1156a34939Shaad  * of the GNU Lesser General Public License v.2.1.
1256a34939Shaad  *
1356a34939Shaad  * You should have received a copy of the GNU Lesser General Public License
1456a34939Shaad  * along with this program; if not, write to the Free Software Foundation,
1556a34939Shaad  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1656a34939Shaad  */
1756a34939Shaad 
1856a34939Shaad #include "tools.h"
1956a34939Shaad 
vgremove_single(struct cmd_context * cmd,const char * vg_name,struct volume_group * vg,void * handle __attribute ((unused)))2056a34939Shaad static int vgremove_single(struct cmd_context *cmd, const char *vg_name,
21*7c604eeaShaad 			   struct volume_group *vg,
2256a34939Shaad 			   void *handle __attribute((unused)))
2356a34939Shaad {
24*7c604eeaShaad 	unsigned lv_count;
25*7c604eeaShaad 	force_t force;
26*7c604eeaShaad 
27*7c604eeaShaad 	if (!vg_check_status(vg, EXPORTED_VG)) {
28*7c604eeaShaad 		stack;
2956a34939Shaad 		return ECMD_FAILED;
30*7c604eeaShaad 	}
31*7c604eeaShaad 
32*7c604eeaShaad 	lv_count = vg_visible_lvs(vg);
33*7c604eeaShaad 
34*7c604eeaShaad 	force = arg_count(cmd, force_ARG);
35*7c604eeaShaad 	if (lv_count) {
36*7c604eeaShaad 		if ((force == PROMPT) &&
37*7c604eeaShaad 		    (yes_no_prompt("Do you really want to remove volume "
38*7c604eeaShaad 				   "group \"%s\" containing %u "
39*7c604eeaShaad 				   "logical volumes? [y/n]: ",
40*7c604eeaShaad 				   vg_name, lv_count) == 'n')) {
41*7c604eeaShaad 			log_print("Volume group \"%s\" not removed", vg_name);
42*7c604eeaShaad 			return ECMD_FAILED;
43*7c604eeaShaad 		}
44*7c604eeaShaad 		if (!remove_lvs_in_vg(cmd, vg, force)) {
45*7c604eeaShaad 			stack;
46*7c604eeaShaad 			return ECMD_FAILED;
47*7c604eeaShaad 		}
48*7c604eeaShaad 	}
49*7c604eeaShaad 
50*7c604eeaShaad 	if (!vg_remove_check(vg)) {
51*7c604eeaShaad 		stack;
52*7c604eeaShaad 		return ECMD_FAILED;
53*7c604eeaShaad 	}
54*7c604eeaShaad 
55*7c604eeaShaad 	if (!vg_remove(vg)) {
56*7c604eeaShaad 		stack;
57*7c604eeaShaad 		return ECMD_FAILED;
58*7c604eeaShaad 	}
5956a34939Shaad 
6056a34939Shaad 	return ECMD_PROCESSED;
6156a34939Shaad }
6256a34939Shaad 
vgremove(struct cmd_context * cmd,int argc,char ** argv)6356a34939Shaad int vgremove(struct cmd_context *cmd, int argc, char **argv)
6456a34939Shaad {
6556a34939Shaad 	int ret;
6656a34939Shaad 
6756a34939Shaad 	if (!argc) {
6856a34939Shaad 		log_error("Please enter one or more volume group paths");
6956a34939Shaad 		return EINVALID_CMD_LINE;
7056a34939Shaad 	}
7156a34939Shaad 
7256a34939Shaad 	ret = process_each_vg(cmd, argc, argv,
73*7c604eeaShaad 			      READ_FOR_UPDATE,
7456a34939Shaad 			      NULL, &vgremove_single);
7556a34939Shaad 
7656a34939Shaad 	return ret;
7756a34939Shaad }
78