]>
sourceware.org Git - lvm2.git/blob - tools/pvscan.c
2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU General Public License v.2.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 int pv_max_name_len
= 0;
19 int vg_max_name_len
= 0;
21 static void _pvscan_display_single(struct cmd_context
*cmd
,
22 struct physical_volume
*pv
,
23 void *handle
__attribute((unused
)))
25 char uuid
[64] __attribute((aligned(8)));
26 unsigned vg_name_len
= 0;
28 char pv_tmp_name
[NAME_LEN
] = { 0, };
29 char vg_tmp_name
[NAME_LEN
] = { 0, };
30 char vg_name_this
[NAME_LEN
] = { 0, };
33 if (arg_count(cmd
, short_ARG
) > 0) {
34 log_print("%s", dev_name(pv
->dev
));
38 if (arg_count(cmd
, verbose_ARG
) > 1) {
39 /* FIXME As per pv_display! Drop through for now. */
42 /* FIXME - Moved to Volume Group structure */
43 /* log_print("System Id %s", pv->vg->system_id); */
49 memset(pv_tmp_name
, 0, sizeof(pv_tmp_name
));
51 vg_name_len
= strlen(pv
->vg_name
) + 1;
53 if (arg_count(cmd
, uuid_ARG
)) {
54 if (!id_write_format(&pv
->id
, uuid
, sizeof(uuid
))) {
59 sprintf(pv_tmp_name
, "%-*s with UUID %s",
60 pv_max_name_len
- 2, dev_name(pv
->dev
), uuid
);
62 sprintf(pv_tmp_name
, "%s", dev_name(pv
->dev
));
66 log_print("PV %-*s %-*s %s [%s]",
67 pv_max_name_len
, pv_tmp_name
,
69 pv
->fmt
? pv
->fmt
->name
: " ",
70 display_size(cmd
, pv
->size
));
74 if (pv
->status
& EXPORTED_VG
) {
75 strncpy(vg_name_this
, pv
->vg_name
, vg_name_len
);
76 log_print("PV %-*s is in exported VG %s "
78 pv_max_name_len
, pv_tmp_name
,
80 display_size(cmd
, (uint64_t) pv
->pe_count
*
82 display_size(cmd
, (uint64_t) (pv
->pe_count
-
88 sprintf(vg_tmp_name
, "%s", pv
->vg_name
);
89 log_print("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len
,
90 pv_tmp_name
, vg_max_name_len
, vg_tmp_name
,
91 pv
->fmt
? pv
->fmt
->name
: " ",
92 display_size(cmd
, (uint64_t) pv
->pe_count
* pv
->pe_size
),
94 (uint64_t) (pv
->pe_count
- pv
->pe_alloc_count
) *
99 int pvscan(struct cmd_context
*cmd
, int argc
__attribute((unused
)),
100 char **argv
__attribute((unused
)))
102 int new_pvs_found
= 0;
105 struct list
*pvslist
;
107 struct physical_volume
*pv
;
109 uint64_t size_total
= 0;
110 uint64_t size_new
= 0;
116 if (arg_count(cmd
, novolumegroup_ARG
) && arg_count(cmd
, exported_ARG
)) {
117 log_error("Options -e and -n are incompatible");
118 return EINVALID_CMD_LINE
;
121 if (arg_count(cmd
, exported_ARG
) || arg_count(cmd
, novolumegroup_ARG
))
122 log_print("WARNING: only considering physical volumes %s",
123 arg_count(cmd
, exported_ARG
) ?
124 "of exported volume group(s)" : "in no volume group");
126 persistent_filter_wipe(cmd
->filter
);
129 log_verbose("Walking through all physical volumes");
130 if (!(pvslist
= get_pvs(cmd
)))
133 /* eliminate exported/new if required */
134 list_iterate_items(pvl
, pvslist
) {
137 if ((arg_count(cmd
, exported_ARG
)
138 && !(pv
->status
& EXPORTED_VG
))
139 || (arg_count(cmd
, novolumegroup_ARG
) && (*pv
->vg_name
))) {
140 list_del(&pvl
->list
);
144 /* Also check for MD use? */
146 if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
148 ("WARNING: physical volume \"%s\" belongs to a meta device",
151 if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
158 size_new
+= pv
->size
;
159 size_total
+= pv
->size
;
161 size_total
+= pv
->pe_count
* pv
->pe_size
;
164 /* find maximum pv name length */
165 pv_max_name_len
= vg_max_name_len
= 0;
166 list_iterate_items(pvl
, pvslist
) {
168 len
= strlen(dev_name(pv
->dev
));
169 if (pv_max_name_len
< len
)
170 pv_max_name_len
= len
;
171 len
= strlen(pv
->vg_name
);
172 if (vg_max_name_len
< len
)
173 vg_max_name_len
= len
;
175 pv_max_name_len
+= 2;
176 vg_max_name_len
+= 2;
178 list_iterate_items(pvl
, pvslist
)
179 _pvscan_display_single(cmd
, pvl
->pv
, NULL
);
182 log_print("No matching physical volumes found");
183 return ECMD_PROCESSED
;
186 log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
188 display_size(cmd
, size_total
),
189 pvs_found
- new_pvs_found
,
190 display_size(cmd
, (size_total
- size_new
)),
191 new_pvs_found
, display_size(cmd
, size_new
));
193 return ECMD_PROCESSED
;
This page took 0.046154 seconds and 6 git commands to generate.