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