]> sourceware.org Git - lvm2.git/blame - tools/pvscan.c
str_list_del
[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
8ef2b021
AK
26static void _pvscan_display_single(struct cmd_context *cmd,
27 struct physical_volume *pv, void *handle)
5a52dca9
AK
28{
29 char uuid[64];
8ef2b021 30 unsigned int vg_name_len = 0;
5a52dca9 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 83 vg_name_this,
8ef2b021
AK
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)
4c64ed4c 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 : " ",
8ef2b021
AK
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));
5a52dca9
AK
103 return;
104}
105
60274aba 106int pvscan(struct cmd_context *cmd, int argc, char **argv)
9e300c84
AK
107{
108 int new_pvs_found = 0;
109 int pvs_found = 0;
9e300c84 110
8ef2b021 111 struct list *pvslist;
1b9fcf48 112 struct list *pvh;
b6c041d7 113 struct pv_list *pvl;
9e300c84
AK
114 struct physical_volume *pv;
115
ee1f91bf
AK
116 uint64_t size_total = 0;
117 uint64_t size_new = 0;
9e300c84
AK
118
119 int len = 0;
120 pv_max_name_len = 0;
121 vg_max_name_len = 0;
122
6fda126d 123 if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
b6c041d7 124 log_error("Options -e and -n are incompatible");
ee1f91bf 125 return EINVALID_CMD_LINE;
9e300c84
AK
126 }
127
6fda126d 128 if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG))
9e300c84 129 log_print("WARNING: only considering physical volumes %s",
6fda126d 130 arg_count(cmd, exported_ARG) ?
9e300c84
AK
131 "of exported volume group(s)" : "in no volume group");
132
d2393d23 133 log_verbose("Wiping cache of LVM-capable devices");
60274aba 134 persistent_filter_wipe(cmd->filter);
9e300c84 135
5a52dca9 136 log_verbose("Wiping internal cache");
914c9723 137 lvmcache_destroy();
5a52dca9 138
d2393d23 139 log_verbose("Walking through all physical volumes");
8ef2b021 140 if (!(pvslist = get_pvs(cmd)))
ee1f91bf 141 return ECMD_FAILED;
9e300c84
AK
142
143 /* eliminate exported/new if required */
8ef2b021 144 list_iterate(pvh, pvslist) {
1b9fcf48 145 pvl = list_item(pvh, struct pv_list);
cc282870 146 pv = pvl->pv;
9e300c84 147
25b73380 148 if ((arg_count(cmd, exported_ARG)
6fda126d
AK
149 && !(pv->status & EXPORTED_VG))
150 || (arg_count(cmd, novolumegroup_ARG) && (*pv->vg_name))) {
1b9fcf48 151 list_del(&pvl->list);
9e300c84
AK
152 continue;
153 }
154
155 /* Also check for MD use? */
156/*******
157 if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
158 log_print
159 ("WARNING: physical volume \"%s\" belongs to a meta device",
160 pv[p]->pv_name);
161 }
162 if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
163 continue;
164********/
165 pvs_found++;
25d42d50 166
b6c041d7 167 if (!*pv->vg_name) {
9e300c84 168 new_pvs_found++;
b6c041d7
AK
169 size_new += pv->size;
170 size_total += pv->size;
1b9fcf48 171 } else
25b73380 172 size_total += (pv->pe_count - pv->pe_alloc_count)
6fda126d 173 * pv->pe_size;
9e300c84
AK
174 }
175
176 /* find maximum pv name length */
177 pv_max_name_len = vg_max_name_len = 0;
8ef2b021 178 list_iterate(pvh, pvslist) {
cc282870 179 pv = list_item(pvh, struct pv_list)->pv;
c7f0b573 180 len = strlen(dev_name(pv->dev));
9e300c84
AK
181 if (pv_max_name_len < len)
182 pv_max_name_len = len;
183 len = strlen(pv->vg_name);
184 if (vg_max_name_len < len)
185 vg_max_name_len = len;
186 }
187 pv_max_name_len += 2;
188 vg_max_name_len += 2;
189
8ef2b021
AK
190 list_iterate(pvh, pvslist)
191 _pvscan_display_single(cmd, list_item(pvh, struct pv_list)->pv,
192 NULL);
9e300c84
AK
193
194 if (!pvs_found) {
195 log_print("No matching physical volumes found");
196 return 0;
197 }
198
b6c041d7 199 log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
9e300c84 200 pvs_found,
4c64ed4c 201 display_size(cmd, size_total / 2, SIZE_SHORT),
9e300c84 202 pvs_found - new_pvs_found,
4c64ed4c
AK
203 display_size(cmd, (size_total - size_new) / 2, SIZE_SHORT),
204 new_pvs_found, display_size(cmd, size_new / 2, SIZE_SHORT));
9e300c84
AK
205
206 return 0;
207}
This page took 0.056287 seconds and 5 git commands to generate.