2001-10-01 19:29:39 +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 pvcreate_single ( const char * pv_name ) ;
int pvcreate ( int argc , char * * argv )
{
int opt ;
if ( ! argc ) {
log_error ( " Please enter a physical volume path " ) ;
2001-10-05 02:53:37 +04:00
return EINVALID_CMD_LINE ;
2001-10-01 19:29:39 +04:00
}
if ( arg_count ( yes_ARG ) & & ! arg_count ( force_ARG ) ) {
log_error ( " option y can only be given with option f " ) ;
2001-10-05 02:53:37 +04:00
return EINVALID_CMD_LINE ;
2001-10-01 19:29:39 +04:00
}
for ( opt = 0 ; opt < argc ; opt + + )
pvcreate_single ( argv [ opt ] ) ;
return 0 ;
}
void pvcreate_single ( const char * pv_name )
{
int size ;
2001-10-02 02:12:10 +04:00
struct physical_volume * pv = NULL ;
2001-10-01 19:29:39 +04:00
struct device * pv_dev ;
2001-10-02 02:12:10 +04:00
if ( ! ( pv_dev = dev_cache_get ( pv_name ) ) ) {
2001-10-01 19:29:39 +04:00
log_error ( " Device %s not found " , pv_name ) ;
return ;
}
2001-10-02 02:12:10 +04:00
if ( ( size = dev_get_size ( pv_dev ) ) < 0 ) {
2001-10-01 19:29:39 +04:00
log_error ( " Unable to get size of %s " , pv_name ) ;
return ;
}
2001-10-02 02:12:10 +04:00
if ( arg_count ( force_ARG ) < 1 & & ! partition_type_is_lvm ( ios , pv_dev ) ) {
2001-10-01 19:29:39 +04:00
return ;
}
2001-10-02 02:12:10 +04:00
pv = ios - > pv_read ( ios , pv_dev ) ;
if ( pv & & ( pv - > status & STATUS_EXPORTED ) ) {
2001-10-02 21:09:05 +04:00
log_error ( " Physical volume %s belongs to exported volume "
" group %s " , pv_name , pv - > vg_name ) ;
2001-10-01 19:29:39 +04:00
return ;
}
2001-10-02 02:12:10 +04:00
if ( pv & & pv - > vg_name [ 0 ] ) {
2001-10-01 19:29:39 +04:00
if ( arg_count ( force_ARG ) < 2 ) {
log_error ( " Can't initialize physical volume %s of "
" volume group %s without -ff " , pv_name ,
pv - > vg_name ) ;
return ;
}
if ( ! arg_count ( yes_ARG ) ) {
if ( yes_no_prompt
( " Really INITIALIZE physical volume %s "
" of volume group %s [y/n]? " , pv_name ,
pv - > vg_name ) = = ' n ' ) {
log_print ( " physical volume %s not initialized " ,
pv_name ) ;
return ;
}
}
}
2001-10-06 01:39:30 +04:00
if ( pv & & ( pv - > status & ACTIVE ) ) {
2001-10-02 21:09:05 +04:00
log_error ( " Can't create on active physical volume %s " , pv_name ) ;
2001-10-02 02:12:10 +04:00
return ;
}
if ( ! pv ) {
if ( ! ( pv = pv_create ( ) ) )
return ;
/* FIXME: Set up initial size & PEs here */
}
2001-10-01 19:29:39 +04:00
if ( arg_count ( force_ARG ) ) {
/* FIXME: Change to log_print */
printf ( " WARNING: forcing physical volume creation on %s " ,
pv_name ) ;
if ( pv - > vg_name [ 0 ] )
printf ( " of volume group %s " , pv - > vg_name ) ;
printf ( " \n " ) ;
}
/* FIXME: If PV is in VG, remove it. NoOp? Or cache? */
log_verbose ( " creating new physical volume " ) ;
log_verbose ( " setting up physical volume for %s with %u sectors " ,
pv_name , size ) ;
log_verbose ( " writing physical volume data to disk %s " , pv_name ) ;
2001-10-02 02:12:10 +04:00
if ( ! ( pv_write ( ios , pv ) ) ) {
2001-10-01 19:29:39 +04:00
log_error ( " Failed to create physical volume %s " , pv_name ) ;
2001-10-02 02:12:10 +04:00
return ;
2001-10-01 19:29:39 +04:00
}
printf ( " physical volume %s successfully created \n " , pv_name ) ;
/* FIXME: Add the dbg_frees throughout! */
return ;
}