]> sourceware.org Git - lvm2.git/blob - tools/pvscan.c
Run through indent - no (intentional) changes to any code.
[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 cmd_context *cmd, struct physical_volume *pv);
24
25 int pv_max_name_len = 0;
26 int vg_max_name_len = 0;
27
28 int pvscan(struct cmd_context *cmd, 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(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
47 log_error("Options -e and -n are incompatible");
48 return EINVALID_CMD_LINE;
49 }
50
51 if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG))
52 log_print("WARNING: only considering physical volumes %s",
53 arg_count(cmd, 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(cmd->filter);
58
59 log_verbose("Walking through all physical volumes");
60 if (!(pvs = cmd->fid->ops->get_pvs(cmd->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 (
69 (arg_count(cmd, exported_ARG)
70 && !(pv->status & EXPORTED_VG))
71 || (arg_count(cmd, novolumegroup_ARG) && (*pv->vg_name))) {
72 list_del(&pvl->list);
73 continue;
74 }
75
76 /* Also check for MD use? */
77 /*******
78 if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
79 log_print
80 ("WARNING: physical volume \"%s\" belongs to a meta device",
81 pv[p]->pv_name);
82 }
83 if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
84 continue;
85 ********/
86 pvs_found++;
87
88 if (!*pv->vg_name) {
89 new_pvs_found++;
90 size_new += pv->size;
91 size_total += pv->size;
92 } else
93 size_total += (pv->pe_count - pv->pe_allocated)
94 * pv->pe_size;
95 }
96
97 /* find maximum pv name length */
98 pv_max_name_len = vg_max_name_len = 0;
99 list_iterate(pvh, pvs) {
100 pv = list_item(pvh, struct pv_list)->pv;
101 len = strlen(dev_name(pv->dev));
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_iterate(pvh, pvs)
112 pvscan_display_single(cmd, list_item(pvh, struct pv_list)->pv);
113
114 if (!pvs_found) {
115 log_print("No matching physical volumes found");
116 return 0;
117 }
118
119 log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
120 pvs_found,
121 (s1 = display_size(size_total / 2, SIZE_SHORT)),
122 pvs_found - new_pvs_found,
123 (s2 =
124 display_size((size_total - size_new) / 2, SIZE_SHORT)),
125 new_pvs_found, (s3 = display_size(size_new / 2, SIZE_SHORT)));
126 dbg_free(s1);
127 dbg_free(s2);
128 dbg_free(s3);
129
130 return 0;
131 }
132
133 void pvscan_display_single(struct cmd_context *cmd, struct physical_volume *pv)
134 {
135 char uuid[64];
136 int vg_name_len = 0;
137
138 char *s1, *s2;
139
140 char pv_tmp_name[NAME_LEN] = { 0, };
141 char vg_tmp_name[NAME_LEN] = { 0, };
142 char vg_name_this[NAME_LEN] = { 0, };
143
144 /* short listing? */
145 if (arg_count(cmd, short_ARG) > 0) {
146 log_print("%s", dev_name(pv->dev));
147 return;
148 }
149
150 if (arg_count(cmd, verbose_ARG) > 1) {
151 /* FIXME As per pv_display! Drop through for now. */
152 /* pv_show(pv); */
153
154 /* FIXME - Moved to Volume Group structure */
155 /* log_print("System Id %s", pv->vg->system_id); */
156
157 /* log_print(" "); */
158 /* return; */
159 }
160
161 memset(pv_tmp_name, 0, sizeof(pv_tmp_name));
162
163 vg_name_len = strlen(pv->vg_name) + 1;
164
165 if (arg_count(cmd, uuid_ARG)) {
166 if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
167 stack;
168 return;
169 }
170
171 sprintf(pv_tmp_name, "%-*s with UUID %s",
172 pv_max_name_len - 2, dev_name(pv->dev), uuid);
173 } else {
174 sprintf(pv_tmp_name, "%s", dev_name(pv->dev));
175 }
176
177 if (!*pv->vg_name) {
178 log_print("PV %-*s %-*s [%s]",
179 pv_max_name_len, pv_tmp_name,
180 vg_max_name_len, " ",
181 (s1 = display_size(pv->size / 2, SIZE_SHORT)));
182 dbg_free(s1);
183 return;
184 }
185
186 if (pv->status & EXPORTED_VG) {
187 strncpy(vg_name_this, pv->vg_name, vg_name_len);
188 log_print("PV %-*s is in exported VG %s "
189 "[%s / %s free]",
190 pv_max_name_len, pv_tmp_name,
191 vg_name_this, (s1 =
192 display_size(pv->pe_count *
193 pv->pe_size / 2,
194 SIZE_SHORT)),
195 (s2 = display_size((pv->pe_count - pv->pe_allocated)
196 * pv->pe_size / 2, SIZE_SHORT)));
197 dbg_free(s1);
198 dbg_free(s2);
199 return;
200 }
201
202 sprintf(vg_tmp_name, "%s", pv->vg_name);
203 log_print
204 ("PV %-*s VG %-*s [%s / %s free]", pv_max_name_len,
205 pv_tmp_name, vg_max_name_len, vg_tmp_name,
206 (s1 = display_size(pv->pe_count * pv->pe_size / 2, SIZE_SHORT)),
207 (s2 =
208 display_size((pv->pe_count - pv->pe_allocated) * pv->pe_size / 2,
209 SIZE_SHORT)));
210 dbg_free(s1);
211 dbg_free(s2);
212
213 return;
214 }
This page took 0.042836 seconds and 6 git commands to generate.