1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-06 01:58:01 +03:00

New column-based reporting tools: lvs, pvs & vgs.

This commit is contained in:
Alasdair Kergon 2002-12-12 20:55:49 +00:00
parent eb537fa130
commit 4c64ed4ced
40 changed files with 2192 additions and 249 deletions

View File

@ -1 +1 @@
1.95.11-cvs (2002-11-18)
1.95.12-cvs (2002-12-12)

View File

@ -32,4 +32,5 @@
../lib/misc/lvm-string.h
../lib/misc/sharedlib.h
../lib/regex/matcher.h
../lib/report/report.h
../lib/uuid/uuid.h

View File

@ -56,6 +56,7 @@ SOURCES=\
regex/matcher.c \
regex/parse_rx.c \
regex/ttree.c \
report/report.c \
uuid/uuid.c
ifeq ("@LVM1@", "internal")

View File

@ -20,6 +20,7 @@
#include "lvm-file.h"
#include "format-text.h"
#include "sharedlib.h"
#include "display.h"
#ifdef LVM1_INTERNAL
#include "format1.h"
@ -153,6 +154,20 @@ static int _process_config(struct cmd_context *cmd)
DEFAULT_ACTIVATION);
set_activation(cmd->default_settings.activation);
cmd->default_settings.suffix = find_config_int(cmd->cf->root,
"global/suffix",
'/', DEFAULT_SUFFIX);
if (!(cmd->default_settings.unit_factor =
units_to_bytes(find_config_str(cmd->cf->root,
"global/units",
'/',
DEFAULT_UNITS),
&cmd->default_settings.unit_type))) {
log_error("Invalid units specification");
return 0;
}
return 1;
}

View File

@ -25,6 +25,9 @@ struct config_info {
int test;
int syslog;
int activation;
int suffix;
uint64_t unit_factor;
char unit_type;
const char *msg_prefix;
int cmd_name; /* Show command name? */

View File

@ -715,7 +715,7 @@ struct config_node *find_config_node(struct config_node *cn,
}
const char *find_config_str(struct config_node *cn,
const char *path, char sep, const char *fail)
const char *path, const char sep, const char *fail)
{
struct config_node *n = find_config_node(cn, path, sep);

View File

@ -51,10 +51,10 @@ int write_config_file(struct config_tree *cf, const char *file);
int reload_config_file(struct config_tree **cf);
struct config_node *find_config_node(struct config_node *cn,
const char *path, char seperator);
const char *path, char separator);
const char *find_config_str(struct config_node *cn,
const char *path, char sep, const char *fail);
const char *path, const char sep, const char *fail);
int find_config_int(struct config_node *cn, const char *path,
char sep, int fail);

View File

@ -47,6 +47,8 @@
#define DEFAULT_VERBOSE 0
#define DEFAULT_LOGLEVEL 0
#define DEFAULT_INDENT 1
#define DEFAULT_UNITS "h"
#define DEFAULT_SUFFIX 1
#define DEFAULT_ACTIVATION 1
@ -54,4 +56,24 @@
#define DEFAULT_MAX_HISTORY 100
#endif
#define DEFAULT_REP_ALIGNED 1
#define DEFAULT_REP_BUFFERED 1
#define DEFAULT_REP_HEADINGS 1
#define DEFAULT_REP_SEPARATOR " "
#define DEFAULT_LVS_COLS "lv_name,vg_name,lv_attr,lv_size,origin,snap_percent"
#define DEFAULT_VGS_COLS "vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free"
#define DEFAULT_PVS_COLS "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free"
#define DEFAULT_SEGS_COLS "lv_name,vg_name,lv_attr,stripes,segtype,seg_size"
#define DEFAULT_LVS_COLS_VERB "lv_name,vg_name,seg_count,lv_attr,lv_size,lv_minor,origin,snap_percent,lv_uuid"
#define DEFAULT_VGS_COLS_VERB "vg_name,vg_attr,vg_extent_size,pv_count,lv_count,snap_count,vg_size,vg_free,vg_uuid"
#define DEFAULT_PVS_COLS_VERB "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free,pv_uuid"
#define DEFAULT_SEGS_COLS_VERB "lv_name,vg_name,lv_attr,seg_start,seg_size,stripes,segtype,stripesize,chunksize"
#define DEFAULT_LVS_SORT "vg_name,lv_name"
#define DEFAULT_VGS_SORT "vg_name"
#define DEFAULT_PVS_SORT "pv_name"
#define DEFAULT_SEGS_SORT "vg_name,lv_name,seg_start"
#endif /* _LVM_DEFAULTS_H */

View File

@ -13,11 +13,13 @@ struct list {
struct list *n, *p;
};
static inline void list_init(struct list *head) {
static inline void list_init(struct list *head)
{
head->n = head->p = head;
}
static inline void list_add(struct list *head, struct list *elem) {
static inline void list_add(struct list *head, struct list *elem)
{
assert(head->n);
elem->n = head;
@ -27,7 +29,8 @@ static inline void list_add(struct list *head, struct list *elem) {
head->p = elem;
}
static inline void list_add_h(struct list *head, struct list *elem) {
static inline void list_add_h(struct list *head, struct list *elem)
{
assert(head->n);
elem->n = head->n;
@ -37,27 +40,35 @@ static inline void list_add_h(struct list *head, struct list *elem) {
head->n = elem;
}
static inline void list_del(struct list *elem) {
static inline void list_del(struct list *elem)
{
elem->n->p = elem->p;
elem->p->n = elem->n;
}
static inline int list_empty(struct list *head) {
static inline int list_empty(struct list *head)
{
return head->n == head;
}
static inline int list_end(struct list *head, struct list *elem)
{
return elem->n == head;
}
#define list_iterate(v, head) \
for (v = (head)->n; v != head; v = v->n)
#define list_iterate_safe(v, t, head) \
for (v = (head)->n, t = v->n; v != head; v = t, t = v->n)
static inline int list_size(struct list *head) {
static inline int list_size(struct list *head)
{
int s = 0;
struct list *v;
list_iterate(v, head)
s++;
s++;
return s;
}

View File

@ -49,6 +49,72 @@ static struct {
static int _num_policies = sizeof(_policies) / sizeof(*_policies);
static int _num_segtypes = sizeof(_segtypes) / sizeof(*_segtypes);
uint64_t units_to_bytes(const char *units, char *unit_type)
{
char *ptr;
uint64_t v;
ptr = (char *) units;
if (isdigit(*units)) {
v = (uint64_t) strtod(units, &ptr);
if (ptr == units)
return 0;
} else
v = 1;
if (v == 1)
*unit_type = *ptr;
else
*unit_type = 'U';
switch (*ptr) {
case 'h':
case 'H':
v = 1ULL;
*unit_type = *ptr;
break;
case 's':
v *= SECTOR_SIZE;
case 'b':
case 'B':
v *= 1ULL;
break;
case 'k':
v *= 1024ULL;
break;
case 'm':
v *= 1024ULL * 1024ULL;
break;
case 'g':
v *= 1024ULL * 1024ULL * 1024ULL;
break;
case 't':
v *= 1024ULL * 1024ULL * 1024ULL * 1024ULL;
break;
case 'K':
v *= 1000ULL;
break;
case 'M':
v *= 1000ULL * 1000ULL;
break;
case 'G':
v *= 1000ULL * 1000ULL * 1000ULL;
break;
case 'T':
v *= 1000ULL * 1000ULL * 1000ULL * 1000ULL;
break;
default:
return 0;
}
if (*(ptr + 1))
return 0;
return v;
}
const char *get_alloc_string(alloc_policy_t alloc)
{
int i;
@ -68,7 +134,7 @@ const char *get_segtype_string(segment_type_t segtype)
if (_segtypes[i].segtype == segtype)
return _segtypes[i].str;
return NULL;
return "unknown";
}
alloc_policy_t get_alloc_from_string(const char *str)
@ -95,36 +161,60 @@ segment_type_t get_segtype_from_string(const char *str)
return SEG_STRIPED;
}
char *display_size(uint64_t size, size_len_t sl)
const char *display_size(struct cmd_context *cmd, uint64_t size, size_len_t sl)
{
int s;
ulong byte = 1024 * 1024 * 1024;
int suffix = 1;
uint64_t byte;
uint64_t units = 1024ULL;
char *size_buf = NULL;
char *size_str[][2] = {
{" Terabyte", "TB"},
{" Gigabyte", "GB"},
{" Megabyte", "MB"},
{" Kilobyte", "KB"},
{"", ""},
{" ", " "}
char *size_str[][3] = {
{" Terabyte", " TB", "T"},
{" Gigabyte", " GB", "G"},
{" Megabyte", " MB", "M"},
{" Kilobyte", " KB", "K"},
{"", "", ""},
{" Byte ", " B ", "B"},
{" Units ", " Un", "U"},
{" Sectors ", " Se", "S"},
{" ", " ", " "},
};
if (!(size_buf = dbg_malloc(SIZE_BUF))) {
if (!(size_buf = pool_alloc(cmd->mem, SIZE_BUF))) {
log_error("no memory for size display buffer");
return NULL;
return "";
}
if (size == 0LL)
sprintf(size_buf, "0%s", size_str[5][sl]);
else {
suffix = cmd->current_settings.suffix;
for (s = 0; s < 8; s++)
if (toupper((int) cmd->current_settings.unit_type) ==
*size_str[s][2])
break;
if (size == 0ULL) {
sprintf(size_buf, "0%s", suffix ? size_str[s][sl] : "");
return size_buf;
}
if (s < 8) {
byte = cmd->current_settings.unit_factor;
size *= 1024ULL;
} else {
suffix = 1;
if (cmd->current_settings.unit_type == 'H')
units = 1000ULL;
else
units = 1024ULL;
byte = units * units * units;
s = 0;
while (size_str[s] && size < byte)
s++, byte /= 1024;
snprintf(size_buf, SIZE_BUF - 1,
"%.2f%s", (float) size / byte, size_str[s][sl]);
s++, byte /= units;
}
/* Caller to deallocate */
snprintf(size_buf, SIZE_BUF - 1, "%.2f%s", (float) size / byte,
suffix ? size_str[s][sl] : "");
return size_buf;
}
@ -155,10 +245,11 @@ void pvdisplay_colons(struct physical_volume *pv)
}
/* FIXME Include label fields */
void pvdisplay_full(struct physical_volume *pv, void *handle)
void pvdisplay_full(struct cmd_context *cmd, struct physical_volume *pv,
void *handle)
{
char uuid[64];
char *size, *size1; /*, *size2; */
const char *size;
uint64_t pe_free;
@ -175,23 +266,21 @@ void pvdisplay_full(struct physical_volume *pv, void *handle)
log_print("VG Name %s%s", pv->vg_name,
pv->status & EXPORTED_VG ? " (exported)" : "");
size = display_size((uint64_t) pv->size / 2, SIZE_SHORT);
size = display_size(cmd, (uint64_t) pv->size / 2, SIZE_SHORT);
if (pv->pe_size && pv->pe_count) {
size1 = display_size((pv->size - pv->pe_count * pv->pe_size)
/ 2, SIZE_SHORT);
/******** FIXME display LVM on-disk data size
size2 = display_size(pv->size / 2, SIZE_SHORT);
********/
log_print("PV Size %s" " / not usable %s", /* [LVM: %s]", */
size, size1); /* , size2); */
size, display_size(cmd,
(pv->size -
pv->pe_count * pv->pe_size) / 2,
SIZE_SHORT));
dbg_free(size1);
/* dbg_free(size2); */
} else
log_print("PV Size %s", size);
dbg_free(size);
/* PV number not part of LVM2 design
log_print("PV# %u", pv->pv_number);
@ -265,7 +354,6 @@ void lvdisplay_colons(struct logical_volume *lv)
int lvdisplay_full(struct cmd_context *cmd, struct logical_volume *lv,
void *handle)
{
char *size;
struct dm_info info;
int inkernel, snap_active;
char uuid[64];
@ -326,10 +414,10 @@ int lvdisplay_full(struct cmd_context *cmd, struct logical_volume *lv,
if (inkernel)
log_print("# open %u", info.open_count);
size = display_size(snap ? snap->origin->size / 2 : lv->size / 2,
SIZE_SHORT);
log_print("LV Size %s", size);
dbg_free(size);
log_print("LV Size %s",
display_size(cmd,
snap ? snap->origin->size / 2 : lv->size / 2,
SIZE_SHORT));
log_print("Current LE %u",
snap ? snap->origin->le_count : lv->le_count);
@ -348,9 +436,8 @@ int lvdisplay_full(struct cmd_context *cmd, struct logical_volume *lv,
if (snap_percent == -1)
snap_percent = 100;
size = display_size(snap->chunk_size / 2, SIZE_SHORT);
log_print("Snapshot chunk size %s", size);
dbg_free(size);
log_print("Snapshot chunk size %s",
display_size(cmd, snap->chunk_size / 2, SIZE_SHORT));
/*
size = display_size(lv->size / 2, SIZE_SHORT);
@ -451,7 +538,6 @@ void vgdisplay_full(struct volume_group *vg)
{
uint32_t access;
uint32_t active_pvs;
char *s1;
char uuid[64];
if (vg->status & PARTIAL_VG)
@ -497,28 +583,33 @@ void vgdisplay_full(struct volume_group *vg)
log_print("Cur PV %u", vg->pv_count);
log_print("Act PV %u", active_pvs);
s1 = display_size((uint64_t) vg->extent_count * (vg->extent_size / 2),
SIZE_SHORT);
log_print("VG Size %s", s1);
dbg_free(s1);
log_print("VG Size %s",
display_size(vg->cmd,
(uint64_t) vg->extent_count * (vg->extent_size /
2), SIZE_SHORT));
s1 = display_size(vg->extent_size / 2, SIZE_SHORT);
log_print("PE Size %s", s1);
dbg_free(s1);
log_print("PE Size %s",
display_size(vg->cmd, vg->extent_size / 2, SIZE_SHORT));
log_print("Total PE %u", vg->extent_count);
s1 = display_size(((uint64_t)
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);
vg->extent_count - vg->free_count, display_size(vg->cmd,
((uint64_t)
vg->
extent_count
-
vg->
free_count) *
(vg->
extent_size /
2),
SIZE_SHORT));
s1 = display_size((uint64_t) vg->free_count * (vg->extent_size / 2),
SIZE_SHORT);
log_print("Free PE / Size %u / %s", vg->free_count, s1);
dbg_free(s1);
log_print("Free PE / Size %u / %s", vg->free_count,
display_size(vg->cmd,
(uint64_t) vg->free_count * (vg->extent_size /
2), SIZE_SHORT));
if (!id_write_format(&vg->id, uuid, sizeof(uuid))) {
stack;
@ -538,16 +629,15 @@ void vgdisplay_colons(struct volume_group *vg)
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\" %-9s [%-9s used / %s free]", vg->name,
/********* FIXME if "open" print "/used" else print "/idle"??? ******/
s1, s2, s3);
dbg_free(s1);
dbg_free(s2);
dbg_free(s3);
display_size(vg->cmd, vg->extent_count * vg->extent_size / 2,
SIZE_SHORT), display_size(vg->cmd,
(vg->extent_count -
vg->free_count) *
vg->extent_size / 2,
SIZE_SHORT),
display_size(vg->cmd, vg->free_count * vg->extent_size / 2,
SIZE_SHORT));
return;
}

View File

@ -25,14 +25,17 @@
#include <stdint.h>
typedef enum { SIZE_LONG = 0, SIZE_SHORT = 1 } size_len_t;
typedef enum { SIZE_LONG = 0, SIZE_SHORT = 1, SIZE_UNIT = 2 } size_len_t;
uint64_t units_to_bytes(const char *units, char *unit_type);
/* Specify size in KB */
char *display_size(uint64_t size, size_len_t sl);
const char *display_size(struct cmd_context *cmd, uint64_t size, size_len_t sl);
char *display_uuid(char *uuidstr);
void pvdisplay_colons(struct physical_volume *pv);
void pvdisplay_full(struct physical_volume *pv, void *handle);
void pvdisplay_full(struct cmd_context *cmd, struct physical_volume *pv,
void *handle);
int pvdisplay_short(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv, void *handle);

View File

@ -297,14 +297,11 @@ static int _pv_setup(struct format_type *fmt,
uint64_t pvmetadatasize, struct list *mdas,
struct physical_volume *pv, struct volume_group *vg)
{
char *sz;
if (pv->size > MAX_PV_SIZE)
pv->size--;
if (pv->size > MAX_PV_SIZE) {
log_error("Physical volumes cannot be bigger than %s",
sz = display_size(MAX_PV_SIZE / 2, SIZE_SHORT));
dbg_free(sz);
display_size(fmt->cmd, MAX_PV_SIZE / 2, SIZE_SHORT));
return 0;
}
@ -365,9 +362,9 @@ static int _lv_setup(struct format_instance *fid, struct logical_volume *lv)
return 0;
}
if (lv->size > max_size) {
char *dummy = display_size(max_size / 2, SIZE_SHORT);
log_error("logical volumes cannot be larger than %s", dummy);
dbg_free(dummy);
log_error("logical volumes cannot be larger than %s",
display_size(fid->fmt->cmd, max_size / 2,
SIZE_SHORT));
return 0;
}
@ -447,22 +444,20 @@ int _vg_setup(struct format_instance *fid, struct volume_group *vg)
vg->max_pv = MAX_PV - 1;
if (vg->extent_size > MAX_PE_SIZE || vg->extent_size < MIN_PE_SIZE) {
char *dummy, *dummy2;
log_error("Extent size must be between %s and %s",
(dummy = display_size(MIN_PE_SIZE / 2, SIZE_SHORT)),
(dummy2 = display_size(MAX_PE_SIZE / 2, SIZE_SHORT)));
display_size(fid->fmt->cmd, MIN_PE_SIZE / 2,
SIZE_SHORT), display_size(fid->fmt->cmd,
MAX_PE_SIZE /
2,
SIZE_SHORT));
dbg_free(dummy);
dbg_free(dummy2);
return 0;
}
if (vg->extent_size % MIN_PE_SIZE) {
char *dummy;
log_error("Extent size must be multiple of %s",
(dummy = display_size(MIN_PE_SIZE / 2, SIZE_SHORT)));
dbg_free(dummy);
display_size(fid->fmt->cmd, MIN_PE_SIZE / 2,
SIZE_SHORT));
return 0;
}

View File

@ -28,8 +28,8 @@
*
*/
#include <stdio.h> /* FILE */
#include <string.h> /* strerror() */
#include <stdio.h> /* FILE */
#include <string.h> /* strerror() */
#include <errno.h>
#define _LOG_DEBUG 7
@ -65,7 +65,7 @@ int ignorelockingfailure(void);
void log_suppress(int suppress);
void print_log(int level, const char *file, int line, const char *format, ...)
__attribute__ (( format (printf, 4, 5) ));
__attribute__ ((format(printf, 4, 5)));
#define plog(l, x...) print_log(l, __FILE__, __LINE__ , ## x)
@ -90,4 +90,3 @@ void print_log(int level, const char *file, int line, const char *format, ...)
log_info("%s: %s failed: %s", y, x, strerror(errno))
#endif

52
lib/report/columns.h Normal file
View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2002 Sistina Software (UK) Limited.
*
* This file is released under the LGPL.
*/
/* Report type, Containing struct, Field type, Report heading,
* Data field with struct to pass to display function, Minimum display width,
* Display Fn, Unique format identifier */
FIELD(LVS, lv, STR, "LV UUID", lvid.id[1], 38, uuid, "lv_uuid")
FIELD(LVS, lv, STR, "LV", name, 4, string, "lv_name")
FIELD(LVS, lv, STR, "Attr", lvid, 4, lvstatus, "lv_attr")
FIELD(LVS, lv, NUM, "Min", minor, 3, int32, "lv_minor")
FIELD(LVS, lv, NUM, "LSize", size, 5, size64, "lv_size")
FIELD(LVS, lv, NUM, "#Seg", lvid, 4, lvsegcount, "seg_count")
FIELD(LVS, lv, STR, "Origin", lvid, 6, origin, "origin")
FIELD(LVS, lv, NUM, "Snap%", lvid, 6, snpercent, "snap_percent")
FIELD(PVS, pv, STR, "Fmt", id, 3, pvfmt, "pv_fmt")
FIELD(PVS, pv, STR, "PV UUID", id, 38, uuid, "pv_uuid")
FIELD(PVS, pv, NUM, "PSize", id, 5, pvsize, "pv_size")
FIELD(PVS, pv, NUM, "PFree", id, 5, pvfree, "pv_free")
FIELD(PVS, pv, NUM, "Used", id, 4, pvused, "pv_used")
FIELD(PVS, pv, STR, "PV", dev, 10, dev_name, "pv_name")
FIELD(PVS, pv, STR, "Attr", status, 4, pvstatus, "pv_attr")
FIELD(PVS, pv, NUM, "PE", pe_count, 3, uint32, "pv_pe_count")
FIELD(PVS, pv, NUM, "Alloc", pe_alloc_count, 5, uint32, "pv_pe_alloc_count")
FIELD(VGS, vg, STR, "Fmt", cmd, 3, vgfmt, "vg_fmt")
FIELD(VGS, vg, STR, "VG UUID", id, 38, uuid, "vg_uuid")
FIELD(VGS, vg, STR, "VG", name, 4, string, "vg_name")
FIELD(VGS, vg, STR, "Attr", status, 4, vgstatus, "vg_attr")
FIELD(VGS, vg, NUM, "VSize", cmd, 5, vgsize, "vg_size")
FIELD(VGS, vg, NUM, "VFree", cmd, 5, vgfree, "vg_free")
FIELD(VGS, vg, STR, "SYS ID", system_id, 6, string, "vg_sysid")
FIELD(VGS, vg, NUM, "Ext", extent_size, 3, size32, "vg_extent_size")
FIELD(VGS, vg, NUM, "#Ext", extent_count, 4, uint32, "vg_extent_count")
FIELD(VGS, vg, NUM, "Free", free_count, 4, uint32, "vg_free_count")
FIELD(VGS, vg, NUM, "MaxLV", max_lv, 5, uint32, "max_lv")
FIELD(VGS, vg, NUM, "MaxPV", max_pv, 5, uint32, "max_pv")
FIELD(VGS, vg, NUM, "#PV", pv_count, 3, uint32, "pv_count")
FIELD(VGS, vg, NUM, "#LV", lv_count, 3, uint32, "lv_count")
FIELD(VGS, vg, NUM, "#SN", snapshot_count, 3, uint32, "snap_count")
FIELD(VGS, vg, NUM, "Seq", seqno, 3, uint32, "vg_seqno")
FIELD(SEGS, seg, STR, "Type", list, 4, segtype, "segtype")
FIELD(SEGS, seg, NUM, "#Str", stripes, 4, uint32, "stripes")
FIELD(SEGS, seg, NUM, "Stripe", stripe_size, 6, size32, "stripesize")
FIELD(SEGS, seg, NUM, "Chunk", chunk_size, 5, size32, "chunksize")
FIELD(SEGS, seg, NUM, "Start", list, 5, segstart, "seg_start")
FIELD(SEGS, seg, NUM, "SSize", list, 5, segsize, "seg_size")

1067
lib/report/report.c Normal file

File diff suppressed because it is too large Load Diff

43
lib/report/report.h Normal file
View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2002 Sistina Software
*
* This LVM library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This LVM library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this LVM library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA
*
*/
#ifndef _LVM_REPORT_H
#define _LVM_REPORT_H
#include "metadata.h"
typedef enum { LVS = 1, PVS = 2, VGS = 4, SEGS = 8 } report_type_t;
struct field;
struct report_handle;
typedef int (*field_report_fn) (struct report_handle * dh, struct field * field,
const void *data);
void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
report_type_t *report_type, const char *separator,
int aligned, int buffered, int headings);
void report_free(void *handle);
int report_object(void *handle, struct volume_group *vg,
struct logical_volume *lv, struct physical_volume *pv,
struct lv_segment *seg);
int report_output(void *handle);
#endif

View File

@ -13,11 +13,13 @@ struct list {
struct list *n, *p;
};
static inline void list_init(struct list *head) {
static inline void list_init(struct list *head)
{
head->n = head->p = head;
}
static inline void list_add(struct list *head, struct list *elem) {
static inline void list_add(struct list *head, struct list *elem)
{
assert(head->n);
elem->n = head;
@ -27,7 +29,8 @@ static inline void list_add(struct list *head, struct list *elem) {
head->p = elem;
}
static inline void list_add_h(struct list *head, struct list *elem) {
static inline void list_add_h(struct list *head, struct list *elem)
{
assert(head->n);
elem->n = head->n;
@ -37,27 +40,35 @@ static inline void list_add_h(struct list *head, struct list *elem) {
head->n = elem;
}
static inline void list_del(struct list *elem) {
static inline void list_del(struct list *elem)
{
elem->n->p = elem->p;
elem->p->n = elem->n;
}
static inline int list_empty(struct list *head) {
static inline int list_empty(struct list *head)
{
return head->n == head;
}
static inline int list_end(struct list *head, struct list *elem)
{
return elem->n == head;
}
#define list_iterate(v, head) \
for (v = (head)->n; v != head; v = v->n)
#define list_iterate_safe(v, t, head) \
for (v = (head)->n, t = v->n; v != head; v = t, t = v->n)
static inline int list_size(struct list *head) {
static inline int list_size(struct list *head)
{
int s = 0;
struct list *v;
list_iterate(v, head)
s++;
s++;
return s;
}

View File

@ -22,11 +22,11 @@ VPATH = @srcdir@
MAN5=lvm.conf.5
MAN8=lvchange.8 lvcreate.8 lvdisplay.8 lvextend.8 lvm.8 lvmchange.8 \
lvreduce.8 lvremove.8 lvrename.8 lvscan.8 pvchange.8 \
pvcreate.8 pvdisplay.8 pvremove.8 pvscan.8 vgcfgbackup.8 \
lvreduce.8 lvremove.8 lvrename.8 lvs.8 lvscan.8 pvchange.8 \
pvcreate.8 pvdisplay.8 pvremove.8 pvs.8 pvscan.8 vgcfgbackup.8 \
vgcfgrestore.8 vgchange.8 vgck.8 vgcreate.8 \
vgconvert.8 vgdisplay.8 vgextend.8 vgmerge.8 vgreduce.8 vgremove.8 \
vgrename.8 vgscan.8
vgrename.8 vgs.8 vgscan.8
MAN5DIR=${mandir}/man5
MAN8DIR=${mandir}/man8

64
man/lvs.8 Normal file
View File

@ -0,0 +1,64 @@
.TH LVS 8 "LVM TOOLS" "Sistina Software UK" \" -*- nroff -*-
.SH NAME
lvs \- report information about logical volumes
.SH SYNOPSIS
.B lvs
[\-\-aligned] [\-d/\-\-debug] [\-h/\-?/\-\-help]
[\-\-ignorelockingfailure] [\-\-noheadings] [\-\-nosuffix]
[\-o/\-\-options [+]Field[,Field]]
[\-O/\-\-sort [+/-]Key1[,[+/-]Key2[,...]]]
[\-P/\-\-partial] [\-\-segments]
[\-\-separator Separator] [\-\-unbuffered]
[\-\-units hsbkmgtHKMGT]
[\-v/\-\-verbose]
[\-\-version] [VolumeGroupName [VolumeGroupName...]]
.SH DESCRIPTION
vgs produces formatted output about volume groups
.SH OPTIONS
See \fBlvm\fP for common options.
.TP
.I \-\-aligned
Use with \-\-separator to align the output columns.
.TP
.I \-\-noheadings
Suppress the headings line that is normally the first line of output.
Useful if grepping the output.
.TP
.I \-\-nosuffix
Suppress the suffix on output sizes. Use with \-\-units (except h and H)
if processing the output.
.TP
.I \-o, \-\-options
Comma-separated ordered list of columns. Precede the list with '+' to append
to the default selection of columns. Column names are:
lv_uuid, lv_name, lv_attr, lv_minor, lv_size, seg_count, origin,
snap_percent (suppressed if no kernel driver), segtype, stripes,
stripesize, chunksize, seg_start, seg_size.
With \-\-segments, any "seg_" prefixes are optional; otherwise any "lv_"
prefixes are optional. Columns mentioned in \fBvgs (8)\fP
can also be chosen
The lv_attr bits are: (o)rigin, (s)napshot, (w)riteable, (r)eadonly,
(c)ontiguous allocation, (n)ext free allocation, fixed (m)inor, (s)uspended,
(a)ctive, device (o)pen.
.TP
.I \-\-segments
Use default columns that emphasize segment information.
.TP
.I \-O, \-\-sort
Comma-separated ordered list of columns to sort by. Replaces the default
selection. Precede any column with - for a reverse sort on that column.
.TP
.I \-\-separator Separator
String to use to separate each column. Useful if grepping the output.
.TP
.I \-\-unbuffered
Produce output immediately without sorting or aligning the columns properly.
.TP
.I \-\-units hsbkmgtHKMGT
All sizes are output in these units: (h)uman-readable, (s)ectors, (b)ytes,
(k)ilobytes, (m)egabytes, (g)igabytes, (t)erabytes. Capitalise to use multiples
of 1000 (S.I.) instead of 1024. Can also specify custom (u)nits e.g.
\-\-units 3M
.SH SEE ALSO
.BR pvs (8),
.BR vgs (8)

54
man/pvs.8 Normal file
View File

@ -0,0 +1,54 @@
.TH PVS 8 "LVM TOOLS" "Sistina Software UK" \" -*- nroff -*-
.SH NAME
pvs \- report information about physical volumes
.SH SYNOPSIS
.B pvs
[\-\-aligned] [\-d/\-\-debug] [\-h/\-?/\-\-help]
[\-\-ignorelockingfailure] [\-\-noheadings] [\-\-nosuffix]
[\-o/\-\-options [+]Field[,Field]]
[\-O/\-\-sort [+/-]Key1[,[+/-]Key2[,...]]]
[\-\-separator Separator] [\-\-unbuffered]
[\-\-units hsbkmgtHKMGT]
[\-v/\-\-verbose]
[\-\-version] [PhysicalVolume [PhysicalVolume...]]
.SH DESCRIPTION
pvs produces formatted output about physical volumes
.SH OPTIONS
See \fBlvm\fP for common options.
.TP
.I \-\-aligned
Use with \-\-separator to align the output columns.
.TP
.I \-\-noheadings
Suppress the headings line that is normally the first line of output.
Useful if grepping the output.
.TP
.I \-\-nosuffix
Suppress the suffix on output sizes. Use with \-\-units (except h and H)
if processing the output.
.TP
.I \-o, \-\-options
Comma-separated ordered list of columns. Precede the list with '+' to append
to the default selection of columns. Column names are: pv_fmt, pv_uuid,
pv_size, pv_free, pv_used, pv_name, pv_attr, pv_pe_count, pv_pe_alloc_count.
The "pv_" prefix is optional. Columns mentioned in \fBvgs (8)\fP can also
be chosen. The pv_attr bits are: (a)llocatable and e(x)ported.
.TP
.I \-O, \-\-sort
Comma-separated ordered list of columns to sort by. Replaces the default
selection. Precede any column with - for a reverse sort on that column.
.TP
.I \-\-separator Separator
String to use to separate each column. Useful if grepping the output.
.TP
.I \-\-unbuffered
Produce output immediately without sorting or aligning the columns properly.
.TP
.I \-\-units hsbkmgtHKMGT
All sizes are output in these units: (h)uman-readable, (s)ectors, (b)ytes,
(k)ilobytes, (m)egabytes, (g)igabytes, (t)erabytes. Capitalise to use multiples
of 1000 (S.I.) instead of 1024. Can also specify custom (u)nits e.g.
\-\-units 3M
.SH SEE ALSO
.BR lvs (8),
.BR vgs (8)

58
man/vgs.8 Normal file
View File

@ -0,0 +1,58 @@
.TH VGS 8 "LVM TOOLS" "Sistina Software UK" \" -*- nroff -*-
.SH NAME
vgs \- report information about volume groups
.SH SYNOPSIS
.B vgs
[\-\-aligned] [\-d/\-\-debug] [\-h/\-?/\-\-help]
[\-\-ignorelockingfailure] [\-\-noheadings] [\-\-nosuffix]
[\-o/\-\-options [+]Field[,Field]]
[\-O/\-\-sort [+/-]Key1[,[+/-]Key2[,...]]]
[\-P/\-\-partial]
[\-\-separator Separator] [\-\-unbuffered]
[\-\-units hsbkmgtHKMGT]
[\-v/\-\-verbose]
[\-\-version] [VolumeGroupName [VolumeGroupName...]]
.SH DESCRIPTION
vgs produces formatted output about volume groups
.SH OPTIONS
See \fBlvm\fP for common options.
.TP
.I \-\-aligned
Use with \-\-separator to align the output columns.
.TP
.I \-\-noheadings
Suppress the headings line that is normally the first line of output.
Useful if grepping the output.
.TP
.I \-\-nosuffix
Suppress the suffix on output sizes. Use with \-\-units (except h and H)
if processing the output.
.TP
.I \-o, \-\-options
Comma-separated ordered list of columns. Precede the list with '+' to append
to the default selection of columns. Column names are: vg_fmt, vg_uuid,
vg_name, vg_attr, vg_size, vg_free, vg_sysid, vg_extent_size, vg_extent_count,
vg_free_count, max_lv, max_pv, pv_count, lv_count, snap_count, vg_seqno.
Any "vg_" prefixes are optional. Columns mentioned in either \fBpvs (8)\fP
or \fBlvs (8)\fP can also be chosen, but columns cannot be taken from both
at the same time. The vg_attr bits are: (w)riteable, (r)eadonly,
resi(z)eable, e(x)ported, (p)artial.
.TP
.I \-O, \-\-sort
Comma-separated ordered list of columns to sort by. Replaces the default
selection. Precede any column with - for a reverse sort on that column.
.TP
.I \-\-separator Separator
String to use to separate each column. Useful if grepping the output.
.TP
.I \-\-unbuffered
Produce output immediately without sorting or aligning the columns properly.
.TP
.I \-\-units hsbkmgtHKMGT
All sizes are output in these units: (h)uman-readable, (s)ectors, (b)ytes,
(k)ilobytes, (m)egabytes, (g)igabytes, (t)erabytes. Capitalise to use multiples
of 1000 (S.I.) instead of 1024. Can also specify custom (u)nits e.g.
\-\-units 3M
.SH SEE ALSO
.BR pvs (8),
.BR lvs (8)

View File

@ -39,6 +39,7 @@ SOURCES=\
pvdisplay.c \
pvremove.c \
pvscan.c \
report.c \
toollib.c \
vgcfgbackup.c \
vgcfgrestore.c \
@ -67,8 +68,8 @@ lvm: $(OBJECTS) $(top_srcdir)/lib/liblvm.a
$(CC) -o lvm $(OBJECTS) $(LD_FLAGS) -L$(top_srcdir)/lib \
-L$(DESTDIR)/lib -llvm -ldevmapper $(LIBS) -ldl -rdynamic
.commands: commands.h cmdnames.h
$(CC) -E -P cmdnames.h | grep -v help > .commands
.commands: commands.h cmdnames.h Makefile
$(CC) -E -P cmdnames.h | egrep -v '(help|version)' > .commands
install: $(TARGETS)
$(INSTALL) -D -o $(OWNER) -g $(GROUP) -m 555 $(STRIP) lvm \

View File

@ -17,6 +17,12 @@ arg(metadatasize_ARG, '\0', "metadatasize", size_mb_arg)
arg(restorefile_ARG, '\0', "restorefile", string_arg)
arg(labelsector_ARG, '\0', "labelsector", int_arg)
arg(driverloaded_ARG, '\0', "driverloaded", yes_no_arg)
arg(aligned_ARG, '\0', "aligned", NULL)
arg(unbuffered_ARG, '\0', "unbuffered", NULL)
arg(noheadings_ARG, '\0', "noheadings", NULL)
arg(segments_ARG, '\0', "segments", NULL)
arg(units_ARG, '\0', "units", string_arg)
arg(nosuffix_ARG, '\0', "nosuffix", NULL)
/* Allow some variations */
arg(resizable_ARG, '\0', "resizable", yes_no_arg)
@ -32,6 +38,7 @@ arg(activevolumegroups_ARG, 'A', "activevolumegroups", NULL)
arg(blockdevice_ARG, 'b', "blockdevice", NULL)
arg(chunksize_ARG, 'c', "chunksize", size_kb_arg)
arg(colon_ARG, 'c', "colon", NULL)
arg(columns_ARG, 'C', "columns", NULL)
arg(contiguous_ARG, 'C', "contiguous", yes_no_arg)
arg(debug_ARG, 'd', "debug", NULL)
arg(disk_ARG, 'D', "disk", NULL)
@ -61,6 +68,7 @@ arg(oldpath_ARG, 'n', "oldpath", NULL)
arg(nofsck_ARG, 'n', "nofsck", NULL)
arg(novolumegroup_ARG, 'n', "novolumegroup", NULL)
arg(options_ARG, 'o', "options", string_arg)
arg(sort_ARG, 'O', "sort", string_arg)
arg(permission_ARG, 'p', "permission", permission_arg)
arg(maxphysicalvolumes_ARG, 'p', "maxphysicalvolumes", int_arg)
arg(partial_ARG, 'P', "partial", NULL)
@ -68,6 +76,7 @@ arg(physicalvolume_ARG, 'P', "physicalvolume", NULL)
arg(readahead_ARG, 'r', "readahead", int_arg)
arg(reset_ARG, 'R', "reset", NULL)
arg(physicalextentsize_ARG, 's', "physicalextentsize", size_mb_arg)
arg(separator_ARG, 's', "separator", string_arg)
arg(stdin_ARG, 's', "stdin", NULL)
arg(snapshot_ARG, 's', "snapshot", NULL)
arg(short_ARG, 's', "short", NULL)

View File

@ -62,6 +62,7 @@ xx(lvchange,
"\t[-r|--readahead ReadAheadSectors]\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
autobackup_ARG, available_ARG, contiguous_ARG,
@ -118,11 +119,34 @@ xx(lvdisplay,
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[-m|--maps]\n"
"\t[--nosuffix]\n"
"\t[-P|--partial] " "\n"
"\t[--units hsbkmgtHKMGT]\n"
"\t[-v|--verbose]\n"
"\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
"\t[--version]" "\n"
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n"
"\n"
"lvdisplay --columns|-C\n"
"\t[--aligned]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
"\t[-o|--options [+]Field[,Field]]\n"
"\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n"
"\t[-P|--partial] " "\n"
"\t[--segments]\n"
"\t[--separator Separator]\n"
"\t[--unbuffered]\n"
"\t[--units hsbkmgtHKMGT]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
colon_ARG, disk_ARG, ignorelockingfailure_ARG, maps_ARG, partial_ARG)
aligned_ARG, colon_ARG, columns_ARG, disk_ARG, ignorelockingfailure_ARG,
maps_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, sort_ARG,
partial_ARG, segments_ARG, separator_ARG, unbuffered_ARG, units_ARG)
xx(lvextend,
"Add space to a logical volume",
@ -135,6 +159,7 @@ xx(lvextend,
"\t -L|--size [+]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\tLogicalVolume[Path] [ PhysicalVolumePath... ]\n",
autobackup_ARG, extents_ARG, size_ARG, stripes_ARG,
@ -146,7 +171,8 @@ xx(lvmchange,
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[-R|--reset]\n"
"\t[-v|--verbose]\n",
"\t[-v|--verbose]\n"
"\t[--version]" "\n",
reset_ARG)
@ -155,7 +181,8 @@ xx(lvmdiskscan,
"lvmdiskscan\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[-l|--lvmpartition]\n",
"\t[-l|--lvmpartition]\n"
"\t[--version]" "\n",
lvmpartition_ARG)
@ -165,6 +192,7 @@ xx(lvmsadc,
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\t[LogFilePath]\n" )
xx(lvmsar,
@ -175,6 +203,7 @@ xx(lvmsar,
"\t[-h|--help]\n"
"\t[-s|--stdin]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\tLogFilePath\n",
full_ARG, stdin_ARG)
@ -190,6 +219,7 @@ xx(lvreduce,
"\t -L|--size [-]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\tLogicalVolume[Path]\n",
autobackup_ARG, force_ARG, extents_ARG,
@ -204,6 +234,7 @@ xx(lvremove,
"\t[-h|--help]\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
autobackup_ARG, force_ARG, test_ARG)
@ -233,11 +264,36 @@ xx(lvresize,
"\t -L|--size [+|-]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\tLogicalVolume[Path] [ PhysicalVolumePath... ]\n",
autobackup_ARG, extents_ARG, size_ARG, stripes_ARG, stripesize_ARG,
test_ARG)
xx(lvs,
"Display information about logical volumes",
"lvs" "\n"
"\t[--aligned]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
"\t[-o|--options [+]Field[,Field]]\n"
"\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n"
"\t[-P|--partial] " "\n"
"\t[--segments]\n"
"\t[--separator Separator]\n"
"\t[--unbuffered]\n"
"\t[--units hsbkmgtHKMGT]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
aligned_ARG, ignorelockingfailure_ARG, noheadings_ARG, nosuffix_ARG,
options_ARG, partial_ARG, segments_ARG, separator_ARG, sort_ARG,
unbuffered_ARG, units_ARG)
xx(lvscan,
"List all logical volumes in all volume groups",
"lvscan " "\n"
@ -258,6 +314,7 @@ xx(pvchange,
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\t[-a|--all]\n"
"\t[-t|--test]\n"
"\t[-x|--allocatable y|n]\n"
@ -307,18 +364,39 @@ xx(pvdata,
physicalvolume_ARG, uuidlist_ARG, volumegroup_ARG)
xx(pvdisplay,
"Display various attributes of logical volume(s)",
"Display various attributes of physical volume(s)",
"pvdisplay\n"
"\t[-c|--colon]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[-m|--maps]\n"
"\t[--nosuffix]\n"
"\t[-s|--short]\n"
"\t[--units hsbkmgtHKMGT]\n"
"\t[-v|--verbose]\n"
"\tPhysicalVolumePath [PhysicalVolumePath...]\n",
"\t[--version]" "\n"
"\t[PhysicalVolumePath [PhysicalVolumePath...]]\n"
"\n"
"pvdisplay --columns|-C\n"
"\t[--aligned]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--noheadings]\n"
"\t[--nosuffix]\n"
"\t[-o|--options [+]Field[,Field]]\n"
"\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n"
"\t[--separator Separator]\n"
"\t[--unbuffered]\n"
"\t[--units hsbkmgtHKMGT]\n"
"\t[-v|--verbose]\n"
"\t[--version]" "\n"
"\t[PhysicalVolumePath [PhysicalVolumePath...]]\n",
colon_ARG, ignorelockingfailure_ARG, maps_ARG, short_ARG)
aligned_ARG, colon_ARG, columns_ARG, ignorelockingfailure_ARG, maps_ARG,
noheadings_ARG, nosuffix_ARG, options_ARG, separator_ARG, short_ARG,
sort_ARG, unbuffered_ARG, units_ARG)
xx(pvmove,
"Move extents from one physical volume to another",
@ -366,6 +444,27 @@ xx(pvresize,
***/
autobackup_ARG, physicalvolumesize_ARG)
xx(pvs,
"Display information about physical volumes",
"