]>
sourceware.org Git - lvm2.git/blob - tools/pvscan.c
2 * Copyright (C) 2001 Sistina Software
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)
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.
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.
23 int pv_max_name_len
= 0;
24 int vg_max_name_len
= 0;
26 static void _pvscan_display_single(struct cmd_context
*cmd
,
27 struct physical_volume
*pv
, void *handle
)
30 unsigned int vg_name_len
= 0;
32 char pv_tmp_name
[NAME_LEN
] = { 0, };
33 char vg_tmp_name
[NAME_LEN
] = { 0, };
34 char vg_name_this
[NAME_LEN
] = { 0, };
37 if (arg_count(cmd
, short_ARG
) > 0) {
38 log_print("%s", dev_name(pv
->dev
));
42 if (arg_count(cmd
, verbose_ARG
) > 1) {
43 /* FIXME As per pv_display! Drop through for now. */
46 /* FIXME - Moved to Volume Group structure */
47 /* log_print("System Id %s", pv->vg->system_id); */
53 memset(pv_tmp_name
, 0, sizeof(pv_tmp_name
));
55 vg_name_len
= strlen(pv
->vg_name
) + 1;
57 if (arg_count(cmd
, uuid_ARG
)) {
58 if (!id_write_format(&pv
->id
, uuid
, sizeof(uuid
))) {
63 sprintf(pv_tmp_name
, "%-*s with UUID %s",
64 pv_max_name_len
- 2, dev_name(pv
->dev
), uuid
);
66 sprintf(pv_tmp_name
, "%s", dev_name(pv
->dev
));
70 log_print("PV %-*s %-*s %s [%s]",
71 pv_max_name_len
, pv_tmp_name
,
73 pv
->fmt
? pv
->fmt
->name
: " ",
74 display_size(cmd
, pv
->size
/ 2, SIZE_SHORT
));
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 "
82 pv_max_name_len
, pv_tmp_name
,
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
-
88 * pv
->pe_size
/ 2, SIZE_SHORT
));
92 sprintf(vg_tmp_name
, "%s", pv
->vg_name
);
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)
100 pv
->pe_alloc_count
) *
106 int pvscan(struct cmd_context
*cmd
, int argc
, char **argv
)
108 int new_pvs_found
= 0;
111 struct list
*pvslist
;
113 struct physical_volume
*pv
;
115 uint64_t size_total
= 0;
116 uint64_t size_new
= 0;
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
;
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");
132 log_verbose("Wiping cache of LVM-capable devices");
133 persistent_filter_wipe(cmd
->filter
);
135 log_verbose("Wiping internal cache");
138 log_verbose("Walking through all physical volumes");
139 if (!(pvslist
= get_pvs(cmd
)))
142 /* eliminate exported/new if required */
143 list_iterate_items(pvl
, pvslist
) {
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
);
153 /* Also check for MD use? */
155 if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
157 ("WARNING: physical volume \"%s\" belongs to a meta device",
160 if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
167 size_new
+= pv
->size
;
168 size_total
+= pv
->size
;
170 size_total
+= (pv
->pe_count
- pv
->pe_alloc_count
)
174 /* find maximum pv name length */
175 pv_max_name_len
= vg_max_name_len
= 0;
176 list_iterate_items(pvl
, pvslist
) {
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
;
185 pv_max_name_len
+= 2;
186 vg_max_name_len
+= 2;
188 list_iterate_items(pvl
, pvslist
)
189 _pvscan_display_single(cmd
, pvl
->pv
, NULL
);
192 log_print("No matching physical volumes found");
196 log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
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
));
This page took 0.049091 seconds and 6 git commands to generate.