1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-28 02:50:41 +03:00

vgdisplay

This commit is contained in:
Alasdair Kergon 2001-11-19 15:20:50 +00:00
parent 8a5ff3ee29
commit 7f3859bb5c
13 changed files with 302 additions and 60 deletions

View File

@ -188,5 +188,6 @@ int dev_zero(struct device *dev, uint64_t offset, int64_t len)
}
}
/* FIXME: Always display error */
return (len == 0);
}

View File

@ -187,10 +187,10 @@ void pvdisplay_full(struct physical_volume *pv)
return;
}
void pv_display_short(struct physical_volume *pv)
int pvdisplay_short(struct volume_group *vg, struct physical_volume *pv)
{
if (!pv)
return;
return 0;
log_print("PV Name %s ", dev_name(pv->dev));
/* FIXME pv->pv_number); */
@ -200,9 +200,11 @@ void pv_display_short(struct physical_volume *pv)
log_print("Total PE / Free PE %u / %u",
pv->pe_count, pv->pe_count - pv->pe_allocated);
return;
log_print(" ");
return 0;
}
void lvdisplay_colons(struct logical_volume *lv)
{
log_print("%s/%s:%s:%d:%d:-1:%d:%" PRIu64 ":%d:-1:%d:%d:-1:-1",
@ -222,7 +224,7 @@ void lvdisplay_colons(struct logical_volume *lv)
return;
}
void lvdisplay_full(struct logical_volume *lv)
int lvdisplay_full(struct logical_volume *lv)
{
char *size;
uint32_t alloc;
@ -389,7 +391,7 @@ void lvdisplay_full(struct logical_volume *lv)
MAJOR(lv->lv_dev), MINOR(lv->lv_dev));
*************/
return;
return 0;
}
@ -430,5 +432,112 @@ void lvdisplay_extents(struct logical_volume *lv)
dev_name(lv->map[le].pv->dev), lv->map[le].pe);
}
log_verbose(" ");
return;
}
void vgdisplay_extents(struct volume_group *vg)
{
return;
}
void vgdisplay_full(struct volume_group *vg)
{
uint32_t access;
char *s1;
log_print("--- Volume group ---");
log_print("VG Name %s", vg->name);
access = vg->status & (LVM_READ | LVM_WRITE);
log_print("VG Access %s%s%s%s",
access == (LVM_READ | LVM_WRITE) ? "read/write" : "",
access == LVM_READ ? "read" : "",
access == LVM_WRITE ? "write" : "",
access == 0 ? "error" : "");
log_print("VG Status %savailable%s/%sresizable",
vg->status & ACTIVE ? "" : "NOT ",
vg->status & EXPORTED_VG ? "/exported" : "",
vg->status & EXTENDABLE_VG ? "" : "NOT ");
/******* FIXME vg number
log_print ("VG # %u\n", vg->vg_number);
********/
if (vg->status & CLUSTERED) {
log_print("Clustered yes");
log_print("Shared %s",
vg->status & SHARED ? "yes" : "no");
}
log_print("MAX LV %u", vg->max_lv);
log_print("Cur LV %u", vg->lv_count);
/****** FIXME Open LVs
log_print ( "Open LV %u", vg->lv_open);
*******/
/****** FIXME Max LV Size
log_print ( "MAX LV Size %s",
( s1 = display_size ( LVM_LV_SIZE_MAX(vg) / 2, SIZE_SHORT)));
free ( s1);
*********/
log_print("Max PV %u", vg->max_pv);
log_print("Cur PV %u", vg->pv_count);
/******* FIXME act PVs
log_print ( "Act PV %u", vg->pv_act);
*********/
s1 = display_size(vg->extent_count * vg->extent_size / 2, SIZE_SHORT);
log_print("VG Size %s", s1);
dbg_free(s1);
s1 = display_size(vg->extent_size / 2, SIZE_SHORT);
log_print("PE Size %s", s1);
dbg_free(s1);
log_print("Total PE %u", vg->extent_count);
s1 =
display_size((vg->extent_count - vg->free_count) *
vg->extent_size / 2, SIZE_SHORT);
log_print("Alloc PE / Size %u / %s",
vg->extent_count - vg->free_count, s1);
dbg_free(s1);
s1 = display_size(vg->free_count * vg->extent_size / 2, SIZE_SHORT);
log_print("Free PE / Size %u / %s", vg->free_count, s1);
dbg_free(s1);
if (strlen(vg->id.uuid))
s1 = display_uuid(vg->id.uuid);
else
s1 = "none";
log_print("VG UUID %s", s1);
if (strlen(vg->id.uuid))
dbg_free(s1);
log_print(" ");
return;
}
void vgdisplay_colons(struct volume_group *vg)
{
return;
}
void vgdisplay_short(struct volume_group *vg)
{
char *s1, *s2, *s3;
s1 = display_size(vg->extent_count * vg->extent_size / 2, SIZE_SHORT);
s2 =
display_size((vg->extent_count - vg->free_count) * vg->extent_size /
2, SIZE_SHORT);
s3 = display_size(vg->free_count * vg->extent_size / 2, SIZE_SHORT);
log_print("%s (%s) %-9s [%-9s used / %s free]", vg->name,
(vg->status & ACTIVE) ? "active" : "inactive",
/********* FIXME if "open" print "/used" else print "/idle"??? ******/
s1, s2, s3);
dbg_free(s1);
dbg_free(s2);
dbg_free(s3);
return;
}

View File

@ -33,21 +33,15 @@ char *display_uuid(char *uuidstr);
void pvdisplay_colons(struct physical_volume *pv);
void pvdisplay_full(struct physical_volume *pv);
int pvdisplay_short(struct volume_group *vg, struct physical_volume *pv);
void lvdisplay_colons(struct logical_volume *lv);
void lvdisplay_extents(struct logical_volume *lv);
void lvdisplay_full(struct logical_volume *lv);
int lvdisplay_full(struct logical_volume *lv);
#if 0
void pv_show_short(pv_t * pv);
void pv_display_pe(pv_t * pv, pe_disk_t * pe);
void pv_display_pe_free(int pe_free, int p);
void pv_display_pe_text(pv_t * pv, pe_disk_t * pe, lv_disk_t * lvs);
static inline unsigned long get_pe_offset(ulong p, pv_t *pv)
{
return pv->pe_start + (p * pv->pe_size);
}
void vgdisplay_extents(struct volume_group *vg);
void vgdisplay_full(struct volume_group *vg);
void vgdisplay_colons(struct volume_group *vg);
void vgdisplay_short(struct volume_group *vg);
#endif
#endif

View File

@ -40,6 +40,7 @@ SOURCES=\
vgck.c \
vgchange.c \
vgcreate.c \
vgdisplay.c \
vgextend.c \
vgreduce.c \
vgremove.c \

View File

@ -20,7 +20,7 @@
#include "tools.h"
static int lvchange_single(struct volume_group *vg, struct logical_volume *lv);
static int lvchange_single(struct logical_volume *lv);
static int lvchange_permission(struct logical_volume *lv);
static int lvchange_availability(struct logical_volume *lv);
static int lvchange_contiguous(struct logical_volume *lv);
@ -42,12 +42,12 @@ int lvchange(int argc, char **argv)
return process_each_lv(argc, argv, &lvchange_single);
}
static int lvchange_single(struct volume_group *vg, struct logical_volume *lv)
static int lvchange_single(struct logical_volume *lv)
{
char *vg_name;
int doit = 0;
if (!(vg->status & ACTIVE)) {
if (!(lv->vg->status & ACTIVE)) {
log_error("Volume group %s must be active before changing a "
"logical volume", vg_name);
return ECMD_FAILED;

View File

@ -20,8 +20,6 @@
#include "tools.h"
static int lvdisplay_single(struct volume_group *vg, struct logical_volume *lv);
int lvdisplay(int argc, char **argv)
{
/* FIXME Allow VG args via process_each */
@ -34,7 +32,7 @@ int lvdisplay(int argc, char **argv)
return process_each_lv(argc, argv, &lvdisplay_single);
}
static int lvdisplay_single(struct volume_group *vg, struct logical_volume *lv)
int lvdisplay_single(struct logical_volume *lv)
{
if (arg_count(colon_ARG))
lvdisplay_colons(lv);

View File

@ -20,7 +20,7 @@
#include "tools.h"
static int lvremove_single(struct volume_group *vg, struct logical_volume *lv);
static int lvremove_single(struct logical_volume *lv);
int lvremove(int argc, char **argv)
{
@ -32,8 +32,11 @@ int lvremove(int argc, char **argv)
return process_each_lv(argc, argv, &lvremove_single);
}
static int lvremove_single(struct volume_group *vg, struct logical_volume *lv)
static int lvremove_single(struct logical_volume *lv)
{
struct volume_group *vg;
vg = lv->vg;
if (!(vg->status & ACTIVE)) {
log_error("Volume group %s must be active before removing a "
"logical volume", vg->name);

View File

@ -20,7 +20,7 @@
#include "tools.h"
static int lvscan_single(struct volume_group *vg, struct logical_volume *lv);
static int lvscan_single(struct logical_volume *lv);
int lvscan(int argc, char **argv)
{
@ -54,7 +54,7 @@ int lvscan(int argc, char **argv)
}
static int lvscan_single(struct volume_group *vg, struct logical_volume *lv)
static int lvscan_single(struct logical_volume *lv)
{
int lv_active = 0;
int lv_total = 0;
@ -87,7 +87,7 @@ static int lvscan_single(struct volume_group *vg, struct logical_volume *lv)
dummy = display_size(lv->size / 2, SIZE_SHORT);
log_print("%s%s '%s%s/%s' [%s]%s%s", active_str, snapshot_str,
fid->cmd->dev_dir, vg->name, lv->name, dummy,
fid->cmd->dev_dir, lv->vg->name, lv->name, dummy,
(lv->status & ALLOC_STRICT) ? " strict" : "",
(lv->status & ALLOC_CONTIGUOUS) ? " contiguous" : "");

View File

@ -25,7 +25,6 @@ int lvmsar(int argc, char **argv) {return 1;}
int pvdata(int argc, char **argv) {return 1;}
int vgcfgbackup(int argc, char **argv) {return 1;}
int vgcfgrestore(int argc, char **argv) {return 1;}
int vgdisplay(int argc, char **argv) {return 1;}
int vgexport(int argc, char **argv) {return 1;}
int vgimport(int argc, char **argv) {return 1;}
int vgmerge(int argc, char **argv) {return 1;}

View File

@ -87,9 +87,33 @@ int do_autobackup(struct volume_group *vg)
return 0;
}
int process_each_lv_in_vg(struct volume_group *vg,
int (*process_single) (struct logical_volume *lv))
{
int ret_max = 0;
int ret = 0;
struct list *lvh;
struct logical_volume *lv;
/* FIXME Export-handling */
if (vg->status & EXPORTED_VG) {
log_error("Volume group %s is exported", vg->name);
return ECMD_FAILED;
}
list_iterate(lvh, &vg->lvs) {
lv = &list_item(lvh, struct lv_list)->lv;
ret = process_single(lv);
if (ret > ret_max)
ret_max = ret;
}
return ret_max;
}
int process_each_lv(int argc, char **argv,
int (*process_single) (struct volume_group * vg,
struct logical_volume * lv))
int (*process_single) (struct logical_volume * lv))
{
int opt = 0;
int ret_max = 0;
@ -135,7 +159,7 @@ int process_each_lv(int argc, char **argv,
lv = &list_item(lvh, struct lv_list)->lv;
if ((ret = process_single(vg, lv)) > ret_max)
if ((ret = process_single(lv)) > ret_max)
ret_max = ret;
}
} else {
@ -152,20 +176,9 @@ int process_each_lv(int argc, char **argv,
ret_max = ECMD_FAILED;
continue;
}
/* FIXME Export-handling */
if (vg->status & EXPORTED_VG) {
log_error("Volume group %s is exported",
vg_name);
if (ret_max < ECMD_FAILED)
ret_max = ECMD_FAILED;
continue;
}
list_iterate(lvh, &vg->lvs) {
lv = &list_item(lvh, struct lv_list)->lv;
ret = process_single(vg, lv);
if (ret > ret_max)
ret_max = ret;
}
ret = process_each_lv_in_vg(vg, process_single);
if (ret > ret_max)
ret_max = ret;
vg_count++;
}
}
@ -196,8 +209,8 @@ int process_each_vg(int argc, char **argv,
}
list_iterate(vgh, vgs) {
ret =
process_single(list_item(vgh, struct name_list)->
name);
process_single(list_item
(vgh, struct name_list)->name);
if (ret > ret_max)
ret_max = ret;
}
@ -206,6 +219,25 @@ int process_each_vg(int argc, char **argv,
return ret_max;
}
int process_each_pv_in_vg(struct volume_group *vg,
int (*process_single) (struct volume_group * vg,
struct physical_volume * pv))
{
int ret_max = 0;
int ret = 0;
struct list *pvh;
list_iterate(pvh, &vg->pvs) {
ret = process_single(vg,
&list_item(pvh,
struct pv_list)->pv);
if (ret > ret_max)
ret_max = ret;
}
return ret_max;
}
int process_each_pv(int argc, char **argv, struct volume_group *vg,
int (*process_single) (struct volume_group * vg,
struct physical_volume * pv))
@ -233,13 +265,7 @@ int process_each_pv(int argc, char **argv, struct volume_group *vg,
}
} else {
log_verbose("Using all physical volume(s) in volume group");
list_iterate(pvh, &vg->pvs) {
ret = process_single(vg,
&list_item(pvh,
struct pv_list)->pv);
if (ret > ret_max)
ret_max = ret;
}
process_each_pv_in_vg(vg, process_single);
}
return ret_max;

View File

@ -29,12 +29,17 @@ int process_each_vg(int argc, char **argv,
int (*process_single) (const char *vg_name));
int process_each_pv(int argc, char **argv, struct volume_group *vg,
int (*process_single) (struct volume_group *vg,
struct physical_volume *pv));
int (*process_single) (struct volume_group * vg,
struct physical_volume * pv));
int process_each_lv(int argc, char **argv,
int (*process_single) (struct logical_volume * lv));
int process_each_lv(int argc, char **argv,
int (*process_single) (struct volume_group *vg,
struct logical_volume *lv));
int process_each_pv_in_vg(struct volume_group *vg,
int (*process_single) (struct volume_group * vg,
struct physical_volume * pv));
int process_each_lv_in_vg(struct volume_group *vg,
int (*process_single) (struct logical_volume * lv));
int is_valid_chars(char *n);

View File

@ -142,4 +142,6 @@ static inline const char *command_name(void)
extern struct format_instance *fid;
extern int lvdisplay_single(struct logical_volume *lv);
#endif

104
tools/vgdisplay.c Normal file
View File

@ -0,0 +1,104 @@
/*
* Copyright (C) 2001 Sistina Software
*
* LVM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* LVM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LVM; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "tools.h"
static int vgdisplay_single(const char *vg_name);
int vgdisplay(int argc, char **argv)
{
if (arg_count(colon_ARG) && arg_count(short_ARG)) {
log_error("Option -c is not allowed with option -s");
return EINVALID_CMD_LINE;
}
if (argc && arg_count(activevolumegroups_ARG)) {
log_error("Option -A is not allowed with volume group names");
return EINVALID_CMD_LINE;
}
/* FIXME -D disk_ARG is now redundant */
/********* FIXME: Do without this - or else 2(+) passes!
Figure out longest volume group name
for (c = opt; opt < argc; opt++) {
len = strlen(argv[opt]);
if (len > max_len)
max_len = len;
}
**********/
process_each_vg(argc, argv, &vgdisplay_single);
/******** FIXME Need to count number processed
Add this to process_each_vg if arg_count(activevolumegroups_ARG) ?
if (opt == argc) {
log_print("no ");
if (arg_count(activevolumegroups_ARG))
printf("active ");
printf("volume groups found\n\n");
return LVM_E_NO_VG;
}
************/
return 0;
}
static int vgdisplay_single(const char *vg_name)
{
struct volume_group *vg;
/* FIXME Do the active check here if activevolumegroups_ARG ? */
log_very_verbose("Finding volume group %s", vg_name);
if (!(vg = fid->ops->vg_read(fid, vg_name))) {
log_error("Volume group %s doesn't exist", vg_name);
return ECMD_FAILED;
}
if (vg->status & EXPORTED_VG)
log_print("WARNING: volume group %s is exported", vg_name);
if (arg_count(colon_ARG)) {
vgdisplay_colons(vg);
return 0;
}
if (arg_count(short_ARG)) {
vgdisplay_short(vg);
return 0;
}
vgdisplay_full(vg); /* was vg_show */
if (arg_count(verbose_ARG)) {
vgdisplay_extents(vg);
process_each_lv_in_vg(vg, &lvdisplay_full);
log_print("--- Physical volumes ---");
process_each_pv_in_vg(vg, &pvdisplay_short);
}
return 0;
}