xref: /netbsd-src/external/gpl2/lvm2/dist/tools/vgscan.c (revision 7c604eea85b4f330dc75ffe65e947f4d73758aa0)
1*7c604eeaShaad /*	$NetBSD: vgscan.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 
vgscan_single(struct cmd_context * cmd,const char * vg_name,struct volume_group * vg,void * handle __attribute ((unused)))2056a34939Shaad static int vgscan_single(struct cmd_context *cmd, const char *vg_name,
21*7c604eeaShaad 			 struct volume_group *vg,
2256a34939Shaad 			 void *handle __attribute((unused)))
2356a34939Shaad {
2456a34939Shaad 	log_print("Found %svolume group \"%s\" using metadata type %s",
25*7c604eeaShaad 		  vg_is_exported(vg) ? "exported " : "", vg_name,
2656a34939Shaad 		  vg->fid->fmt->name);
2756a34939Shaad 
2856a34939Shaad 	check_current_backup(vg);
2956a34939Shaad 
3056a34939Shaad 	return ECMD_PROCESSED;
3156a34939Shaad }
3256a34939Shaad 
vgscan(struct cmd_context * cmd,int argc,char ** argv)3356a34939Shaad int vgscan(struct cmd_context *cmd, int argc, char **argv)
3456a34939Shaad {
3556a34939Shaad 	int maxret, ret;
3656a34939Shaad 
3756a34939Shaad 	if (argc) {
3856a34939Shaad 		log_error("Too many parameters on command line");
3956a34939Shaad 		return EINVALID_CMD_LINE;
4056a34939Shaad 	}
4156a34939Shaad 
4256a34939Shaad 	if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE)) {
4356a34939Shaad 		log_error("Unable to obtain global lock.");
4456a34939Shaad 		return ECMD_FAILED;
4556a34939Shaad 	}
4656a34939Shaad 
4756a34939Shaad 	persistent_filter_wipe(cmd->filter);
4856a34939Shaad 	lvmcache_destroy(cmd, 1);
4956a34939Shaad 
5056a34939Shaad 	log_print("Reading all physical volumes.  This may take a while...");
5156a34939Shaad 
52*7c604eeaShaad 	maxret = process_each_vg(cmd, argc, argv, 0, NULL,
5356a34939Shaad 				 &vgscan_single);
5456a34939Shaad 
5556a34939Shaad 	if (arg_count(cmd, mknodes_ARG)) {
5656a34939Shaad 		ret = vgmknodes(cmd, argc, argv);
5756a34939Shaad 		if (ret > maxret)
5856a34939Shaad 			maxret = ret;
5956a34939Shaad 	}
6056a34939Shaad 
6156a34939Shaad 	unlock_vg(cmd, VG_GLOBAL);
6256a34939Shaad 	return maxret;
6356a34939Shaad }
64