]> sourceware.org Git - lvm2.git/blame - tools/pvscan.c
Preparation for an LVM2 liblvm - pass cmd_context into each tool and
[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
60274aba 23void pvscan_display_single(struct cmd_context *cmd, struct physical_volume *pv);
9e300c84
AK
24
25int pv_max_name_len = 0;
26int vg_max_name_len = 0;
27
60274aba 28int pvscan(struct cmd_context *cmd, int argc, char **argv)
9e300c84
AK
29{
30 int new_pvs_found = 0;
31 int pvs_found = 0;
32 char *s1, *s2, *s3;
33
1b9fcf48
JT
34 struct list *pvs;
35 struct list *pvh;
b6c041d7 36 struct pv_list *pvl;
9e300c84
AK
37 struct physical_volume *pv;
38
ee1f91bf
AK
39 uint64_t size_total = 0;
40 uint64_t size_new = 0;
9e300c84
AK
41
42 int len = 0;
43 pv_max_name_len = 0;
44 vg_max_name_len = 0;
45
60274aba 46 if (arg_count(cmd,novolumegroup_ARG) && arg_count(cmd,exported_ARG)) {
b6c041d7 47 log_error("Options -e and -n are incompatible");
ee1f91bf 48 return EINVALID_CMD_LINE;
9e300c84
AK
49 }
50
60274aba 51 if (arg_count(cmd,exported_ARG) || arg_count(cmd,novolumegroup_ARG))
9e300c84 52 log_print("WARNING: only considering physical volumes %s",
60274aba 53 arg_count(cmd,exported_ARG) ?
9e300c84
AK
54 "of exported volume group(s)" : "in no volume group");
55
d2393d23 56 log_verbose("Wiping cache of LVM-capable devices");
60274aba 57 persistent_filter_wipe(cmd->filter);
9e300c84 58
d2393d23 59 log_verbose("Walking through all physical volumes");
60274aba 60 if (!(pvs = cmd->fid->ops->get_pvs(cmd->fid)))
ee1f91bf 61 return ECMD_FAILED;
9e300c84
AK
62
63 /* eliminate exported/new if required */
1b9fcf48
JT
64 list_iterate(pvh, pvs) {
65 pvl = list_item(pvh, struct pv_list);
cc282870 66 pv = pvl->pv;
9e300c84 67
60274aba
AK
68 if ((arg_count(cmd,exported_ARG) && !(pv->status & EXPORTED_VG))
69 || (arg_count(cmd,novolumegroup_ARG) && (*pv->vg_name))) {
1b9fcf48 70 list_del(&pvl->list);
9e300c84
AK
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++;
25d42d50 85
9e300c84 86
b6c041d7 87 if (!*pv->vg_name) {
9e300c84 88 new_pvs_found++;
b6c041d7
AK
89 size_new += pv->size;
90 size_total += pv->size;
1b9fcf48
JT
91 } else
92 size_total += (pv->pe_count - pv->pe_allocated)
b6c041d7 93 * pv->pe_size;
9e300c84
AK
94 }
95
96 /* find maximum pv name length */
97 pv_max_name_len = vg_max_name_len = 0;
1b9fcf48 98 list_iterate(pvh, pvs) {
cc282870 99 pv = list_item(pvh, struct pv_list)->pv;
c7f0b573 100 len = strlen(dev_name(pv->dev));
9e300c84
AK
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
1b9fcf48 110 list_iterate(pvh, pvs)
60274aba 111 pvscan_display_single(cmd, list_item(pvh, struct pv_list)->pv);
9e300c84
AK
112
113 if (!pvs_found) {
114 log_print("No matching physical volumes found");
115 return 0;
116 }
117
b6c041d7 118 log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
9e300c84
AK
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)),
25d42d50 124 new_pvs_found, (s3 = display_size(size_new / 2, SIZE_SHORT)));
9e300c84
AK
125 dbg_free(s1);
126 dbg_free(s2);
127 dbg_free(s3);
128
129 return 0;
130}
131
60274aba 132void pvscan_display_single(struct cmd_context *cmd, struct physical_volume *pv)
9e300c84 133{
d29265b9 134 char uuid[64];
9e300c84 135 int vg_name_len = 0;
9e300c84
AK
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? */
60274aba 144 if (arg_count(cmd,short_ARG) > 0) {
c7f0b573 145 log_print("%s", dev_name(pv->dev));
9e300c84
AK
146 return;
147 }
148
60274aba 149 if (arg_count(cmd,verbose_ARG) > 1) {
b6c041d7
AK
150 /* FIXME As per pv_display! Drop through for now. */
151 /* pv_show(pv); */
152
f53c6aa6
AK
153 /* FIXME - Moved to Volume Group structure */
154 /* log_print("System Id %s", pv->vg->system_id); */
b6c041d7
AK
155
156 /* log_print(" "); */
157 /* return; */
9e300c84
AK
158 }
159
160 memset(pv_tmp_name, 0, sizeof (pv_tmp_name));
161
f53c6aa6 162 vg_name_len = strlen(pv->vg_name) + 1;
9e300c84 163
60274aba 164 if (arg_count(cmd,uuid_ARG)) {
d29265b9
JT
165 if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
166 stack;
167 return;
168 }
169
170 sprintf(pv_tmp_name, "%-*s with UUID %s",
171 pv_max_name_len - 2, dev_name(pv->dev), uuid);
9e300c84 172 } else {
c7f0b573 173 sprintf(pv_tmp_name, "%s", dev_name(pv->dev));
9e300c84
AK
174 }
175
b6c041d7 176 if (!*pv->vg_name) {
d518bc39 177 log_print("PV %-*s %-*s [%s]",
9e300c84 178 pv_max_name_len, pv_tmp_name,
d518bc39 179 vg_max_name_len, " ",
9e300c84
AK
180 (s1 = display_size(pv->size / 2, SIZE_SHORT)));
181 dbg_free(s1);
182 return;
183 }
184
f53c6aa6 185 if (pv->status & EXPORTED_VG) {
9e300c84 186 strncpy(vg_name_this, pv->vg_name, vg_name_len);
08907484
HM
187 log_print("PV %-*s is in exported VG %s "
188 "[%s / %s free]",
4a624ca0 189 pv_max_name_len, pv_tmp_name,
9e300c84 190 vg_name_this, (s1 =
b6c041d7 191 display_size(pv->pe_count *
9e300c84
AK
192 pv->pe_size / 2,
193 SIZE_SHORT)),
b6c041d7 194 (s2 = display_size((pv->pe_count - pv->pe_allocated)
9e300c84
AK
195 * pv->pe_size / 2, SIZE_SHORT)));
196 dbg_free(s1);
197 dbg_free(s2);
198 return;
199 }
200
9e300c84
AK
201 sprintf(vg_tmp_name, "%s", pv->vg_name);
202 log_print
d518bc39 203 ("PV %-*s VG %-*s [%s / %s free]", pv_max_name_len,
9e300c84 204 pv_tmp_name, vg_max_name_len, vg_tmp_name,
b6c041d7 205 (s1 = display_size(pv->pe_count * pv->pe_size / 2, SIZE_SHORT)),
9e300c84 206 (s2 =
b6c041d7 207 display_size((pv->pe_count - pv->pe_allocated) * pv->pe_size / 2,
9e300c84
AK
208 SIZE_SHORT)));
209 dbg_free(s1);
210 dbg_free(s2);
211
212 return;
213}
This page took 0.050515 seconds and 5 git commands to generate.