2001-09-25 16:49:28 +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"
int lvactivate ( int argc , char * * argv )
{
int p ;
struct device * pv_dev ;
2001-10-02 02:12:10 +04:00
char * lv_name ;
2001-09-25 16:49:28 +04:00
char * pv_name ;
2001-10-02 02:12:10 +04:00
struct physical_volume * pv = NULL ;
struct logical_volume * lv = NULL ;
2001-09-25 16:49:28 +04:00
if ( argc < 2 ) {
log_error ( " please enter logical volume & physical volume(s) " ) ;
2001-10-05 02:53:37 +04:00
return EINVALID_CMD_LINE ;
2001-09-25 16:49:28 +04:00
}
2001-10-02 02:12:10 +04:00
lv_name = argv [ 0 ] ;
2001-09-25 16:49:28 +04:00
argc - - ;
argv + + ;
while ( argc - - ) {
pv_name = argv [ argc ] ;
2001-10-02 02:12:10 +04:00
if ( ! ( pv_dev = dev_cache_get ( pv_name ) ) ) {
2001-09-25 16:49:28 +04:00
log_error ( " device \" %s \" not found " , pv_name ) ;
return - 1 ;
}
2001-10-02 02:12:10 +04:00
if ( ! ( pv = pv_read ( ios , pv_dev ) ) ) {
2001-09-25 16:49:28 +04:00
return - 1 ;
}
2001-10-06 01:39:30 +04:00
if ( pv - > status & ALLOCATED_PV ) {
2001-09-25 16:49:28 +04:00
if ( ! ( pv - > pe = pv_read_pe ( pv_name , pv ) ) )
goto pvdisplay_device_out ;
if ( ! ( lvs = pv_read_lvs ( pv ) ) ) {
log_error ( " Failed to read LVs on %s " ,
pv - > pv_name ) ;
goto pvdisplay_device_out ;
}
} else
log_print ( " no logical volume on physical volume %s " ,
pv_name ) ;
for ( p = 0 ; p < pv - > pe_total ; p + + ) {
int l = pv - > pe [ p ] . lv_num ;
int le = pv - > pe [ p ] . le_num ;
2001-10-02 21:09:05 +04:00
long pe_size_guess = lvs [ l - 1 ] . lv_size /
lvs [ l - 1 ] . lv_allocated_le ;
2001-09-25 16:49:28 +04:00
if ( l & & ! strcmp ( lv , lvs [ l - 1 ] . lv_name ) )
2001-10-02 21:09:05 +04:00
printf ( " %012ld %ld linear %s %012ld \n " ,
pe_size_guess * le ,
pe_size_guess ,
pv_name , get_pe_offset ( p , pv ) ) ;
2001-09-25 16:49:28 +04:00
}
2001-09-25 20:26:38 +04:00
if ( pv )
dbg_free ( pv - > pe ) ;
2001-09-25 16:49:28 +04:00
dbg_free ( pv ) ;
dbg_free ( lvs ) ;
}
return 0 ;
pvdisplay_device_out :
2001-09-25 20:26:38 +04:00
if ( pv )
dbg_free ( pv - > pe ) ;
2001-09-25 16:49:28 +04:00
dbg_free ( pv ) ;
dbg_free ( lvs ) ;
return - 1 ;
}