2001-11-06 22:02:26 +03:00
/*
2008-01-30 17:00:02 +03:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2014-02-04 21:57:08 +04:00
* Copyright ( C ) 2004 - 2014 Red Hat , Inc . All rights reserved .
2001-11-06 22:02:26 +03:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2001-11-06 22:02:26 +03:00
*
2004-03-30 23:35:44 +04:00
* 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 .
2004-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2001-11-06 22:02:26 +03:00
*/
# include "tools.h"
2002-01-01 00:27:39 +03:00
2001-11-16 18:38:52 +03:00
# include <fcntl.h>
2001-11-06 22:02:26 +03:00
2009-07-26 06:31:41 +04:00
struct lvcreate_cmdline_params {
2010-11-30 14:53:31 +03:00
percent_type_t percent ;
2009-07-26 06:32:00 +04:00
uint64_t size ;
2009-07-26 06:32:50 +04:00
char * * pvs ;
2014-02-25 12:43:04 +04:00
uint32_t pv_count ;
2009-07-26 06:31:41 +04:00
} ;
2011-09-06 04:26:42 +04:00
static int _set_vg_name ( struct lvcreate_params * lp , const char * vg_name )
{
/* Can't do anything */
if ( ! vg_name )
return 1 ;
/* If VG name already known, ensure this 2nd copy is identical */
if ( lp - > vg_name & & strcmp ( lp - > vg_name , vg_name ) ) {
log_error ( " Inconsistent volume group names "
" given: \" %s \" and \" %s \" " ,
lp - > vg_name , vg_name ) ;
return 0 ;
}
lp - > vg_name = vg_name ;
return 1 ;
}
2006-04-19 19:33:07 +04:00
static int _lvcreate_name_params ( struct lvcreate_params * lp ,
struct cmd_context * cmd ,
int * pargc , char * * * pargv )
2002-02-15 14:53:22 +03:00
{
int argc = * pargc ;
char * * argv = * pargv , * ptr ;
2011-02-18 17:47:28 +03:00
const char * vg_name ;
2002-02-15 14:53:22 +03:00
2011-09-06 04:26:42 +04:00
lp - > pool = arg_str_value ( cmd , thinpool_ARG , NULL ) ;
/* If --thinpool contains VG name, extract it. */
if ( lp - > pool & & strchr ( lp - > pool , ' / ' ) ) {
if ( ! ( lp - > vg_name = extract_vgname ( cmd , lp - > pool ) ) )
return 0 ;
/* Strip VG from pool */
if ( ( ptr = strrchr ( lp - > pool , ( int ) ' / ' ) ) )
lp - > pool = ptr + 1 ;
}
2009-11-03 18:50:42 +03:00
lp - > lv_name = arg_str_value ( cmd , name_ARG , NULL ) ;
2002-02-15 14:53:22 +03:00
2011-09-06 04:26:42 +04:00
/* If --name contains VG name, extract it. */
if ( lp - > lv_name & & strchr ( lp - > lv_name , ' / ' ) ) {
if ( ! _set_vg_name ( lp , extract_vgname ( cmd , lp - > lv_name ) ) )
return_0 ;
/* Strip VG from lv_name */
if ( ( ptr = strrchr ( lp - > lv_name , ( int ) ' / ' ) ) )
lp - > lv_name = ptr + 1 ;
}
2014-02-05 02:50:16 +04:00
if ( seg_is_cache ( lp ) ) {
/*
* We are looking for the origin or cache_pool LV .
* Could be in the form ' lv ' or ' vg / lv '
*
* We store the lv name in ' lp - > origin ' for now , but
* it must be accessed later ( when we can look - up the
* LV in the VG ) whether it is truly the origin that
* was specified , or whether it is the cache_pool .
*/
if ( ! argc ) {
log_error ( " Please specify a logical volume to act as "
" the origin or cache_pool. " ) ;
return 0 ;
}
lp - > origin = skip_dev_dir ( cmd , argv [ 0 ] , NULL ) ;
if ( strrchr ( lp - > origin , ' / ' ) ) {
if ( ! _set_vg_name ( lp , extract_vgname ( cmd , lp - > origin ) ) )
return_0 ;
/* Strip the volume group from the origin */
if ( ( ptr = strrchr ( lp - > origin , ( int ) ' / ' ) ) )
lp - > origin = ptr + 1 ;
}
if ( ! lp - > vg_name & &
! _set_vg_name ( lp , extract_vgname ( cmd , NULL ) ) )
return_0 ;
if ( ! lp - > vg_name ) {
log_error ( " The origin or cache_pool name should include "
" the volume group. " ) ;
return 0 ;
}
lp - > cache = 1 ;
( * pargv ) + + , ( * pargc ) - - ;
} else if ( lp - > snapshot & & ! arg_count ( cmd , virtualsize_ARG ) ) {
2011-09-06 04:26:42 +04:00
/* argv[0] might be origin or vg/origin */
2002-02-15 14:53:22 +03:00
if ( ! argc ) {
2009-07-16 00:02:46 +04:00
log_error ( " Please specify a logical volume to act as "
" the snapshot origin. " ) ;
2002-02-15 14:53:22 +03:00
return 0 ;
}
2011-09-06 04:26:42 +04:00
lp - > origin = skip_dev_dir ( cmd , argv [ 0 ] , NULL ) ;
if ( strrchr ( lp - > origin , ' / ' ) ) {
if ( ! _set_vg_name ( lp , extract_vgname ( cmd , lp - > origin ) ) )
return_0 ;
/* Strip the volume group from the origin */
if ( ( ptr = strrchr ( lp - > origin , ( int ) ' / ' ) ) )
lp - > origin = ptr + 1 ;
}
2012-02-27 14:00:23 +04:00
if ( ! lp - > vg_name & &
! _set_vg_name ( lp , extract_vgname ( cmd , NULL ) ) )
return_0 ;
2011-11-07 15:01:53 +04:00
2011-09-06 04:26:42 +04:00
if ( ! lp - > vg_name ) {
2009-07-16 00:02:46 +04:00
log_error ( " The origin name should include the "
" volume group. " ) ;
2002-02-15 14:53:22 +03:00
return 0 ;
}
2011-09-06 04:26:42 +04:00
( * pargv ) + + , ( * pargc ) - - ;
} else if ( seg_is_thin ( lp ) & & ! lp - > pool & & argc ) {
/* argv[0] might be vg or vg/Pool */
vg_name = skip_dev_dir ( cmd , argv [ 0 ] , NULL ) ;
if ( ! strrchr ( vg_name , ' / ' ) ) {
if ( ! _set_vg_name ( lp , vg_name ) )
return_0 ;
} else {
lp - > pool = vg_name ;
if ( ! _set_vg_name ( lp , extract_vgname ( cmd , lp - > pool ) ) )
return_0 ;
2011-11-07 15:01:53 +04:00
2012-02-27 14:00:23 +04:00
if ( ! lp - > vg_name & &
! _set_vg_name ( lp , extract_vgname ( cmd , NULL ) ) )
return_0 ;
2011-11-07 15:01:53 +04:00
2011-09-06 04:26:42 +04:00
if ( ! lp - > vg_name ) {
log_error ( " The pool name should include the "
" volume group. " ) ;
return 0 ;
}
2002-02-18 13:59:51 +03:00
2011-09-06 04:26:42 +04:00
/* Strip the volume group */
if ( ( ptr = strrchr ( lp - > pool , ( int ) ' / ' ) ) )
lp - > pool = ptr + 1 ;
}
( * pargv ) + + , ( * pargc ) - - ;
2002-02-15 14:53:22 +03:00
} else {
/*
2011-09-06 04:26:42 +04:00
* If VG not on command line , try environment default .
2002-02-15 14:53:22 +03:00
*/
if ( ! argc ) {
2011-09-06 04:26:42 +04:00
if ( ! lp - > vg_name & & ! ( lp - > vg_name = extract_vgname ( cmd , NULL ) ) ) {
2009-07-16 00:02:46 +04:00
log_error ( " Please provide a volume group name " ) ;
2002-02-15 14:53:22 +03:00
return 0 ;
}
} else {
2007-03-09 23:47:41 +03:00
vg_name = skip_dev_dir ( cmd , argv [ 0 ] , NULL ) ;
2004-10-15 19:53:18 +04:00
if ( strrchr ( vg_name , ' / ' ) ) {
2002-07-17 20:04:05 +04:00
log_error ( " Volume group name expected "
" (no slash) " ) ;
return 0 ;
}
2011-09-06 04:26:42 +04:00
if ( ! _set_vg_name ( lp , vg_name ) )
return_0 ;
2002-02-15 14:53:22 +03:00
( * pargv ) + + , ( * pargc ) - - ;
}
2001-11-06 22:02:26 +03:00
}
2007-11-02 23:40:05 +03:00
if ( ! validate_name ( lp - > vg_name ) ) {
log_error ( " Volume group name %s has invalid characters " ,
lp - > vg_name ) ;
return 0 ;
}
2003-04-25 02:23:24 +04:00
if ( lp - > lv_name ) {
2008-01-30 16:19:47 +03:00
if ( ! apply_lvname_restrictions ( lp - > lv_name ) )
return_0 ;
2002-11-18 17:04:08 +03:00
2003-04-25 02:23:24 +04:00
if ( ! validate_name ( lp - > lv_name ) ) {
2003-09-15 19:01:00 +04:00
log_error ( " Logical volume name \" %s \" is invalid " ,
lp - > lv_name ) ;
2003-04-25 02:23:24 +04:00
return 0 ;
}
2003-02-03 23:09:58 +03:00
}
2011-09-06 04:26:42 +04:00
if ( lp - > pool ) {
if ( ! apply_lvname_restrictions ( lp - > pool ) )
return_0 ;
if ( ! validate_name ( lp - > pool ) ) {
log_error ( " Logical volume name \" %s \" is invalid " ,
lp - > pool ) ;
return 0 ;
}
if ( lp - > lv_name & & ! strcmp ( lp - > lv_name , lp - > pool ) ) {
log_error ( " Logical volume name %s and pool name %s must be different. " ,
lp - > lv_name , lp - > pool ) ;
return 0 ;
}
}
return 1 ;
}
/*
* Normal snapshot or thinly - provisioned snapshot ?
*/
static int _determine_snapshot_type ( struct volume_group * vg ,
struct lvcreate_params * lp )
{
struct lv_list * lvl ;
if ( ! ( lvl = find_lv_in_vg ( vg , lp - > origin ) ) ) {
2011-11-10 16:43:05 +04:00
log_error ( " Snapshot origin LV %s not found in Volume group %s. " ,
lp - > origin , vg - > name ) ;
2011-09-06 04:26:42 +04:00
return 0 ;
}
2011-11-10 16:39:46 +04:00
if ( ! arg_count ( vg - > cmd , extents_ARG ) & & ! arg_count ( vg - > cmd , size_ARG ) ) {
2013-04-02 16:53:58 +04:00
if ( seg_is_thin ( lp ) ) {
if ( ! ( lp - > segtype = get_segtype_from_string ( vg - > cmd , " thin " ) ) )
return_0 ;
return 1 ;
}
2011-11-10 16:39:46 +04:00
if ( ! lv_is_thin_volume ( lvl - > lv ) ) {
log_error ( " Please specify either size or extents with snapshots. " ) ;
return 0 ;
}
2011-09-06 04:26:42 +04:00
if ( ! ( lp - > segtype = get_segtype_from_string ( vg - > cmd , " thin " ) ) )
return_0 ;
2011-09-07 02:43:56 +04:00
lp - > pool = first_seg ( lvl - > lv ) - > pool_lv - > name ;
2011-09-06 04:26:42 +04:00
}
2002-02-15 14:53:22 +03:00
return 1 ;
}
2014-02-04 19:58:35 +04:00
static int _lvcreate_update_pool_params ( struct volume_group * vg ,
struct lvcreate_params * lp )
{
2014-02-04 21:50:27 +04:00
if ( seg_is_cache_pool ( lp ) )
return update_cache_pool_params ( vg , lp - > target_attr ,
lp - > passed_args ,
lp - > extents , vg - > extent_size ,
& lp - > thin_chunk_size_calc_policy ,
& lp - > chunk_size , & lp - > discards ,
& lp - > poolmetadatasize ,
& lp - > zero ) ;
2014-02-04 19:58:35 +04:00
return update_thin_pool_params ( vg , lp - > target_attr , lp - > passed_args ,
lp - > extents , vg - > extent_size ,
& lp - > thin_chunk_size_calc_policy ,
& lp - > chunk_size , & lp - > discards ,
& lp - > poolmetadatasize , & lp - > zero ) ;
}
2014-02-05 02:50:16 +04:00
/*
* _determine_cache_argument
* @ vg
* @ lp
*
* ' lp - > origin ' is set with an LV that could be either the origin
* or the cache_pool of the cached LV which is being created . This
* function determines which it is and sets ' lp - > origin ' or
* ' lp - > pool ' appropriately .
*/
static int _determine_cache_argument ( struct volume_group * vg ,
struct lvcreate_params * lp )
{
struct lv_list * lvl ;
if ( ! seg_is_cache ( lp ) ) {
log_error ( INTERNAL_ERROR
" Unable to determine cache argument on %s segtype " ,
lp - > segtype - > name ) ;
return 0 ;
}
if ( ! ( lvl = find_lv_in_vg ( vg , lp - > origin ) ) ) {
log_error ( " LV %s not found in Volume group %s. " ,
lp - > origin , vg - > name ) ;
return 0 ;
}
if ( lv_is_cache_pool ( lvl - > lv ) ) {
lp - > pool = lp - > origin ;
lp - > origin = NULL ;
} else {
lp - > pool = NULL ;
lp - > create_pool = 1 ;
lp - > poolmetadataspare = arg_int_value ( vg - > cmd ,
poolmetadataspare_ARG ,
DEFAULT_POOL_METADATA_SPARE ) ;
lp - > origin = lp - > origin ;
}
return 1 ;
}
2009-07-26 06:31:18 +04:00
/*
* Update extents parameters based on other parameters which affect the size
2011-11-10 16:43:05 +04:00
* calculation .
2009-07-26 06:31:18 +04:00
* NOTE : We must do this here because of the percent_t typedef and because we
* need the vg .
*/
static int _update_extents_params ( struct volume_group * vg ,
2009-07-26 06:31:41 +04:00
struct lvcreate_params * lp ,
struct lvcreate_cmdline_params * lcp )
2009-07-26 06:31:18 +04:00
{
uint32_t pv_extent_count ;
2010-02-03 06:58:08 +03:00
struct logical_volume * origin = NULL ;
2012-04-11 16:33:34 +04:00
uint32_t size_rest ;
uint32_t stripesize_extents ;
2013-05-29 23:43:46 +04:00
uint32_t extents ;
2009-07-26 06:31:18 +04:00
2009-07-26 06:32:00 +04:00
if ( lcp - > size & &
2009-07-26 06:34:09 +04:00
! ( lp - > extents = extents_from_size ( vg - > cmd , lcp - > size ,
2009-07-26 06:31:18 +04:00
vg - > extent_size ) ) )
return_0 ;
if ( lp - > voriginsize & &
2009-07-26 06:34:09 +04:00
! ( lp - > voriginextents = extents_from_size ( vg - > cmd , lp - > voriginsize ,
2009-07-26 06:31:18 +04:00
vg - > extent_size ) ) )
return_0 ;
/*
2009-07-26 06:31:41 +04:00
* Create the pv list before we parse lcp - > percent - might be
2009-07-26 06:31:18 +04:00
* PERCENT_PVSs
*/
2009-07-26 06:32:50 +04:00
if ( lcp - > pv_count ) {
2009-07-26 06:31:18 +04:00
if ( ! ( lp - > pvh = create_pv_list ( vg - > cmd - > mem , vg ,
2013-06-24 13:48:08 +04:00
lcp - > pv_count , lcp - > pvs , 1 ) ) )
2009-07-26 06:31:18 +04:00
return_0 ;
} else
lp - > pvh = & vg - > pvs ;
2014-02-25 12:36:26 +04:00
switch ( lcp - > percent ) {
2009-07-26 06:31:18 +04:00
case PERCENT_VG :
2014-02-22 04:26:01 +04:00
extents = percent_of_extents ( lp - > extents , vg - > extent_count , 0 ) ;
2009-07-26 06:31:18 +04:00
break ;
case PERCENT_FREE :
2014-02-22 04:26:01 +04:00
extents = percent_of_extents ( lp - > extents , vg - > free_count , 0 ) ;
2009-07-26 06:31:18 +04:00
break ;
case PERCENT_PVS :
2013-06-24 13:48:08 +04:00
if ( lcp - > pv_count ) {
2009-11-04 17:47:27 +03:00
pv_extent_count = pv_list_extents_free ( lp - > pvh ) ;
2014-02-22 04:26:01 +04:00
extents = percent_of_extents ( lp - > extents , pv_extent_count , 0 ) ;
2013-06-24 13:48:08 +04:00
} else
2014-02-22 04:26:01 +04:00
extents = percent_of_extents ( lp - > extents , vg - > extent_count , 0 ) ;
2009-07-26 06:31:18 +04:00
break ;
case PERCENT_LV :
log_error ( " Please express size as %%VG, %%PVS, or "
" %%FREE. " ) ;
return 0 ;
2010-02-03 06:58:08 +03:00
case PERCENT_ORIGIN :
if ( lp - > snapshot & & lp - > origin & &
! ( origin = find_lv ( vg , lp - > origin ) ) ) {
log_error ( " Couldn't find origin volume '%s'. " ,
lp - > origin ) ;
return 0 ;
}
2010-10-25 16:05:46 +04:00
if ( ! origin ) {
log_error ( INTERNAL_ERROR " Couldn't find origin volume. " ) ;
return 0 ;
}
2014-02-22 04:26:01 +04:00
extents = percent_of_extents ( lp - > extents , origin - > le_count , 0 ) ;
2010-02-03 06:58:08 +03:00
break ;
2009-07-26 06:31:18 +04:00
case PERCENT_NONE :
2014-02-22 04:26:01 +04:00
extents = lp - > extents ;
2009-07-26 06:31:18 +04:00
break ;
2014-02-25 12:36:26 +04:00
default :
log_error ( INTERNAL_ERROR " Unsupported percent type %u. " , lcp - > percent ) ;
return 0 ;
2009-07-26 06:31:18 +04:00
}
2011-11-05 02:43:10 +04:00
2014-02-22 04:26:01 +04:00
if ( lcp - > percent ) {
2014-02-25 02:48:23 +04:00
/* FIXME Don't do the adjustment for parallel allocation with PERCENT_ORIGIN! */
2014-02-22 04:26:01 +04:00
lp - > approx_alloc = 1 ;
log_verbose ( " Converted % " PRIu32 " %%%s into % " PRIu32 " extents. " , lp - > extents , get_percent_string ( lcp - > percent ) , extents ) ;
lp - > extents = extents ;
}
2013-05-31 13:00:29 +04:00
if ( lp - > snapshot & & lp - > origin & & lp - > extents ) {
if ( ! lp - > chunk_size ) {
log_error ( INTERNAL_ERROR " Missing snapshot chunk size. " ) ;
return 0 ;
}
2013-05-29 23:43:46 +04:00
if ( ! origin & & ! ( origin = find_lv ( vg , lp - > origin ) ) ) {
log_error ( " Couldn't find origin volume '%s'. " ,
lp - > origin ) ;
return 0 ;
}
extents = cow_max_extents ( origin , lp - > chunk_size ) ;
if ( extents < lp - > extents ) {
2013-05-30 19:56:02 +04:00
log_print_unless_silent ( " Reducing COW size %s down to maximum usable size %s. " ,
2013-05-29 23:43:46 +04:00
display_size ( vg - > cmd , ( uint64_t ) vg - > extent_size * lp - > extents ) ,
display_size ( vg - > cmd , ( uint64_t ) vg - > extent_size * extents ) ) ;
lp - > extents = extents ;
}
}
2012-04-11 16:33:34 +04:00
if ( ! ( stripesize_extents = lp - > stripe_size / vg - > extent_size ) )
stripesize_extents = 1 ;
if ( ( lcp - > percent ! = PERCENT_NONE ) & & lp - > stripes & &
( size_rest = lp - > extents % ( lp - > stripes * stripesize_extents ) ) & &
( vg - > free_count < lp - > extents - size_rest + ( lp - > stripes * stripesize_extents ) ) ) {
config: add silent mode
Accept -q as the short form of --quiet.
Suppress non-essential standard output if -q is given twice.
Treat log/silent in lvm.conf as equivalent to -qq.
Review all log_print messages and change some to
log_print_unless_silent.
When silent, the following commands still produce output:
dumpconfig, lvdisplay, lvmdiskscan, lvs, pvck, pvdisplay,
pvs, version, vgcfgrestore -l, vgdisplay, vgs.
[Needs checking.]
Non-essential messages are shifted from log level 4 to log level 5
for syslog and lvm2_log_fn purposes.
2012-08-25 23:35:48 +04:00
log_print_unless_silent ( " Rounding size (%d extents) down to stripe boundary "
" size (%d extents) " , lp - > extents ,
2012-04-11 16:33:34 +04:00
lp - > extents - size_rest ) ;
lp - > extents = lp - > extents - size_rest ;
}
2014-01-22 20:30:55 +04:00
if ( lp - > create_pool ) {
2014-02-04 19:58:35 +04:00
if ( ! _lvcreate_update_pool_params ( vg , lp ) )
2012-11-19 15:47:34 +04:00
return_0 ;
2012-03-03 00:18:25 +04:00
if ( ! ( lp - > poolmetadataextents =
extents_from_size ( vg - > cmd , lp - > poolmetadatasize , vg - > extent_size ) ) )
return_0 ;
2013-05-13 15:03:04 +04:00
if ( lcp - > percent = = PERCENT_FREE ) {
if ( lp - > extents < = ( 2 * lp - > poolmetadataextents ) ) {
log_error ( " Not enough space for thin pool creation. " ) ;
return 0 ;
}
/* FIXME: persistent hidden space in VG wanted */
lp - > extents - = ( 2 * lp - > poolmetadataextents ) ;
}
2012-03-03 00:18:25 +04:00
}
2011-11-05 02:43:10 +04:00
2009-07-26 06:31:18 +04:00
return 1 ;
}
2002-02-15 14:53:22 +03:00
static int _read_size_params ( struct lvcreate_params * lp ,
2009-07-26 06:31:41 +04:00
struct lvcreate_cmdline_params * lcp ,
2006-05-10 01:23:51 +04:00
struct cmd_context * cmd )
2002-02-15 14:53:22 +03:00
{
2011-09-06 04:26:42 +04:00
if ( arg_count ( cmd , extents_ARG ) & & arg_count ( cmd , size_ARG ) ) {
2004-05-11 20:01:58 +04:00
log_error ( " Please specify either size or extents (not both) " ) ;
2002-02-15 14:53:22 +03:00
return 0 ;
2001-11-06 22:02:26 +03:00
}
2011-09-06 04:26:42 +04:00
if ( ! lp - > thin & & ! lp - > snapshot & & ! arg_count ( cmd , extents_ARG ) & & ! arg_count ( cmd , size_ARG ) ) {
log_error ( " Please specify either size or extents " ) ;
return 0 ;
}
2003-09-15 19:04:39 +04:00
if ( arg_count ( cmd , extents_ARG ) ) {
2012-02-28 18:24:57 +04:00
if ( arg_sign_value ( cmd , extents_ARG , SIGN_NONE ) = = SIGN_MINUS ) {
2003-09-15 19:04:39 +04:00
log_error ( " Negative number of extents is invalid " ) ;
return 0 ;
}
2002-12-20 02:25:55 +03:00
lp - > extents = arg_uint_value ( cmd , extents_ARG , 0 ) ;
2009-07-26 06:31:41 +04:00
lcp - > percent = arg_percent_value ( cmd , extents_ARG , PERCENT_NONE ) ;
2003-09-15 19:04:39 +04:00
}
2002-02-15 14:53:22 +03:00
/* Size returned in kilobyte units; held in sectors */
2003-09-15 19:04:39 +04:00
if ( arg_count ( cmd , size_ARG ) ) {
2012-02-28 18:24:57 +04:00
if ( arg_sign_value ( cmd , size_ARG , SIGN_NONE ) = = SIGN_MINUS ) {
2003-09-15 19:04:39 +04:00
log_error ( " Negative size is invalid " ) ;
return 0 ;
}
2009-07-26 06:32:00 +04:00
lcp - > size = arg_uint64_value ( cmd , size_ARG , UINT64_C ( 0 ) ) ;
2009-07-26 06:31:41 +04:00
lcp - > percent = PERCENT_NONE ;
2003-09-15 19:04:39 +04:00
}
2002-02-15 14:53:22 +03:00
2011-09-06 04:26:42 +04:00
/* If size/extents given with thin, then we are creating a thin pool */
2013-04-02 16:53:58 +04:00
if ( seg_is_thin ( lp ) & & ( arg_count ( cmd , size_ARG ) | | arg_count ( cmd , extents_ARG ) ) )
2014-01-22 20:30:55 +04:00
lp - > create_pool = 1 ;
2011-09-06 04:26:42 +04:00
2014-01-22 20:30:55 +04:00
if ( ! lp - > create_pool & & arg_count ( cmd , poolmetadatasize_ARG ) ) {
2012-11-19 15:47:34 +04:00
log_error ( " --poolmetadatasize may only be specified when allocating the thin pool. " ) ;
return 0 ;
2011-11-05 02:43:10 +04:00
}
2009-05-27 20:30:29 +04:00
if ( arg_count ( cmd , virtualsize_ARG ) ) {
2011-09-06 04:26:42 +04:00
if ( seg_is_thin_pool ( lp ) ) {
log_error ( " Virtual size in incompatible with thin_pool segment type. " ) ;
return 0 ;
}
2012-02-28 18:24:57 +04:00
if ( arg_sign_value ( cmd , virtualsize_ARG , SIGN_NONE ) = = SIGN_MINUS ) {
2009-04-25 05:17:59 +04:00
log_error ( " Negative virtual origin size is invalid " ) ;
return 0 ;
}
2013-06-24 22:54:05 +04:00
/* Size returned in kilobyte units; held in sectors */
2009-05-27 20:30:29 +04:00
lp - > voriginsize = arg_uint64_value ( cmd , virtualsize_ARG ,
2009-04-25 05:17:59 +04:00
UINT64_C ( 0 ) ) ;
if ( ! lp - > voriginsize ) {
log_error ( " Virtual origin size may not be zero " ) ;
return 0 ;
}
2011-09-06 04:26:42 +04:00
} else {
2013-04-02 16:53:58 +04:00
/* No virtual size given and no snapshot, so no thin LV to create. */
if ( seg_is_thin_volume ( lp ) & & ! lp - > snapshot & &
! ( lp - > segtype = get_segtype_from_string ( cmd , " thin-pool " ) ) )
2011-09-06 04:26:42 +04:00
return_0 ;
lp - > thin = 0 ;
2009-04-25 05:17:59 +04:00
}
2002-02-15 14:53:22 +03:00
return 1 ;
}
2007-09-24 17:29:49 +04:00
/*
* Generic mirror parameter checks .
* FIXME : Should eventually be moved into lvm library .
*/
2010-07-09 19:34:40 +04:00
static int _validate_mirror_params ( const struct cmd_context * cmd __attribute__ ( ( unused ) ) ,
2007-09-25 01:30:00 +04:00
const struct lvcreate_params * lp )
2005-06-01 20:51:55 +04:00
{
2006-08-17 22:23:44 +04:00
int pagesize = lvm_getpagesize ( ) ;
2005-06-01 20:51:55 +04:00
if ( lp - > region_size & ( lp - > region_size - 1 ) ) {
log_error ( " Region size (% " PRIu32 " ) must be a power of 2 " ,
lp - > region_size ) ;
return 0 ;
}
2006-04-28 21:25:54 +04:00
if ( lp - > region_size % ( pagesize > > SECTOR_SHIFT ) ) {
log_error ( " Region size (% " PRIu32 " ) must be a multiple of "
" machine memory page size (%d) " ,
lp - > region_size , pagesize > > SECTOR_SHIFT ) ;
return 0 ;
}
2006-04-28 17:11:05 +04:00
if ( ! lp - > region_size ) {
log_error ( " Non-zero region size must be supplied. " ) ;
return 0 ;
}
2007-09-24 17:29:49 +04:00
return 1 ;
}
static int _read_mirror_params ( struct lvcreate_params * lp ,
2007-10-01 19:01:26 +04:00
struct cmd_context * cmd )
2007-09-24 17:29:49 +04:00
{
int region_size ;
const char * mirrorlog ;
2010-01-12 17:00:51 +03:00
int corelog = arg_count ( cmd , corelog_ARG ) ;
2007-08-02 01:01:06 +04:00
2007-08-30 23:34:19 +04:00
mirrorlog = arg_str_value ( cmd , mirrorlog_ARG ,
2010-01-12 17:00:51 +03:00
corelog ? " core " : DEFAULT_MIRRORLOG ) ;
2007-08-30 23:34:19 +04:00
2010-03-27 01:15:43 +03:00
if ( strcmp ( " core " , mirrorlog ) & & corelog ) {
log_error ( " Please use only one of --mirrorlog or --corelog " ) ;
return 0 ;
}
if ( ! strcmp ( " mirrored " , mirrorlog ) ) {
lp - > log_count = 2 ;
} else if ( ! strcmp ( " disk " , mirrorlog ) ) {
2010-01-09 01:32:35 +03:00
lp - > log_count = 1 ;
2010-01-12 17:00:51 +03:00
} else if ( ! strcmp ( " core " , mirrorlog ) )
2010-01-09 01:32:35 +03:00
lp - > log_count = 0 ;
2007-08-21 23:46:36 +04:00
else {
log_error ( " Unknown mirrorlog type: %s " , mirrorlog ) ;
return 0 ;
2007-08-02 01:01:06 +04:00
}
2007-08-21 23:46:36 +04:00
log_verbose ( " Setting logging type to %s " , mirrorlog ) ;
2009-11-03 18:50:42 +03:00
lp - > nosync = arg_is_set ( cmd , nosync_ARG ) ;
2006-05-11 22:54:04 +04:00
2007-09-24 17:29:49 +04:00
if ( arg_count ( cmd , regionsize_ARG ) ) {
2012-02-28 18:24:57 +04:00
if ( arg_sign_value ( cmd , regionsize_ARG , SIGN_NONE ) = = SIGN_MINUS ) {
2007-09-24 17:29:49 +04:00
log_error ( " Negative regionsize is invalid " ) ;
return 0 ;
}
2007-11-14 03:08:25 +03:00
lp - > region_size = arg_uint_value ( cmd , regionsize_ARG , 0 ) ;
2007-09-24 17:29:49 +04:00
} else {
2013-02-21 00:40:17 +04:00
region_size = get_default_region_size ( cmd ) ;
2007-09-24 17:29:49 +04:00
if ( region_size < 0 ) {
log_error ( " Negative regionsize in configuration file "
" is invalid " ) ;
return 0 ;
}
lp - > region_size = region_size ;
}
if ( ! _validate_mirror_params ( cmd , lp ) )
return 0 ;
2005-06-01 20:51:55 +04:00
return 1 ;
}
2011-08-03 02:07:20 +04:00
static int _read_raid_params ( struct lvcreate_params * lp ,
struct cmd_context * cmd )
{
if ( ! segtype_is_raid ( lp - > segtype ) )
return 1 ;
if ( arg_count ( cmd , corelog_ARG ) | |
arg_count ( cmd , mirrorlog_ARG ) ) {
log_error ( " Log options not applicable to %s segtype " ,
lp - > segtype - > name ) ;
return 0 ;
}
RAID: Allow implicit stripe (and parity) when creating RAID LVs
There are typically 2 functions for the more advanced segment types that
deal with parameters in lvcreate.c: _get_*_params() and _check_*_params().
(Not all segment types name their functions according to this scheme.)
The former function is responsible for reading parameters before the VG
has been read. The latter is for sanity checking and possibly setting
parameters after the VG has been read.
This patch adds a _check_raid_parameters() function that will determine
if the user has specified 'stripe' or 'mirror' parameters. If not, the
proper number is computed from the list of PVs the user has supplied or
the number that are available in the VG. Now that _check_raid_parameters()
is available, we move the check for proper number of stripes from
_get_* to _check_*.
This gives the user the ability to create RAID LVs as follows:
# 5-device RAID5, 4-data, 1-parity (i.e. implicit '-i 4')
~> lvcreate --type raid5 -L 100G -n lv vg /dev/sd[abcde]1
# 5-device RAID6, 3-data, 2-parity (i.e. implicit '-i 3')
~> lvcreate --type raid6 -L 100G -n lv vg /dev/sd[abcde]1
# If 5 PVs in VG, 4-data, 1-parity RAID5
~> lvcreate --type raid5 -L 100G -n lv vg
Considerations:
This patch only affects RAID. It might also be useful to apply this to
the 'stripe' segment type. LVM RAID may include RAID0 at some point in
the future and the implicit stripes would apply there. It would be odd
to have RAID0 be able to auto-determine the stripe count while 'stripe'
could not.
The only draw-back of this patch that I can see is that there might be
less error checking. Rather than informing the user that they forgot
to supply an argument (e.g. '-i'), the value would be computed and it
may differ from what the user actually wanted. I don't see this as a
problem, because the user can check the device count after creation
and remove the LV if they have made an error.
2014-02-18 06:18:23 +04:00
if ( ! strcmp ( lp - > segtype - > name , " raid10 " ) & & ( lp - > stripes < 2 ) ) {
2012-11-22 04:46:52 +04:00
if ( arg_count ( cmd , stripes_ARG ) ) {
/* User supplied the bad argument */
log_error ( " Segment type 'raid10' requires 2 or more stripes. " ) ;
return 0 ;
}
/* No stripe argument was given - default to 2 */
lp - > stripes = 2 ;
2013-06-25 14:30:34 +04:00
lp - > stripe_size = find_config_tree_int ( cmd , metadata_stripesize_CFG , NULL ) * 2 ;
2011-08-03 02:07:20 +04:00
}
2012-08-08 21:32:27 +04:00
/*
* RAID types without a mirror component do not take ' - m ' arg
*/
if ( ! segtype_is_mirrored ( lp - > segtype ) & &
arg_count ( cmd , mirrors_ARG ) ) {
log_error ( " Mirror argument cannot be used with segment type, %s " ,
lp - > segtype - > name ) ;
return 0 ;
}
/*
* RAID1 does not take a stripe arg
*/
if ( ( lp - > stripes > 1 ) & &
segtype_is_mirrored ( lp - > segtype ) & &
strcmp ( lp - > segtype - > name , " raid10 " ) ) {
log_error ( " Stripe argument cannot be used with segment type, %s " ,
lp - > segtype - > name ) ;
return 0 ;
}
2011-08-03 02:07:20 +04:00
/*
* _read_mirror_params is called before _read_raid_params
* and already sets :
* lp - > nosync
* lp - > region_size
*
* But let ' s ensure that programmers don ' t reorder
* that by checking and warning if they aren ' t set .
*/
if ( ! lp - > region_size ) {
2011-09-06 04:26:42 +04:00
log_error ( INTERNAL_ERROR " region_size not set. " ) ;
return 0 ;
}
2013-05-31 20:25:52 +04:00
if ( arg_count ( cmd , minrecoveryrate_ARG ) )
lp - > min_recovery_rate = arg_uint_value ( cmd ,
minrecoveryrate_ARG , 0 ) ;
if ( arg_count ( cmd , maxrecoveryrate_ARG ) )
lp - > max_recovery_rate = arg_uint_value ( cmd ,
maxrecoveryrate_ARG , 0 ) ;
/* Rates are recorded in kiB/sec/disk, not sectors/sec/disk */
lp - > min_recovery_rate / = 2 ;
lp - > max_recovery_rate / = 2 ;
if ( lp - > max_recovery_rate & &
( lp - > max_recovery_rate < lp - > min_recovery_rate ) ) {
2014-02-22 03:23:59 +04:00
log_error ( " Minimum recovery rate cannot be higher than maximum. " ) ;
2013-05-31 20:25:52 +04:00
return 0 ;
}
2011-09-06 04:26:42 +04:00
return 1 ;
}
2014-02-04 21:57:08 +04:00
static int _read_cache_pool_params ( struct lvcreate_params * lp ,
struct cmd_context * cmd )
{
const char * str_arg ;
if ( ! segtype_is_cache_pool ( lp - > segtype ) )
return 1 ;
if ( arg_sign_value ( cmd , chunksize_ARG , SIGN_NONE ) = = SIGN_MINUS ) {
log_error ( " Negative chunk size is invalid. " ) ;
return 0 ;
}
lp - > chunk_size = arg_uint_value ( cmd , chunksize_ARG ,
DEFAULT_CACHE_POOL_CHUNK_SIZE * 2 ) ;
str_arg = arg_str_value ( cmd , cachemode_ARG , NULL ) ;
if ( str_arg ) {
if ( ! strcmp ( str_arg , " writeback " ) )
lp - > feature_flags | = DM_CACHE_FEATURE_WRITEBACK ;
else if ( ! strcmp ( str_arg , " writethrough " ) )
lp - > feature_flags | = DM_CACHE_FEATURE_WRITETHROUGH ;
else {
log_error ( " Unknown cachemode argument " ) ;
return 0 ;
}
}
return 1 ;
}
static int _read_activation_params ( struct lvcreate_params * lp ,
struct cmd_context * cmd ,
2012-08-06 20:01:01 +04:00
struct volume_group * vg )
2011-09-06 04:26:42 +04:00
{
unsigned pagesize ;
2012-02-28 18:24:57 +04:00
lp - > activate = ( activation_change_t )
2012-06-27 15:48:31 +04:00
arg_uint_value ( cmd , activate_ARG , CHANGE_AY ) ;
2011-09-06 04:26:42 +04:00
2014-02-18 23:52:17 +04:00
if ( ! is_change_activating ( lp - > activate ) ) {
2011-09-06 04:26:42 +04:00
if ( lp - > zero & & ! seg_is_thin ( lp ) ) {
2012-06-27 15:48:31 +04:00
log_error ( " --activate n requires --zero n " ) ;
2011-09-06 04:26:42 +04:00
return 0 ;
}
2012-06-28 12:15:07 +04:00
} else if ( lp - > activate = = CHANGE_AAY ) {
2013-11-06 19:05:50 +04:00
if ( arg_count ( cmd , zero_ARG ) | | arg_count ( cmd , wipesignatures_ARG ) ) {
log_error ( " -Z and -W is incompatible with --activate a " ) ;
2012-06-28 12:15:07 +04:00
return 0 ;
}
lp - > zero = 0 ;
2011-09-06 04:26:42 +04:00
}
/*
* Read ahead .
*/
lp - > read_ahead = arg_uint_value ( cmd , readahead_ARG ,
cmd - > default_settings . read_ahead ) ;
pagesize = lvm_getpagesize ( ) > > SECTOR_SHIFT ;
if ( lp - > read_ahead ! = DM_READ_AHEAD_AUTO & &
lp - > read_ahead ! = DM_READ_AHEAD_NONE & &
lp - > read_ahead % pagesize ) {
if ( lp - > read_ahead < pagesize )
lp - > read_ahead = pagesize ;
else
lp - > read_ahead = ( lp - > read_ahead / pagesize ) * pagesize ;
log_warn ( " WARNING: Overriding readahead to %u sectors, a multiple "
2013-07-06 13:04:19 +04:00
" of %uK page size. " , lp - > read_ahead , pagesize > > 1 ) ;
2011-09-06 04:26:42 +04:00
}
/*
* Permissions .
*/
lp - > permission = arg_uint_value ( cmd , permission_ARG ,
LVM_READ | LVM_WRITE ) ;
2014-02-26 03:17:11 +04:00
if ( lp - > snapshot ) {
/* Snapshot has to zero COW header */
lp - > zero = 1 ;
lp - > wipe_signatures = 0 ;
} else if ( ! ( lp - > permission & LVM_WRITE ) ) {
/* Must not zero/wipe read only volume */
2011-09-06 04:26:42 +04:00
lp - > zero = 0 ;
2013-11-06 19:05:50 +04:00
lp - > wipe_signatures = 0 ;
}
2011-09-06 04:26:42 +04:00
2012-03-06 06:30:49 +04:00
if ( arg_count ( cmd , major_ARG ) > 1 ) {
log_error ( " Option -j/--major may not be repeated. " ) ;
return 0 ;
}
if ( arg_count ( cmd , minor_ARG ) > 1 ) {
log_error ( " Option --minor may not be repeated. " ) ;
return 0 ;
}
2011-09-06 04:26:42 +04:00
lp - > minor = arg_int_value ( cmd , minor_ARG , - 1 ) ;
lp - > major = arg_int_value ( cmd , major_ARG , - 1 ) ;
/* Persistent minor */
if ( arg_count ( cmd , persistent_ARG ) ) {
2014-01-22 20:30:55 +04:00
if ( lp - > create_pool & & ! lp - > thin ) {
2011-09-06 04:26:42 +04:00
log_error ( " --persistent is not permitted when creating a thin pool device. " ) ;
return 0 ;
}
if ( ! strcmp ( arg_str_value ( cmd , persistent_ARG , " n " ) , " y " ) ) {
if ( lp - > minor = = - 1 ) {
log_error ( " Please specify minor number with "
" --minor when using -My " ) ;
return 0 ;
}
2014-04-04 15:29:39 +04:00
if ( ! strncmp ( cmd - > kernel_vsn , " 2.4. " , 4 ) ) {
if ( lp - > major = = - 1 ) {
log_error ( " Please specify major number with "
" --major when using -My " ) ;
return 0 ;
}
} else {
if ( lp - > major > = 0 )
log_warn ( " Ignoring supplied major number - kernel assigns "
" major numbers dynamically. Using major number %d instead. " ,
cmd - > dev_types - > device_mapper_major ) ;
lp - > major = cmd - > dev_types - > device_mapper_major ;
2011-09-06 04:26:42 +04:00
}
2012-08-06 20:01:01 +04:00
if ( ! major_minor_valid ( cmd , vg - > fid - > fmt , lp - > major , lp - > minor ) )
return 0 ;
2011-09-06 04:26:42 +04:00
} else {
if ( ( lp - > minor ! = - 1 ) | | ( lp - > major ! = - 1 ) ) {
log_error ( " --major and --minor incompatible "
" with -Mn " ) ;
return 0 ;
}
}
} else if ( arg_count ( cmd , minor_ARG ) | | arg_count ( cmd , major_ARG ) ) {
log_error ( " --major and --minor require -My " ) ;
2011-08-03 02:07:20 +04:00
return 0 ;
}
2013-07-10 16:06:50 +04:00
if ( arg_count ( cmd , setactivationskip_ARG ) ) {
lp - > activation_skip | = ACTIVATION_SKIP_SET ;
if ( arg_int_value ( cmd , setactivationskip_ARG , 0 ) )
lp - > activation_skip | = ACTIVATION_SKIP_SET_ENABLED ;
}
if ( arg_count ( cmd , ignoreactivationskip_ARG ) )
lp - > activation_skip | = ACTIVATION_SKIP_IGNORE ;
if ( lp - > zero & & ( lp - > activation_skip & ACTIVATION_SKIP_SET_ENABLED )
& & ! ( lp - > activation_skip & ACTIVATION_SKIP_IGNORE ) ) {
log_error ( " --setactivationskip y requires either --zero n "
" or --ignoreactivationskip " ) ;
return 0 ;
}
2013-11-06 19:16:34 +04:00
lp - > yes = arg_count ( cmd , yes_ARG ) ;
lp - > force = ( force_t ) arg_count ( cmd , force_ARG ) ;
2013-07-10 16:06:50 +04:00
2011-08-03 02:07:20 +04:00
return 1 ;
}
2009-07-26 06:31:41 +04:00
static int _lvcreate_params ( struct lvcreate_params * lp ,
struct lvcreate_cmdline_params * lcp ,
struct cmd_context * cmd ,
2006-04-19 19:33:07 +04:00
int argc , char * * argv )
2002-02-15 14:53:22 +03:00
{
2004-05-19 02:12:53 +04:00
int contiguous ;
2010-11-11 20:29:05 +03:00
struct arg_value_group_list * current_group ;
2011-08-03 02:07:20 +04:00
const char * segtype_str ;
2010-11-11 20:29:05 +03:00
const char * tag ;
2004-05-19 02:12:53 +04:00
2002-07-17 20:04:05 +04:00
memset ( lp , 0 , sizeof ( * lp ) ) ;
2009-07-26 06:31:41 +04:00
memset ( lcp , 0 , sizeof ( * lcp ) ) ;
2010-11-11 20:29:05 +03:00
dm_list_init ( & lp - > tags ) ;
2012-11-26 14:05:30 +04:00
lp - > target_attr = ~ 0 ;
2002-07-17 20:04:05 +04:00
2002-02-15 14:53:22 +03:00
/*
2004-05-11 20:01:58 +04:00
* Check selected options are compatible and determine segtype
2002-02-15 14:53:22 +03:00
*/
2012-10-12 14:18:06 +04:00
if ( ( arg_count ( cmd , thin_ARG ) | | arg_count ( cmd , thinpool_ARG ) ) & &
arg_count ( cmd , mirrors_ARG ) ) {
2013-05-31 13:02:52 +04:00
log_error ( " --thin, --thinpool and --mirrors are incompatible. " ) ;
2011-09-06 04:26:42 +04:00
return 0 ;
}
2013-07-23 23:46:22 +04:00
/* Set default segtype - remember, '-m 0' implies stripe. */
if ( arg_count ( cmd , mirrors_ARG ) & &
arg_uint_value ( cmd , mirrors_ARG , 0 ) )
2013-02-21 01:10:04 +04:00
if ( arg_uint_value ( cmd , arg_count ( cmd , stripes_long_ARG ) ?
stripes_long_ARG : stripes_ARG , 1 ) > 1 ) {
2013-06-25 14:29:54 +04:00
segtype_str = find_config_tree_str ( cmd , global_raid10_segtype_default_CFG , NULL ) ; ;
2013-02-21 01:10:04 +04:00
} else {
2013-06-25 14:29:54 +04:00
segtype_str = find_config_tree_str ( cmd , global_mirror_segtype_default_CFG , NULL ) ;
2013-02-21 01:10:04 +04:00
}
2011-09-06 04:26:42 +04:00
else if ( arg_count ( cmd , thin_ARG ) | | arg_count ( cmd , thinpool_ARG ) )
segtype_str = " thin " ;
else
segtype_str = " striped " ;
2011-08-03 02:07:20 +04:00
2012-03-02 01:21:54 +04:00
segtype_str = arg_str_value ( cmd , type_ARG , segtype_str ) ;
if ( ! ( lp - > segtype = get_segtype_from_string ( cmd , segtype_str ) ) )
return_0 ;
2004-05-11 20:01:58 +04:00
2011-09-08 20:41:18 +04:00
if ( seg_unknown ( lp ) ) {
2012-03-02 01:21:54 +04:00
log_error ( " Unable to create LV with unknown segment type %s. " , segtype_str ) ;
2011-09-08 20:41:18 +04:00
return 0 ;
}
2013-04-02 16:53:58 +04:00
if ( ( arg_count ( cmd , snapshot_ARG ) | | seg_is_snapshot ( lp ) ) & &
arg_count ( cmd , thin_ARG ) ) {
log_error ( " --thin and --snapshot are incompatible. " ) ;
return 0 ;
}
2009-05-27 20:30:29 +04:00
if ( arg_count ( cmd , snapshot_ARG ) | | seg_is_snapshot ( lp ) | |
2011-09-06 04:26:42 +04:00
( ! seg_is_thin ( lp ) & & arg_count ( cmd , virtualsize_ARG ) ) )
2004-05-11 20:01:58 +04:00
lp - > snapshot = 1 ;
2014-02-04 21:57:08 +04:00
if ( seg_is_cache_pool ( lp ) )
lp - > create_pool = 1 ;
2011-09-06 04:26:42 +04:00
if ( seg_is_thin_pool ( lp ) ) {
if ( lp - > snapshot ) {
log_error ( " Snapshots are incompatible with thin_pool segment_type. " ) ;
return 0 ;
}
2014-01-22 20:30:55 +04:00
lp - > create_pool = 1 ;
2011-09-06 04:26:42 +04:00
}
if ( seg_is_thin_volume ( lp ) )
lp - > thin = 1 ;
2005-06-01 20:51:55 +04:00
lp - > mirrors = 1 ;
2012-08-25 00:34:19 +04:00
/* Default to 2 mirrored areas if '--type mirror|raid1|raid10' */
2011-03-26 00:56:28 +03:00
if ( segtype_is_mirrored ( lp - > segtype ) )
2005-06-01 20:51:55 +04:00
lp - > mirrors = 2 ;
if ( arg_count ( cmd , mirrors_ARG ) ) {
2013-06-24 13:55:18 +04:00
if ( arg_sign_value ( cmd , mirrors_ARG , SIGN_NONE ) = = SIGN_MINUS ) {
log_error ( " Mirrors argument may not be negative " ) ;
return 0 ;
}
2005-06-01 20:51:55 +04:00
lp - > mirrors = arg_uint_value ( cmd , mirrors_ARG , 0 ) + 1 ;
2013-06-24 13:55:18 +04:00
if ( lp - > mirrors > DEFAULT_MIRROR_MAX_IMAGES ) {
log_error ( " Only up to " DM_TO_STRING ( DEFAULT_MIRROR_MAX_IMAGES )
" images in mirror supported currently. " ) ;
return 0 ;
}
2011-09-22 19:36:21 +04:00
if ( lp - > mirrors = = 1 ) {
if ( segtype_is_mirrored ( lp - > segtype ) ) {
2011-09-27 16:37:07 +04:00
log_error ( " --mirrors must be at least 1 with segment type %s. " , lp - > segtype - > name ) ;
2011-09-22 19:36:21 +04:00
return 0 ;
}
config: add silent mode
Accept -q as the short form of --quiet.
Suppress non-essential standard output if -q is given twice.
Treat log/silent in lvm.conf as equivalent to -qq.
Review all log_print messages and change some to
log_print_unless_silent.
When silent, the following commands still produce output:
dumpconfig, lvdisplay, lvmdiskscan, lvs, pvck, pvdisplay,
pvs, version, vgcfgrestore -l, vgdisplay, vgs.
[Needs checking.]
Non-essential messages are shifted from log level 4 to log level 5
for syslog and lvm2_log_fn purposes.
2012-08-25 23:35:48 +04:00
log_print_unless_silent ( " Redundant mirrors argument: default is 0 " ) ;
2011-09-22 19:36:21 +04:00
}
2012-08-25 00:34:19 +04:00
if ( ( lp - > mirrors > 2 ) & & ! strcmp ( lp - > segtype - > name , " raid10 " ) ) {
/*
* FIXME : When RAID10 is no longer limited to
* 2 - way mirror , ' lv_mirror_count ( ) '
* must also change for RAID10 .
*/
log_error ( " RAID10 currently supports "
" only 2-way mirroring (i.e. '-m 1') " ) ;
return 0 ;
}
2005-06-01 20:51:55 +04:00
}
2011-09-06 04:26:42 +04:00
if ( lp - > snapshot & & arg_count ( cmd , zero_ARG ) ) {
log_error ( " -Z is incompatible with snapshots " ) ;
return 0 ;
2002-07-17 20:04:05 +04:00
}
2002-02-15 14:53:22 +03:00
2011-08-03 02:07:20 +04:00
if ( segtype_is_mirrored ( lp - > segtype ) | | segtype_is_raid ( lp - > segtype ) ) {
2005-06-01 20:51:55 +04:00
if ( lp - > snapshot ) {
log_error ( " mirrors and snapshots are currently "
" incompatible " ) ;
return 0 ;
}
2006-05-11 22:54:04 +04:00
} else {
if ( arg_count ( cmd , corelog_ARG ) ) {
log_error ( " --corelog is only available with mirrors " ) ;
return 0 ;
}
2006-05-12 00:03:40 +04:00
2010-05-12 01:40:11 +04:00
if ( arg_count ( cmd , mirrorlog_ARG ) ) {
log_error ( " --mirrorlog is only available with mirrors " ) ;
return 0 ;
}
2006-05-12 00:03:40 +04:00
if ( arg_count ( cmd , nosync_ARG ) ) {
log_error ( " --nosync is only available with mirrors " ) ;
return 0 ;
}
2005-06-01 20:51:55 +04:00
}
2014-02-24 16:15:40 +04:00
if ( activation ( ) & & lp - > segtype - > ops - > target_present ) {
if ( ! lp - > segtype - > ops - > target_present ( cmd , NULL , & lp - > target_attr ) ) {
log_error ( " %s: Required device-mapper target(s) not detected in your kernel. " ,
lp - > segtype - > name ) ;
2012-08-25 00:34:19 +04:00
return 0 ;
}
2014-02-24 16:15:40 +04:00
if ( ( strcmp ( lp - > segtype - > name , " raid10 " ) = = 0 ) & &
! ( lp - > target_attr & RAID_FEATURE_RAID10 ) ) {
log_error ( " RAID module does not support RAID10. " ) ;
2012-08-25 00:34:19 +04:00
return 0 ;
}
2004-05-11 20:01:58 +04:00
}
2012-11-15 17:47:37 +04:00
/*
2013-11-06 19:05:50 +04:00
* Should we zero / wipe signatures on the lv .
2012-11-15 17:47:37 +04:00
*/
2014-02-11 16:42:32 +04:00
lp - > zero = ( ! ( lp - > segtype - > flags & SEG_CANNOT_BE_ZEROED ) & &
( strcmp ( arg_str_value ( cmd , zero_ARG , " y " ) , " y " ) = = 0 ) ) ? 1 : 0 ;
2012-11-15 17:47:37 +04:00
2013-11-06 19:05:50 +04:00
if ( arg_count ( cmd , wipesignatures_ARG ) ) {
/* If -W/--wipesignatures is given on command line directly, respect it. */
2014-02-11 16:42:32 +04:00
lp - > wipe_signatures = ( ! ( lp - > segtype - > flags & SEG_CANNOT_BE_ZEROED ) & &
( strcmp ( arg_str_value ( cmd , wipesignatures_ARG , " y " ) , " y " ) = = 0 ) ) ? 1 : 0 ;
2013-11-06 19:05:50 +04:00
} else {
/*
* If - W / - - wipesignatures is not given on command line ,
2013-12-09 13:35:47 +04:00
* look at the allocation / wipe_signatures_when_zeroing_new_lvs
2013-11-06 19:05:50 +04:00
* to decide what should be done exactly .
*/
2013-12-09 13:35:47 +04:00
if ( find_config_tree_bool ( cmd , allocation_wipe_signatures_when_zeroing_new_lvs_CFG , NULL ) )
2013-11-06 19:05:50 +04:00
lp - > wipe_signatures = lp - > zero ;
else
lp - > wipe_signatures = 0 ;
}
2006-04-19 19:33:07 +04:00
if ( ! _lvcreate_name_params ( lp , cmd , & argc , & argv ) | |
2009-07-26 06:31:41 +04:00
! _read_size_params ( lp , lcp , cmd ) | |
2010-04-13 05:54:32 +04:00
! get_stripe_params ( cmd , & lp - > stripes , & lp - > stripe_size ) | |
2014-01-22 20:30:55 +04:00
( lp - > create_pool & &
2013-06-27 13:22:02 +04:00
! get_pool_params ( cmd , NULL , & lp - > passed_args ,
2013-10-04 17:32:23 +04:00
& lp - > thin_chunk_size_calc_policy ,
2013-03-06 14:58:09 +04:00
& lp - > chunk_size , & lp - > discards ,
2012-11-19 19:23:18 +04:00
& lp - > poolmetadatasize , & lp - > zero ) ) | |
2011-08-03 02:07:20 +04:00
! _read_mirror_params ( lp , cmd ) | |
2014-02-04 21:57:08 +04:00
! _read_raid_params ( lp , cmd ) | |
! _read_cache_pool_params ( lp , cmd ) )
2008-01-30 16:19:47 +03:00
return_0 ;
2001-11-12 22:28:50 +03:00
2013-05-31 13:02:52 +04:00
if ( lp - > snapshot & & ( lp - > extents | | lcp - > size ) ) {
if ( arg_sign_value ( cmd , chunksize_ARG , SIGN_NONE ) = = SIGN_MINUS ) {
log_error ( " Negative chunk size is invalid. " ) ;
return 0 ;
}
lp - > chunk_size = arg_uint_value ( cmd , chunksize_ARG , 8 ) ;
if ( lp - > chunk_size < 8 | | lp - > chunk_size > 1024 | |
( lp - > chunk_size & ( lp - > chunk_size - 1 ) ) ) {
log_error ( " Chunk size must be a power of 2 in the "
" range 4K to 512K. " ) ;
2012-11-19 15:47:34 +04:00
return 0 ;
2011-09-06 04:26:42 +04:00
}
2013-05-31 13:02:52 +04:00
log_verbose ( " Setting chunksize to %s. " , display_size ( cmd , lp - > chunk_size ) ) ;
if ( ! ( lp - > segtype = get_segtype_from_string ( cmd , " snapshot " ) ) )
return_0 ;
2014-01-22 20:30:55 +04:00
} else if ( ! lp - > create_pool & & arg_count ( cmd , chunksize_ARG ) ) {
2013-05-31 13:02:52 +04:00
log_error ( " --chunksize is only available with snapshots and thin pools. " ) ;
return 0 ;
2011-06-01 23:21:03 +04:00
}
2013-05-31 13:02:52 +04:00
2014-01-22 20:30:55 +04:00
if ( lp - > create_pool ) {
2013-06-25 15:34:31 +04:00
/* TODO: add lvm.conf default y|n */
lp - > poolmetadataspare = arg_int_value ( cmd , poolmetadataspare_ARG ,
DEFAULT_POOL_METADATA_SPARE ) ;
} else if ( arg_count ( cmd , poolmetadataspare_ARG ) ) {
log_error ( " --poolmetadataspare is only available with thin pool creation. " ) ;
return 0 ;
}
2002-02-15 14:53:22 +03:00
/*
2011-09-06 04:26:42 +04:00
* Allocation parameters
2002-02-15 14:53:22 +03:00
*/
2011-09-06 04:26:42 +04:00
contiguous = strcmp ( arg_str_value ( cmd , contiguous_ARG , " n " ) , " n " ) ;
2007-01-10 17:13:46 +03:00
2011-09-06 04:26:42 +04:00
lp - > alloc = contiguous ? ALLOC_CONTIGUOUS : ALLOC_INHERIT ;
2002-02-15 14:53:22 +03:00
2012-02-28 18:24:57 +04:00
lp - > alloc = ( alloc_policy_t ) arg_uint_value ( cmd , alloc_ARG , lp - > alloc ) ;
2002-02-15 14:53:22 +03:00
2011-09-06 04:26:42 +04:00
if ( contiguous & & ( lp - > alloc ! = ALLOC_CONTIGUOUS ) ) {
log_error ( " Conflicting contiguous and alloc arguments " ) ;
2008-09-24 20:32:51 +04:00
return 0 ;
2001-11-06 22:02:26 +03:00
}
2010-11-11 20:29:05 +03:00
dm_list_iterate_items ( current_group , & cmd - > arg_value_groups ) {
if ( ! grouped_arg_is_set ( current_group - > arg_values , addtag_ARG ) )
continue ;
if ( ! ( tag = grouped_arg_str_value ( current_group - > arg_values , addtag_ARG , NULL ) ) ) {
log_error ( " Failed to get tag " ) ;
return 0 ;
}
if ( ! str_list_add ( cmd - > mem , & lp - > tags , tag ) ) {
2011-09-06 04:26:42 +04:00
log_error ( " Unable to allocate memory for tag %s " , tag ) ;
2010-11-11 20:29:05 +03:00
return 0 ;
}
2011-09-06 04:26:42 +04:00
}
2009-07-26 06:30:57 +04:00
2009-07-26 06:32:50 +04:00
lcp - > pv_count = argc ;
lcp - > pvs = argv ;
2001-11-06 22:02:26 +03:00
2002-02-15 14:53:22 +03:00
return 1 ;
}
2011-09-06 04:26:42 +04:00
static int _check_thin_parameters ( struct volume_group * vg , struct lvcreate_params * lp ,
struct lvcreate_cmdline_params * lcp )
{
struct lv_list * lvl ;
2013-05-31 13:02:52 +04:00
unsigned i ;
2011-09-06 04:26:42 +04:00
2014-01-22 20:30:55 +04:00
if ( ! lp - > thin & & ! lp - > create_pool & & ! lp - > snapshot ) {
2011-09-06 04:26:42 +04:00
log_error ( " Please specify device size(s). " ) ;
return 0 ;
}
2013-04-02 16:53:58 +04:00
if ( lp - > thin & & lp - > snapshot ) {
2013-05-31 13:02:52 +04:00
log_error ( " Please either create snapshot or thin volume. " ) ;
2013-04-02 16:53:58 +04:00
return 0 ;
}
2014-01-22 20:30:55 +04:00
if ( ! lp - > create_pool ) {
2013-05-31 13:02:52 +04:00
static const int _argname [ ] = {
alloc_ARG ,
chunksize_ARG ,
contiguous_ARG ,
discards_ARG ,
poolmetadatasize_ARG ,
2013-06-25 15:34:31 +04:00
poolmetadataspare_ARG ,
2013-05-31 13:02:52 +04:00
stripes_ARG ,
stripesize_ARG ,
zero_ARG
} ;
2014-04-04 23:10:30 +04:00
for ( i = 0 ; i < DM_ARRAY_SIZE ( _argname ) ; + + i ) {
2013-05-31 13:02:52 +04:00
if ( arg_count ( vg - > cmd , _argname [ i ] ) ) {
log_error ( " %s is only available for thin pool creation. " ,
arg_long_option_name ( _argname [ i ] ) ) ;
return 0 ;
}
2011-09-06 04:26:42 +04:00
}
if ( lcp - > pv_count ) {
log_error ( " Only specify Physical volumes when allocating the thin pool. " ) ;
return 0 ;
}
2013-05-31 13:02:52 +04:00
if ( ! lp - > pool ) {
log_error ( " Please specify name of existing thin pool. " ) ;
2011-09-06 04:26:42 +04:00
return 0 ;
}
if ( ! ( lvl = find_lv_in_vg ( vg , lp - > pool ) ) ) {
2013-05-31 13:02:52 +04:00
log_error ( " Thin pool %s not found in Volume group %s. " , lp - > pool , vg - > name ) ;
2011-09-06 04:26:42 +04:00
return 0 ;
}
2013-05-31 13:02:52 +04:00
2011-09-06 23:25:42 +04:00
if ( ! lv_is_thin_pool ( lvl - > lv ) ) {
2011-09-06 04:26:42 +04:00
log_error ( " Logical volume %s is not a thin pool. " , lp - > pool ) ;
return 0 ;
}
2013-05-31 13:02:52 +04:00
} else if ( lp - > pool & & find_lv_in_vg ( vg , lp - > pool ) ) {
log_error ( " Thin pool %s already exists in Volume group %s. " , lp - > pool , vg - > name ) ;
2011-09-06 04:26:42 +04:00
return 0 ;
}
2013-04-02 16:53:58 +04:00
if ( ! lp - > thin & & ! lp - > snapshot ) {
if ( lp - > lv_name ) {
log_error ( " --name may only be given when creating a new thin Logical volume or snapshot. " ) ;
return 0 ;
}
2011-09-06 04:26:42 +04:00
if ( arg_count ( vg - > cmd , readahead_ARG ) ) {
log_error ( " --readhead may only be given when creating a new thin Logical volume or snapshot. " ) ;
return 0 ;
}
if ( arg_count ( vg - > cmd , permission_ARG ) ) {
log_error ( " --permission may only be given when creating a new thin Logical volume or snapshot. " ) ;
return 0 ;
}
if ( arg_count ( vg - > cmd , persistent_ARG ) ) {
log_error ( " --persistent may only be given when creating a new thin Logical volume or snapshot. " ) ;
return 0 ;
}
}
return 1 ;
}
RAID: Allow implicit stripe (and parity) when creating RAID LVs
There are typically 2 functions for the more advanced segment types that
deal with parameters in lvcreate.c: _get_*_params() and _check_*_params().
(Not all segment types name their functions according to this scheme.)
The former function is responsible for reading parameters before the VG
has been read. The latter is for sanity checking and possibly setting
parameters after the VG has been read.
This patch adds a _check_raid_parameters() function that will determine
if the user has specified 'stripe' or 'mirror' parameters. If not, the
proper number is computed from the list of PVs the user has supplied or
the number that are available in the VG. Now that _check_raid_parameters()
is available, we move the check for proper number of stripes from
_get_* to _check_*.
This gives the user the ability to create RAID LVs as follows:
# 5-device RAID5, 4-data, 1-parity (i.e. implicit '-i 4')
~> lvcreate --type raid5 -L 100G -n lv vg /dev/sd[abcde]1
# 5-device RAID6, 3-data, 2-parity (i.e. implicit '-i 3')
~> lvcreate --type raid6 -L 100G -n lv vg /dev/sd[abcde]1
# If 5 PVs in VG, 4-data, 1-parity RAID5
~> lvcreate --type raid5 -L 100G -n lv vg
Considerations:
This patch only affects RAID. It might also be useful to apply this to
the 'stripe' segment type. LVM RAID may include RAID0 at some point in
the future and the implicit stripes would apply there. It would be odd
to have RAID0 be able to auto-determine the stripe count while 'stripe'
could not.
The only draw-back of this patch that I can see is that there might be
less error checking. Rather than informing the user that they forgot
to supply an argument (e.g. '-i'), the value would be computed and it
may differ from what the user actually wanted. I don't see this as a
problem, because the user can check the device count after creation
and remove the LV if they have made an error.
2014-02-18 06:18:23 +04:00
static int _check_raid_parameters ( struct volume_group * vg ,
struct lvcreate_params * lp ,
struct lvcreate_cmdline_params * lcp )
{
2014-02-25 12:43:04 +04:00
unsigned devs = lcp - > pv_count ? : dm_list_size ( & vg - > pvs ) ;
RAID: Allow implicit stripe (and parity) when creating RAID LVs
There are typically 2 functions for the more advanced segment types that
deal with parameters in lvcreate.c: _get_*_params() and _check_*_params().
(Not all segment types name their functions according to this scheme.)
The former function is responsible for reading parameters before the VG
has been read. The latter is for sanity checking and possibly setting
parameters after the VG has been read.
This patch adds a _check_raid_parameters() function that will determine
if the user has specified 'stripe' or 'mirror' parameters. If not, the
proper number is computed from the list of PVs the user has supplied or
the number that are available in the VG. Now that _check_raid_parameters()
is available, we move the check for proper number of stripes from
_get_* to _check_*.
This gives the user the ability to create RAID LVs as follows:
# 5-device RAID5, 4-data, 1-parity (i.e. implicit '-i 4')
~> lvcreate --type raid5 -L 100G -n lv vg /dev/sd[abcde]1
# 5-device RAID6, 3-data, 2-parity (i.e. implicit '-i 3')
~> lvcreate --type raid6 -L 100G -n lv vg /dev/sd[abcde]1
# If 5 PVs in VG, 4-data, 1-parity RAID5
~> lvcreate --type raid5 -L 100G -n lv vg
Considerations:
This patch only affects RAID. It might also be useful to apply this to
the 'stripe' segment type. LVM RAID may include RAID0 at some point in
the future and the implicit stripes would apply there. It would be odd
to have RAID0 be able to auto-determine the stripe count while 'stripe'
could not.
The only draw-back of this patch that I can see is that there might be
less error checking. Rather than informing the user that they forgot
to supply an argument (e.g. '-i'), the value would be computed and it
may differ from what the user actually wanted. I don't see this as a
problem, because the user can check the device count after creation
and remove the LV if they have made an error.
2014-02-18 06:18:23 +04:00
struct cmd_context * cmd = vg - > cmd ;
/*
* If number of devices was not supplied , we can infer from
* the PVs given .
*/
if ( ! seg_is_mirrored ( lp ) ) {
if ( ! arg_count ( cmd , stripes_ARG ) & &
( devs > 2 * lp - > segtype - > parity_devs ) )
lp - > stripes = devs - lp - > segtype - > parity_devs ;
if ( ! lp - > stripe_size )
lp - > stripe_size = find_config_tree_int ( cmd , metadata_stripesize_CFG , NULL ) * 2 ;
if ( lp - > stripes < = lp - > segtype - > parity_devs ) {
log_error ( " Number of stripes must be at least %d for %s " ,
lp - > segtype - > parity_devs + 1 ,
lp - > segtype - > name ) ;
return 0 ;
}
} else if ( ! strcmp ( lp - > segtype - > name , " raid10 " ) ) {
if ( ! arg_count ( cmd , stripes_ARG ) )
lp - > stripes = devs / lp - > mirrors ;
if ( lp - > stripes < 2 ) {
log_error ( " Unable to create RAID10 LV, "
" insufficient number of devices. " ) ;
return 0 ;
}
}
/* 'mirrors' defaults to 2 - not the number of PVs supplied */
return 1 ;
}
2011-09-06 04:26:42 +04:00
/*
* Ensure the set of thin parameters extracted from the command line is consistent .
*/
static int _validate_internal_thin_processing ( const struct lvcreate_params * lp )
{
int r = 1 ;
/*
The final state should be one of :
2014-01-22 20:30:55 +04:00
thin create_pool snapshot origin pool
1 1 0 0 y / n - create new pool and a thin LV in it
1 0 0 0 y - create new thin LV in existing pool
0 1 0 0 y / n - create new pool only
1 0 1 1 y - create thin snapshot of existing thin LV
2011-09-06 04:26:42 +04:00
*/
2014-01-22 20:30:55 +04:00
if ( ! lp - > create_pool & & ! lp - > pool ) {
2011-09-06 04:26:42 +04:00
log_error ( INTERNAL_ERROR " --thinpool not identified. " ) ;
r = 0 ;
}
if ( ( lp - > snapshot & & ! lp - > origin ) | | ( ! lp - > snapshot & & lp - > origin ) ) {
log_error ( INTERNAL_ERROR " Inconsistent snapshot and origin parameters identified. " ) ;
r = 0 ;
}
2014-01-22 20:30:55 +04:00
if ( ! lp - > thin & & ! lp - > create_pool & & ! lp - > snapshot ) {
2011-09-06 04:26:42 +04:00
log_error ( INTERNAL_ERROR " Failed to identify what type of thin target to use. " ) ;
r = 0 ;
}
if ( seg_is_thin_pool ( lp ) & & lp - > thin ) {
log_error ( INTERNAL_ERROR " Thin volume cannot be created with thin pool segment type. " ) ;
r = 0 ;
}
return r ;
}
2002-02-15 14:53:22 +03:00
int lvcreate ( struct cmd_context * cmd , int argc , char * * argv )
{
2013-06-30 23:40:56 +04:00
int r = ECMD_FAILED ;
2002-02-15 14:53:22 +03:00
struct lvcreate_params lp ;
2009-07-26 06:31:41 +04:00
struct lvcreate_cmdline_params lcp ;
2007-11-15 05:20:03 +03:00
struct volume_group * vg ;
2002-02-15 14:53:22 +03:00
2009-07-26 06:31:41 +04:00
if ( ! _lvcreate_params ( & lp , & lcp , cmd , argc , argv ) )
2003-10-22 02:06:07 +04:00
return EINVALID_CMD_LINE ;
2002-02-15 14:53:22 +03:00
2007-11-15 05:20:03 +03:00
log_verbose ( " Finding volume group \" %s \" " , lp . vg_name ) ;
2009-07-01 20:59:37 +04:00
vg = vg_read_for_update ( cmd , lp . vg_name , NULL , 0 ) ;
2009-07-07 05:18:35 +04:00
if ( vg_read_error ( vg ) ) {
2011-08-11 00:25:29 +04:00
release_vg ( vg ) ;
2013-07-01 13:27:22 +04:00
return_ECMD_FAILED ;
2009-07-07 05:18:35 +04:00
}
2002-02-15 14:53:22 +03:00
2013-06-30 23:40:56 +04:00
if ( lp . snapshot & & lp . origin & & ! _determine_snapshot_type ( vg , & lp ) )
2011-09-06 04:26:42 +04:00
goto_out ;
2013-06-30 23:40:56 +04:00
if ( seg_is_thin ( & lp ) & & ! _check_thin_parameters ( vg , & lp , & lcp ) )
2011-09-06 04:26:42 +04:00
goto_out ;
2014-02-05 02:50:16 +04:00
if ( seg_is_cache ( & lp ) & & ! _determine_cache_argument ( vg , & lp ) )
goto_out ;
RAID: Allow implicit stripe (and parity) when creating RAID LVs
There are typically 2 functions for the more advanced segment types that
deal with parameters in lvcreate.c: _get_*_params() and _check_*_params().
(Not all segment types name their functions according to this scheme.)
The former function is responsible for reading parameters before the VG
has been read. The latter is for sanity checking and possibly setting
parameters after the VG has been read.
This patch adds a _check_raid_parameters() function that will determine
if the user has specified 'stripe' or 'mirror' parameters. If not, the
proper number is computed from the list of PVs the user has supplied or
the number that are available in the VG. Now that _check_raid_parameters()
is available, we move the check for proper number of stripes from
_get_* to _check_*.
This gives the user the ability to create RAID LVs as follows:
# 5-device RAID5, 4-data, 1-parity (i.e. implicit '-i 4')
~> lvcreate --type raid5 -L 100G -n lv vg /dev/sd[abcde]1
# 5-device RAID6, 3-data, 2-parity (i.e. implicit '-i 3')
~> lvcreate --type raid6 -L 100G -n lv vg /dev/sd[abcde]1
# If 5 PVs in VG, 4-data, 1-parity RAID5
~> lvcreate --type raid5 -L 100G -n lv vg
Considerations:
This patch only affects RAID. It might also be useful to apply this to
the 'stripe' segment type. LVM RAID may include RAID0 at some point in
the future and the implicit stripes would apply there. It would be odd
to have RAID0 be able to auto-determine the stripe count while 'stripe'
could not.
The only draw-back of this patch that I can see is that there might be
less error checking. Rather than informing the user that they forgot
to supply an argument (e.g. '-i'), the value would be computed and it
may differ from what the user actually wanted. I don't see this as a
problem, because the user can check the device count after creation
and remove the LV if they have made an error.
2014-02-18 06:18:23 +04:00
if ( seg_is_raid ( & lp ) & & ! _check_raid_parameters ( vg , & lp , & lcp ) )
goto_out ;
2011-11-10 16:40:29 +04:00
/*
* Check activation parameters to support inactive thin snapshot creation
* FIXME : anything else needs to be moved past _determine_snapshot_type ( ) ?
*/
2013-06-30 23:40:56 +04:00
if ( ! _read_activation_params ( & lp , cmd , vg ) )
2011-11-10 16:40:29 +04:00
goto_out ;
2013-06-30 23:40:56 +04:00
if ( ! _update_extents_params ( vg , & lp , & lcp ) )
2009-11-04 17:47:27 +03:00
goto_out ;
2009-07-26 06:31:18 +04:00
2013-06-30 23:40:56 +04:00
if ( seg_is_thin ( & lp ) & & ! _validate_internal_thin_processing ( & lp ) )
2011-09-06 04:26:42 +04:00
goto_out ;
2014-01-22 20:30:55 +04:00
if ( lp . create_pool ) {
2013-06-25 15:34:31 +04:00
if ( ! handle_pool_metadata_spare ( vg , lp . poolmetadataextents ,
lp . pvh , lp . poolmetadataspare ) )
goto_out ;
2011-09-06 04:26:42 +04:00
log_verbose ( " Making thin pool %s in VG %s using segtype %s " ,
lp . pool ? : " with generated name " , lp . vg_name , lp . segtype - > name ) ;
2013-06-25 15:34:31 +04:00
}
2011-09-06 04:26:42 +04:00
if ( lp . thin )
log_verbose ( " Making thin LV %s in pool %s in VG %s%s%s using segtype %s " ,
lp . lv_name ? : " with generated name " ,
2012-02-01 05:54:20 +04:00
lp . pool ? : " with generated name " , lp . vg_name ,
lp . snapshot ? " as snapshot of " : " " ,
2011-09-06 04:26:42 +04:00
lp . snapshot ? lp . origin : " " , lp . segtype - > name ) ;
2013-06-30 23:40:56 +04:00
if ( ! lv_create_single ( vg , & lp ) )
goto_out ;
r = ECMD_PROCESSED ;
2009-11-04 17:47:27 +03:00
out :
2011-08-11 00:25:29 +04:00
unlock_and_release_vg ( cmd , vg , lp . vg_name ) ;
2002-02-15 14:53:22 +03:00
return r ;
2001-11-06 22:02:26 +03:00
}