2001-10-04 00:38:07 +04:00
/*
2001-11-07 11:50:07 +03:00
* Copyright ( C ) 2001 Sistina Software
*
* vgcreate 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 .
*
* vgcreate 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 .
2001-10-04 00:38:07 +04:00
*
*/
# include "tools.h"
2001-10-15 22:39:40 +04:00
/* FIXME From config file? */
# define DEFAULT_PV 255
# define DEFAULT_LV 255
2001-10-16 00:29:15 +04:00
# define DEFAULT_EXTENT 4096 /* In KB */
2001-10-12 16:21:43 +04:00
2001-10-04 00:38:07 +04:00
int vgcreate ( int argc , char * * argv )
{
2001-11-06 22:02:26 +03:00
int max_lv , max_pv ;
uint32_t extent_size ;
2001-10-15 16:49:58 +04:00
char * vg_name ;
2001-10-04 00:38:07 +04:00
struct volume_group * vg ;
2001-10-12 16:21:43 +04:00
if ( ! argc ) {
log_error ( " Please provide volume group name and "
" physical volumes " ) ;
2001-10-05 02:53:37 +04:00
return EINVALID_CMD_LINE ;
2001-10-04 00:38:07 +04:00
}
if ( argc = = 1 ) {
2001-10-12 16:21:43 +04:00
log_error ( " Please enter physical volume name(s) " ) ;
2001-10-05 02:53:37 +04:00
return EINVALID_CMD_LINE ;
2001-10-04 00:38:07 +04:00
}
2001-10-15 16:49:58 +04:00
vg_name = argv [ 0 ] ;
2001-10-12 18:25:53 +04:00
max_lv = arg_int_value ( maxlogicalvolumes_ARG , DEFAULT_LV ) ;
max_pv = arg_int_value ( maxphysicalvolumes_ARG , DEFAULT_PV ) ;
2001-10-16 00:29:15 +04:00
/* Units of 512-byte sectors */
extent_size = arg_int_value ( physicalextentsize_ARG , DEFAULT_EXTENT ) * 2 ;
2001-10-12 16:21:43 +04:00
2001-10-15 22:39:40 +04:00
if ( max_lv < 1 ) {
log_error ( " maxlogicalvolumes too low " ) ;
return EINVALID_CMD_LINE ;
}
2002-01-10 17:27:47 +03:00
2001-10-15 22:39:40 +04:00
if ( max_pv < 1 ) {
log_error ( " maxphysicalvolumes too low " ) ;
return EINVALID_CMD_LINE ;
}
2002-01-10 17:27:47 +03:00
2001-11-15 20:27:45 +03:00
/* Strip dev_dir if present */
2001-11-12 18:10:01 +03:00
if ( ! strncmp ( vg_name , fid - > cmd - > dev_dir , strlen ( fid - > cmd - > dev_dir ) ) )
vg_name + = strlen ( fid - > cmd - > dev_dir ) ;
2001-10-15 22:39:40 +04:00
if ( ! is_valid_chars ( vg_name ) ) {
log_error ( " New volume group name '%s' has invalid characters " ,
vg_name ) ;
return ECMD_FAILED ;
}
2001-11-21 22:32:35 +03:00
/* Create the new VG */
2002-01-10 17:27:47 +03:00
if ( ! ( vg = vg_create ( fid , vg_name , extent_size , max_pv , max_lv ,
2001-10-15 22:39:40 +04:00
argc - 1 , argv + 1 ) ) )
2001-10-05 02:53:37 +04:00
return ECMD_FAILED ;
2001-10-04 00:38:07 +04:00
2002-01-10 17:27:47 +03:00
if ( max_lv ! = vg - > max_lv )
log_error ( " Warning: Setting maxlogicalvolumes to %d " ,
2001-10-15 22:39:40 +04:00
vg - > max_lv ) ;
2002-01-10 17:27:47 +03:00
if ( max_pv ! = vg - > max_pv )
log_error ( " Warning: Setting maxphysicalvolumes to %d " ,
2001-10-15 22:39:40 +04:00
vg - > max_pv ) ;
2002-01-09 16:17:14 +03:00
if ( ! archive ( vg ) )
return ECMD_FAILED ;
2001-11-21 22:32:35 +03:00
/* Store VG on disk(s) */
2001-11-12 18:10:01 +03:00
if ( ! fid - > ops - > vg_write ( fid , vg ) )
2001-10-05 02:53:37 +04:00
return ECMD_FAILED ;
2001-10-04 00:38:07 +04:00
2002-01-07 14:12:11 +03:00
backup ( vg ) ;
2002-01-01 00:27:39 +03:00
2001-11-21 22:32:35 +03:00
log_print ( " Volume group %s successfully created " , vg - > name ) ;
2001-10-12 18:25:53 +04:00
2001-10-04 00:38:07 +04:00
return 0 ;
}