2007-03-31 01:00:26 +04:00
/*
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
* Copyright ( C ) 2007 Red Hat , Inc . All rights reserved .
*
* This file is part of LVM2 .
*
* 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 .
2007-03-31 01:00:26 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2007-03-31 01:00:26 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2007-03-31 01:00:26 +04:00
*/
2018-06-08 15:40:53 +03:00
# include "base/memory/zalloc.h"
2007-03-31 01:00:26 +04:00
# include "tools.h"
int pvck ( struct cmd_context * cmd , int argc , char * * argv )
{
2018-05-04 01:12:07 +03:00
struct dm_list devs ;
struct device_list * devl ;
struct device * dev ;
const char * pv_name ;
uint64_t labelsector ;
2007-04-26 00:03:16 +04:00
int i ;
2014-11-13 15:26:43 +03:00
int ret_max = ECMD_PROCESSED ;
2007-04-26 00:03:16 +04:00
2018-05-04 01:12:07 +03:00
labelsector = arg_uint64_value ( cmd , labelsector_ARG , UINT64_C ( 0 ) ) ;
2018-02-15 20:06:50 +03:00
2018-05-04 01:12:07 +03:00
dm_list_init ( & devs ) ;
2007-04-26 00:03:16 +04:00
2018-05-04 01:12:07 +03:00
for ( i = 0 ; i < argc ; i + + ) {
2011-08-30 18:55:15 +04:00
dm_unescape_colons_and_at_signs ( argv [ i ] , NULL , NULL ) ;
2018-05-04 01:12:07 +03:00
pv_name = argv [ i ] ;
2018-06-15 19:03:55 +03:00
dev = dev_cache_get ( cmd , pv_name , cmd - > filter ) ;
2018-05-04 01:12:07 +03:00
if ( ! dev ) {
log_error ( " Device %s %s. " , pv_name , dev_cache_filtered_reason ( pv_name ) ) ;
continue ;
}
2018-06-08 15:40:53 +03:00
if ( ! ( devl = zalloc ( sizeof ( * devl ) ) ) )
2018-05-04 01:12:07 +03:00
continue ;
devl - > dev = dev ;
dm_list_add ( & devs , & devl - > list ) ;
}
label_scan_setup_bcache ( ) ;
label_scan_devs ( cmd , cmd - > filter , & devs ) ;
dm_list_iterate_items ( devl , & devs ) {
2018-05-11 00:27:34 +03:00
/*
* The scan above will populate lvmcache with any info from the
* standard locations at the start of the device . Now populate
* lvmcache with any info from non - standard offsets .
*
* FIXME : is it possible for a real lvm label sector to be
* anywhere other than the first four sectors of the disk ?
* If not , drop the code in label_read_sector / find_lvm_header
* that supports searching at any sector .
*/
if ( labelsector ) {
if ( ! label_read_sector ( devl - > dev , labelsector ) ) {
stack ;
ret_max = ECMD_FAILED ;
continue ;
}
}
2018-05-04 01:12:07 +03:00
if ( ! pv_analyze ( cmd , devl - > dev , labelsector ) ) {
2014-11-13 15:26:43 +03:00
stack ;
ret_max = ECMD_FAILED ;
}
2007-04-26 00:03:16 +04:00
}
2014-11-13 15:26:43 +03:00
return ret_max ;
2007-03-31 01:00:26 +04:00
}