Tizen 2.1 base
[external/device-mapper.git] / tools / vgscan.c
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3  * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
4  *
5  * This file is part of LVM2.
6  *
7  * This copyrighted material is made available to anyone wishing to use,
8  * modify, copy, or redistribute it subject to the terms and conditions
9  * of the GNU Lesser General Public License v.2.1.
10  *
11  * You should have received a copy of the GNU Lesser General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14  */
15
16 #include "tools.h"
17
18 static int vgscan_single(struct cmd_context *cmd, const char *vg_name,
19                          struct volume_group *vg,
20                          void *handle __attribute__((unused)))
21 {
22         log_print("Found %svolume group \"%s\" using metadata type %s",
23                   vg_is_exported(vg) ? "exported " : "", vg_name,
24                   vg->fid->fmt->name);
25
26         check_current_backup(vg);
27
28         return ECMD_PROCESSED;
29 }
30
31 int vgscan(struct cmd_context *cmd, int argc, char **argv)
32 {
33         int maxret, ret;
34
35         if (argc) {
36                 log_error("Too many parameters on command line");
37                 return EINVALID_CMD_LINE;
38         }
39
40         if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE)) {
41                 log_error("Unable to obtain global lock.");
42                 return ECMD_FAILED;
43         }
44
45         persistent_filter_wipe(cmd->filter);
46         lvmcache_destroy(cmd, 1);
47
48         log_print("Reading all physical volumes.  This may take a while...");
49
50         maxret = process_each_vg(cmd, argc, argv, 0, NULL,
51                                  &vgscan_single);
52
53         if (arg_count(cmd, mknodes_ARG)) {
54                 ret = vgmknodes(cmd, argc, argv);
55                 if (ret > maxret)
56                         maxret = ret;
57         }
58
59         unlock_vg(cmd, VG_GLOBAL);
60         return maxret;
61 }