2002-12-12 23:55:49 +03:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2002 - 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 .
2002-12-12 23:55:49 +03:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2002-12-12 23:55:49 +03: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 .
2002-12-12 23:55:49 +03: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
2002-12-12 23:55:49 +03:00
*/
# include "lib.h"
# include "metadata.h"
# include "report.h"
# include "toolcontext.h"
# include "lvm-string.h"
# include "display.h"
# include "activate.h"
2004-09-16 22:40:56 +04:00
# include "segtype.h"
2006-10-03 21:55:20 +04:00
# include "str_list.h"
2007-01-16 21:06:12 +03:00
# include "lvmcache.h"
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
struct lvm_report_object {
struct volume_group * vg ;
struct logical_volume * lv ;
struct physical_volume * pv ;
struct lv_segment * seg ;
struct pv_segment * pvseg ;
} ;
/*
2002-12-12 23:55:49 +03:00
* For macro use
*/
static union {
struct physical_volume _pv ;
struct logical_volume _lv ;
struct volume_group _vg ;
struct lv_segment _seg ;
2005-04-20 00:58:25 +04:00
struct pv_segment _pvseg ;
2002-12-12 23:55:49 +03:00
} _dummy ;
2004-05-19 02:12:53 +04:00
static char _alloc_policy_char ( alloc_policy_t alloc )
{
switch ( alloc ) {
case ALLOC_CONTIGUOUS :
return ' c ' ;
2006-10-08 16:01:13 +04:00
case ALLOC_CLING :
2007-03-27 17:35:33 +04:00
return ' l ' ;
2004-05-19 02:12:53 +04:00
case ALLOC_NORMAL :
return ' n ' ;
case ALLOC_ANYWHERE :
return ' a ' ;
default :
return ' i ' ;
}
}
2007-11-09 19:51:54 +03:00
static const uint64_t _minusone = UINT64_C ( - 1 ) ;
2002-12-12 23:55:49 +03:00
/*
* Data - munging functions to prepare each data type for display and sorting
*/
2007-08-22 18:38:18 +04:00
static int _string_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2007-01-22 18:07:21 +03:00
return dm_report_field_string ( rh , field , ( const char * * ) data ) ;
2002-12-12 23:55:49 +03:00
}
2007-08-22 18:38:18 +04:00
static int _dev_name_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const char * name = dev_name ( * ( const struct device * * ) data ) ;
2002-12-12 23:55:49 +03:00
2007-01-22 18:07:21 +03:00
return dm_report_field_string ( rh , field , & name ) ;
2002-12-12 23:55:49 +03:00
}
2007-12-15 00:53:02 +03:00
static int _format_pvsegs ( struct dm_pool * mem , struct dm_report_field * field ,
const void * data , int range_format )
2004-05-05 14:58:44 +04:00
{
const struct lv_segment * seg = ( const struct lv_segment * ) data ;
unsigned int s ;
2005-10-17 03:03:59 +04:00
const char * name = NULL ;
uint32_t extent = 0 ;
2004-05-05 14:58:44 +04:00
char extent_str [ 32 ] ;
2007-01-16 21:06:12 +03:00
if ( ! dm_pool_begin_object ( mem , 256 ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_begin_object failed " ) ;
2004-05-05 14:58:44 +04:00
return 0 ;
}
for ( s = 0 ; s < seg - > area_count ; s + + ) {
2005-06-01 20:51:55 +04:00
switch ( seg_type ( seg , s ) ) {
2004-05-05 14:58:44 +04:00
case AREA_LV :
2005-06-01 20:51:55 +04:00
name = seg_lv ( seg , s ) - > name ;
extent = seg_le ( seg , s ) ;
2004-05-05 14:58:44 +04:00
break ;
case AREA_PV :
2005-06-01 20:51:55 +04:00
name = dev_name ( seg_dev ( seg , s ) ) ;
extent = seg_pe ( seg , s ) ;
2004-05-05 14:58:44 +04:00
break ;
2005-06-14 21:54:48 +04:00
case AREA_UNASSIGNED :
name = " unassigned " ;
2004-05-05 14:58:44 +04:00
extent = 0 ;
}
2007-01-16 21:06:12 +03:00
if ( ! dm_pool_grow_object ( mem , name , strlen ( name ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_grow_object failed " ) ;
2004-05-05 14:58:44 +04:00
return 0 ;
}
2007-12-15 00:53:02 +03:00
if ( dm_snprintf ( extent_str , sizeof ( extent_str ) ,
2008-01-30 17:00:02 +03:00
" %s% " PRIu32 " %s " ,
2007-12-15 00:53:02 +03:00
range_format ? " : " : " ( " , extent ,
range_format ? " - " : " ) " ) < 0 ) {
2006-08-21 16:54:53 +04:00
log_error ( " Extent number dm_snprintf failed " ) ;
2004-05-05 14:58:44 +04:00
return 0 ;
}
2007-01-16 21:06:12 +03:00
if ( ! dm_pool_grow_object ( mem , extent_str , strlen ( extent_str ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_grow_object failed " ) ;
2004-05-05 14:58:44 +04:00
return 0 ;
}
2007-12-15 00:53:02 +03:00
if ( range_format ) {
if ( dm_snprintf ( extent_str , sizeof ( extent_str ) ,
2008-01-30 17:00:02 +03:00
" % " PRIu32 , extent + seg - > area_len - 1 ) < 0 ) {
2007-12-15 00:53:02 +03:00
log_error ( " Extent number dm_snprintf failed " ) ;
return 0 ;
}
if ( ! dm_pool_grow_object ( mem , extent_str , strlen ( extent_str ) ) ) {
log_error ( " dm_pool_grow_object failed " ) ;
return 0 ;
}
}
2004-05-05 14:58:44 +04:00
if ( ( s ! = seg - > area_count - 1 ) & &
2007-12-15 00:53:02 +03:00
! dm_pool_grow_object ( mem , range_format ? " " : " , " , 1 ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_grow_object failed " ) ;
2004-05-05 14:58:44 +04:00
return 0 ;
}
}
2007-01-16 21:06:12 +03:00
if ( ! dm_pool_grow_object ( mem , " \0 " , 1 ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_grow_object failed " ) ;
2004-05-05 14:58:44 +04:00
return 0 ;
}
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , dm_pool_end_object ( mem ) , NULL ) ;
2004-05-05 14:58:44 +04:00
return 1 ;
}
2006-10-03 21:55:20 +04:00
2007-12-15 00:53:02 +03:00
static int _devices_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private __attribute ( ( unused ) ) )
{
return _format_pvsegs ( mem , field , data , 0 ) ;
}
static int _peranges_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private __attribute ( ( unused ) ) )
{
return _format_pvsegs ( mem , field , data , 1 ) ;
}
2007-08-22 18:38:18 +04:00
static int _tags_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2004-03-08 20:19:15 +03:00
{
const struct list * tags = ( const struct list * ) data ;
struct str_list * sl ;
2007-01-16 21:06:12 +03:00
if ( ! dm_pool_begin_object ( mem , 256 ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_begin_object failed " ) ;
2004-03-08 20:19:15 +03:00
return 0 ;
}
list_iterate_items ( sl , tags ) {
2007-01-16 21:06:12 +03:00
if ( ! dm_pool_grow_object ( mem , sl - > str , strlen ( sl - > str ) ) | |
( sl - > list . n ! = tags & & ! dm_pool_grow_object ( mem , " , " , 1 ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_grow_object failed " ) ;
2004-03-08 20:19:15 +03:00
return 0 ;
}
}
2007-01-16 21:06:12 +03:00
if ( ! dm_pool_grow_object ( mem , " \0 " , 1 ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_grow_object failed " ) ;
2004-03-08 20:19:15 +03:00
return 0 ;
}
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , dm_pool_end_object ( mem ) , NULL ) ;
2004-03-08 20:19:15 +03:00
return 1 ;
}
2007-01-16 21:06:12 +03:00
static int _modules_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2006-10-03 21:55:20 +04:00
{
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
struct list * modules ;
2007-01-16 21:06:12 +03:00
if ( ! ( modules = str_list_create ( mem ) ) ) {
2006-10-03 21:55:20 +04:00
log_error ( " modules str_list allocation failed " ) ;
return 0 ;
}
2007-01-16 21:06:12 +03:00
if ( ! list_lv_modules ( mem , lv , modules ) )
2006-10-03 21:55:20 +04:00
return_0 ;
2007-01-16 21:06:12 +03:00
return _tags_disp ( rh , mem , field , modules , private ) ;
2006-10-03 21:55:20 +04:00
}
2007-01-16 21:06:12 +03:00
static int _vgfmt_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct volume_group * vg = ( const struct volume_group * ) data ;
2002-12-12 23:55:49 +03:00
if ( ! vg - > fid ) {
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , " " , NULL ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-01-16 21:06:12 +03:00
return _string_disp ( rh , mem , field , & vg - > fid - > fmt - > name , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static int _pvfmt_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct physical_volume * pv =
( const struct physical_volume * ) data ;
2002-12-12 23:55:49 +03:00
if ( ! pv - > fmt ) {
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , " " , NULL ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-01-16 21:06:12 +03:00
return _string_disp ( rh , mem , field , & pv - > fmt - > name , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-08-22 18:38:18 +04:00
static int _lvkmaj_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2004-07-04 02:07:52 +04:00
{
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
struct lvinfo info ;
2007-11-12 23:51:54 +03:00
if ( lv_info ( lv - > vg - > cmd , lv , & info , 0 , 0 ) & & info . exists )
2007-01-22 18:07:21 +03:00
return dm_report_field_int ( rh , field , & info . major ) ;
2004-07-04 02:07:52 +04:00
2007-11-09 19:51:54 +03:00
return dm_report_field_uint64 ( rh , field , & _minusone ) ;
2004-07-04 02:07:52 +04:00
}
2007-08-22 18:38:18 +04:00
static int _lvkmin_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2004-07-04 02:07:52 +04:00
{
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
struct lvinfo info ;
2007-11-12 23:51:54 +03:00
if ( lv_info ( lv - > vg - > cmd , lv , & info , 0 , 0 ) & & info . exists )
2007-01-22 18:07:21 +03:00
return dm_report_field_int ( rh , field , & info . minor ) ;
2004-07-04 02:07:52 +04:00
2007-11-09 19:51:54 +03:00
return dm_report_field_uint64 ( rh , field , & _minusone ) ;
2004-07-04 02:07:52 +04:00
}
2008-01-10 21:35:51 +03:00
static int _lv_mimage_in_sync ( const struct logical_volume * lv )
2007-12-22 05:13:00 +03:00
{
float percent ;
2008-01-16 22:00:59 +03:00
struct lv_segment * mirror_seg = find_mirror_seg ( first_seg ( lv ) ) ;
2007-12-22 05:13:00 +03:00
2008-01-16 22:00:59 +03:00
if ( ! ( lv - > status & MIRROR_IMAGE ) | | ! mirror_seg )
2007-12-22 05:13:00 +03:00
return_0 ;
2008-01-16 22:00:59 +03:00
if ( ! lv_mirror_percent ( lv - > vg - > cmd , mirror_seg - > lv , 0 , & percent , NULL ) )
2007-12-22 05:13:00 +03:00
return_0 ;
if ( percent > = 100.0 )
return 1 ;
return 0 ;
}
2007-08-22 18:38:18 +04:00
static int _lvstatus_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
2003-01-09 01:44:07 +03:00
struct lvinfo info ;
2002-12-20 02:25:55 +03:00
char * repstr ;
2003-01-21 21:50:50 +03:00
float snap_percent ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_zalloc ( mem , 7 ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2003-05-06 16:06:02 +04:00
if ( lv - > status & PVMOVE )
repstr [ 0 ] = ' p ' ;
2008-01-10 21:35:51 +03:00
else if ( lv - > status & CONVERTING )
repstr [ 0 ] = ' c ' ;
2006-05-12 00:17:17 +04:00
else if ( lv - > status & MIRRORED ) {
if ( lv - > status & MIRROR_NOTSYNCED )
repstr [ 0 ] = ' M ' ;
else
repstr [ 0 ] = ' m ' ;
} else if ( lv - > status & MIRROR_IMAGE )
2007-12-22 05:13:00 +03:00
if ( _lv_mimage_in_sync ( lv ) )
repstr [ 0 ] = ' i ' ;
else
repstr [ 0 ] = ' I ' ;
2005-06-01 20:51:55 +04:00
else if ( lv - > status & MIRROR_LOG )
repstr [ 0 ] = ' l ' ;
2004-05-11 20:01:58 +04:00
else if ( lv - > status & VIRTUAL )
repstr [ 0 ] = ' v ' ;
2003-05-06 16:06:02 +04:00
else if ( lv_is_origin ( lv ) )
2002-12-20 02:25:55 +03:00
repstr [ 0 ] = ' o ' ;
2006-04-06 17:39:16 +04:00
else if ( lv_is_cow ( lv ) )
2002-12-20 02:25:55 +03:00
repstr [ 0 ] = ' s ' ;
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 0 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
2003-05-06 16:06:02 +04:00
if ( lv - > status & PVMOVE )
repstr [ 1 ] = ' - ' ;
else if ( lv - > status & LVM_WRITE )
2002-12-20 02:25:55 +03:00
repstr [ 1 ] = ' w ' ;
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 1 ] = ' r ' ;
2002-12-12 23:55:49 +03:00
2004-05-19 02:12:53 +04:00
repstr [ 2 ] = _alloc_policy_char ( lv - > alloc ) ;
2002-12-12 23:55:49 +03:00
2003-05-06 16:06:02 +04:00
if ( lv - > status & LOCKED )
repstr [ 2 ] = toupper ( repstr [ 2 ] ) ;
2002-12-12 23:55:49 +03:00
if ( lv - > status & FIXED_MINOR )
2002-12-20 02:25:55 +03:00
repstr [ 3 ] = ' m ' ; /* Fixed Minor */
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 3 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
2007-11-12 23:51:54 +03:00
if ( lv_info ( lv - > vg - > cmd , lv , & info , 1 , 0 ) & & info . exists ) {
2002-12-12 23:55:49 +03:00
if ( info . suspended )
2002-12-20 02:25:55 +03:00
repstr [ 4 ] = ' s ' ; /* Suspended */
2005-11-09 01:52:26 +03:00
else if ( info . live_table )
2002-12-20 02:25:55 +03:00
repstr [ 4 ] = ' a ' ; /* Active */
2005-11-09 01:52:26 +03:00
else if ( info . inactive_table )
repstr [ 4 ] = ' i ' ; /* Inactive with table */
2002-12-12 23:55:49 +03:00
else
2005-11-09 01:52:26 +03:00
repstr [ 4 ] = ' d ' ; /* Inactive without table */
2003-01-21 21:50:50 +03:00
/* Snapshot dropped? */
2006-04-06 17:39:16 +04:00
if ( info . live_table & & lv_is_cow ( lv ) & &
2006-04-06 18:06:27 +04:00
( ! lv_snapshot_percent ( lv , & snap_percent ) | |
2003-07-05 02:34:56 +04:00
snap_percent < 0 | | snap_percent > = 100 ) ) {
2003-01-21 21:50:50 +03:00
repstr [ 0 ] = toupper ( repstr [ 0 ] ) ;
2003-07-05 02:34:56 +04:00
if ( info . suspended )
2005-11-09 01:52:26 +03:00
repstr [ 4 ] = ' S ' ; /* Susp Inv snapshot */
2003-07-05 02:34:56 +04:00
else
2005-11-09 01:52:26 +03:00
repstr [ 4 ] = ' I ' ; /* Invalid snapshot */
2003-07-05 02:34:56 +04:00
}
2003-01-21 21:50:50 +03:00
2005-11-09 01:52:26 +03:00
if ( info . open_count )
repstr [ 5 ] = ' o ' ; /* Open */
else
repstr [ 5 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
} else {
2002-12-20 02:25:55 +03:00
repstr [ 4 ] = ' - ' ;
repstr [ 5 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , NULL ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _pvstatus_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const uint32_t status = * ( const uint32_t * ) data ;
char * repstr ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_zalloc ( mem , 4 ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
if ( status & ALLOCATABLE_PV )
2002-12-20 02:25:55 +03:00
repstr [ 0 ] = ' a ' ;
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 0 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
if ( status & EXPORTED_VG )
2002-12-20 02:25:55 +03:00
repstr [ 1 ] = ' x ' ;
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 1 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , NULL ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _vgstatus_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2004-05-19 02:12:53 +04:00
const struct volume_group * vg = ( const struct volume_group * ) data ;
2002-12-20 02:25:55 +03:00
char * repstr ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_zalloc ( mem , 7 ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2004-05-19 02:12:53 +04:00
if ( vg - > status & LVM_WRITE )
2002-12-20 02:25:55 +03:00
repstr [ 0 ] = ' w ' ;
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 0 ] = ' r ' ;
2002-12-12 23:55:49 +03:00
2004-05-19 02:12:53 +04:00
if ( vg - > status & RESIZEABLE_VG )
2002-12-20 02:25:55 +03:00
repstr [ 1 ] = ' z ' ;
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 1 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
2004-05-19 02:12:53 +04:00
if ( vg - > status & EXPORTED_VG )
2002-12-20 02:25:55 +03:00
repstr [ 2 ] = ' x ' ;
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 2 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
2004-05-19 02:12:53 +04:00
if ( vg - > status & PARTIAL_VG )
2002-12-20 02:25:55 +03:00
repstr [ 3 ] = ' p ' ;
2002-12-12 23:55:49 +03:00
else
2002-12-20 02:25:55 +03:00
repstr [ 3 ] = ' - ' ;
2002-12-12 23:55:49 +03:00
2004-05-19 02:12:53 +04:00
repstr [ 4 ] = _alloc_policy_char ( vg - > alloc ) ;
2008-04-10 21:09:32 +04:00
if ( vg_is_clustered ( vg ) )
2005-08-16 03:34:11 +04:00
repstr [ 5 ] = ' c ' ;
else
repstr [ 5 ] = ' - ' ;
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , NULL ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-01-16 21:06:12 +03:00
static int _segtype_disp ( struct dm_report * rh __attribute ( ( unused ) ) ,
2007-08-22 18:38:18 +04:00
struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct lv_segment * seg = ( const struct lv_segment * ) data ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
if ( seg - > area_count = = 1 ) {
dm_report_field_set_value ( field , " linear " , NULL ) ;
return 1 ;
}
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , seg - > segtype - > ops - > name ( seg ) , NULL ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _origin_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
2002-12-12 23:55:49 +03:00
2006-04-06 17:39:16 +04:00
if ( lv_is_cow ( lv ) )
2007-01-22 18:07:21 +03:00
return dm_report_field_string ( rh , field ,
( const char * * ) & origin_from_cow ( lv ) - > name ) ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , " " , NULL ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _loglv_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2005-06-01 20:51:55 +04:00
{
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
struct lv_segment * seg ;
list_iterate_items ( seg , & lv - > segments ) {
if ( ! seg_is_mirrored ( seg ) | | ! seg - > log_lv )
continue ;
2007-01-22 18:07:21 +03:00
return dm_report_field_string ( rh , field ,
( const char * * ) & seg - > log_lv - > name ) ;
2005-06-01 20:51:55 +04:00
}
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , " " , NULL ) ;
2005-06-01 20:51:55 +04:00
return 1 ;
}
2007-01-16 21:06:12 +03:00
static int _lvname_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2005-06-03 18:49:51 +04:00
{
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
2007-01-16 21:06:12 +03:00
char * repstr , * lvname ;
2005-06-03 18:49:51 +04:00
size_t len ;
2006-04-07 21:41:56 +04:00
if ( lv_is_visible ( lv ) ) {
2005-06-03 18:49:51 +04:00
repstr = lv - > name ;
2007-01-22 18:07:21 +03:00
return dm_report_field_string ( rh , field , ( const char * * ) & repstr ) ;
2005-06-03 18:49:51 +04:00
}
len = strlen ( lv - > name ) + 3 ;
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_zalloc ( mem , len ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2005-06-03 18:49:51 +04:00
return 0 ;
}
2006-08-21 16:54:53 +04:00
if ( dm_snprintf ( repstr , len , " [%s] " , lv - > name ) < 0 ) {
2005-06-03 18:49:51 +04:00
log_error ( " lvname snprintf failed " ) ;
return 0 ;
}
2007-01-16 21:06:12 +03:00
if ( ! ( lvname = dm_pool_strdup ( mem , lv - > name ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_strdup failed " ) ;
2005-06-03 18:49:51 +04:00
return 0 ;
}
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , lvname ) ;
2005-06-03 18:49:51 +04:00
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _movepv_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2003-05-06 16:06:02 +04:00
{
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
const char * name ;
struct lv_segment * seg ;
2005-06-01 20:51:55 +04:00
list_iterate_items ( seg , & lv - > segments ) {
2003-05-06 16:06:02 +04:00
if ( ! ( seg - > status & PVMOVE ) )
continue ;
2005-06-01 20:51:55 +04:00
name = dev_name ( seg_dev ( seg , 0 ) ) ;
2007-01-22 18:07:21 +03:00
return dm_report_field_string ( rh , field , & name ) ;
2003-05-06 16:06:02 +04:00
}
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , " " , NULL ) ;
2003-05-06 16:06:02 +04:00
return 1 ;
}
2008-01-10 21:35:51 +03:00
static int _convertlv_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
struct dm_report_field * field ,
const void * data , void * private __attribute ( ( unused ) ) )
{
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
const char * name = NULL ;
struct lv_segment * seg ;
if ( lv - > status & CONVERTING ) {
if ( lv - > status & MIRRORED ) {
seg = first_seg ( lv ) ;
/* Temporary mirror is always area_num == 0 */
if ( seg_type ( seg , 0 ) = = AREA_LV & &
is_temporary_mirror_layer ( seg_lv ( seg , 0 ) ) )
name = seg_lv ( seg , 0 ) - > name ;
}
}
if ( name )
return dm_report_field_string ( rh , field , & name ) ;
dm_report_field_set_value ( field , " " , NULL ) ;
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _size32_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const uint32_t size = * ( const uint32_t * ) data ;
2007-01-16 21:06:12 +03:00
const char * disp , * repstr ;
2002-12-20 02:25:55 +03:00
uint64_t * sortval ;
2002-12-12 23:55:49 +03:00
2008-01-30 16:19:47 +03:00
if ( ! * ( disp = display_size_units ( private , ( uint64_t ) size ) ) )
return_0 ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_strdup ( mem , disp ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_strdup failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2007-01-16 21:06:12 +03:00
if ( ! ( sortval = dm_pool_alloc ( mem , sizeof ( uint64_t ) ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2002-12-20 02:25:55 +03:00
* sortval = ( const uint64_t ) size ;
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , sortval ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _size64_disp ( struct dm_report * rh __attribute ( ( unused ) ) ,
struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const uint64_t size = * ( const uint64_t * ) data ;
2007-01-16 21:06:12 +03:00
const char * disp , * repstr ;
2002-12-20 02:25:55 +03:00
uint64_t * sortval ;
2002-12-12 23:55:49 +03:00
2008-01-30 16:19:47 +03:00
if ( ! * ( disp = display_size_units ( private , size ) ) )
return_0 ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_strdup ( mem , disp ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_strdup failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2007-01-16 21:06:12 +03:00
if ( ! ( sortval = dm_pool_alloc ( mem , sizeof ( uint64_t ) ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2002-12-20 02:25:55 +03:00
* sortval = size ;
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , sortval ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-11-09 19:51:54 +03:00
static int _lvreadahead_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private __attribute ( ( unused ) ) )
{
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
if ( lv - > read_ahead = = DM_READ_AHEAD_AUTO ) {
dm_report_field_set_value ( field , " auto " , & _minusone ) ;
return 1 ;
}
2007-11-14 03:08:25 +03:00
return _size32_disp ( rh , mem , field , & lv - > read_ahead , private ) ;
2007-11-09 19:51:54 +03:00
}
static int _lvkreadahead_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data ,
2007-11-14 03:08:25 +03:00
void * private )
2007-11-09 19:51:54 +03:00
{
2007-11-12 23:51:54 +03:00
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
struct lvinfo info ;
2007-11-14 03:08:25 +03:00
if ( ! lv_info ( lv - > vg - > cmd , lv , & info , 0 , 1 ) | | ! info . exists )
return dm_report_field_uint64 ( rh , field , & _minusone ) ;
2007-11-12 23:51:54 +03:00
2007-11-14 03:08:25 +03:00
return _size32_disp ( rh , mem , field , & info . read_ahead , private ) ;
2007-11-09 19:51:54 +03:00
}
2007-01-16 21:06:12 +03:00
static int _vgsize_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct volume_group * vg = ( const struct volume_group * ) data ;
2002-12-12 23:55:49 +03:00
uint64_t size ;
2005-02-01 19:19:48 +03:00
size = ( uint64_t ) vg - > extent_count * vg - > extent_size ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & size , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static int _segstart_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct lv_segment * seg = ( const struct lv_segment * ) data ;
2002-12-12 23:55:49 +03:00
uint64_t start ;
2005-02-01 19:19:48 +03:00
start = ( uint64_t ) seg - > le * seg - > lv - > vg - > extent_size ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & start , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-12-20 19:49:37 +03:00
static int _segstartpe_disp ( struct dm_report * rh ,
struct dm_pool * mem __attribute ( ( unused ) ) ,
struct dm_report_field * field ,
const void * data ,
void * private __attribute ( ( unused ) ) )
2007-12-15 00:53:02 +03:00
{
const struct lv_segment * seg = ( const struct lv_segment * ) data ;
return dm_report_field_uint32 ( rh , field , & seg - > le ) ;
}
2007-01-16 21:06:12 +03:00
static int _segsize_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct lv_segment * seg = ( const struct lv_segment * ) data ;
2002-12-12 23:55:49 +03:00
uint64_t size ;
2005-02-01 19:19:48 +03:00
size = ( uint64_t ) seg - > len * seg - > lv - > vg - > extent_size ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & size , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static int _chunksize_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2005-09-23 21:06:01 +04:00
{
const struct lv_segment * seg = ( const struct lv_segment * ) data ;
uint64_t size ;
2006-04-06 17:39:16 +04:00
if ( lv_is_cow ( seg - > lv ) )
size = ( uint64_t ) find_cow ( seg - > lv ) - > chunk_size ;
2005-09-23 21:06:01 +04:00
else
size = 0 ;
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & size , private ) ;
2005-09-23 21:06:01 +04:00
}
2007-01-16 21:06:12 +03:00
static int _pvused_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct physical_volume * pv =
( const struct physical_volume * ) data ;
2002-12-12 23:55:49 +03:00
uint64_t used ;
if ( ! pv - > pe_count )
used = 0LL ;
else
2005-02-01 19:19:48 +03:00
used = ( uint64_t ) pv - > pe_alloc_count * pv - > pe_size ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & used , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static int _pvfree_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct physical_volume * pv =
( const struct physical_volume * ) data ;
uint64_t freespace ;
2002-12-12 23:55:49 +03:00
if ( ! pv - > pe_count )
2002-12-20 02:25:55 +03:00
freespace = pv - > size ;
2002-12-12 23:55:49 +03:00
else
2005-02-01 19:19:48 +03:00
freespace = ( uint64_t ) ( pv - > pe_count - pv - > pe_alloc_count ) * pv - > pe_size ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & freespace , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static int _pvsize_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct physical_volume * pv =
( const struct physical_volume * ) data ;
2002-12-12 23:55:49 +03:00
uint64_t size ;
if ( ! pv - > pe_count )
size = pv - > size ;
else
2005-02-01 19:19:48 +03:00
size = ( uint64_t ) pv - > pe_count * pv - > pe_size ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & size , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static int _devsize_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2004-08-11 17:15:05 +04:00
{
const struct device * dev = * ( const struct device * * ) data ;
uint64_t size ;
if ( ! dev_get_size ( dev , & size ) )
size = 0 ;
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & size , private ) ;
2004-08-11 17:15:05 +04:00
}
2007-01-16 21:06:12 +03:00
static int _vgfree_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct volume_group * vg = ( const struct volume_group * ) data ;
uint64_t freespace ;
2002-12-12 23:55:49 +03:00
2005-02-01 19:19:48 +03:00
freespace = ( uint64_t ) vg - > free_count * vg - > extent_size ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
return _size64_disp ( rh , mem , field , & freespace , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-08-22 18:38:18 +04:00
static int _uuid_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
char * repstr = NULL ;
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_alloc ( mem , 40 ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2008-01-30 16:19:47 +03:00
if ( ! id_write_format ( ( const struct id * ) data , repstr , 40 ) )
return_0 ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , NULL ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _uint32_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2007-01-22 18:07:21 +03:00
return dm_report_field_uint32 ( rh , field , data ) ;
2002-12-12 23:55:49 +03:00
}
2007-08-22 18:38:18 +04:00
static int _int32_disp ( struct dm_report * rh , struct dm_pool * mem __attribute ( ( unused ) ) ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2007-01-22 18:07:21 +03:00
return dm_report_field_int32 ( rh , field , data ) ;
2002-12-12 23:55:49 +03:00
}
2007-07-09 19:40:43 +04:00
static int _pvmdas_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
{
2008-01-30 17:00:02 +03:00
struct lvmcache_info * info ;
2007-07-10 22:20:00 +04:00
uint32_t count ;
2007-07-10 22:18:33 +04:00
const char * pvid = ( const char * ) ( & ( ( struct id * ) data ) - > uuid ) ;
2007-07-09 19:40:43 +04:00
2008-01-30 02:45:48 +03:00
info = info_from_pvid ( pvid , 0 ) ;
2007-07-10 22:18:33 +04:00
count = info ? list_size ( & info - > mdas ) : 0 ;
2007-07-09 19:40:43 +04:00
return _uint32_disp ( rh , mem , field , & count , private ) ;
}
static int _vgmdas_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
{
const struct volume_group * vg = ( const struct volume_group * ) data ;
uint32_t count ;
count = list_size ( & vg - > fid - > metadata_areas ) ;
return _uint32_disp ( rh , mem , field , & count , private ) ;
}
2007-11-05 20:17:55 +03:00
static int _pvmdafree_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
{
2008-01-30 17:00:02 +03:00
struct lvmcache_info * info ;
2007-11-05 20:17:55 +03:00
uint64_t freespace = UINT64_MAX , mda_free ;
const char * pvid = ( const char * ) ( & ( ( struct id * ) data ) - > uuid ) ;
struct metadata_area * mda ;
2008-01-30 02:45:48 +03:00
info = info_from_pvid ( pvid , 0 ) ;
2007-11-05 20:17:55 +03:00
list_iterate_items ( mda , & info - > mdas ) {
if ( ! mda - > ops - > mda_free_sectors )
continue ;
mda_free = mda - > ops - > mda_free_sectors ( mda ) ;
if ( mda_free < freespace )
freespace = mda_free ;
}
if ( freespace = = UINT64_MAX )
freespace = UINT64_C ( 0 ) ;
return _size64_disp ( rh , mem , field , & freespace , private ) ;
}
static int _vgmdafree_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
{
const struct volume_group * vg = ( const struct volume_group * ) data ;
uint64_t freespace = UINT64_MAX , mda_free ;
struct metadata_area * mda ;
list_iterate_items ( mda , & vg - > fid - > metadata_areas ) {
if ( ! mda - > ops - > mda_free_sectors )
continue ;
mda_free = mda - > ops - > mda_free_sectors ( mda ) ;
if ( mda_free < freespace )
freespace = mda_free ;
}
if ( freespace = = UINT64_MAX )
freespace = UINT64_C ( 0 ) ;
return _size64_disp ( rh , mem , field , & freespace , private ) ;
}
2008-04-10 21:19:02 +04:00
static int _lvcount_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
{
const struct volume_group * vg = ( const struct volume_group * ) data ;
struct lv_list * lvl ;
uint32_t count = 0 ;
list_iterate_items ( lvl , & vg - > lvs )
if ( lv_is_visible ( lvl - > lv ) & & ! ( lvl - > lv - > status & SNAPSHOT ) )
count + + ;
return _uint32_disp ( rh , mem , field , & count , private ) ;
}
2007-01-16 21:06:12 +03:00
static int _lvsegcount_disp ( struct dm_report * rh , struct dm_pool * mem ,
struct dm_report_field * field ,
const void * data , void * private )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
2002-12-12 23:55:49 +03:00
uint32_t count ;
count = list_size ( & lv - > segments ) ;
2007-01-16 21:06:12 +03:00
return _uint32_disp ( rh , mem , field , & count , private ) ;
2002-12-12 23:55:49 +03:00
}
2007-08-22 18:38:18 +04:00
static int _snpercent_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2002-12-12 23:55:49 +03:00
{
2002-12-20 02:25:55 +03:00
const struct logical_volume * lv = ( const struct logical_volume * ) data ;
2003-07-05 02:34:56 +04:00
struct lvinfo info ;
2002-12-12 23:55:49 +03:00
float snap_percent ;
2002-12-20 02:25:55 +03:00
uint64_t * sortval ;
char * repstr ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
/* Suppress snapshot percentage if not using driver */
if ( ! activation ( ) ) {
dm_report_field_set_value ( field , " " , NULL ) ;
return 1 ;
}
if ( ! ( sortval = dm_pool_alloc ( mem , sizeof ( uint64_t ) ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2006-04-06 18:06:27 +04:00
if ( ! lv_is_cow ( lv ) | |
2007-11-12 23:51:54 +03:00
( lv_info ( lv - > vg - > cmd , lv , & info , 0 , 0 ) & & ! info . exists ) ) {
2003-03-24 21:08:53 +03:00
* sortval = UINT64_C ( 0 ) ;
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , " " , sortval ) ;
2002-12-12 23:55:49 +03:00
return 1 ;
}
2006-04-06 18:06:27 +04:00
if ( ! lv_snapshot_percent ( lv , & snap_percent ) | | snap_percent < 0 ) {
2003-03-24 21:08:53 +03:00
* sortval = UINT64_C ( 100 ) ;
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , " 100.00 " , sortval ) ;
2003-01-21 21:50:50 +03:00
return 1 ;
}
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_zalloc ( mem , 8 ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2002-12-12 23:55:49 +03:00
return 0 ;
}
2006-08-21 16:54:53 +04:00
if ( dm_snprintf ( repstr , 7 , " %.2f " , snap_percent ) < 0 ) {
2002-12-12 23:55:49 +03:00
log_error ( " snapshot percentage too large " ) ;
return 0 ;
}
2003-03-24 21:08:53 +03:00
* sortval = snap_percent * UINT64_C ( 1000 ) ;
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , sortval ) ;
2002-12-20 02:25:55 +03:00
2002-12-12 23:55:49 +03:00
return 1 ;
}
2007-08-22 18:38:18 +04:00
static int _copypercent_disp ( struct dm_report * rh __attribute ( ( unused ) ) , struct dm_pool * mem ,
2007-01-16 21:06:12 +03:00
struct dm_report_field * field ,
2007-08-22 18:38:18 +04:00
const void * data , void * private __attribute ( ( unused ) ) )
2003-05-06 16:06:02 +04:00
{
struct logical_volume * lv = ( struct logical_volume * ) data ;
2004-05-05 14:58:44 +04:00
float percent ;
2003-05-06 16:06:02 +04:00
uint64_t * sortval ;
char * repstr ;
2007-01-16 21:06:12 +03:00
if ( ! ( sortval = dm_pool_alloc ( mem , sizeof ( uint64_t ) ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2003-05-06 16:06:02 +04:00
return 0 ;
}
2004-05-05 22:23:11 +04:00
if ( ( ! ( lv - > status & PVMOVE ) & & ! ( lv - > status & MIRRORED ) ) | |
2005-10-17 22:00:02 +04:00
! lv_mirror_percent ( lv - > vg - > cmd , lv , 0 , & percent , NULL ) ) {
2003-05-06 16:06:02 +04:00
* sortval = UINT64_C ( 0 ) ;
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , " " , sortval ) ;
2003-05-06 16:06:02 +04:00
return 1 ;
}
2004-05-05 21:56:20 +04:00
percent = copy_percent ( lv ) ;
2003-05-06 16:06:02 +04:00
2007-01-16 21:06:12 +03:00
if ( ! ( repstr = dm_pool_zalloc ( mem , 8 ) ) ) {
2005-10-17 03:03:59 +04:00
log_error ( " dm_pool_alloc failed " ) ;
2003-05-06 16:06:02 +04:00
return 0 ;
}
2006-08-21 16:54:53 +04:00
if ( dm_snprintf ( repstr , 7 , " %.2f " , percent ) < 0 ) {
2004-05-05 14:58:44 +04:00
log_error ( " copy percentage too large " ) ;
2003-05-06 16:06:02 +04:00
return 0 ;
}
2004-05-05 14:58:44 +04:00
* sortval = percent * UINT64_C ( 1000 ) ;
2007-01-16 21:06:12 +03:00
dm_report_field_set_value ( field , repstr , sortval ) ;
2003-05-06 16:06:02 +04:00
return 1 ;
}
2007-01-16 21:06:12 +03:00
/* Report object types */
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
/* necessary for displaying something for PVs not belonging to VG */
static struct volume_group _dummy_vg = {
2008-02-06 18:47:28 +03:00
. name = ( char * ) " " ,
2002-12-12 23:55:49 +03:00
} ;
2007-01-16 21:06:12 +03:00
static void * _obj_get_vg ( void * obj )
2006-10-02 20:46:27 +04:00
{
2007-01-16 21:06:12 +03:00
struct volume_group * vg = ( ( struct lvm_report_object * ) obj ) - > vg ;
2006-10-02 20:46:27 +04:00
2007-01-16 21:06:12 +03:00
return vg ? vg : & _dummy_vg ;
2006-10-02 20:46:27 +04:00
}
2007-01-16 21:06:12 +03:00
static void * _obj_get_lv ( void * obj )
2002-12-12 23:55:49 +03:00
{
2007-01-16 21:06:12 +03:00
return ( ( struct lvm_report_object * ) obj ) - > lv ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static void * _obj_get_pv ( void * obj )
2002-12-12 23:55:49 +03:00
{
2007-01-16 21:06:12 +03:00
return ( ( struct lvm_report_object * ) obj ) - > pv ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static void * _obj_get_seg ( void * obj )
2002-12-12 23:55:49 +03:00
{
2007-01-16 21:06:12 +03:00
return ( ( struct lvm_report_object * ) obj ) - > seg ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static void * _obj_get_pvseg ( void * obj )
2002-12-12 23:55:49 +03:00
{
2007-01-16 21:06:12 +03:00
return ( ( struct lvm_report_object * ) obj ) - > pvseg ;
2002-12-12 23:55:49 +03:00
}
2007-01-16 21:06:12 +03:00
static const struct dm_report_object_type _report_types [ ] = {
{ VGS , " Volume Group " , " vg_ " , _obj_get_vg } ,
{ LVS , " Logical Volume " , " lv_ " , _obj_get_lv } ,
{ PVS , " Physical Volume " , " pv_ " , _obj_get_pv } ,
{ SEGS , " Logical Volume Segment " , " seg_ " , _obj_get_seg } ,
{ PVSEGS , " Physical Volume Segment " , " pvseg_ " , _obj_get_pvseg } ,
{ 0 , " " , " " , NULL } ,
} ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
/*
* Import column definitions
*/
2002-12-12 23:55:49 +03:00
2007-01-18 20:48:29 +03:00
# define STR DM_REPORT_FIELD_TYPE_STRING
# define NUM DM_REPORT_FIELD_TYPE_NUMBER
2008-01-31 15:19:36 +03:00
# define FIELD(type, strct, sorttype, head, field, width, func, id, desc) {type, sorttype, (off_t)((uintptr_t)&_dummy._ ## strct.field - (uintptr_t)&_dummy._ ## strct), width, id, head, &_ ## func ## _disp, desc},
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
static struct dm_report_field_type _fields [ ] = {
# include "columns.h"
2007-01-30 02:01:18 +03:00
{ 0 , 0 , 0 , 0 , " " , " " , NULL , NULL } ,
2007-01-16 21:06:12 +03:00
} ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
# undef STR
# undef NUM
# undef FIELD
void * report_init ( struct cmd_context * cmd , const char * format , const char * keys ,
2007-07-10 22:20:00 +04:00
report_type_t * report_type , const char * separator ,
int aligned , int buffered , int headings )
2007-01-16 21:06:12 +03:00
{
uint32_t report_flags = 0 ;
2002-12-12 23:55:49 +03:00
if ( aligned )
2007-01-16 21:06:12 +03:00
report_flags | = DM_REPORT_OUTPUT_ALIGNED ;
2002-12-12 23:55:49 +03:00
if ( buffered )
2007-01-16 21:06:12 +03:00
report_flags | = DM_REPORT_OUTPUT_BUFFERED ;
2002-12-12 23:55:49 +03:00
if ( headings )
2007-01-16 21:06:12 +03:00
report_flags | = DM_REPORT_OUTPUT_HEADINGS ;
2002-12-12 23:55:49 +03:00
2007-07-10 22:20:00 +04:00
return dm_report_init ( report_type , _report_types , _fields , format ,
2007-01-16 21:06:12 +03:00
separator , report_flags , keys , cmd ) ;
2002-12-12 23:55:49 +03:00
}
/*
* Create a row of data for an object
*/
int report_object ( void * handle , struct volume_group * vg ,
struct logical_volume * lv , struct physical_volume * pv ,
2005-04-20 00:58:25 +04:00
struct lv_segment * seg , struct pv_segment * pvseg )
2002-12-12 23:55:49 +03:00
{
2007-01-16 21:06:12 +03:00
struct lvm_report_object obj ;
2002-12-12 23:55:49 +03:00
2007-01-16 21:06:12 +03:00
obj . vg = vg ;
obj . lv = lv ;
obj . pv = pv ;
obj . seg = seg ;
obj . pvseg = pvseg ;
2004-05-05 22:23:11 +04:00
2007-01-16 21:06:12 +03:00
return dm_report_object ( handle , & obj ) ;
2002-12-12 23:55:49 +03:00
}