]> sourceware.org Git - lvm2.git/blame - tools/pvscan.c
pvscan framework
[lvm2.git] / tools / pvscan.c
CommitLineData
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
23void pvscan_display_single(struct physical_volume *pv);
24
25int pv_max_name_len = 0;
26int vg_max_name_len = 0;
27
28int 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 io_space *ios;
35 struct pv_list *pvs_list, *pvl;
36 struct list_head *pvh;
37 struct physical_volume *pv;
38
39 __uint64_t size_total = 0;
40 __uint64_t size_new = 0;
41 __uint64_t size = 0;
42
43 int len = 0;
44 pv_max_name_len = 0;
45 vg_max_name_len = 0;
46
47 if (arg_count(novolumegroup_ARG) && arg_count(exported_ARG)) {
48 log_error("options e and n incompatible");
49 return LVM_EINVALID_CMD_LINE;
50 }
51
52 if (arg_count(exported_ARG) || arg_count(novolumegroup_ARG))
53 log_print("WARNING: only considering physical volumes %s",
54 arg_count(exported_ARG) ?
55 "of exported volume group(s)" : "in no volume group");
56
57 log_verbose("Walking through all physical volumes");
58
59 ios = active_ios();
60
61 if (!(pvs_list = ios->get_pvs(ios)))
62 return LVM_ECMD_FAILED;
63
64 /* eliminate exported/new if required */
65 list_for_each(pvh, &pvs_list->list) {
66 pvl = list_entry(pvh, struct pv_list, list);
67 pv = &pvl->pv;
68
69 if ((arg_count(exported_ARG) && !(pv->status & STATUS_EXPORTED))
70 || (arg_count(novolumegroup_ARG) && (pv->vg_name[0]))) {
71 list_del(&pvl->list); /* Plus deallocation? */
72 continue;
73 }
74
75 /* Also check for MD use? */
76/*******
77 if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
78 log_print
79 ("WARNING: physical volume \"%s\" belongs to a meta device",
80 pv[p]->pv_name);
81 }
82 if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
83 continue;
84********/
85 pvs_found++;
86
87 size = dev_get_size(pv->dev);
88 size_total += size;
89
90 if (pv->vg_name[0]) {
91 new_pvs_found++;
92 size_new += size;
93 }
94 }
95
96 /* find maximum pv name length */
97 pv_max_name_len = vg_max_name_len = 0;
98 list_for_each(pvh, &pvs_list->list) {
99 pvl = list_entry(pvh, struct pv_list, list);
100 pv = &pvl->pv;
101 len = strlen(pv->dev->name);
102 if (pv_max_name_len < len)
103 pv_max_name_len = len;
104 len = strlen(pv->vg_name);
105 if (vg_max_name_len < len)
106 vg_max_name_len = len;
107 }
108 pv_max_name_len += 2;
109 vg_max_name_len += 2;
110
111 list_for_each(pvh, &pvs_list->list) {
112 pvl = list_entry(pvh, struct pv_list, list);
113 pv = &pvl->pv;
114
115 pvscan_display_single(pv);
116 }
117
118 if (!pvs_found) {
119 log_print("No matching physical volumes found");
120 return 0;
121 }
122
123 log_print("total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
124 pvs_found,
125 (s1 = display_size(size_total / 2, SIZE_SHORT)),
126 pvs_found - new_pvs_found,
127 (s2 =
128 display_size((size_total - size_new) / 2, SIZE_SHORT)),
129 new_pvs_found, (s3 =
130 display_size(size_new / 2,
131 SIZE_SHORT)));
132 dbg_free(s1);
133 dbg_free(s2);
134 dbg_free(s3);
135
136 return 0;
137}
138
139void pvscan_display_single(struct physical_volume *pv)
140{
141
142 int vg_name_len = 0;
143 const char *active_str;
144
145 char *s1, *s2;
146
147 char pv_tmp_name[NAME_LEN] = { 0, };
148 char vg_tmp_name[NAME_LEN] = { 0, };
149 char vg_name_this[NAME_LEN] = { 0, };
150
151 /* short listing? */
152 if (arg_count(short_ARG) > 0) {
153 log_print("%s", pv->dev->name);
154 return;
155 }
156
157 if (arg_count(verbose_ARG) > 1) {
158 pv_show(pv);
159 log_print("System Id %s", pv->exported);
160 log_print("");
161 return;
162 }
163
164 memset(pv_tmp_name, 0, sizeof (pv_tmp_name));
165
166 active_str = (pv->status & STATUS_ACTIVE) ? "ACTIVE " : "inactive ";
167
168 vg_name_len = strlen(pv->vg_name) - sizeof (EXPORTED) + 1;
169
170 if (arg_count(uuid_ARG)) {
171 sprintf(pv_tmp_name,
172 "%-*s with UUID %s",
173 pv_max_name_len - 2,
174 pv->dev->name, display_uuid(pv->id->uuid));
175 } else {
176 sprintf(pv_tmp_name, "%s", pv->dev.name);
177 }
178
179 if (!pv->vg_name[0]) {
180 log_print("%s PV %-*s is in no VG [%s]", active_str,
181 pv_max_name_len, pv_tmp_name,
182 (s1 = display_size(pv->size / 2, SIZE_SHORT)));
183 dbg_free(s1);
184 return;
185 }
186
187 /* FIXME What is pe_total now? */
188 if (strcmp(&pv->vg_name[vg_name_len], EXPORTED_TAG) == 0) {
189 strncpy(vg_name_this, pv->vg_name, vg_name_len);
190 log_print("%sPV %-*s is in EXPORTED VG %s [%s / %s free]",
191 active_str, pv_max_name_len, pv_tmp_name,
192 vg_name_this, (s1 =
193 display_size(pv->pe_total *
194 pv->pe_size / 2,
195 SIZE_SHORT)),
196 (s2 = display_size((pv->pe_total - pv->pe_allocated)
197 * pv->pe_size / 2, SIZE_SHORT)));
198 dbg_free(s1);
199 dbg_free(s2);
200 return;
201 }
202
203 if (!vg_check_name(pv->vg_name)) {
204 log_print
205 ("%sPV %-*s is associated to an unknown VG ",
206 active_str, pv_max_name_len, pv_tmp_name);
207 return;
208 }
209
210 sprintf(vg_tmp_name, "%s", pv->vg_name);
211 log_print
212 ("%sPV %-*s of VG %-*s [%s / %s free]", active_str, pv_max_name_len,
213 pv_tmp_name, vg_max_name_len, vg_tmp_name,
214 (s1 = display_size(pv->pe_total * pv->pe_size / 2, SIZE_SHORT)),
215 (s2 =
216 display_size((pv->pe_total - pv->pe_allocated) * pv->pe_size / 2,
217 SIZE_SHORT)));
218 dbg_free(s1);
219 dbg_free(s2);
220
221 return;
222}
This page took 0.040079 seconds and 5 git commands to generate.