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