]>
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 void pvscan_display_single(struct physical_volume
*pv
);
25 int pv_max_name_len
= 0;
26 int vg_max_name_len
= 0;
28 int pvscan(int argc
, char **argv
)
30 int new_pvs_found
= 0;
35 struct pv_list
*pvs_list
, *pvl
;
36 struct list_head
*pvh
;
37 struct physical_volume
*pv
;
39 uint64_t size_total
= 0;
40 uint64_t size_new
= 0;
47 if (arg_count(novolumegroup_ARG
) && arg_count(exported_ARG
)) {
48 log_error("options e and n incompatible");
49 return EINVALID_CMD_LINE
;
52 if (arg_count(exported_ARG
) || arg_count(novolumegroup_ARG
))
53 log_print("WARNING: only considering physical volumes %s",
54 arg_count(exported_ARG
) ?
55 "of exported volume group(s)" : "in no volume group");
57 log_verbose("Walking through all physical volumes");
61 if (!(pvs_list
= ios
->get_pvs(ios
)))
64 /* eliminate exported/new if required */
65 list_for_each(pvh
, &pvs_list
->list
) {
66 pvl
= list_entry(pvh
, struct pv_list
, list
);
69 if ((arg_count(exported_ARG
) && !(pv
->status
& STATUS_EXPORTED
))
70 || (arg_count(novolumegroup_ARG
) && (pv
->vg_name
[0]))) {
71 list_del(&pvl
->list
); /* Plus deallocation? */
75 /* Also check for MD use? */
77 if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
79 ("WARNING: physical volume \"%s\" belongs to a meta device",
82 if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
87 size
= dev_get_size(pv
->dev
);
96 /* find maximum pv name length */
97 pv_max_name_len
= vg_max_name_len
= 0;
98 list_for_each(pvh
, &pvs_list
->list
) {
99 pvl
= list_entry(pvh
, struct pv_list
, list
);
101 len
= strlen(pv
->dev
->name
);
102 if (pv_max_name_len
< len
)
103 pv_max_name_len
= len
;
104 len
= strlen(pv
->vg_name
);
105 if (vg_max_name_len
< len
)
106 vg_max_name_len
= len
;
108 pv_max_name_len
+= 2;
109 vg_max_name_len
+= 2;
111 list_for_each(pvh
, &pvs_list
->list
) {
112 pvl
= list_entry(pvh
, struct pv_list
, list
);
115 pvscan_display_single(pv
);
119 log_print("No matching physical volumes found");
123 log_print("total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
125 (s1
= display_size(size_total
/ 2, SIZE_SHORT
)),
126 pvs_found
- new_pvs_found
,
128 display_size((size_total
- size_new
) / 2, SIZE_SHORT
)),
130 display_size(size_new
/ 2,
139 void pvscan_display_single(struct physical_volume
*pv
)
143 const char *active_str
;
147 char pv_tmp_name
[NAME_LEN
] = { 0, };
148 char vg_tmp_name
[NAME_LEN
] = { 0, };
149 char vg_name_this
[NAME_LEN
] = { 0, };
152 if (arg_count(short_ARG
) > 0) {
153 log_print("%s", pv
->dev
->name
);
157 if (arg_count(verbose_ARG
) > 1) {
159 log_print("System Id %s", pv
->exported
);
164 memset(pv_tmp_name
, 0, sizeof (pv_tmp_name
));
166 active_str
= (pv
->status
& STATUS_ACTIVE
) ? "ACTIVE " : "inactive ";
168 vg_name_len
= strlen(pv
->vg_name
) - sizeof (EXPORTED
) + 1;
170 if (arg_count(uuid_ARG
)) {
174 pv
->dev
->name
, display_uuid(pv
->id
->uuid
));
176 sprintf(pv_tmp_name
, "%s", pv
->dev
.name
);
179 if (!pv
->vg_name
[0]) {
180 log_print("%s PV %-*s is in no VG [%s]", active_str
,
181 pv_max_name_len
, pv_tmp_name
,
182 (s1
= display_size(pv
->size
/ 2, SIZE_SHORT
)));
187 /* FIXME What is pe_total now? */
188 if (strcmp(&pv
->vg_name
[vg_name_len
], EXPORTED_TAG
) == 0) {
189 strncpy(vg_name_this
, pv
->vg_name
, vg_name_len
);
190 log_print("%sPV %-*s is in EXPORTED VG %s [%s / %s free]",
191 active_str
, pv_max_name_len
, pv_tmp_name
,
193 display_size(pv
->pe_total
*
196 (s2
= display_size((pv
->pe_total
- pv
->pe_allocated
)
197 * pv
->pe_size
/ 2, SIZE_SHORT
)));
203 if (!vg_check_name(pv
->vg_name
)) {
205 ("%sPV %-*s is associated to an unknown VG ",
206 active_str
, pv_max_name_len
, pv_tmp_name
);
210 sprintf(vg_tmp_name
, "%s", pv
->vg_name
);
212 ("%sPV %-*s of VG %-*s [%s / %s free]", active_str
, pv_max_name_len
,
213 pv_tmp_name
, vg_max_name_len
, vg_tmp_name
,
214 (s1
= display_size(pv
->pe_total
* pv
->pe_size
/ 2, SIZE_SHORT
)),
216 display_size((pv
->pe_total
- pv
->pe_allocated
) * pv
->pe_size
/ 2,
This page took 0.490757 seconds and 6 git commands to generate.