]>
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 | ||
5a52dca9 AK |
26 | void pvscan_display_single(struct cmd_context *cmd, struct physical_volume *pv, |
27 | void *handle) | |
28 | { | |
29 | char uuid[64]; | |
30 | int vg_name_len = 0; | |
31 | ||
32 | char *s1, *s2; | |
33 | ||
34 | char pv_tmp_name[NAME_LEN] = { 0, }; | |
35 | char vg_tmp_name[NAME_LEN] = { 0, }; | |
36 | char vg_name_this[NAME_LEN] = { 0, }; | |
37 | ||
38 | /* short listing? */ | |
39 | if (arg_count(cmd, short_ARG) > 0) { | |
40 | log_print("%s", dev_name(pv->dev)); | |
41 | return; | |
42 | } | |
43 | ||
44 | if (arg_count(cmd, verbose_ARG) > 1) { | |
45 | /* FIXME As per pv_display! Drop through for now. */ | |
46 | /* pv_show(pv); */ | |
47 | ||
48 | /* FIXME - Moved to Volume Group structure */ | |
49 | /* log_print("System Id %s", pv->vg->system_id); */ | |
50 | ||
51 | /* log_print(" "); */ | |
52 | /* return; */ | |
53 | } | |
54 | ||
55 | memset(pv_tmp_name, 0, sizeof(pv_tmp_name)); | |
56 | ||
57 | vg_name_len = strlen(pv->vg_name) + 1; | |
58 | ||
59 | if (arg_count(cmd, uuid_ARG)) { | |
60 | if (!id_write_format(&pv->id, uuid, sizeof(uuid))) { | |
61 | stack; | |
62 | return; | |
63 | } | |
64 | ||
65 | sprintf(pv_tmp_name, "%-*s with UUID %s", | |
66 | pv_max_name_len - 2, dev_name(pv->dev), uuid); | |
67 | } else { | |
68 | sprintf(pv_tmp_name, "%s", dev_name(pv->dev)); | |
69 | } | |
70 | ||
71 | if (!*pv->vg_name) { | |
72 | log_print("PV %-*s %-*s %s [%s]", | |
73 | pv_max_name_len, pv_tmp_name, | |
74 | vg_max_name_len, " ", | |
75 | pv->fmt ? pv->fmt->name : " ", | |
76 | (s1 = display_size(pv->size / 2, SIZE_SHORT))); | |
77 | dbg_free(s1); | |
78 | return; | |
79 | } | |
80 | ||
81 | if (pv->status & EXPORTED_VG) { | |
82 | strncpy(vg_name_this, pv->vg_name, vg_name_len); | |
83 | log_print("PV %-*s is in exported VG %s " | |
84 | "[%s / %s free]", | |
85 | pv_max_name_len, pv_tmp_name, | |
86 | vg_name_this, (s1 = | |
87 | display_size(pv->pe_count * | |
88 | pv->pe_size / 2, | |
89 | SIZE_SHORT)), | |
90 | (s2 = display_size((pv->pe_count - pv->pe_alloc_count) | |
91 | * pv->pe_size / 2, SIZE_SHORT))); | |
92 | dbg_free(s1); | |
93 | dbg_free(s2); | |
94 | return; | |
95 | } | |
96 | ||
97 | sprintf(vg_tmp_name, "%s", pv->vg_name); | |
98 | log_print | |
99 | ("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len, | |
100 | pv_tmp_name, vg_max_name_len, vg_tmp_name, | |
101 | pv->fmt ? pv->fmt->name : " ", | |
102 | (s1 = display_size(pv->pe_count * pv->pe_size / 2, SIZE_SHORT)), | |
103 | (s2 = | |
104 | display_size((pv->pe_count - pv->pe_alloc_count) * pv->pe_size / | |
105 | 2, SIZE_SHORT))); | |
106 | dbg_free(s1); | |
107 | dbg_free(s2); | |
108 | ||
109 | return; | |
110 | } | |
111 | ||
60274aba | 112 | int pvscan(struct cmd_context *cmd, int argc, char **argv) |
9e300c84 AK |
113 | { |
114 | int new_pvs_found = 0; | |
115 | int pvs_found = 0; | |
116 | char *s1, *s2, *s3; | |
117 | ||
1b9fcf48 JT |
118 | struct list *pvs; |
119 | struct list *pvh; | |
b6c041d7 | 120 | struct pv_list *pvl; |
9e300c84 AK |
121 | struct physical_volume *pv; |
122 | ||
ee1f91bf AK |
123 | uint64_t size_total = 0; |
124 | uint64_t size_new = 0; | |
9e300c84 AK |
125 | |
126 | int len = 0; | |
127 | pv_max_name_len = 0; | |
128 | vg_max_name_len = 0; | |
129 | ||
6fda126d | 130 | if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) { |
b6c041d7 | 131 | log_error("Options -e and -n are incompatible"); |
ee1f91bf | 132 | return EINVALID_CMD_LINE; |
9e300c84 AK |
133 | } |
134 | ||
6fda126d | 135 | if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG)) |
9e300c84 | 136 | log_print("WARNING: only considering physical volumes %s", |
6fda126d | 137 | arg_count(cmd, exported_ARG) ? |
9e300c84 AK |
138 | "of exported volume group(s)" : "in no volume group"); |
139 | ||
d2393d23 | 140 | log_verbose("Wiping cache of LVM-capable devices"); |
60274aba | 141 | persistent_filter_wipe(cmd->filter); |
9e300c84 | 142 | |
5a52dca9 AK |
143 | log_verbose("Wiping internal cache"); |
144 | cache_destroy(); | |
145 | ||
d2393d23 | 146 | log_verbose("Walking through all physical volumes"); |
25b73380 | 147 | if (!(pvs = get_pvs(cmd))) |
ee1f91bf | 148 | return ECMD_FAILED; |
9e300c84 AK |
149 | |
150 | /* eliminate exported/new if required */ | |
1b9fcf48 JT |
151 | list_iterate(pvh, pvs) { |
152 | pvl = list_item(pvh, struct pv_list); | |
cc282870 | 153 | pv = pvl->pv; |
9e300c84 | 154 | |
25b73380 | 155 | if ((arg_count(cmd, exported_ARG) |
6fda126d AK |
156 | && !(pv->status & EXPORTED_VG)) |
157 | || (arg_count(cmd, novolumegroup_ARG) && (*pv->vg_name))) { | |
1b9fcf48 | 158 | list_del(&pvl->list); |
9e300c84 AK |
159 | continue; |
160 | } | |
161 | ||
162 | /* Also check for MD use? */ | |
163 | /******* | |
164 | if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) { | |
165 | log_print | |
166 | ("WARNING: physical volume \"%s\" belongs to a meta device", | |
167 | pv[p]->pv_name); | |
168 | } | |
169 | if (MAJOR(pv[p]->pv_dev) != MD_MAJOR) | |
170 | continue; | |
171 | ********/ | |
172 | pvs_found++; | |
25d42d50 | 173 | |
b6c041d7 | 174 | if (!*pv->vg_name) { |
9e300c84 | 175 | new_pvs_found++; |
b6c041d7 AK |
176 | size_new += pv->size; |
177 | size_total += pv->size; | |
1b9fcf48 | 178 | } else |
25b73380 | 179 | size_total += (pv->pe_count - pv->pe_alloc_count) |
6fda126d | 180 | * pv->pe_size; |
9e300c84 AK |
181 | } |
182 | ||
183 | /* find maximum pv name length */ | |
184 | pv_max_name_len = vg_max_name_len = 0; | |
1b9fcf48 | 185 | list_iterate(pvh, pvs) { |
cc282870 | 186 | pv = list_item(pvh, struct pv_list)->pv; |
c7f0b573 | 187 | len = strlen(dev_name(pv->dev)); |
9e300c84 AK |
188 | if (pv_max_name_len < len) |
189 | pv_max_name_len = len; | |
190 | len = strlen(pv->vg_name); | |
191 | if (vg_max_name_len < len) | |
192 | vg_max_name_len = len; | |
193 | } | |
194 | pv_max_name_len += 2; | |
195 | vg_max_name_len += 2; | |
196 | ||
1b9fcf48 | 197 | list_iterate(pvh, pvs) |
5a52dca9 AK |
198 | pvscan_display_single(cmd, list_item(pvh, struct pv_list)->pv, |
199 | NULL); | |
9e300c84 AK |
200 | |
201 | if (!pvs_found) { | |
202 | log_print("No matching physical volumes found"); | |
203 | return 0; | |
204 | } | |
205 | ||
b6c041d7 | 206 | log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]", |
9e300c84 AK |
207 | pvs_found, |
208 | (s1 = display_size(size_total / 2, SIZE_SHORT)), | |
209 | pvs_found - new_pvs_found, | |
210 | (s2 = | |
211 | display_size((size_total - size_new) / 2, SIZE_SHORT)), | |
25d42d50 | 212 | new_pvs_found, (s3 = display_size(size_new / 2, SIZE_SHORT))); |
9e300c84 AK |
213 | dbg_free(s1); |
214 | dbg_free(s2); | |
215 | dbg_free(s3); | |
216 | ||
217 | return 0; | |
218 | } |