2001-10-02 21:09:05 +04:00
/*
* Copyright ( C ) 2001 Sistina Software
*
* LVM is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 , or ( at your option )
* any later version .
*
* LVM is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with LVM ; see the file COPYING . If not , write to
* the Free Software Foundation , 59 Temple Place - Suite 330 ,
* Boston , MA 02111 - 1307 , USA .
*
*/
# include "tools.h"
void pvscan_display_single ( struct physical_volume * pv ) ;
int pv_max_name_len = 0 ;
int vg_max_name_len = 0 ;
int pvscan ( int argc , char * * argv )
{
int new_pvs_found = 0 ;
int pvs_found = 0 ;
char * s1 , * s2 , * s3 ;
2001-10-31 15:47:01 +03:00
struct list * pvs ;
struct list * pvh ;
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 ;
if ( arg_count ( novolumegroup_ARG ) & & arg_count ( 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
}
if ( arg_count ( exported_ARG ) | | arg_count ( novolumegroup_ARG ) )
log_print ( " WARNING: only considering physical volumes %s " ,
arg_count ( exported_ARG ) ?
" of exported volume group(s) " : " in no volume group " ) ;
2001-10-24 21:53:50 +04:00
log_verbose ( " Wiping cache of LVM-capable devices " ) ;
2001-11-12 18:10:01 +03:00
persistent_filter_wipe ( fid - > cmd - > filter ) ;
2001-10-02 21:09:05 +04:00
2001-10-24 21:53:50 +04:00
log_verbose ( " Walking through all physical volumes " ) ;
2001-11-12 18:10:01 +03:00
if ( ! ( pvs = fid - > ops - > get_pvs ( fid ) ) )
2001-10-05 02:53:37 +04:00
return ECMD_FAILED ;
2001-10-02 21:09:05 +04:00
/* eliminate exported/new if required */
2001-10-31 15:47:01 +03:00
list_iterate ( pvh , pvs ) {
pvl = list_item ( pvh , struct pv_list ) ;
2001-10-02 21:09:05 +04:00
pv = & pvl - > pv ;
2001-10-16 22:07:54 +04:00
if ( ( arg_count ( exported_ARG ) & & ! ( pv - > status & EXPORTED_VG ) )
| | ( arg_count ( novolumegroup_ARG ) & & ( * pv - > vg_name ) ) ) {
2001-10-31 15:47:01 +03:00
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 ) {
log_print
( " 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
2001-10-02 21:09:05 +04:00
2001-10-16 22:07:54 +04:00
if ( ! * pv - > vg_name ) {
2001-10-02 21:09:05 +04:00
new_pvs_found + + ;
2001-10-16 22:07:54 +04:00
size_new + = pv - > size ;
size_total + = pv - > size ;
2001-10-31 15:47:01 +03:00
} else
size_total + = ( pv - > pe_count - pv - > pe_allocated )
2001-10-16 22:07:54 +04:00
* pv - > pe_size ;
2001-10-02 21:09:05 +04:00
}
/* find maximum pv name length */
pv_max_name_len = vg_max_name_len = 0 ;
2001-10-31 15:47:01 +03:00
list_iterate ( pvh , pvs ) {
pv = & list_item ( pvh , struct pv_list ) - > pv ;
2001-10-25 18:04:18 +04:00
len = strlen ( dev_name ( pv - > dev ) ) ;
2001-10-02 21:09:05 +04:00
if ( pv_max_name_len < len )
pv_max_name_len = len ;
len = strlen ( pv - > vg_name ) ;
if ( vg_max_name_len < len )
vg_max_name_len = len ;
}
pv_max_name_len + = 2 ;
vg_max_name_len + = 2 ;
2001-10-31 15:47:01 +03:00
list_iterate ( pvh , pvs )
pvscan_display_single ( & list_item ( pvh , struct pv_list ) - > pv ) ;
2001-10-02 21:09:05 +04:00
if ( ! pvs_found ) {
log_print ( " No matching physical volumes found " ) ;
return 0 ;
}
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 ,
( s1 = display_size ( size_total / 2 , SIZE_SHORT ) ) ,
pvs_found - new_pvs_found ,
( s2 =
display_size ( ( size_total - size_new ) / 2 , SIZE_SHORT ) ) ,
2001-10-06 01:39:30 +04:00
new_pvs_found , ( s3 = display_size ( size_new / 2 , SIZE_SHORT ) ) ) ;
2001-10-02 21:09:05 +04:00
dbg_free ( s1 ) ;
dbg_free ( s2 ) ;
dbg_free ( s3 ) ;
return 0 ;
}
void pvscan_display_single ( struct physical_volume * pv )
{
2002-01-21 14:29:06 +03:00
char uuid [ 64 ] ;
2001-10-02 21:09:05 +04:00
int vg_name_len = 0 ;
char * s1 , * s2 ;
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 ( short_ARG ) > 0 ) {
2001-10-25 18:04:18 +04:00
log_print ( " %s " , dev_name ( pv - > dev ) ) ;
2001-10-02 21:09:05 +04:00
return ;
}
if ( arg_count ( verbose_ARG ) > 1 ) {
2001-10-16 22:07:54 +04:00
/* FIXME As per pv_display! Drop through for now. */
/* pv_show(pv); */
2001-10-02 21:09:05 +04:00
log_print ( " System Id %s " , pv - > exported ) ;
2001-10-16 22:07:54 +04:00
/* log_print(" "); */
/* return; */
2001-10-02 21:09:05 +04:00
}
memset ( pv_tmp_name , 0 , sizeof ( pv_tmp_name ) ) ;
2001-10-16 22:07:54 +04:00
vg_name_len = strlen ( pv - > vg_name ) - sizeof ( EXPORTED_TAG ) + 1 ;
2001-10-02 21:09:05 +04:00
if ( arg_count ( uuid_ARG ) ) {
2002-01-21 14:29:06 +03:00
if ( ! id_write_format ( & pv - > id , uuid , sizeof ( uuid ) ) ) {
stack ;
return ;
}
sprintf ( pv_tmp_name , " %-*s with UUID %s " ,
pv_max_name_len - 2 , dev_name ( pv - > dev ) , uuid ) ;
2001-10-02 21:09:05 +04:00
} else {
2001-10-25 18:04:18 +04:00
sprintf ( pv_tmp_name , " %s " , dev_name ( pv - > dev ) ) ;
2001-10-02 21:09:05 +04:00
}
2001-10-16 22:07:54 +04:00
if ( ! * pv - > vg_name ) {
2002-01-11 02:21:07 +03:00
log_print ( " PV %-*s is in no VG %-*s [%s] " ,
2001-10-02 21:09:05 +04:00
pv_max_name_len , pv_tmp_name ,
2001-10-16 22:07:54 +04:00
vg_max_name_len - 6 , " " ,
2001-10-02 21:09:05 +04:00
( s1 = display_size ( pv - > size / 2 , SIZE_SHORT ) ) ) ;
dbg_free ( s1 ) ;
return ;
}
if ( strcmp ( & pv - > vg_name [ vg_name_len ] , EXPORTED_TAG ) = = 0 ) {
strncpy ( vg_name_this , pv - > vg_name , vg_name_len ) ;
2002-01-11 02:21:07 +03:00
log_print ( " PV %-*s is in EXPORTED VG %s [%s / %s free] " ,
pv_max_name_len , pv_tmp_name ,
2001-10-02 21:09:05 +04:00
vg_name_this , ( s1 =
2001-10-16 22:07:54 +04:00
display_size ( pv - > pe_count *
2001-10-02 21:09:05 +04:00
pv - > pe_size / 2 ,
SIZE_SHORT ) ) ,
2001-10-16 22:07:54 +04:00
( s2 = display_size ( ( pv - > pe_count - pv - > pe_allocated )
2001-10-02 21:09:05 +04:00
* pv - > pe_size / 2 , SIZE_SHORT ) ) ) ;
dbg_free ( s1 ) ;
dbg_free ( s2 ) ;
return ;
}
sprintf ( vg_tmp_name , " %s " , pv - > vg_name ) ;
log_print
2002-01-11 02:21:07 +03:00
( " PV %-*s of VG %-*s [%s / %s free] " , pv_max_name_len ,
2001-10-02 21:09:05 +04:00
pv_tmp_name , vg_max_name_len , vg_tmp_name ,
2001-10-16 22:07:54 +04:00
( s1 = display_size ( pv - > pe_count * pv - > pe_size / 2 , SIZE_SHORT ) ) ,
2001-10-02 21:09:05 +04:00
( s2 =
2001-10-16 22:07:54 +04:00
display_size ( ( pv - > pe_count - pv - > pe_allocated ) * pv - > pe_size / 2 ,
2001-10-02 21:09:05 +04:00
SIZE_SHORT ) ) ) ;
dbg_free ( s1 ) ;
dbg_free ( s2 ) ;
return ;
}