xref: /netbsd-src/external/gpl2/lvm2/dist/tools/vgimport.c (revision 7c604eea85b4f330dc75ffe65e947f4d73758aa0)
1*7c604eeaShaad /*	$NetBSD: vgimport.c,v 1.1.1.2 2009/12/02 00:25:57 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 
vgimport_single(struct cmd_context * cmd __attribute ((unused)),const char * vg_name,struct volume_group * vg,void * handle __attribute ((unused)))2056a34939Shaad static int vgimport_single(struct cmd_context *cmd __attribute((unused)),
2156a34939Shaad 			   const char *vg_name,
22*7c604eeaShaad 			   struct volume_group *vg,
2356a34939Shaad 			   void *handle __attribute((unused)))
2456a34939Shaad {
2556a34939Shaad 	struct pv_list *pvl;
2656a34939Shaad 	struct physical_volume *pv;
2756a34939Shaad 
28*7c604eeaShaad 	if (!vg_is_exported(vg)) {
2956a34939Shaad 		log_error("Volume group \"%s\" is not exported", vg_name);
30*7c604eeaShaad 		goto bad;
3156a34939Shaad 	}
3256a34939Shaad 
3356a34939Shaad 	if (vg_status(vg) & PARTIAL_VG) {
3456a34939Shaad 		log_error("Volume group \"%s\" is partially missing", vg_name);
35*7c604eeaShaad 		goto bad;
3656a34939Shaad 	}
3756a34939Shaad 
3856a34939Shaad 	if (!archive(vg))
39*7c604eeaShaad 		goto_bad;
4056a34939Shaad 
4156a34939Shaad 	vg->status &= ~EXPORTED_VG;
4256a34939Shaad 
4356a34939Shaad 	dm_list_iterate_items(pvl, &vg->pvs) {
4456a34939Shaad 		pv = pvl->pv;
4556a34939Shaad 		pv->status &= ~EXPORTED_VG;
4656a34939Shaad 	}
4756a34939Shaad 
4856a34939Shaad 	if (!vg_write(vg) || !vg_commit(vg))
49*7c604eeaShaad 		goto_bad;
5056a34939Shaad 
5156a34939Shaad 	backup(vg);
5256a34939Shaad 
5356a34939Shaad 	log_print("Volume group \"%s\" successfully imported", vg->name);
5456a34939Shaad 
5556a34939Shaad 	return ECMD_PROCESSED;
5656a34939Shaad 
57*7c604eeaShaad bad:
5856a34939Shaad 	return ECMD_FAILED;
5956a34939Shaad }
6056a34939Shaad 
vgimport(struct cmd_context * cmd,int argc,char ** argv)6156a34939Shaad int vgimport(struct cmd_context *cmd, int argc, char **argv)
6256a34939Shaad {
6356a34939Shaad 	if (!argc && !arg_count(cmd, all_ARG)) {
6456a34939Shaad 		log_error("Please supply volume groups or use -a for all.");
6556a34939Shaad 		return ECMD_FAILED;
6656a34939Shaad 	}
6756a34939Shaad 
6856a34939Shaad 	if (argc && arg_count(cmd, all_ARG)) {
6956a34939Shaad 		log_error("No arguments permitted when using -a for all.");
7056a34939Shaad 		return ECMD_FAILED;
7156a34939Shaad 	}
7256a34939Shaad 
73*7c604eeaShaad 	return process_each_vg(cmd, argc, argv,
74*7c604eeaShaad 			       READ_FOR_UPDATE | READ_ALLOW_EXPORTED,
75*7c604eeaShaad 			       NULL,
7656a34939Shaad 			       &vgimport_single);
7756a34939Shaad }
78