1 /*        $NetBSD: vgscan.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 
vgscan_single(struct cmd_context * cmd,const char * vg_name,struct volume_group * vg,void * handle __attribute ((unused)))20 static int vgscan_single(struct cmd_context *cmd, const char *vg_name,
21                                struct volume_group *vg,
22                                void *handle __attribute((unused)))
23 {
24           log_print("Found %svolume group \"%s\" using metadata type %s",
25                       vg_is_exported(vg) ? "exported " : "", vg_name,
26                       vg->fid->fmt->name);
27 
28           check_current_backup(vg);
29 
30           return ECMD_PROCESSED;
31 }
32 
vgscan(struct cmd_context * cmd,int argc,char ** argv)33 int vgscan(struct cmd_context *cmd, int argc, char **argv)
34 {
35           int maxret, ret;
36 
37           if (argc) {
38                     log_error("Too many parameters on command line");
39                     return EINVALID_CMD_LINE;
40           }
41 
42           if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE)) {
43                     log_error("Unable to obtain global lock.");
44                     return ECMD_FAILED;
45           }
46 
47           persistent_filter_wipe(cmd->filter);
48           lvmcache_destroy(cmd, 1);
49 
50           log_print("Reading all physical volumes.  This may take a while...");
51 
52           maxret = process_each_vg(cmd, argc, argv, 0, NULL,
53                                          &vgscan_single);
54 
55           if (arg_count(cmd, mknodes_ARG)) {
56                     ret = vgmknodes(cmd, argc, argv);
57                     if (ret > maxret)
58                               maxret = ret;
59           }
60 
61           unlock_vg(cmd, VG_GLOBAL);
62           return maxret;
63 }
64