1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 03:27:58 +03:00
lvm2/tools/pvscan.c

199 lines
5.2 KiB
C
Raw Normal View History

2001-10-02 21:09:05 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
2001-10-02 21:09:05 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2.
2001-10-02 21:09:05 +04:00
*
2004-03-30 23:35:44 +04:00
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
2001-10-02 21:09:05 +04:00
*
* You should have received a copy of the GNU General Public License
2004-03-30 23:35:44 +04:00
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2001-10-02 21:09:05 +04:00
*/
#include "tools.h"
int pv_max_name_len = 0;
int vg_max_name_len = 0;
static void _pvscan_display_single(struct cmd_context *cmd,
struct physical_volume *pv, void *handle)
2002-11-18 17:04:08 +03:00
{
char uuid[64];
unsigned int vg_name_len = 0;
2002-11-18 17:04:08 +03:00
char pv_tmp_name[NAME_LEN] = { 0, };
char vg_tmp_name[NAME_LEN] = { 0, };
char vg_name_this[NAME_LEN] = { 0, };
/* short listing? */
if (arg_count(cmd, short_ARG) > 0) {
log_print("%s", dev_name(pv->dev));
return;
}
if (arg_count(cmd, verbose_ARG) > 1) {
/* FIXME As per pv_display! Drop through for now. */
/* pv_show(pv); */
/* FIXME - Moved to Volume Group structure */
/* log_print("System Id %s", pv->vg->system_id); */
/* log_print(" "); */
/* return; */
}
memset(pv_tmp_name, 0, sizeof(pv_tmp_name));
vg_name_len = strlen(pv->vg_name) + 1;
if (arg_count(cmd, uuid_ARG)) {
if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
stack;
return;
}
sprintf(pv_tmp_name, "%-*s with UUID %s",
pv_max_name_len - 2, dev_name(pv->dev), uuid);
} else {
sprintf(pv_tmp_name, "%s", dev_name(pv->dev));
}
if (!*pv->vg_name) {
log_print("PV %-*s %-*s %s [%s]",
pv_max_name_len, pv_tmp_name,
vg_max_name_len, " ",
pv->fmt ? pv->fmt->name : " ",
display_size(cmd, pv->size / 2, SIZE_SHORT));
2002-11-18 17:04:08 +03:00
return;
}
if (pv->status & EXPORTED_VG) {
strncpy(vg_name_this, pv->vg_name, vg_name_len);
log_print("PV %-*s is in exported VG %s "
"[%s / %s free]",
pv_max_name_len, pv_tmp_name,
vg_name_this,
display_size(cmd, (uint64_t) pv->pe_count *
pv->pe_size / 2, SIZE_SHORT),
display_size(cmd, (uint64_t) (pv->pe_count -
pv->pe_alloc_count)
* pv->pe_size / 2, SIZE_SHORT));
2002-11-18 17:04:08 +03:00
return;
}
sprintf(vg_tmp_name, "%s", pv->vg_name);
log_print
("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len,
pv_tmp_name, vg_max_name_len, vg_tmp_name,
pv->fmt ? pv->fmt->name : " ",
display_size(cmd, (uint64_t) pv->pe_count * pv->pe_size / 2,
SIZE_SHORT), display_size(cmd, (uint64_t)
(pv->pe_count -
pv->pe_alloc_count) *
pv->pe_size / 2,
SIZE_SHORT));
2002-11-18 17:04:08 +03:00
return;
}
int pvscan(struct cmd_context *cmd, int argc, char **argv)
2001-10-02 21:09:05 +04:00
{
int new_pvs_found = 0;
int pvs_found = 0;
struct list *pvslist;
2001-10-16 22:07:54 +04:00
struct pv_list *pvl;
2001-10-02 21:09:05 +04:00
struct physical_volume *pv;
uint64_t size_total = 0;
uint64_t size_new = 0;
2001-10-02 21:09:05 +04:00
int len = 0;
pv_max_name_len = 0;
vg_max_name_len = 0;
if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
2001-10-16 22:07:54 +04:00
log_error("Options -e and -n are incompatible");
return EINVALID_CMD_LINE;
2001-10-02 21:09:05 +04:00
}
if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG))
2001-10-02 21:09:05 +04:00
log_print("WARNING: only considering physical volumes %s",
arg_count(cmd, exported_ARG) ?
2001-10-02 21:09:05 +04:00
"of exported volume group(s)" : "in no volume group");
log_verbose("Wiping cache of LVM-capable devices");
persistent_filter_wipe(cmd->filter);
2001-10-02 21:09:05 +04:00
2002-11-18 17:04:08 +03:00
log_verbose("Wiping internal cache");
lvmcache_destroy();
2002-11-18 17:04:08 +03:00
log_verbose("Walking through all physical volumes");
if (!(pvslist = get_pvs(cmd)))
return ECMD_FAILED;
2001-10-02 21:09:05 +04:00
/* eliminate exported/new if required */
2003-10-16 00:02:46 +04:00
list_iterate_items(pvl, pvslist) {
pv = pvl->pv;
2001-10-02 21:09:05 +04:00
if ((arg_count(cmd, exported_ARG)
&& !(pv->status & EXPORTED_VG))
|| (arg_count(cmd, novolumegroup_ARG) && (*pv->vg_name))) {
2001-10-31 15:47:01 +03:00
list_del(&pvl->list);
2001-10-02 21:09:05 +04:00
continue;
}
/* Also check for MD use? */
/*******
if (MAJOR(pv_create_kdev_t(pv[p]->pv_name)) != MD_MAJOR) {
log_print
("WARNING: physical volume \"%s\" belongs to a meta device",
pv[p]->pv_name);
}
if (MAJOR(pv[p]->pv_dev) != MD_MAJOR)
continue;
********/
pvs_found++;
2001-10-06 01:39:30 +04:00
2001-10-16 22:07:54 +04:00
if (!*pv->vg_name) {
2001-10-02 21:09:05 +04:00
new_pvs_found++;
2001-10-16 22:07:54 +04:00
size_new += pv->size;
size_total += pv->size;
2001-10-31 15:47:01 +03:00
} else
size_total += pv->pe_count * pv->pe_size;
2001-10-02 21:09:05 +04:00
}
/* find maximum pv name length */
pv_max_name_len = vg_max_name_len = 0;
2003-10-16 00:02:46 +04:00
list_iterate_items(pvl, pvslist) {
pv = pvl->pv;
len = strlen(dev_name(pv->dev));
2001-10-02 21:09:05 +04:00
if (pv_max_name_len < len)
pv_max_name_len = len;
len = strlen(pv->vg_name);
if (vg_max_name_len < len)
vg_max_name_len = len;
}
pv_max_name_len += 2;
vg_max_name_len += 2;
2003-10-16 00:02:46 +04:00
list_iterate_items(pvl, pvslist)
_pvscan_display_single(cmd, pvl->pv, NULL);
2001-10-02 21:09:05 +04:00
if (!pvs_found) {
log_print("No matching physical volumes found");
2003-10-22 02:06:07 +04:00
return ECMD_PROCESSED;
2001-10-02 21:09:05 +04:00
}
2001-10-16 22:07:54 +04:00
log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
2001-10-02 21:09:05 +04:00
pvs_found,
display_size(cmd, size_total / 2, SIZE_SHORT),
2001-10-02 21:09:05 +04:00
pvs_found - new_pvs_found,
display_size(cmd, (size_total - size_new) / 2, SIZE_SHORT),
new_pvs_found, display_size(cmd, size_new / 2, SIZE_SHORT));
2001-10-02 21:09:05 +04:00
2003-10-22 02:06:07 +04:00
return ECMD_PROCESSED;
2001-10-02 21:09:05 +04:00
}