2005-06-06 21:12:08 +04:00
/*
2016-02-25 17:01:12 +03:00
* Copyright ( C ) 2005 - 2016 Red Hat , Inc . All rights reserved .
2005-06-06 21:12:08 +04:00
*
* This file is part of LVM2 .
*
* 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 .
2005-06-06 21:12:08 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2005-06-06 21:12:08 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2005-06-06 21:12:08 +04:00
*/
# include "tools.h"
2015-07-06 19:30:18 +03:00
2007-12-22 15:13:29 +03:00
# include "polldaemon.h"
2005-11-29 21:20:23 +03:00
# include "lv_alloc.h"
2015-03-12 18:23:19 +03:00
# include "lvconvert_poll.h"
2005-06-06 21:12:08 +04:00
2016-06-30 20:02:43 +03:00
/*
* Guidelines for mapping options to operations .
*
* There should be a clear and unique correspondence between an option
* name and the operation to be performed .
*
* An option with a given name should always perform the same operation .
* If the same operation applies to two types of LV , then the same option
* name can be used with both LV types . But , a given option name should
* not be used to perform different operations depending on the LV type it
* is used with .
*
* - - merge and - - split are examples where a single option name has been
* overloaded with different operations . The case of - - split has been
* corrected with the clear and unique variations - - splitcache ,
* - - splitsnapshot , - - splitmirror , which should allow - - split to be
* deprecated . ( The same is still needed for - - merge . )
*/
2005-06-06 21:12:08 +04:00
struct lvconvert_params {
2016-06-22 20:40:22 +03:00
/* Exactly one of these options is chosen */
int merge ; /* Either merge_snapshot or merge_mirror is also set */
2014-07-11 14:15:23 +04:00
int cache ;
2016-06-22 20:40:22 +03:00
int corelog ;
int mirrorlog ;
int mirrors_supplied ; /* When type_str is not set, this may be set with keep_mimages for --splitmirrors */
int repair ;
int replace ;
2006-04-06 00:43:23 +04:00
int snapshot ;
2014-10-04 17:32:24 +04:00
int split ;
int splitcache ;
2013-12-04 06:09:37 +04:00
int splitsnapshot ;
2013-03-11 15:40:05 +04:00
int thin ;
2014-10-04 17:32:24 +04:00
int uncache ;
2016-06-22 20:40:22 +03:00
const char * type_str ; /* When this is set, mirrors_supplied may optionally also be set */
const struct segment_type * segtype ;
int merge_snapshot ; /* merge is also set */
int merge_mirror ; /* merge is also set */
int poolmetadataspare ;
int force ;
2013-03-11 15:40:05 +04:00
int yes ;
2006-04-06 00:43:23 +04:00
int zero ;
2005-08-15 18:10:28 +04:00
const char * lv_name ;
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
const char * lv_split_name ;
2007-12-22 15:13:29 +03:00
const char * lv_name_full ;
2006-04-06 00:43:23 +04:00
const char * vg_name ;
2008-01-15 00:11:47 +03:00
int wait_completion ;
int need_polling ;
2006-04-06 00:43:23 +04:00
2013-10-04 17:32:23 +04:00
int thin_chunk_size_calc_policy ;
2006-04-06 00:43:23 +04:00
uint32_t chunk_size ;
uint32_t region_size ;
2005-08-15 18:10:28 +04:00
uint32_t mirrors ;
2005-11-29 21:20:23 +03:00
sign_t mirrors_sign ;
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
uint32_t keep_mimages ;
2010-04-13 05:54:32 +04:00
uint32_t stripes ;
uint32_t stripe_size ;
2012-11-19 16:37:57 +04:00
uint32_t read_ahead ;
2016-04-25 14:39:30 +03:00
cache_mode_t cache_mode ; /* cache */
2015-07-15 12:06:40 +03:00
const char * policy_name ; /* cache */
struct dm_config_tree * policy_settings ; /* cache */
2006-04-06 00:43:23 +04:00
2012-11-15 13:32:13 +04:00
unsigned target_attr ;
2005-08-15 18:10:28 +04:00
alloc_policy_t alloc ;
int pv_count ;
char * * pvs ;
2008-11-04 01:14:30 +03:00
struct dm_list * pvh ;
2010-01-13 04:49:52 +03:00
2011-11-30 06:02:10 +04:00
int replace_pv_count ;
char * * replace_pvs ;
struct dm_list * replace_pvh ;
2010-01-13 04:49:52 +03:00
struct logical_volume * lv_to_poll ;
2015-07-15 21:02:54 +03:00
struct dm_list idls ;
2012-05-09 16:17:06 +04:00
2014-10-30 15:04:06 +03:00
uint32_t pool_metadata_extents ;
2013-03-06 14:58:09 +04:00
int passed_args ;
2014-07-11 14:15:23 +04:00
uint64_t pool_metadata_size ;
2014-10-07 12:43:47 +04:00
const char * origin_name ;
const char * pool_data_name ;
2014-07-11 14:15:23 +04:00
struct logical_volume * pool_data_lv ;
2014-10-07 12:43:47 +04:00
const char * pool_metadata_name ;
2014-07-11 14:15:23 +04:00
struct logical_volume * pool_metadata_lv ;
2012-05-14 15:57:30 +04:00
thin_discards_t discards ;
2005-06-06 21:12:08 +04:00
} ;
2015-07-15 21:02:54 +03:00
struct convert_poll_id_list {
struct dm_list list ;
struct poll_operation_id * id ;
unsigned is_merging_origin : 1 ;
unsigned is_merging_origin_thin : 1 ;
} ;
2014-11-24 02:35:27 +03:00
static int _lvconvert_validate_names ( struct lvconvert_params * lp )
{
2016-02-23 14:18:48 +03:00
unsigned i , j ;
2014-11-24 02:35:27 +03:00
const char * names [ ] = {
( lp - > lv_name = = lp - > pool_data_name ) ? NULL : lp - > lv_name , " converted " ,
lp - > pool_data_name , " pool " ,
lp - > pool_metadata_name , " pool metadata " ,
lp - > origin_name , " origin " ,
} ;
for ( i = 0 ; i < DM_ARRAY_SIZE ( names ) ; i + = 2 )
if ( names [ i ] )
for ( j = i + 2 ; j < DM_ARRAY_SIZE ( names ) ; j + = 2 )
if ( names [ j ] & & ! strcmp ( names [ i ] , names [ j ] ) ) {
log_error ( " Can't use same name %s for %s and %s volume. " ,
names [ i ] , names [ i + 1 ] , names [ j + 1 ] ) ;
return 0 ;
}
return 1 ;
}
2006-04-19 19:33:07 +04:00
static int _lvconvert_name_params ( struct lvconvert_params * lp ,
struct cmd_context * cmd ,
int * pargc , char * * * pargv )
2006-04-06 00:43:23 +04:00
{
2014-08-13 16:19:13 +04:00
if ( lp - > merge ) {
2016-06-22 20:40:22 +03:00
/* FIXME Multiple arguments that mix snap and mirror? */
2014-08-13 16:19:13 +04:00
if ( ! * pargc ) {
log_error ( " Please specify a logical volume path. " ) ;
return 0 ;
}
2016-06-22 20:40:22 +03:00
if ( ! strstr ( ( * pargv ) [ 0 ] , " _rimage_ " ) ) { /* Snapshot */
if ( ! ( lp - > segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_SNAPSHOT ) ) )
return_0 ;
lp - > merge_snapshot = 1 ;
return 1 ;
}
/* Mirror */
lp - > merge_mirror = 1 ;
2014-08-13 16:19:13 +04:00
}
2010-02-06 01:44:37 +03:00
2014-07-11 14:15:23 +04:00
if ( ! * pargc ) {
if ( lp - > cache ) {
log_error ( " Logical volume name for caching is missing. " ) ;
return 0 ;
}
if ( lp - > thin ) {
2006-04-06 00:43:23 +04:00
log_error ( " Please specify a logical volume to act as "
2014-07-11 14:15:23 +04:00
" the external origin. " ) ;
2006-04-06 00:43:23 +04:00
return 0 ;
}
2014-07-11 14:15:23 +04:00
if ( lp - > snapshot ) {
log_error ( " Please specify a logical volume to act as "
" the snapshot exception store. " ) ;
2006-04-06 00:43:23 +04:00
return 0 ;
}
2014-10-04 17:32:24 +04:00
if ( lp - > split ) {
log_error ( " Logical volume for split is missing. " ) ;
return 0 ;
}
if ( lp - > splitcache ) {
log_error ( " Cache logical volume for split is missing. " ) ;
return 0 ;
}
if ( lp - > uncache ) {
log_error ( " Cache logical volume for uncache is missing. " ) ;
return 0 ;
}
2014-07-11 14:15:23 +04:00
if ( ! lp - > lv_name_full ) {
log_error ( " Please provide logical volume path. " ) ;
return 0 ;
2013-02-04 16:56:54 +04:00
}
2014-07-11 14:15:23 +04:00
} else if ( ! lp - > lv_name_full ) {
lp - > lv_name_full = ( * pargv ) [ 0 ] ;
( * pargv ) + + , ( * pargc ) - - ;
2013-02-05 14:26:27 +04:00
}
2013-02-04 16:56:54 +04:00
2014-10-08 13:14:33 +04:00
if ( ! validate_restricted_lvname_param ( cmd , & lp - > vg_name , & lp - > pool_metadata_name ) )
2014-07-11 14:15:23 +04:00
return_0 ;
2012-05-09 16:17:06 +04:00
2014-10-08 13:14:33 +04:00
if ( ! validate_restricted_lvname_param ( cmd , & lp - > vg_name , & lp - > pool_data_name ) )
2014-07-11 14:15:23 +04:00
return_0 ;
2006-04-06 00:43:23 +04:00
2014-10-08 13:14:33 +04:00
if ( ! validate_restricted_lvname_param ( cmd , & lp - > vg_name , & lp - > origin_name ) )
2014-07-11 14:15:23 +04:00
return_0 ;
2006-04-06 00:43:23 +04:00
2014-10-08 13:14:33 +04:00
if ( ! validate_restricted_lvname_param ( cmd , & lp - > vg_name , & lp - > lv_split_name ) )
2014-07-17 14:19:48 +04:00
return_0 ;
2016-03-08 12:13:38 +03:00
if ( ! lp - > vg_name & & ! strchr ( lp - > lv_name_full , ' / ' ) ) {
/* Check for $LVM_VG_NAME */
if ( ! ( lp - > vg_name = extract_vgname ( cmd , NULL ) ) ) {
log_error ( " Please specify a logical volume path. " ) ;
return 0 ;
}
2006-04-06 00:43:23 +04:00
}
2016-03-08 12:13:38 +03:00
if ( ! validate_lvname_param ( cmd , & lp - > vg_name , & lp - > lv_name_full ) )
return_0 ;
lp - > lv_name = lp - > lv_name_full ;
2006-04-06 00:43:23 +04:00
if ( ! validate_name ( lp - > vg_name ) ) {
log_error ( " Please provide a valid volume group name " ) ;
return 0 ;
}
2012-05-14 15:57:30 +04:00
if ( ! lp - > merge_mirror & &
2016-02-25 17:12:17 +03:00
! lp - > repair & &
2016-06-22 20:40:22 +03:00
! lp - > keep_mimages & &
2012-05-14 15:57:30 +04:00
! strstr ( lp - > lv_name , " _tdata " ) & &
! strstr ( lp - > lv_name , " _tmeta " ) & &
2015-11-19 15:30:55 +03:00
! strstr ( lp - > lv_name , " _cdata " ) & &
! strstr ( lp - > lv_name , " _cmeta " ) & &
2012-05-14 15:57:30 +04:00
! apply_lvname_restrictions ( lp - > lv_name ) )
2006-04-06 00:43:23 +04:00
return_0 ;
2014-07-11 14:15:23 +04:00
if ( * pargc ) {
if ( lp - > snapshot ) {
log_error ( " Too many arguments provided for snapshots. " ) ;
return 0 ;
}
if ( lp - > splitsnapshot ) {
log_error ( " Too many arguments provided with --splitsnapshot. " ) ;
return 0 ;
}
2014-10-04 17:32:24 +04:00
if ( lp - > splitcache ) {
log_error ( " Too many arguments provided with --splitcache. " ) ;
return 0 ;
}
if ( lp - > split ) {
log_error ( " Too many arguments provided with --split. " ) ;
return 0 ;
}
if ( lp - > uncache ) {
log_error ( " Too many arguments provided with --uncache. " ) ;
return 0 ;
}
2014-10-07 12:43:47 +04:00
if ( lp - > pool_data_name & & lp - > pool_metadata_name ) {
2014-07-11 14:15:23 +04:00
log_error ( " Too many arguments provided for pool. " ) ;
return 0 ;
}
2012-05-09 16:17:06 +04:00
}
2014-11-24 02:35:27 +03:00
if ( ! _lvconvert_validate_names ( lp ) )
return_0 ;
2006-04-06 00:43:23 +04:00
return 1 ;
}
2013-07-23 19:04:43 +04:00
static int _check_conversion_type ( struct cmd_context * cmd , const char * type_str )
{
if ( ! type_str | | ! * type_str )
return 1 ;
2015-12-03 17:40:14 +03:00
if ( ! strcmp ( type_str , " mirror " ) ) {
2016-06-22 00:24:52 +03:00
if ( ! arg_is_set ( cmd , mirrors_ARG ) ) {
2015-12-03 17:40:14 +03:00
log_error ( " Conversions to --type mirror require -m/--mirrors " ) ;
2013-07-23 19:04:43 +04:00
return 0 ;
}
return 1 ;
}
/* FIXME: Check thin-pool and thin more thoroughly! */
2016-07-02 00:20:54 +03:00
if ( ! strcmp ( type_str , " snapshot " ) | | ! strcmp ( type_str , " linear " ) | |
2016-06-22 20:40:22 +03:00
! strcmp ( type_str , " striped " ) | |
2014-02-12 19:51:42 +04:00
! strncmp ( type_str , " raid " , 4 ) | |
2014-02-19 19:26:03 +04:00
! strcmp ( type_str , " cache-pool " ) | | ! strcmp ( type_str , " cache " ) | |
2013-07-23 19:04:43 +04:00
! strcmp ( type_str , " thin-pool " ) | | ! strcmp ( type_str , " thin " ) )
return 1 ;
log_error ( " Conversion using --type %s is not supported. " , type_str ) ;
return 0 ;
}
/* -s/--snapshot and --type snapshot are synonyms */
2016-06-22 20:40:22 +03:00
static int _snapshot_type_requested ( struct cmd_context * cmd , const char * type_str )
{
2016-06-22 00:24:52 +03:00
return ( arg_is_set ( cmd , snapshot_ARG ) | | ! strcmp ( type_str , " snapshot " ) ) ;
2014-07-01 12:13:10 +04:00
}
2016-06-22 20:40:22 +03:00
static int _raid0_type_requested ( struct cmd_context * cmd , const char * type_str )
{
2016-07-02 00:20:54 +03:00
return ( ! strcmp ( type_str , " raid0 " ) | | ! strcmp ( type_str , " raid0_meta " ) ) ;
2016-06-22 20:40:22 +03:00
}
2013-07-23 19:04:43 +04:00
/* mirror/raid* (1,10,4,5,6 and their variants) reshape */
2016-06-22 20:40:22 +03:00
static int _mirror_or_raid_type_requested ( struct cmd_context * cmd , const char * type_str )
{
return ( arg_is_set ( cmd , mirrors_ARG ) | | ! strcmp ( type_str , " mirror " ) | |
( ! strncmp ( type_str , " raid " , 4 ) & & ! _raid0_type_requested ( cmd , type_str ) ) ) ;
}
static int _striped_type_requested ( struct cmd_context * cmd , const char * type_str )
{
2016-07-02 00:20:54 +03:00
return ( ! strcmp ( type_str , SEG_TYPE_NAME_STRIPED ) | | ! strcmp ( type_str , SEG_TYPE_NAME_LINEAR ) ) ;
}
static int _linear_type_requested ( const char * type_str )
{
return ( ! strcmp ( type_str , SEG_TYPE_NAME_LINEAR ) ) ;
2014-07-01 12:13:10 +04:00
}
2013-07-23 19:04:43 +04:00
2014-10-31 13:31:22 +03:00
static int _read_pool_params ( struct cmd_context * cmd , int * pargc , char * * * pargv ,
2016-06-22 20:40:22 +03:00
struct lvconvert_params * lp )
2014-07-11 14:15:23 +04:00
{
int cachepool = 0 ;
int thinpool = 0 ;
2014-10-07 12:43:47 +04:00
if ( ( lp - > pool_data_name = arg_str_value ( cmd , cachepool_ARG , NULL ) ) ) {
2016-06-22 20:40:22 +03:00
if ( lp - > type_str [ 0 ] & &
strcmp ( lp - > type_str , " cache " ) & &
strcmp ( lp - > type_str , " cache-pool " ) ) {
2014-07-11 14:15:23 +04:00
log_error ( " --cachepool argument is only valid with "
" the cache or cache-pool segment type. " ) ;
return 0 ;
}
cachepool = 1 ;
2016-06-22 20:40:22 +03:00
lp - > type_str = " cache-pool " ;
} else if ( ! strcmp ( lp - > type_str , " cache-pool " ) )
2014-07-11 14:15:23 +04:00
cachepool = 1 ;
2014-10-07 12:43:47 +04:00
else if ( ( lp - > pool_data_name = arg_str_value ( cmd , thinpool_ARG , NULL ) ) ) {
2016-06-22 20:40:22 +03:00
if ( lp - > type_str [ 0 ] & &
strcmp ( lp - > type_str , " thin " ) & &
strcmp ( lp - > type_str , " thin-pool " ) ) {
2014-07-11 14:15:23 +04:00
log_error ( " --thinpool argument is only valid with "
" the thin or thin-pool segment type. " ) ;
return 0 ;
}
thinpool = 1 ;
2016-06-22 20:40:22 +03:00
lp - > type_str = " thin-pool " ;
} else if ( ! strcmp ( lp - > type_str , " thin-pool " ) )
2014-07-11 14:15:23 +04:00
thinpool = 1 ;
2015-07-23 16:35:12 +03:00
if ( lp - > cache & & ! cachepool ) {
log_error ( " --cache requires --cachepool. " ) ;
return 0 ;
}
2016-07-12 12:05:34 +03:00
2015-07-23 16:35:12 +03:00
if ( ( lp - > cache | | cachepool ) & &
! get_cache_params ( cmd , & lp - > cache_mode , & lp - > policy_name , & lp - > policy_settings ) ) {
log_error ( " Failed to parse cache policy and/or settings. " ) ;
return 0 ;
2014-07-11 14:15:23 +04:00
}
2014-07-18 14:19:40 +04:00
if ( thinpool ) {
lp - > discards = ( thin_discards_t ) arg_uint_value ( cmd , discards_ARG , THIN_DISCARDS_PASSDOWN ) ;
2014-10-07 12:43:47 +04:00
lp - > origin_name = arg_str_value ( cmd , originname_ARG , NULL ) ;
2014-07-18 14:19:40 +04:00
} else {
if ( arg_from_list_is_set ( cmd , " is valid only with thin pools " ,
discards_ARG , originname_ARG , thinpool_ARG ,
zero_ARG , - 1 ) )
return_0 ;
if ( lp - > thin ) {
log_error ( " --thin requires --thinpool. " ) ;
return 0 ;
}
}
2014-07-11 14:15:23 +04:00
if ( thinpool | | cachepool ) {
2014-07-18 23:56:37 +04:00
if ( arg_from_list_is_set ( cmd , " is invalid with pools " ,
merge_ARG , mirrors_ARG , repair_ARG , snapshot_ARG ,
2014-07-23 00:20:18 +04:00
splitmirrors_ARG , splitsnapshot_ARG , - 1 ) )
2014-07-11 14:15:23 +04:00
return_0 ;
2016-06-22 20:40:22 +03:00
if ( ! ( lp - > segtype = get_segtype_from_string ( cmd , lp - > type_str ) ) )
2014-07-23 00:20:18 +04:00
return_0 ;
2014-07-11 14:15:23 +04:00
2014-07-23 00:20:18 +04:00
if ( ! get_pool_params ( cmd , lp - > segtype , & lp - > passed_args ,
& lp - > pool_metadata_size ,
& lp - > poolmetadataspare ,
& lp - > chunk_size , & lp - > discards ,
& lp - > zero ) )
return_0 ;
2014-07-11 14:15:23 +04:00
2014-10-07 12:43:47 +04:00
if ( ( lp - > pool_metadata_name = arg_str_value ( cmd , poolmetadata_ARG , NULL ) ) & &
2014-07-23 00:20:18 +04:00
arg_from_list_is_set ( cmd , " is invalid with --poolmetadata " ,
stripesize_ARG , stripes_long_ARG ,
readahead_ARG , - 1 ) )
return_0 ;
2014-07-11 14:15:23 +04:00
2014-10-07 12:43:47 +04:00
if ( ! lp - > pool_data_name ) {
2014-07-11 14:15:23 +04:00
if ( ! * pargc ) {
log_error ( " Please specify the pool data LV. " ) ;
return 0 ;
}
2014-10-07 12:43:47 +04:00
lp - > pool_data_name = ( * pargv ) [ 0 ] ;
2014-07-18 14:19:40 +04:00
( * pargv ) + + , ( * pargc ) - - ;
2014-07-11 14:15:23 +04:00
}
if ( ! lp - > thin & & ! lp - > cache )
2014-10-07 12:43:47 +04:00
lp - > lv_name_full = lp - > pool_data_name ;
2014-07-23 00:20:18 +04:00
2014-07-11 14:15:23 +04:00
/* Hmm _read_activation_params */
lp - > read_ahead = arg_uint_value ( cmd , readahead_ARG ,
cmd - > default_settings . read_ahead ) ;
2014-07-18 23:56:37 +04:00
} else if ( arg_from_list_is_set ( cmd , " is valid only with pools " ,
poolmetadatasize_ARG , poolmetadataspare_ARG ,
- 1 ) )
2014-07-11 14:15:23 +04:00
return_0 ;
return 1 ;
}
2014-10-31 13:31:22 +03:00
static int _read_params ( struct cmd_context * cmd , int argc , char * * argv ,
struct lvconvert_params * lp )
2005-08-15 18:10:28 +04:00
{
2011-11-30 06:02:10 +04:00
int i ;
const char * tmp_str ;
struct arg_value_group_list * group ;
2006-04-28 19:01:39 +04:00
int region_size ;
2006-08-17 22:23:44 +04:00
int pagesize = lvm_getpagesize ( ) ;
2006-04-28 19:01:39 +04:00
2016-06-22 20:40:22 +03:00
lp - > type_str = arg_str_value ( cmd , type_ARG , " " ) ;
if ( arg_is_set ( cmd , type_ARG ) & & ! _check_conversion_type ( cmd , lp - > type_str ) )
2013-07-23 19:04:43 +04:00
return_0 ;
2016-06-22 20:40:22 +03:00
/* If --repair, check for incompatible args. */
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , repair_ARG ) ) {
2016-02-25 17:12:17 +03:00
if ( arg_outside_list_is_set ( cmd , " cannot be used with --repair " ,
repair_ARG ,
alloc_ARG , usepolicies_ARG ,
stripes_long_ARG , stripesize_ARG ,
force_ARG , noudevsync_ARG , test_ARG ,
- 1 ) )
return_0 ;
lp - > repair = 1 ;
}
2014-07-11 00:02:54 +04:00
2016-06-22 20:40:22 +03:00
if ( arg_is_set ( cmd , mirrorlog_ARG ) )
lp - > mirrorlog = 1 ;
if ( arg_is_set ( cmd , corelog_ARG ) )
lp - > corelog = 1 ;
if ( lp - > mirrorlog & & lp - > corelog ) {
2014-07-11 00:02:54 +04:00
log_error ( " --mirrorlog and --corelog are incompatible. " ) ;
return 0 ;
}
2014-10-04 17:32:24 +04:00
if ( arg_is_set ( cmd , split_ARG ) ) {
if ( arg_outside_list_is_set ( cmd , " cannot be used with --split " ,
split_ARG ,
2016-03-07 12:30:21 +03:00
name_ARG ,
2014-10-04 17:32:24 +04:00
force_ARG , noudevsync_ARG , test_ARG ,
- 1 ) )
return_0 ;
lp - > split = 1 ;
}
if ( arg_is_set ( cmd , splitcache_ARG ) ) {
if ( arg_outside_list_is_set ( cmd , " cannot be used with --splitcache " ,
splitcache_ARG ,
force_ARG , noudevsync_ARG , test_ARG ,
- 1 ) )
return_0 ;
lp - > splitcache = 1 ;
}
2016-03-07 12:30:21 +03:00
if ( arg_is_set ( cmd , splitsnapshot_ARG ) ) {
if ( arg_outside_list_is_set ( cmd , " cannot be used with --splitsnapshot " ,
splitsnapshot_ARG ,
force_ARG , noudevsync_ARG , test_ARG ,
- 1 ) )
return_0 ;
lp - > splitsnapshot = 1 ;
}
2014-10-04 17:32:24 +04:00
if ( arg_is_set ( cmd , uncache_ARG ) ) {
if ( arg_outside_list_is_set ( cmd , " cannot be used with --uncache " ,
uncache_ARG ,
force_ARG , noudevsync_ARG , test_ARG ,
- 1 ) )
return_0 ;
lp - > uncache = 1 ;
}
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , cache_ARG ) )
2014-07-11 14:15:23 +04:00
lp - > cache = 1 ;
2010-01-13 04:45:15 +03:00
2016-06-22 20:40:22 +03:00
if ( ! strcmp ( lp - > type_str , " cache " ) )
2014-07-11 14:15:23 +04:00
lp - > cache = 1 ;
else if ( lp - > cache ) {
2016-06-22 20:40:22 +03:00
if ( lp - > type_str [ 0 ] ) {
log_error ( " --cache is incompatible with --type %s " , lp - > type_str ) ;
2014-07-11 14:15:23 +04:00
return 0 ;
}
2016-06-22 20:40:22 +03:00
lp - > type_str = " cache " ;
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
}
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , thin_ARG ) )
2013-03-11 15:40:05 +04:00
lp - > thin = 1 ;
2016-06-22 20:40:22 +03:00
if ( ! strcmp ( lp - > type_str , " thin " ) )
2014-07-11 14:15:23 +04:00
lp - > thin = 1 ;
else if ( lp - > thin ) {
2016-06-22 20:40:22 +03:00
if ( lp - > type_str [ 0 ] ) {
log_error ( " --thin is incompatible with --type %s " , lp - > type_str ) ;
2014-02-12 19:55:35 +04:00
return 0 ;
}
2016-06-22 20:40:22 +03:00
lp - > type_str = " thin " ;
2014-07-11 14:15:23 +04:00
}
2016-06-22 20:40:22 +03:00
/* May set lp->segtype */
if ( ! _read_pool_params ( cmd , & argc , & argv , lp ) )
2014-07-11 14:15:23 +04:00
return_0 ;
2016-06-22 00:24:52 +03:00
if ( ! arg_is_set ( cmd , background_ARG ) )
2014-07-11 14:15:23 +04:00
lp - > wait_completion = 1 ;
2016-06-22 20:40:22 +03:00
if ( _snapshot_type_requested ( cmd , lp - > type_str ) ) {
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , merge_ARG ) ) {
2014-07-11 14:15:23 +04:00
log_error ( " --snapshot and --merge are mutually exclusive. " ) ;
2012-05-09 16:17:06 +04:00
return 0 ;
}
2014-07-11 14:15:23 +04:00
lp - > snapshot = 1 ;
2012-05-09 16:17:06 +04:00
}
2014-10-04 17:32:24 +04:00
if ( lp - > split ) {
lp - > lv_split_name = arg_str_value ( cmd , name_ARG , NULL ) ;
2016-06-22 20:40:22 +03:00
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
/*
* The ' - - splitmirrors n ' argument is equivalent to ' - - mirrors - n '
* ( note the minus sign ) , except that it signifies the additional
* intent to keep the mimage that is detached , rather than
* discarding it .
*/
2016-06-22 00:24:52 +03:00
} else if ( arg_is_set ( cmd , splitmirrors_ARG ) ) {
2016-06-22 20:40:22 +03:00
if ( _mirror_or_raid_type_requested ( cmd , lp - > type_str ) ) {
2014-07-11 14:15:23 +04:00
log_error ( " --mirrors/--type mirror/--type raid* and --splitmirrors are "
" mutually exclusive. " ) ;
return 0 ;
}
2016-06-22 00:24:52 +03:00
if ( ! arg_is_set ( cmd , name_ARG ) & &
! arg_is_set ( cmd , trackchanges_ARG ) ) {
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
log_error ( " Please name the new logical volume using '--name' " ) ;
return 0 ;
}
2014-07-17 14:19:48 +04:00
lp - > lv_split_name = arg_str_value ( cmd , name_ARG , NULL ) ;
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
lp - > keep_mimages = 1 ;
lp - > mirrors = arg_uint_value ( cmd , splitmirrors_ARG , 0 ) ;
lp - > mirrors_sign = SIGN_MINUS ;
2016-06-22 00:24:52 +03:00
} else if ( arg_is_set ( cmd , name_ARG ) ) {
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
log_error ( " The 'name' argument is only valid "
" with --splitmirrors " ) ;
return 0 ;
}
2016-06-22 20:40:22 +03:00
if ( arg_is_set ( cmd , merge_ARG ) )
lp - > merge = 1 ;
if ( arg_is_set ( cmd , replace_ARG ) )
lp - > replace = 1 ;
/* If no other case was identified, then use of --stripes means --type striped */
2016-06-23 00:10:42 +03:00
if ( ! arg_is_set ( cmd , type_ARG ) & & ! * lp - > type_str & & ! lp - > merge & & ! lp - > splitsnapshot & &
2016-06-22 20:40:22 +03:00
! lp - > splitcache & & ! lp - > split & & ! lp - > snapshot & & ! lp - > uncache & & ! lp - > cache & & ! lp - > thin & &
2016-06-23 00:10:42 +03:00
! lp - > replace & & ! lp - > repair & & ! lp - > mirrorlog & & ! lp - > corelog & &
2016-06-22 20:40:22 +03:00
( arg_is_set ( cmd , stripes_long_ARG ) | | arg_is_set ( cmd , stripesize_ARG ) ) )
lp - > type_str = " striped " ;
if ( ( _snapshot_type_requested ( cmd , lp - > type_str ) | | lp - > merge ) & &
( lp - > mirrorlog | | _mirror_or_raid_type_requested ( cmd , lp - > type_str ) | |
lp - > repair | | arg_is_set ( cmd , thinpool_ARG ) | | _raid0_type_requested ( cmd , lp - > type_str ) | |
_striped_type_requested ( cmd , lp - > type_str ) ) ) {
log_error ( " --snapshot/--type snapshot or --merge argument "
2016-07-02 00:20:54 +03:00
" cannot be mixed with --mirrors/--type mirror/--type raid*/--stripes/--type striped/--type linear, "
2016-06-22 20:40:22 +03:00
" --mirrorlog, --repair or --thinpool. " ) ;
return 0 ;
}
if ( ( arg_is_set ( cmd , stripes_long_ARG ) | | arg_is_set ( cmd , stripesize_ARG ) ) & &
! ( _mirror_or_raid_type_requested ( cmd , lp - > type_str ) | | _striped_type_requested ( cmd , lp - > type_str ) | |
_raid0_type_requested ( cmd , lp - > type_str ) | | lp - > repair | | arg_is_set ( cmd , thinpool_ARG ) ) ) {
log_error ( " --stripes or --stripesize argument is only valid "
2016-07-02 00:20:54 +03:00
" with --mirrors/--type mirror/--type raid*/--type striped/--type linear, --repair and --thinpool " ) ;
2016-06-22 20:40:22 +03:00
return 0 ;
2011-08-18 23:43:08 +04:00
}
2010-01-13 04:45:15 +03:00
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , mirrors_ARG ) ) {
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
/*
2016-06-22 20:40:22 +03:00
* - - splitmirrors is the mechanism for detaching and keeping a mimage
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
*/
2016-06-22 20:40:22 +03:00
lp - > mirrors_supplied = 1 ;
2006-04-06 00:43:23 +04:00
lp - > mirrors = arg_uint_value ( cmd , mirrors_ARG , 0 ) ;
2012-02-28 18:24:57 +04:00
lp - > mirrors_sign = arg_sign_value ( cmd , mirrors_ARG , SIGN_NONE ) ;
2006-04-06 00:43:23 +04:00
}
2012-03-02 01:14:43 +04:00
lp - > alloc = ( alloc_policy_t ) arg_uint_value ( cmd , alloc_ARG , ALLOC_INHERIT ) ;
2005-08-15 18:10:28 +04:00
2016-06-22 20:40:22 +03:00
/*
* Final checking of each case :
* lp - > merge
* lp - > splitsnapshot
* lp - > splitcache
* lp - > split
* lp - > uncache
* lp - > cache
* lp - > thin
* lp - > snapshot
* lp - > replace
* - - type mirror | raid lp - > repair lp - > mirrorlog lp - > corelog
* - - type raid0 | striped
*/
if ( lp - > merge ) { /* Snapshot or mirror merge */
2014-07-18 23:56:37 +04:00
if ( arg_outside_list_is_set ( cmd , " cannot be used with --merge " ,
merge_ARG ,
background_ARG , interval_ARG ,
force_ARG , noudevsync_ARG , test_ARG ,
- 1 ) )
2014-07-17 17:38:13 +04:00
return_0 ;
2013-12-04 06:09:37 +04:00
} else if ( lp - > splitsnapshot ) /* Destroy snapshot retaining cow as separate LV */
;
2016-07-12 12:05:34 +03:00
else if ( lp - > splitcache )
2016-06-22 20:40:22 +03:00
;
2016-07-12 12:05:34 +03:00
else if ( lp - > split )
2016-06-22 20:40:22 +03:00
;
2016-07-12 12:05:34 +03:00
else if ( lp - > uncache )
2016-06-22 20:40:22 +03:00
;
2016-07-12 12:05:34 +03:00
else if ( lp - > cache )
2016-06-22 20:40:22 +03:00
;
2016-07-12 12:05:34 +03:00
else if ( lp - > thin )
2016-06-22 20:40:22 +03:00
;
else if ( lp - > keep_mimages ) /* --splitmirrors */
;
2013-12-04 06:09:37 +04:00
else if ( lp - > snapshot ) { /* Snapshot creation from pre-existing cow */
2014-07-11 14:15:23 +04:00
if ( ! argc ) {
2014-07-17 16:46:38 +04:00
log_error ( " Please provide logical volume path for snapshot origin. " ) ;
2014-07-11 14:15:23 +04:00
return 0 ;
}
2014-10-07 12:43:47 +04:00
lp - > origin_name = argv [ 0 ] ;
2014-07-11 14:15:23 +04:00
argv + + , argc - - ;
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , regionsize_ARG ) ) {
2006-04-06 00:43:23 +04:00
log_error ( " --regionsize is only available with mirrors " ) ;
return 0 ;
}
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , stripesize_ARG ) | | arg_is_set ( cmd , stripes_long_ARG ) ) {
2010-04-13 05:54:32 +04:00
log_error ( " --stripes and --stripesize are only available with striped mirrors " ) ;
return 0 ;
}
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , chunksize_ARG ) & &
2014-07-08 00:40:36 +04:00
( arg_sign_value ( cmd , chunksize_ARG , SIGN_NONE ) = = SIGN_MINUS ) ) {
log_error ( " Negative chunk size is invalid. " ) ;
2006-04-06 00:43:23 +04:00
return 0 ;
}
2014-07-08 00:40:36 +04:00
2007-11-14 03:08:25 +03:00
lp - > chunk_size = arg_uint_value ( cmd , chunksize_ARG , 8 ) ;
2006-04-06 00:43:23 +04:00
if ( lp - > chunk_size < 8 | | lp - > chunk_size > 1024 | |
2016-06-30 19:59:44 +03:00
! is_power_of_2 ( lp - > chunk_size ) ) {
2006-04-06 00:43:23 +04:00
log_error ( " Chunk size must be a power of 2 in the "
" range 4K to 512K " ) ;
return 0 ;
}
2014-07-01 13:03:31 +04:00
log_verbose ( " Setting chunk size to %s. " , display_size ( cmd , lp - > chunk_size ) ) ;
2005-08-15 18:10:28 +04:00
2015-09-22 21:04:12 +03:00
if ( ! ( lp - > segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_SNAPSHOT ) ) )
2006-04-06 00:43:23 +04:00
return_0 ;
2005-11-29 21:20:23 +03:00
2014-10-11 20:17:46 +04:00
lp - > zero = ( lp - > segtype - > flags & SEG_CANNOT_BE_ZEROED )
? 0 : arg_int_value ( cmd , zero_ARG , 1 ) ;
2006-04-06 00:43:23 +04:00
2016-06-22 20:40:22 +03:00
} else if ( lp - > replace ) { /* RAID device replacement */
2011-11-30 06:02:10 +04:00
lp - > replace_pv_count = arg_count ( cmd , replace_ARG ) ;
lp - > replace_pvs = dm_pool_alloc ( cmd - > mem , sizeof ( char * ) * lp - > replace_pv_count ) ;
if ( ! lp - > replace_pvs )
return_0 ;
i = 0 ;
dm_list_iterate_items ( group , & cmd - > arg_value_groups ) {
if ( ! grouped_arg_is_set ( group - > arg_values , replace_ARG ) )
continue ;
if ( ! ( tmp_str = grouped_arg_str_value ( group - > arg_values ,
replace_ARG ,
NULL ) ) ) {
log_error ( " Failed to get '--replace' argument " ) ;
return 0 ;
}
if ( ! ( lp - > replace_pvs [ i + + ] = dm_pool_strdup ( cmd - > mem ,
tmp_str ) ) )
return_0 ;
}
2016-06-22 20:40:22 +03:00
} else if ( _mirror_or_raid_type_requested ( cmd , lp - > type_str ) | |
lp - > repair | | lp - > mirrorlog | | lp - > corelog ) { /* Mirrors (and some RAID functions) */
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , chunksize_ARG ) ) {
2014-07-08 00:40:36 +04:00
log_error ( " --chunksize is only available with snapshots or pools. " ) ;
2005-11-29 21:20:23 +03:00
return 0 ;
}
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , zero_ARG ) ) {
2012-05-14 15:57:30 +04:00
log_error ( " --zero is only available with snapshots or thin pools. " ) ;
2006-04-06 00:43:23 +04:00
return 0 ;
}
/*
2014-07-11 14:25:18 +04:00
* - - regionsize is only valid if converting an LV into a mirror .
* Checked when we know the state of the LV being converted .
*/
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , regionsize_ARG ) ) {
2012-02-28 18:24:57 +04:00
if ( arg_sign_value ( cmd , regionsize_ARG , SIGN_NONE ) = =
2006-04-06 00:43:23 +04:00
SIGN_MINUS ) {
2016-07-12 12:05:34 +03:00
log_error ( " Negative regionsize is invalid. " ) ;
2006-04-06 00:43:23 +04:00
return 0 ;
}
2007-11-14 03:08:25 +03:00
lp - > region_size = arg_uint_value ( cmd , regionsize_ARG , 0 ) ;
2006-04-28 19:01:39 +04:00
} else {
2013-02-21 00:40:17 +04:00
region_size = get_default_region_size ( cmd ) ;
2006-04-28 19:01:39 +04:00
if ( region_size < 0 ) {
log_error ( " Negative regionsize in "
2016-07-12 12:05:34 +03:00
" configuration file is invalid. " ) ;
2006-04-28 19:01:39 +04:00
return 0 ;
}
lp - > region_size = region_size ;
}
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 "
2016-07-12 12:05:34 +03:00
" page size (%d). " ,
2006-04-28 21:25:54 +04:00
lp - > region_size , pagesize > > SECTOR_SHIFT ) ;
return 0 ;
}
2016-06-30 19:59:44 +03:00
if ( ! is_power_of_2 ( lp - > region_size ) ) {
2006-04-06 00:43:23 +04:00
log_error ( " Region size (% " PRIu32
2016-07-12 12:05:34 +03:00
" ) must be a power of 2. " , lp - > region_size ) ;
2006-04-06 00:43:23 +04:00
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 ;
}
2010-04-13 05:54:32 +04:00
/* Default is never striped, regardless of existing LV configuration. */
2013-07-01 13:27:11 +04:00
if ( ! get_stripe_params ( cmd , & lp - > stripes , & lp - > stripe_size ) )
return_0 ;
2010-04-13 05:54:32 +04:00
2016-06-22 20:40:22 +03:00
/* FIXME man page says in one place that --type and --mirrors can't be mixed */
if ( lp - > mirrors_supplied & & ! lp - > mirrors ) {
2013-08-08 01:01:45 +04:00
/* down-converting to linear/stripe? */
if ( ! ( lp - > segtype =
2015-09-22 21:04:12 +03:00
get_segtype_from_string ( cmd , SEG_TYPE_NAME_STRIPED ) ) )
2013-08-08 01:01:45 +04:00
return_0 ;
2016-06-22 00:24:52 +03:00
} else if ( arg_is_set ( cmd , type_ARG ) ) {
2013-08-08 01:01:45 +04:00
/* changing mirror type? */
if ( ! ( lp - > segtype = get_segtype_from_string ( cmd , arg_str_value ( cmd , type_ARG , find_config_tree_str ( cmd , global_mirror_segtype_default_CFG , NULL ) ) ) ) )
return_0 ;
2016-07-12 12:05:34 +03:00
}
2016-07-02 00:20:54 +03:00
} else if ( _raid0_type_requested ( cmd , lp - > type_str ) | | _striped_type_requested ( cmd , lp - > type_str ) ) { /* striped or linear or raid0 */
if ( arg_from_list_is_set ( cmd , " cannot be used with --type raid0 or --type striped or --type linear " ,
2016-06-22 20:40:22 +03:00
chunksize_ARG , corelog_ARG , mirrors_ARG , mirrorlog_ARG , regionsize_ARG , zero_ARG ,
- 1 ) )
return_0 ;
if ( ! get_stripe_params ( cmd , & lp - > stripes , & lp - > stripe_size ) )
return_0 ;
2016-07-02 00:20:54 +03:00
/* FIXME Shouldn't need to override get_stripe_params which defaults to 1 stripe (i.e. linear)! */
/* The default keeps existing number of stripes, handled inside the library code */
if ( ! arg_is_set ( cmd , stripes_long_ARG ) & & ! _linear_type_requested ( lp - > type_str ) )
lp - > stripes = 0 ;
2016-06-22 20:40:22 +03:00
if ( ! ( lp - > segtype = get_segtype_from_string ( cmd , lp - > type_str ) ) )
return_0 ;
2016-06-23 00:10:42 +03:00
} /* else segtype will default to current type */
2005-08-15 18:10:28 +04:00
2013-03-11 15:40:05 +04:00
lp - > force = arg_count ( cmd , force_ARG ) ;
lp - > yes = arg_count ( cmd , yes_ARG ) ;
2011-11-30 06:02:10 +04:00
if ( activation ( ) & & lp - > segtype & & lp - > segtype - > ops - > target_present & &
2012-11-15 13:32:13 +04:00
! lp - > segtype - > ops - > target_present ( cmd , NULL , & lp - > target_attr ) ) {
2006-04-06 00:43:23 +04:00
log_error ( " %s: Required device-mapper target(s) not "
2016-07-12 12:05:34 +03:00
" detected in your kernel. " , lp - > segtype - > name ) ;
2005-08-15 18:10:28 +04:00
return 0 ;
}
2006-04-19 19:33:07 +04:00
if ( ! _lvconvert_name_params ( lp , cmd , & argc , & argv ) )
2006-04-06 00:43:23 +04:00
return_0 ;
2005-08-15 18:10:28 +04:00
lp - > pv_count = argc ;
lp - > pvs = argv ;
return 1 ;
}
2007-12-22 15:13:29 +03:00
static struct poll_functions _lvconvert_mirror_fns = {
2009-09-30 22:15:06 +04:00
. poll_progress = poll_mirror_progress ,
2015-03-12 18:23:19 +03:00
. finish_copy = lvconvert_mirror_finish ,
2007-12-22 15:13:29 +03:00
} ;
2010-01-13 04:49:52 +03:00
static struct poll_functions _lvconvert_merge_fns = {
2015-03-12 18:23:19 +03:00
. poll_progress = poll_merge_progress ,
. finish_copy = lvconvert_merge_finish ,
2010-01-13 04:49:52 +03:00
} ;
2013-11-30 00:28:18 +04:00
static struct poll_functions _lvconvert_thin_merge_fns = {
2015-03-12 18:23:19 +03:00
. poll_progress = poll_thin_merge_progress ,
. finish_copy = lvconvert_merge_finish ,
2013-11-30 00:28:18 +04:00
} ;
2015-04-10 15:08:19 +03:00
static struct poll_operation_id * _create_id ( struct cmd_context * cmd ,
const char * vg_name ,
const char * lv_name ,
const char * uuid )
{
2016-02-25 15:31:31 +03:00
struct poll_operation_id * id ;
2015-04-10 15:08:19 +03:00
char lv_full_name [ NAME_LEN ] ;
2016-02-25 15:31:31 +03:00
if ( ! vg_name | | ! lv_name | | ! uuid ) {
log_error ( INTERNAL_ERROR " Wrong params for lvconvert _create_id. " ) ;
2015-04-10 15:08:19 +03:00
return NULL ;
}
if ( dm_snprintf ( lv_full_name , sizeof ( lv_full_name ) , " %s/%s " , vg_name , lv_name ) < 0 ) {
log_error ( INTERNAL_ERROR " Name \" %s/%s \" is too long. " , vg_name , lv_name ) ;
return NULL ;
}
2016-02-25 15:31:31 +03:00
if ( ! ( id = dm_pool_alloc ( cmd - > mem , sizeof ( * id ) ) ) ) {
log_error ( " Poll operation ID allocation failed. " ) ;
return NULL ;
}
2015-04-10 15:08:19 +03:00
2016-02-25 15:31:31 +03:00
if ( ! ( id - > display_name = dm_pool_strdup ( cmd - > mem , lv_full_name ) ) | |
! ( id - > lv_name = strchr ( id - > display_name , ' / ' ) ) | |
! ( id - > vg_name = dm_pool_strdup ( cmd - > mem , vg_name ) ) | |
! ( id - > uuid = dm_pool_strdup ( cmd - > mem , uuid ) ) ) {
2015-04-10 15:08:19 +03:00
log_error ( " Failed to copy one or more poll operation ID members. " ) ;
2016-02-25 15:31:31 +03:00
dm_pool_free ( cmd - > mem , id ) ;
return NULL ;
2015-04-10 15:08:19 +03:00
}
2016-02-25 15:31:31 +03:00
id - > lv_name + + ; /* skip over '/' */
2015-04-10 15:08:19 +03:00
return id ;
}
2015-07-15 21:02:54 +03:00
static int _lvconvert_poll_by_id ( struct cmd_context * cmd , struct poll_operation_id * id ,
unsigned background ,
int is_merging_origin ,
int is_merging_origin_thin )
{
2015-09-02 17:53:23 +03:00
if ( test_mode ( ) )
return ECMD_PROCESSED ;
2015-07-15 21:02:54 +03:00
if ( is_merging_origin )
return poll_daemon ( cmd , background ,
( MERGING | ( is_merging_origin_thin ? THIN_VOLUME : SNAPSHOT ) ) ,
is_merging_origin_thin ? & _lvconvert_thin_merge_fns : & _lvconvert_merge_fns ,
" Merged " , id ) ;
else
return poll_daemon ( cmd , background , CONVERTING ,
& _lvconvert_mirror_fns , " Converted " , id ) ;
}
2009-06-01 18:43:27 +04:00
int lvconvert_poll ( struct cmd_context * cmd , struct logical_volume * lv ,
2008-01-10 21:35:51 +03:00
unsigned background )
2007-12-22 15:13:29 +03:00
{
2015-07-15 21:02:54 +03:00
int r ;
2015-04-10 15:08:19 +03:00
struct poll_operation_id * id = _create_id ( cmd , lv - > vg - > name , lv - > name , lv - > lvid . s ) ;
2015-07-15 21:02:54 +03:00
int is_merging_origin = 0 ;
int is_merging_origin_thin = 0 ;
2009-06-01 18:43:27 +04:00
2015-04-10 15:08:19 +03:00
if ( ! id ) {
log_error ( " Failed to allocate poll identifier for lvconvert. " ) ;
2014-07-11 14:24:32 +04:00
return ECMD_FAILED ;
2014-06-16 14:39:32 +04:00
}
2009-06-01 18:43:27 +04:00
2015-07-15 21:02:54 +03:00
/* FIXME: check this in polling instead */
2015-05-05 16:11:50 +03:00
if ( lv_is_merging_origin ( lv ) ) {
2015-07-15 21:02:54 +03:00
is_merging_origin = 1 ;
is_merging_origin_thin = seg_is_thin_volume ( find_snapshot ( lv ) ) ;
}
r = _lvconvert_poll_by_id ( cmd , id , background , is_merging_origin , is_merging_origin_thin ) ;
2015-04-10 15:08:19 +03:00
2015-05-05 16:11:50 +03:00
return r ;
2007-12-22 15:13:29 +03:00
}
2007-12-22 05:13:00 +03:00
static int _insert_lvconvert_layer ( struct cmd_context * cmd ,
struct logical_volume * lv )
{
2015-11-05 20:32:47 +03:00
char format [ NAME_LEN ] , layer_name [ NAME_LEN ] ;
2007-12-22 05:13:00 +03:00
int i ;
/*
2015-11-05 20:32:47 +03:00
* We would like to give the same number for this layer
* and the newly added mimage .
* However , LV name of newly added mimage is determined * after *
2007-12-22 05:13:00 +03:00
* the LV name of this layer is determined .
*
* So , use generate_lv_name ( ) to generate mimage name first
* and take the number from it .
*/
2015-11-05 20:32:47 +03:00
if ( dm_snprintf ( format , sizeof ( format ) , " %s_mimage_%%d " , lv - > name ) < 0 ) {
log_error ( " lvconvert: layer name creation failed. " ) ;
2007-12-22 05:13:00 +03:00
return 0 ;
}
2015-11-05 20:32:47 +03:00
if ( ! generate_lv_name ( lv - > vg , format , layer_name , sizeof ( layer_name ) ) | |
2007-12-22 05:13:00 +03:00
sscanf ( layer_name , format , & i ) ! = 1 ) {
log_error ( " lvconvert: layer name generation failed. " ) ;
return 0 ;
}
2015-11-05 20:32:47 +03:00
if ( dm_snprintf ( layer_name , sizeof ( layer_name ) , MIRROR_SYNC_LAYER " _%d " , i ) < 0 ) {
log_error ( " layer name creation failed. " ) ;
2007-12-22 05:13:00 +03:00
return 0 ;
}
if ( ! insert_layer_for_lv ( cmd , lv , 0 , layer_name ) ) {
log_error ( " Failed to insert resync layer " ) ;
return 0 ;
}
return 1 ;
}
2009-05-21 07:04:52 +04:00
static int _failed_mirrors_count ( struct logical_volume * lv )
2009-04-23 20:56:21 +04:00
{
struct lv_segment * lvseg ;
int ret = 0 ;
2011-04-08 18:40:18 +04:00
unsigned s ;
2009-05-21 07:04:52 +04:00
2009-04-23 20:56:21 +04:00
dm_list_iterate_items ( lvseg , & lv - > segments ) {
if ( ! seg_is_mirrored ( lvseg ) )
return - 1 ;
2011-05-07 17:56:13 +04:00
for ( s = 0 ; s < lvseg - > area_count ; s + + ) {
if ( seg_type ( lvseg , s ) = = AREA_LV ) {
if ( is_temporary_mirror_layer ( seg_lv ( lvseg , s ) ) )
ret + = _failed_mirrors_count ( seg_lv ( lvseg , s ) ) ;
2016-03-02 22:59:03 +03:00
else if ( lv_is_partial ( seg_lv ( lvseg , s ) ) )
2011-05-07 17:56:13 +04:00
+ + ret ;
}
2015-05-25 14:16:57 +03:00
else if ( seg_type ( lvseg , s ) = = AREA_PV & &
2015-05-22 10:50:42 +03:00
is_missing_pv ( seg_pv ( lvseg , s ) ) )
+ + ret ;
2011-05-07 17:56:13 +04:00
}
2009-04-23 20:56:21 +04:00
}
2009-05-21 07:04:52 +04:00
2009-04-23 20:56:21 +04:00
return ret ;
}
2011-05-07 17:56:13 +04:00
static int _failed_logs_count ( struct logical_volume * lv )
{
2012-02-24 02:36:56 +04:00
int ret = 0 ;
unsigned s ;
2011-05-07 17:56:13 +04:00
struct logical_volume * log_lv = first_seg ( lv ) - > log_lv ;
2016-03-02 22:59:03 +03:00
if ( log_lv & & lv_is_partial ( log_lv ) ) {
2014-09-16 00:33:53 +04:00
if ( lv_is_mirrored ( log_lv ) )
2011-05-07 17:56:13 +04:00
ret + = _failed_mirrors_count ( log_lv ) ;
else
ret + = 1 ;
}
for ( s = 0 ; s < first_seg ( lv ) - > area_count ; s + + ) {
if ( seg_type ( first_seg ( lv ) , s ) = = AREA_LV & &
is_temporary_mirror_layer ( seg_lv ( first_seg ( lv ) , s ) ) )
ret + = _failed_logs_count ( seg_lv ( first_seg ( lv ) , s ) ) ;
}
return ret ;
}
2009-04-23 20:56:21 +04:00
static struct dm_list * _failed_pv_list ( struct volume_group * vg )
{
2009-05-21 07:04:52 +04:00
struct dm_list * failed_pvs ;
2009-04-23 20:56:21 +04:00
struct pv_list * pvl , * new_pvl ;
2009-05-21 07:04:52 +04:00
if ( ! ( failed_pvs = dm_pool_alloc ( vg - > vgmem , sizeof ( * failed_pvs ) ) ) ) {
log_error ( " Allocation of list of failed_pvs failed. " ) ;
2014-05-20 14:53:51 +04:00
return NULL ;
2009-04-23 20:56:21 +04:00
}
2009-05-21 07:04:52 +04:00
dm_list_init ( failed_pvs ) ;
2009-04-23 20:56:21 +04:00
dm_list_iterate_items ( pvl , & vg - > pvs ) {
2010-03-16 17:37:38 +03:00
if ( ! is_missing_pv ( pvl - > pv ) )
2009-04-23 20:56:21 +04:00
continue ;
2014-07-11 14:25:18 +04:00
/*
2010-01-06 16:26:21 +03:00
* Finally , - - repair will remove empty PVs .
* But we only want remove these which are output of repair ,
* Do not count these which are already empty here .
* FIXME : code should traverse PV in LV not in whole VG .
* FIXME : layer violation ? should it depend on vgreduce - - removemising ?
*/
if ( pvl - > pv - > pe_alloc_count = = 0 )
continue ;
2009-04-23 20:56:21 +04:00
if ( ! ( new_pvl = dm_pool_alloc ( vg - > vgmem , sizeof ( * new_pvl ) ) ) ) {
2009-05-21 07:04:52 +04:00
log_error ( " Allocation of failed_pvs list entry failed. " ) ;
2014-05-20 14:53:51 +04:00
return NULL ;
2009-04-23 20:56:21 +04:00
}
new_pvl - > pv = pvl - > pv ;
2009-05-21 07:04:52 +04:00
dm_list_add ( failed_pvs , & new_pvl - > list ) ;
2009-04-23 20:56:21 +04:00
}
2009-05-21 07:04:52 +04:00
return failed_pvs ;
2009-04-23 20:56:21 +04:00
}
2010-05-24 19:32:20 +04:00
static int _is_partial_lv ( struct logical_volume * lv ,
2010-07-09 19:34:40 +04:00
void * baton __attribute__ ( ( unused ) ) )
2010-05-24 19:32:20 +04:00
{
2016-03-02 22:59:03 +03:00
return lv_is_partial ( lv ) ;
2010-05-24 19:32:20 +04:00
}
2009-05-21 07:04:52 +04:00
/*
* Walk down the stacked mirror LV to the original mirror LV .
*/
2008-01-16 22:16:48 +03:00
static struct logical_volume * _original_lv ( struct logical_volume * lv )
{
struct logical_volume * next_lv = lv , * tmp_lv ;
while ( ( tmp_lv = find_temporary_mirror ( next_lv ) ) )
next_lv = tmp_lv ;
return next_lv ;
}
2009-06-04 16:01:15 +04:00
static void _lvconvert_mirrors_repair_ask ( struct cmd_context * cmd ,
int failed_log , int failed_mirrors ,
int * replace_log , int * replace_mirrors )
{
2014-05-20 22:10:29 +04:00
const char * leg_policy , * log_policy ;
2009-06-04 16:01:15 +04:00
int force = arg_count ( cmd , force_ARG ) ;
int yes = arg_count ( cmd , yes_ARG ) ;
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , usepolicies_ARG ) ) {
2013-06-25 14:29:54 +04:00
leg_policy = find_config_tree_str ( cmd , activation_mirror_image_fault_policy_CFG , NULL ) ;
log_policy = find_config_tree_str ( cmd , activation_mirror_log_fault_policy_CFG , NULL ) ;
2009-06-04 16:01:15 +04:00
* replace_mirrors = strcmp ( leg_policy , " remove " ) ;
* replace_log = strcmp ( log_policy , " remove " ) ;
return ;
}
if ( force ! = PROMPT ) {
* replace_log = * replace_mirrors = 0 ;
return ;
}
2014-05-20 22:10:29 +04:00
* replace_log = * replace_mirrors = 1 ;
2012-12-11 12:52:54 +04:00
if ( yes )
return ;
2009-06-04 16:01:15 +04:00
if ( failed_log & &
2014-05-20 22:10:55 +04:00
yes_no_prompt ( " Attempt to replace failed mirror log? [y/n]: " ) = = ' n ' )
2009-06-04 16:01:15 +04:00
* replace_log = 0 ;
if ( failed_mirrors & &
yes_no_prompt ( " Attempt to replace failed mirror images "
2014-05-20 22:10:55 +04:00
" (requires full device resync)? [y/n]: " ) = = ' n ' )
2009-06-04 16:01:15 +04:00
* replace_mirrors = 0 ;
}
2010-03-27 01:15:43 +03:00
/*
* _get_log_count
* @ lv : the mirror LV
*
* Get the number of on - disk copies of the log .
* 0 = ' core '
* 1 = ' disk '
* 2 + = ' mirrored '
*/
2013-11-25 16:42:30 +04:00
static uint32_t _get_log_count ( struct logical_volume * lv )
2009-08-03 01:56:29 +04:00
{
2010-03-27 01:15:43 +03:00
struct logical_volume * log_lv ;
log_lv = first_seg ( _original_lv ( lv ) ) - > log_lv ;
2011-05-07 17:56:13 +04:00
if ( log_lv )
return lv_mirror_count ( log_lv ) ;
2010-03-27 01:15:43 +03:00
2011-05-07 17:56:13 +04:00
return 0 ;
2009-08-03 01:56:29 +04:00
}
2010-06-24 00:32:29 +04:00
static int _lv_update_mirrored_log ( struct logical_volume * lv ,
struct dm_list * operable_pvs ,
int log_count )
{
int old_log_count ;
struct logical_volume * log_lv ;
2010-08-03 01:07:40 +04:00
/*
* When log_count is 0 , mirrored log doesn ' t need to be
* updated here but it will be removed later .
*/
if ( ! log_count )
return 1 ;
2010-06-24 00:32:29 +04:00
log_lv = first_seg ( _original_lv ( lv ) ) - > log_lv ;
2014-09-16 00:33:53 +04:00
if ( ! log_lv | | ! lv_is_mirrored ( log_lv ) )
2010-06-24 00:32:29 +04:00
return 1 ;
old_log_count = _get_log_count ( lv ) ;
if ( old_log_count = = log_count )
return 1 ;
/* Reducing redundancy of the log */
2010-08-03 01:07:40 +04:00
return remove_mirror_images ( log_lv , log_count ,
is_mirror_image_removable ,
operable_pvs , 0U ) ;
2010-06-24 00:32:29 +04:00
}
2009-08-03 01:56:29 +04:00
static int _lv_update_log_type ( struct cmd_context * cmd ,
struct lvconvert_params * lp ,
struct logical_volume * lv ,
2010-03-27 01:15:43 +03:00
struct dm_list * operable_pvs ,
2010-01-09 01:32:35 +03:00
int log_count )
2009-08-03 01:56:29 +04:00
{
2010-03-27 01:15:43 +03:00
int old_log_count ;
2012-02-13 22:36:55 +04:00
uint32_t region_size = ( lp ) ? lp - > region_size :
first_seg ( lv ) - > region_size ;
alloc_policy_t alloc = ( lp ) ? lp - > alloc : lv - > alloc ;
2010-03-27 01:15:43 +03:00
struct logical_volume * original_lv ;
struct logical_volume * log_lv ;
old_log_count = _get_log_count ( lv ) ;
if ( old_log_count = = log_count )
return 1 ;
original_lv = _original_lv ( lv ) ;
/* Remove an existing log completely */
if ( ! log_count ) {
2010-10-12 20:41:17 +04:00
if ( ! remove_mirror_log ( cmd , original_lv , operable_pvs ,
arg_count ( cmd , yes_ARG ) | |
arg_count ( cmd , force_ARG ) ) )
2009-08-03 01:56:29 +04:00
return_0 ;
2010-03-27 01:15:43 +03:00
return 1 ;
2009-08-03 01:56:29 +04:00
}
2010-03-27 01:15:43 +03:00
log_lv = first_seg ( original_lv ) - > log_lv ;
/* Adding redundancy to the log */
if ( old_log_count < log_count ) {
2011-05-07 17:56:13 +04:00
region_size = adjusted_mirror_region_size ( lv - > vg - > extent_size ,
lv - > le_count ,
2015-02-25 23:42:15 +03:00
region_size , 0 ,
vg_is_clustered ( lv - > vg ) ) ;
2011-05-07 17:56:13 +04:00
2011-01-11 20:05:08 +03:00
if ( ! add_mirror_log ( cmd , original_lv , log_count ,
2012-02-13 22:36:55 +04:00
region_size , operable_pvs , alloc ) )
2011-01-11 20:05:08 +03:00
return_0 ;
/*
* FIXME : This simple approach won ' t work in cluster mirrors ,
2016-07-12 12:05:34 +03:00
* but it doesn ' t matter because we don ' t support
* mirrored logs in cluster mirrors .
2011-01-11 20:05:08 +03:00
*/
2012-08-02 13:38:07 +04:00
if ( old_log_count & &
2014-09-09 00:48:42 +04:00
! lv_update_and_reload ( log_lv ) )
2012-08-02 13:38:07 +04:00
return_0 ;
2011-01-11 20:05:08 +03:00
return 1 ;
2010-03-27 01:15:43 +03:00
}
/* Reducing redundancy of the log */
2012-02-13 22:36:55 +04:00
return remove_mirror_images ( log_lv , log_count ,
is_mirror_image_removable , operable_pvs , 1U ) ;
2009-08-03 01:56:29 +04:00
}
2010-01-06 16:26:21 +03:00
/*
* Reomove missing and empty PVs from VG , if are also in provided list
*/
static void _remove_missing_empty_pv ( struct volume_group * vg , struct dm_list * remove_pvs )
{
struct pv_list * pvl , * pvl_vg , * pvlt ;
int removed = 0 ;
if ( ! remove_pvs )
return ;
dm_list_iterate_items ( pvl , remove_pvs ) {
dm_list_iterate_items_safe ( pvl_vg , pvlt , & vg - > pvs ) {
if ( ! id_equal ( & pvl - > pv - > id , & pvl_vg - > pv - > id ) | |
2010-03-16 17:37:38 +03:00
! is_missing_pv ( pvl_vg - > pv ) | |
2010-01-06 16:26:21 +03:00
pvl_vg - > pv - > pe_alloc_count ! = 0 )
continue ;
/* FIXME: duplication of vgreduce code, move this to library */
vg - > free_count - = pvl_vg - > pv - > pe_count ;
vg - > extent_count - = pvl_vg - > pv - > pe_count ;
2010-04-13 21:26:03 +04:00
del_pvl_from_vgs ( vg , pvl_vg ) ;
2011-03-11 17:56:56 +03:00
free_pv_fid ( pvl_vg - > pv ) ;
2010-01-06 16:26:21 +03:00
removed + + ;
}
}
if ( removed ) {
if ( ! vg_write ( vg ) | | ! vg_commit ( vg ) ) {
stack ;
return ;
}
log_warn ( " %d missing and now unallocated Physical Volumes removed from VG. " , removed ) ;
}
}
2010-03-27 01:15:43 +03:00
/*
* _lvconvert_mirrors_parse_params
*
* This function performs the following :
* 1 ) Gets the old values of mimage and log counts
* 2 ) Parses the CLI args to find the new desired values
* 3 ) Adjusts ' lp - > mirrors ' to the appropriate absolute value .
* ( Remember , ' lp - > mirrors ' is specified in terms of the number of " copies "
2016-07-12 12:05:34 +03:00
* vs . the number of mimages . It can also be a relative value . )
2010-03-27 01:15:43 +03:00
* 4 ) Sets ' lp - > need_polling ' if collapsing
* 5 ) Validates other mirror params
*
* Returns : 1 on success , 0 on error
*/
static int _lvconvert_mirrors_parse_params ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct lvconvert_params * lp ,
uint32_t * old_mimage_count ,
uint32_t * old_log_count ,
uint32_t * new_mimage_count ,
uint32_t * new_log_count )
2005-06-06 21:12:08 +04:00
{
2010-03-27 01:15:43 +03:00
* old_mimage_count = lv_mirror_count ( lv ) ;
* old_log_count = _get_log_count ( lv ) ;
2007-12-21 04:08:18 +03:00
2016-06-22 20:40:22 +03:00
if ( is_lockd_type ( lv - > vg - > lock_type ) & & lp - > keep_mimages ) {
2015-07-10 19:46:24 +03:00
/* FIXME: we need to create a lock for the new LV. */
log_error ( " Unable to split mirrors in VG with lock_type %s " , lv - > vg - > lock_type ) ;
return 0 ;
}
2010-03-27 01:15:43 +03:00
/*
* Collapsing a stack of mirrors :
*
* If called with no argument , try collapsing the resync layers
*/
2016-06-22 20:40:22 +03:00
if ( ! lp - > mirrors_supplied & & ! lp - > mirrorlog & &
! lp - > corelog & & ! arg_is_set ( cmd , regionsize_ARG ) & &
! lp - > keep_mimages & & ! lp - > repair ) {
2010-03-27 01:15:43 +03:00
* new_mimage_count = * old_mimage_count ;
* new_log_count = * old_log_count ;
2014-09-16 00:33:53 +04:00
if ( find_temporary_mirror ( lv ) | | lv_is_converting ( lv ) )
2009-06-15 16:08:59 +04:00
lp - > need_polling = 1 ;
2007-12-22 15:13:29 +03:00
return 1 ;
2007-12-21 04:08:18 +03:00
}
2005-11-29 21:20:23 +03:00
2007-08-02 00:54:28 +04:00
/*
2010-03-27 01:15:43 +03:00
* Adjusting mimage count ?
2007-08-02 00:54:28 +04:00
*/
2016-06-22 20:40:22 +03:00
if ( ! lp - > mirrors_supplied & & ! lp - > keep_mimages )
2010-03-27 01:15:43 +03:00
lp - > mirrors = * old_mimage_count ;
2007-08-02 00:54:28 +04:00
else if ( lp - > mirrors_sign = = SIGN_PLUS )
2010-03-27 01:15:43 +03:00
lp - > mirrors = * old_mimage_count + lp - > mirrors ;
2007-08-02 00:54:28 +04:00
else if ( lp - > mirrors_sign = = SIGN_MINUS )
2010-07-14 01:53:07 +04:00
lp - > mirrors = ( * old_mimage_count > lp - > mirrors ) ?
* old_mimage_count - lp - > mirrors : 0 ;
2007-08-02 00:54:28 +04:00
else
2005-11-29 21:20:23 +03:00
lp - > mirrors + = 1 ;
2010-03-27 01:15:43 +03:00
* new_mimage_count = lp - > mirrors ;
/* Too many mimages? */
2009-11-27 17:35:38 +03:00
if ( lp - > mirrors > DEFAULT_MIRROR_MAX_IMAGES ) {
log_error ( " Only up to %d images in mirror supported currently. " ,
DEFAULT_MIRROR_MAX_IMAGES ) ;
return 0 ;
}
2010-03-27 01:15:43 +03:00
/* Did the user try to subtract more legs than available? */
if ( lp - > mirrors < 1 ) {
2010-07-14 01:53:07 +04:00
log_error ( " Unable to reduce images by specified amount - only %d in %s " ,
* old_mimage_count , lv - > name ) ;
2010-03-27 01:15:43 +03:00
return 0 ;
2010-01-07 23:42:55 +03:00
}
2010-03-27 01:15:43 +03:00
/*
* FIXME : It would be nice to say what we are adjusting to , but
* I really don ' t know whether to specify the # of copies or mimages .
*/
if ( * old_mimage_count ! = * new_mimage_count )
log_verbose ( " Adjusting mirror image count of %s " , lv - > name ) ;
2009-04-30 00:11:46 +04:00
2010-03-27 01:15:43 +03:00
/*
* Adjust log type
*
* If we are converting from a mirror to another mirror or simply
* changing the log type , we start by assuming they want the log
* type the same and then parse the given args . OTOH , If we are
* converting from linear to mirror , then we start from the default
* position that the user would like a ' disk ' log .
*/
* new_log_count = ( * old_mimage_count > 1 ) ? * old_log_count : 1 ;
2016-06-22 20:40:22 +03:00
if ( ! lp - > corelog & & ! lp - > mirrorlog )
2010-03-27 01:15:43 +03:00
return 1 ;
2010-01-09 01:32:35 +03:00
2016-06-22 20:40:22 +03:00
* new_log_count = arg_int_value ( cmd , mirrorlog_ARG , lp - > corelog ? MIRROR_LOG_CORE : DEFAULT_MIRRORLOG ) ;
2007-08-21 23:46:36 +04:00
2010-08-02 23:03:45 +04:00
/*
* No mirrored logs for cluster mirrors until
* log daemon is multi - threaded .
*/
2014-10-22 23:02:29 +04:00
if ( ( * new_log_count = = MIRROR_LOG_MIRRORED ) & & vg_is_clustered ( lv - > vg ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " Log type, \" mirrored \" , is unavailable to cluster mirrors. " ) ;
2010-08-02 23:03:45 +04:00
return 0 ;
}
2016-07-12 12:05:34 +03:00
log_verbose ( " Setting logging type to %s. " , get_mirror_log_name ( * new_log_count ) ) ;
2010-03-27 01:15:43 +03:00
2007-08-02 01:01:06 +04:00
/*
* Region size must not change on existing mirrors
*/
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , regionsize_ARG ) & & lv_is_mirrored ( lv ) & &
2010-03-27 01:15:43 +03:00
( lp - > region_size ! = first_seg ( lv ) - > region_size ) ) {
2005-11-29 21:20:23 +03:00
log_error ( " Mirror log region size cannot be changed on "
" an existing mirror. " ) ;
return 0 ;
}
2005-06-06 21:12:08 +04:00
2009-04-23 20:56:21 +04:00
/*
2009-05-19 14:27:47 +04:00
* For the most part , we cannot handle multi - segment mirrors . Bail out
* early if we have encountered one .
2009-04-23 20:56:21 +04:00
*/
2014-09-16 00:33:53 +04:00
if ( lv_is_mirrored ( lv ) & & dm_list_size ( & lv - > segments ) ! = 1 ) {
2009-04-23 20:56:21 +04:00
log_error ( " Logical volume %s has multiple "
2016-07-12 12:05:34 +03:00
" mirror segments. " , display_lvname ( lv ) ) ;
2009-04-23 20:56:21 +04:00
return 0 ;
}
2009-04-30 00:11:46 +04:00
2010-03-27 01:15:43 +03:00
return 1 ;
}
2009-06-04 16:01:15 +04:00
2010-03-27 01:15:43 +03:00
/*
* _lvconvert_mirrors_aux
*
* Add / remove mirror images and adjust log type . ' operable_pvs '
* are the set of PVs open to removal or allocation - depending
* on the operation being performed .
*/
static int _lvconvert_mirrors_aux ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct lvconvert_params * lp ,
struct dm_list * operable_pvs ,
uint32_t new_mimage_count ,
2010-04-14 17:51:58 +04:00
uint32_t new_log_count )
2010-03-27 01:15:43 +03:00
{
uint32_t region_size ;
struct lv_segment * seg ;
struct logical_volume * layer_lv ;
uint32_t old_mimage_count = lv_mirror_count ( lv ) ;
uint32_t old_log_count = _get_log_count ( lv ) ;
2014-09-16 00:33:53 +04:00
if ( ( lp - > mirrors = = 1 ) & & ! lv_is_mirrored ( lv ) ) {
2012-10-16 12:14:41 +04:00
log_warn ( " Logical volume %s is already not mirrored. " ,
2016-07-12 12:05:34 +03:00
display_lvname ( lv ) ) ;
2010-03-27 01:15:43 +03:00
return 1 ;
2007-08-02 00:54:28 +04:00
}
2010-03-27 01:15:43 +03:00
region_size = adjusted_mirror_region_size ( lv - > vg - > extent_size ,
lv - > le_count ,
2015-02-25 23:42:15 +03:00
lp - > region_size , 0 ,
vg_is_clustered ( lv - > vg ) ) ;
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
2010-08-06 19:38:32 +04:00
if ( ! operable_pvs )
2010-03-27 01:15:43 +03:00
operable_pvs = lp - > pvh ;
This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.
If more than one leg is split off, a new mirror will be the
result. The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_1] /dev/sdc1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mimage_3] /dev/sde1(0)
[lv_mlog] /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
LV Copy% Devices
lv 100.00 lv_mimage_0(0),lv_mimage_2(0)
[lv_mimage_0] /dev/sdb1(0)
[lv_mimage_2] /dev/sdd1(0)
[lv_mlog] /dev/sdi1(0)
split 100.00 split_mimage_0(0),split_mimage_1(0)
[split_mimage_0] /dev/sde1(0)
[split_mimage_1] /dev/sdc1(0)
It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-09 01:00:31 +03:00
2010-03-27 01:15:43 +03:00
seg = first_seg ( lv ) ;
2009-04-30 00:11:46 +04:00
2010-03-27 01:15:43 +03:00
/*
* Up - convert from linear to mirror
*/
2014-09-16 00:33:53 +04:00
if ( ! lv_is_mirrored ( lv ) ) {
2007-08-02 00:54:28 +04:00
/* FIXME Share code with lvcreate */
2009-04-23 20:56:21 +04:00
/*
* FIXME should we give not only lp - > pvh , but also all PVs
* currently taken by the mirror ? Would make more sense from
* user perspective .
*/
2010-04-13 05:54:32 +04:00
if ( ! lv_add_mirrors ( cmd , lv , new_mimage_count - 1 , lp - > stripes ,
lp - > stripe_size , region_size , new_log_count , operable_pvs ,
2012-01-26 02:38:40 +04:00
lp - > alloc , MIRROR_BY_LV ) )
return_0 ;
2008-01-15 00:11:47 +03:00
if ( lp - > wait_completion )
lp - > need_polling = 1 ;
2010-03-27 01:15:43 +03:00
goto out ;
}
/*
* Up - convert m - way mirror to n - way mirror
*/
if ( new_mimage_count > old_mimage_count ) {
2011-03-29 16:51:57 +04:00
if ( lv - > status & LV_NOTSYNCED ) {
2009-06-15 17:43:15 +04:00
log_error ( " Can't add mirror to out-of-sync mirrored "
" LV: use lvchange --resync first. " ) ;
2007-12-22 05:13:00 +03:00
return 0 ;
}
2009-10-26 13:01:56 +03:00
/*
* We allow snapshots of mirrors , but for now , we
* do not allow up converting mirrors that are under
* snapshots . The layering logic is somewhat complex ,
* and preliminary test show that the conversion can ' t
* seem to get the correct % ' age of completion .
*/
if ( lv_is_origin ( lv ) ) {
log_error ( " Can't add additional mirror images to "
2016-07-12 12:05:34 +03:00
" mirrors that are under snapshots, " ) ;
2010-04-14 17:51:58 +04:00
return 0 ;
2009-10-26 13:01:56 +03:00
}
2010-04-21 18:04:24 +04:00
/*
* Is there already a convert in progress ? We do not
* currently allow more than one .
*/
2014-09-16 00:33:53 +04:00
if ( find_temporary_mirror ( lv ) | | lv_is_converting ( lv ) ) {
2010-04-21 18:04:24 +04:00
log_error ( " %s is already being converted. Unable to start another conversion. " ,
2016-07-12 12:05:34 +03:00
display_lvname ( lv ) ) ;
2010-04-21 18:04:24 +04:00
return 0 ;
}
2008-01-10 21:35:51 +03:00
/*
* Log addition / removal should be done before the layer
* insertion to make the end result consistent with
* linear - to - mirror conversion .
*/
2010-03-27 01:15:43 +03:00
if ( ! _lv_update_log_type ( cmd , lp , lv ,
2013-07-01 13:27:11 +04:00
operable_pvs , new_log_count ) )
return_0 ;
2010-03-27 01:15:43 +03:00
2008-01-10 21:35:51 +03:00
/* Insert a temporary layer for syncing,
* only if the original lv is using disk log . */
if ( seg - > log_lv & & ! _insert_lvconvert_layer ( cmd , lv ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " Failed to insert resync layer. " ) ;
2007-12-20 21:55:46 +03:00
return 0 ;
}
2010-03-27 01:15:43 +03:00
2008-01-10 21:35:51 +03:00
/* FIXME: can't have multiple mlogs. force corelog. */
2010-03-27 01:15:43 +03:00
if ( ! lv_add_mirrors ( cmd , lv ,
2011-01-11 20:05:08 +03:00
new_mimage_count - old_mimage_count ,
lp - > stripes , lp - > stripe_size ,
2010-03-27 01:15:43 +03:00
region_size , 0U , operable_pvs , lp - > alloc ,
2009-10-23 05:24:17 +04:00
MIRROR_BY_LV ) ) {
layer_lv = seg_lv ( first_seg ( lv ) , 0 ) ;
if ( ! remove_layer_from_lv ( lv , layer_lv ) | |
2013-04-11 01:47:04 +04:00
( lv_is_active ( layer_lv ) & &
! deactivate_lv ( cmd , layer_lv ) ) | |
2009-10-23 05:24:17 +04:00
! lv_remove ( layer_lv ) | | ! vg_write ( lv - > vg ) | |
! vg_commit ( lv - > vg ) ) {
log_error ( " ABORTING: Failed to remove "
" temporary mirror layer %s. " ,
2016-07-12 12:05:34 +03:00
display_lvname ( layer_lv ) ) ;
2009-10-23 05:24:17 +04:00
log_error ( " Manual cleanup with vgcfgrestore "
" and dmsetup may be required. " ) ;
return 0 ;
}
2013-07-01 13:27:11 +04:00
return_0 ;
2009-10-23 05:24:17 +04:00
}
2010-02-06 00:49:16 +03:00
if ( seg - > log_lv )
lv - > status | = CONVERTING ;
2008-01-15 00:11:47 +03:00
lp - > need_polling = 1 ;
2010-03-27 01:15:43 +03:00
goto out_skip_log_convert ;
2005-06-06 21:12:08 +04:00
}
2010-03-27 01:15:43 +03:00
/*
* Down - convert ( reduce # of mimages ) .
*/
if ( new_mimage_count < old_mimage_count ) {
uint32_t nmc = old_mimage_count - new_mimage_count ;
uint32_t nlc = ( ! new_log_count | | lp - > mirrors = = 1 ) ? 1U : 0U ;
2010-04-20 16:18:31 +04:00
/* FIXME: Why did nlc used to be calculated that way? */
2010-03-27 01:15:43 +03:00
/* Reduce number of mirrors */
if ( lp - > keep_mimages ) {
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , trackchanges_ARG ) ) {
2011-08-18 23:38:26 +04:00
log_error ( " --trackchanges is not available "
2016-07-12 12:05:34 +03:00
" to 'mirror' segment type. " ) ;
2011-08-18 23:38:26 +04:00
return 0 ;
}
2010-03-27 01:15:43 +03:00
if ( ! lv_split_mirror_images ( lv , lp - > lv_split_name ,
nmc , operable_pvs ) )
2014-05-20 14:53:51 +04:00
return_0 ;
2010-03-27 01:15:43 +03:00
} else if ( ! lv_remove_mirrors ( cmd , lv , nmc , nlc ,
2010-05-24 19:32:20 +04:00
is_mirror_image_removable , operable_pvs , 0 ) )
2010-03-27 01:15:43 +03:00
return_0 ;
goto out ; /* Just in case someone puts code between */
}
out :
/*
* Converting the log type
*/
2014-09-16 00:33:53 +04:00
if ( lv_is_mirrored ( lv ) & & ( old_log_count ! = new_log_count ) ) {
2010-03-27 01:15:43 +03:00
if ( ! _lv_update_log_type ( cmd , lp , lv ,
2013-07-01 13:27:11 +04:00
operable_pvs , new_log_count ) )
return_0 ;
2009-04-23 20:56:21 +04:00
}
2010-03-27 01:15:43 +03:00
out_skip_log_convert :
2014-09-09 00:48:42 +04:00
if ( ! lv_update_and_reload ( lv ) )
2012-08-02 13:38:07 +04:00
return_0 ;
2005-06-06 21:12:08 +04:00
2010-03-27 01:15:43 +03:00
return 1 ;
}
2011-05-07 17:56:13 +04:00
int mirror_remove_missing ( struct cmd_context * cmd ,
struct logical_volume * lv , int force )
{
struct dm_list * failed_pvs ;
int log_count = _get_log_count ( lv ) - _failed_logs_count ( lv ) ;
if ( ! ( failed_pvs = _failed_pv_list ( lv - > vg ) ) )
return_0 ;
2013-11-25 16:42:30 +04:00
if ( force & & _failed_mirrors_count ( lv ) = = ( int ) lv_mirror_count ( lv ) ) {
2016-02-25 17:01:12 +03:00
log_error ( " No usable images left in %s. " , display_lvname ( lv ) ) ;
2012-03-02 01:14:43 +04:00
return lv_remove_with_dependencies ( cmd , lv , DONT_PROMPT , 0 ) ;
2016-07-12 12:05:34 +03:00
}
2011-05-07 17:56:13 +04:00
/*
* We must adjust the log first , or the entire mirror
* will get stuck during a suspend .
*/
if ( ! _lv_update_mirrored_log ( lv , failed_pvs , log_count ) )
2014-05-20 14:53:51 +04:00
return_0 ;
2011-05-07 17:56:13 +04:00
if ( _failed_mirrors_count ( lv ) > 0 & &
! lv_remove_mirrors ( cmd , lv , _failed_mirrors_count ( lv ) ,
log_count ? 0U : 1U ,
_is_partial_lv , NULL , 0 ) )
2014-05-20 14:53:51 +04:00
return_0 ;
2011-05-07 17:56:13 +04:00
2012-11-15 00:58:47 +04:00
if ( lv_is_mirrored ( lv ) & &
! _lv_update_log_type ( cmd , NULL , lv , failed_pvs , log_count ) )
2014-05-20 14:53:51 +04:00
return_0 ;
2011-05-07 17:56:13 +04:00
2014-09-09 00:48:42 +04:00
if ( ! lv_update_and_reload ( lv ) )
2012-08-02 13:38:07 +04:00
return_0 ;
2011-05-07 17:56:13 +04:00
return 1 ;
}
2010-03-27 01:15:43 +03:00
/*
* _lvconvert_mirrors_repair
*
* This function operates in two phases . First , all of the bad
* devices are removed from the mirror . Then , if desired by the
* user , the devices are replaced .
*
* ' old_mimage_count ' and ' old_log_count ' are there so we know
* what to convert to after the removal of devices .
*/
static int _lvconvert_mirrors_repair ( struct cmd_context * cmd ,
struct logical_volume * lv ,
2011-05-07 17:56:13 +04:00
struct lvconvert_params * lp )
2010-03-27 01:15:43 +03:00
{
2014-05-20 22:10:29 +04:00
int failed_logs ;
int failed_mimages ;
2011-05-07 17:56:13 +04:00
int replace_logs = 0 ;
int replace_mimages = 0 ;
uint32_t log_count ;
uint32_t original_mimages = lv_mirror_count ( lv ) ;
uint32_t original_logs = _get_log_count ( lv ) ;
2010-03-27 01:15:43 +03:00
cmd - > handles_missing_pvs = 1 ;
cmd - > partial_activation = 1 ;
lp - > need_polling = 0 ;
2010-05-24 19:32:20 +04:00
lv_check_transient ( lv ) ; /* TODO check this in lib for all commands? */
2016-03-02 22:59:03 +03:00
if ( ! lv_is_partial ( lv ) ) {
2016-02-25 17:01:12 +03:00
log_print_unless_silent ( " Volume %s is consistent. Nothing to repair. " ,
display_lvname ( lv ) ) ;
2010-03-27 01:15:43 +03:00
return 1 ;
}
2011-05-07 17:56:13 +04:00
failed_mimages = _failed_mirrors_count ( lv ) ;
failed_logs = _failed_logs_count ( lv ) ;
2010-03-27 01:15:43 +03:00
2014-05-20 14:57:42 +04:00
if ( ! mirror_remove_missing ( cmd , lv , 0 ) )
return_0 ;
2010-03-27 01:15:43 +03:00
2011-05-07 17:56:13 +04:00
if ( failed_mimages )
2014-05-20 14:56:49 +04:00
log_print_unless_silent ( " Mirror status: %d of %d images failed. " ,
failed_mimages , original_mimages ) ;
2010-03-27 01:15:43 +03:00
/*
* Count the failed log devices
*/
2011-05-07 17:56:13 +04:00
if ( failed_logs )
2014-05-20 14:56:49 +04:00
log_print_unless_silent ( " Mirror log status: %d of %d images failed. " ,
failed_logs , original_logs ) ;
2010-03-27 01:15:43 +03:00
/*
* Find out our policies
*/
2011-05-07 17:56:13 +04:00
_lvconvert_mirrors_repair_ask ( cmd , failed_logs , failed_mimages ,
& replace_logs , & replace_mimages ) ;
2010-03-27 01:15:43 +03:00
/*
* Second phase - replace faulty devices
*/
2011-05-07 17:56:13 +04:00
lp - > mirrors = replace_mimages ? original_mimages : ( original_mimages - failed_mimages ) ;
2010-03-27 01:15:43 +03:00
2010-05-24 19:32:20 +04:00
/*
* It does not make sense to replace the log if the volume is no longer
* a mirror .
*/
2011-05-07 17:56:13 +04:00
if ( lp - > mirrors = = 1 )
replace_logs = 0 ;
2010-05-24 19:32:20 +04:00
2011-05-07 17:56:13 +04:00
log_count = replace_logs ? original_logs : ( original_logs - failed_logs ) ;
2010-04-14 17:51:58 +04:00
2011-05-07 17:56:13 +04:00
while ( replace_mimages | | replace_logs ) {
2010-04-14 17:51:58 +04:00
log_warn ( " Trying to up-convert to %d images, %d logs. " , lp - > mirrors , log_count ) ;
if ( _lvconvert_mirrors_aux ( cmd , lv , lp , NULL ,
lp - > mirrors , log_count ) )
break ;
2014-05-20 22:10:55 +04:00
if ( lp - > mirrors > 2 )
- - lp - > mirrors ;
else if ( log_count > 0 )
- - log_count ;
else
break ; /* nowhere to go, anymore... */
2009-04-23 20:56:21 +04:00
}
2011-05-07 17:56:13 +04:00
if ( replace_mimages & & lv_mirror_count ( lv ) ! = original_mimages )
2016-02-25 17:01:12 +03:00
log_warn ( " WARNING: Failed to replace %d of %d images in volume %s. " ,
original_mimages - lv_mirror_count ( lv ) , original_mimages ,
display_lvname ( lv ) ) ;
2011-05-07 17:56:13 +04:00
if ( replace_logs & & _get_log_count ( lv ) ! = original_logs )
2016-02-25 17:01:12 +03:00
log_warn ( " WARNING: Failed to replace %d of %d logs in volume %s. " ,
original_logs - _get_log_count ( lv ) , original_logs ,
display_lvname ( lv ) ) ;
2010-04-14 17:51:58 +04:00
2016-06-22 00:24:52 +03:00
/* if (!arg_is_set(cmd, use_policies_ARG) && (lp->mirrors != old_mimage_count
2010-04-14 17:51:58 +04:00
| | log_count ! = old_log_count ) )
return 0 ; */
2010-03-27 01:15:43 +03:00
return 1 ;
}
2013-07-24 17:25:22 +04:00
static int _lvconvert_validate_thin ( struct logical_volume * lv ,
struct lvconvert_params * lp )
{
if ( ! lv_is_thin_pool ( lv ) & & ! lv_is_thin_volume ( lv ) )
return 1 ;
2016-02-25 17:01:12 +03:00
log_error ( " Converting thin%s segment type for %s to %s is not supported. " ,
2013-07-24 17:25:22 +04:00
lv_is_thin_pool ( lv ) ? " pool " : " " ,
2016-02-25 17:01:12 +03:00
display_lvname ( lv ) , lp - > segtype - > name ) ;
2013-07-24 17:25:22 +04:00
if ( lv_is_thin_volume ( lv ) )
return 0 ;
/* Give advice for thin pool conversion */
2016-02-25 17:01:12 +03:00
log_error ( " For pool data volume conversion use %s. " ,
display_lvname ( seg_lv ( first_seg ( lv ) , 0 ) ) ) ;
log_error ( " For pool metadata volume conversion use %s. " ,
display_lvname ( first_seg ( lv ) - > metadata_lv ) ) ;
2016-07-12 12:05:34 +03:00
2013-07-24 17:25:22 +04:00
return 0 ;
}
2010-03-27 01:15:43 +03:00
/*
* _lvconvert_mirrors
*
* Determine what is being done . Are we doing a conversion , repair , or
* collapsing a stack ? Once determined , call helper functions .
*/
static int _lvconvert_mirrors ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct lvconvert_params * lp )
{
2016-07-07 00:33:25 +03:00
const char * new_type ;
2010-03-27 01:15:43 +03:00
uint32_t old_mimage_count ;
uint32_t old_log_count ;
uint32_t new_mimage_count ;
uint32_t new_log_count ;
2011-08-18 23:43:08 +04:00
if ( lp - > merge_mirror ) {
log_error ( " Unable to merge mirror images "
2016-07-12 12:05:34 +03:00
" of segment type 'mirror'. " ) ;
2011-08-18 23:43:08 +04:00
return 0 ;
}
2013-07-24 17:25:22 +04:00
if ( ! _lvconvert_validate_thin ( lv , lp ) )
return_0 ;
Mirror/Thin: Disallow thinpools on mirror logical volumes
The same corner cases that exist for snapshots on mirrors exist for
any logical volume layered on top of mirror. (One example is when
a mirror image fails and a non-repair LVM command is the first to
detect it via label reading. In this case, the LVM command will hang
and prevent the necessary LVM repair command from running.) When
a better alternative exists, it makes no sense to allow a new target
to stack on mirrors as a new feature. Since, RAID is now capable of
running EX in a cluster and thin is not active-active aware, it makes
sense to pair these two rather than mirror+thinpool.
As further background, here are some additional comments that I made
when addressing a bug related to mirror+thinpool:
(https://bugzilla.redhat.com/show_bug.cgi?id=919604#c9)
I am going to disallow thin* on top of mirror logical volumes.
Users will have to use the "raid1" segment type if they want this.
This bug has come down to a choice between:
1) Disallowing thin-LVs from being used as PVs.
2) Disallowing thinpools on top of mirrors.
The problem is that the code in dev_manager.c:device_is_usable() is unable
to tell whether there is a mirror device lower in the stack from the device
being checked. Pretty much anything layered on top of a mirror will suffer
from this problem. (Snapshots are a good example of this; and option #1
above has been chosen to deal with them. This can also be seen in
dev_manager.c:device_is_usable().) When a mirror failure occurs, the
kernel blocks all I/O to it. If there is an LVM command that comes along
to do the repair (or a different operation that requires label reading), it
would normally avoid the mirror when it sees that it is blocked. However,
if there is a snapshot or a thin-LV that is on a mirror, the above code
will not detect the mirror underneath and will issue label reading I/O.
This causes the command to hang.
Choosing #1 would mean that thin-LVs could never be used as PVs - even if
they are stacked on something other than mirrors.
Choosing #2 means that thinpools can never be placed on mirrors. This is
probably better than we think, since it is preferred that people use the
"raid1" segment type in the first place. However, RAID* cannot currently
be used in a cluster volume group - even in EX-only mode. Thus, a complete
solution for option #2 must include the ability to activate RAID logical
volumes (and perform RAID operations) in a cluster volume group. I've
already begun working on this.
2013-09-12 00:58:44 +04:00
if ( lv_is_thin_type ( lv ) ) {
log_error ( " Mirror segment type cannot be used for thinpool%s. \n "
2014-09-24 17:24:41 +04:00
" Try \" %s \" segment type instead. " ,
lv_is_thin_pool_data ( lv ) ? " s " : " metadata " ,
SEG_TYPE_NAME_RAID1 ) ;
Mirror/Thin: Disallow thinpools on mirror logical volumes
The same corner cases that exist for snapshots on mirrors exist for
any logical volume layered on top of mirror. (One example is when
a mirror image fails and a non-repair LVM command is the first to
detect it via label reading. In this case, the LVM command will hang
and prevent the necessary LVM repair command from running.) When
a better alternative exists, it makes no sense to allow a new target
to stack on mirrors as a new feature. Since, RAID is now capable of
running EX in a cluster and thin is not active-active aware, it makes
sense to pair these two rather than mirror+thinpool.
As further background, here are some additional comments that I made
when addressing a bug related to mirror+thinpool:
(https://bugzilla.redhat.com/show_bug.cgi?id=919604#c9)
I am going to disallow thin* on top of mirror logical volumes.
Users will have to use the "raid1" segment type if they want this.
This bug has come down to a choice between:
1) Disallowing thin-LVs from being used as PVs.
2) Disallowing thinpools on top of mirrors.
The problem is that the code in dev_manager.c:device_is_usable() is unable
to tell whether there is a mirror device lower in the stack from the device
being checked. Pretty much anything layered on top of a mirror will suffer
from this problem. (Snapshots are a good example of this; and option #1
above has been chosen to deal with them. This can also be seen in
dev_manager.c:device_is_usable().) When a mirror failure occurs, the
kernel blocks all I/O to it. If there is an LVM command that comes along
to do the repair (or a different operation that requires label reading), it
would normally avoid the mirror when it sees that it is blocked. However,
if there is a snapshot or a thin-LV that is on a mirror, the above code
will not detect the mirror underneath and will issue label reading I/O.
This causes the command to hang.
Choosing #1 would mean that thin-LVs could never be used as PVs - even if
they are stacked on something other than mirrors.
Choosing #2 means that thinpools can never be placed on mirrors. This is
probably better than we think, since it is preferred that people use the
"raid1" segment type in the first place. However, RAID* cannot currently
be used in a cluster volume group - even in EX-only mode. Thus, a complete
solution for option #2 must include the ability to activate RAID logical
volumes (and perform RAID operations) in a cluster volume group. I've
already begun working on this.
2013-09-12 00:58:44 +04:00
return 0 ;
}
2014-09-17 19:41:58 +04:00
if ( lv_is_cache_type ( lv ) ) {
log_error ( " Mirrors are not yet supported on cache LVs %s. " ,
display_lvname ( lv ) ) ;
return 0 ;
}
2016-07-07 00:33:25 +03:00
if ( ( new_type = arg_str_value ( cmd , type_ARG , NULL ) ) & &
! strcmp ( new_type , SEG_TYPE_NAME_LINEAR ) ) {
if ( arg_is_set ( cmd , mirrors_ARG ) & & ( arg_uint_value ( cmd , mirrors_ARG , 0 ) ! = 0 ) ) {
log_error ( " Cannot specify mirrors with linear type. " ) ;
return 0 ;
}
lp - > mirrors_supplied = 1 ;
lp - > mirrors = 0 ;
}
2010-03-27 01:15:43 +03:00
/* Adjust mimage and/or log count */
if ( ! _lvconvert_mirrors_parse_params ( cmd , lv , lp ,
& old_mimage_count , & old_log_count ,
& new_mimage_count , & new_log_count ) )
return 0 ;
2016-07-12 12:05:34 +03:00
if ( ( ( old_mimage_count < new_mimage_count & & old_log_count > new_log_count ) | |
( old_mimage_count > new_mimage_count & & old_log_count < new_log_count ) ) & &
lp - > pv_count ) {
2011-01-06 02:18:46 +03:00
log_error ( " Cannot both allocate and free extents when "
" specifying physical volumes to use. " ) ;
2010-11-25 20:15:46 +03:00
log_error ( " Please specify the operation in two steps. " ) ;
return 0 ;
2016-07-12 12:05:34 +03:00
}
2010-11-25 20:15:46 +03:00
2010-03-27 01:15:43 +03:00
/* Nothing to do? (Probably finishing collapse.) */
if ( ( old_mimage_count = = new_mimage_count ) & &
2016-02-25 17:12:17 +03:00
( old_log_count = = new_log_count ) & & ! lp - > repair )
2010-03-27 01:15:43 +03:00
return 1 ;
2016-02-25 17:12:17 +03:00
if ( lp - > repair )
2011-05-07 17:56:13 +04:00
return _lvconvert_mirrors_repair ( cmd , lv , lp ) ;
2010-03-27 01:15:43 +03:00
if ( ! _lvconvert_mirrors_aux ( cmd , lv , lp , NULL ,
2010-04-14 17:51:58 +04:00
new_mimage_count , new_log_count ) )
2010-03-27 01:15:43 +03:00
return 0 ;
2008-01-15 00:11:47 +03:00
if ( ! lp - > need_polling )
2016-07-12 12:05:34 +03:00
log_print_unless_silent ( " Logical volume %s converted. " ,
display_lvname ( lv ) ) ;
2005-06-06 21:12:08 +04:00
2009-04-21 18:31:57 +04:00
backup ( lv - > vg ) ;
2016-07-12 12:05:34 +03:00
2010-03-27 01:15:43 +03:00
return 1 ;
2005-06-06 21:12:08 +04:00
}
2013-12-04 06:09:37 +04:00
static int _is_valid_raid_conversion ( const struct segment_type * from_segtype ,
2011-08-11 22:24:40 +04:00
const struct segment_type * to_segtype )
{
if ( from_segtype = = to_segtype )
return 1 ;
2016-06-22 20:40:22 +03:00
/* Support raid0 <-> striped conversions */
if ( segtype_is_striped ( from_segtype ) & & segtype_is_striped ( to_segtype ) )
return 1 ;
2011-08-11 22:24:40 +04:00
if ( ! segtype_is_raid ( from_segtype ) & & ! segtype_is_raid ( to_segtype ) )
return_0 ; /* Not converting to or from RAID? */
2011-10-07 18:52:26 +04:00
return 1 ;
2011-08-11 22:24:40 +04:00
}
2014-07-01 11:55:04 +04:00
static void _lvconvert_raid_repair_ask ( struct cmd_context * cmd ,
struct lvconvert_params * lp ,
int * replace_dev )
2011-12-06 23:30:15 +04:00
{
2014-07-01 11:55:04 +04:00
const char * dev_policy ;
2011-12-06 23:30:15 +04:00
2012-12-11 12:52:54 +04:00
* replace_dev = 1 ;
2011-12-06 23:30:15 +04:00
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , usepolicies_ARG ) ) {
2013-06-25 14:29:54 +04:00
dev_policy = find_config_tree_str ( cmd , activation_raid_fault_policy_CFG , NULL ) ;
2011-12-06 23:30:15 +04:00
if ( ! strcmp ( dev_policy , " allocate " ) | |
! strcmp ( dev_policy , " replace " ) )
2012-12-11 12:52:54 +04:00
return ;
/* else if (!strcmp(dev_policy, "anything_else")) -- no replace */
* replace_dev = 0 ;
2011-12-06 23:30:15 +04:00
return ;
}
2014-07-01 11:55:04 +04:00
if ( ! lp - > yes & &
yes_no_prompt ( " Attempt to replace failed RAID images "
2012-12-11 12:52:54 +04:00
" (requires full device resync)? [y/n]: " ) = = ' n ' ) {
* replace_dev = 0 ;
2011-12-06 23:30:15 +04:00
}
}
2013-12-04 06:09:37 +04:00
static int _lvconvert_raid ( struct logical_volume * lv , struct lvconvert_params * lp )
2011-08-11 22:24:40 +04:00
{
2016-07-07 00:44:18 +03:00
const char * new_type ;
2013-12-05 12:41:03 +04:00
int replace = 0 , image_count = 0 ;
2011-12-06 23:30:15 +04:00
struct dm_list * failed_pvs ;
2011-08-11 22:24:40 +04:00
struct cmd_context * cmd = lv - > vg - > cmd ;
struct lv_segment * seg = first_seg ( lv ) ;
2014-06-09 14:08:27 +04:00
dm_percent_t sync_percent ;
2011-08-11 22:24:40 +04:00
2016-06-23 00:10:42 +03:00
if ( ! lp - > segtype )
2011-08-11 22:24:40 +04:00
lp - > segtype = seg - > segtype ;
2016-07-07 00:44:18 +03:00
if ( ( new_type = arg_str_value ( cmd , type_ARG , NULL ) ) & &
! strcmp ( new_type , SEG_TYPE_NAME_LINEAR ) ) {
if ( arg_is_set ( cmd , mirrors_ARG ) & & ( arg_uint_value ( cmd , mirrors_ARG , 0 ) ! = 0 ) ) {
log_error ( " Cannot specify mirrors with linear type. " ) ;
return 0 ;
}
lp - > mirrors_supplied = 1 ;
lp - > mirrors = 0 ;
}
2011-10-07 18:52:26 +04:00
/* Can only change image count for raid1 and linear */
2016-06-22 20:40:22 +03:00
if ( lp - > mirrors_supplied & & ! seg_is_mirrored ( seg ) & & ! seg_is_linear ( seg ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " '--mirrors/-m' is not compatible with %s. " ,
2014-10-20 20:40:39 +04:00
lvseg_name ( seg ) ) ;
2011-08-11 22:24:40 +04:00
return 0 ;
}
2013-07-24 17:25:22 +04:00
if ( ! _lvconvert_validate_thin ( lv , lp ) )
return_0 ;
2013-12-04 06:09:37 +04:00
if ( ! _is_valid_raid_conversion ( seg - > segtype , lp - > segtype ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " Unable to convert %s from %s to %s. " ,
display_lvname ( lv ) , lvseg_name ( seg ) ,
lp - > segtype - > name ) ;
2011-08-11 22:24:40 +04:00
return 0 ;
}
2016-06-22 20:40:22 +03:00
if ( seg_is_linear ( seg ) & & ! lp - > merge_mirror & & ! lp - > mirrors_supplied ) {
2016-07-12 12:05:34 +03:00
log_error ( " Raid conversions require -m/--mirrors. " ) ;
2015-12-03 17:40:14 +03:00
return 0 ;
}
2011-08-11 22:24:40 +04:00
/* Change number of RAID1 images */
2016-06-22 20:40:22 +03:00
if ( lp - > mirrors_supplied | | lp - > keep_mimages ) {
2011-08-11 22:24:40 +04:00
image_count = lv_raid_image_count ( lv ) ;
if ( lp - > mirrors_sign = = SIGN_PLUS )
image_count + = lp - > mirrors ;
else if ( lp - > mirrors_sign = = SIGN_MINUS )
image_count - = lp - > mirrors ;
else
image_count = lp - > mirrors + 1 ;
if ( image_count < 1 ) {
2016-07-12 12:05:34 +03:00
log_error ( " Unable to %s images by specified amount. " ,
2016-06-22 20:40:22 +03:00
lp - > keep_mimages ? " split " : " reduce " ) ;
2011-08-11 22:24:40 +04:00
return 0 ;
}
}
2011-08-18 23:43:08 +04:00
if ( lp - > merge_mirror )
return lv_raid_merge ( lv ) ;
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , trackchanges_ARG ) )
2011-08-18 23:43:08 +04:00
return lv_raid_split_and_track ( lv , lp - > pvh ) ;
2016-06-22 20:40:22 +03:00
if ( lp - > keep_mimages )
2011-08-18 23:43:08 +04:00
return lv_raid_split ( lv , lp - > lv_split_name ,
image_count , lp - > pvh ) ;
2016-06-22 20:40:22 +03:00
if ( lp - > mirrors_supplied )
2011-08-18 23:43:08 +04:00
return lv_raid_change_image_count ( lv , image_count , lp - > pvh ) ;
2016-06-22 20:40:22 +03:00
if ( ( seg_is_linear ( seg ) | | seg_is_striped ( seg ) | | seg_is_mirrored ( seg ) | | lv_is_raid ( lv ) ) & &
2016-06-28 04:42:30 +03:00
( lp - > type_str & & lp - > type_str [ 0 ] ) ) {
2016-06-22 20:40:22 +03:00
if ( segtype_is_any_raid0 ( lp - > segtype ) & &
! ( lp - > target_attr & RAID_FEATURE_RAID0 ) ) {
log_error ( " RAID module does not support RAID0. " ) ;
return 0 ;
}
2016-06-28 04:42:30 +03:00
if ( ! lv_raid_convert ( lv , lp - > segtype , lp - > yes , lp - > force , lp - > stripes , lp - > stripe_size , lp - > pvh ) )
return_0 ;
2016-07-12 12:05:34 +03:00
log_print_unless_silent ( " Logical volume %s successfully converted. " ,
display_lvname ( lv ) ) ;
2016-06-28 04:42:30 +03:00
return 1 ;
2016-06-22 20:40:22 +03:00
}
2011-10-07 18:56:01 +04:00
2016-06-22 20:40:22 +03:00
if ( lp - > replace )
2011-11-30 06:02:10 +04:00
return lv_raid_replace ( lv , lp - > replace_pvh , lp - > pvh ) ;
2016-02-25 17:12:17 +03:00
if ( lp - > repair ) {
2014-10-21 12:53:56 +04:00
if ( ! lv_is_active_exclusive_locally ( lv_lock_holder ( lv ) ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " %s must be active %sto perform this operation. " ,
display_lvname ( lv ) ,
2013-09-11 01:33:22 +04:00
vg_is_clustered ( lv - > vg ) ?
" exclusive locally " : " " ) ;
2012-12-19 00:40:42 +04:00
return 0 ;
}
2016-06-22 20:40:22 +03:00
if ( ! seg_is_striped ( seg ) & & ! seg_is_any_raid0 ( seg ) & &
! lv_raid_percent ( lv , & sync_percent ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " Unable to determine sync status of %s. " ,
display_lvname ( lv ) ) ;
2012-12-19 00:40:42 +04:00
return 0 ;
}
2014-06-09 14:08:27 +04:00
if ( sync_percent ! = DM_PERCENT_100 ) {
2016-07-12 12:05:34 +03:00
log_warn ( " WARNING: %s is not in-sync. " ,
display_lvname ( lv ) ) ;
2014-07-01 11:53:58 +04:00
log_warn ( " WARNING: Portions of the array may be unrecoverable. " ) ;
2012-12-19 00:40:42 +04:00
/*
* The kernel will not allow a device to be replaced
* in an array that is not in - sync unless we override
* by forcing the array to be considered " in-sync " .
*/
init_mirror_in_sync ( 1 ) ;
}
2014-07-01 11:55:04 +04:00
_lvconvert_raid_repair_ask ( cmd , lp , & replace ) ;
2011-12-06 23:30:15 +04:00
if ( replace ) {
2012-02-22 19:20:50 +04:00
if ( ! ( failed_pvs = _failed_pv_list ( lv - > vg ) ) )
return_0 ;
2012-02-22 20:03:55 +04:00
if ( ! lv_raid_replace ( lv , failed_pvs , lp - > pvh ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " Failed to replace faulty devices in %s. " ,
display_lvname ( lv ) ) ;
2012-02-22 20:03:55 +04:00
return 0 ;
}
2016-07-12 12:05:34 +03:00
log_print_unless_silent ( " Faulty devices in %s successfully "
" replaced. " , display_lvname ( lv ) ) ;
2012-02-22 20:03:55 +04:00
return 1 ;
2011-12-06 23:30:15 +04:00
}
/* "warn" if policy not set to replace */
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , usepolicies_ARG ) )
2016-07-12 12:05:34 +03:00
log_warn ( " Use 'lvconvert --repair %s' to replace "
" failed device. " , display_lvname ( lv ) ) ;
2011-12-06 23:30:15 +04:00
return 1 ;
}
2011-08-11 22:24:40 +04:00
log_error ( " Conversion operation not yet supported. " ) ;
2016-07-12 12:05:34 +03:00
2011-08-11 22:24:40 +04:00
return 0 ;
}
2013-12-04 06:09:37 +04:00
static int _lvconvert_splitsnapshot ( struct cmd_context * cmd , struct logical_volume * cow ,
struct lvconvert_params * lp )
{
struct volume_group * vg = cow - > vg ;
2016-03-07 12:45:50 +03:00
const char * cow_name = display_lvname ( cow ) ;
2013-12-04 06:09:37 +04:00
if ( ! lv_is_cow ( cow ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " %s is not a snapshot. " , cow_name ) ;
2014-10-04 19:17:49 +04:00
return 0 ;
2013-12-04 06:09:37 +04:00
}
if ( lv_is_origin ( cow ) | | lv_is_external_origin ( cow ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " Unable to split LV %s that is a snapshot origin. " , cow_name ) ;
2014-10-04 19:17:49 +04:00
return 0 ;
2013-12-04 06:09:37 +04:00
}
if ( lv_is_merging_cow ( cow ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " Unable to split off snapshot %s being merged into its origin. " , cow_name ) ;
2014-10-04 19:17:49 +04:00
return 0 ;
2013-12-04 06:09:37 +04:00
}
if ( lv_is_virtual_origin ( origin_from_cow ( cow ) ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " Unable to split off snapshot %s with virtual origin. " , cow_name ) ;
2014-10-04 19:17:49 +04:00
return 0 ;
2013-12-04 06:09:37 +04:00
}
if ( lv_is_thin_pool ( cow ) | | lv_is_pool_metadata_spare ( cow ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " Unable to split off LV %s needed by thin volume(s). " , cow_name ) ;
2014-10-04 19:17:49 +04:00
return 0 ;
2013-12-04 06:09:37 +04:00
}
if ( ! ( vg - > fid - > fmt - > features & FMT_MDAS ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " Unable to split off snapshot %s using old LVM1-style metadata. " , cow_name ) ;
2014-10-04 19:17:49 +04:00
return 0 ;
2013-12-04 06:09:37 +04:00
}
2015-07-10 19:46:24 +03:00
if ( is_lockd_type ( vg - > lock_type ) ) {
/* FIXME: we need to create a lock for the new LV. */
2016-07-12 12:05:34 +03:00
log_error ( " Unable to split snapshots in VG with lock_type %s. " , vg - > lock_type ) ;
2015-07-10 19:46:24 +03:00
return 0 ;
}
2013-12-04 06:09:37 +04:00
if ( ! vg_check_status ( vg , LVM_WRITE ) )
2014-10-04 19:17:49 +04:00
return_0 ;
2013-12-04 06:09:37 +04:00
2014-09-16 00:33:53 +04:00
if ( lv_is_pvmove ( cow ) | | lv_is_mirror_type ( cow ) | | lv_is_raid_type ( cow ) | | lv_is_thin_type ( cow ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " LV %s type is unsupported with --splitsnapshot. " , cow_name ) ;
2014-10-04 19:17:49 +04:00
return 0 ;
2013-12-04 06:09:37 +04:00
}
2014-09-24 12:05:26 +04:00
if ( lv_is_active_locally ( cow ) ) {
2016-04-22 00:14:10 +03:00
if ( ! lv_check_not_in_use ( cow , 1 ) )
2014-10-04 19:17:49 +04:00
return_0 ;
2013-12-04 06:09:37 +04:00
2014-10-06 16:42:47 +04:00
if ( ( lp - > force = = PROMPT ) & & ! lp - > yes & &
2014-07-11 14:25:18 +04:00
lv_is_visible ( cow ) & &
lv_is_active ( cow ) ) {
if ( yes_no_prompt ( " Do you really want to split off active "
2016-03-07 12:45:50 +03:00
" logical volume %s? [y/n]: " , cow_name ) = = ' n ' ) {
log_error ( " Logical volume %s not split. " , cow_name ) ;
2014-10-04 19:17:49 +04:00
return 0 ;
2014-07-11 14:25:18 +04:00
}
}
}
2013-12-04 06:09:37 +04:00
if ( ! archive ( vg ) )
2014-10-04 19:17:49 +04:00
return_0 ;
2013-12-04 06:09:37 +04:00
2016-03-07 12:45:50 +03:00
log_verbose ( " Splitting snapshot %s from its origin. " , cow_name ) ;
2013-12-04 06:09:37 +04:00
if ( ! vg_remove_snapshot ( cow ) )
2014-10-04 19:17:49 +04:00
return_0 ;
2013-12-04 06:09:37 +04:00
backup ( vg ) ;
2016-03-07 12:45:50 +03:00
log_print_unless_silent ( " Logical Volume %s split from its origin. " , cow_name ) ;
2013-12-04 06:09:37 +04:00
2014-10-04 19:17:49 +04:00
return 1 ;
2013-12-04 06:09:37 +04:00
}
2014-10-04 17:32:24 +04:00
static int _lvconvert_split_cached ( struct cmd_context * cmd ,
struct logical_volume * lv )
{
struct logical_volume * cache_pool_lv = first_seg ( lv ) - > pool_lv ;
log_debug ( " Detaching cache pool %s from cached LV %s. " ,
display_lvname ( cache_pool_lv ) , display_lvname ( lv ) ) ;
if ( ! archive ( lv - > vg ) )
return_0 ;
if ( ! lv_cache_remove ( lv ) )
return_0 ;
if ( ! vg_write ( lv - > vg ) | | ! vg_commit ( lv - > vg ) )
return_0 ;
backup ( lv - > vg ) ;
log_print_unless_silent ( " Logical volume %s is not cached and cache pool %s is unused. " ,
display_lvname ( lv ) , display_lvname ( cache_pool_lv ) ) ;
return 1 ;
}
static int _lvconvert_uncache ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct lvconvert_params * lp )
{
2016-03-08 12:47:27 +03:00
struct lv_segment * seg ;
struct logical_volume * remove_lv ;
2014-10-04 17:32:24 +04:00
if ( lv_is_thin_pool ( lv ) )
lv = seg_lv ( first_seg ( lv ) , 0 ) ; /* cached _tdata ? */
if ( ! lv_is_cache ( lv ) ) {
log_error ( " Cannot uncache non-cached logical volume %s. " ,
display_lvname ( lv ) ) ;
return 0 ;
}
2016-03-08 12:47:27 +03:00
seg = first_seg ( lv ) ;
if ( lv_is_partial ( seg_lv ( seg , 0 ) ) ) {
log_warn ( " WARNING: Cache origin logical volume %s is missing. " ,
display_lvname ( seg_lv ( seg , 0 ) ) ) ;
remove_lv = lv ; /* When origin is missing, drop everything */
} else
remove_lv = seg - > pool_lv ;
if ( lv_is_partial ( seg_lv ( first_seg ( seg - > pool_lv ) , 0 ) ) )
log_warn ( " WARNING: Cache pool data logical volume %s is missing. " ,
display_lvname ( seg_lv ( first_seg ( seg - > pool_lv ) , 0 ) ) ) ;
if ( lv_is_partial ( first_seg ( seg - > pool_lv ) - > metadata_lv ) )
log_warn ( " WARNING: Cache pool metadata logical volume %s is missing. " ,
display_lvname ( first_seg ( seg - > pool_lv ) - > metadata_lv ) ) ;
/* TODO: Check for failed cache as well to get prompting? */
if ( lv_is_partial ( lv ) ) {
2016-04-25 14:39:30 +03:00
if ( first_seg ( seg - > pool_lv ) - > cache_mode ! = CACHE_MODE_WRITETHROUGH ) {
2016-03-08 12:47:27 +03:00
if ( ! lp - > force ) {
log_error ( " Conversion aborted. " ) ;
log_error ( " Cannot uncache writethrough cache volume %s without --force. " ,
display_lvname ( lv ) ) ;
return 0 ;
}
log_warn ( " WARNING: Uncaching of partially missing writethrough cache volume %s might destroy your data. " ,
display_lvname ( first_seg ( seg - > pool_lv ) - > metadata_lv ) ) ;
}
if ( ! lp - > yes & &
yes_no_prompt ( " Do you really want to uncache %s? with missing LVs [y/n]: " ,
display_lvname ( lv ) ) = = ' n ' ) {
log_error ( " Conversion aborted. " ) ;
return 0 ;
}
}
2016-03-15 01:19:22 +03:00
if ( lvremove_single ( cmd , remove_lv , NULL ) ! = ECMD_PROCESSED )
2014-10-04 17:32:24 +04:00
return_0 ;
2016-03-08 12:47:27 +03:00
if ( remove_lv ! = lv )
log_print_unless_silent ( " Logical volume %s is not cached. " , display_lvname ( lv ) ) ;
2014-10-04 17:32:24 +04:00
return 1 ;
}
2013-12-04 06:09:37 +04:00
static int _lvconvert_snapshot ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct lvconvert_params * lp )
2006-04-06 00:43:23 +04:00
{
struct logical_volume * org ;
2016-03-07 12:45:50 +03:00
const char * snap_name = display_lvname ( lv ) ;
2006-04-06 00:43:23 +04:00
2014-10-06 14:27:35 +04:00
if ( lv_is_cache_type ( lv ) ) {
log_error ( " Snapshots are not yet supported with cache type LVs %s. " ,
2016-03-07 12:45:50 +03:00
snap_name ) ;
2014-10-06 14:27:35 +04:00
return 0 ;
}
2014-09-16 00:33:53 +04:00
if ( lv_is_mirrored ( lv ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " Unable to convert mirrored LV %s into a snapshot. " , snap_name ) ;
2014-03-17 17:05:17 +04:00
return 0 ;
}
2014-03-17 12:41:36 +04:00
if ( lv_is_origin ( lv ) ) {
/* Unsupported stack */
2016-03-07 12:45:50 +03:00
log_error ( " Unable to convert origin %s into a snapshot. " , snap_name ) ;
2014-03-17 12:41:36 +04:00
return 0 ;
}
2014-10-06 14:27:35 +04:00
if ( lv_is_pool ( lv ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " Unable to convert pool LVs %s into a snapshot. " , snap_name ) ;
2014-09-17 19:41:58 +04:00
return 0 ;
}
2014-10-07 12:43:47 +04:00
if ( ! ( org = find_lv ( lv - > vg , lp - > origin_name ) ) ) {
2014-10-06 14:27:35 +04:00
log_error ( " Couldn't find origin volume %s in Volume group %s. " ,
2014-10-07 12:43:47 +04:00
lp - > origin_name , lv - > vg - > name ) ;
2006-04-06 00:43:23 +04:00
return 0 ;
}
2007-11-07 19:33:12 +03:00
if ( org = = lv ) {
2016-03-07 12:45:50 +03:00
log_error ( " Unable to use %s as both snapshot and origin. " , snap_name ) ;
2007-11-07 19:33:12 +03:00
return 0 ;
}
2014-03-17 16:06:00 +04:00
if ( ! cow_has_min_chunks ( lv - > vg , lv - > le_count , lp - > chunk_size ) )
return_0 ;
2014-10-06 14:27:35 +04:00
if ( lv_is_locked ( org ) | |
lv_is_cache_type ( org ) | |
lv_is_thin_type ( org ) | |
lv_is_pvmove ( org ) | |
lv_is_mirrored ( org ) | |
lv_is_cow ( org ) ) {
2011-06-01 16:24:15 +04:00
log_error ( " Unable to convert an LV into a snapshot of a %s LV. " ,
2014-09-16 00:33:53 +04:00
lv_is_locked ( org ) ? " locked " :
2014-10-06 14:27:35 +04:00
lv_is_cache_type ( org ) ? " cache type " :
lv_is_thin_type ( org ) ? " thin type " :
2014-09-16 00:33:53 +04:00
lv_is_pvmove ( org ) ? " pvmove " :
lv_is_mirrored ( org ) ? " mirrored " :
2008-06-27 01:38:58 +04:00
" snapshot " ) ;
2006-04-06 00:43:23 +04:00
return 0 ;
}
2014-07-08 00:33:31 +04:00
log_warn ( " WARNING: Converting logical volume %s to snapshot exception store. " ,
2016-03-07 12:45:50 +03:00
snap_name ) ;
2014-07-08 00:33:31 +04:00
log_warn ( " THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.) " ) ;
if ( ! lp - > yes & &
yes_no_prompt ( " Do you really want to convert %s? [y/n]: " ,
2016-03-07 12:45:50 +03:00
snap_name ) = = ' n ' ) {
2014-07-08 00:33:31 +04:00
log_error ( " Conversion aborted. " ) ;
2007-08-02 00:54:28 +04:00
return 0 ;
2006-04-06 00:43:23 +04:00
}
if ( ! deactivate_lv ( cmd , lv ) ) {
2016-03-07 12:45:50 +03:00
log_error ( " Couldn't deactivate logical volume %s. " , snap_name ) ;
2006-04-06 00:43:23 +04:00
return 0 ;
}
2014-07-08 00:33:31 +04:00
if ( ! lp - > zero | | ! ( lv - > status & LVM_WRITE ) )
2016-07-12 12:05:34 +03:00
log_warn ( " WARNING: %s not zeroed. " , snap_name ) ;
2014-07-08 00:33:31 +04:00
else {
lv - > status | = LV_TEMPORARY ;
if ( ! activate_lv_local ( cmd , lv ) | |
! wipe_lv ( lv , ( struct wipe_params ) { . do_zero = 1 } ) ) {
log_error ( " Aborting. Failed to wipe snapshot exception store. " ) ;
return 0 ;
}
lv - > status & = ~ LV_TEMPORARY ;
/* Deactivates cleared metadata LV */
if ( ! deactivate_lv_local ( lv - > vg - > cmd , lv ) ) {
log_error ( " Failed to deactivate zeroed snapshot exception store. " ) ;
return 0 ;
}
}
2014-03-17 16:07:08 +04:00
if ( ! archive ( lv - > vg ) )
return_0 ;
2009-05-14 01:21:58 +04:00
if ( ! vg_add_snapshot ( org , lv , NULL , org - > le_count , lp - > chunk_size ) ) {
2006-04-06 00:43:23 +04:00
log_error ( " Couldn't create snapshot. " ) ;
return 0 ;
}
/* store vg on disk(s) */
2014-09-09 00:48:42 +04:00
if ( ! lv_update_and_reload ( org ) )
2006-04-06 00:43:23 +04:00
return_0 ;
2016-03-07 12:45:50 +03:00
log_print_unless_silent ( " Logical volume %s converted to snapshot. " , snap_name ) ;
2012-08-02 13:38:07 +04:00
return 1 ;
2006-04-06 00:43:23 +04:00
}
2013-11-26 15:09:41 +04:00
static int _lvconvert_merge_old_snapshot ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct lvconvert_params * lp )
2010-01-13 04:45:15 +03:00
{
2010-01-13 04:54:34 +03:00
int merge_on_activate = 0 ;
2010-01-13 04:45:15 +03:00
struct logical_volume * origin = origin_from_cow ( lv ) ;
2013-07-03 00:26:03 +04:00
struct lv_segment * snap_seg = find_snapshot ( lv ) ;
2010-01-13 04:47:18 +03:00
struct lvinfo info ;
2014-06-09 14:08:27 +04:00
dm_percent_t snap_percent ;
2010-01-13 04:45:15 +03:00
/* Check if merge is possible */
2013-11-26 15:09:41 +04:00
if ( ! lv_is_cow ( lv ) ) {
log_error ( " \" %s \" is not a mergeable logical volume. " ,
lv - > name ) ;
return 0 ;
}
2010-01-13 04:55:43 +03:00
if ( lv_is_merging_cow ( lv ) ) {
2013-11-26 15:09:41 +04:00
log_error ( " Snapshot %s is already merging. " , lv - > name ) ;
2010-01-13 04:45:15 +03:00
return 0 ;
}
2013-11-26 15:09:41 +04:00
2010-01-13 04:55:43 +03:00
if ( lv_is_merging_origin ( origin ) ) {
2013-11-28 14:39:38 +04:00
log_error ( " Snapshot %s is already merging into the origin. " ,
find_snapshot ( origin ) - > cow - > name ) ;
2010-01-13 04:45:15 +03:00
return 0 ;
}
2013-11-26 15:09:41 +04:00
2013-10-12 00:47:45 +04:00
if ( lv_is_virtual_origin ( origin ) ) {
log_error ( " Snapshot %s has virtual origin. " , lv - > name ) ;
return 0 ;
}
2010-01-13 04:45:15 +03:00
2013-11-26 15:09:41 +04:00
if ( lv_is_external_origin ( origin_from_cow ( lv ) ) ) {
log_error ( " Cannot merge snapshot \" %s \" into "
" the read-only external origin \" %s \" . " ,
lv - > name , origin_from_cow ( lv ) - > name ) ;
return 0 ;
}
2014-09-23 18:49:46 +04:00
/* FIXME: test when snapshot is remotely active */
if ( lv_info ( cmd , lv , 0 , & info , 1 , 0 )
2013-11-26 15:09:41 +04:00
& & info . exists & & info . live_table & &
( ! lv_snapshot_percent ( lv , & snap_percent ) | |
2014-06-09 14:08:27 +04:00
snap_percent = = DM_PERCENT_INVALID ) ) {
2013-11-26 15:09:41 +04:00
log_error ( " Unable to merge invalidated snapshot LV \" %s \" . " ,
lv - > name ) ;
return 0 ;
}
2014-09-23 22:23:09 +04:00
if ( snap_seg - > segtype - > ops - > target_present & &
! snap_seg - > segtype - > ops - > target_present ( cmd , snap_seg , NULL ) ) {
log_error ( " Can't initialize snapshot merge. "
" Missing support in kernel? " ) ;
return 0 ;
}
2013-11-26 15:09:41 +04:00
if ( ! archive ( lv - > vg ) )
return_0 ;
2010-01-13 04:47:18 +03:00
/*
* Prevent merge with open device ( s ) as it would likely lead
2010-01-13 04:54:34 +03:00
* to application / filesystem failure . Merge on origin ' s next
* activation if either the origin or snapshot LV are currently
* open .
2010-01-13 04:47:18 +03:00
*
* FIXME testing open_count is racey ; snapshot - merge target ' s
* constructor and DM should prevent appropriate devices from
* being open .
*/
2014-09-24 12:05:26 +04:00
if ( lv_is_active_locally ( origin ) ) {
2016-04-22 00:14:10 +03:00
if ( ! lv_check_not_in_use ( origin , 0 ) ) {
log_print_unless_silent ( " Can't merge until origin volume is closed. " ) ;
2014-09-24 12:05:26 +04:00
merge_on_activate = 1 ;
2016-04-22 00:14:10 +03:00
} else if ( ! lv_check_not_in_use ( lv , 0 ) ) {
log_print_unless_silent ( " Can't merge until snapshot is closed. " ) ;
2014-09-24 12:05:26 +04:00
merge_on_activate = 1 ;
}
} else if ( vg_is_clustered ( origin - > vg ) & & lv_is_active ( origin ) ) {
/* When it's active somewhere else */
log_print_unless_silent ( " Can't check whether remotely active snapshot is open. " ) ;
2013-11-22 18:27:47 +04:00
merge_on_activate = 1 ;
2010-01-13 04:47:18 +03:00
}
2013-11-22 17:52:35 +04:00
init_snapshot_merge ( snap_seg , origin ) ;
2010-01-13 04:54:34 +03:00
if ( merge_on_activate ) {
2014-09-23 22:23:09 +04:00
/* Store and commit vg but skip starting the merge */
if ( ! vg_write ( lv - > vg ) | | ! vg_commit ( lv - > vg ) )
return_0 ;
backup ( lv - > vg ) ;
} else {
/* Perform merge */
if ( ! lv_update_and_reload ( origin ) )
2010-01-13 04:54:34 +03:00
return_0 ;
2010-01-13 04:45:15 +03:00
2014-09-23 22:23:09 +04:00
lp - > need_polling = 1 ;
lp - > lv_to_poll = origin ;
2010-01-13 04:45:15 +03:00
}
2014-09-23 22:23:09 +04:00
if ( merge_on_activate )
log_print_unless_silent ( " Merging of snapshot %s will occur on "
" next activation of %s. " ,
display_lvname ( lv ) , display_lvname ( origin ) ) ;
else
2016-07-12 12:05:34 +03:00
log_print_unless_silent ( " Merging of volume %s started. " ,
display_lvname ( lv ) ) ;
2014-09-22 16:06:52 +04:00
2014-09-23 22:23:09 +04:00
return 1 ;
2010-01-13 04:45:15 +03:00
}
2013-11-30 00:28:18 +04:00
static int _lvconvert_merge_thin_snapshot ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct lvconvert_params * lp )
{
int origin_is_active = 0 , r = 0 ;
struct lv_segment * snap_seg = first_seg ( lv ) ;
struct logical_volume * origin = snap_seg - > origin ;
if ( ! origin ) {
2015-11-14 01:38:34 +03:00
log_error ( " %s is not a mergeable logical volume. " ,
display_lvname ( lv ) ) ;
2013-11-30 00:28:18 +04:00
return 0 ;
}
/* Check if merge is possible */
if ( lv_is_merging_origin ( origin ) ) {
log_error ( " Snapshot %s is already merging into the origin. " ,
2015-11-13 13:05:00 +03:00
display_lvname ( find_snapshot ( origin ) - > lv ) ) ;
2013-11-30 00:28:18 +04:00
return 0 ;
}
if ( lv_is_external_origin ( origin ) ) {
2015-11-14 01:38:34 +03:00
if ( ! ( origin = origin_from_cow ( lv ) ) )
log_error ( INTERNAL_ERROR " %s is missing origin. " ,
display_lvname ( lv ) ) ;
else
log_error ( " %s is read-only external origin %s. " ,
display_lvname ( lv ) , display_lvname ( origin ) ) ;
2013-11-30 00:28:18 +04:00
return 0 ;
}
if ( lv_is_origin ( origin ) ) {
log_error ( " Merging into the old snapshot origin %s is not supported. " ,
2015-11-13 13:05:00 +03:00
display_lvname ( origin ) ) ;
2013-11-30 00:28:18 +04:00
return 0 ;
}
if ( ! archive ( lv - > vg ) )
return_0 ;
// FIXME: allow origin to be specified
// FIXME: verify snapshot is descendant of specified origin
/*
* Prevent merge with open device ( s ) as it would likely lead
* to application / filesystem failure . Merge on origin ' s next
* activation if either the origin or snapshot LV can ' t be
* deactivated .
*/
if ( ! deactivate_lv ( cmd , lv ) )
log_print_unless_silent ( " Delaying merge since snapshot is open. " ) ;
else if ( ( origin_is_active = lv_is_active ( origin ) ) & &
! deactivate_lv ( cmd , origin ) )
log_print_unless_silent ( " Delaying merge since origin volume is open. " ) ;
else {
/*
* Both thin snapshot and origin are inactive ,
* replace the origin LV with its snapshot LV .
*/
2015-03-12 18:23:19 +03:00
if ( ! thin_merge_finish ( cmd , origin , lv ) )
2013-11-30 00:28:18 +04:00
goto_out ;
if ( origin_is_active & & ! activate_lv ( cmd , lv ) ) {
2015-11-13 13:05:00 +03:00
log_error ( " Failed to reactivate origin %s. " ,
display_lvname ( lv ) ) ;
2013-11-30 00:28:18 +04:00
goto out ;
}
r = 1 ;
goto out ;
}
init_snapshot_merge ( snap_seg , origin ) ;
/* Commit vg, merge will start with next activation */
if ( ! vg_write ( lv - > vg ) | | ! vg_commit ( lv - > vg ) )
return_0 ;
r = 1 ;
out :
backup ( lv - > vg ) ;
2014-09-22 16:06:52 +04:00
if ( r )
log_print_unless_silent ( " Merging of thin snapshot %s will occur on "
" next activation of %s. " ,
display_lvname ( lv ) , display_lvname ( origin ) ) ;
2016-07-12 12:05:34 +03:00
2013-11-30 00:28:18 +04:00
return r ;
}
2015-11-19 15:32:03 +03:00
static int _lvconvert_thin_pool_repair ( struct cmd_context * cmd ,
struct logical_volume * pool_lv ,
struct lvconvert_params * lp )
2013-07-24 17:25:34 +04:00
{
const char * dmdir = dm_dir ( ) ;
const char * thin_dump =
find_config_tree_str_allow_empty ( cmd , global_thin_dump_executable_CFG , NULL ) ;
const char * thin_repair =
find_config_tree_str_allow_empty ( cmd , global_thin_repair_executable_CFG , NULL ) ;
const struct dm_config_node * cn ;
const struct dm_config_value * cv ;
int ret = 0 , status ;
int args = 0 ;
const char * argv [ 19 ] ; /* Max supported 10 args */
2015-07-08 12:22:24 +03:00
char * dm_name , * trans_id_str ;
2013-07-24 17:25:34 +04:00
char meta_path [ PATH_MAX ] ;
char pms_path [ PATH_MAX ] ;
uint64_t trans_id ;
struct logical_volume * pmslv ;
struct logical_volume * mlv = first_seg ( pool_lv ) - > metadata_lv ;
2013-08-06 17:21:42 +04:00
struct pipe_data pdata ;
2013-07-24 17:25:34 +04:00
FILE * f ;
2015-11-09 11:48:17 +03:00
if ( ! thin_repair | | ! thin_repair [ 0 ] ) {
2013-07-24 17:25:34 +04:00
log_error ( " Thin repair commnand is not configured. Repair is disabled. " ) ;
return 0 ; /* Checking disabled */
}
2013-08-06 17:21:42 +04:00
pmslv = pool_lv - > vg - > pool_metadata_spare_lv ;
2013-07-24 17:25:34 +04:00
/* Check we have pool metadata spare LV */
2015-09-11 21:56:02 +03:00
if ( ! handle_pool_metadata_spare ( pool_lv - > vg , 0 , lp - > pvh , 1 ) )
2013-07-24 17:25:34 +04:00
return_0 ;
2013-08-06 17:21:42 +04:00
if ( pmslv ! = pool_lv - > vg - > pool_metadata_spare_lv ) {
if ( ! vg_write ( pool_lv - > vg ) | | ! vg_commit ( pool_lv - > vg ) )
return_0 ;
pmslv = pool_lv - > vg - > pool_metadata_spare_lv ;
}
2013-07-24 17:25:34 +04:00
if ( ! ( dm_name = dm_build_dm_name ( cmd - > mem , mlv - > vg - > name ,
mlv - > name , NULL ) ) | |
( dm_snprintf ( meta_path , sizeof ( meta_path ) , " %s/%s " , dmdir , dm_name ) < 0 ) ) {
log_error ( " Failed to build thin metadata path. " ) ;
return 0 ;
}
if ( ! ( dm_name = dm_build_dm_name ( cmd - > mem , pmslv - > vg - > name ,
pmslv - > name , NULL ) ) | |
( dm_snprintf ( pms_path , sizeof ( pms_path ) , " %s/%s " , dmdir , dm_name ) < 0 ) ) {
log_error ( " Failed to build pool metadata spare path. " ) ;
return 0 ;
}
config: {thin,cache}_{check,repair}_options are never undefined
Require global/{thin,cache}_{check,repair}_options to be always defined.
If not defined directly by user in the configuration and if there's no
concrete default option to use, make "" (empty string) the default one -
it's then clearly visible in the "lvmconfig --type default" (and
generated lvm.conf) and also it makes its handling in the code more
straightforward so we don't need to handle undefined values.
This means, if there are no default values for these settings defined,
we end up with this generated now:
{thin,cache}_{check,repair}_options = [ "" ]
So the value is never undefined and if it is, it's an error.
(The cache_repair_options is actually not used in the code at the moment,
but once the code using this setting is in, it will follow the same logic
as used for thin_repair_options.)
2015-07-14 11:03:19 +03:00
if ( ! ( cn = find_config_tree_array ( cmd , global_thin_repair_options_CFG , NULL ) ) ) {
log_error ( INTERNAL_ERROR " Unable to find configuration for global/thin_repair_options " ) ;
return 0 ;
}
2015-07-08 12:22:24 +03:00
for ( cv = cn - > v ; cv & & args < 16 ; cv = cv - > next ) {
if ( cv - > type ! = DM_CFG_STRING ) {
log_error ( " Invalid string in config file: "
" global/thin_repair_options " ) ;
2013-07-24 17:25:34 +04:00
return 0 ;
}
2015-07-08 12:22:24 +03:00
argv [ + + args ] = cv - > v . str ;
2013-07-24 17:25:34 +04:00
}
if ( args = = 10 ) {
log_error ( " Too many options for thin repair command. " ) ;
return 0 ;
}
argv [ 0 ] = thin_repair ;
argv [ + + args ] = " -i " ;
argv [ + + args ] = meta_path ;
argv [ + + args ] = " -o " ;
argv [ + + args ] = pms_path ;
argv [ + + args ] = NULL ;
if ( pool_is_active ( pool_lv ) ) {
log_error ( " Only inactive pool can be repaired. " ) ;
return 0 ;
}
if ( ! activate_lv_local ( cmd , pmslv ) ) {
log_error ( " Cannot activate pool metadata spare volume %s. " ,
pmslv - > name ) ;
return 0 ;
}
if ( ! activate_lv_local ( cmd , mlv ) ) {
log_error ( " Cannot activate thin pool metadata volume %s. " ,
mlv - > name ) ;
goto deactivate_pmslv ;
}
if ( ! ( ret = exec_cmd ( cmd , ( const char * const * ) argv , & status , 1 ) ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " Repair of thin metadata volume of thin pool %s failed (status:%d). "
2013-07-24 17:25:34 +04:00
" Manual repair required! " ,
2016-07-12 12:05:34 +03:00
display_lvname ( pool_lv ) , status ) ;
2013-07-24 17:25:34 +04:00
goto deactivate_mlv ;
}
if ( thin_dump [ 0 ] ) {
2013-08-06 17:21:42 +04:00
argv [ 0 ] = thin_dump ;
argv [ 1 ] = pms_path ;
argv [ 2 ] = NULL ;
2013-07-24 17:25:34 +04:00
2013-08-06 17:21:42 +04:00
if ( ! ( f = pipe_open ( cmd , argv , 0 , & pdata ) ) )
log_warn ( " WARNING: Cannot read output from %s %s. " , thin_dump , pms_path ) ;
2013-07-24 17:25:34 +04:00
else {
/*
* Scan only the 1 st . line for transation id .
* Watch out , if the thin_dump format changes
*/
2015-08-18 16:48:05 +03:00
if ( fgets ( meta_path , sizeof ( meta_path ) , f ) & &
2013-07-24 17:25:34 +04:00
( trans_id_str = strstr ( meta_path , " transaction= \" " ) ) & &
2015-07-06 17:09:17 +03:00
( sscanf ( trans_id_str + 13 , FMTu64 , & trans_id ) = = 1 ) & &
2013-07-24 17:25:34 +04:00
( trans_id ! = first_seg ( pool_lv ) - > transaction_id ) & &
( ( trans_id - 1 ) ! = first_seg ( pool_lv ) - > transaction_id ) )
2015-07-06 17:09:17 +03:00
log_error ( " Transaction id " FMTu64 " from pool \" %s/%s \" "
2013-07-24 17:25:34 +04:00
" does not match repaired transaction id "
2015-07-06 17:09:17 +03:00
FMTu64 " from %s. " ,
2013-07-24 17:25:34 +04:00
first_seg ( pool_lv ) - > transaction_id ,
pool_lv - > vg - > name , pool_lv - > name , trans_id ,
pms_path ) ;
2013-08-06 17:21:42 +04:00
( void ) pipe_close ( & pdata ) ; /* killing pipe */
2013-07-24 17:25:34 +04:00
}
}
deactivate_mlv :
if ( ! deactivate_lv ( cmd , mlv ) ) {
log_error ( " Cannot deactivate thin pool metadata volume %s. " ,
mlv - > name ) ;
return 0 ;
}
deactivate_pmslv :
if ( ! deactivate_lv ( cmd , pmslv ) ) {
log_error ( " Cannot deactivate thin pool metadata volume %s. " ,
mlv - > name ) ;
return 0 ;
}
if ( ! ret )
return 0 ;
if ( pmslv = = pool_lv - > vg - > pool_metadata_spare_lv ) {
pool_lv - > vg - > pool_metadata_spare_lv = NULL ;
pmslv - > status & = ~ POOL_METADATA_SPARE ;
lv_set_visible ( pmslv ) ;
}
/* Try to allocate new pool metadata spare LV */
2016-01-27 14:11:03 +03:00
if ( ! handle_pool_metadata_spare ( pool_lv - > vg , 0 , lp - > pvh ,
lp - > poolmetadataspare ) )
2013-07-24 17:25:34 +04:00
stack ;
2014-06-30 13:01:04 +04:00
if ( dm_snprintf ( meta_path , sizeof ( meta_path ) , " %s_meta%%d " , pool_lv - > name ) < 0 ) {
log_error ( " Can't prepare new metadata name for %s. " , pool_lv - > name ) ;
2013-07-24 17:25:34 +04:00
return 0 ;
}
if ( ! generate_lv_name ( pool_lv - > vg , meta_path , pms_path , sizeof ( pms_path ) ) ) {
log_error ( " Can't generate new name for %s. " , meta_path ) ;
return 0 ;
}
if ( ! detach_pool_metadata_lv ( first_seg ( pool_lv ) , & mlv ) )
return_0 ;
2015-09-11 21:56:53 +03:00
/* Swap _pmspare and _tmeta name */
2015-03-12 18:23:19 +03:00
if ( ! swap_lv_identifiers ( cmd , mlv , pmslv ) )
2013-07-24 17:25:34 +04:00
return_0 ;
if ( ! attach_pool_metadata_lv ( first_seg ( pool_lv ) , pmslv ) )
return_0 ;
2015-09-11 21:56:53 +03:00
/* Used _tmeta (now _pmspare) becomes _meta%d */
2013-07-24 17:25:34 +04:00
if ( ! lv_rename_update ( cmd , mlv , pms_path , 0 ) )
return_0 ;
if ( ! vg_write ( pool_lv - > vg ) | | ! vg_commit ( pool_lv - > vg ) )
return_0 ;
2016-07-12 12:05:34 +03:00
log_warn ( " WARNING: If everything works, remove %s volume. " ,
display_lvname ( mlv ) ) ;
2013-07-24 17:25:34 +04:00
2016-07-12 12:05:34 +03:00
log_warn ( " WARNING: Use pvmove command to move %s on the best fitting PV. " ,
display_lvname ( first_seg ( pool_lv ) - > metadata_lv ) ) ;
2013-07-24 17:25:34 +04:00
return 1 ;
}
2014-07-11 14:15:23 +04:00
/* Currently converts only to thin volume with external origin */
static int _lvconvert_thin ( struct cmd_context * cmd ,
struct logical_volume * lv ,
struct lvconvert_params * lp )
2013-02-05 14:26:27 +04:00
{
2014-07-11 14:15:23 +04:00
struct logical_volume * torigin_lv , * pool_lv = lp - > pool_data_lv ;
2014-09-22 16:09:55 +04:00
struct volume_group * vg = lv - > vg ;
2013-03-08 17:12:56 +04:00
struct lvcreate_params lvc = {
2014-09-19 16:28:28 +04:00
. activate = CHANGE_AEY ,
2013-03-08 17:12:56 +04:00
. alloc = ALLOC_INHERIT ,
2014-10-07 12:43:47 +04:00
. lv_name = lp - > origin_name ,
2013-03-08 17:12:56 +04:00
. major = - 1 ,
. minor = - 1 ,
. permission = LVM_READ ,
2014-10-07 12:43:47 +04:00
. pool_name = pool_lv - > name ,
2013-03-08 17:12:56 +04:00
. pvh = & vg - > pvs ,
. read_ahead = DM_READ_AHEAD_AUTO ,
. stripes = 1 ,
2014-10-31 13:33:19 +03:00
. virtual_extents = lv - > le_count ,
2013-03-08 17:12:56 +04:00
} ;
2013-02-05 14:26:27 +04:00
2014-07-11 14:15:23 +04:00
if ( lv = = pool_lv ) {
log_error ( " Can't use same LV %s for thin pool and thin volume. " ,
display_lvname ( pool_lv ) ) ;
return 0 ;
}
2014-10-20 00:04:02 +04:00
if ( lv_is_locked ( lv ) | |
! lv_is_visible ( lv ) | |
lv_is_cache_type ( lv ) | |
2014-10-06 15:15:31 +04:00
lv_is_cow ( lv ) | |
lv_is_pool ( lv ) | |
2014-10-20 00:04:02 +04:00
lv_is_pool_data ( lv ) | |
lv_is_pool_metadata ( lv ) ) {
log_error ( " Can't use%s%s %s %s as external origin. " ,
lv_is_locked ( lv ) ? " locked " : " " ,
lv_is_visible ( lv ) ? " " : " hidden " ,
2014-10-20 20:40:39 +04:00
lvseg_name ( first_seg ( lv ) ) ,
2014-07-11 14:15:23 +04:00
display_lvname ( lv ) ) ;
return 0 ;
}
2015-03-05 23:00:44 +03:00
if ( is_lockd_type ( lv - > vg - > lock_type ) ) {
2015-07-10 21:27:02 +03:00
/*
* FIXME : external origins don ' t work in lockd VGs .
* Prior to the lvconvert , there ' s a lock associated with
* the uuid of the external origin LV . After the convert ,
* that uuid belongs to the new thin LV , and a new LV with
* a new uuid exists as the non - thin , readonly external LV .
* We ' d need to remove the lock for the previous uuid
* ( the new thin LV will have no lock ) , and create a new
* lock for the new LV uuid used by the external LV .
*/
2015-03-05 23:00:44 +03:00
log_error ( " Can't use lock_type %s LV as external origin. " ,
lv - > vg - > lock_type ) ;
return 0 ;
}
2013-02-05 14:26:27 +04:00
dm_list_init ( & lvc . tags ) ;
2014-07-11 14:15:23 +04:00
if ( ! pool_supports_external_origin ( first_seg ( pool_lv ) , lv ) )
2014-01-29 17:27:13 +04:00
return_0 ;
2015-09-22 21:04:12 +03:00
if ( ! ( lvc . segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_THIN ) ) )
2013-02-05 14:26:27 +04:00
return_0 ;
2014-07-11 14:15:23 +04:00
if ( ! archive ( vg ) )
return_0 ;
2013-02-05 14:26:27 +04:00
/* New thin LV needs to be created (all messages sent to pool) */
if ( ! ( torigin_lv = lv_create_single ( vg , & lvc ) ) )
return_0 ;
2013-03-08 17:12:56 +04:00
/* Deactivate prepared Thin LV */
2013-02-05 14:26:27 +04:00
if ( ! deactivate_lv ( cmd , torigin_lv ) ) {
log_error ( " Aborting. Unable to deactivate new LV. "
" Manual intervention required. " ) ;
return 0 ;
}
/*
* Crashing till this point will leave plain thin volume
* which could be easily removed by the user after i . e . power - off
*/
2015-03-12 18:23:19 +03:00
if ( ! swap_lv_identifiers ( cmd , torigin_lv , lv ) ) {
2013-02-05 14:26:27 +04:00
stack ;
goto revert_new_lv ;
}
/* Preserve read-write status of original LV here */
2014-07-11 14:15:23 +04:00
torigin_lv - > status | = ( lv - > status & LVM_WRITE ) ;
2013-02-05 14:26:27 +04:00
2014-07-11 14:15:23 +04:00
if ( ! attach_thin_external_origin ( first_seg ( torigin_lv ) , lv ) ) {
2013-02-05 14:26:27 +04:00
stack ;
goto revert_new_lv ;
}
2014-09-09 00:48:42 +04:00
if ( ! lv_update_and_reload ( torigin_lv ) ) {
2013-02-05 14:26:27 +04:00
stack ;
goto deactivate_and_revert_new_lv ;
}
2014-07-11 14:15:23 +04:00
log_print_unless_silent ( " Converted %s to thin volume with "
" external origin %s. " ,
display_lvname ( torigin_lv ) ,
display_lvname ( lv ) ) ;
2013-02-05 14:26:27 +04:00
return 1 ;
deactivate_and_revert_new_lv :
2015-03-12 18:23:19 +03:00
if ( ! swap_lv_identifiers ( cmd , torigin_lv , lv ) )
2013-02-05 14:26:27 +04:00
stack ;
if ( ! deactivate_lv ( cmd , torigin_lv ) ) {
log_error ( " Unable to deactivate failed new LV. "
" Manual intervention required. " ) ;
return 0 ;
}
if ( ! detach_thin_external_origin ( first_seg ( torigin_lv ) ) )
return_0 ;
revert_new_lv :
/* FIXME Better to revert to backup of metadata? */
if ( ! lv_remove ( torigin_lv ) | | ! vg_write ( vg ) | | ! vg_commit ( vg ) )
log_error ( " Manual intervention may be required to remove "
" abandoned LV(s) before retrying. " ) ;
else
backup ( vg ) ;
return 0 ;
}
2014-02-12 19:51:42 +04:00
static int _lvconvert_update_pool_params ( struct logical_volume * pool_lv ,
struct lvconvert_params * lp )
{
2014-10-30 15:04:06 +03:00
if ( lp - > pool_metadata_size & &
! ( lp - > pool_metadata_extents =
extents_from_size ( pool_lv - > vg - > cmd , lp - > pool_metadata_size , pool_lv - > vg - > extent_size ) ) )
return_0 ;
2014-07-23 00:20:18 +04:00
return update_pool_params ( lp - > segtype ,
pool_lv - > vg ,
lp - > target_attr ,
lp - > passed_args ,
pool_lv - > le_count ,
2014-10-30 15:04:06 +03:00
& lp - > pool_metadata_extents ,
2014-07-23 00:20:18 +04:00
& lp - > thin_chunk_size_calc_policy ,
& lp - > chunk_size ,
& lp - > discards ,
& lp - > zero ) ;
2014-02-12 19:51:42 +04:00
}
2012-05-14 15:57:30 +04:00
/*
2014-09-18 02:00:41 +04:00
* Converts a data lv and a metadata lv into a thin or cache pool lv .
*
2012-05-14 15:57:30 +04:00
* Thin lvconvert version which
* rename metadata
* convert / layers thinpool over data
* attach metadata
2014-09-18 02:00:41 +04:00
*
* pool_lv might or might not already be a pool .
2012-05-14 15:57:30 +04:00
*/
2014-07-11 14:15:23 +04:00
static int _lvconvert_pool ( struct cmd_context * cmd ,
struct logical_volume * pool_lv ,
struct lvconvert_params * lp )
2012-05-09 16:17:06 +04:00
{
int r = 0 ;
2012-12-02 19:40:07 +04:00
const char * old_name ;
2012-05-09 16:17:06 +04:00
struct lv_segment * seg ;
2014-07-11 14:15:23 +04:00
struct volume_group * vg = pool_lv - > vg ;
2013-10-08 15:24:22 +04:00
struct logical_volume * data_lv ;
2014-07-11 14:15:23 +04:00
struct logical_volume * metadata_lv = NULL ;
2012-12-02 19:40:07 +04:00
struct logical_volume * pool_metadata_lv ;
2015-03-05 23:00:44 +03:00
char * lockd_data_args = NULL ;
char * lockd_meta_args = NULL ;
char * lockd_data_name = NULL ;
char * lockd_meta_name = NULL ;
struct id lockd_data_id ;
struct id lockd_meta_id ;
2013-07-04 13:25:41 +04:00
char metadata_name [ NAME_LEN ] , data_name [ NAME_LEN ] ;
2013-10-16 12:11:37 +04:00
int activate_pool ;
2012-05-14 15:57:30 +04:00
2014-11-23 01:37:31 +03:00
if ( lp - > pool_data_name ) {
if ( ( lp - > thin | | lp - > cache ) & &
! strcmp ( lp - > pool_data_name , pool_lv - > name ) ) {
log_error ( " Converted volume %s and pool volume must differ. " ,
display_lvname ( pool_lv ) ) ;
return 0 ;
}
if ( ! ( pool_lv = find_lv ( vg , lp - > pool_data_name ) ) ) {
log_error ( " Unknown pool data LV %s. " , lp - > pool_data_name ) ;
return 0 ;
}
2012-11-19 16:37:57 +04:00
}
2015-03-05 23:00:44 +03:00
/* An existing LV needs to have its lock freed once it becomes a data LV. */
if ( is_lockd_type ( vg - > lock_type ) & & ! lv_is_pool ( pool_lv ) & & pool_lv - > lock_args ) {
lockd_data_args = dm_pool_strdup ( cmd - > mem , pool_lv - > lock_args ) ;
lockd_data_name = dm_pool_strdup ( cmd - > mem , pool_lv - > name ) ;
memcpy ( & lockd_data_id , & pool_lv - > lvid . id [ 1 ] , sizeof ( struct id ) ) ;
}
2014-09-22 16:15:13 +04:00
if ( ! lv_is_visible ( pool_lv ) ) {
log_error ( " Can't convert internal LV %s. " , display_lvname ( pool_lv ) ) ;
return 0 ;
}
if ( lv_is_locked ( pool_lv ) ) {
log_error ( " Can't convert locked LV %s. " , display_lvname ( pool_lv ) ) ;
2014-09-18 02:00:41 +04:00
return 0 ;
}
2014-09-22 16:15:13 +04:00
if ( lv_is_thin_pool ( pool_lv ) & & ( segtype_is_cache_pool ( lp - > segtype ) | | lp - > cache ) ) {
2014-10-06 15:44:59 +04:00
log_error ( " Can't convert thin pool LV %s. " , display_lvname ( pool_lv ) ) ;
return 0 ;
}
if ( lv_is_cache ( pool_lv ) & & ! segtype_is_thin_pool ( lp - > segtype ) ) {
log_error ( " Cached LV %s could be only converted into a thin pool volume. " ,
2014-09-18 01:31:51 +04:00
display_lvname ( pool_lv ) ) ;
return 0 ;
}
2014-09-22 16:15:13 +04:00
if ( lv_is_cache_pool ( pool_lv ) & & ( segtype_is_thin_pool ( lp - > segtype ) | | lp - > thin ) ) {
2014-10-06 15:44:59 +04:00
log_error ( " Cannot convert cache pool %s as pool data volume. " ,
2014-09-18 01:31:51 +04:00
display_lvname ( pool_lv ) ) ;
return 0 ;
}
2014-09-22 16:15:13 +04:00
if ( lv_is_mirror ( pool_lv ) ) {
log_error ( " Mirror logical volumes cannot be used as pools. " ) ;
2014-09-24 17:24:41 +04:00
log_print_unless_silent ( " Try \" %s \" segment type instead. " , SEG_TYPE_NAME_RAID1 ) ;
2014-09-22 16:15:13 +04:00
return 0 ;
}
/*
* Only linear , striped and raid supported .
* FIXME Tidy up all these type restrictions .
*/
if ( ! lv_is_pool ( pool_lv ) & &
( lv_is_thin_type ( pool_lv ) | |
lv_is_cow ( pool_lv ) | | lv_is_merging_cow ( pool_lv ) | |
lv_is_origin ( pool_lv ) | | lv_is_merging_origin ( pool_lv ) | |
lv_is_external_origin ( pool_lv ) | |
lv_is_virtual ( pool_lv ) ) ) {
log_error ( " Pool data LV %s is of an unsupported type. " , display_lvname ( pool_lv ) ) ;
return 0 ;
}
2014-10-07 12:43:47 +04:00
if ( lp - > pool_metadata_name ) {
if ( ! ( lp - > pool_metadata_lv = find_lv ( vg , lp - > pool_metadata_name ) ) ) {
log_error ( " Unknown pool metadata LV %s. " , lp - > pool_metadata_name ) ;
2014-01-28 16:21:39 +04:00
return 0 ;
}
2014-11-04 16:14:52 +03:00
lp - > pool_metadata_extents = lp - > pool_metadata_lv - > le_count ;
2014-07-11 14:15:23 +04:00
metadata_lv = lp - > pool_metadata_lv ;
2014-01-28 16:21:39 +04:00
2015-03-05 23:00:44 +03:00
/* An existing LV needs to have its lock freed once it becomes a meta LV. */
if ( is_lockd_type ( vg - > lock_type ) & & metadata_lv - > lock_args ) {
lockd_meta_args = dm_pool_strdup ( cmd - > mem , metadata_lv - > lock_args ) ;
lockd_meta_name = dm_pool_strdup ( cmd - > mem , metadata_lv - > name ) ;
memcpy ( & lockd_meta_id , & metadata_lv - > lvid . id [ 1 ] , sizeof ( struct id ) ) ;
}
2014-09-22 16:15:13 +04:00
if ( metadata_lv = = pool_lv ) {
log_error ( " Can't use same LV for pool data and metadata LV %s. " ,
2014-07-11 14:15:23 +04:00
display_lvname ( metadata_lv ) ) ;
2013-02-05 14:26:27 +04:00
return 0 ;
}
2014-09-18 02:00:41 +04:00
2014-09-22 16:15:13 +04:00
if ( ! lv_is_visible ( metadata_lv ) ) {
log_error ( " Can't convert internal LV %s. " ,
display_lvname ( metadata_lv ) ) ;
2014-07-11 14:15:23 +04:00
return 0 ;
}
2014-09-18 02:00:41 +04:00
2014-09-16 00:33:53 +04:00
if ( lv_is_locked ( metadata_lv ) ) {
2014-07-11 14:15:23 +04:00
log_error ( " Can't convert locked LV %s. " ,
display_lvname ( metadata_lv ) ) ;
return 0 ;
}
2014-09-18 02:00:41 +04:00
2014-09-22 16:15:13 +04:00
if ( lv_is_mirror ( metadata_lv ) ) {
log_error ( " Mirror logical volumes cannot be used for pool metadata. " ) ;
2014-09-24 17:24:41 +04:00
log_print_unless_silent ( " Try \" %s \" segment type instead. " , SEG_TYPE_NAME_RAID1 ) ;
2013-08-10 01:04:30 +04:00
return 0 ;
}
2014-09-18 02:00:41 +04:00
/* FIXME Tidy up all these type restrictions. */
2014-09-22 16:15:13 +04:00
if ( lv_is_cache_type ( metadata_lv ) | |
lv_is_thin_type ( metadata_lv ) | |
lv_is_cow ( metadata_lv ) | | lv_is_merging_cow ( metadata_lv ) | |
lv_is_origin ( metadata_lv ) | | lv_is_merging_origin ( metadata_lv ) | |
lv_is_external_origin ( metadata_lv ) | |
lv_is_virtual ( metadata_lv ) ) {
2014-09-18 02:00:41 +04:00
log_error ( " Pool metadata LV %s is of an unsupported type. " ,
display_lvname ( metadata_lv ) ) ;
return 0 ;
}
2014-07-11 14:15:23 +04:00
if ( ! lv_is_pool ( pool_lv ) ) {
if ( ! _lvconvert_update_pool_params ( pool_lv , lp ) )
return_0 ;
2014-11-04 16:14:52 +03:00
if ( lp - > pool_metadata_extents > metadata_lv - > le_count ) {
2014-07-11 14:15:23 +04:00
log_error ( " Logical volume %s is too small for metadata. " ,
display_lvname ( metadata_lv ) ) ;
return 0 ;
}
2013-02-05 14:26:27 +04:00
}
}
2014-07-11 14:15:23 +04:00
if ( lv_is_pool ( pool_lv ) ) {
lp - > pool_data_lv = pool_lv ;
2013-07-04 13:25:41 +04:00
2014-07-11 14:15:23 +04:00
if ( ! metadata_lv ) {
2014-07-18 23:56:37 +04:00
if ( arg_from_list_is_set ( cmd , " is invalid with existing pool " ,
2015-08-25 15:48:31 +03:00
chunksize_ARG , discards_ARG ,
2014-07-18 23:56:37 +04:00
zero_ARG , poolmetadatasize_ARG , - 1 ) )
2014-07-11 14:15:23 +04:00
return_0 ;
2014-09-22 16:15:13 +04:00
if ( lp - > thin | | lp - > cache )
/* already pool, can continue converting volume */
return 1 ;
log_error ( " LV %s is already pool. " , display_lvname ( pool_lv ) ) ;
return 0 ;
2012-05-09 16:17:06 +04:00
}
2014-07-11 14:15:23 +04:00
if ( lp - > thin | | lp - > cache ) {
log_error ( " --%s and pool metadata swap is not supported. " ,
lp - > thin ? " thin " : " cache " ) ;
2012-05-14 15:57:30 +04:00
return 0 ;
2012-05-09 16:17:06 +04:00
}
2014-07-11 14:15:23 +04:00
/* FIXME cache pool */
if ( lv_is_thin_pool ( pool_lv ) & & pool_is_active ( pool_lv ) ) {
/* If any volume referencing pool active - abort here */
log_error ( " Cannot convert pool %s with active volumes. " ,
display_lvname ( pool_lv ) ) ;
2012-05-14 15:57:30 +04:00
return 0 ;
2012-05-09 16:17:06 +04:00
}
2012-12-02 19:40:07 +04:00
2015-01-28 17:12:38 +03:00
lp - > passed_args | = PASS_ARG_CHUNK_SIZE | PASS_ARG_DISCARDS | PASS_ARG_ZERO ;
2014-07-11 14:15:23 +04:00
seg = first_seg ( pool_lv ) ;
2014-07-01 13:06:36 +04:00
2014-07-11 14:15:23 +04:00
/* Normally do NOT change chunk size when swapping */
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , chunksize_ARG ) & &
2014-11-03 16:00:09 +03:00
( lp - > chunk_size ! = seg - > chunk_size ) & &
! dm_list_empty ( & pool_lv - > segs_using_this_lv ) ) {
2014-07-11 14:15:23 +04:00
if ( lp - > force = = PROMPT ) {
log_error ( " Chunk size can be only changed with --force. Conversion aborted. " ) ;
return 0 ;
2012-12-02 19:40:07 +04:00
}
2014-07-11 14:15:23 +04:00
log_warn ( " WARNING: Changing chunk size %s to "
" %s for %s pool volume. " ,
display_size ( cmd , seg - > chunk_size ) ,
display_size ( cmd , lp - > chunk_size ) ,
display_lvname ( pool_lv ) ) ;
/* Ok, user has likely some serious reason for this */
2014-07-01 13:06:36 +04:00
if ( ! lp - > yes & &
2014-07-11 14:15:23 +04:00
yes_no_prompt ( " Do you really want to change chunk size "
" for %s pool volume? [y/n]: " ,
display_lvname ( pool_lv ) ) = = ' n ' ) {
2014-07-01 13:06:36 +04:00
log_error ( " Conversion aborted. " ) ;
return 0 ;
}
2014-07-11 14:15:23 +04:00
} else
lp - > chunk_size = seg - > chunk_size ;
2014-07-01 13:06:36 +04:00
2014-07-11 14:15:23 +04:00
if ( ! _lvconvert_update_pool_params ( pool_lv , lp ) )
return_0 ;
2014-07-01 13:06:36 +04:00
2014-11-04 16:14:52 +03:00
if ( metadata_lv - > le_count < lp - > pool_metadata_extents )
2014-07-11 14:15:23 +04:00
log_print_unless_silent ( " Continuing with swap... " ) ;
2012-12-02 19:40:07 +04:00
2016-06-22 00:24:52 +03:00
if ( ! arg_is_set ( cmd , discards_ARG ) )
2014-07-11 14:15:23 +04:00
lp - > discards = seg - > discards ;
2016-06-22 00:24:52 +03:00
if ( ! arg_is_set ( cmd , zero_ARG ) )
2014-07-11 14:15:23 +04:00
lp - > zero = seg - > zero_new_blocks ;
2012-12-02 19:40:07 +04:00
2014-07-11 14:15:23 +04:00
if ( ! lp - > yes & &
yes_no_prompt ( " Do you want to swap metadata of %s "
2014-08-19 16:16:39 +04:00
" pool with metadata volume %s? [y/n]: " ,
2014-07-11 14:15:23 +04:00
display_lvname ( pool_lv ) ,
display_lvname ( metadata_lv ) ) = = ' n ' ) {
log_error ( " Conversion aborted. " ) ;
2014-05-20 18:21:14 +04:00
return 0 ;
}
2014-07-11 14:15:23 +04:00
} else {
log_warn ( " WARNING: Converting logical volume %s%s%s to pool's data%s. " ,
display_lvname ( pool_lv ) ,
metadata_lv ? " and " : " " ,
metadata_lv ? display_lvname ( metadata_lv ) : " " ,
metadata_lv ? " and metadata volumes " : " volume " ) ;
log_warn ( " THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.) " ) ;
2014-05-20 18:21:14 +04:00
2014-07-11 14:15:23 +04:00
if ( ! lp - > yes & &
yes_no_prompt ( " Do you really want to convert %s%s%s? [y/n]: " ,
display_lvname ( pool_lv ) ,
metadata_lv ? " and " : " " ,
metadata_lv ? display_lvname ( metadata_lv ) : " " ) = = ' n ' ) {
log_error ( " Conversion aborted. " ) ;
2012-05-14 15:57:30 +04:00
return 0 ;
2012-05-09 16:17:06 +04:00
}
2014-07-11 14:15:23 +04:00
}
2014-07-01 13:06:36 +04:00
2014-07-11 14:15:23 +04:00
if ( segtype_is_cache_pool ( lp - > segtype ) )
activate_pool = 0 ; /* Cannot activate cache pool */
else
/* Allow to have only thinpool active and restore it's active state */
activate_pool = lv_is_active ( pool_lv ) ;
2014-09-22 16:15:13 +04:00
if ( ( dm_snprintf ( metadata_name , sizeof ( metadata_name ) , " %s%s " ,
pool_lv - > name ,
( segtype_is_cache_pool ( lp - > segtype ) ) ?
" _cmeta " : " _tmeta " ) < 0 ) | |
( dm_snprintf ( data_name , sizeof ( data_name ) , " %s%s " ,
pool_lv - > name ,
( segtype_is_cache_pool ( lp - > segtype ) ) ?
" _cdata " : " _tdata " ) < 0 ) ) {
log_error ( " Failed to create internal lv names, "
" pool name is too long. " ) ;
return 0 ;
}
2014-07-11 14:15:23 +04:00
if ( ! metadata_lv ) {
2014-02-12 19:51:42 +04:00
if ( ! _lvconvert_update_pool_params ( pool_lv , lp ) )
2012-11-19 16:37:57 +04:00
return_0 ;
2013-10-29 16:18:14 +04:00
2014-07-11 14:15:23 +04:00
if ( ! get_stripe_params ( cmd , & lp - > stripes , & lp - > stripe_size ) )
return_0 ;
2014-07-01 13:06:36 +04:00
2014-07-11 14:15:23 +04:00
if ( ! archive ( vg ) )
return_0 ;
if ( ! ( metadata_lv = alloc_pool_metadata ( pool_lv , metadata_name ,
lp - > read_ahead , lp - > stripes ,
lp - > stripe_size ,
2014-10-30 15:04:06 +03:00
lp - > pool_metadata_extents ,
2014-07-11 14:15:23 +04:00
lp - > alloc , lp - > pvh ) ) )
return_0 ;
} else {
if ( ! deactivate_lv ( cmd , metadata_lv ) ) {
log_error ( " Aborting. Failed to deactivate %s. " ,
display_lvname ( metadata_lv ) ) ;
2014-07-01 13:06:36 +04:00
return 0 ;
}
2014-07-11 14:15:23 +04:00
if ( ! archive ( vg ) )
return_0 ;
/* Swap normal LV with pool's metadata LV ? */
if ( lv_is_pool ( pool_lv ) ) {
/* Swap names between old and new metadata LV */
2014-07-11 16:19:22 +04:00
seg = first_seg ( pool_lv ) ;
if ( ! detach_pool_metadata_lv ( seg , & pool_metadata_lv ) )
2014-07-11 14:15:23 +04:00
return_0 ;
old_name = metadata_lv - > name ;
if ( ! lv_rename_update ( cmd , metadata_lv , " pvmove_tmeta " , 0 ) )
return_0 ;
if ( ! lv_rename_update ( cmd , pool_metadata_lv , old_name , 0 ) )
return_0 ;
goto mda_write ;
}
2013-10-29 16:18:14 +04:00
metadata_lv - > status | = LV_TEMPORARY ;
if ( ! activate_lv_local ( cmd , metadata_lv ) ) {
2014-02-12 19:51:42 +04:00
log_error ( " Aborting. Failed to activate metadata lv. " ) ;
2013-10-29 16:18:14 +04:00
return 0 ;
}
2013-11-06 19:16:34 +04:00
2013-11-28 14:22:24 +04:00
if ( ! wipe_lv ( metadata_lv , ( struct wipe_params ) { . do_zero = 1 } ) ) {
2014-02-12 19:51:42 +04:00
log_error ( " Aborting. Failed to wipe metadata lv. " ) ;
2013-10-29 16:18:14 +04:00
return 0 ;
}
2012-05-14 15:57:30 +04:00
}
2014-07-11 14:15:23 +04:00
/* We are changing target type, so deactivate first */
2012-05-14 15:57:30 +04:00
if ( ! deactivate_lv ( cmd , metadata_lv ) ) {
2014-02-12 19:51:42 +04:00
log_error ( " Aborting. Failed to deactivate metadata lv. "
2012-05-14 15:57:30 +04:00
" Manual intervention required. " ) ;
return 0 ;
}
2014-07-11 14:15:23 +04:00
if ( ! deactivate_lv ( cmd , pool_lv ) ) {
log_error ( " Aborting. Failed to deactivate logical volume %s. " ,
display_lvname ( pool_lv ) ) ;
return 0 ;
2014-07-01 13:06:36 +04:00
}
data_lv = pool_lv ;
2013-03-11 12:49:10 +04:00
old_name = data_lv - > name ; /* Use for pool name */
2012-05-14 15:57:30 +04:00
/*
2014-02-12 19:51:42 +04:00
* Since we wish to have underlaying devs to match _ [ ct ] data
2013-03-11 12:49:10 +04:00
* rename data LV to match pool LV subtree first ,
* also checks for visible LV .
2012-05-14 15:57:30 +04:00
*/
/* FIXME: any more types prohibited here? */
2013-03-11 12:49:10 +04:00
if ( ! lv_rename_update ( cmd , data_lv , data_name , 0 ) )
return_0 ;
2012-05-14 15:57:30 +04:00
2013-03-11 12:49:10 +04:00
if ( ! ( pool_lv = lv_create_empty ( old_name , NULL ,
2014-02-12 19:51:42 +04:00
( ( segtype_is_cache_pool ( lp - > segtype ) ) ?
CACHE_POOL : THIN_POOL ) |
VISIBLE_LV | LVM_READ | LVM_WRITE ,
2014-07-11 14:15:23 +04:00
ALLOC_INHERIT , vg ) ) ) {
2013-03-11 12:49:10 +04:00
log_error ( " Creation of pool LV failed. " ) ;
return 0 ;
}
2014-07-11 14:15:23 +04:00
/* Allocate a new pool segment */
2013-03-11 12:49:10 +04:00
if ( ! ( seg = alloc_lv_segment ( lp - > segtype , pool_lv , 0 , data_lv - > le_count ,
2014-10-26 10:13:59 +03:00
pool_lv - > status , 0 , NULL , 1 ,
2014-02-12 19:51:42 +04:00
data_lv - > le_count , 0 , 0 , 0 , NULL ) ) )
2012-05-09 16:17:06 +04:00
return_0 ;
2013-03-11 12:49:10 +04:00
/* Add the new segment to the layer LV */
dm_list_add ( & pool_lv - > segments , & seg - > list ) ;
pool_lv - > le_count = data_lv - > le_count ;
pool_lv - > size = data_lv - > size ;
2012-05-09 16:17:06 +04:00
2012-12-02 19:27:39 +04:00
if ( ! attach_pool_data_lv ( seg , data_lv ) )
return_0 ;
2015-03-05 23:00:44 +03:00
/*
2015-07-15 21:02:54 +03:00
* Create a new lock for a thin pool LV . A cache pool LV has no lock .
2015-03-05 23:00:44 +03:00
* Locks are removed from existing LVs that are being converted to
* data and meta LVs ( they are unlocked and deleted below . )
*/
if ( is_lockd_type ( vg - > lock_type ) ) {
if ( segtype_is_cache_pool ( lp - > segtype ) ) {
data_lv - > lock_args = NULL ;
metadata_lv - > lock_args = NULL ;
} else {
data_lv - > lock_args = NULL ;
metadata_lv - > lock_args = NULL ;
if ( ! strcmp ( vg - > lock_type , " sanlock " ) )
pool_lv - > lock_args = " pending " ;
else if ( ! strcmp ( vg - > lock_type , " dlm " ) )
pool_lv - > lock_args = " dlm " ;
/* The lock_args will be set in vg_write(). */
}
}
2013-03-11 12:49:10 +04:00
/* FIXME: revert renamed LVs in fail path? */
/* FIXME: any common code with metadata/thin_manip.c extend_pool() ? */
2012-05-14 15:57:30 +04:00
seg - > transaction_id = 0 ;
2012-12-02 19:40:07 +04:00
mda_write :
2012-12-02 19:27:39 +04:00
seg - > chunk_size = lp - > chunk_size ;
seg - > discards = lp - > discards ;
seg - > zero_new_blocks = lp - > zero ? 1 : 0 ;
2012-05-09 16:17:06 +04:00
2015-08-25 15:48:31 +03:00
if ( lp - > cache_mode & &
2016-04-25 14:39:30 +03:00
! cache_set_cache_mode ( seg , lp - > cache_mode ) )
2015-08-25 15:48:31 +03:00
return_0 ;
2015-07-15 12:06:40 +03:00
if ( ( lp - > policy_name | | lp - > policy_settings ) & &
2015-08-11 15:01:12 +03:00
! cache_set_policy ( seg , lp - > policy_name , lp - > policy_settings ) )
2015-07-15 12:06:40 +03:00
return_0 ;
2012-12-02 19:27:39 +04:00
/* Rename deactivated metadata LV to have _tmeta suffix */
/* Implicit checks if metadata_lv is visible */
2014-10-07 12:43:47 +04:00
if ( lp - > pool_metadata_name & &
2013-03-11 12:49:10 +04:00
! lv_rename_update ( cmd , metadata_lv , metadata_name , 0 ) )
2012-05-09 16:17:06 +04:00
return_0 ;
2012-12-02 19:27:39 +04:00
if ( ! attach_pool_metadata_lv ( seg , metadata_lv ) )
2012-05-09 16:17:06 +04:00
return_0 ;
2014-07-11 14:15:23 +04:00
if ( ! handle_pool_metadata_spare ( vg , metadata_lv - > le_count ,
lp - > pvh , lp - > poolmetadataspare ) )
2012-05-09 16:17:06 +04:00
return_0 ;
2014-07-11 14:15:23 +04:00
if ( ! vg_write ( vg ) | | ! vg_commit ( vg ) )
return_0 ;
if ( seg - > zero_new_blocks & &
seg - > chunk_size > = DEFAULT_THIN_POOL_CHUNK_SIZE_PERFORMANCE * 2 )
log_warn ( " WARNING: Pool zeroing and large %s chunk size slows down "
" provisioning. " , display_size ( cmd , seg - > chunk_size ) ) ;
2015-03-05 23:00:44 +03:00
if ( activate_pool & & ! lockd_lv ( cmd , pool_lv , " ex " , LDLV_PERSISTENT ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " Failed to lock pool LV %s. " , display_lvname ( pool_lv ) ) ;
2015-03-05 23:00:44 +03:00
goto out ;
}
2013-10-16 12:11:37 +04:00
if ( activate_pool & &
! activate_lv_excl ( cmd , pool_lv ) ) {
2014-07-11 14:15:23 +04:00
log_error ( " Failed to activate pool logical volume %s. " ,
display_lvname ( pool_lv ) ) ;
2012-12-02 19:31:27 +04:00
/* Deactivate subvolumes */
if ( ! deactivate_lv ( cmd , seg_lv ( seg , 0 ) ) )
2016-07-12 12:05:34 +03:00
log_error ( " Failed to deactivate pool data logical volume %s. " ,
display_lvname ( seg_lv ( seg , 0 ) ) ) ;
2012-12-02 19:31:27 +04:00
if ( ! deactivate_lv ( cmd , seg - > metadata_lv ) )
2016-07-12 12:05:34 +03:00
log_error ( " Failed to deactivate pool metadata logical volume %s. " ,
display_lvname ( seg - > metadata_lv ) ) ;
2012-05-09 16:17:06 +04:00
goto out ;
}
r = 1 ;
2014-07-11 14:15:23 +04:00
lp - > pool_data_lv = pool_lv ;
out :
backup ( vg ) ;
2013-02-05 14:26:27 +04:00
2014-09-22 16:06:52 +04:00
if ( r )
log_print_unless_silent ( " Converted %s to %s pool. " ,
display_lvname ( pool_lv ) ,
( segtype_is_cache_pool ( lp - > segtype ) ) ?
" cache " : " thin " ) ;
2015-03-05 23:00:44 +03:00
/*
* Unlock and free the locks from existing LVs that became pool data
* and meta LVs .
*/
if ( lockd_data_name ) {
if ( ! lockd_lv_name ( cmd , vg , lockd_data_name , & lockd_data_id , lockd_data_args , " un " , LDLV_PERSISTENT ) )
log_error ( " Failed to unlock pool data LV %s/%s " , vg - > name , lockd_data_name ) ;
lockd_free_lv ( cmd , vg , lockd_data_name , & lockd_data_id , lockd_data_args ) ;
}
if ( lockd_meta_name ) {
if ( ! lockd_lv_name ( cmd , vg , lockd_meta_name , & lockd_meta_id , lockd_meta_args , " un " , LDLV_PERSISTENT ) )
log_error ( " Failed to unlock pool metadata LV %s/%s " , vg - > name , lockd_meta_name ) ;
lockd_free_lv ( cmd , vg , lockd_meta_name , & lockd_meta_id , lockd_meta_args ) ;
}
2012-05-09 16:17:06 +04:00
return r ;
2014-07-11 14:15:23 +04:00
#if 0
revert_new_lv :
2016-07-12 12:05:34 +03:00
/* TBD */
2014-07-11 14:15:23 +04:00
if ( ! lp - > pool_metadata_lv_name ) {
if ( ! deactivate_lv ( cmd , metadata_lv ) ) {
log_error ( " Failed to deactivate metadata lv. " ) ;
return 0 ;
}
if ( ! lv_remove ( metadata_lv ) | | ! vg_write ( vg ) | | ! vg_commit ( vg ) )
log_error ( " Manual intervention may be required to remove "
" abandoned LV(s) before retrying. " ) ;
else
backup ( vg ) ;
}
return 0 ;
# endif
2012-05-09 16:17:06 +04:00
}
2014-09-18 02:00:41 +04:00
/*
* Convert origin into a cache LV by attaching a cache pool .
*/
2014-07-11 14:15:23 +04:00
static int _lvconvert_cache ( struct cmd_context * cmd ,
2014-10-03 20:52:08 +04:00
struct logical_volume * origin_lv ,
2014-02-12 19:55:35 +04:00
struct lvconvert_params * lp )
{
2014-07-11 14:15:23 +04:00
struct logical_volume * pool_lv = lp - > pool_data_lv ;
2014-02-12 19:55:35 +04:00
struct logical_volume * cache_lv ;
2014-11-02 19:03:14 +03:00
if ( ! validate_lv_cache_create_pool ( pool_lv ) )
2014-10-03 20:52:08 +04:00
return_0 ;
2014-09-18 02:00:41 +04:00
2014-10-03 20:52:08 +04:00
if ( ! archive ( origin_lv - > vg ) )
2014-02-12 19:55:35 +04:00
return_0 ;
2014-10-03 20:52:08 +04:00
if ( ! ( cache_lv = lv_cache_create ( pool_lv , origin_lv ) ) )
2014-02-12 19:55:35 +04:00
return_0 ;
2014-07-11 14:15:23 +04:00
2016-04-25 14:39:30 +03:00
if ( ! cache_set_cache_mode ( first_seg ( cache_lv ) , lp - > cache_mode ) )
2015-08-11 15:01:12 +03:00
return_0 ;
if ( ! cache_set_policy ( first_seg ( cache_lv ) , lp - > policy_name , lp - > policy_settings ) )
return_0 ;
2015-09-10 16:07:59 +03:00
cache_check_for_warns ( first_seg ( cache_lv ) ) ;
2014-09-09 00:48:42 +04:00
if ( ! lv_update_and_reload ( cache_lv ) )
2014-02-12 19:55:35 +04:00
return_0 ;
2014-07-11 14:15:23 +04:00
log_print_unless_silent ( " Logical volume %s is now cached. " ,
display_lvname ( cache_lv ) ) ;
2014-02-12 19:55:35 +04:00
return 1 ;
}
2016-06-28 20:24:41 +03:00
/*
* Functions called to perform a specific operation on a specific LV type .
*
* _convert_ < lvtype > _ < operation >
*
* For cases where an operation does not apply to the LV itself , but
* is implicitly redirected to a sub - LV , these functions locate the
* correct sub - LV and call the operation on that sub - LV . If a sub - LV
* of the proper type is not found , these functions report the error .
*
* FIXME : the _lvconvert_foo ( ) functions can be cleaned up since they
* are now only called for valid combinations of LV type and operation .
* After that happens , the code remaining in those functions can be
* moved into the _convert_lvtype_operation ( ) functions below .
*/
2016-06-30 20:02:43 +03:00
/*
* Separate a COW snapshot LV from its origin .
* lvconvert - - splitsnapshot LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_cow_snapshot_splitsnapshot ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_splitsnapshot ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Merge a COW snapshot LV into its origin .
* lvconvert - - merge LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_cow_snapshot_merge ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_merge_old_snapshot ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Merge a snapshot thin LV into its origin .
* lvconvert - - merge LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_thin_volume_merge ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_merge_thin_snapshot ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Split and preserve a cache pool from the data portion of a thin pool LV .
* lvconvert - - splitcache LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_thin_pool_splitcache ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
struct logical_volume * sublv1 ;
sublv1 = seg_lv ( first_seg ( lv ) , 0 ) ; /* cached _tdata ? */
if ( ! lv_is_cache ( sublv1 ) ) {
log_error ( " Sub LV %s must be cache. " , display_lvname ( sublv1 ) ) ;
return 0 ;
}
return _lvconvert_split_cached ( cmd , sublv1 ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Split and remove a cache pool from the data portion of a thin pool LV .
* lvconvert - - uncache LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_thin_pool_uncache ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
struct logical_volume * sublv1 = NULL ;
sublv1 = seg_lv ( first_seg ( lv ) , 0 ) ; /* cached _tdata ? */
if ( ! lv_is_cache ( sublv1 ) ) {
log_error ( " Sub LV %s must be cache. " , display_lvname ( sublv1 ) ) ;
return 0 ;
}
return _lvconvert_uncache ( cmd , sublv1 , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Repair a thin pool LV .
* lvconvert - - repair LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_thin_pool_repair ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_thin_pool_repair ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert the data portion of a thin pool LV to a cache LV .
* lvconvert - - type cache LV
*
* Required options :
* - - cachepool LV
*
* Auxiliary operation :
* Converts the - - cachepool arg to a cache pool if it is not already .
*
* Alternate syntax :
* lvconvert - - cache LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_thin_pool_cache ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
2016-06-30 20:02:43 +03:00
/* lvconvert --type cache includes an implicit conversion of the cachepool arg to type cache-pool. */
2016-06-28 20:24:41 +03:00
if ( ! _lvconvert_pool ( cmd , lv , lp ) ) {
log_error ( " Implicit conversion of --cachepool arg to type cache-pool failed. " ) ;
return 0 ;
}
/* Do we need to grab the tdata sub LV to pass on? */
return _lvconvert_cache ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Replace the metadata LV in a thin pool LV .
* lvconvert - - poolmetadata NewLV - - thinpool LV
* FIXME : this will change so - - swap - poolmetadata defines the operation .
* FIXME : should be lvconvert - - swap - poolmetadata NewLV LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_thin_pool_swapmetadata ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_pool ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Split and preserve a cache pool from a cache LV .
* lvconvert - - splitcache LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_cache_volume_splitcache ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_split_cached ( cmd , lv ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Split and remove a cache pool from a cache LV .
* lvconvert - - uncache LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_cache_volume_uncache ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_uncache ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Split images from the raid1 | mirror origin of a cache LV and use them to create a new LV .
* lvconvert - - splitmirrors Number LV
*
* Required options :
* - - trackchanges | - - name Name
*/
2016-06-28 20:24:41 +03:00
static int _convert_cache_volume_splitmirrors ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
struct logical_volume * sublv1 ;
sublv1 = seg_lv ( first_seg ( lv ) , 0 ) ;
if ( lv_is_raid ( sublv1 ) )
return _lvconvert_raid ( sublv1 , lp ) ;
if ( lv_is_mirror ( sublv1 ) )
return _lvconvert_mirrors ( cmd , lv , lp ) ;
log_error ( " Sub LV %s must be raid or mirror. " , display_lvname ( sublv1 ) ) ;
return 0 ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a cache LV to a thin pool ( using the cache LV for thin pool data ) .
* lvconvert - - type thin - pool LV
*
* Alternate syntax :
* This is equivalent to above , but not preferred because it ' s ambiguous and inconsistent .
* lvconvert - - thinpool LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_cache_volume_thin_pool ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_pool ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Split a cache volume from a cache pool LV .
* lvconvert - - splitcache LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_cache_pool_splitcache ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
struct logical_volume * sublv1 ;
struct lv_segment * seg ;
/* When passed used cache-pool of used cached LV -> split cached LV */
if ( ( dm_list_size ( & lv - > segs_using_this_lv ) = = 1 ) & &
( seg = get_only_segment_using_this_lv ( lv ) ) & &
seg_is_cache ( seg ) )
sublv1 = seg - > lv ;
else {
log_error ( " Sub LV of cache type not found. " ) ;
return 0 ;
}
if ( ! lv_is_cache ( sublv1 ) ) {
log_error ( " Sub LV %s must be cache. " , display_lvname ( sublv1 ) ) ;
return 0 ;
}
return _lvconvert_split_cached ( cmd , sublv1 ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Replace the metadata LV in a cache pool LV .
* lvconvert - - poolmetadata NewLV - - cachepool LV
* FIXME : this will change so - - swap - poolmetadata defines the operation .
* FIXME : should be lvconvert - - swap - poolmetadata NewLV LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_cache_pool_swapmetadata ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_pool ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Change the number of images in a mirror LV .
* lvconvert - - mirrors Number LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_mirror_number ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_mirrors ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Split images from a mirror LV and use them to create a new LV .
* lvconvert - - splitmirrors Number LV
*
* Required options :
* - - name Name
*/
2016-06-28 20:24:41 +03:00
static int _convert_mirror_splitmirrors ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_mirrors ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Change the type of log used by a mirror LV .
* lvconvert - - mirrorlog Type LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_mirror_log ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_mirrors ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Replace failed PVs in a mirror LV .
* lvconvert - - repair LV
*
* Auxiliary operation :
* Removes missing , empty PVs from the VG , like vgreduce .
*/
2016-06-28 20:24:41 +03:00
static int _convert_mirror_repair ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
struct dm_list * failed_pvs ;
int ret ;
ret = _lvconvert_mirrors_repair ( cmd , lv , lp ) ;
if ( ret & & arg_is_set ( cmd , usepolicies_ARG ) ) {
if ( ( failed_pvs = _failed_pv_list ( lv - > vg ) ) )
_remove_missing_empty_pv ( lv - > vg , failed_pvs ) ;
}
return ret ;
}
2016-07-07 00:33:25 +03:00
/*
* Convert mirror LV to linear LV .
* lvconvert - - type linear LV
*
* Alternate syntax :
* lvconvert - - mirrors 0 LV
*/
static int _convert_mirror_linear ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-07-07 00:33:25 +03:00
{
return _lvconvert_mirrors ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert mirror LV to raid1 LV .
* lvconvert - - type raid1 LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_mirror_raid ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Change the number of images in a raid1 LV .
* lvconvert - - mirrors Number LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_number ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Split images from a raid1 LV and use them to create a new LV .
* lvconvert - - splitmirrors Number LV
*
* Required options :
* - - trackchanges | - - name Name
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_splitmirrors ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
/* FIXME: split the splitmirrors section out of _lvconvert_raid and call it here. */
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Merge a raid1 LV into originalLV if the raid1 LV was
* previously split from the originalLV using - - trackchanges .
* lvconvert - - merge LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_merge ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
/* FIXME: split the merge section out of _lvconvert_raid and call it here. */
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Replace failed PVs in a raid * LV .
* lvconvert - - repair LV
*
* Auxiliary operation :
* Removes missing , empty PVs from the VG , like vgreduce .
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_repair ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
struct dm_list * failed_pvs ;
int ret ;
/* FIXME: split the repair section out of _lvconvert_raid and call it here. */
ret = _lvconvert_raid ( lv , lp ) ;
if ( ret & & arg_is_set ( cmd , usepolicies_ARG ) ) {
if ( ( failed_pvs = _failed_pv_list ( lv - > vg ) ) )
_remove_missing_empty_pv ( lv - > vg , failed_pvs ) ;
}
return ret ;
}
2016-06-30 20:02:43 +03:00
/*
* Replace a specific PV in a raid * LV with another PV .
2016-07-12 12:05:34 +03:00
* lvconvert - - replace PV LV
2016-06-30 20:02:43 +03:00
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_replace ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
/* FIXME: remove the replace section from _lvconvert_raid */
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Combine a raid * LV with a snapshot LV that was previously
* split from the raid * LV using - - splitsnapshot .
* lvconvert - - type snapshot LV SnapshotLV
*
* Alternate syntax :
* lvconvert - - snapshot LV SnapshotLV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_snapshot ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_snapshot ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a raid * LV to a thin LV with an external origin .
* lvconvert - - type thin LV
*
* Required options :
* - - thinpool LV
*
* Auxiliary operation :
* Converts the - - thinpool arg to a thin pool if it is not already .
*
* Alternate syntax :
* lvconvert - - thin LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_thin ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
/* lvconvert --thin includes an implicit conversion of the thinpool arg to type thin-pool. */
if ( ! _lvconvert_pool ( cmd , lv , lp ) ) {
log_error ( " Implicit conversion of --thinpool arg to type thin-pool failed. " ) ;
return 0 ;
}
return _lvconvert_thin ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a raid * LV to a cache LV .
* lvconvert - - type cache LV
*
* Required options :
* - - cachepool LV
*
* Auxiliary operation :
* Converts the - - cachepool arg to a cache pool if it is not already .
*
* Alternate syntax :
* lvconvert - - cache LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_cache ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
2016-06-30 20:02:43 +03:00
/* lvconvert --type cache includes an implicit conversion of the cachepool arg to type cache-pool. */
2016-06-28 20:24:41 +03:00
if ( ! _lvconvert_pool ( cmd , lv , lp ) ) {
log_error ( " Implicit conversion of --cachepool arg to type cache-pool failed. " ) ;
return 0 ;
}
return _lvconvert_cache ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a raid * LV to a thin - pool LV .
* lvconvert - - type thin - pool LV
*
* Alternate syntax :
* This is equivalent to above , but not preferred because it ' s ambiguous and inconsistent .
* lvconvert - - thinpool LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_thin_pool ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_pool ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a raid * LV to cache - pool LV .
* lvconvert - - type cache - pool LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_cache_pool ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_pool ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a raid * LV to use a different raid level .
* lvconvert - - type raid * LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_raid ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a raid * LV to a striped LV .
* lvconvert - - type striped LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_striped ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a raid * LV to a linear LV .
* lvconvert - - type linear LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_raid_linear ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Merge a striped / linear LV into a raid1 LV if the striped / linear LV was
* previously split from the raid1 LV using - - trackchanges .
* lvconvert - - merge LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_striped_merge ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_raid ( lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Combine a linear / striped LV with a snapshot LV that was previously
* split from the linear / striped LV using - - splitsnapshot .
* lvconvert - - type snapshot LV SnapshotLV
*
* Alternate syntax :
* lvconvert - - snapshot LV SnapshotLV
*/
static int _convert_striped_snapshot ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-30 20:02:43 +03:00
{
return _lvconvert_snapshot ( cmd , lv , lp ) ;
}
/*
* Convert a striped / linear LV to a thin LV with an external origin .
* lvconvert - - type thin LV
*
* Required options :
* - - thinpool LV
*
* Auxiliary operation :
* Converts the - - thinpool arg to a thin pool if it is not already .
*
* Alternate syntax :
* lvconvert - - thin LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_striped_thin ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
/* lvconvert --thin includes an implicit conversion of the thinpool arg to type thin-pool. */
if ( ! _lvconvert_pool ( cmd , lv , lp ) ) {
log_error ( " Implicit conversion of --thinpool arg to type thin-pool failed. " ) ;
return 0 ;
}
return _lvconvert_thin ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a striped / linear LV to a cache LV .
* lvconvert - - type cache LV
*
* Required options :
* - - cachepool LV
*
* Auxiliary operation :
* Converts the - - cachepool arg to a cache pool if it is not already .
*
* Alternate syntax :
* lvconvert - - cache LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_striped_cache ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
/* lvconvert --cache includes an implicit conversion of the cachepool arg to type cache-pool. */
if ( ! _lvconvert_pool ( cmd , lv , lp ) ) {
log_error ( " Implicit conversion of --cachepool arg to type cache-pool failed. " ) ;
return 0 ;
}
return _lvconvert_cache ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a striped / linear LV to a thin - pool LV .
* lvconvert - - type thin - pool LV
*
* Alternate syntax :
* This is equivalent to above , but not preferred because it ' s ambiguous and inconsistent .
* lvconvert - - thinpool LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_striped_thin_pool ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_pool ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a striped / linear LV to a cache - pool LV .
* lvconvert - - type cache - pool LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_striped_cache_pool ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_pool ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a striped / linear LV to a mirror LV .
* lvconvert - - type mirror LV
*
* Required options :
* - - mirrors Number
*
* Alternate syntax :
* This is equivalent to above when global / mirror_segtype_default = " mirror " .
* lvconvert - - mirrors Number LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_striped_mirror ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_mirrors ( cmd , lv , lp ) ;
}
2016-06-30 20:02:43 +03:00
/*
* Convert a striped / linear LV to a raid * LV .
* lvconvert - - type raid * LV
*
* Required options :
* - - mirrors Number
*
* Alternate syntax :
* This is equivalent to above when global / mirror_segtype_default = " raid1 " .
* lvconvert - - mirrors Number LV
*/
2016-06-28 20:24:41 +03:00
static int _convert_striped_raid ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
return _lvconvert_raid ( lv , lp ) ;
}
/*
* Functions called to perform all valid operations on a given LV type .
*
* _convert_ < lvtype >
*/
static int _convert_cow_snapshot ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , splitsnapshot_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_cow_snapshot_splitsnapshot ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
/* FIXME: add --merge-snapshot to make this distinct from --merge-mirror. */
if ( arg_is_set ( cmd , merge_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_cow_snapshot_merge ( cmd , lv , lp ) ;
2016-07-12 12:05:34 +03:00
log_error ( " Operation not permitted on COW snapshot LV %s. " , display_lvname ( lv ) ) ;
2016-06-28 20:24:41 +03:00
log_error ( " Operations permitted on a COW snapshot LV are: \n "
" --splitsnapshot \n "
" --merge \n " ) ;
return 0 ;
}
static int _convert_thin_volume ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
2016-07-01 18:18:05 +03:00
/* FIXME: add --merge-snapshot to make this distinct from --merge-mirror. */
if ( arg_is_set ( cmd , merge_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_thin_volume_merge ( cmd , lv , lp ) ;
2016-07-12 12:05:34 +03:00
log_error ( " Operation not permitted on thin LV %s. " , display_lvname ( lv ) ) ;
2016-06-28 20:24:41 +03:00
log_error ( " Operations permitted on a thin LV are: \n "
" --merge \n " ) ;
return 0 ;
}
static int _convert_thin_pool ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
2016-07-01 18:18:05 +03:00
const char * new_type = arg_str_value ( cmd , type_ARG , NULL ) ;
if ( arg_is_set ( cmd , splitcache_ARG ) )
return _convert_thin_pool_splitcache ( cmd , lv , lp ) ;
if ( arg_is_set ( cmd , split_ARG ) ) {
log_warn ( " WARNING: Using --splitcache which has replaced the --split option. " ) ;
2016-06-28 20:24:41 +03:00
return _convert_thin_pool_splitcache ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
}
2016-06-28 20:24:41 +03:00
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , uncache_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_thin_pool_uncache ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_CACHE ) ) | | arg_is_set ( cmd , cache_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_thin_pool_cache ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , repair_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_thin_pool_repair ( cmd , lv , lp ) ;
/* FIXME: swapping the thin pool metadata LV needs a specific option like --swapmetadata */
if ( arg_is_set ( cmd , poolmetadata_ARG ) )
return _convert_thin_pool_swapmetadata ( cmd , lv , lp ) ;
/* FIXME: add --swapmetadata to list of permitted operations. */
2016-07-12 12:05:34 +03:00
log_error ( " Operation not permitted on thin pool LV %s. " , display_lvname ( lv ) ) ;
2016-06-28 20:24:41 +03:00
log_error ( " Operations permitted on a thin pool LV are: \n "
2016-07-08 21:29:19 +03:00
" --splitcache (operates on cache sub LV) \n "
" --uncache (operates on cache sub LV) \n "
" --type cache (operates on data sub LV) \n "
2016-06-28 20:24:41 +03:00
" --repair \n " ) ;
return 0 ;
}
static int _convert_cache_volume ( struct cmd_context * cmd , struct logical_volume * lv ,
2016-07-12 12:05:34 +03:00
struct lvconvert_params * lp )
2016-06-28 20:24:41 +03:00
{
const char * new_type = arg_str_value ( cmd , type_ARG , NULL ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , splitcache_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_cache_volume_splitcache ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , split_ARG ) ) {
log_warn ( " WARNING: Using --splitcache which has replaced the --split option. " ) ;
return _convert_cache_volume_splitcache ( cmd , lv , lp ) ;
}
if ( arg_is_set ( cmd , uncache_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_cache_volume_uncache ( cmd , lv , lp ) ;
if ( arg_is_set ( cmd , splitmirrors_ARG ) )
return _convert_cache_volume_splitmirrors ( cmd , lv , lp ) ;
2016-06-30 20:02:43 +03:00
/* Using --thinpool is ambiguous and not preferred. */
2016-06-30 18:09:54 +03:00
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_THIN_POOL ) ) | | arg_is_set ( cmd , thinpool_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_cache_volume_thin_pool ( cmd , lv , lp ) ;
2016-06-30 20:02:43 +03:00
/* The --thinpool alternative for --type thin-pool is not preferred, so not shown. */
2016-06-30 18:09:54 +03:00
2016-07-12 12:05:34 +03:00
log_error ( " Operation not permitted on cache LV %s. " , display_lvname ( lv ) ) ;
2016-06-28 20:24:41 +03:00
log_error ( " Operations permitted on a cache LV are: \n "
" --splitcache \n "
" --uncache \n "
" --splitmirrors (operates on mirror or raid sub LV) \n "
" --type thin-pool \n " ) ;
return 0 ;
}
static int _convert_cache_pool ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , splitcache_ARG ) )
return _convert_cache_pool_splitcache ( cmd , lv , lp ) ;
if ( arg_is_set ( cmd , split_ARG ) ) {
log_warn ( " WARNING: Using --splitcache which has replaced the --split option. " ) ;
2016-06-28 20:24:41 +03:00
return _convert_cache_pool_splitcache ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
}
2016-06-28 20:24:41 +03:00
/* FIXME: swapping the cache pool metadata LV needs a specific option like --swapmetadata */
if ( arg_is_set ( cmd , poolmetadata_ARG ) )
return _convert_cache_pool_swapmetadata ( cmd , lv , lp ) ;
/* FIXME: add --swapmetadata to list of permitted operations. */
2016-07-12 12:05:34 +03:00
log_error ( " Operation not permitted on cache pool LV %s. " , display_lvname ( lv ) ) ;
2016-06-28 20:24:41 +03:00
log_error ( " Operations permitted on a cache pool LV are: \n "
2016-07-08 21:29:19 +03:00
" --splitcache (operates on cache LV) \n " ) ;
2016-06-28 20:24:41 +03:00
return 0 ;
}
static int _convert_mirror ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
const char * new_type = arg_str_value ( cmd , type_ARG , NULL ) ;
const struct segment_type * new_segtype = NULL ;
if ( new_type )
new_segtype = get_segtype_from_string ( cmd , new_type ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , mirrors_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_mirror_number ( cmd , lv , lp ) ;
if ( arg_is_set ( cmd , splitmirrors_ARG ) )
return _convert_mirror_splitmirrors ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , mirrorlog_ARG ) | | arg_is_set ( cmd , corelog_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_mirror_log ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , repair_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_mirror_repair ( cmd , lv , lp ) ;
2016-07-07 00:33:25 +03:00
if ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_LINEAR ) )
return _convert_mirror_linear ( cmd , lv , lp ) ;
2016-06-28 20:24:41 +03:00
if ( new_type & & new_segtype & & segtype_is_raid ( new_segtype ) )
return _convert_mirror_raid ( cmd , lv , lp ) ;
/*
* FIXME : this is here to preserve old behavior , but an
* explicit option should be added to enable this case ,
* rather than making it the result of an ambiguous
* " lvconvert vg/lv " command .
2016-06-30 20:02:43 +03:00
* Add ' lvconvert - - poll - mirror vg / lv ' for this case .
2016-06-28 20:24:41 +03:00
*
* Old behavior was described as :
* " Collapsing a stack of mirrors.
* If called with no argument , try collapsing the resync layers "
*/
log_debug ( " Checking if LV %s is converting. " , display_lvname ( lv ) ) ;
if ( lv_is_converting ( lv ) ) {
lp - > need_polling = 1 ;
return 1 ;
}
2016-07-12 12:05:34 +03:00
log_error ( " Operation not permitted on mirror LV %s. " , display_lvname ( lv ) ) ;
2016-06-28 20:24:41 +03:00
log_error ( " Operations permitted on a mirror LV are: \n "
" --mirrors \n "
" --splitmirrors \n "
" --mirrorlog \n "
" --repair \n "
2016-07-07 00:33:25 +03:00
" --type linear \n "
2016-06-28 20:24:41 +03:00
" --type raid* \n " ) ;
2016-07-12 12:05:34 +03:00
2016-06-28 20:24:41 +03:00
return 0 ;
}
static int _convert_raid ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
const char * new_type = arg_str_value ( cmd , type_ARG , NULL ) ;
const struct segment_type * new_segtype = NULL ;
if ( new_type )
new_segtype = get_segtype_from_string ( cmd , new_type ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , mirrors_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_number ( cmd , lv , lp ) ;
if ( arg_is_set ( cmd , splitmirrors_ARG ) )
return _convert_raid_splitmirrors ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , merge_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_merge ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , repair_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_repair ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , replace_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_replace ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_SNAPSHOT ) ) | | arg_is_set ( cmd , snapshot_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_snapshot ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_THIN ) ) | | arg_is_set ( cmd , thin_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_thin ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_CACHE ) ) | | arg_is_set ( cmd , cache_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_cache ( cmd , lv , lp ) ;
2016-06-30 20:02:43 +03:00
/* Using --thinpool is ambiguous and not preferred. */
2016-06-28 20:24:41 +03:00
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_THIN_POOL ) ) | | arg_is_set ( cmd , thinpool_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_thin_pool ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_CACHE_POOL ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_cache_pool ( cmd , lv , lp ) ;
if ( new_type & & new_segtype & & segtype_is_raid ( new_segtype ) )
return _convert_raid_raid ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_STRIPED ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_striped ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_LINEAR ) )
2016-06-28 20:24:41 +03:00
return _convert_raid_linear ( cmd , lv , lp ) ;
2016-06-30 20:02:43 +03:00
/* The --thinpool alternative for --type thin-pool is not preferred, so not shown. */
2016-06-28 20:24:41 +03:00
2016-07-12 12:05:34 +03:00
log_error ( " Operation not permitted on raid LV %s. " , display_lvname ( lv ) ) ;
2016-06-28 20:24:41 +03:00
log_error ( " Operations permitted on a raid LV are: \n "
" --mirrors \n "
" --splitmirrors \n "
" --merge \n "
" --repair \n "
" --replace \n "
2016-07-08 21:29:19 +03:00
" --type snapshot \n "
" --type thin \n "
" --type cache \n "
2016-06-28 20:24:41 +03:00
" --type thin-pool \n "
" --type cache-pool \n "
" --type raid* \n "
" --type striped \n "
" --type linear \n " ) ;
return 0 ;
}
static int _convert_striped ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
const char * new_type = arg_str_value ( cmd , type_ARG , NULL ) ;
const struct segment_type * new_segtype = NULL ;
const char * mirrors_type = find_config_tree_str ( cmd , global_mirror_segtype_default_CFG , NULL ) ;
if ( new_type )
new_segtype = get_segtype_from_string ( cmd , new_type ) ;
2016-07-01 18:18:05 +03:00
/* FIXME: add --merge-mirror to make this distinct from --merge-snapshot. */
if ( arg_is_set ( cmd , merge_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_striped_merge ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_SNAPSHOT ) ) | | arg_is_set ( cmd , snapshot_ARG ) )
2016-06-30 20:02:43 +03:00
return _convert_striped_snapshot ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_THIN ) ) | | arg_is_set ( cmd , thin_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_striped_thin ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_CACHE ) ) | | arg_is_set ( cmd , cache_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_striped_cache ( cmd , lv , lp ) ;
2016-06-30 20:02:43 +03:00
/* Using --thinpool is ambiguous and not preferred. */
2016-06-28 20:24:41 +03:00
2016-07-01 18:18:05 +03:00
if ( ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_THIN_POOL ) ) | | arg_is_set ( cmd , thinpool_ARG ) )
2016-06-28 20:24:41 +03:00
return _convert_striped_thin_pool ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_CACHE_POOL ) )
2016-06-28 20:24:41 +03:00
return _convert_striped_cache_pool ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( new_type & & ! strcmp ( new_type , SEG_TYPE_NAME_MIRROR ) )
2016-06-28 20:24:41 +03:00
return _convert_striped_mirror ( cmd , lv , lp ) ;
if ( new_type & & new_segtype & & segtype_is_raid ( new_segtype ) )
return _convert_striped_raid ( cmd , lv , lp ) ;
/* --mirrors can mean --type mirror or --type raid1 depending on config setting. */
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , mirrors_ARG ) & & mirrors_type & & ! strcmp ( mirrors_type , SEG_TYPE_NAME_MIRROR ) )
2016-06-28 20:24:41 +03:00
return _convert_striped_mirror ( cmd , lv , lp ) ;
2016-07-01 18:18:05 +03:00
if ( arg_is_set ( cmd , mirrors_ARG ) & & mirrors_type & & ! strcmp ( mirrors_type , SEG_TYPE_NAME_RAID1 ) )
2016-06-28 20:24:41 +03:00
return _convert_striped_raid ( cmd , lv , lp ) ;
2016-06-30 20:02:43 +03:00
/* The --thinpool alternative for --type thin-pool is not preferred, so not shown. */
2016-06-28 20:24:41 +03:00
2016-07-12 12:05:34 +03:00
log_error ( " Operation not permitted on striped or linear LV %s. " , display_lvname ( lv ) ) ;
2016-06-28 20:24:41 +03:00
log_error ( " Operations permitted on a striped or linear LV are: \n "
" --merge \n "
2016-07-08 21:29:19 +03:00
" --type snapshot \n "
" --type thin \n "
" --type cache \n "
2016-06-28 20:24:41 +03:00
" --type thin-pool \n "
" --type cache-pool \n "
2016-07-08 21:29:19 +03:00
" --type mirror \n "
" --type raid* \n " ) ;
2016-07-12 12:05:34 +03:00
2016-06-28 20:24:41 +03:00
return 0 ;
}
/*
* lvconvert performs a specific < operation > on a specific < lv_type > .
*
2016-07-01 18:18:05 +03:00
* The < operation > is specified by command line args .
2016-06-28 20:24:41 +03:00
* The < lv_type > is found using lv_is_foo ( lv ) functions .
*
* for each lvtype ,
* _convert_lvtype ( ) ;
2016-07-01 18:18:05 +03:00
* for each arg_is_set ( operation )
2016-06-28 20:24:41 +03:00
* _convert_lvtype_operation ( ) ;
2016-06-30 20:02:43 +03:00
*
2016-06-28 20:24:41 +03:00
*/
static int _lvconvert ( struct cmd_context * cmd , struct logical_volume * lv ,
struct lvconvert_params * lp )
{
struct lv_segment * lv_seg = first_seg ( lv ) ;
int ret = 0 ;
/*
* Check some conditions that can never be processed .
*/
if ( lv_is_locked ( lv ) ) {
log_error ( " Cannot convert locked LV %s. " , display_lvname ( lv ) ) ;
ret = 0 ;
goto out ;
}
if ( lv_is_pvmove ( lv ) ) {
log_error ( " Cannot convert pvmove LV %s. " , display_lvname ( lv ) ) ;
ret = 0 ;
goto out ;
}
if ( ! lv_is_visible ( lv ) ) {
/*
* FIXME : there are some exceptions to the rule of only
* operating on visible LVs . These should be fixed by running
* the command on the visible LV with an option indicating
* which sub LV is intended rather than naming the ! visible LV .
*/
if ( ! lv_is_cache_pool_metadata ( lv ) & &
! lv_is_cache_pool_data ( lv ) & &
! lv_is_thin_pool_metadata ( lv ) & &
! lv_is_thin_pool_data ( lv ) & &
2016-07-08 22:08:55 +03:00
! lv_is_used_cache_pool ( lv ) & &
2016-06-28 20:24:41 +03:00
! lv_is_raid_image ( lv ) ) {
log_error ( " Cannot convert internal LV %s. " , display_lvname ( lv ) ) ;
ret = 0 ;
goto out ;
}
}
/*
* Each LV type that can be converted .
* ( The existing type of the LV , not a requested type . )
*/
if ( lv_is_cow ( lv ) ) {
ret = _convert_cow_snapshot ( cmd , lv , lp ) ;
goto out ;
}
if ( lv_is_thin_volume ( lv ) ) {
ret = _convert_thin_volume ( cmd , lv , lp ) ;
goto out ;
}
if ( lv_is_thin_pool ( lv ) ) {
ret = _convert_thin_pool ( cmd , lv , lp ) ;
goto out ;
}
if ( lv_is_cache ( lv ) ) {
ret = _convert_cache_volume ( cmd , lv , lp ) ;
goto out ;
}
if ( lv_is_cache_pool ( lv ) ) {
ret = _convert_cache_pool ( cmd , lv , lp ) ;
goto out ;
}
if ( lv_is_mirror ( lv ) ) {
ret = _convert_mirror ( cmd , lv , lp ) ;
goto out ;
}
if ( lv_is_raid ( lv ) ) {
ret = _convert_raid ( cmd , lv , lp ) ;
goto out ;
}
/*
* FIXME : add lv_is_striped ( ) and lv_is_linear ( ) ?
* This does not include raid0 .
* If operations differ between striped and linear , split this case .
*/
if ( segtype_is_striped ( lv_seg - > segtype ) | | segtype_is_linear ( lv_seg - > segtype ) ) {
ret = _convert_striped ( cmd , lv , lp ) ;
goto out ;
}
/*
* The intention is to explicitly check all cases above and never
* reach here , but this covers anything that was missed .
*/
log_error ( " Cannot convert LV %s. " , display_lvname ( lv ) ) ;
ret = 0 ;
out :
return ret ? ECMD_PROCESSED : ECMD_FAILED ;
}
2005-06-06 21:12:08 +04:00
2015-07-15 21:02:54 +03:00
static struct convert_poll_id_list * _convert_poll_id_list_create ( struct cmd_context * cmd ,
const struct logical_volume * lv )
2010-02-06 01:44:37 +03:00
{
2015-07-15 21:02:54 +03:00
struct convert_poll_id_list * idl = ( struct convert_poll_id_list * ) dm_pool_alloc ( cmd - > mem , sizeof ( struct convert_poll_id_list ) ) ;
if ( ! idl ) {
log_error ( " Convert poll ID list allocation failed. " ) ;
return NULL ;
}
if ( ! ( idl - > id = _create_id ( cmd , lv - > vg - > name , lv - > name , lv - > lvid . s ) ) ) {
dm_pool_free ( cmd - > mem , idl ) ;
2015-07-22 13:26:28 +03:00
return_NULL ;
2015-07-15 21:02:54 +03:00
}
idl - > is_merging_origin = lv_is_merging_origin ( lv ) ;
idl - > is_merging_origin_thin = idl - > is_merging_origin & & seg_is_thin_volume ( find_snapshot ( lv ) ) ;
return idl ;
}
2016-05-23 21:42:17 +03:00
static int _lvconvert_and_add_to_poll_list ( struct cmd_context * cmd ,
struct lvconvert_params * lp ,
struct logical_volume * lv )
2015-07-15 21:02:54 +03:00
{
int ret ;
2008-01-10 21:35:51 +03:00
struct lvinfo info ;
2015-07-15 21:02:54 +03:00
struct convert_poll_id_list * idl ;
2005-06-06 21:12:08 +04:00
2016-05-23 21:42:17 +03:00
/* _lvconvert() call may alter the reference in lp->lv_to_poll */
if ( ( ret = _lvconvert ( cmd , lv , lp ) ) ! = ECMD_PROCESSED )
2015-07-15 21:02:54 +03:00
stack ;
else if ( lp - > need_polling ) {
if ( ! lv_info ( cmd , lp - > lv_to_poll , 0 , & info , 0 , 0 ) | | ! info . exists )
log_print_unless_silent ( " Conversion starts after activation. " ) ;
else {
2015-07-22 13:26:28 +03:00
if ( ! ( idl = _convert_poll_id_list_create ( cmd , lp - > lv_to_poll ) ) )
2015-07-15 21:02:54 +03:00
return_ECMD_FAILED ;
2015-07-22 13:26:28 +03:00
dm_list_add ( & lp - > idls , & idl - > list ) ;
2015-07-15 21:02:54 +03:00
}
2005-06-06 21:12:08 +04:00
}
2014-02-23 02:13:43 +04:00
2015-07-15 21:02:54 +03:00
return ret ;
2010-02-06 01:44:37 +03:00
}
2016-05-23 21:42:17 +03:00
static int _lvconvert_single ( struct cmd_context * cmd , struct logical_volume * lv ,
struct processing_handle * handle )
2010-02-06 01:44:37 +03:00
{
2016-05-23 21:42:17 +03:00
struct lvconvert_params * lp = ( struct lvconvert_params * ) handle - > custom_handle ;
struct volume_group * vg = lv - > vg ;
2015-05-19 17:46:11 +03:00
2016-01-19 01:53:14 +03:00
if ( test_mode ( ) & & is_lockd_type ( vg - > lock_type ) ) {
2016-07-12 12:05:34 +03:00
log_error ( " Test mode is not yet supported with lock type %s. " ,
2016-01-19 01:53:14 +03:00
vg - > lock_type ) ;
2016-05-23 21:42:17 +03:00
return ECMD_FAILED ;
2015-05-19 17:46:11 +03:00
}
2005-06-06 21:12:08 +04:00
2010-04-26 22:12:40 +04:00
/*
* lp - > pvh holds the list of PVs available for allocation or removal
*/
2010-02-06 01:44:37 +03:00
if ( lp - > pv_count ) {
2015-05-19 17:46:11 +03:00
if ( ! ( lp - > pvh = create_pv_list ( cmd - > mem , vg , lp - > pv_count , lp - > pvs , 0 ) ) )
2016-05-23 21:42:17 +03:00
return_ECMD_FAILED ;
2005-06-06 21:12:08 +04:00
} else
2015-05-19 17:46:11 +03:00
lp - > pvh = & vg - > pvs ;
2005-06-06 21:12:08 +04:00
2011-11-30 06:02:10 +04:00
if ( lp - > replace_pv_count & &
2015-05-19 17:46:11 +03:00
! ( lp - > replace_pvh = create_pv_list ( cmd - > mem , vg ,
2011-11-30 06:02:10 +04:00
lp - > replace_pv_count ,
lp - > replace_pvs , 0 ) ) )
2016-05-23 21:42:17 +03:00
return_ECMD_FAILED ;
2011-11-30 06:02:10 +04:00
2010-02-06 01:47:22 +03:00
lp - > lv_to_poll = lv ;
2015-07-15 21:02:54 +03:00
2016-05-23 21:42:17 +03:00
return _lvconvert_and_add_to_poll_list ( cmd , lp , lv ) ;
2005-06-06 21:12:08 +04:00
}
2010-02-06 01:44:37 +03:00
2013-12-04 06:09:37 +04:00
static int _lvconvert_merge_single ( struct cmd_context * cmd , struct logical_volume * lv ,
2014-11-27 17:02:13 +03:00
struct processing_handle * handle )
2010-02-06 01:44:37 +03:00
{
2014-11-27 17:02:13 +03:00
struct lvconvert_params * lp = ( struct lvconvert_params * ) handle - > custom_handle ;
2015-03-05 23:00:44 +03:00
lp - > lv_to_poll = lv ;
2016-05-23 21:42:17 +03:00
return _lvconvert_and_add_to_poll_list ( cmd , lp , lv ) ;
2015-03-05 23:00:44 +03:00
}
2010-02-06 01:44:37 +03:00
int lvconvert ( struct cmd_context * cmd , int argc , char * * argv )
{
2015-07-22 13:26:28 +03:00
int poll_ret , ret ;
2015-07-15 21:02:54 +03:00
struct convert_poll_id_list * idl ;
2014-08-13 16:20:10 +04:00
struct lvconvert_params lp = {
. target_attr = ~ 0 ,
2016-02-25 14:15:26 +03:00
. idls = DM_LIST_HEAD_INIT ( lp . idls ) ,
2014-08-13 16:20:10 +04:00
} ;
2016-05-31 13:24:05 +03:00
struct processing_handle * handle = init_processing_handle ( cmd , NULL ) ;
2010-02-06 01:44:37 +03:00
2016-02-25 14:15:26 +03:00
if ( ! handle ) {
2015-02-13 12:36:06 +03:00
log_error ( " Failed to initialize processing handle. " ) ;
2016-02-25 14:15:26 +03:00
return ECMD_FAILED ;
2015-02-13 12:36:06 +03:00
}
handle - > custom_handle = & lp ;
2014-11-27 17:02:13 +03:00
2014-10-31 13:31:22 +03:00
if ( ! _read_params ( cmd , argc , argv , & lp ) ) {
2014-11-28 17:04:25 +03:00
ret = EINVALID_CMD_LINE ;
goto_out ;
2010-02-06 01:44:37 +03:00
}
2016-05-23 21:42:17 +03:00
if ( lp . merge ) {
ret = process_each_lv ( cmd , argc , argv , NULL , NULL ,
READ_FOR_UPDATE , handle , & _lvconvert_merge_single ) ;
} else {
int saved_ignore_suspended_devices = ignore_suspended_devices ( ) ;
if ( lp . repair | | lp . uncache ) {
init_ignore_suspended_devices ( 1 ) ;
cmd - > handles_missing_pvs = 1 ;
}
ret = process_each_lv ( cmd , 0 , NULL , lp . vg_name , lp . lv_name ,
READ_FOR_UPDATE , handle , & _lvconvert_single ) ;
init_ignore_suspended_devices ( saved_ignore_suspended_devices ) ;
}
2015-07-15 21:02:54 +03:00
dm_list_iterate_items ( idl , & lp . idls ) {
2015-07-22 13:26:28 +03:00
poll_ret = _lvconvert_poll_by_id ( cmd , idl - > id ,
lp . wait_completion ? 0 : 1U ,
idl - > is_merging_origin ,
idl - > is_merging_origin_thin ) ;
if ( poll_ret > ret )
ret = poll_ret ;
2015-07-15 21:02:54 +03:00
}
2014-11-28 17:04:25 +03:00
out :
2015-07-15 12:06:40 +03:00
if ( lp . policy_settings )
dm_config_destroy ( lp . policy_settings ) ;
2016-02-25 14:15:26 +03:00
2015-02-13 12:42:21 +03:00
destroy_processing_handle ( cmd , handle ) ;
2016-02-25 14:15:26 +03:00
2014-11-28 17:04:25 +03:00
return ret ;
2010-02-06 01:44:37 +03:00
}