]>
Commit | Line | Data |
---|---|---|
9e300c84 | 1 | /* |
6606c3ae AK |
2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. |
3 | * Copyright (C) 2004 Red Hat, Inc. All rights reserved. | |
9e300c84 | 4 | * |
6606c3ae | 5 | * This file is part of LVM2. |
9e300c84 | 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 | |
9 | * of the GNU General Public License v.2. | |
9e300c84 AK |
10 | * |
11 | * You should have received a copy of the GNU 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 | |
9e300c84 AK |
14 | */ |
15 | ||
16 | #include "tools.h" | |
17 | ||
9e300c84 AK |
18 | int pv_max_name_len = 0; |
19 | int vg_max_name_len = 0; | |
20 | ||
8ef2b021 AK |
21 | static void _pvscan_display_single(struct cmd_context *cmd, |
22 | struct physical_volume *pv, void *handle) | |
5a52dca9 AK |
23 | { |
24 | char uuid[64]; | |
8ef2b021 | 25 | unsigned int vg_name_len = 0; |
5a52dca9 | 26 | |
5a52dca9 AK |
27 | char pv_tmp_name[NAME_LEN] = { 0, }; |
28 | char vg_tmp_name[NAME_LEN] = { 0, }; | |
29 | char vg_name_this[NAME_LEN] = { 0, }; | |
30 | ||
31 | /* short listing? */ | |
32 | if (arg_count(cmd, short_ARG) > 0) { | |
33 | log_print("%s", dev_name(pv->dev)); | |
34 | return; | |
35 | } | |
36 | ||
37 | if (arg_count(cmd, verbose_ARG) > 1) { | |
38 | /* FIXME As per pv_display! Drop through for now. */ | |
39 | /* pv_show(pv); */ | |
40 | ||
41 | /* FIXME - Moved to Volume Group structure */ | |
42 | /* log_print("System Id %s", pv->vg->system_id); */ | |
43 | ||
44 | /* log_print(" "); */ | |
45 | /* return; */ | |
46 | } | |
47 | ||
48 | memset(pv_tmp_name, 0, sizeof(pv_tmp_name)); | |
49 | ||
50 | vg_name_len = strlen(pv->vg_name) + 1; | |
51 | ||
52 | if (arg_count(cmd, uuid_ARG)) { | |
53 | if (!id_write_format(&pv->id, uuid, sizeof(uuid))) { | |
54 | stack; | |
55 | return; | |
56 | } | |
57 | ||
58 | sprintf(pv_tmp_name, "%-*s with UUID %s", | |
59 | pv_max_name_len - 2, dev_name(pv->dev), uuid); | |
60 | } else { | |
61 | sprintf(pv_tmp_name, "%s", dev_name(pv->dev)); | |
62 | } | |
63 | ||
64 | if (!*pv->vg_name) { | |
65 | log_print("PV %-*s %-*s %s [%s]", | |
66 | pv_max_name_len, pv_tmp_name, | |
67 | vg_max_name_len, " ", | |
68 | pv->fmt ? pv->fmt->name : " ", | |
30bab85b | 69 | display_size(cmd, pv->size, SIZE_SHORT)); |
5a52dca9 AK |
70 | return; |
71 | } | |
72 | ||
73 | if (pv->status & EXPORTED_VG) { | |
74 | strncpy(vg_name_this, pv->vg_name, vg_name_len); | |
75 | log_print("PV %-*s is in exported VG %s " | |
76 | "[%s / %s free]", | |
77 | pv_max_name_len, pv_tmp_name, | |
4c64ed4c | 78 | vg_name_this, |
8ef2b021 | 79 | display_size(cmd, (uint64_t) pv->pe_count * |
30bab85b | 80 | pv->pe_size, SIZE_SHORT), |
8ef2b021 AK |
81 | display_size(cmd, (uint64_t) (pv->pe_count - |
82 | pv->pe_alloc_count) | |
30bab85b | 83 | * pv->pe_size, SIZE_SHORT)); |
5a52dca9 AK |
84 | return; |
85 | } | |
86 | ||
87 | sprintf(vg_tmp_name, "%s", pv->vg_name); | |
30bab85b AK |
88 | log_print("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len, |
89 | pv_tmp_name, vg_max_name_len, vg_tmp_name, | |
90 | pv->fmt ? pv->fmt->name : " ", | |
91 | display_size(cmd, (uint64_t) pv->pe_count * pv->pe_size, | |
92 | SIZE_SHORT), | |
93 | display_size(cmd, | |
94 | (uint64_t) (pv->pe_count - pv->pe_alloc_count) * | |
95 | pv->pe_size, | |
96 | SIZE_SHORT)); | |
5a52dca9 AK |
97 | return; |
98 | } | |
99 | ||
60274aba | 100 | int pvscan(struct cmd_context *cmd, int argc, char **argv) |
9e300c84 AK |
101 | { |
102 | int new_pvs_found = 0; | |
103 | int pvs_found = 0; | |
9e300c84 | 104 | |
8ef2b021 | 105 | struct list *pvslist; |
b6c041d7 | 106 | struct pv_list *pvl; |
9e300c84 AK |
107 | struct physical_volume *pv; |
108 | ||
ee1f91bf AK |
109 | uint64_t size_total = 0; |
110 | uint64_t size_new = 0; | |
9e300c84 AK |
111 | |
112 | int len = 0; | |
113 | pv_max_name_len = 0; | |
114 | vg_max_name_len = 0; | |
115 | ||
6fda126d | 116 | if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) { |
b6c041d7 | 117 | log_error("Options -e and -n are incompatible"); |
ee1f91bf | 118 | return EINVALID_CMD_LINE; |
9e300c84 AK |
119 | } |
120 | ||
6fda126d | 121 | if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG)) |
9e300c84 | 122 | log_print("WARNING: only considering physical volumes %s", |
6fda126d | 123 | arg_count(cmd, exported_ARG) ? |
9e300c84 AK |
124 | "of exported volume group(s)" : "in no volume group"); |
125 | ||
60274aba | 126 | persistent_filter_wipe(cmd->filter); |
914c9723 | 127 | lvmcache_destroy(); |
5a52dca9 | 128 | |
d2393d23 | 129 | log_verbose("Walking through all physical volumes"); |
8ef2b021 | 130 | if (!(pvslist = get_pvs(cmd))) |
ee1f91bf | 131 | return ECMD_FAILED; |
9e300c84 AK |
132 | |
133 | /* eliminate exported/new if required */ | |
f2b7349e | 134 | list_iterate_items(pvl, pvslist) { |
cc282870 | 135 | pv = pvl->pv; |
9e300c84 | 136 | |
25b73380 | 137 | if ((arg_count(cmd, exported_ARG) |
6fda126d AK |
138 | && !(pv->status & EXPORTED_VG)) |
139 | || (arg_count(cmd, novolumegroup_ARG) && (*pv->vg_name))) { | |
1b9fcf48 | 140 | list_del(&pvl->list); |
9e300c84 AK |
141 | continue; |
142 | } | |
143 | ||
144 | /* Also check for MD use? */ | |
145 | /******* | |
146 | if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) { | |
147 | log_print | |
148 | ("WARNING: physical volume \"%s\" belongs to a meta device", | |
149 | pv[p]->pv_name); | |
150 | } | |
151 | if (MAJOR(pv[p]->pv_dev) != MD_MAJOR) | |
152 | continue; | |
153 | ********/ | |
154 | pvs_found++; | |
25d42d50 | 155 | |
b6c041d7 | 156 | if (!*pv->vg_name) { |
9e300c84 | 157 | new_pvs_found++; |
b6c041d7 AK |
158 | size_new += pv->size; |
159 | size_total += pv->size; | |
1b9fcf48 | 160 | } else |
607131b6 | 161 | size_total += pv->pe_count * pv->pe_size; |
9e300c84 AK |
162 | } |
163 | ||
164 | /* find maximum pv name length */ | |
165 | pv_max_name_len = vg_max_name_len = 0; | |
f2b7349e AK |
166 | list_iterate_items(pvl, pvslist) { |
167 | pv = pvl->pv; | |
c7f0b573 | 168 | len = strlen(dev_name(pv->dev)); |
9e300c84 AK |
169 | if (pv_max_name_len < len) |
170 | pv_max_name_len = len; | |
171 | len = strlen(pv->vg_name); | |
172 | if (vg_max_name_len < len) | |
173 | vg_max_name_len = len; | |
174 | } | |
175 | pv_max_name_len += 2; | |
176 | vg_max_name_len += 2; | |
177 | ||
f2b7349e AK |
178 | list_iterate_items(pvl, pvslist) |
179 | _pvscan_display_single(cmd, pvl->pv, NULL); | |
9e300c84 AK |
180 | |
181 | if (!pvs_found) { | |
182 | log_print("No matching physical volumes found"); | |
cfb7bfc7 | 183 | return ECMD_PROCESSED; |
9e300c84 AK |
184 | } |
185 | ||
b6c041d7 | 186 | log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]", |
9e300c84 | 187 | pvs_found, |
30bab85b | 188 | display_size(cmd, size_total, SIZE_SHORT), |
9e300c84 | 189 | pvs_found - new_pvs_found, |
30bab85b AK |
190 | display_size(cmd, (size_total - size_new), SIZE_SHORT), |
191 | new_pvs_found, display_size(cmd, size_new, SIZE_SHORT)); | |
9e300c84 | 192 | |
cfb7bfc7 | 193 | return ECMD_PROCESSED; |
9e300c84 | 194 | } |