]> sourceware.org Git - lvm2.git/blob - tools/pvscan.c
macro changes
[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 int pv_max_name_len = 0;
24 int vg_max_name_len = 0;
25
26 static void _pvscan_display_single(struct cmd_context *cmd,
27 struct physical_volume *pv, void *handle)
28 {
29 char uuid[64];
30 unsigned int vg_name_len = 0;
31
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 : " ",
74 display_size(cmd, pv->size / 2, SIZE_SHORT));
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,
83 vg_name_this,
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)
88 * pv->pe_size / 2, SIZE_SHORT));
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 : " ",
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));
103 return;
104 }
105
106 int pvscan(struct cmd_context *cmd, int argc, char **argv)
107 {
108 int new_pvs_found = 0;
109 int pvs_found = 0;
110
111 struct list *pvslist;
112 struct pv_list *pvl;
113 struct physical_volume *pv;
114
115 uint64_t size_total = 0;
116 uint64_t size_new = 0;
117
118 int len = 0;
119 pv_max_name_len = 0;
120 vg_max_name_len = 0;
121
122 if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
123 log_error("Options -e and -n are incompatible");
124 return EINVALID_CMD_LINE;
125 }
126
127 if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG))
128 log_print("WARNING: only considering physical volumes %s",
129 arg_count(cmd, exported_ARG) ?
130 "of exported volume group(s)" : "in no volume group");
131
132 log_verbose("Wiping cache of LVM-capable devices");
133 persistent_filter_wipe(cmd->filter);
134
135 log_verbose("Wiping internal cache");
136 lvmcache_destroy();
137
138 log_verbose("Walking through all physical volumes");
139 if (!(pvslist = get_pvs(cmd)))
140 return ECMD_FAILED;
141
142 /* eliminate exported/new if required */
143 list_iterate_items(pvl, pvslist) {
144 pv = pvl->pv;
145
146 if ((arg_count(cmd, exported_ARG)
147 && !(pv->status & EXPORTED_VG))
148 || (arg_count(cmd, novolumegroup_ARG) && (*pv->vg_name))) {
149 list_del(&pvl->list);
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++;
164
165 if (!*pv->vg_name) {
166 new_pvs_found++;
167 size_new += pv->size;
168 size_total += pv->size;
169 } else
170 size_total += (pv->pe_count - pv->pe_alloc_count)
171 * pv->pe_size;
172 }
173
174 /* find maximum pv name length */
175 pv_max_name_len = vg_max_name_len = 0;
176 list_iterate_items(pvl, pvslist) {
177 pv = pvl->pv;
178 len = strlen(dev_name(pv->dev));
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
188 list_iterate_items(pvl, pvslist)
189 _pvscan_display_single(cmd, pvl->pv, NULL);
190
191 if (!pvs_found) {
192 log_print("No matching physical volumes found");
193 return 0;
194 }
195
196 log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
197 pvs_found,
198 display_size(cmd, size_total / 2, SIZE_SHORT),
199 pvs_found - new_pvs_found,
200 display_size(cmd, (size_total - size_new) / 2, SIZE_SHORT),
201 new_pvs_found, display_size(cmd, size_new / 2, SIZE_SHORT));
202
203 return 0;
204 }
This page took 0.049091 seconds and 6 git commands to generate.