]>
Commit | Line | Data |
---|---|---|
34e1c94b | 1 | /* |
67cdbd7e | 2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. |
be684599 | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
34e1c94b | 4 | * |
6606c3ae | 5 | * This file is part of LVM2. |
34e1c94b | 6 | * |
6606c3ae AK |
7 | * This copyrighted material is made available to anyone wishing to use, |
8 | * modify, copy, or redistribute it subject to the terms and conditions | |
be684599 | 9 | * of the GNU Lesser General Public License v.2.1. |
34e1c94b | 10 | * |
be684599 | 11 | * You should have received a copy of the GNU Lesser General Public License |
6606c3ae AK |
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 | |
34e1c94b AK |
14 | */ |
15 | ||
16 | #include "tools.h" | |
17 | ||
5a52dca9 | 18 | static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv, |
08f1ddea | 19 | void *handle __attribute__((unused))) |
34e1c94b | 20 | { |
199e490e | 21 | struct lvinfo info; |
e6493477 AK |
22 | int inkernel, snap_active = 1; |
23 | struct lv_segment *snap_seg = NULL; | |
8191fe4f | 24 | percent_t snap_percent; /* fused, fsize; */ |
34e1c94b | 25 | |
34e1c94b AK |
26 | const char *active_str, *snapshot_str; |
27 | ||
afd9ba98 | 28 | if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv)) |
191abde9 AK |
29 | return ECMD_PROCESSED; |
30 | ||
401a40d9 | 31 | inkernel = lv_info(cmd, lv, 0, &info, 0, 0) && info.exists; |
e6493477 | 32 | if (lv_is_origin(lv)) { |
2c44337b | 33 | dm_list_iterate_items_gen(snap_seg, &lv->snapshot_segs, |
e6493477 AK |
34 | origin_list) { |
35 | if (inkernel && | |
36 | (snap_active = lv_snapshot_percent(snap_seg->cow, | |
8191fe4f PR |
37 | &snap_percent))) |
38 | if (snap_percent == PERCENT_INVALID) | |
e6493477 AK |
39 | snap_active = 0; |
40 | } | |
41 | snap_seg = NULL; | |
2cd0aa72 | 42 | } else if (lv_is_cow(lv)) { |
e6493477 | 43 | if (inkernel && |
8191fe4f PR |
44 | (snap_active = lv_snapshot_percent(lv, &snap_percent))) |
45 | if (snap_percent == PERCENT_INVALID) | |
e6493477 AK |
46 | snap_active = 0; |
47 | } | |
48 | ||
8ef2b021 | 49 | /* FIXME Add -D arg to skip this! */ |
e6493477 | 50 | if (inkernel && snap_active) |
9b7742bb | 51 | active_str = "ACTIVE "; |
41967a02 | 52 | else |
9b7742bb | 53 | active_str = "inactive "; |
34e1c94b | 54 | |
b6afcf64 | 55 | if (lv_is_origin(lv)) |
9b7742bb | 56 | snapshot_str = "Original"; |
b6afcf64 | 57 | else if (lv_is_cow(lv)) |
9b7742bb AK |
58 | snapshot_str = "Snapshot"; |
59 | else | |
60 | snapshot_str = " "; | |
34e1c94b | 61 | |
5a52dca9 | 62 | log_print("%s%s '%s%s/%s' [%s] %s", active_str, snapshot_str, |
4c64ed4c | 63 | cmd->dev_dir, lv->vg->name, lv->name, |
72b2cb61 | 64 | display_size(cmd, lv->size), |
097d49e7 | 65 | get_alloc_string(lv->alloc)); |
34e1c94b | 66 | |
cfb7bfc7 | 67 | return ECMD_PROCESSED; |
34e1c94b | 68 | } |
5a52dca9 AK |
69 | |
70 | int lvscan(struct cmd_context *cmd, int argc, char **argv) | |
71 | { | |
72 | if (argc) { | |
73 | log_error("No additional command line arguments allowed"); | |
74 | return EINVALID_CMD_LINE; | |
75 | } | |
76 | ||
13e8c7e4 | 77 | return process_each_lv(cmd, argc, argv, 0, NULL, |
5a52dca9 AK |
78 | &lvscan_single); |
79 | } |