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