1 /* $NetBSD: pvscan.c,v 1.1.1.2 2009/12/02 00:25:54 haad Exp $ */
4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 int pv_max_name_len = 0;
21 int vg_max_name_len = 0;
23 static void _pvscan_display_single(struct cmd_context *cmd,
24 struct physical_volume *pv,
25 void *handle __attribute((unused)))
27 char uuid[64] __attribute((aligned(8)));
28 unsigned vg_name_len = 0;
30 char pv_tmp_name[NAME_LEN] = { 0, };
31 char vg_tmp_name[NAME_LEN] = { 0, };
32 char vg_name_this[NAME_LEN] = { 0, };
35 if (arg_count(cmd, short_ARG) > 0) {
36 log_print("%s", pv_dev_name(pv));
40 if (arg_count(cmd, verbose_ARG) > 1) {
41 /* FIXME As per pv_display! Drop through for now. */
44 /* FIXME - Moved to Volume Group structure */
45 /* log_print("System Id %s", pv->vg->system_id); */
51 memset(pv_tmp_name, 0, sizeof(pv_tmp_name));
53 vg_name_len = strlen(pv_vg_name(pv)) + 1;
55 if (arg_count(cmd, uuid_ARG)) {
56 if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
61 sprintf(pv_tmp_name, "%-*s with UUID %s",
62 pv_max_name_len - 2, pv_dev_name(pv), uuid);
64 sprintf(pv_tmp_name, "%s", pv_dev_name(pv));
68 log_print("PV %-*s %-*s %s [%s]",
69 pv_max_name_len, pv_tmp_name,
71 pv->fmt ? pv->fmt->name : " ",
72 display_size(cmd, pv_size(pv)));
76 if (pv_status(pv) & EXPORTED_VG) {
77 strncpy(vg_name_this, pv_vg_name(pv), vg_name_len);
78 log_print("PV %-*s is in exported VG %s "
80 pv_max_name_len, pv_tmp_name,
82 display_size(cmd, (uint64_t) pv_pe_count(pv) *
84 display_size(cmd, (uint64_t) (pv_pe_count(pv) -
85 pv_pe_alloc_count(pv))
90 sprintf(vg_tmp_name, "%s", pv_vg_name(pv));
91 log_print("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len,
92 pv_tmp_name, vg_max_name_len, vg_tmp_name,
93 pv->fmt ? pv->fmt->name : " ",
94 display_size(cmd, (uint64_t) pv_pe_count(pv) *
96 display_size(cmd, (uint64_t) (pv_pe_count(pv) -
97 pv_pe_alloc_count(pv)) *
102 int pvscan(struct cmd_context *cmd, int argc __attribute((unused)),
103 char **argv __attribute((unused)))
105 int new_pvs_found = 0;
108 struct dm_list *pvslist;
110 struct physical_volume *pv;
112 uint64_t size_total = 0;
113 uint64_t size_new = 0;
119 if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
120 log_error("Options -e and -n are incompatible");
121 return EINVALID_CMD_LINE;
124 if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG))
125 log_warn("WARNING: only considering physical volumes %s",
126 arg_count(cmd, exported_ARG) ?
127 "of exported volume group(s)" : "in no volume group");
129 if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE)) {
130 log_error("Unable to obtain global lock.");
134 persistent_filter_wipe(cmd->filter);
135 lvmcache_destroy(cmd, 1);
137 log_verbose("Walking through all physical volumes");
138 if (!(pvslist = get_pvs(cmd))) {
139 unlock_vg(cmd, VG_GLOBAL);
144 /* eliminate exported/new if required */
145 dm_list_iterate_items(pvl, pvslist) {
148 if ((arg_count(cmd, exported_ARG)
149 && !(pv_status(pv) & EXPORTED_VG))
150 || (arg_count(cmd, novolumegroup_ARG) && (!is_orphan(pv)))) {
151 dm_list_del(&pvl->list);
155 /* Also check for MD use? */
157 if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
159 ("WARNING: physical volume \"%s\" belongs to a meta device",
162 if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
169 size_new += pv_size(pv);
170 size_total += pv_size(pv);
172 size_total += pv_pe_count(pv) * pv_pe_size(pv);
175 /* find maximum pv name length */
176 pv_max_name_len = vg_max_name_len = 0;
177 dm_list_iterate_items(pvl, pvslist) {
179 len = strlen(pv_dev_name(pv));
180 if (pv_max_name_len < len)
181 pv_max_name_len = len;
182 len = strlen(pv_vg_name(pv));
183 if (vg_max_name_len < len)
184 vg_max_name_len = len;
186 pv_max_name_len += 2;
187 vg_max_name_len += 2;
189 dm_list_iterate_items(pvl, pvslist)
190 _pvscan_display_single(cmd, pvl->pv, NULL);
193 log_print("No matching physical volumes found");
194 unlock_vg(cmd, VG_GLOBAL);
195 return ECMD_PROCESSED;
198 log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
200 display_size(cmd, size_total),
201 pvs_found - new_pvs_found,
202 display_size(cmd, (size_total - size_new)),
203 new_pvs_found, display_size(cmd, size_new));
205 unlock_vg(cmd, VG_GLOBAL);
207 return ECMD_PROCESSED;