2001-10-02 21:09:05 +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-10-02 21:09:05 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2001-10-02 21:09:05 +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-10-02 21:09:05 +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-10-02 21:09:05 +04:00
*/
# include "tools.h"
int pv_max_name_len = 0 ;
int vg_max_name_len = 0 ;
2002-12-20 02:25:55 +03:00
static void _pvscan_display_single ( struct cmd_context * cmd ,
2006-05-10 01:23:51 +04:00
struct physical_volume * pv ,
void * handle __attribute ( ( unused ) ) )
2002-11-18 17:04:08 +03:00
{
2006-12-01 02:11:42 +03:00
char uuid [ 64 ] __attribute ( ( aligned ( 8 ) ) ) ;
2006-05-10 01:23:51 +04:00
unsigned vg_name_len = 0 ;
2002-11-18 17:04:08 +03:00
char pv_tmp_name [ NAME_LEN ] = { 0 , } ;
char vg_tmp_name [ NAME_LEN ] = { 0 , } ;
char vg_name_this [ NAME_LEN ] = { 0 , } ;
/* short listing? */
if ( arg_count ( cmd , short_ARG ) > 0 ) {
2007-10-12 18:29:32 +04:00
log_print ( " %s " , pv_dev_name ( pv ) ) ;
2002-11-18 17:04:08 +03:00
return ;
}
if ( arg_count ( cmd , verbose_ARG ) > 1 ) {
/* FIXME As per pv_display! Drop through for now. */
/* pv_show(pv); */
/* FIXME - Moved to Volume Group structure */
/* log_print("System Id %s", pv->vg->system_id); */
/* log_print(" "); */
/* return; */
}
memset ( pv_tmp_name , 0 , sizeof ( pv_tmp_name ) ) ;
2007-06-16 02:16:55 +04:00
vg_name_len = strlen ( pv_vg_name ( pv ) ) + 1 ;
2002-11-18 17:04:08 +03:00
if ( arg_count ( cmd , uuid_ARG ) ) {
if ( ! id_write_format ( & pv - > id , uuid , sizeof ( uuid ) ) ) {
stack ;
return ;
}
sprintf ( pv_tmp_name , " %-*s with UUID %s " ,
2007-10-12 18:29:32 +04:00
pv_max_name_len - 2 , pv_dev_name ( pv ) , uuid ) ;
2002-11-18 17:04:08 +03:00
} else {
2007-10-12 18:29:32 +04:00
sprintf ( pv_tmp_name , " %s " , pv_dev_name ( pv ) ) ;
2002-11-18 17:04:08 +03:00
}
2007-11-02 17:54:40 +03:00
if ( is_orphan ( pv ) ) {
2002-11-18 17:04:08 +03:00
log_print ( " PV %-*s %-*s %s [%s] " ,
pv_max_name_len , pv_tmp_name ,
vg_max_name_len , " " ,
pv - > fmt ? pv - > fmt - > name : " " ,
2007-06-16 02:16:55 +04:00
display_size ( cmd , pv_size ( pv ) ) ) ;
2002-11-18 17:04:08 +03:00
return ;
}
2007-06-16 02:16:55 +04:00
if ( pv_status ( pv ) & EXPORTED_VG ) {
strncpy ( vg_name_this , pv_vg_name ( pv ) , vg_name_len ) ;
2002-11-18 17:04:08 +03:00
log_print ( " PV %-*s is in exported VG %s "
" [%s / %s free] " ,
pv_max_name_len , pv_tmp_name ,
2002-12-12 23:55:49 +03:00
vg_name_this ,
2007-06-16 02:16:55 +04:00
display_size ( cmd , ( uint64_t ) pv_pe_count ( pv ) *
pv_pe_size ( pv ) ) ,
display_size ( cmd , ( uint64_t ) ( pv_pe_count ( pv ) -
pv_pe_alloc_count ( pv ) )
* pv_pe_size ( pv ) ) ) ;
2002-11-18 17:04:08 +03:00
return ;
}
2007-06-16 02:16:55 +04:00
sprintf ( vg_tmp_name , " %s " , pv_vg_name ( pv ) ) ;
2004-06-07 19:22:43 +04:00
log_print ( " PV %-*s VG %-*s %s [%s / %s free] " , pv_max_name_len ,
pv_tmp_name , vg_max_name_len , vg_tmp_name ,
pv - > fmt ? pv - > fmt - > name : " " ,
2008-01-30 17:00:02 +03:00
display_size ( cmd , ( uint64_t ) pv_pe_count ( pv ) *
2007-06-16 02:16:55 +04:00
pv_pe_size ( pv ) ) ,
2008-01-30 17:00:02 +03:00
display_size ( cmd , ( uint64_t ) ( pv_pe_count ( pv ) -
2007-06-16 02:16:55 +04:00
pv_pe_alloc_count ( pv ) ) *
pv_pe_size ( pv ) ) ) ;
2002-11-18 17:04:08 +03:00
}
2006-05-10 01:23:51 +04:00
int pvscan ( struct cmd_context * cmd , int argc __attribute ( ( unused ) ) ,
char * * argv __attribute ( ( unused ) ) )
2001-10-02 21:09:05 +04:00
{
int new_pvs_found = 0 ;
int pvs_found = 0 ;
2008-11-04 01:14:30 +03:00
struct dm_list * pvslist ;
2001-10-16 22:07:54 +04:00
struct pv_list * pvl ;
2001-10-02 21:09:05 +04:00
struct physical_volume * pv ;
2001-10-05 02:53:37 +04:00
uint64_t size_total = 0 ;
uint64_t size_new = 0 ;
2001-10-02 21:09:05 +04:00
int len = 0 ;
pv_max_name_len = 0 ;
vg_max_name_len = 0 ;
2002-02-12 00:00:35 +03:00
if ( arg_count ( cmd , novolumegroup_ARG ) & & arg_count ( cmd , exported_ARG ) ) {
2001-10-16 22:07:54 +04:00
log_error ( " Options -e and -n are incompatible " ) ;
2001-10-05 02:53:37 +04:00
return EINVALID_CMD_LINE ;
2001-10-02 21:09:05 +04:00
}
2002-02-12 00:00:35 +03:00
if ( arg_count ( cmd , exported_ARG ) | | arg_count ( cmd , novolumegroup_ARG ) )
2007-06-28 21:33:44 +04:00
log_warn ( " WARNING: only considering physical volumes %s " ,
2002-02-12 00:00:35 +03:00
arg_count ( cmd , exported_ARG ) ?
2001-10-02 21:09:05 +04:00
" of exported volume group(s) " : " in no volume group " ) ;
2007-08-23 19:02:26 +04:00
if ( ! lock_vol ( cmd , VG_GLOBAL , LCK_VG_WRITE ) ) {
log_error ( " Unable to obtain global lock. " ) ;
return ECMD_FAILED ;
}
2002-02-11 23:50:53 +03:00
persistent_filter_wipe ( cmd - > filter ) ;
2008-04-08 16:49:21 +04:00
lvmcache_destroy ( cmd , 1 ) ;
2002-11-18 17:04:08 +03:00
2001-10-24 21:53:50 +04:00
log_verbose ( " Walking through all physical volumes " ) ;
2007-08-23 19:02:26 +04:00
if ( ! ( pvslist = get_pvs ( cmd ) ) ) {
unlock_vg ( cmd , VG_GLOBAL ) ;
2009-09-15 02:47:49 +04:00
stack ;
2001-10-05 02:53:37 +04:00
return ECMD_FAILED ;
2007-08-23 19:02:26 +04:00
}
2001-10-02 21:09:05 +04:00
/* eliminate exported/new if required */
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( pvl , pvslist ) {
2002-01-21 19:05:23 +03:00
pv = pvl - > pv ;
2001-10-02 21:09:05 +04:00
2002-04-24 22:20:51 +04:00
if ( ( arg_count ( cmd , exported_ARG )
2007-06-16 02:16:55 +04:00
& & ! ( pv_status ( pv ) & EXPORTED_VG ) )
2007-11-02 17:54:40 +03:00
| | ( arg_count ( cmd , novolumegroup_ARG ) & & ( ! is_orphan ( pv ) ) ) ) {
2008-11-04 01:14:30 +03:00
dm_list_del ( & pvl - > list ) ;
2001-10-02 21:09:05 +04:00
continue ;
}
/* Also check for MD use? */
/*******
if ( MAJOR ( pv_create_kdev_t ( pv [ p ] - > pv_name ) ) ! = MD_MAJOR ) {
2010-04-01 14:34:09 +04:00
log_warn
2001-10-02 21:09:05 +04:00
( " WARNING: physical volume \" %s \" belongs to a meta device " ,
pv [ p ] - > pv_name ) ;
}
if ( MAJOR ( pv [ p ] - > pv_dev ) ! = MD_MAJOR )
continue ;
* * * * * * * */
pvs_found + + ;
2001-10-06 01:39:30 +04:00
2007-11-02 17:54:40 +03:00
if ( is_orphan ( pv ) ) {
2001-10-02 21:09:05 +04:00
new_pvs_found + + ;
2007-06-16 02:16:55 +04:00
size_new + = pv_size ( pv ) ;
size_total + = pv_size ( pv ) ;
2001-10-31 15:47:01 +03:00
} else
2010-05-07 19:24:17 +04:00
size_total + = ( uint64_t ) pv_pe_count ( pv ) * pv_pe_size ( pv ) ;
2001-10-02 21:09:05 +04:00
}
/* find maximum pv name length */
pv_max_name_len = vg_max_name_len = 0 ;
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( pvl , pvslist ) {
2003-10-16 00:02:46 +04:00
pv = pvl - > pv ;
2007-10-12 18:29:32 +04:00
len = strlen ( pv_dev_name ( pv ) ) ;
2001-10-02 21:09:05 +04:00
if ( pv_max_name_len < len )
pv_max_name_len = len ;
2007-06-16 02:16:55 +04:00
len = strlen ( pv_vg_name ( pv ) ) ;
2001-10-02 21:09:05 +04:00
if ( vg_max_name_len < len )
vg_max_name_len = len ;
}
pv_max_name_len + = 2 ;
vg_max_name_len + = 2 ;
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( pvl , pvslist )
2003-10-16 00:02:46 +04:00
_pvscan_display_single ( cmd , pvl - > pv , NULL ) ;
2001-10-02 21:09:05 +04:00
if ( ! pvs_found ) {
log_print ( " No matching physical volumes found " ) ;
2007-08-23 19:02:26 +04:00
unlock_vg ( cmd , VG_GLOBAL ) ;
2003-10-22 02:06:07 +04:00
return ECMD_PROCESSED ;
2001-10-02 21:09:05 +04:00
}
2001-10-16 22:07:54 +04:00
log_print ( " Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s] " ,
2001-10-02 21:09:05 +04:00
pvs_found ,
2006-05-10 01:23:51 +04:00
display_size ( cmd , size_total ) ,
2001-10-02 21:09:05 +04:00
pvs_found - new_pvs_found ,
2006-05-10 01:23:51 +04:00
display_size ( cmd , ( size_total - size_new ) ) ,
new_pvs_found , display_size ( cmd , size_new ) ) ;
2001-10-02 21:09:05 +04:00
2007-08-23 19:02:26 +04:00
unlock_vg ( cmd , VG_GLOBAL ) ;
2003-10-22 02:06:07 +04:00
return ECMD_PROCESSED ;
2001-10-02 21:09:05 +04:00
}