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