2001-10-03 20:38:07 +00:00
/*
2001-10-12 14:25:53 +00:00
* Copyright ( C ) 2001 Sistina Software ( UK ) Limited .
2001-10-03 20:38:07 +00:00
*
2001-10-12 14:25:53 +00:00
* This file is released under the GPL .
2001-10-03 20:38:07 +00:00
*/
# include "tools.h"
2001-10-15 18:39:40 +00:00
/* FIXME From config file? */
# define DEFAULT_PV 255
# define DEFAULT_LV 255
2001-10-15 20:29:15 +00:00
# define DEFAULT_EXTENT 4096 /* In KB */
2001-10-12 12:21:43 +00:00
2001-10-03 20:38:07 +00:00
int vgcreate ( int argc , char * * argv )
{
2001-10-12 14:25:53 +00:00
int max_lv , max_pv , extent_size ;
2001-10-15 12:49:58 +00:00
char * vg_name ;
2001-10-03 20:38:07 +00:00
struct volume_group * vg ;
2001-10-12 12:21:43 +00:00
if ( ! argc ) {
log_error ( " Please provide volume group name and "
" physical volumes " ) ;
2001-10-04 22:53:37 +00:00
return EINVALID_CMD_LINE ;
2001-10-03 20:38:07 +00:00
}
if ( argc = = 1 ) {
2001-10-12 12:21:43 +00:00
log_error ( " Please enter physical volume name(s) " ) ;
2001-10-04 22:53:37 +00:00
return EINVALID_CMD_LINE ;
2001-10-03 20:38:07 +00:00
}
2001-10-15 12:49:58 +00:00
vg_name = argv [ 0 ] ;
2001-10-12 14:25:53 +00:00
max_lv = arg_int_value ( maxlogicalvolumes_ARG , DEFAULT_LV ) ;
max_pv = arg_int_value ( maxphysicalvolumes_ARG , DEFAULT_PV ) ;
2001-10-15 20:29:15 +00:00
/* Units of 512-byte sectors */
extent_size = arg_int_value ( physicalextentsize_ARG , DEFAULT_EXTENT ) * 2 ;
2001-10-12 12:21:43 +00:00
2001-10-15 18:39:40 +00:00
if ( max_lv < 1 ) {
log_error ( " maxlogicalvolumes too low " ) ;
return EINVALID_CMD_LINE ;
}
if ( max_pv < 1 ) {
log_error ( " maxphysicalvolumes too low " ) ;
return EINVALID_CMD_LINE ;
}
/* Strip prefix if present */
if ( ! strncmp ( vg_name , ios - > prefix , strlen ( ios - > prefix ) ) )
vg_name + = strlen ( ios - > prefix ) ;
if ( ! is_valid_chars ( vg_name ) ) {
log_error ( " New volume group name '%s' has invalid characters " ,
vg_name ) ;
return ECMD_FAILED ;
}
2001-10-12 14:25:53 +00:00
/* create the new vg */
2001-10-15 18:39:40 +00:00
if ( ! ( vg = vg_create ( ios , vg_name , extent_size , max_pv , max_lv ,
argc - 1 , argv + 1 ) ) )
2001-10-04 22:53:37 +00:00
return ECMD_FAILED ;
2001-10-03 20:38:07 +00:00
2001-10-15 18:39:40 +00:00
if ( max_lv ! = vg - > max_lv )
log_error ( " Warning: Setting maxlogicalvolumes to %d " ,
vg - > max_lv ) ;
if ( max_pv ! = vg - > max_pv )
log_error ( " Warning: Setting maxphysicalvolumes to %d " ,
vg - > max_pv ) ;
2001-10-03 20:38:07 +00:00
/* store vg on disk(s) */
2001-10-15 18:39:40 +00:00
if ( ! ios - > vg_write ( ios , vg ) )
2001-10-04 22:53:37 +00:00
return ECMD_FAILED ;
2001-10-03 20:38:07 +00:00
2001-10-15 12:49:58 +00:00
/* FIXME Create /dev/vg */
/* FIXME Activate */
2001-10-03 20:38:07 +00:00
log_print ( " Volume group %s successfully created and activated " ,
2001-10-15 12:49:58 +00:00
vg_name ) ;
2001-10-12 14:25:53 +00:00
2001-10-03 20:38:07 +00:00
return 0 ;
}