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 .
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2007 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
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2001-09-25 16:49:28 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser 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-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"
2012-01-20 20:59:58 +04:00
# include "defaults.h"
2013-10-25 12:38:09 +04:00
# include <math.h> /* fabs() */
# include <float.h> /* DBL_EPSILON */
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 ;
2008-08-07 18:01:17 +04:00
static const struct {
2002-11-18 17:01:16 +03:00
alloc_policy_t alloc ;
2010-11-09 15:34:40 +03:00
const char str [ 14 ] ; /* must be changed when size extends 13 chars */
2010-10-25 17:54:29 +04:00
const char repchar ;
2002-11-18 17:01:16 +03:00
} _policies [ ] = {
{
2010-10-25 17:54:29 +04:00
ALLOC_CONTIGUOUS , " contiguous " , ' c ' } , {
ALLOC_CLING , " cling " , ' l ' } , {
2010-11-09 15:34:40 +03:00
ALLOC_CLING_BY_TAGS , " cling_by_tags " , ' t ' } , { /* Only used in log mesgs */
2010-10-25 17:54:29 +04:00
ALLOC_NORMAL , " normal " , ' n ' } , {
ALLOC_ANYWHERE , " anywhere " , ' a ' } , {
ALLOC_INHERIT , " inherit " , ' i ' }
2002-11-18 17:01:16 +03:00
} ;
2008-08-07 18:01:17 +04:00
static const int _num_policies = sizeof ( _policies ) / sizeof ( * _policies ) ;
2002-11-18 17:01:16 +03:00
2013-10-25 12:38:09 +04:00
/* Test if the doubles are close enough to be considered equal */
static int _close_enough ( double d1 , double d2 )
{
return fabs ( d1 - d2 ) < DBL_EPSILON ;
}
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 ;
2011-02-19 02:09:55 +03:00
double custom_value = 0 ;
uint64_t multiplier ;
2002-12-12 23:55:49 +03:00
if ( isdigit ( * units ) ) {
2011-02-19 02:09:55 +03:00
custom_value = strtod ( units , & ptr ) ;
2002-12-12 23:55:49 +03:00
if ( ptr = = units )
return 0 ;
2011-02-19 02:09:55 +03:00
v = ( uint64_t ) strtoull ( units , NULL , 10 ) ;
2013-10-25 12:38:09 +04:00
if ( _close_enough ( ( double ) v , custom_value ) )
2011-02-19 02:09:55 +03:00
custom_value = 0 ; /* Use integer arithmetic */
2002-12-20 02:25:55 +03:00
units = ptr ;
2002-12-12 23:55:49 +03:00
} else
v = 1 ;
2011-02-19 02:09:55 +03:00
/* Only one units char permitted. */
2012-02-13 18:23:40 +04:00
if ( units [ 0 ] & & units [ 1 ] )
2011-02-19 02:09:55 +03:00
return 0 ;
2002-12-12 23:55:49 +03:00
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 ' :
2011-02-19 02:09:55 +03:00
multiplier = 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 ' b ' :
case ' B ' :
2011-02-19 02:09:55 +03:00
multiplier = 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)
2009-07-07 23:28:57 +04:00
case ' s ' :
2009-09-28 20:36:03 +04:00
case ' S ' :
2011-02-19 02:09:55 +03:00
multiplier = ( KILO / 2 ) ;
2009-07-07 23:28:57 +04:00
break ;
2002-12-12 23:55:49 +03:00
case ' k ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO ;
2003-07-05 02:34:56 +04:00
break ;
2002-12-12 23:55:49 +03:00
case ' m ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' g ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' t ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO * KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
2006-11-10 21:24:11 +03:00
case ' p ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO * KILO * KILO * KILO ;
2006-11-10 21:24:11 +03:00
break ;
case ' e ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO * KILO * KILO * KILO * KILO ;
2006-11-10 21:24:11 +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 ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' M ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' G ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
case ' T ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO * KILO * KILO ;
2002-12-12 23:55:49 +03:00
break ;
2006-11-10 21:24:11 +03:00
case ' P ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO * KILO * KILO * KILO ;
2006-11-10 21:24:11 +03:00
break ;
case ' E ' :
2011-02-19 02:09:55 +03:00
multiplier = KILO * KILO * KILO * KILO * KILO * KILO ;
2006-11-10 21:24:11 +03:00
break ;
2002-12-20 02:25:55 +03:00
# undef KILO
2002-12-12 23:55:49 +03:00
default :
return 0 ;
}
2013-10-25 12:38:09 +04:00
if ( _close_enough ( custom_value , 0. ) )
return v * multiplier ; /* Use integer arithmetic */
2011-02-19 02:09:55 +03:00
else
2013-10-25 12:38:09 +04:00
return ( uint64_t ) ( custom_value * multiplier ) ;
2002-12-12 23:55:49 +03:00
}
2011-03-01 23:17:56 +03:00
char alloc_policy_char ( alloc_policy_t alloc )
2010-10-25 17:54:29 +04:00
{
int i ;
for ( i = 0 ; i < _num_policies ; i + + )
if ( _policies [ i ] . alloc = = alloc )
return _policies [ i ] . repchar ;
return ' - ' ;
}
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 ;
2010-11-09 15:34:40 +03:00
/* cling_by_tags is part of cling */
if ( ! strcmp ( " cling_by_tags " , str ) )
return ALLOC_CLING ;
2002-11-18 17:01:16 +03:00
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 */
2010-11-09 15:34:40 +03:00
if ( ! strcmp ( " next free " , str ) )
2004-05-19 02:12:53 +04:00
return ALLOC_NORMAL ;
log_error ( " Unrecognised allocation policy %s " , str ) ;
return ALLOC_INVALID ;
2002-11-18 17:01:16 +03:00
}
2009-09-30 18:19:00 +04:00
# define BASE_UNKNOWN 0
# define BASE_SHARED 1
2013-07-18 20:55:58 +04:00
# define BASE_1024 8
# define BASE_1000 15
# define BASE_SPECIAL 21
2009-09-30 18:19:00 +04:00
# define NUM_UNIT_PREFIXES 6
# define NUM_SPECIAL 3
2004-06-07 19:22:43 +04:00
/* Size supplied in sectors */
2007-08-07 13:06:05 +04:00
static const char * _display_size ( const struct cmd_context * cmd ,
uint64_t size , size_len_t sl )
2001-09-25 16:49:28 +04:00
{
2009-09-30 18:19:00 +04:00
unsigned base = BASE_UNKNOWN ;
unsigned 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 ;
2008-08-07 18:01:17 +04:00
const char * const size_str [ ] [ 3 ] = {
2009-09-30 18:19:00 +04:00
/* BASE_UNKNOWN */
{ " " , " " , " " } , /* [0] */
/* BASE_SHARED - Used if cmd->si_unit_consistency = 0 */
{ " Exabyte " , " EB " , " E " } , /* [1] */
{ " Petabyte " , " PB " , " P " } , /* [2] */
{ " Terabyte " , " TB " , " T " } , /* [3] */
{ " Gigabyte " , " GB " , " G " } , /* [4] */
{ " Megabyte " , " MB " , " M " } , /* [5] */
{ " Kilobyte " , " KB " , " K " } , /* [6] */
2013-07-18 20:55:58 +04:00
{ " Byte " , " B " , " B " } , /* [7] */
2009-09-30 18:19:00 +04:00
/* BASE_1024 - Used if cmd->si_unit_consistency = 1 */
2013-07-18 20:55:58 +04:00
{ " Exbibyte " , " EiB " , " e " } , /* [8] */
{ " Pebibyte " , " PiB " , " p " } , /* [9] */
{ " Tebibyte " , " TiB " , " t " } , /* [10] */
{ " Gibibyte " , " GiB " , " g " } , /* [11] */
{ " Mebibyte " , " MiB " , " m " } , /* [12] */
{ " Kibibyte " , " KiB " , " k " } , /* [13] */
{ " Byte " , " B " , " b " } , /* [14] */
2009-09-30 18:19:00 +04:00
/* BASE_1000 - Used if cmd->si_unit_consistency = 1 */
2013-07-18 20:55:58 +04:00
{ " Exabyte " , " EB " , " E " } , /* [15] */
{ " Petabyte " , " PB " , " P " } , /* [16] */
{ " Terabyte " , " TB " , " T " } , /* [17] */
{ " Gigabyte " , " GB " , " G " } , /* [18] */
{ " Megabyte " , " MB " , " M " } , /* [19] */
{ " Kilobyte " , " kB " , " K " } , /* [20] */
2009-09-30 18:19:00 +04:00
/* BASE_SPECIAL */
2013-07-18 20:55:58 +04:00
{ " Byte " , " B " , " B " } , /* [21] (shared with BASE_1000) */
{ " Units " , " Un " , " U " } , /* [22] */
{ " Sectors " , " Se " , " S " } , /* [23] */
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 ;
2009-09-30 18:19:00 +04:00
if ( ! cmd - > si_unit_consistency ) {
/* Case-independent match */
for ( s = 0 ; s < NUM_UNIT_PREFIXES ; s + + )
if ( toupper ( ( int ) cmd - > current_settings . unit_type ) = =
* size_str [ BASE_SHARED + s ] [ 2 ] ) {
base = BASE_SHARED ;
break ;
}
} else {
/* Case-dependent match for powers of 1000 */
for ( s = 0 ; s < NUM_UNIT_PREFIXES ; s + + )
if ( cmd - > current_settings . unit_type = =
* size_str [ BASE_1000 + s ] [ 2 ] ) {
base = BASE_1000 ;
break ;
}
/* Case-dependent match for powers of 1024 */
if ( base = = BASE_UNKNOWN )
for ( s = 0 ; s < NUM_UNIT_PREFIXES ; s + + )
if ( cmd - > current_settings . unit_type = =
* size_str [ BASE_1024 + s ] [ 2 ] ) {
base = BASE_1024 ;
break ;
}
}
if ( base = = BASE_UNKNOWN )
/* Check for special units - s, b or u */
for ( s = 0 ; s < NUM_SPECIAL ; s + + )
if ( toupper ( ( int ) cmd - > current_settings . unit_type ) = =
* size_str [ BASE_SPECIAL + s ] [ 2 ] ) {
base = BASE_SPECIAL ;
break ;
}
2002-12-12 23:55:49 +03:00
2003-03-24 21:08:53 +03:00
if ( size = = UINT64_C ( 0 ) ) {
2009-09-30 18:19:00 +04:00
if ( base = = BASE_UNKNOWN )
s = 0 ;
sprintf ( size_buf , " 0%s " , suffix ? size_str [ base + s ] [ sl ] : " " ) ;
2002-12-12 23:55:49 +03:00
return size_buf ;
2001-09-25 16:49:28 +04:00
}
2007-11-05 20:13:54 +03:00
size * = UINT64_C ( 512 ) ;
2009-09-30 18:19:00 +04:00
if ( base ! = BASE_UNKNOWN )
2002-12-12 23:55:49 +03:00
byte = cmd - > current_settings . unit_factor ;
2007-11-05 20:13:54 +03:00
else {
2009-09-30 18:19:00 +04:00
/* Human-readable style */
if ( cmd - > current_settings . unit_type = = ' H ' ) {
2003-03-24 21:08:53 +03:00
units = UINT64_C ( 1000 ) ;
2009-09-30 18:19:00 +04:00
base = BASE_1000 ;
} else {
2003-03-24 21:08:53 +03:00
units = UINT64_C ( 1024 ) ;
2009-09-30 18:19:00 +04:00
base = BASE_1024 ;
}
if ( ! cmd - > si_unit_consistency )
base = BASE_SHARED ;
2007-11-05 20:13:54 +03:00
byte = units * units * units * units * units * units ;
2009-09-30 18:19:00 +04:00
for ( s = 0 ; s < NUM_UNIT_PREFIXES & & size < byte ; s + + )
byte / = units ;
suffix = 1 ;
2001-09-25 16:49:28 +04:00
}
2004-05-28 16:47:57 +04:00
/* FIXME Make precision configurable */
2013-07-18 20:55:58 +04:00
switch ( toupper ( * size_str [ base + s ] [ SIZE_UNIT ] ) ) {
2004-05-28 16:47:57 +04:00
case ' B ' :
case ' S ' :
precision = 0 ;
break ;
default :
precision = 2 ;
}
snprintf ( size_buf , SIZE_BUF - 1 , " %.*f%s " , precision ,
2009-09-30 18:19:00 +04:00
( double ) size / byte , suffix ? size_str [ base + s ] [ sl ] : " " ) ;
2002-12-12 23:55:49 +03:00
2001-09-25 16:49:28 +04:00
return size_buf ;
}
2007-08-07 13:06:05 +04:00
const char * display_size_long ( const struct cmd_context * cmd , uint64_t size )
2006-05-10 01:23:51 +04:00
{
return _display_size ( cmd , size , SIZE_LONG ) ;
}
2007-08-07 13:06:05 +04:00
const char * display_size_units ( const struct cmd_context * cmd , uint64_t size )
2006-05-10 01:23:51 +04:00
{
return _display_size ( cmd , size , SIZE_UNIT ) ;
}
2007-08-07 13:06:05 +04:00
const char * display_size ( const struct cmd_context * cmd , uint64_t size )
2006-05-10 01:23:51 +04:00
{
return _display_size ( cmd , size , SIZE_SHORT ) ;
}
2007-08-07 13:06:05 +04:00
void pvdisplay_colons ( const struct physical_volume * pv )
2001-10-18 20:55:19 +04:00
{
2010-07-09 19:34:40 +04:00
char uuid [ 64 ] __attribute__ ( ( aligned ( 8 ) ) ) ;
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
2009-11-25 01:55:55 +03:00
log_print ( " %s:%s:% " PRIu64 " :-1:% " PRIu64 " :% " PRIu64 " :-1:% " PRIu32 " :%u:%u:%u:%s " ,
2007-10-12 18:29:32 +04:00
pv_dev_name ( pv ) , pv - > vg_name , pv - > size ,
2001-11-13 20:53:06 +03:00
/* 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
}
2007-08-07 13:06:05 +04:00
void pvdisplay_segments ( const struct physical_volume * pv )
2007-05-31 00:43:09 +04:00
{
2007-08-07 13:06:05 +04:00
const struct pv_segment * pvseg ;
2007-05-31 00:43:09 +04:00
2007-06-01 00:26:11 +04:00
if ( pv - > pe_size )
log_print ( " --- Physical Segments --- " ) ;
2007-05-31 00:43:09 +04:00
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( pvseg , & pv - > segments ) {
2007-05-31 00:43:09 +04:00
log_print ( " Physical extent %u to %u: " ,
2007-05-31 18:19:57 +04:00
pvseg - > pe , pvseg - > pe + pvseg - > len - 1 ) ;
2007-05-31 00:43:09 +04:00
2008-03-26 19:48:10 +03:00
if ( pvseg_is_allocated ( pvseg ) ) {
2007-05-31 00:43:09 +04:00
log_print ( " Logical volume \t %s%s/%s " ,
2007-05-31 18:19:57 +04:00
pvseg - > lvseg - > lv - > vg - > cmd - > dev_dir ,
pvseg - > lvseg - > lv - > vg - > name ,
pvseg - > lvseg - > lv - > name ) ;
2007-05-31 00:43:09 +04:00
log_print ( " Logical extents \t %d to %d " ,
2007-05-31 18:19:57 +04:00
pvseg - > lvseg - > le , pvseg - > lvseg - > le +
pvseg - > lvseg - > len - 1 ) ;
2007-05-31 00:43:09 +04:00
} else
log_print ( " FREE " ) ;
}
log_print ( " " ) ;
}
2002-11-18 17:01:16 +03:00
/* FIXME Include label fields */
2007-08-07 13:06:05 +04:00
void pvdisplay_full ( const struct cmd_context * cmd ,
const struct physical_volume * pv ,
2010-07-09 19:34:40 +04:00
void * handle __attribute__ ( ( unused ) ) )
2001-10-18 20:55:19 +04:00
{
2010-07-09 19:34:40 +04:00
char uuid [ 64 ] __attribute__ ( ( aligned ( 8 ) ) ) ;
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 ;
2007-11-05 05:10:39 +03:00
uint64_t data_size , pvsize , unusable ;
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 " ) ;
2007-10-12 18:29:32 +04:00
log_print ( " PV Name %s " , pv_dev_name ( pv ) ) ;
2008-02-06 18:47:28 +03:00
log_print ( " VG Name %s%s " ,
is_orphan ( pv ) ? " " : pv - > vg_name ,
2002-01-29 19:30:18 +03:00
pv - > status & EXPORTED_VG ? " (exported) " : " " ) ;
2001-10-18 20:55:19 +04:00
2007-11-05 05:10:39 +03:00
data_size = ( uint64_t ) pv - > pe_count * pv - > pe_size ;
if ( pv - > size > data_size + pv - > pe_start ) {
2007-11-05 04:47:49 +03:00
pvsize = pv - > size ;
2007-11-05 05:10:39 +03:00
unusable = pvsize - data_size ;
2007-11-05 04:47:49 +03:00
} else {
2007-11-05 05:10:39 +03:00
pvsize = data_size + pv - > pe_start ;
unusable = pvsize - pv - > size ;
2007-11-05 04:47:49 +03:00
}
2001-10-18 20:55:19 +04:00
2007-11-05 04:47:49 +03:00
size = display_size ( cmd , pvsize ) ;
2007-11-05 05:10:39 +03:00
if ( data_size )
2007-11-05 04:47:49 +03:00
log_print ( " PV Size %s / not usable %s " , /* [LVM: %s]", */
size , display_size ( cmd , unusable ) ) ;
else
2001-10-18 20:55:19 +04:00
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 ) ;
*/
2009-09-28 20:23:44 +04:00
if ( cmd - > si_unit_consistency )
log_print ( " PE Size %s " , display_size ( cmd , ( uint64_t ) pv - > pe_size ) ) ;
else
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 ( " " ) ;
}
2010-07-09 19:34:40 +04:00
int pvdisplay_short ( const struct cmd_context * cmd __attribute__ ( ( unused ) ) ,
const struct volume_group * vg __attribute__ ( ( unused ) ) ,
2007-08-07 13:06:05 +04:00
const struct physical_volume * pv ,
2010-07-09 19:34:40 +04:00
void * handle __attribute__ ( ( unused ) ) )
2001-10-18 20:55:19 +04:00
{
2010-07-09 19:34:40 +04:00
char uuid [ 64 ] __attribute__ ( ( aligned ( 8 ) ) ) ;
2002-12-03 16:26:17 +03:00
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
2008-01-30 16:19:47 +03:00
if ( ! id_write_format ( & pv - > id , uuid , sizeof ( uuid ) ) )
return_0 ;
2002-12-03 16:26:17 +03:00
2007-10-12 18:29:32 +04:00
log_print ( " PV Name %s " , pv_dev_name ( pv ) ) ;
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
}
2007-08-07 13:06:05 +04:00
void lvdisplay_colons ( const 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 ;
2010-08-17 20:25:32 +04:00
inkernel = lv_info ( lv - > vg - > cmd , lv , 0 , & info , 1 , 0 ) & & info . exists ;
2001-11-21 22:32:35 +03:00
2009-11-25 01:55:55 +03:00
log_print ( " %s%s/%s:%s:% " PRIu64 " :%d:-1:%d:% " PRIu64 " :%d:-1:%d:%d:%d:%d " ,
2001-11-21 22:32:35 +03:00
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 ,
2012-01-12 20:58:43 +04:00
( ( lv - > status & ( LVM_READ | LVM_WRITE ) ) > > 8 ) |
2012-01-25 21:14:56 +04:00
( ( inkernel & & info . read_only ) ? 4 : 0 ) , 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
}
2007-08-07 13:06:05 +04:00
int lvdisplay_full ( struct cmd_context * cmd ,
const struct logical_volume * lv ,
2010-07-09 19:34:40 +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 ;
2010-07-09 19:34:40 +04:00
char uuid [ 64 ] __attribute__ ( ( aligned ( 8 ) ) ) ;
2012-01-12 20:58:43 +04:00
const char * access_str ;
2009-10-26 13:01:56 +03:00
struct lv_segment * snap_seg = NULL , * mirror_seg = NULL ;
2012-01-20 20:59:58 +04:00
struct lv_segment * seg = NULL ;
int lvm1compat ;
2010-11-30 14:53:31 +03:00
percent_t snap_percent ;
2012-01-20 20:59:58 +04:00
int thin_data_active = 0 , thin_metadata_active = 0 ;
percent_t thin_data_percent , thin_metadata_percent ;
int thin_active = 0 ;
percent_t thin_percent ;
2002-02-21 18:26:44 +03:00
2008-01-30 16:19:47 +03:00
if ( ! id_write_format ( & lv - > lvid . id [ 1 ] , uuid , sizeof ( uuid ) ) )
return_0 ;
2001-11-21 22:32:35 +03:00
2010-08-17 20:25:32 +04:00
inkernel = lv_info ( cmd , lv , 0 , & info , 1 , 1 ) & & info . exists ;
2001-10-18 20:55:19 +04:00
2012-01-12 20:58:43 +04:00
if ( ( lv - > status & LVM_WRITE ) & & inkernel & & info . read_only )
access_str = " read/write (activated read only) " ;
else if ( lv - > status & LVM_WRITE )
access_str = " read/write " ;
else
access_str = " read only " ;
2001-11-13 20:53:06 +03:00
log_print ( " --- Logical volume --- " ) ;
2001-10-18 20:55:19 +04:00
2013-06-25 14:31:53 +04:00
lvm1compat = find_config_tree_bool ( cmd , global_lvdisplay_shows_full_device_path_CFG , NULL ) ;
2012-01-20 20:59:58 +04:00
2012-01-26 18:02:42 +04:00
if ( lvm1compat )
/* /dev/vgname/lvname doen't actually exist for internal devices */
2012-01-20 20:59:58 +04:00
log_print ( " LV Name %s%s/%s " ,
lv - > vg - > cmd - > dev_dir , lv - > vg - > name , lv - > name ) ;
2012-01-26 18:02:42 +04:00
else if ( lv_is_visible ( lv ) ) {
2012-01-20 20:59:58 +04:00
/* Thin pool does not have /dev/vg/name link */
if ( ! lv_is_thin_pool ( lv ) )
log_print ( " LV Path %s%s/%s " ,
lv - > vg - > cmd - > dev_dir ,
lv - > vg - > name , lv - > name ) ;
log_print ( " LV Name %s " , lv - > name ) ;
} else
2012-01-26 18:02:42 +04:00
log_print ( " Internal LV Name %s " , lv - > name ) ;
2001-11-08 19:15:58 +03:00
2012-01-20 20:59:58 +04:00
log_print ( " VG Name %s " , lv - > vg - > name ) ;
2002-02-21 18:26:44 +03:00
log_print ( " LV UUID %s " , uuid ) ;
2012-01-12 20:58:43 +04:00
log_print ( " LV Write Access %s " , access_str ) ;
2012-01-20 20:59:58 +04:00
log_print ( " LV Creation host, time %s, %s " ,
lv_host_dup ( cmd - > mem , lv ) , lv_time_dup ( cmd - > mem , lv ) ) ;
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
2008-11-04 01:14:30 +03:00
dm_list_iterate_items_gen ( snap_seg , & lv - > snapshot_segs ,
2005-04-07 16:39:44 +04:00
origin_list ) {
if ( inkernel & &
( snap_active = lv_snapshot_percent ( snap_seg - > cow ,
2010-11-30 14:53:31 +03:00
& snap_percent ) ) )
if ( snap_percent = = PERCENT_INVALID )
2005-04-07 16:39:44 +04:00
snap_active = 0 ;
2012-01-20 20:59:58 +04:00
if ( lvm1compat )
log_print ( " %s%s/%s [%s] " ,
lv - > vg - > cmd - > dev_dir , lv - > vg - > name ,
snap_seg - > cow - > name ,
snap_active ? " active " : " INACTIVE " ) ;
else
log_print ( " %s [%s] " ,
snap_seg - > cow - > name ,
snap_active ? " active " : " INACTIVE " ) ;
2002-05-08 20:57:46 +04:00
}
2005-04-07 16:39:44 +04:00
snap_seg = NULL ;
2013-07-03 00:26:03 +04:00
} else if ( ( snap_seg = find_snapshot ( lv ) ) ) {
2005-04-07 16:39:44 +04:00
if ( inkernel & &
( snap_active = lv_snapshot_percent ( snap_seg - > cow ,
2010-11-30 14:53:31 +03:00
& snap_percent ) ) )
if ( snap_percent = = PERCENT_INVALID )
2005-04-07 16:39:44 +04:00
snap_active = 0 ;
2012-01-20 20:59:58 +04:00
if ( lvm1compat )
log_print ( " LV snapshot status %s destination for %s%s/%s " ,
snap_active ? " active " : " INACTIVE " ,
lv - > vg - > cmd - > dev_dir , lv - > vg - > name ,
snap_seg - > origin - > name ) ;
else
log_print ( " LV snapshot status %s destination for %s " ,
snap_active ? " active " : " INACTIVE " ,
snap_seg - > origin - > name ) ;
2001-10-18 20:55:19 +04:00
}
2002-05-10 01:17:57 +04:00
2011-09-26 17:11:02 +04:00
if ( lv_is_thin_volume ( lv ) ) {
2012-01-20 20:59:58 +04:00
seg = first_seg ( lv ) ;
log_print ( " LV Pool name %s " , seg - > pool_lv - > name ) ;
2013-11-11 13:05:45 +04:00
log_print ( " LV Thin device ID %u " , seg - > device_id ) ;
2012-01-20 20:59:58 +04:00
if ( seg - > origin )
log_print ( " LV Thin origin name %s " ,
seg - > origin - > name ) ;
2013-01-15 18:16:16 +04:00
if ( seg - > external_lv )
log_print ( " LV External origin name %s " ,
2013-04-19 23:03:38 +04:00
seg - > external_lv - > name ) ;
2012-01-20 20:59:58 +04:00
if ( inkernel )
thin_active = lv_thin_percent ( lv , 0 , & thin_percent ) ;
2011-09-26 17:11:02 +04:00
} else if ( lv_is_thin_pool ( lv ) ) {
2012-01-20 20:59:58 +04:00
if ( inkernel ) {
thin_data_active = lv_thin_pool_percent ( lv , 0 , & thin_data_percent ) ;
thin_metadata_active = lv_thin_pool_percent ( lv , 1 , & thin_metadata_percent ) ;
}
2011-10-03 22:31:03 +04:00
/* FIXME: display thin_pool targets transid for activated LV as well */
2012-01-20 20:59:58 +04:00
seg = first_seg ( lv ) ;
log_print ( " LV Pool transaction ID % " PRIu64 , seg - > transaction_id ) ;
log_print ( " LV Pool metadata %s " , seg - > metadata_lv - > name ) ;
log_print ( " LV Pool data %s " , seg_lv ( seg , 0 ) - > name ) ;
log_print ( " LV Pool chunk size %s " ,
2012-01-24 04:55:03 +04:00
display_size ( cmd , seg - > chunk_size ) ) ;
2011-10-04 16:39:59 +04:00
log_print ( " LV Zero new blocks %s " ,
2012-01-20 20:59:58 +04:00
seg - > zero_new_blocks ? " yes " : " no " ) ;
2011-09-26 17:11:02 +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
2012-01-20 20:59:58 +04:00
if ( thin_data_active )
log_print ( " Allocated pool data %.2f%% " ,
percent_to_float ( thin_data_percent ) ) ;
if ( thin_metadata_active )
log_print ( " Allocated metadata %.2f%% " ,
percent_to_float ( thin_metadata_percent ) ) ;
if ( thin_active )
log_print ( " Mapped size %.2f%% " ,
percent_to_float ( thin_percent ) ) ;
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 )
2012-01-20 20:59:58 +04:00
log_print ( " Allocated to snapshot %.2f%% " ,
2010-11-30 14:53:31 +03:00
percent_to_float ( 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
2009-10-26 13:01:56 +03:00
if ( lv - > status & MIRRORED ) {
2012-01-20 20:59:58 +04:00
mirror_seg = first_seg ( lv ) ;
2009-10-26 13:01:56 +03:00
log_print ( " Mirrored volumes % " PRIu32 , mirror_seg - > area_count ) ;
if ( lv - > status & CONVERTING )
log_print ( " LV type Mirror undergoing conversion " ) ;
}
2008-11-04 01:14:30 +03:00
log_print ( " Segments %u " , dm_list_size ( & lv - > segments ) ) ;
2005-04-07 16:39:44 +04:00
/********* FIXME Stripes & stripesize for each segment
2009-09-28 20:23:44 +04:00
log_print ( " Stripe size %s " , display_size ( cmd , ( uint64_t ) lv - > stripesize ) ) ;
2005-04-07 16:39:44 +04:00
* * * * * * * * * * */
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 ) ) ;
2007-11-12 23:51:54 +03:00
if ( lv - > read_ahead = = DM_READ_AHEAD_AUTO )
log_print ( " Read ahead sectors auto " ) ;
else if ( lv - > read_ahead = = DM_READ_AHEAD_NONE )
log_print ( " Read ahead sectors 0 " ) ;
else
log_print ( " Read ahead sectors %u " , lv - > read_ahead ) ;
if ( inkernel & & lv - > read_ahead ! = info . read_ahead )
log_print ( " - currently set to %u " , info . 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 ) ?
2007-10-12 18:29:32 +04:00
pv_dev_name ( seg_pv ( 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
2007-08-07 13:06:05 +04:00
int lvdisplay_segments ( const struct logical_volume * lv )
2002-01-21 15:05:39 +03:00
{
2007-08-07 13:06:05 +04:00
const 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
2008-11-04 01:14:30 +03:00
dm_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
}
2010-07-09 19:34:40 +04:00
void vgdisplay_extents ( const struct volume_group * vg __attribute__ ( ( unused ) ) )
2001-11-19 18:20:50 +03:00
{
}
2007-08-07 13:06:05 +04:00
void vgdisplay_full ( const struct volume_group * vg )
2001-11-19 18:20:50 +03:00
{
2008-11-03 21:59:59 +03:00
uint32_t access_str ;
2002-11-18 17:01:16 +03:00
uint32_t active_pvs ;
2010-07-09 19:34:40 +04:00
char uuid [ 64 ] __attribute__ ( ( aligned ( 8 ) ) ) ;
2002-04-30 01:43:14 +04:00
2008-09-19 10:42:00 +04:00
active_pvs = vg - > pv_count - vg_missing_pv_count ( vg ) ;
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 " ,
2010-06-29 00:32:21 +04:00
vg_mda_count ( vg ) ) ;
2002-11-18 17:01:16 +03:00
log_print ( " Metadata Sequence No %d " , vg - > seqno ) ;
}
2008-11-03 21:59:59 +03:00
access_str = vg - > status & ( LVM_READ | LVM_WRITE ) ;
2001-11-19 18:20:50 +03:00
log_print ( " VG Access %s%s%s%s " ,
2008-11-03 21:59:59 +03:00
access_str = = ( LVM_READ | LVM_WRITE ) ? " read/write " : " " ,
access_str = = LVM_READ ? " read " : " " ,
access_str = = LVM_WRITE ? " write " : " " ,
access_str = = 0 ? " error " : " " ) ;
2002-01-29 19:30:18 +03:00
log_print ( " VG Status %s%sresizable " ,
2009-09-14 23:44:15 +04:00
vg_is_exported ( vg ) ? " exported/ " : " " ,
2009-09-15 22:35:13 +04:00
vg_is_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 ) ;
*/
2008-04-10 21:09:32 +04:00
if ( vg_is_clustered ( vg ) ) {
2001-11-19 18:20:50 +03:00
log_print ( " Clustered yes " ) ;
log_print ( " Shared %s " ,
vg - > status & SHARED ? " yes " : " no " ) ;
}
2008-04-10 21:19:02 +04:00
2001-11-19 18:20:50 +03:00
log_print ( " MAX LV %u " , vg - > max_lv ) ;
2009-05-14 01:27:43 +04:00
log_print ( " Cur LV %u " , vg_visible_lvs ( vg ) ) ;
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 ,
2009-07-27 14:18:31 +04:00
display_size ( vg - > cmd , vg_free ( vg ) ) ) ;
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 ( " " ) ;
}
2007-08-07 13:06:05 +04:00
void vgdisplay_colons ( const struct volume_group * vg )
2001-11-19 18:20:50 +03:00
{
2004-03-30 18:35:40 +04:00
uint32_t active_pvs ;
2008-11-03 21:59:59 +03:00
const char * access_str ;
2010-07-09 19:34:40 +04:00
char uuid [ 64 ] __attribute__ ( ( aligned ( 8 ) ) ) ;
2004-03-30 18:35:40 +04:00
2008-09-19 10:42:00 +04:00
active_pvs = vg - > pv_count - vg_missing_pv_count ( vg ) ;
2004-03-30 18:35:40 +04:00
switch ( vg - > status & ( LVM_READ | LVM_WRITE ) ) {
case LVM_READ | LVM_WRITE :
2008-11-03 21:59:59 +03:00
access_str = " r/w " ;
2004-03-30 18:35:40 +04:00
break ;
case LVM_READ :
2008-11-03 21:59:59 +03:00
access_str = " r " ;
2004-03-30 18:35:40 +04:00
break ;
case LVM_WRITE :
2008-11-03 21:59:59 +03:00
access_str = " w " ;
2004-03-30 18:35:40 +04:00
break ;
default :
2008-11-03 21:59:59 +03:00
access_str = " " ;
2004-03-30 18:35:40 +04:00
}
if ( ! id_write_format ( & vg - > id , uuid , sizeof ( uuid ) ) ) {
stack ;
return ;
}
2009-11-25 01:55:55 +03:00
log_print ( " %s:%s:% " PRIu64 " :-1:%u:%u:%u:-1:%u:%u:%u:% " PRIu64 " :% " PRIu32
2004-03-30 18:35:40 +04:00
" :%u:%u:%u:%s " ,
vg - > name ,
2008-11-03 21:59:59 +03:00
access_str ,
2004-03-30 18:35:40 +04:00
vg - > status ,
/* internal volume group number; obsolete */
vg - > max_lv ,
2009-05-14 01:27:43 +04:00
vg_visible_lvs ( vg ) ,
2004-03-30 18:35:40 +04:00
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 ,
2008-01-30 17:00:02 +03:00
vg - > extent_count - vg - > free_count ,
2004-03-30 18:35:40 +04:00
vg - > free_count ,
uuid [ 0 ] ? uuid : " none " ) ;
2001-11-19 18:20:50 +03:00
}
2007-08-07 13:06:05 +04:00
void vgdisplay_short ( const struct volume_group * vg )
2001-11-19 18:20:50 +03:00
{
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 ) ,
2009-07-27 14:18:31 +04:00
display_size ( vg - > cmd , vg_free ( vg ) ) ) ;
2001-11-13 20:53:06 +03:00
}
2004-09-14 20:42:46 +04:00
2007-08-07 13:06:05 +04:00
void display_formats ( const struct cmd_context * cmd )
2004-09-14 20:42:46 +04:00
{
2007-08-07 13:06:05 +04:00
const struct format_type * fmt ;
2004-09-14 20:42:46 +04:00
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( fmt , & cmd - > formats ) {
2004-09-14 20:42:46 +04:00
log_print ( " %s " , fmt - > name ) ;
}
}
2007-08-07 13:06:05 +04:00
void display_segtypes ( const struct cmd_context * cmd )
2004-09-14 20:42:46 +04:00
{
2007-08-07 13:06:05 +04:00
const struct segment_type * segtype ;
2004-09-14 20:42:46 +04:00
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( segtype , & cmd - > segtypes ) {
2004-09-14 20:42:46 +04:00
log_print ( " %s " , segtype - > name ) ;
}
}
2013-09-26 20:37:40 +04:00
void display_name_error ( name_error_t name_error )
{
if ( name_error ! = NAME_VALID ) {
switch ( name_error ) {
case NAME_INVALID_EMPTY :
log_error ( " Name is zero length " ) ;
break ;
case NAME_INVALID_HYPEN :
log_error ( " Name cannot start with hyphen " ) ;
break ;
case NAME_INVALID_DOTS :
log_error ( " Name starts with . or .. and has no "
" following character(s) " ) ;
break ;
case NAME_INVALID_CHARSET :
log_error ( " Name contains invalid character, valid set includes: "
" [a-zA-Z0-9.-_+] " ) ;
break ;
case NAME_INVALID_LENGTH :
/* Report that name length -1 to accommodate nul*/
log_error ( " Name length exceeds maximum limit of %d " , ( NAME_LEN - 1 ) ) ;
break ;
default :
log_error ( " Unknown error %d on name validation " , name_error ) ;
break ;
}
}
}
2012-08-26 03:15:45 +04:00
/*
* Prompt for y or n from stdin .
* Defaults to ' no ' in silent mode .
* All callers should support - - yes and / or - - force to override this .
*/
2007-08-20 21:04:53 +04:00
char yes_no_prompt ( const char * prompt , . . . )
{
int c = 0 , ret = 0 ;
va_list ap ;
2012-08-26 03:15:45 +04:00
if ( silent_mode ( ) )
return ' n ' ;
2007-08-20 21:04:53 +04:00
sigint_allow ( ) ;
do {
if ( c = = ' \n ' | | ! c ) {
va_start ( ap , prompt ) ;
2011-11-23 05:34:38 +04:00
vfprintf ( stderr , prompt , ap ) ;
2007-08-20 21:04:53 +04:00
va_end ( ap ) ;
2011-11-23 05:34:38 +04:00
fflush ( stderr ) ;
ret = 0 ;
2007-08-20 21:04:53 +04:00
}
if ( ( c = getchar ( ) ) = = EOF ) {
2013-07-06 13:04:19 +04:00
ret = ' n ' ; /* SIGINT */
2007-08-20 21:04:53 +04:00
break ;
}
c = tolower ( c ) ;
2011-11-23 05:34:38 +04:00
if ( ( c = = ' y ' ) | | ( c = = ' n ' ) ) {
/* If both 'y' and 'n' given, begin again. */
if ( ret & & c ! = ret )
ret = - 1 ;
else
ret = c ;
}
} while ( ret < 1 | | c ! = ' \n ' ) ;
2007-08-20 21:04:53 +04:00
sigint_restore ( ) ;
if ( c ! = ' \n ' )
config: add silent mode
Accept -q as the short form of --quiet.
Suppress non-essential standard output if -q is given twice.
Treat log/silent in lvm.conf as equivalent to -qq.
Review all log_print messages and change some to
log_print_unless_silent.
When silent, the following commands still produce output:
dumpconfig, lvdisplay, lvmdiskscan, lvs, pvck, pvdisplay,
pvs, version, vgcfgrestore -l, vgdisplay, vgs.
[Needs checking.]
Non-essential messages are shifted from log level 4 to log level 5
for syslog and lvm2_log_fn purposes.
2012-08-25 23:35:48 +04:00
fprintf ( stderr , " \n " ) ;
2007-08-20 21:04:53 +04:00
return ret ;
}