2001-09-25 16:49:28 +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-09-25 16:49:28 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2001-09-25 16:49:28 +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-09-25 16:49:28 +04:00
*
2004-03-30 23:35:44 +04:00
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2001-09-25 16:49:28 +04:00
*/
2002-11-18 17:01:16 +03:00
# include "lib.h"
2001-10-01 19:14:39 +04:00
# include "metadata.h"
2001-10-18 20:55:19 +04:00
# include "display.h"
2001-11-08 19:15:58 +03:00
# include "activate.h"
2002-02-11 23:50:53 +03:00
# include "toolcontext.h"
2004-09-16 22:40:56 +04:00
# include "segtype.h"
2002-01-21 14:29:06 +03:00
2001-09-25 16:49:28 +04:00
# define SIZE_BUF 128
2006-05-10 01:23:51 +04:00
typedef enum { SIZE_LONG = 0 , SIZE_SHORT = 1 , SIZE_UNIT = 2 } size_len_t ;
2002-11-18 17:01:16 +03:00
static struct {
alloc_policy_t alloc ;
const char * str ;
} _policies [ ] = {
{
ALLOC_CONTIGUOUS , " contiguous " } , {
2004-05-19 02:12:53 +04:00
ALLOC_NORMAL , " normal " } , {
ALLOC_ANYWHERE , " anywhere " } , {
ALLOC_INHERIT , " inherit " }
2002-11-18 17:01:16 +03:00
} ;
static int _num_policies = sizeof ( _policies ) / sizeof ( * _policies ) ;
2002-12-12 23:55:49 +03:00
uint64_t units_to_bytes ( const char * units , char * unit_type )
{
2002-12-20 02:25:55 +03:00
char * ptr = NULL ;
2002-12-12 23:55:49 +03:00
uint64_t v ;
if ( isdigit ( * units ) ) {
v = ( uint64_t ) strtod ( units , & ptr ) ;
if ( ptr = = units )
return 0 ;
2002-12-20 02:25:55 +03:00
units = ptr ;
2002-12-12 23:55:49 +03:00
} else
v = 1 ;
if ( v = = 1 )
2002-12-20 02:25:55 +03:00
* unit_type = * units ;
2002-12-12 23:55:49 +03:00
else
* unit_type = ' U ' ;
2002-12-20 02:25:55 +03:00
switch ( * units ) {
2002-12-12 23:55:49 +03:00
case ' h ' :
case ' H ' :
2003-03-24 21:08:53 +03:00
v = UINT64_C ( 1 ) ;
2002-12-20 02:25:55 +03:00
* unit_type = * units ;
2002-12-12 23:55:49 +03:00
break ;
case ' s ' :
v * = SECTOR_SIZE ;
2003-07-05 02:34:56 +04:00
break ;
2002-12-12 23:55:49 +03:00
case ' b ' :
case ' B ' :
2003-03-24 21:08:53 +03:00
v * = UINT64_C ( 1 ) ;
2002-12-12 23:55:49 +03:00
break ;
2003-03-24 21:08:53 +03:00
# define KILO UINT64_C(1024)
2002-12-12 23:55:49 +03:00
case ' k ' :
2002-12-20 02:25:55 +03:00
v * = KILO ;
2003-07-05 02:34:56 +04:00
break ;
2002-12-12 23:55:49 +03:00
case ' m ' :
2002-12-20 02:25:55 +03:00
v * = KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' g ' :
2002-12-20 02:25:55 +03:00
v * = KILO * KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' t ' :
2002-12-20 02:25:55 +03:00
v * = KILO * KILO * KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
2002-12-20 02:25:55 +03:00
# undef KILO
2003-03-24 21:08:53 +03:00
# define KILO UINT64_C(1000)
2002-12-12 23:55:49 +03:00
case ' K ' :
2002-12-20 02:25:55 +03:00
v * = KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' M ' :
2002-12-20 02:25:55 +03:00
v * = KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' G ' :
2002-12-20 02:25:55 +03:00
v * = KILO * KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' T ' :
2002-12-20 02:25:55 +03:00
v * = KILO * KILO * KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
2002-12-20 02:25:55 +03:00
# undef KILO
2002-12-12 23:55:49 +03:00
default :
return 0 ;
}
2002-12-20 02:25:55 +03:00
if ( * ( units + 1 ) )
2002-12-12 23:55:49 +03:00
return 0 ;
return v ;
}
2002-11-18 17:01:16 +03:00
const char * get_alloc_string ( alloc_policy_t alloc )
{
int i ;
for ( i = 0 ; i < _num_policies ; i + + )
if ( _policies [ i ] . alloc = = alloc )
return _policies [ i ] . str ;
return NULL ;
}
alloc_policy_t get_alloc_from_string ( const char * str )
{
int i ;
for ( i = 0 ; i < _num_policies ; i + + )
if ( ! strcmp ( _policies [ i ] . str , str ) )
return _policies [ i ] . alloc ;
2004-05-19 02:12:53 +04:00
/* Special case for old metadata */
if ( ! strcmp ( " next free " , str ) )
return ALLOC_NORMAL ;
log_error ( " Unrecognised allocation policy %s " , str ) ;
return ALLOC_INVALID ;
2002-11-18 17:01:16 +03:00
}
2004-06-07 19:22:43 +04:00
/* Size supplied in sectors */
2006-05-10 01:23:51 +04:00
static const char * _display_size ( struct cmd_context * cmd , uint64_t size , size_len_t sl )
2001-09-25 16:49:28 +04:00
{
int s ;
2004-05-28 16:47:57 +04:00
int suffix = 1 , precision ;
2003-04-02 23:11:23 +04:00
uint64_t byte = UINT64_C ( 0 ) ;
2003-03-24 21:08:53 +03:00
uint64_t units = UINT64_C ( 1024 ) ;
2001-09-25 16:49:28 +04:00
char * size_buf = NULL ;
2002-12-20 02:25:55 +03:00
const char * size_str [ ] [ 3 ] = {
2002-12-12 23:55:49 +03:00
{ " Terabyte " , " TB " , " T " } ,
{ " Gigabyte " , " GB " , " G " } ,
{ " Megabyte " , " MB " , " M " } ,
{ " Kilobyte " , " KB " , " K " } ,
{ " " , " " , " " } ,
{ " Byte " , " B " , " B " } ,
{ " Units " , " Un " , " U " } ,
{ " Sectors " , " Se " , " S " } ,
{ " " , " " , " " } ,
2001-09-25 16:49:28 +04:00
} ;
2005-10-17 03:03:59 +04:00
if ( ! ( size_buf = dm_pool_alloc ( cmd - > mem , SIZE_BUF ) ) ) {
2001-09-25 16:49:28 +04:00
log_error ( " no memory for size display buffer " ) ;
2002-12-12 23:55:49 +03:00
return " " ;
}
suffix = cmd - > current_settings . suffix ;
for ( s = 0 ; s < 8 ; s + + )
if ( toupper ( ( int ) cmd - > current_settings . unit_type ) = =
* size_str [ s ] [ 2 ] )
break ;
2003-03-24 21:08:53 +03:00
if ( size = = UINT64_C ( 0 ) ) {
2002-12-12 23:55:49 +03:00
sprintf ( size_buf , " 0%s " , suffix ? size_str [ s ] [ sl ] : " " ) ;
return size_buf ;
2001-09-25 16:49:28 +04:00
}
2002-12-12 23:55:49 +03:00
if ( s < 8 ) {
byte = cmd - > current_settings . unit_factor ;
2004-06-07 19:22:43 +04:00
size * = UINT64_C ( 512 ) ;
2002-12-12 23:55:49 +03:00
} else {
2004-06-07 19:22:43 +04:00
size / = 2 ;
2002-12-12 23:55:49 +03:00
suffix = 1 ;
if ( cmd - > current_settings . unit_type = = ' H ' )
2003-03-24 21:08:53 +03:00
units = UINT64_C ( 1000 ) ;
2002-12-12 23:55:49 +03:00
else
2003-03-24 21:08:53 +03:00
units = UINT64_C ( 1024 ) ;
2002-12-12 23:55:49 +03:00
byte = units * units * units ;
2001-09-25 16:49:28 +04:00
s = 0 ;
while ( size_str [ s ] & & size < byte )
2002-12-12 23:55:49 +03:00
s + + , byte / = units ;
2001-09-25 16:49:28 +04:00
}
2004-05-28 16:47:57 +04:00
/* FIXME Make precision configurable */
switch ( toupper ( ( int ) cmd - > current_settings . unit_type ) ) {
case ' B ' :
case ' S ' :
precision = 0 ;
break ;
default :
precision = 2 ;
}
snprintf ( size_buf , SIZE_BUF - 1 , " %.*f%s " , precision ,
2004-06-07 19:22:43 +04:00
( double ) size / byte , suffix ? size_str [ s ] [ sl ] : " " ) ;
2002-12-12 23:55:49 +03:00
2001-09-25 16:49:28 +04:00
return size_buf ;
}
2006-05-10 01:23:51 +04:00
const char * display_size_long ( struct cmd_context * cmd , uint64_t size )
{
return _display_size ( cmd , size , SIZE_LONG ) ;
}
const char * display_size_units ( struct cmd_context * cmd , uint64_t size )
{
return _display_size ( cmd , size , SIZE_UNIT ) ;
}
const char * display_size ( struct cmd_context * cmd , uint64_t size )
{
return _display_size ( cmd , size , SIZE_SHORT ) ;
}
2001-10-18 20:55:19 +04:00
void pvdisplay_colons ( struct physical_volume * pv )
{
2002-01-21 14:29:06 +03:00
char uuid [ 64 ] ;
2001-10-18 20:55:19 +04:00
if ( ! pv )
return ;
2002-01-21 14:29:06 +03:00
if ( ! id_write_format ( & pv - > id , uuid , sizeof ( uuid ) ) ) {
stack ;
return ;
}
2001-10-18 20:55:19 +04:00
2002-12-20 02:25:55 +03:00
log_print ( " %s:%s:% " PRIu64 " :-1:%u:%u:-1:% " PRIu32 " :%u:%u:%u:%s " ,
2001-11-13 20:53:06 +03:00
dev_name ( pv - > dev ) , pv - > vg_name , pv - > size ,
/* FIXME pv->pv_number, Derive or remove? */
pv - > status , /* FIXME Support old or new format here? */
2002-04-24 22:20:51 +04:00
pv - > status & ALLOCATABLE_PV , /* FIXME remove? */
2001-11-13 20:53:06 +03:00
/* FIXME pv->lv_cur, Remove? */
pv - > pe_size / 2 ,
pv - > pe_count ,
2002-04-24 22:20:51 +04:00
pv - > pe_count - pv - > pe_alloc_count ,
pv - > pe_alloc_count , * uuid ? uuid : " none " ) ;
2001-10-18 20:55:19 +04:00
return ;
}
2002-11-18 17:01:16 +03:00
/* FIXME Include label fields */
2002-12-12 23:55:49 +03:00
void pvdisplay_full ( struct cmd_context * cmd , struct physical_volume * pv ,
2006-05-10 01:23:51 +04:00
void * handle __attribute ( ( unused ) ) )
2001-10-18 20:55:19 +04:00
{
2002-01-21 14:29:06 +03:00
char uuid [ 64 ] ;
2002-12-12 23:55:49 +03:00
const char * size ;
2001-10-18 20:55:19 +04:00
2002-12-20 02:25:55 +03:00
uint32_t pe_free ;
2001-10-18 20:55:19 +04:00
2001-11-13 20:53:06 +03:00
if ( ! pv )
return ;
2001-10-18 20:55:19 +04:00
2002-01-21 14:29:06 +03:00
if ( ! id_write_format ( & pv - > id , uuid , sizeof ( uuid ) ) ) {
stack ;
return ;
}
2001-10-18 20:55:19 +04:00
log_print ( " --- %sPhysical volume --- " , pv - > pe_size ? " " : " NEW " ) ;
2001-10-25 18:04:18 +04:00
log_print ( " PV Name %s " , dev_name ( pv - > dev ) ) ;
2002-01-29 19:30:18 +03:00
log_print ( " VG Name %s%s " , pv - > vg_name ,
pv - > status & EXPORTED_VG ? " (exported) " : " " ) ;
2001-10-18 20:55:19 +04:00
2006-05-10 01:23:51 +04:00
size = display_size ( cmd , ( uint64_t ) pv - > size ) ;
2001-10-18 20:55:19 +04:00
if ( pv - > pe_size & & pv - > pe_count ) {
2002-11-18 17:01:16 +03:00
/******** FIXME display LVM on-disk data size
2006-05-10 01:23:51 +04:00
size2 = display_size ( cmd , pv - > size ) ;
2001-10-18 20:55:19 +04:00
* * * * * * * */
2002-11-18 17:01:16 +03:00
log_print ( " PV Size %s " " / not usable %s " , /* [LVM: %s]", */
2004-06-07 19:22:43 +04:00
size ,
display_size ( cmd , ( pv - > size -
2006-05-10 01:23:51 +04:00
( uint64_t ) pv - > pe_count * pv - > pe_size ) ) ) ;
2001-10-18 20:55:19 +04:00
} else
log_print ( " PV Size %s " , size ) ;
2002-11-18 17:01:16 +03:00
/* PV number not part of LVM2 design
log_print ( " PV# %u " , pv - > pv_number ) ;
*/
2001-10-18 20:55:19 +04:00
2002-04-24 22:20:51 +04:00
pe_free = pv - > pe_count - pv - > pe_alloc_count ;
2002-01-10 18:09:51 +03:00
if ( pv - > pe_count & & ( pv - > status & ALLOCATABLE_PV ) )
2001-10-18 20:55:19 +04:00
log_print ( " Allocatable yes %s " ,
( ! pe_free & & pv - > pe_count ) ? " (but full) " : " " ) ;
else
log_print ( " Allocatable NO " ) ;
2002-11-18 17:01:16 +03:00
/* LV count is no longer available when displaying PV
log_print ( " Cur LV %u " , vg - > lv_count ) ;
*/
2002-12-20 02:25:55 +03:00
log_print ( " PE Size (KByte) % " PRIu32 , pv - > pe_size / 2 ) ;
2001-10-18 20:55:19 +04:00
log_print ( " Total PE %u " , pv - > pe_count ) ;
2002-12-20 02:25:55 +03:00
log_print ( " Free PE % " PRIu32 , pe_free ) ;
2002-04-24 22:20:51 +04:00
log_print ( " Allocated PE %u " , pv - > pe_alloc_count ) ;
2001-10-18 20:55:19 +04:00
log_print ( " PV UUID %s " , * uuid ? uuid : " none " ) ;
log_print ( " " ) ;
return ;
}
2006-05-10 01:23:51 +04:00
int pvdisplay_short ( struct cmd_context * cmd __attribute ( ( unused ) ) ,
struct volume_group * vg __attribute ( ( unused ) ) ,
struct physical_volume * pv ,
void * handle __attribute ( ( unused ) ) )
2001-10-18 20:55:19 +04:00
{
2002-12-03 16:26:17 +03:00
char uuid [ 64 ] ;
2001-11-13 20:53:06 +03:00
if ( ! pv )
2001-11-19 18:20:50 +03:00
return 0 ;
2001-10-18 20:55:19 +04:00
2002-12-03 16:26:17 +03:00
if ( ! id_write_format ( & pv - > id , uuid , sizeof ( uuid ) ) ) {
stack ;
return 0 ;
}
2001-10-25 18:04:18 +04:00
log_print ( " PV Name %s " , dev_name ( pv - > dev ) ) ;
2001-10-18 20:55:19 +04:00
/* FIXME pv->pv_number); */
2002-12-03 16:26:17 +03:00
log_print ( " PV UUID %s " , * uuid ? uuid : " none " ) ;
2002-01-11 02:21:07 +03:00
log_print ( " PV Status %sallocatable " ,
2002-01-10 18:09:51 +03:00
( pv - > status & ALLOCATABLE_PV ) ? " " : " NOT " ) ;
2001-10-18 20:55:19 +04:00
log_print ( " Total PE / Free PE %u / %u " ,
2002-04-24 22:20:51 +04:00
pv - > pe_count , pv - > pe_count - pv - > pe_alloc_count ) ;
2001-10-18 20:55:19 +04:00
2001-11-19 18:20:50 +03:00
log_print ( " " ) ;
return 0 ;
2001-10-18 20:55:19 +04:00
}
2001-11-08 19:15:58 +03:00
void lvdisplay_colons ( struct logical_volume * lv )
2001-10-18 20:55:19 +04:00
{
2001-11-21 22:32:35 +03:00
int inkernel ;
2003-01-09 01:44:07 +03:00
struct lvinfo info ;
2005-10-17 22:00:02 +04:00
inkernel = lv_info ( lv - > vg - > cmd , lv , & info , 1 ) & & info . exists ;
2001-11-21 22:32:35 +03:00
log_print ( " %s%s/%s:%s:%d:%d:-1:%d:% " PRIu64 " :%d:-1:%d:%d:%d:%d " ,
lv - > vg - > cmd - > dev_dir ,
2001-11-08 19:15:58 +03:00
lv - > vg - > name ,
2001-11-13 20:53:06 +03:00
lv - > name ,
lv - > vg - > name ,
2002-04-24 22:20:51 +04:00
( lv - > status & ( LVM_READ | LVM_WRITE ) ) > > 8 , inkernel ? 1 : 0 ,
2001-11-13 20:53:06 +03:00
/* FIXME lv->lv_number, */
2001-11-21 22:32:35 +03:00
inkernel ? info . open_count : 0 , lv - > size , lv - > le_count ,
2001-11-13 20:53:06 +03:00
/* FIXME Add num allocated to struct! lv->lv_allocated_le, */
2002-11-18 17:01:16 +03:00
( lv - > alloc = = ALLOC_CONTIGUOUS ? 2 : 0 ) , lv - > read_ahead ,
2002-04-24 22:20:51 +04:00
inkernel ? info . major : - 1 , inkernel ? info . minor : - 1 ) ;
2001-10-18 20:55:19 +04:00
return ;
}
2002-11-18 17:01:16 +03:00
int lvdisplay_full ( struct cmd_context * cmd , struct logical_volume * lv ,
2006-05-10 01:23:51 +04:00
void * handle __attribute ( ( unused ) ) )
2001-10-18 20:55:19 +04:00
{
2003-01-09 01:44:07 +03:00
struct lvinfo info ;
2005-04-07 16:39:44 +04:00
int inkernel , snap_active = 0 ;
2002-02-21 18:26:44 +03:00
char uuid [ 64 ] ;
2005-04-07 16:39:44 +04:00
struct lv_segment * snap_seg = NULL ;
2002-11-27 00:56:57 +03:00
float snap_percent ; /* fused, fsize; */
2002-02-21 18:26:44 +03:00
2002-03-05 23:03:09 +03:00
if ( ! id_write_format ( & lv - > lvid . id [ 1 ] , uuid , sizeof ( uuid ) ) ) {
2002-02-21 18:26:44 +03:00
stack ;
return 0 ;
}
2001-11-21 22:32:35 +03:00
2005-10-17 22:00:02 +04:00
inkernel = lv_info ( cmd , lv , & info , 1 ) & & info . exists ;
2001-10-18 20:55:19 +04:00
2001-11-13 20:53:06 +03:00
log_print ( " --- Logical volume --- " ) ;
2001-10-18 20:55:19 +04:00
2001-11-21 22:32:35 +03:00
log_print ( " LV Name %s%s/%s " , lv - > vg - > cmd - > dev_dir ,
lv - > vg - > name , lv - > name ) ;
2001-11-13 20:53:06 +03:00
log_print ( " VG Name %s " , lv - > vg - > name ) ;
2001-11-08 19:15:58 +03:00
2002-02-21 18:26:44 +03:00
log_print ( " LV UUID %s " , uuid ) ;
2002-11-18 17:01:16 +03:00
2001-11-13 20:53:06 +03:00
log_print ( " LV Write Access %s " ,
( lv - > status & LVM_WRITE ) ? " read/write " : " read only " ) ;
2001-10-18 20:55:19 +04:00
2002-11-18 17:01:16 +03:00
if ( lv_is_origin ( lv ) ) {
2002-05-08 21:58:52 +04:00
log_print ( " LV snapshot status source of " ) ;
2002-11-18 17:01:16 +03:00
2005-04-07 16:39:44 +04:00
list_iterate_items_gen ( snap_seg , & lv - > snapshot_segs ,
origin_list ) {
if ( inkernel & &
( snap_active = lv_snapshot_percent ( snap_seg - > cow ,
& snap_percent ) ) )
if ( snap_percent < 0 | | snap_percent > = 100 )
snap_active = 0 ;
2002-05-08 20:57:46 +04:00
log_print ( " %s%s/%s [%s] " ,
2002-11-18 17:01:16 +03:00
lv - > vg - > cmd - > dev_dir , lv - > vg - > name ,
2005-04-07 16:39:44 +04:00
snap_seg - > cow - > name ,
2002-11-18 17:01:16 +03:00
( snap_active > 0 ) ? " active " : " INACTIVE " ) ;
2002-05-08 20:57:46 +04:00
}
2005-04-07 16:39:44 +04:00
snap_seg = NULL ;
} else if ( ( snap_seg = find_cow ( lv ) ) ) {
if ( inkernel & &
( snap_active = lv_snapshot_percent ( snap_seg - > cow ,
& snap_percent ) ) )
if ( snap_percent < 0 | | snap_percent > = 100 )
snap_active = 0 ;
2002-04-30 01:43:14 +04:00
log_print ( " LV snapshot status %s destination for %s%s/%s " ,
2002-11-18 17:01:16 +03:00
( snap_active > 0 ) ? " active " : " INACTIVE " ,
2002-05-10 01:17:57 +04:00
lv - > vg - > cmd - > dev_dir , lv - > vg - > name ,
2005-04-07 16:39:44 +04:00
snap_seg - > origin - > name ) ;
2001-10-18 20:55:19 +04:00
}
2002-05-10 01:17:57 +04:00
2001-11-21 22:32:35 +03:00
if ( inkernel & & info . suspended )
log_print ( " LV Status suspended " ) ;
else
log_print ( " LV Status %savailable " ,
2002-11-18 17:01:16 +03:00
inkernel ? " " : " NOT " ) ;
2001-11-08 19:15:58 +03:00
2002-11-18 17:01:16 +03:00
/********* FIXME lv_number
2001-11-08 19:15:58 +03:00
log_print ( " LV # %u " , lv - > lv_number + 1 ) ;
* * * * * * * * * * * */
2001-11-21 22:32:35 +03:00
if ( inkernel )
log_print ( " # open %u " , info . open_count ) ;
2001-11-08 19:15:58 +03:00
2002-12-12 23:55:49 +03:00
log_print ( " LV Size %s " ,
display_size ( cmd ,
2006-05-10 01:23:51 +04:00
snap_seg ? snap_seg - > origin - > size : lv - > size ) ) ;
2001-10-18 20:55:19 +04:00
2002-11-18 17:01:16 +03:00
log_print ( " Current LE %u " ,
2005-04-07 16:39:44 +04:00
snap_seg ? snap_seg - > origin - > le_count : lv - > le_count ) ;
2001-11-28 16:45:50 +03:00
2005-04-07 16:39:44 +04:00
if ( snap_seg ) {
log_print ( " COW-table size %s " ,
2006-05-10 01:23:51 +04:00
display_size ( cmd , ( uint64_t ) lv - > size ) ) ;
2005-04-07 16:39:44 +04:00
log_print ( " COW-table LE %u " , lv - > le_count ) ;
2001-10-18 20:55:19 +04:00
2005-04-07 16:39:44 +04:00
if ( snap_active )
log_print ( " Allocated to snapshot %.2f%% " , snap_percent ) ;
2002-11-18 17:01:16 +03:00
2002-12-12 23:55:49 +03:00
log_print ( " Snapshot chunk size %s " ,
2006-05-10 01:23:51 +04:00
display_size ( cmd , ( uint64_t ) snap_seg - > chunk_size ) ) ;
2002-11-27 00:56:57 +03:00
}
2002-11-18 17:01:16 +03:00
2005-04-07 16:39:44 +04:00
log_print ( " Segments %u " , list_size ( & lv - > segments ) ) ;
/********* FIXME Stripes & stripesize for each segment
log_print ( " Stripe size (KByte) %u " , lv - > stripesize / 2 ) ;
* * * * * * * * * * */
2001-10-18 20:55:19 +04:00
2002-07-11 18:21:49 +04:00
log_print ( " Allocation %s " , get_alloc_string ( lv - > alloc ) ) ;
2001-11-21 22:32:35 +03:00
log_print ( " Read ahead sectors %u " , lv - > read_ahead ) ;
2001-10-18 20:55:19 +04:00
2003-04-02 23:14:43 +04:00
if ( lv - > status & FIXED_MINOR ) {
if ( lv - > major > = 0 )
log_print ( " Persistent major %d " , lv - > major ) ;
2002-02-01 20:54:39 +03:00
log_print ( " Persistent minor %d " , lv - > minor ) ;
2003-04-02 23:14:43 +04:00
}
2002-02-01 20:54:39 +03:00
2001-11-21 22:32:35 +03:00
if ( inkernel )
2002-04-24 22:20:51 +04:00
log_print ( " Block device %d:%d " , info . major ,
2001-11-21 22:32:35 +03:00
info . minor ) ;
log_print ( " " ) ;
2001-11-08 19:15:58 +03:00
2001-11-19 18:20:50 +03:00
return 0 ;
2001-11-08 19:15:58 +03:00
}
2001-10-18 20:55:19 +04:00
2004-05-05 01:25:57 +04:00
void display_stripe ( const struct lv_segment * seg , uint32_t s , const char * pre )
2001-11-13 20:53:06 +03:00
{
2005-06-01 20:51:55 +04:00
switch ( seg_type ( seg , s ) ) {
2003-04-25 02:23:24 +04:00
case AREA_PV :
2005-05-03 21:28:23 +04:00
/* FIXME Re-check the conditions for 'Missing' */
2003-04-25 02:23:24 +04:00
log_print ( " %sPhysical volume \t %s " , pre ,
2005-06-01 20:51:55 +04:00
seg_pv ( seg , s ) ?
dev_name ( seg_dev ( seg , s ) ) :
2005-05-03 21:28:23 +04:00
" Missing " ) ;
2003-04-25 02:23:24 +04:00
2005-06-01 20:51:55 +04:00
if ( seg_pv ( seg , s ) )
2003-04-25 02:23:24 +04:00
log_print ( " %sPhysical extents \t %d to %d " , pre ,
2005-06-01 20:51:55 +04:00
seg_pe ( seg , s ) ,
seg_pe ( seg , s ) + seg - > area_len - 1 ) ;
2003-04-25 02:23:24 +04:00
break ;
case AREA_LV :
log_print ( " %sLogical volume \t %s " , pre ,
2005-06-01 20:51:55 +04:00
seg_lv ( seg , s ) ?
seg_lv ( seg , s ) - > name : " Missing " ) ;
2001-11-13 20:53:06 +03:00
2005-06-01 20:51:55 +04:00
if ( seg_lv ( seg , s ) )
2003-04-25 02:23:24 +04:00
log_print ( " %sLogical extents \t %d to %d " , pre ,
2005-06-01 20:51:55 +04:00
seg_le ( seg , s ) ,
seg_le ( seg , s ) + seg - > area_len - 1 ) ;
2005-06-14 21:54:48 +04:00
break ;
case AREA_UNASSIGNED :
log_print ( " %sUnassigned area " , pre ) ;
2003-04-25 02:23:24 +04:00
}
2002-01-21 15:05:39 +03:00
}
2001-11-13 20:53:06 +03:00
2002-01-21 15:05:39 +03:00
int lvdisplay_segments ( struct logical_volume * lv )
{
2002-11-18 17:01:16 +03:00
struct lv_segment * seg ;
2001-11-13 20:53:06 +03:00
2002-01-21 15:05:39 +03:00
log_print ( " --- Segments --- " ) ;
2001-11-13 20:53:06 +03:00
2004-05-05 01:25:57 +04:00
list_iterate_items ( seg , & lv - > segments ) {
2002-11-27 00:56:57 +03:00
log_print ( " Logical extent %u to %u: " ,
2002-01-21 15:05:39 +03:00
seg - > le , seg - > le + seg - > len - 1 ) ;
2001-11-13 20:53:06 +03:00
2004-05-05 01:25:57 +04:00
log_print ( " Type \t \t %s " , seg - > segtype - > ops - > name ( seg ) ) ;
if ( seg - > segtype - > ops - > display )
seg - > segtype - > ops - > display ( seg ) ;
2001-11-13 20:53:06 +03:00
}
2001-12-03 23:23:53 +03:00
log_print ( " " ) ;
2002-01-21 15:05:39 +03:00
return 1 ;
2001-11-19 18:20:50 +03:00
}
2006-05-10 01:23:51 +04:00
void vgdisplay_extents ( struct volume_group * vg __attribute ( ( unused ) ) )
2001-11-19 18:20:50 +03:00
{
return ;
}
void vgdisplay_full ( struct volume_group * vg )
{
uint32_t access ;
2002-11-18 17:01:16 +03:00
uint32_t active_pvs ;
2002-01-21 14:29:06 +03:00
char uuid [ 64 ] ;
2002-04-30 01:43:14 +04:00
2002-11-18 17:01:16 +03:00
if ( vg - > status & PARTIAL_VG )
active_pvs = list_size ( & vg - > pvs ) ;
2002-04-30 01:43:14 +04:00
else
2002-11-18 17:01:16 +03:00
active_pvs = vg - > pv_count ;
2001-11-19 18:20:50 +03:00
log_print ( " --- Volume group --- " ) ;
log_print ( " VG Name %s " , vg - > name ) ;
2002-01-29 19:30:18 +03:00
log_print ( " System ID %s " , vg - > system_id ) ;
2002-11-18 17:01:16 +03:00
log_print ( " Format %s " , vg - > fid - > fmt - > name ) ;
if ( vg - > fid - > fmt - > features & FMT_MDAS ) {
log_print ( " Metadata Areas %d " ,
list_size ( & vg - > fid - > metadata_areas ) ) ;
log_print ( " Metadata Sequence No %d " , vg - > seqno ) ;
}
2001-11-19 18:20:50 +03:00
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 " : " " ) ;
2002-01-29 19:30:18 +03:00
log_print ( " VG Status %s%sresizable " ,
2002-11-18 17:01:16 +03:00
vg - > status & EXPORTED_VG ? " exported/ " : " " ,
2002-01-10 18:09:51 +03:00
vg - > status & RESIZEABLE_VG ? " " : " NOT " ) ;
2002-11-18 17:01:16 +03:00
/* vg number not part of LVM2 design
log_print ( " VG # %u \n " , vg - > vg_number ) ;
*/
2001-11-19 18:20:50 +03:00
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 ) ;
2005-04-07 16:39:44 +04:00
log_print ( " Cur LV %u " , vg - > lv_count + vg - > snapshot_count ) ;
2002-11-18 17:01:16 +03:00
log_print ( " Open LV %u " , lvs_in_vg_opened ( vg ) ) ;
/****** FIXME Max LV Size
log_print ( " MAX LV Size %s " ,
2006-05-10 01:23:51 +04:00
( s1 = display_size ( LVM_LV_SIZE_MAX ( vg ) ) ) ) ;
2002-11-18 17:01:16 +03:00
free ( s1 ) ;
* * * * * * * * */
2001-11-19 18:20:50 +03:00
log_print ( " Max PV %u " , vg - > max_pv ) ;
log_print ( " Cur PV %u " , vg - > pv_count ) ;
2002-11-18 17:01:16 +03:00
log_print ( " Act PV %u " , active_pvs ) ;
2001-11-19 18:20:50 +03:00
2002-12-12 23:55:49 +03:00
log_print ( " VG Size %s " ,
display_size ( vg - > cmd ,
2006-05-10 01:23:51 +04:00
( uint64_t ) vg - > extent_count * vg - > extent_size ) ) ;
2001-11-19 18:20:50 +03:00
2002-12-12 23:55:49 +03:00
log_print ( " PE Size %s " ,
2006-05-10 01:23:51 +04:00
display_size ( vg - > cmd , ( uint64_t ) vg - > extent_size ) ) ;
2001-11-19 18:20:50 +03:00
log_print ( " Total PE %u " , vg - > extent_count ) ;
log_print ( " Alloc PE / Size %u / %s " ,
2004-06-07 19:22:43 +04:00
vg - > extent_count - vg - > free_count ,
display_size ( vg - > cmd ,
( ( uint64_t ) vg - > extent_count - vg - > free_count ) *
2006-05-10 01:23:51 +04:00
vg - > extent_size ) ) ;
2002-12-12 23:55:49 +03:00
log_print ( " Free PE / Size %u / %s " , vg - > free_count ,
display_size ( vg - > cmd ,
2006-05-10 01:23:51 +04:00
( uint64_t ) vg - > free_count * vg - > extent_size ) ) ;
2001-11-19 18:20:50 +03:00
2002-01-21 14:29:06 +03:00
if ( ! id_write_format ( & vg - > id , uuid , sizeof ( uuid ) ) ) {
stack ;
return ;
}
2001-11-19 18:20:50 +03:00
2002-01-21 14:29:06 +03:00
log_print ( " VG UUID %s " , uuid ) ;
2001-11-19 18:20:50 +03:00
log_print ( " " ) ;
return ;
}
void vgdisplay_colons ( struct volume_group * vg )
{
2004-03-30 18:35:40 +04:00
uint32_t active_pvs ;
const char * access ;
char uuid [ 64 ] ;
if ( vg - > status & PARTIAL_VG )
active_pvs = list_size ( & vg - > pvs ) ;
else
active_pvs = vg - > pv_count ;
switch ( vg - > status & ( LVM_READ | LVM_WRITE ) ) {
case LVM_READ | LVM_WRITE :
access = " r/w " ;
break ;
case LVM_READ :
access = " r " ;
break ;
case LVM_WRITE :
access = " w " ;
break ;
default :
access = " " ;
}
if ( ! id_write_format ( & vg - > id , uuid , sizeof ( uuid ) ) ) {
stack ;
return ;
}
log_print ( " %s:%s:%d:-1:%u:%u:%u:-1:%u:%u:%u:% " PRIu64 " :% " PRIu32
" :%u:%u:%u:%s " ,
vg - > name ,
access ,
vg - > status ,
/* internal volume group number; obsolete */
vg - > max_lv ,
vg - > lv_count ,
lvs_in_vg_opened ( vg ) ,
/* FIXME: maximum logical volume size */
vg - > max_pv ,
vg - > pv_count ,
active_pvs ,
( uint64_t ) vg - > extent_count * ( vg - > extent_size / 2 ) ,
vg - > extent_size / 2 ,
vg - > extent_count ,
vg - > extent_count - vg - > free_count ,
vg - > free_count ,
uuid [ 0 ] ? uuid : " none " ) ;
2001-11-19 18:20:50 +03:00
return ;
}
void vgdisplay_short ( struct volume_group * vg )
{
2002-01-30 18:04:48 +03:00
log_print ( " \" %s \" %-9s [%-9s used / %s free] " , vg - > name ,
2001-11-19 18:20:50 +03:00
/********* FIXME if "open" print "/used" else print "/idle"??? ******/
2004-06-07 19:22:43 +04:00
display_size ( vg - > cmd ,
2006-05-10 01:23:51 +04:00
( uint64_t ) vg - > extent_count * vg - > extent_size ) ,
2002-12-20 02:25:55 +03:00
display_size ( vg - > cmd ,
( ( uint64_t ) vg - > extent_count -
2006-05-10 01:23:51 +04:00
vg - > free_count ) * vg - > extent_size ) ,
2004-06-07 19:22:43 +04:00
display_size ( vg - > cmd ,
2006-05-10 01:23:51 +04:00
( uint64_t ) vg - > free_count * vg - > extent_size ) ) ;
2001-11-13 20:53:06 +03:00
return ;
}
2004-09-14 20:42:46 +04:00
void display_formats ( struct cmd_context * cmd )
{
struct format_type * fmt ;
list_iterate_items ( fmt , & cmd - > formats ) {
log_print ( " %s " , fmt - > name ) ;
}
}
void display_segtypes ( struct cmd_context * cmd )
{
struct segment_type * segtype ;
list_iterate_items ( segtype , & cmd - > segtypes ) {
log_print ( " %s " , segtype - > name ) ;
}
}