Tizen 2.1 base
[external/device-mapper.git] / tools / lvscan.c
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3  * Copyright (C) 2004-2006 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 lvscan_single(struct cmd_context *cmd, struct logical_volume *lv,
19                          void *handle __attribute__((unused)))
20 {
21         struct lvinfo info;
22         int lv_total = 0;
23         uint64_t lv_capacity_total = 0;
24         int inkernel, snap_active = 1;
25         struct lv_segment *snap_seg = NULL;
26         percent_t snap_percent;     /* fused, fsize; */
27
28         const char *active_str, *snapshot_str;
29
30         if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
31                 return ECMD_PROCESSED;
32
33         inkernel = lv_info(cmd, lv, 0, &info, 1, 0) && info.exists;
34         if (lv_is_origin(lv)) {
35                 dm_list_iterate_items_gen(snap_seg, &lv->snapshot_segs,
36                                        origin_list) {
37                         if (inkernel &&
38                             (snap_active = lv_snapshot_percent(snap_seg->cow,
39                                                                &snap_percent)))
40                                 if (snap_percent == PERCENT_INVALID)
41                                         snap_active = 0;
42                 }
43                 snap_seg = NULL;
44         } else if (lv_is_cow(lv)) {
45                 if (inkernel &&
46                     (snap_active = lv_snapshot_percent(lv, &snap_percent)))
47                         if (snap_percent == PERCENT_INVALID)
48                                 snap_active = 0;
49         }
50
51 /* FIXME Add -D arg to skip this! */
52         if (inkernel && snap_active)
53                 active_str = "ACTIVE   ";
54         else
55                 active_str = "inactive ";
56
57         if (lv_is_origin(lv))
58                 snapshot_str = "Original";
59         else if (lv_is_cow(lv))
60                 snapshot_str = "Snapshot";
61         else
62                 snapshot_str = "        ";
63
64         log_print("%s%s '%s%s/%s' [%s] %s", active_str, snapshot_str,
65                   cmd->dev_dir, lv->vg->name, lv->name,
66                   display_size(cmd, lv->size),
67                   get_alloc_string(lv->alloc));
68
69         lv_total++;
70
71         lv_capacity_total += lv->size;
72
73         return ECMD_PROCESSED;
74 }
75
76 int lvscan(struct cmd_context *cmd, int argc, char **argv)
77 {
78         if (argc) {
79                 log_error("No additional command line arguments allowed");
80                 return EINVALID_CMD_LINE;
81         }
82
83         return process_each_lv(cmd, argc, argv, 0, NULL,
84                                &lvscan_single);
85 }