2003-05-06 16:22:24 +04:00
/*
2008-01-30 17:00:02 +03:00
* Copyright ( C ) 2003 - 2004 Sistina Software , Inc . All rights reserved .
2008-06-13 16:15:55 +04:00
* Copyright ( C ) 2004 - 2008 Red Hat , Inc . All rights reserved .
2003-05-06 16:22:24 +04:00
*
2004-03-30 23:35:44 +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 .
2004-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2003-05-06 16:22:24 +04:00
*/
# include "lib.h"
# include "metadata.h"
# include "toolcontext.h"
2004-09-16 22:40:56 +04:00
# include "segtype.h"
2004-05-05 01:25:57 +04:00
# include "display.h"
2007-12-20 18:42:55 +03:00
# include "archiver.h"
2004-05-25 00:51:56 +04:00
# include "activate.h"
2005-04-22 19:43:02 +04:00
# include "lv_alloc.h"
2005-06-03 18:49:51 +04:00
# include "lvm-string.h"
2007-03-26 20:10:10 +04:00
# include "str_list.h"
2005-11-29 21:20:23 +03:00
# include "locking.h" /* FIXME Should not be used in this file */
2005-06-03 18:49:51 +04:00
2006-05-11 23:45:53 +04:00
# include "defaults.h" /* FIXME: should this be defaults.h? */
2007-12-21 01:37:42 +03:00
/* These are necessary for _write_log_header() */
# include "xlate.h"
# define MIRROR_MAGIC 0x4D695272
# define MIRROR_DISK_VERSION 2
2006-05-11 23:45:53 +04:00
/* These are the flags that represent the mirror failure restoration policies */
2008-01-30 17:00:02 +03:00
# define MIRROR_REMOVE 0
# define MIRROR_ALLOCATE 1
2006-05-11 23:45:53 +04:00
# define MIRROR_ALLOCATE_ANYWHERE 2
2007-12-20 21:55:46 +03:00
/*
* Returns true if the lv is temporary mirror layer for resync
*/
int is_temporary_mirror_layer ( const struct logical_volume * lv )
{
2014-09-16 00:33:53 +04:00
if ( lv_is_mirror_image ( lv ) & & lv_is_mirrored ( lv ) & & ! lv_is_locked ( lv ) )
2007-12-20 21:55:46 +03:00
return 1 ;
return 0 ;
}
2008-01-16 22:09:35 +03:00
/*
* Return a temporary LV for resyncing added mirror image .
* Add other mirror legs to lvs list .
*/
2008-01-16 22:13:51 +03:00
struct logical_volume * find_temporary_mirror ( const struct logical_volume * lv )
2008-01-16 22:09:35 +03:00
{
struct lv_segment * seg ;
2014-09-16 00:33:53 +04:00
if ( ! lv_is_mirrored ( lv ) )
2008-01-16 22:09:35 +03:00
return NULL ;
seg = first_seg ( lv ) ;
/* Temporary mirror is always area_num == 0 */
if ( seg_type ( seg , 0 ) = = AREA_LV & &
is_temporary_mirror_layer ( seg_lv ( seg , 0 ) ) )
return seg_lv ( seg , 0 ) ;
return NULL ;
}
2010-07-21 17:40:21 +04:00
/*
* cluster_mirror_is_available
*
* Check if the proper kernel module and log daemon are running .
* Caller should check for ' vg_is_clustered ( lv - > vg ) ' before making
* this call .
*
* Returns : 1 if available , 0 otherwise
*/
2015-01-05 18:45:30 +03:00
int cluster_mirror_is_available ( struct cmd_context * cmd )
2010-07-21 17:40:21 +04:00
{
unsigned attr = 0 ;
const struct segment_type * segtype ;
2015-09-22 21:04:12 +03:00
if ( ! ( segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_MIRROR ) ) )
2010-07-21 17:40:21 +04:00
return_0 ;
if ( ! segtype - > ops - > target_present )
return_0 ;
2015-01-05 18:45:30 +03:00
if ( ! segtype - > ops - > target_present ( cmd , NULL , & attr ) )
2010-07-21 17:40:21 +04:00
return_0 ;
if ( ! ( attr & MIRROR_LOG_CLUSTERED ) )
return 0 ;
return 1 ;
}
2007-12-20 18:42:55 +03:00
/*
* Returns the number of mirrors of the LV
*/
2007-12-20 21:55:46 +03:00
uint32_t lv_mirror_count ( const struct logical_volume * lv )
2007-12-20 18:42:55 +03:00
{
2007-12-20 21:55:46 +03:00
struct lv_segment * seg ;
uint32_t s , mirrors ;
2014-09-16 00:33:53 +04:00
if ( ! lv_is_mirrored ( lv ) )
2007-12-20 21:55:46 +03:00
return 1 ;
seg = first_seg ( lv ) ;
2011-09-14 08:10:26 +04:00
2012-08-25 00:34:19 +04:00
/* FIXME: RAID10 only supports 2 copies right now */
2015-09-24 16:59:07 +03:00
if ( seg_is_raid10 ( seg ) )
2012-08-25 00:34:19 +04:00
return 2 ;
2014-09-16 00:33:53 +04:00
if ( lv_is_pvmove ( lv ) )
2011-09-14 08:10:26 +04:00
return seg - > area_count ;
2011-09-14 06:45:36 +04:00
mirrors = 0 ;
2007-12-20 21:55:46 +03:00
for ( s = 0 ; s < seg - > area_count ; s + + ) {
if ( seg_type ( seg , s ) ! = AREA_LV )
continue ;
if ( is_temporary_mirror_layer ( seg_lv ( seg , s ) ) )
2011-09-14 08:10:26 +04:00
mirrors + = lv_mirror_count ( seg_lv ( seg , s ) ) ;
2011-09-14 06:45:36 +04:00
else
mirrors + + ;
2007-12-20 21:55:46 +03:00
}
2011-09-14 06:45:36 +04:00
return mirrors ? mirrors : 1 ;
2007-12-20 18:42:55 +03:00
}
2005-10-27 23:58:22 +04:00
struct lv_segment * find_mirror_seg ( struct lv_segment * seg )
{
2008-01-16 22:00:59 +03:00
struct lv_segment * mirror_seg ;
2016-11-16 17:11:07 +03:00
if ( ! ( mirror_seg = get_only_segment_using_this_lv ( seg - > lv ) ) ) {
log_error ( " Failed to find mirror_seg for %s " , display_lvname ( seg - > lv ) ) ;
2008-01-16 22:00:59 +03:00
return NULL ;
}
if ( ! seg_is_mirrored ( mirror_seg ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " LV %s on %s is not a mirror segments. " ,
display_lvname ( mirror_seg - > lv ) ,
display_lvname ( seg - > lv ) ) ;
2008-01-16 22:00:59 +03:00
return NULL ;
}
return mirror_seg ;
2005-10-27 23:58:22 +04:00
}
2005-08-12 23:23:08 +04:00
/*
2006-11-10 22:35:03 +03:00
* Reduce the region size if necessary to ensure
* the volume size is a multiple of the region size .
2014-09-22 17:54:33 +04:00
*
* For internal use only log only in verbose mode
2005-08-12 23:23:08 +04:00
*/
2017-04-20 21:42:21 +03:00
uint32_t adjusted_mirror_region_size ( struct cmd_context * cmd ,
uint32_t extent_size , uint32_t extents ,
2015-02-25 23:42:15 +03:00
uint32_t region_size , int internal , int clustered )
2005-08-12 23:23:08 +04:00
{
2018-04-20 11:03:26 +03:00
uint64_t region_max , region_min ;
uint32_t region_min_pow2 ;
2005-08-12 23:23:08 +04:00
2018-04-20 11:03:26 +03:00
region_max = ( uint64_t ) extents * extent_size ;
2005-08-12 23:23:08 +04:00
2006-11-10 22:35:03 +03:00
if ( region_max < UINT32_MAX & & region_size > region_max ) {
2018-04-20 11:03:26 +03:00
region_size = UINT64_C ( 1 ) < < ( 31 - clz ( region_max ) ) ;
2014-09-22 17:54:33 +04:00
if ( ! internal )
2017-04-20 21:42:21 +03:00
log_print_unless_silent ( " Using reduced mirror region size of %s " ,
display_size ( cmd , region_size ) ) ;
2018-04-20 11:03:26 +03:00
else
2017-04-20 21:42:21 +03:00
log_verbose ( " Using reduced mirror region size of %s " ,
display_size ( cmd , region_size ) ) ;
2005-08-12 23:23:08 +04:00
}
2015-02-25 23:42:15 +03:00
# ifdef CMIRROR_REGION_COUNT_LIMIT
if ( clustered ) {
/*
* The CPG code used by cluster mirrors can only handle a
* payload of < 1 MB currently . ( This deficiency is tracked by
* http : //bugzilla.redhat.com/682771.) The region size for cluster
* mirrors must be restricted in such a way as to limit the
* size of the bitmap to < 512 kB , because there are two bitmaps
* which get sent around during checkpointing while a cluster
* mirror starts up . Ergo , the number of regions must not
* exceed 512 k * 8. We also need some room for the other
* checkpointing structures as well , so we reduce by another
* factor of two .
*
* This code should be removed when the CPG restriction is
* lifted .
*/
2018-04-20 11:07:42 +03:00
region_min = region_max / CMIRROR_REGION_COUNT_LIMIT ;
if ( region_min > UINT32_MAX / 2 ) {
log_error ( " Can't find proper region size for too big mirror. " ) ;
return 0 ;
}
region_min_pow2 = UINT64_C ( 1 ) < < ( 1 + 31 - clz ( region_min ) ) ;
2015-02-25 23:42:15 +03:00
if ( region_size < region_min_pow2 ) {
if ( internal )
2017-04-20 21:42:21 +03:00
log_print_unless_silent ( " Increasing mirror region size from %s to %s " ,
display_size ( cmd , region_size ) ,
display_size ( cmd , region_min_pow2 ) ) ;
2015-02-25 23:42:15 +03:00
else
2017-04-20 21:42:21 +03:00
log_verbose ( " Increasing mirror region size from %s to %s " ,
display_size ( cmd , region_size ) ,
display_size ( cmd , region_min_pow2 ) ) ;
2015-02-25 23:42:15 +03:00
region_size = region_min_pow2 ;
}
}
# endif /* CMIRROR_REGION_COUNT_LIMIT */
2005-08-12 23:23:08 +04:00
return region_size ;
}
2008-09-18 23:56:50 +04:00
/*
* shift_mirror_images
* @ mirrored_seg
* @ mimage : The position ( index ) of the image to move to the end
*
* When dealing with removal of legs , we often move a ' removable leg '
* to the back of the ' areas ' array . It is critically important not
* to simply swap it for the last area in the array . This would have
* the affect of reordering the remaining legs - altering position of
* the primary . So , we must shuffle all of the areas in the array
* to maintain their relative position before moving the ' removable
* leg ' to the end .
*
* Short illustration of the problem :
* - Mirror consists of legs A , B , C and we want to remove A
* - We swap A and C and then remove A , leaving C , B
* This scenario is problematic in failure cases where A dies , because
* B becomes the primary . If the above happens , we effectively throw
* away any changes made between the time of failure and the time of
* restructuring the mirror .
*
* So , any time we want to move areas to the end to be removed , use
* this function .
*/
int shift_mirror_images ( struct lv_segment * mirrored_seg , unsigned mimage )
{
2011-04-08 18:40:18 +04:00
unsigned i ;
2008-09-18 23:56:50 +04:00
struct lv_segment_area area ;
if ( mimage > = mirrored_seg - > area_count ) {
log_error ( " Invalid index (%u) of mirror image supplied "
2016-11-16 17:11:07 +03:00
" to shift_mirror_images(). " , mimage ) ;
2008-09-18 23:56:50 +04:00
return 0 ;
}
area = mirrored_seg - > areas [ mimage ] ;
/* Shift remaining images down to fill the hole */
for ( i = mimage + 1 ; i < mirrored_seg - > area_count ; i + + )
mirrored_seg - > areas [ i - 1 ] = mirrored_seg - > areas [ i ] ;
/* Place this one at the end */
mirrored_seg - > areas [ i - 1 ] = area ;
2008-09-19 04:20:39 +04:00
return 1 ;
2008-09-18 23:56:50 +04:00
}
2008-01-16 22:09:35 +03:00
/*
* This function writes a new header to the mirror log header to the lv
*
* Returns : 1 on success , 0 on failure
*/
static int _write_log_header ( struct cmd_context * cmd , struct logical_volume * lv )
{
struct device * dev ;
2018-03-09 14:59:13 +03:00
char name [ PATH_MAX ] ;
2008-01-16 22:09:35 +03:00
struct { /* The mirror log header */
uint32_t magic ;
uint32_t version ;
uint64_t nr_regions ;
} log_header ;
log_header . magic = xlate32 ( MIRROR_MAGIC ) ;
log_header . version = xlate32 ( MIRROR_DISK_VERSION ) ;
log_header . nr_regions = xlate64 ( ( uint64_t ) - 1 ) ;
2018-03-09 14:59:13 +03:00
if ( dm_snprintf ( name , sizeof ( name ) , " %s%s/%s " , cmd - > dev_dir ,
lv - > vg - > name , lv - > name ) < 0 ) {
log_error ( " Device path name too long - log header not written (%s). " ,
2016-11-16 17:11:07 +03:00
display_lvname ( lv ) ) ;
2008-01-16 22:09:35 +03:00
return 0 ;
}
2018-03-09 14:59:13 +03:00
log_verbose ( " Writing log header for LV %s to device %s. " , display_lvname ( lv ) , name ) ;
2008-01-16 22:09:35 +03:00
if ( ! ( dev = dev_cache_get ( name , NULL ) ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " %s: not found: log header not written. " , name ) ;
2008-01-16 22:09:35 +03:00
return 0 ;
}
if ( ! dev_open_quiet ( dev ) )
return 0 ;
2017-12-05 02:18:56 +03:00
if ( ! dev_write ( dev , UINT64_C ( 0 ) , sizeof ( log_header ) , DEV_IO_LV , & log_header ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed to write log header to %s. " , name ) ;
2008-01-16 22:09:35 +03:00
dev_close_immediate ( dev ) ;
return 0 ;
}
dev_close_immediate ( dev ) ;
return 1 ;
}
/*
* Initialize mirror log contents
*/
static int _init_mirror_log ( struct cmd_context * cmd ,
2018-03-30 00:26:22 +03:00
struct logical_volume * lock_holder ,
2008-01-16 22:09:35 +03:00
struct logical_volume * log_lv , int in_sync ,
2014-01-31 01:09:28 +04:00
struct dm_list * tagsl , int remove_on_failure )
2008-01-16 22:09:35 +03:00
{
2014-05-29 11:41:03 +04:00
struct dm_str_list * sl ;
2018-03-13 14:48:36 +03:00
if ( log_lv ! = lv_lock_holder ( log_lv ) | | ! lv_is_visible ( log_lv ) ) {
/* Expect fully visible device for init */
log_error ( INTERNAL_ERROR " Log LV %s is not top level LV for initialization. " ,
display_lvname ( log_lv ) ) ;
return 0 ;
}
2008-01-16 22:09:35 +03:00
2011-01-24 17:19:05 +03:00
if ( test_mode ( ) ) {
log_verbose ( " Test mode: Skipping mirror log initialisation. " ) ;
return 1 ;
}
2008-01-16 22:09:35 +03:00
if ( ! activation ( ) & & in_sync ) {
log_error ( " Aborting. Unable to create in-sync mirror log "
" while activation is disabled. " ) ;
return 0 ;
}
/* Temporary tag mirror log for activation */
2014-01-31 01:09:28 +04:00
dm_list_iterate_items ( sl , tagsl )
2018-03-30 00:12:57 +03:00
if ( ! str_list_add ( log_lv - > vg - > vgmem , & log_lv - > tags , sl - > str ) ) {
2008-01-16 22:09:35 +03:00
log_error ( " Aborting. Unable to tag mirror log. " ) ;
2018-03-13 14:48:36 +03:00
return 0 ;
2008-01-16 22:09:35 +03:00
}
/* store mirror log on disk(s) */
2018-03-30 00:26:22 +03:00
if ( ! lock_holder ) {
if ( ! vg_write ( log_lv - > vg ) | | ! vg_commit ( log_lv - > vg ) )
return_0 ;
} else if ( ! lv_update_and_reload ( ( struct logical_volume * ) lock_holder ) )
2018-03-13 14:48:36 +03:00
return_0 ;
2012-02-01 19:05:53 +04:00
2018-03-13 14:48:36 +03:00
if ( ! activate_lv_excl_local ( cmd , log_lv ) ) {
2008-01-16 22:09:35 +03:00
log_error ( " Aborting. Failed to activate mirror log. " ) ;
goto revert_new_lv ;
}
2013-11-06 19:16:34 +04:00
if ( activation ( ) ) {
2013-11-28 14:22:24 +04:00
if ( ! wipe_lv ( log_lv , ( struct wipe_params )
{ . do_zero = 1 , . zero_sectors = log_lv - > size ,
. zero_value = in_sync ? - 1 : 0 } ) ) {
2013-11-06 19:16:34 +04:00
log_error ( " Aborting. Failed to wipe mirror log. " ) ;
goto deactivate_and_revert_new_lv ;
}
2008-01-16 22:09:35 +03:00
2018-03-13 14:48:36 +03:00
if ( ! _write_log_header ( cmd , log_lv ) ) {
log_error ( " Aborting. Failed to write mirror log header. " ) ;
goto deactivate_and_revert_new_lv ;
}
2008-01-16 22:09:35 +03:00
}
if ( ! deactivate_lv ( cmd , log_lv ) ) {
log_error ( " Aborting. Failed to deactivate mirror log. "
" Manual intervention required. " ) ;
2018-03-13 14:48:36 +03:00
goto revert_new_lv ;
2008-01-16 22:09:35 +03:00
}
2018-03-13 14:48:36 +03:00
/* Wait for events following any deactivation before reactivating */
if ( ! sync_local_dev_names ( cmd ) ) {
log_error ( " Aborting. Failed to sync local devices before initialising mirror log %s. " ,
display_lvname ( log_lv ) ) ;
goto revert_new_lv ;
}
2008-01-16 22:09:35 +03:00
2018-03-13 14:48:36 +03:00
/* Remove the temporary tags */
dm_list_iterate_items ( sl , tagsl )
str_list_del ( & log_lv - > tags , sl - > str ) ;
2008-01-17 16:37:51 +03:00
2008-01-16 22:09:35 +03:00
return 1 ;
deactivate_and_revert_new_lv :
if ( ! deactivate_lv ( cmd , log_lv ) ) {
log_error ( " Unable to deactivate mirror log LV. "
" Manual intervention required. " ) ;
return 0 ;
}
revert_new_lv :
2014-01-31 01:09:28 +04:00
dm_list_iterate_items ( sl , tagsl )
2012-02-08 16:52:58 +04:00
str_list_del ( & log_lv - > tags , sl - > str ) ;
2008-01-17 16:37:51 +03:00
if ( remove_on_failure & & ! lv_remove ( log_lv ) ) {
2008-01-16 22:09:35 +03:00
log_error ( " Manual intervention may be required to remove "
" abandoned log LV before retrying. " ) ;
2008-01-17 16:37:51 +03:00
return 0 ;
}
2009-04-21 18:31:57 +04:00
if ( ! vg_write ( log_lv - > vg ) | | ! vg_commit ( log_lv - > vg ) )
2008-01-17 16:37:51 +03:00
log_error ( " Manual intervention may be required to "
" remove/restore abandoned log LV before retrying. " ) ;
2009-04-21 18:31:57 +04:00
else
backup ( log_lv - > vg ) ;
2008-01-16 22:09:35 +03:00
return 0 ;
}
2011-10-06 18:55:39 +04:00
/*
* Activate an LV similarly ( i . e . SH or EX ) to a given " model " LV
*/
static int _activate_lv_like_model ( struct logical_volume * model ,
struct logical_volume * lv )
{
if ( lv_is_active_exclusive ( model ) ) {
if ( ! activate_lv_excl ( lv - > vg - > cmd , lv ) )
return_0 ;
} else {
if ( ! activate_lv ( lv - > vg - > cmd , lv ) )
return_0 ;
}
return 1 ;
}
2007-03-26 20:10:10 +04:00
/*
* Delete independent / orphan LV , it must acquire lock .
*/
2015-01-07 12:52:38 +03:00
static int _delete_lv ( struct logical_volume * mirror_lv , struct logical_volume * lv ,
int reactivate )
2007-03-26 20:10:10 +04:00
{
2007-12-20 21:55:46 +03:00
struct cmd_context * cmd = mirror_lv - > vg - > cmd ;
2014-05-29 11:41:03 +04:00
struct dm_str_list * sl ;
2007-03-26 20:10:10 +04:00
/* Inherit tags - maybe needed for activation */
2010-11-09 15:34:40 +03:00
if ( ! str_list_match_list ( & mirror_lv - > tags , & lv - > tags , NULL ) ) {
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( sl , & mirror_lv - > tags )
2007-03-26 20:10:10 +04:00
if ( ! str_list_add ( cmd - > mem , & lv - > tags , sl - > str ) ) {
log_error ( " Aborting. Unable to tag. " ) ;
return 0 ;
}
2007-12-20 21:55:46 +03:00
if ( ! vg_write ( mirror_lv - > vg ) | |
! vg_commit ( mirror_lv - > vg ) ) {
2007-03-26 20:10:10 +04:00
log_error ( " Intermediate VG commit for orphan volume failed. " ) ;
return 0 ;
}
}
2015-01-07 12:52:38 +03:00
if ( reactivate ) {
/* FIXME: the 'model' should be 'mirror_lv' not 'lv', I think. */
if ( ! _activate_lv_like_model ( lv , lv ) )
return_0 ;
2007-03-26 20:10:10 +04:00
2015-01-07 12:52:38 +03:00
/* FIXME Is this superfluous now? */
2015-06-30 20:54:38 +03:00
if ( ! sync_local_dev_names ( cmd ) ) {
log_error ( " Failed to sync local devices when reactivating %s. " ,
display_lvname ( lv ) ) ;
return 0 ;
}
2012-02-01 19:05:53 +04:00
2015-01-07 12:52:38 +03:00
if ( ! deactivate_lv ( cmd , lv ) )
return_0 ;
}
2007-03-26 20:10:10 +04:00
if ( ! lv_remove ( lv ) )
return_0 ;
return 1 ;
}
2008-01-10 21:35:51 +03:00
static int _merge_mirror_images ( struct logical_volume * lv ,
2008-11-04 01:14:30 +03:00
const struct dm_list * mimages )
2008-01-10 21:35:51 +03:00
{
2008-11-04 01:14:30 +03:00
uint32_t addition = dm_list_size ( mimages ) ;
2008-01-10 21:35:51 +03:00
struct logical_volume * * img_lvs ;
struct lv_list * lvl ;
int i = 0 ;
if ( ! addition )
return 1 ;
2015-11-05 20:32:32 +03:00
img_lvs = alloca ( sizeof ( * img_lvs ) * addition ) ;
2008-01-10 21:35:51 +03:00
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( lvl , mimages )
2008-01-10 21:35:51 +03:00
img_lvs [ i + + ] = lvl - > lv ;
return lv_add_mirror_lvs ( lv , img_lvs , addition ,
MIRROR_IMAGE , first_seg ( lv ) - > region_size ) ;
}
2008-01-16 22:00:59 +03:00
/* Unlink the relationship between the segment and its log_lv */
2008-01-26 03:25:04 +03:00
struct logical_volume * detach_mirror_log ( struct lv_segment * mirrored_seg )
2008-01-16 22:00:59 +03:00
{
struct logical_volume * log_lv ;
if ( ! mirrored_seg - > log_lv )
2008-01-26 03:25:04 +03:00
return NULL ;
2008-01-16 22:00:59 +03:00
log_lv = mirrored_seg - > log_lv ;
mirrored_seg - > log_lv = NULL ;
2009-05-14 01:26:45 +04:00
lv_set_visible ( log_lv ) ;
2008-01-16 22:00:59 +03:00
log_lv - > status & = ~ MIRROR_LOG ;
2013-04-21 15:18:53 +04:00
if ( ! remove_seg_from_segs_using_this_lv ( log_lv , mirrored_seg ) )
return_0 ;
2008-01-26 03:25:04 +03:00
return log_lv ;
2008-01-16 22:00:59 +03:00
}
2008-01-16 22:11:39 +03:00
/* Check if mirror image LV is removable with regard to given removable_pvs */
2010-05-24 19:32:20 +04:00
int is_mirror_image_removable ( struct logical_volume * mimage_lv , void * baton )
2008-01-16 22:11:39 +03:00
{
struct physical_volume * pv ;
struct lv_segment * seg ;
int pv_found ;
struct pv_list * pvl ;
uint32_t s ;
2010-05-24 19:32:20 +04:00
struct dm_list * removable_pvs = baton ;
if ( ! baton | | dm_list_empty ( removable_pvs ) )
return 1 ;
2008-01-16 22:11:39 +03:00
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( seg , & mimage_lv - > segments ) {
2008-01-16 22:11:39 +03:00
for ( s = 0 ; s < seg - > area_count ; s + + ) {
2008-01-16 22:38:39 +03:00
if ( seg_type ( seg , s ) ! = AREA_PV ) {
/* FIXME Recurse for AREA_LV? */
/* Structure of seg_lv is unknown.
* Not removing this LV for safety . */
return 0 ;
}
2008-01-16 22:11:39 +03:00
pv = seg_pv ( seg , s ) ;
pv_found = 0 ;
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( pvl , removable_pvs ) {
2009-04-23 20:43:01 +04:00
if ( id_equal ( & pv - > id , & pvl - > pv - > id ) ) {
pv_found = 1 ;
break ;
}
if ( pvl - > pv - > dev & & pv - > dev & &
pv - > dev - > dev = = pvl - > pv - > dev - > dev ) {
2008-01-16 22:11:39 +03:00
pv_found = 1 ;
break ;
}
}
if ( ! pv_found )
return 0 ;
}
}
return 1 ;
}
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
/*
* _move_removable_mimages_to_end
*
* We always detach mimage LVs from the end of the areas array .
* This function will push ' count ' mimages to the end of the array
* based on if their PVs are removable .
*
* This is an all or nothing function . Either the user specifies
* enough removable PVs to satisfy count , or they don ' t specify
* any removable_pvs at all ( in which case all PVs in the mirror
* are considered removable ) .
*/
static int _move_removable_mimages_to_end ( struct logical_volume * lv ,
uint32_t count ,
struct dm_list * removable_pvs )
{
2010-08-06 19:38:32 +04:00
int i ;
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
struct logical_volume * sub_lv ;
struct lv_segment * mirrored_seg = first_seg ( lv ) ;
if ( ! removable_pvs )
return 1 ;
2010-08-06 19:38:32 +04:00
for ( i = mirrored_seg - > area_count - 1 ; ( i > = 0 ) & & count ; i - - ) {
sub_lv = seg_lv ( mirrored_seg , i ) ;
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 ( ! is_temporary_mirror_layer ( sub_lv ) & &
is_mirror_image_removable ( sub_lv , removable_pvs ) ) {
if ( ! shift_mirror_images ( mirrored_seg , i ) )
return_0 ;
count - - ;
}
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
}
return ! count ;
}
2010-04-20 16:14:28 +04:00
static int _mirrored_lv_in_sync ( struct logical_volume * lv )
{
2014-06-09 14:08:27 +04:00
dm_percent_t sync_percent ;
2010-04-20 16:14:28 +04:00
if ( ! lv_mirror_percent ( lv - > vg - > cmd , lv , 0 , & sync_percent ,
2010-11-30 14:53:31 +03:00
NULL ) ) {
2011-10-06 18:55:39 +04:00
if ( lv_is_active_but_not_locally ( lv ) )
log_error ( " Unable to determine mirror sync status of "
2018-03-27 22:08:20 +03:00
" remotely active LV, %s " ,
display_lvname ( lv ) ) ;
2011-10-06 18:55:39 +04:00
else
log_error ( " Unable to determine mirror "
2018-03-27 22:08:20 +03:00
" sync status of %s. " ,
display_lvname ( lv ) ) ;
2010-04-20 16:14:28 +04:00
return 0 ;
}
2014-06-09 14:08:27 +04:00
return ( sync_percent = = DM_PERCENT_100 ) ? 1 : 0 ;
2010-04-20 16:14:28 +04: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
/*
* Split off ' split_count ' legs from a mirror
*
* Returns : 0 on error , 1 on success
*/
static int _split_mirror_images ( struct logical_volume * lv ,
const char * split_name ,
uint32_t split_count ,
struct dm_list * removable_pvs )
{
uint32_t i ;
2010-07-14 01:48:16 +04:00
struct logical_volume * sub_lv = NULL ;
struct logical_volume * new_lv = 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
struct logical_volume * detached_log_lv = NULL ;
struct lv_segment * mirrored_seg = first_seg ( lv ) ;
struct dm_list split_images ;
2011-10-06 18:55:39 +04:00
struct lv_list * lvl ;
Fix for bug 732142: Unsafe table load during mirror image split
There was a bad sequence:
*) Make changes to LV layout to split images (e.g. 4-way -> 2-way/2-way)
1) vg_write, suspend_lv(original_mirror), vg_commit
2) activate_lv(newly_split_lv)
3) resume_lv(original_mirror)
Step #2 is not allowed. However, without it, the resume of the original
mirror will also resume its former sub-LVs - making it impossible to
activate the newly split LV due to the changes in layering, pointers, and
names that had already been made. Additionally, the resume or the original
brings the sub-lv's online with names that differ from the metadata on disk -
also a no-no. Thus, the split must be done in stages such that the active LVs
always reflect what is in the committed LVM metadata.
First, alter the original mirror by releasing the images. The images are made
visible and independent as an intermediate stage. (This way, we can have
consistency between LVM metadata and active LVs.) The second stage collects
the recently split LVs, deactivates them, forms them into a mirror if necessary,
and then activates them. It is a bit of a circuitous method, but it is the only
way to split a mirror from a mirror and obey these general rules:
1) Never [de]activate sub-lvs when the top-level LV is suspended
2) Avoid having active LVs that differ from the description in the LVM metadata
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2011-09-01 23:22:11 +04:00
struct cmd_context * cmd = lv - > vg - > cmd ;
2016-12-11 14:19:38 +03:00
char layer_name [ NAME_LEN ] , format [ NAME_LEN ] ;
2018-03-13 14:48:36 +03:00
int act ;
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
2014-09-16 00:33:53 +04:00
if ( ! lv_is_mirrored ( lv ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Unable to split non-mirrored LV %s. " ,
display_lvname ( lv ) ) ;
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
return 0 ;
}
if ( ! split_count ) {
Fix for bug 732142: Unsafe table load during mirror image split
There was a bad sequence:
*) Make changes to LV layout to split images (e.g. 4-way -> 2-way/2-way)
1) vg_write, suspend_lv(original_mirror), vg_commit
2) activate_lv(newly_split_lv)
3) resume_lv(original_mirror)
Step #2 is not allowed. However, without it, the resume of the original
mirror will also resume its former sub-LVs - making it impossible to
activate the newly split LV due to the changes in layering, pointers, and
names that had already been made. Additionally, the resume or the original
brings the sub-lv's online with names that differ from the metadata on disk -
also a no-no. Thus, the split must be done in stages such that the active LVs
always reflect what is in the committed LVM metadata.
First, alter the original mirror by releasing the images. The images are made
visible and independent as an intermediate stage. (This way, we can have
consistency between LVM metadata and active LVs.) The second stage collects
the recently split LVs, deactivates them, forms them into a mirror if necessary,
and then activates them. It is a bit of a circuitous method, but it is the only
way to split a mirror from a mirror and obey these general rules:
1) Never [de]activate sub-lvs when the top-level LV is suspended
2) Avoid having active LVs that differ from the description in the LVM metadata
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2011-09-01 23:22:11 +04:00
log_error ( INTERNAL_ERROR " split_count is zero! " ) ;
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
return 0 ;
}
2016-11-16 17:11:07 +03:00
log_verbose ( " Detaching %d images from mirror %s. " ,
split_count , display_lvname ( lv ) ) ;
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
if ( ! _move_removable_mimages_to_end ( lv , split_count , removable_pvs ) ) {
/*
* FIXME : Allow incomplete specification of removable PVs ?
*
* I am forcing the user to either specify no
* removable PVs or all of them . Should we allow
* them to just specify some - making us pick the rest ?
*/
2016-11-16 17:11:07 +03:00
log_error ( " Insufficient removable PVs given to satisfy request. " ) ;
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
return 0 ;
}
Fix for bug 732142: Unsafe table load during mirror image split
There was a bad sequence:
*) Make changes to LV layout to split images (e.g. 4-way -> 2-way/2-way)
1) vg_write, suspend_lv(original_mirror), vg_commit
2) activate_lv(newly_split_lv)
3) resume_lv(original_mirror)
Step #2 is not allowed. However, without it, the resume of the original
mirror will also resume its former sub-LVs - making it impossible to
activate the newly split LV due to the changes in layering, pointers, and
names that had already been made. Additionally, the resume or the original
brings the sub-lv's online with names that differ from the metadata on disk -
also a no-no. Thus, the split must be done in stages such that the active LVs
always reflect what is in the committed LVM metadata.
First, alter the original mirror by releasing the images. The images are made
visible and independent as an intermediate stage. (This way, we can have
consistency between LVM metadata and active LVs.) The second stage collects
the recently split LVs, deactivates them, forms them into a mirror if necessary,
and then activates them. It is a bit of a circuitous method, but it is the only
way to split a mirror from a mirror and obey these general rules:
1) Never [de]activate sub-lvs when the top-level LV is suspended
2) Avoid having active LVs that differ from the description in the LVM metadata
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2011-09-01 23:22:11 +04:00
/*
* Step 1 :
* Remove the images from the mirror .
* Make them visible , independent LVs ( don ' t change names yet ) .
* Track them in a list for later instantiation .
*/
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
dm_list_init ( & split_images ) ;
for ( i = 0 ; i < split_count ; i + + ) {
mirrored_seg - > area_count - - ;
sub_lv = seg_lv ( mirrored_seg , mirrored_seg - > area_count ) ;
sub_lv - > status & = ~ MIRROR_IMAGE ;
2012-06-27 22:37:54 +04:00
if ( ! release_lv_segment_area ( mirrored_seg , mirrored_seg - > area_count , mirrored_seg - > area_len ) )
return_0 ;
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-11-16 17:11:07 +03:00
log_very_verbose ( " LV %s assigned to be split. " , display_lvname ( sub_lv ) ) ;
2010-07-14 01:48:16 +04:00
2011-10-06 18:55:39 +04:00
if ( ! new_lv ) {
lv_set_visible ( sub_lv ) ;
new_lv = sub_lv ;
continue ;
}
/* If there is more than one image being split, add to list */
Fix for bug 732142: Unsafe table load during mirror image split
There was a bad sequence:
*) Make changes to LV layout to split images (e.g. 4-way -> 2-way/2-way)
1) vg_write, suspend_lv(original_mirror), vg_commit
2) activate_lv(newly_split_lv)
3) resume_lv(original_mirror)
Step #2 is not allowed. However, without it, the resume of the original
mirror will also resume its former sub-LVs - making it impossible to
activate the newly split LV due to the changes in layering, pointers, and
names that had already been made. Additionally, the resume or the original
brings the sub-lv's online with names that differ from the metadata on disk -
also a no-no. Thus, the split must be done in stages such that the active LVs
always reflect what is in the committed LVM metadata.
First, alter the original mirror by releasing the images. The images are made
visible and independent as an intermediate stage. (This way, we can have
consistency between LVM metadata and active LVs.) The second stage collects
the recently split LVs, deactivates them, forms them into a mirror if necessary,
and then activates them. It is a bit of a circuitous method, but it is the only
way to split a mirror from a mirror and obey these general rules:
1) Never [de]activate sub-lvs when the top-level LV is suspended
2) Avoid having active LVs that differ from the description in the LVM metadata
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2011-09-01 23:22:11 +04:00
lvl = dm_pool_alloc ( lv - > vg - > vgmem , sizeof ( * lvl ) ) ;
if ( ! lvl ) {
2016-11-16 17:11:07 +03:00
log_error ( " lv_list alloc failed. " ) ;
Fix for bug 732142: Unsafe table load during mirror image split
There was a bad sequence:
*) Make changes to LV layout to split images (e.g. 4-way -> 2-way/2-way)
1) vg_write, suspend_lv(original_mirror), vg_commit
2) activate_lv(newly_split_lv)
3) resume_lv(original_mirror)
Step #2 is not allowed. However, without it, the resume of the original
mirror will also resume its former sub-LVs - making it impossible to
activate the newly split LV due to the changes in layering, pointers, and
names that had already been made. Additionally, the resume or the original
brings the sub-lv's online with names that differ from the metadata on disk -
also a no-no. Thus, the split must be done in stages such that the active LVs
always reflect what is in the committed LVM metadata.
First, alter the original mirror by releasing the images. The images are made
visible and independent as an intermediate stage. (This way, we can have
consistency between LVM metadata and active LVs.) The second stage collects
the recently split LVs, deactivates them, forms them into a mirror if necessary,
and then activates them. It is a bit of a circuitous method, but it is the only
way to split a mirror from a mirror and obey these general rules:
1) Never [de]activate sub-lvs when the top-level LV is suspended
2) Avoid having active LVs that differ from the description in the LVM metadata
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2011-09-01 23:22:11 +04:00
return 0 ;
}
lvl - > lv = sub_lv ;
dm_list_add ( & split_images , & lvl - > list ) ;
}
new_lv - > name = dm_pool_strdup ( lv - > vg - > vgmem , split_name ) ;
if ( ! new_lv - > name ) {
2018-03-27 22:08:20 +03:00
log_error ( " Unable to rename newly split LV. " ) ;
Fix for bug 732142: Unsafe table load during mirror image split
There was a bad sequence:
*) Make changes to LV layout to split images (e.g. 4-way -> 2-way/2-way)
1) vg_write, suspend_lv(original_mirror), vg_commit
2) activate_lv(newly_split_lv)
3) resume_lv(original_mirror)
Step #2 is not allowed. However, without it, the resume of the original
mirror will also resume its former sub-LVs - making it impossible to
activate the newly split LV due to the changes in layering, pointers, and
names that had already been made. Additionally, the resume or the original
brings the sub-lv's online with names that differ from the metadata on disk -
also a no-no. Thus, the split must be done in stages such that the active LVs
always reflect what is in the committed LVM metadata.
First, alter the original mirror by releasing the images. The images are made
visible and independent as an intermediate stage. (This way, we can have
consistency between LVM metadata and active LVs.) The second stage collects
the recently split LVs, deactivates them, forms them into a mirror if necessary,
and then activates them. It is a bit of a circuitous method, but it is the only
way to split a mirror from a mirror and obey these general rules:
1) Never [de]activate sub-lvs when the top-level LV is suspended
2) Avoid having active LVs that differ from the description in the LVM metadata
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2011-09-01 23:22:11 +04:00
return 0 ;
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
}
if ( ! dm_list_empty ( & split_images ) ) {
Fix for bug 732142: Unsafe table load during mirror image split
There was a bad sequence:
*) Make changes to LV layout to split images (e.g. 4-way -> 2-way/2-way)
1) vg_write, suspend_lv(original_mirror), vg_commit
2) activate_lv(newly_split_lv)
3) resume_lv(original_mirror)
Step #2 is not allowed. However, without it, the resume of the original
mirror will also resume its former sub-LVs - making it impossible to
activate the newly split LV due to the changes in layering, pointers, and
names that had already been made. Additionally, the resume or the original
brings the sub-lv's online with names that differ from the metadata on disk -
also a no-no. Thus, the split must be done in stages such that the active LVs
always reflect what is in the committed LVM metadata.
First, alter the original mirror by releasing the images. The images are made
visible and independent as an intermediate stage. (This way, we can have
consistency between LVM metadata and active LVs.) The second stage collects
the recently split LVs, deactivates them, forms them into a mirror if necessary,
and then activates them. It is a bit of a circuitous method, but it is the only
way to split a mirror from a mirror and obey these general rules:
1) Never [de]activate sub-lvs when the top-level LV is suspended
2) Avoid having active LVs that differ from the description in the LVM metadata
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2011-09-01 23:22:11 +04:00
/*
* A number of images have been split and
* a new mirror layer must be formed
*/
if ( ! insert_layer_for_lv ( cmd , new_lv , 0 , " _mimage_%d " ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed to build new mirror, %s. " ,
display_lvname ( new_lv ) ) ;
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
return 0 ;
}
first_seg ( new_lv ) - > region_size = mirrored_seg - > region_size ;
dm_list_iterate_items ( lvl , & split_images ) {
sub_lv = lvl - > lv ;
2016-12-11 14:19:38 +03:00
if ( dm_snprintf ( format , sizeof ( format ) , " %s_mimage_%%d " ,
2012-02-08 15:40:02 +04:00
new_lv - > name ) < 0 ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed to build new image name for %s. " ,
display_lvname ( new_lv ) ) ;
2012-02-08 15:40:02 +04:00
return 0 ;
}
2016-12-11 14:19:38 +03:00
if ( ! generate_lv_name ( lv - > vg , format , layer_name , sizeof ( layer_name ) ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed to generate new image names for %s. " ,
display_lvname ( new_lv ) ) ;
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
return 0 ;
}
2016-12-11 14:19:38 +03:00
if ( ! ( sub_lv - > name = dm_pool_strdup ( lv - > vg - > vgmem , layer_name ) ) ) {
log_error ( " Unable to allocate memory. " ) ;
return 0 ;
}
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
}
if ( ! _merge_mirror_images ( new_lv , & split_images ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed to group split images into new mirror. " ) ;
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
return 0 ;
}
/*
* We don ' t allow splitting a mirror that is not in - sync ,
* so we can bring the newly split mirror up without a
* resync . ( It will be a ' core ' log mirror after all . )
*/
init_mirror_in_sync ( 1 ) ;
}
2011-10-06 18:55:39 +04:00
sub_lv = NULL ;
/*
* If no more mirrors , remove mirror layer .
* The sub_lv is removed entirely later - leaving
* only the top - level ( now linear ) LV .
*/
if ( mirrored_seg - > area_count = = 1 ) {
sub_lv = seg_lv ( mirrored_seg , 0 ) ;
sub_lv - > status & = ~ MIRROR_IMAGE ;
lv_set_visible ( sub_lv ) ;
detached_log_lv = detach_mirror_log ( mirrored_seg ) ;
if ( ! remove_layer_from_lv ( lv , sub_lv ) )
return_0 ;
2016-11-23 12:54:06 +03:00
lv - > status & = ~ ( MIRROR | MIRRORED | LV_NOTSYNCED ) ;
2011-10-06 18:55:39 +04:00
}
/*
2016-11-23 12:57:36 +03:00
* Suspend and resume the mirror - this includes all
* the sub - LVs and soon - to - be - split sub - LVs
2011-10-06 18:55:39 +04:00
*/
2018-03-13 14:48:36 +03:00
if ( ! lv_update_and_reload ( lv ) )
2016-11-23 12:57:36 +03:00
return_0 ;
2011-10-06 18:55:39 +04:00
2018-03-13 14:48:36 +03:00
act = lv_is_active ( lv_lock_holder ( lv ) ) ;
if ( act & & ! _activate_lv_like_model ( lv , new_lv ) ) {
2011-10-06 18:55:39 +04:00
log_error ( " Failed to rename newly split LV in the kernel " ) ;
return 0 ;
}
/* Remove original mirror layer if it has been converted to linear */
2018-03-13 14:48:36 +03:00
if ( sub_lv & & ! _delete_lv ( lv , sub_lv , act ) )
2011-10-06 18:55:39 +04:00
return_0 ;
/* Remove the log if it has been converted to linear */
2018-03-13 14:48:36 +03:00
if ( detached_log_lv & & ! _delete_lv ( lv , detached_log_lv , act ) )
2011-10-06 18:55:39 +04:00
return_0 ;
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
return 1 ;
}
2005-06-06 21:12:08 +04:00
/*
2007-12-20 21:55:46 +03:00
* Remove num_removed images from mirrored_seg
2008-01-17 16:13:54 +03:00
*
* Arguments :
* num_removed : the requested ( maximum ) number of mirrors to be removed
2010-03-27 01:15:43 +03:00
* removable_pvs : if not NULL and list not empty , only mirrors using PVs
* in this list will be removed
2008-01-17 16:13:54 +03:00
* remove_log : if non - zero , log_lv will be removed
* ( even if it ' s 0 , log_lv will be removed if there is no
* mirror remaining after the removal )
* collapse : if non - zero , instead of removing , remove the temporary
* mirror layer and merge mirrors to the original LV .
* removable_pvs should be NULL and num_removed should be
* seg - > area_count - 1.
* removed : if non NULL , the number of removed mirror images is set
* as a result
*
* If collapse is non - zero , < removed > is guaranteed to be equal to num_removed .
*
* Return values :
* Failure ( 0 ) means something unexpected has happend and
* the caller should abort .
* Even if no mirror was removed ( e . g . no LV matches to ' removable_pvs ' ) ,
* returns success ( 1 ) .
2005-06-06 21:12:08 +04:00
*/
2007-12-20 21:55:46 +03:00
static int _remove_mirror_images ( struct logical_volume * lv ,
uint32_t num_removed ,
2010-05-24 19:32:20 +04:00
int ( * is_removable ) ( struct logical_volume * , void * ) ,
void * removable_baton ,
2008-01-17 16:13:54 +03:00
unsigned remove_log , unsigned collapse ,
2011-03-24 15:28:02 +03:00
uint32_t * removed , int preferred_only )
2005-06-06 21:12:08 +04:00
{
uint32_t m ;
2010-04-21 17:55:08 +04:00
int32_t s ;
2005-11-29 21:20:23 +03:00
struct logical_volume * sub_lv ;
2008-01-26 03:25:04 +03:00
struct logical_volume * detached_log_lv = NULL ;
2009-12-09 22:43:39 +03:00
struct logical_volume * temp_layer_lv = NULL ;
2016-11-23 12:48:33 +03:00
struct lv_segment * seg , * pvmove_seg , * mirrored_seg = first_seg ( lv ) ;
2005-11-29 21:20:23 +03:00
uint32_t old_area_count = mirrored_seg - > area_count ;
uint32_t new_area_count = mirrored_seg - > area_count ;
2007-12-20 21:55:46 +03:00
struct lv_list * lvl ;
2008-11-04 01:14:30 +03:00
struct dm_list tmp_orphan_lvs ;
2013-11-25 16:42:30 +04:00
uint32_t orig_removed = num_removed ;
2015-01-07 12:52:38 +03:00
int reactivate ;
2005-11-29 21:20:23 +03:00
2008-01-17 16:13:54 +03:00
if ( removed )
* removed = 0 ;
2016-11-16 17:11:07 +03:00
log_very_verbose ( " Reducing mirror set %s from " FMTu32 " to " FMTu32
" image(s)%s. " , display_lvname ( lv ) ,
2007-12-20 21:55:46 +03:00
old_area_count , old_area_count - num_removed ,
2005-11-29 21:20:23 +03:00
remove_log ? " and no log volume " : " " ) ;
2010-05-24 19:32:20 +04:00
if ( collapse & & ( old_area_count - num_removed ! = 1 ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Incompatible parameters to _remove_mirror_images. " ) ;
2008-01-10 21:35:51 +03:00
return 0 ;
}
2011-03-24 15:28:02 +03:00
num_removed = 0 ;
2005-11-29 21:20:23 +03:00
/* Move removable_pvs to end of array */
2010-05-24 19:32:20 +04:00
for ( s = mirrored_seg - > area_count - 1 ;
2011-03-24 15:28:02 +03:00
s > = 0 & & old_area_count - new_area_count < orig_removed ;
2010-05-24 19:32:20 +04:00
s - - ) {
sub_lv = seg_lv ( mirrored_seg , s ) ;
2012-12-14 22:42:28 +04:00
if ( ! ( is_temporary_mirror_layer ( sub_lv ) & & lv_mirror_count ( sub_lv ) ! = 1 ) ) {
if ( ! is_removable ) {
2013-06-15 04:28:54 +04:00
log_error ( INTERNAL_ERROR " _remove_mirror_images called incorrectly with is_removable undefined. " ) ;
2012-12-14 22:42:28 +04:00
return 0 ;
}
if ( ! is_removable ( sub_lv , removable_baton ) )
continue ;
2010-05-24 19:32:20 +04:00
/*
* Check if the user is trying to pull the
* primary mirror image when the mirror is
* not in - sync .
*/
if ( ( s = = 0 ) & & ! _mirrored_lv_in_sync ( lv ) & &
2016-03-02 22:59:03 +03:00
! ( lv_is_partial ( lv ) ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Unable to remove primary mirror image while mirror volume "
" %s is not in-sync. " , display_lvname ( lv ) ) ;
2012-02-24 02:24:47 +04:00
return 0 ;
2005-11-29 21:20:23 +03:00
}
2010-05-24 19:32:20 +04:00
if ( ! shift_mirror_images ( mirrored_seg , s ) )
return_0 ;
2011-03-24 15:28:02 +03:00
- - new_area_count ;
+ + num_removed ;
2005-11-29 21:20:23 +03:00
}
2010-04-27 18:57:49 +04:00
}
2011-03-24 15:28:02 +03:00
if ( ! preferred_only )
num_removed = orig_removed ;
2010-04-27 18:57:49 +04:00
/*
* If removable_pvs were specified , then they have been shifted
* to the end to ensure they are removed . The remaining balance
* of images left to remove will be taken from the unspecified .
*/
new_area_count = old_area_count - num_removed ;
2005-06-06 21:12:08 +04:00
2010-05-24 19:32:20 +04:00
if ( num_removed & & old_area_count = = new_area_count )
return 1 ;
2007-12-20 21:55:46 +03:00
/* Remove mimage LVs from the segment */
2008-11-04 01:14:30 +03:00
dm_list_init ( & tmp_orphan_lvs ) ;
2007-12-20 21:55:46 +03:00
for ( m = new_area_count ; m < mirrored_seg - > area_count ; m + + ) {
2005-11-29 21:20:23 +03:00
seg_lv ( mirrored_seg , m ) - > status & = ~ MIRROR_IMAGE ;
2009-05-14 01:26:45 +04:00
lv_set_visible ( seg_lv ( mirrored_seg , m ) ) ;
2007-12-20 21:55:46 +03:00
if ( ! ( lvl = dm_pool_alloc ( lv - > vg - > cmd - > mem , sizeof ( * lvl ) ) ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " lv_list alloc failed. " ) ;
2007-12-20 21:55:46 +03:00
return 0 ;
}
lvl - > lv = seg_lv ( mirrored_seg , m ) ;
2008-11-04 01:14:30 +03:00
dm_list_add ( & tmp_orphan_lvs , & lvl - > list ) ;
2012-06-27 22:37:54 +04:00
if ( ! release_lv_segment_area ( mirrored_seg , m , mirrored_seg - > area_len ) )
return_0 ;
2005-11-29 21:20:23 +03:00
}
2007-12-20 21:55:46 +03:00
mirrored_seg - > area_count = new_area_count ;
2005-11-29 21:20:23 +03:00
/* If no more mirrors, remove mirror layer */
2008-01-17 16:13:54 +03:00
/* As an exceptional case, if the lv is temporary layer,
* leave the LV as mirrored and let the lvconvert completion
* to remove the layer . */
if ( new_area_count = = 1 & & ! is_temporary_mirror_layer ( lv ) ) {
2009-12-09 22:43:39 +03:00
temp_layer_lv = seg_lv ( mirrored_seg , 0 ) ;
temp_layer_lv - > status & = ~ MIRROR_IMAGE ;
lv_set_visible ( temp_layer_lv ) ;
2008-01-26 03:25:04 +03:00
detached_log_lv = detach_mirror_log ( mirrored_seg ) ;
2009-12-09 22:43:39 +03:00
if ( ! remove_layer_from_lv ( lv , temp_layer_lv ) )
2006-11-30 20:52:47 +03:00
return_0 ;
2008-01-10 21:35:51 +03:00
if ( collapse & & ! _merge_mirror_images ( lv , & tmp_orphan_lvs ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed to add mirror images. " ) ;
2008-01-10 21:35:51 +03:00
return 0 ;
}
2016-11-23 12:54:06 +03:00
/*
* No longer a mirror ? Even though new_area_count was 1 ,
* _merge_mirror_images may have resulted into lv being still a
* mirror . Fix up the flags if we only have one image left .
*/
if ( lv_mirror_count ( lv ) = = 1 )
lv - > status & = ~ ( MIRROR | MIRRORED | LV_NOTSYNCED ) ;
2010-06-21 20:12:33 +04:00
mirrored_seg = first_seg ( lv ) ;
if ( remove_log & & ! detached_log_lv )
detached_log_lv = detach_mirror_log ( mirrored_seg ) ;
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
2014-09-16 00:33:53 +04:00
if ( lv_is_pvmove ( lv ) )
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
dm_list_iterate_items ( pvmove_seg , & lv - > segments )
pvmove_seg - > status | = PVMOVE ;
2008-01-17 16:13:54 +03:00
} else if ( new_area_count = = 0 ) {
2016-11-16 17:11:07 +03:00
log_very_verbose ( " All mimages of %s are gone. " , display_lvname ( lv ) ) ;
2008-01-19 01:00:46 +03:00
2008-01-17 16:13:54 +03:00
/* All mirror images are gone.
* It can happen for vgreduce - - removemissing . */
2008-01-26 03:25:04 +03:00
detached_log_lv = detach_mirror_log ( mirrored_seg ) ;
2016-11-23 12:54:06 +03:00
lv - > status & = ~ ( MIRROR | MIRRORED | LV_NOTSYNCED ) ;
2008-01-17 16:54:05 +03:00
if ( ! replace_lv_with_error_segment ( lv ) )
2008-01-17 16:13:54 +03:00
return_0 ;
2010-08-03 01:07:40 +04:00
} else if ( remove_log )
2008-01-26 03:25:04 +03:00
detached_log_lv = detach_mirror_log ( mirrored_seg ) ;
2005-06-06 21:12:08 +04:00
2010-08-03 01:07:40 +04:00
/*
* The log may be removed due to repair . If the log
* happens to be a mirrored log , then there is a special
* case we need to consider . One of the images of a
* mirrored log can fail followed shortly afterwards by
* a failure of the second . This means that the top - level
* mirror is waiting for writes to the log to finish , but
* they never will unless the mirrored log can be repaired
* or replaced with an error target . Since both the devices
* have failed , we must replace with error target - it is
* the only way to release the pending writes .
*/
if ( detached_log_lv & & lv_is_mirrored ( detached_log_lv ) & &
2016-03-02 22:59:03 +03:00
lv_is_partial ( detached_log_lv ) ) {
2016-11-23 12:48:33 +03:00
seg = first_seg ( detached_log_lv ) ;
2010-10-15 00:03:12 +04:00
2016-11-16 17:11:07 +03:00
log_very_verbose ( " %s being removed due to failures. " ,
display_lvname ( detached_log_lv ) ) ;
2010-08-03 01:07:40 +04:00
2010-10-15 00:03:12 +04:00
/*
* We are going to replace the mirror with an
* error segment , but before we do , we must remember
* all of the LVs that must be deleted later ( i . e .
* the sub - lv ' s )
*/
for ( m = 0 ; m < seg - > area_count ; m + + ) {
2016-11-16 17:11:07 +03:00
if ( ! ( lvl = dm_pool_alloc ( lv - > vg - > cmd - > mem ,
sizeof ( * lvl ) ) ) )
return_0 ;
2010-10-15 00:03:12 +04:00
seg_lv ( seg , m ) - > status & = ~ MIRROR_IMAGE ;
lv_set_visible ( seg_lv ( seg , m ) ) ;
lvl - > lv = seg_lv ( seg , m ) ;
dm_list_add ( & tmp_orphan_lvs , & lvl - > list ) ;
}
2010-08-03 01:07:40 +04:00
if ( ! replace_lv_with_error_segment ( detached_log_lv ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed error target substitution for %s. " ,
display_lvname ( detached_log_lv ) ) ;
2010-08-03 01:07:40 +04:00
return 0 ;
}
2016-11-23 12:57:36 +03:00
if ( ! lv_update_and_reload ( detached_log_lv ) )
2010-10-15 00:03:12 +04:00
return_0 ;
2010-07-09 19:08:12 +04:00
}
2005-11-29 21:20:23 +03:00
/*
* To successfully remove these unwanted LVs we need to
* remove the LVs from the mirror set , commit that metadata
* then deactivate and remove them fully .
*/
2017-11-24 15:58:23 +03:00
if ( ! lv_update_and_reload_origin ( mirrored_seg - > lv ) )
2010-01-06 00:07:31 +03:00
return_0 ;
2005-06-06 21:12:08 +04:00
2007-12-20 21:55:46 +03:00
/* Save or delete the 'orphan' LVs */
2015-01-07 12:52:38 +03:00
reactivate = lv_is_active ( lv_lock_holder ( lv ) ) ;
2008-01-10 21:35:51 +03:00
if ( ! collapse ) {
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( lvl , & tmp_orphan_lvs )
2015-01-07 12:52:38 +03:00
if ( ! _delete_lv ( lv , lvl - > lv , reactivate ) )
2008-01-26 03:25:04 +03:00
return_0 ;
2007-12-20 21:55:46 +03:00
}
2006-07-21 00:37:10 +04:00
2015-01-07 12:52:38 +03:00
if ( temp_layer_lv & & ! _delete_lv ( lv , temp_layer_lv , reactivate ) )
2008-01-26 03:25:04 +03:00
return_0 ;
2005-11-29 21:20:23 +03:00
2015-01-07 12:52:38 +03:00
if ( detached_log_lv & & ! _delete_lv ( lv , detached_log_lv , reactivate ) )
2008-01-26 03:25:04 +03:00
return_0 ;
2005-11-29 21:20:23 +03:00
2008-01-17 16:13:54 +03:00
/* Mirror with only 1 area is 'in sync'. */
2008-01-26 03:25:04 +03:00
if ( new_area_count = = 1 & & is_temporary_mirror_layer ( lv ) ) {
2018-03-13 14:48:36 +03:00
detached_log_lv = detach_mirror_log ( mirrored_seg ) ;
2018-03-30 00:26:22 +03:00
if ( ! _init_mirror_log ( lv - > vg - > cmd ,
( struct logical_volume * ) lv_lock_holder ( mirrored_seg - > lv ) ,
detached_log_lv ,
2008-01-26 03:25:04 +03:00
1 , & lv - > tags , 0 ) ) {
2008-01-17 16:13:54 +03:00
/* As a result, unnecessary sync may run after
* collapsing . But safe . */
2016-11-16 17:11:07 +03:00
log_error ( " Failed to initialize log device %s. " ,
2018-03-13 14:48:36 +03:00
display_lvname ( detached_log_lv ) ) ;
2012-02-24 02:24:47 +04:00
return 0 ;
2008-01-17 16:13:54 +03:00
}
2018-03-13 14:48:36 +03:00
if ( ! attach_mirror_log ( mirrored_seg , detached_log_lv ) )
return_0 ;
2008-01-17 16:13:54 +03:00
}
if ( removed )
* removed = old_area_count - new_area_count ;
2016-11-16 17:11:07 +03:00
log_very_verbose ( FMTu32 " image(s) removed from %s. " ,
old_area_count - new_area_count ,
display_lvname ( lv ) ) ;
2008-01-19 01:00:46 +03:00
2005-11-29 21:20:23 +03:00
return 1 ;
2005-06-06 21:12:08 +04:00
}
2007-12-20 21:55:46 +03:00
/*
* Remove the number of mirror images from the LV
*/
int remove_mirror_images ( struct logical_volume * lv , uint32_t num_mirrors ,
2010-05-24 19:32:20 +04:00
int ( * is_removable ) ( struct logical_volume * , void * ) ,
void * removable_baton , unsigned remove_log )
2007-12-20 21:55:46 +03:00
{
2008-01-17 16:13:54 +03:00
uint32_t num_removed , removed_once , r ;
2007-12-20 21:55:46 +03:00
uint32_t existing_mirrors = lv_mirror_count ( lv ) ;
2008-01-17 16:13:54 +03:00
struct logical_volume * next_lv = lv ;
2007-12-20 21:55:46 +03:00
2011-03-24 15:28:02 +03:00
int preferred_only = 1 ;
int retries = 0 ;
2007-12-20 21:55:46 +03:00
num_removed = existing_mirrors - num_mirrors ;
2008-01-10 21:35:51 +03:00
/* num_removed can be 0 if the function is called just to remove log */
do {
2008-01-17 16:13:54 +03:00
if ( num_removed < first_seg ( next_lv ) - > area_count )
2007-12-20 21:55:46 +03:00
removed_once = num_removed ;
else
2008-01-17 16:13:54 +03:00
removed_once = first_seg ( next_lv ) - > area_count - 1 ;
2007-12-20 21:55:46 +03:00
2008-01-17 16:13:54 +03:00
if ( ! _remove_mirror_images ( next_lv , removed_once ,
2010-05-24 19:32:20 +04:00
is_removable , removable_baton ,
2011-03-24 15:28:02 +03:00
remove_log , 0 , & r , preferred_only ) )
2007-12-20 21:55:46 +03:00
return_0 ;
2011-03-24 15:28:02 +03:00
if ( r < removed_once | | ! removed_once ) {
2008-01-17 16:13:54 +03:00
/* Some mirrors are removed from the temporary mirror,
* but the temporary layer still exists .
* Down the stack and retry for remainder . */
2008-01-17 16:54:05 +03:00
next_lv = find_temporary_mirror ( next_lv ) ;
2011-03-24 15:28:02 +03:00
if ( ! next_lv ) {
preferred_only = 0 ;
next_lv = lv ;
}
2008-01-17 16:13:54 +03:00
}
num_removed - = r ;
2011-03-24 15:28:02 +03:00
/*
* if there are still images to be removed , try again ; this is
* required since some temporary layers may have been reduced
* to 1 , at which point they are made removable , just like
* normal images
*/
if ( ! next_lv & & ! preferred_only & & ! retries & & num_removed ) {
+ + retries ;
preferred_only = 1 ;
}
2008-01-17 16:13:54 +03:00
} while ( next_lv & & num_removed ) ;
if ( num_removed ) {
if ( num_removed = = existing_mirrors - num_mirrors )
log_error ( " No mirror images found using specified PVs. " ) ;
else {
log_error ( " %u images are removed out of requested %u. " ,
existing_mirrors - lv_mirror_count ( lv ) ,
existing_mirrors - num_mirrors ) ;
}
return 0 ;
}
2007-12-20 21:55:46 +03:00
return 1 ;
}
2010-07-09 19:34:40 +04:00
static int _no_removable_images ( struct logical_volume * lv __attribute__ ( ( unused ) ) ,
void * baton __attribute__ ( ( unused ) ) ) {
2010-05-24 19:32:20 +04:00
return 0 ;
}
2007-12-20 21:55:46 +03:00
/*
* Collapsing temporary mirror layers .
*
* When mirrors are added to already - mirrored LV , a temporary mirror layer
* is inserted at the top of the stack to reduce resync work .
* The function will remove the intermediate layer and collapse the stack
* as far as mirrors are in - sync .
*
* The function is destructive : to remove intermediate mirror layers ,
* VG metadata commits and suspend / resume are necessary .
*/
int collapse_mirrored_lv ( struct logical_volume * lv )
{
2008-01-16 22:00:59 +03:00
struct logical_volume * tmp_lv ;
struct lv_segment * mirror_seg ;
2007-12-20 21:55:46 +03:00
2008-01-16 22:13:51 +03:00
while ( ( tmp_lv = find_temporary_mirror ( lv ) ) ) {
2008-01-16 22:00:59 +03:00
mirror_seg = find_mirror_seg ( first_seg ( tmp_lv ) ) ;
if ( ! mirror_seg ) {
2018-03-27 22:08:20 +03:00
log_error ( " Failed to find mirrored LV for %s. " ,
display_lvname ( tmp_lv ) ) ;
2008-01-16 22:00:59 +03:00
return 0 ;
}
if ( ! _mirrored_lv_in_sync ( mirror_seg - > lv ) ) {
2018-03-27 22:08:20 +03:00
log_verbose ( " Not collapsing %s: out-of-sync. " ,
display_lvname ( mirror_seg - > lv ) ) ;
2007-12-20 21:55:46 +03:00
return 1 ;
}
2008-01-16 22:00:59 +03:00
if ( ! _remove_mirror_images ( mirror_seg - > lv ,
mirror_seg - > area_count - 1 ,
2011-03-24 15:28:02 +03:00
_no_removable_images , NULL , 0 , 1 , NULL , 0 ) ) {
2007-12-20 21:55:46 +03:00
log_error ( " Failed to release mirror images " ) ;
return 0 ;
}
}
return 1 ;
}
2012-08-15 12:44:19 +04:00
#if 0
/* FIXME: reconfigure_mirror_images: remove this code? */
2011-09-14 13:54:21 +04:00
static int _get_mirror_fault_policy ( struct cmd_context * cmd __attribute__ ( ( unused ) ) ,
2007-08-22 18:38:18 +04:00
int log_policy )
2006-05-11 23:45:53 +04:00
{
2013-03-05 20:00:43 +04:00
const char * policy = NULL ;
/*
2006-05-11 23:45:53 +04:00
if ( log_policy )
2013-03-05 20:00:43 +04:00
policy = find_config_tree_str ( cmd , activation_mirror_log_fault_policy_CFG ) ;
2010-01-06 16:27:06 +03:00
else {
2013-03-05 20:00:43 +04:00
policy = find_config_tree_str ( cmd , activation_mirror_image_fault_policy_CFG ) ;
2010-01-06 16:27:06 +03:00
if ( ! policy )
2013-03-05 20:00:43 +04:00
policy = find_config_tree_str ( cmd , activation_mirror_device_fault_policy_CFG ) ;
2010-01-06 16:27:06 +03:00
}
2013-03-05 20:00:43 +04:00
*/
2006-05-11 23:45:53 +04:00
if ( ! strcmp ( policy , " remove " ) )
return MIRROR_REMOVE ;
else if ( ! strcmp ( policy , " allocate " ) )
return MIRROR_ALLOCATE ;
else if ( ! strcmp ( policy , " allocate_anywhere " ) )
return MIRROR_ALLOCATE_ANYWHERE ;
if ( log_policy )
log_error ( " Bad activation/mirror_log_fault_policy " ) ;
else
2006-05-12 23:47:40 +04:00
log_error ( " Bad activation/mirror_device_fault_policy " ) ;
2006-05-11 23:45:53 +04:00
return MIRROR_REMOVE ;
}
2011-09-14 13:54:21 +04:00
static int _get_mirror_log_fault_policy ( struct cmd_context * cmd )
2006-05-11 23:45:53 +04:00
{
2011-09-14 13:54:21 +04:00
return _get_mirror_fault_policy ( cmd , 1 ) ;
2006-05-11 23:45:53 +04:00
}
2011-09-14 13:54:21 +04:00
static int _get_mirror_device_fault_policy ( struct cmd_context * cmd )
2006-05-11 23:45:53 +04:00
{
2011-09-14 13:54:21 +04:00
return _get_mirror_fault_policy ( cmd , 0 ) ;
2006-05-11 23:45:53 +04:00
}
/*
* replace_mirror_images
* @ mirrored_seg : segment ( which may be linear now ) to restore
* @ num_mirrors : number of copies we should end up with
* @ replace_log : replace log if not present
* @ in_sync : was the original mirror in - sync ?
*
* in_sync will be set to 0 if new mirror devices are being added
* In other words , it is only useful if the log ( and only the log )
* is being restored .
*
* Returns : 0 on failure , 1 on reconfig , - 1 if no reconfig done
*/
2011-09-14 13:54:21 +04:00
static int _replace_mirror_images ( struct lv_segment * mirrored_seg ,
2006-05-11 23:45:53 +04:00
uint32_t num_mirrors ,
int log_policy , int in_sync )
{
int r = - 1 ;
struct logical_volume * lv = mirrored_seg - > lv ;
/* FIXME: Use lvconvert rather than duplicating its code */
if ( mirrored_seg - > area_count < num_mirrors ) {
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Failed to replace mirror device in %s. " ,
display_lvname ( mirrored_seg - > lv ) ;
2006-05-11 23:45:53 +04:00
if ( ( mirrored_seg - > area_count > 1 ) & & ! mirrored_seg - > log_lv )
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Use 'lvconvert -m %d %s --corelog' to replace failed devices. " ,
num_mirrors - 1 , display_lvname ( lv ) ) ;
2006-05-11 23:45:53 +04:00
else
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Use 'lvconvert -m %d %s' to replace failed devices. " ,
num_mirrors - 1 , display_lvname ( lv ) ) ;
2006-05-11 23:45:53 +04:00
r = 0 ;
/* REMEMBER/FIXME: set in_sync to 0 if a new mirror device was added */
in_sync = 0 ;
}
/*
* FIXME : right now , we ignore the allocation policy specified to
* allocate the new log .
*/
if ( ( mirrored_seg - > area_count > 1 ) & & ! mirrored_seg - > log_lv & &
( log_policy ! = MIRROR_REMOVE ) ) {
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Failed to replace mirror log device in %s. " ,
display_lvname ( lv ) ) ;
2006-05-11 23:45:53 +04:00
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Use 'lvconvert -m %d %s' to replace failed devices. " ,
mirrored_seg - > area_count - 1 , display_lvname ( lv ) ) ;
2006-05-11 23:45:53 +04:00
r = 0 ;
}
return r ;
}
2006-05-11 23:01:11 +04:00
int reconfigure_mirror_images ( struct lv_segment * mirrored_seg , uint32_t num_mirrors ,
2008-11-04 01:14:30 +03:00
struct dm_list * removable_pvs , unsigned remove_log )
2006-05-11 23:01:11 +04:00
{
int r ;
2007-12-20 21:55:46 +03:00
int in_sync ;
2006-05-11 23:45:53 +04:00
int log_policy , dev_policy ;
uint32_t old_num_mirrors = mirrored_seg - > area_count ;
int had_log = ( mirrored_seg - > log_lv ) ? 1 : 0 ;
2006-05-11 23:01:11 +04:00
/* was the mirror in-sync before problems? */
2007-12-20 21:55:46 +03:00
in_sync = _mirrored_lv_in_sync ( mirrored_seg - > lv ) ;
2006-05-11 23:01:11 +04:00
/*
* While we are only removing devices , we can have sync set .
* Setting this is only useful if we are moving to core log
* otherwise the disk log will contain the sync information
*/
2007-12-20 18:42:55 +03:00
init_mirror_in_sync ( in_sync ) ;
2006-05-11 23:01:11 +04:00
2008-01-17 16:13:54 +03:00
r = _remove_mirror_images ( mirrored_seg - > lv , old_num_mirrors - num_mirrors ,
2010-05-24 19:32:20 +04:00
is_mirror_image_removable , removable_pvs ,
2011-03-24 15:28:02 +03:00
remove_log , 0 , NULL , 0 ) ;
2006-05-11 23:01:11 +04:00
if ( ! r )
/* Unable to remove bad devices */
return 0 ;
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Bad device removed from mirror volume %s. " ,
display_lvname ( mirrored_seg - > lv ) ) ;
2006-05-11 23:45:53 +04:00
2011-09-14 13:54:21 +04:00
log_policy = _get_mirror_log_fault_policy ( mirrored_seg - > lv - > vg - > cmd ) ;
dev_policy = _get_mirror_device_fault_policy ( mirrored_seg - > lv - > vg - > cmd ) ;
2006-05-11 23:45:53 +04:00
2011-09-14 13:54:21 +04:00
r = _replace_mirror_images ( mirrored_seg ,
2006-05-11 23:45:53 +04:00
( dev_policy ! = MIRROR_REMOVE ) ?
old_num_mirrors : num_mirrors ,
2007-12-20 18:42:55 +03:00
log_policy , in_sync ) ;
2006-05-11 23:45:53 +04:00
if ( ! r )
/* Failed to replace device(s) */
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Unable to find substitute device for mirror volume %s. " ,
display_lvname ( mirrored_seg - > lv ) ) ;
2006-05-11 23:45:53 +04:00
else if ( r > 0 )
/* Success in replacing device(s) */
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Mirror volume %s restored - substitute for failed device found. " ,
display_lvname ( mirrored_seg - > lv ) ) ;
2006-05-11 23:45:53 +04:00
else
/* Bad device removed, but not replaced because of policy */
if ( mirrored_seg - > area_count = = 1 ) {
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Mirror volume %s converted to linear due to device failure. " ,
display_lvname ( mirrored_seg - > lv ) ;
2006-05-11 23:45:53 +04:00
} else if ( had_log & & ! mirrored_seg - > log_lv ) {
2016-11-16 17:11:07 +03:00
log_warn ( " WARNING: Mirror volume %s disk log removed due to device failure. " ,
display_lvname ( mirrored_seg - > lv ) ) ;
2006-05-11 23:45:53 +04:00
}
/*
* If we made it here , we at least removed the bad device .
* Consider this success .
*/
2006-05-11 23:01:11 +04:00
return 1 ;
}
2012-08-15 12:44:19 +04:00
# endif
2006-05-11 23:01:11 +04:00
2007-12-20 18:42:55 +03:00
static int _create_mimage_lvs ( struct alloc_handle * ah ,
uint32_t num_mirrors ,
2010-04-09 05:00:10 +04:00
uint32_t stripes ,
uint32_t stripe_size ,
2007-12-20 18:42:55 +03:00
struct logical_volume * lv ,
2010-03-27 01:15:43 +03:00
struct logical_volume * * img_lvs ,
int log )
2005-06-03 18:49:51 +04:00
{
2011-01-11 20:05:08 +03:00
uint32_t m , first_area ;
2016-12-11 14:19:38 +03:00
char img_name [ NAME_LEN ] ;
if ( dm_snprintf ( img_name , sizeof ( img_name ) , " %s_mimage_%%d " , lv - > name ) < 0 ) {
log_error ( " Failed to build new mirror image name for %s. " ,
display_lvname ( lv ) ) ;
2005-06-03 18:49:51 +04:00
return 0 ;
}
for ( m = 0 ; m < num_mirrors ; m + + ) {
2007-10-11 23:20:38 +04:00
if ( ! ( img_lvs [ m ] = lv_create_empty ( img_name ,
2018-03-27 22:08:20 +03:00
NULL , LVM_READ | LVM_WRITE ,
ALLOC_INHERIT , lv - > vg ) ) ) {
2005-10-27 23:58:22 +04:00
log_error ( " Aborting. Failed to create mirror image LV. "
2005-06-03 18:49:51 +04:00
" Remove new LV and retry. " ) ;
return 0 ;
}
2010-03-27 01:15:43 +03:00
if ( log ) {
2011-01-11 20:05:08 +03:00
first_area = m * stripes + ( log - 1 ) ;
if ( ! lv_add_log_segment ( ah , first_area , img_lvs [ m ] , 0 ) ) {
2011-01-11 20:21:01 +03:00
log_error ( " Failed to add mirror image segment "
" to %s. Remove new LV and retry. " ,
2018-03-27 22:08:20 +03:00
display_lvname ( img_lvs [ m ] ) ) ;
2010-03-27 01:15:43 +03:00
return 0 ;
}
} else {
2010-04-09 05:00:10 +04:00
if ( ! lv_add_segment ( ah , m * stripes , stripes , img_lvs [ m ] ,
2015-09-22 21:04:12 +03:00
get_segtype_from_string ( lv - > vg - > cmd , SEG_TYPE_NAME_STRIPED ) ,
2010-04-09 05:00:10 +04:00
stripe_size , 0 , 0 ) ) {
2010-03-27 01:15:43 +03:00
log_error ( " Aborting. Failed to add mirror image segment "
" to %s. Remove new LV and retry. " ,
2018-03-27 22:08:20 +03:00
display_lvname ( img_lvs [ m ] ) ) ;
2010-03-27 01:15:43 +03:00
return 0 ;
}
2005-06-03 18:49:51 +04:00
}
}
2005-10-28 16:48:50 +04:00
return 1 ;
}
2007-12-20 18:42:55 +03:00
/*
* Remove mirrors from each segment .
* ' new_mirrors ' is the number of mirrors after the removal . ' 0 ' for linear .
* If ' status_mask ' is non - zero , the removal happens only when all segments
* has the status bits on .
2003-05-06 16:22:24 +04:00
*/
2007-12-20 18:42:55 +03:00
int remove_mirrors_from_segments ( struct logical_volume * lv ,
2009-11-25 01:55:55 +03:00
uint32_t new_mirrors , uint64_t status_mask )
2003-05-06 16:22:24 +04:00
{
struct lv_segment * seg ;
2007-12-20 18:42:55 +03:00
uint32_t s ;
2004-05-25 00:51:56 +04:00
2007-12-20 18:42:55 +03:00
/* Check the segment params are compatible */
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( seg , & lv - > segments ) {
2007-12-20 18:42:55 +03:00
if ( ! seg_is_mirrored ( seg ) ) {
2018-03-27 22:08:20 +03:00
log_error ( " Segment is not mirrored: %s: " FMTu32 ,
display_lvname ( lv ) , seg - > le ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
2017-06-22 01:57:16 +03:00
}
if ( ( seg - > status & status_mask ) ! = status_mask ) {
2018-03-27 22:08:20 +03:00
log_error ( " Segment status does not match: %s: " FMTu32
" status:0x " FMTx64 " /0x " FMTx64 ,
display_lvname ( lv ) , seg - > le ,
2007-12-20 18:42:55 +03:00
seg - > status , status_mask ) ;
return 0 ;
2004-08-18 02:09:02 +04:00
}
}
2003-05-06 16:22:24 +04:00
2007-12-20 18:42:55 +03:00
/* Convert the segments */
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( seg , & lv - > segments ) {
2007-12-20 18:42:55 +03:00
if ( ! new_mirrors & & seg - > extents_copied = = seg - > area_len ) {
if ( ! move_lv_segment_area ( seg , 0 , seg , 1 ) )
return_0 ;
2003-05-06 16:22:24 +04:00
}
2007-12-20 18:42:55 +03:00
for ( s = new_mirrors + 1 ; s < seg - > area_count ; s + + )
2012-06-28 00:53:02 +04:00
if ( ! release_and_discard_lv_segment_area ( seg , s , seg - > area_len ) )
2012-06-27 22:37:54 +04:00
return_0 ;
2005-06-14 21:54:48 +04:00
2007-12-20 18:42:55 +03:00
seg - > area_count = new_mirrors + 1 ;
2003-05-06 16:22:24 +04:00
2007-12-20 18:42:55 +03:00
if ( ! new_mirrors )
2015-09-22 21:04:12 +03:00
seg - > segtype = get_segtype_from_string ( lv - > vg - > cmd , SEG_TYPE_NAME_STRIPED ) ;
2005-06-14 21:54:48 +04:00
}
2004-08-18 02:09:02 +04:00
2003-05-06 16:22:24 +04:00
return 1 ;
}
2014-09-22 17:50:07 +04:00
const char * get_pvmove_pvname_from_lv_mirr ( const struct logical_volume * lv_mirr )
2003-05-06 16:22:24 +04:00
{
struct lv_segment * seg ;
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( seg , & lv_mirr - > segments ) {
2005-05-09 20:59:01 +04:00
if ( ! seg_is_mirrored ( seg ) )
2003-05-06 16:22:24 +04:00
continue ;
2014-09-16 03:13:46 +04:00
if ( seg_type ( seg , 0 ) = = AREA_PV )
return dev_name ( seg_dev ( seg , 0 ) ) ;
if ( seg_type ( seg , 0 ) = = AREA_LV )
return dev_name ( seg_dev ( first_seg ( seg_lv ( seg , 0 ) ) , 0 ) ) ;
2003-05-06 16:22:24 +04:00
}
return NULL ;
}
2011-06-11 04:03:06 +04:00
/*
* Find first pvmove LV referenced by a segment of an LV .
*/
2014-09-22 17:50:07 +04:00
const struct logical_volume * find_pvmove_lv_in_lv ( const struct logical_volume * lv )
2003-05-06 16:22:24 +04:00
{
2014-09-22 17:50:07 +04:00
const struct lv_segment * seg ;
2003-05-06 16:22:24 +04:00
uint32_t s ;
2017-11-14 22:44:32 +03:00
if ( lv_is_pvmove ( lv ) )
return lv ;
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( seg , & lv - > segments ) {
2003-05-06 16:22:24 +04:00
for ( s = 0 ; s < seg - > area_count ; s + + ) {
2005-06-01 20:51:55 +04:00
if ( seg_type ( seg , s ) ! = AREA_LV )
2003-05-06 16:22:24 +04:00
continue ;
2014-09-16 00:33:53 +04:00
if ( lv_is_pvmove ( seg_lv ( seg , s ) ) )
2011-06-11 04:03:06 +04:00
return seg_lv ( seg , s ) ;
2003-05-06 16:22:24 +04:00
}
}
return NULL ;
}
2014-09-22 17:50:07 +04:00
const char * get_pvmove_pvname_from_lv ( const struct logical_volume * lv )
2011-06-11 04:03:06 +04:00
{
2014-09-22 17:50:07 +04:00
const struct logical_volume * pvmove_lv ;
2011-06-11 04:03:06 +04:00
pvmove_lv = find_pvmove_lv_in_lv ( lv ) ;
if ( pvmove_lv )
return get_pvmove_pvname_from_lv_mirr ( pvmove_lv ) ;
2017-07-19 17:16:12 +03:00
return NULL ;
2011-06-11 04:03:06 +04:00
}
2003-05-06 16:22:24 +04:00
struct logical_volume * find_pvmove_lv ( struct volume_group * vg ,
2004-05-05 21:56:20 +04:00
struct device * dev ,
2011-09-06 22:49:31 +04:00
uint64_t lv_type )
2003-05-06 16:22:24 +04:00
{
2005-06-01 20:51:55 +04:00
struct lv_list * lvl ;
2003-05-06 16:22:24 +04:00
struct logical_volume * lv ;
struct lv_segment * seg ;
/* Loop through all LVs */
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( lvl , & vg - > lvs ) {
2005-06-01 20:51:55 +04:00
lv = lvl - > lv ;
2003-05-06 16:22:24 +04:00
2004-05-05 21:56:20 +04:00
if ( ! ( lv - > status & lv_type ) )
2003-05-06 16:22:24 +04:00
continue ;
2014-06-19 19:52:09 +04:00
/*
* If this is an atomic pvmove , the first
* segment will be a mirror containing
* mimages ( i . e . AREA_LVs )
*/
if ( seg_type ( first_seg ( lv ) , 0 ) = = AREA_LV ) {
seg = first_seg ( lv ) ; /* the mirror segment */
seg = first_seg ( seg_lv ( seg , 0 ) ) ; /* mimage_0 segment0 */
if ( seg_dev ( seg , 0 ) ! = dev )
continue ;
return lv ;
}
/*
* If this is a normal pvmove , check all the segments '
* first areas for the requested device
*/
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( seg , & lv - > segments ) {
2014-06-19 19:52:09 +04:00
if ( seg_type ( seg , 0 ) ! = AREA_PV )
2003-05-06 16:22:24 +04:00
continue ;
2005-06-01 20:51:55 +04:00
if ( seg_dev ( seg , 0 ) ! = dev )
2003-05-06 16:22:24 +04:00
continue ;
2014-06-19 19:52:09 +04:00
2003-05-06 16:22:24 +04:00
return lv ;
}
}
return NULL ;
}
2008-11-04 01:14:30 +03:00
struct dm_list * lvs_using_lv ( struct cmd_context * cmd , struct volume_group * vg ,
2003-05-06 16:22:24 +04:00
struct logical_volume * lv )
{
2008-11-04 01:14:30 +03:00
struct dm_list * lvs ;
2003-05-06 16:22:24 +04:00
struct logical_volume * lv1 ;
2005-06-01 20:51:55 +04:00
struct lv_list * lvl , * lvl1 ;
2003-05-06 16:22:24 +04:00
struct lv_segment * seg ;
uint32_t s ;
2005-10-17 03:03:59 +04:00
if ( ! ( lvs = dm_pool_alloc ( cmd - > mem , sizeof ( * lvs ) ) ) ) {
2018-03-27 22:08:20 +03:00
log_error ( " lvs list alloc failed. " ) ;
2003-05-06 16:22:24 +04:00
return NULL ;
}
2008-11-04 01:14:30 +03:00
dm_list_init ( lvs ) ;
2003-05-06 16:22:24 +04:00
/* Loop through all LVs except the one supplied */
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( lvl1 , & vg - > lvs ) {
2005-06-01 20:51:55 +04:00
lv1 = lvl1 - > lv ;
2003-05-06 16:22:24 +04:00
if ( lv1 = = lv )
continue ;
2004-05-05 22:35:04 +04:00
/* Find whether any segment points at the supplied LV */
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( seg , & lv1 - > segments ) {
2003-05-06 16:22:24 +04:00
for ( s = 0 ; s < seg - > area_count ; s + + ) {
2005-06-01 20:51:55 +04:00
if ( seg_type ( seg , s ) ! = AREA_LV | |
seg_lv ( seg , s ) ! = lv )
2003-05-06 16:22:24 +04:00
continue ;
2005-10-17 03:03:59 +04:00
if ( ! ( lvl = dm_pool_alloc ( cmd - > mem , sizeof ( * lvl ) ) ) ) {
2018-03-27 22:08:20 +03:00
log_error ( " lv_list alloc failed. " ) ;
2003-05-06 16:22:24 +04:00
return NULL ;
}
lvl - > lv = lv1 ;
2008-11-04 01:14:30 +03:00
dm_list_add ( lvs , & lvl - > list ) ;
2003-05-06 16:22:24 +04:00
goto next_lv ;
}
}
next_lv :
2003-07-05 02:34:56 +04:00
;
2003-05-06 16:22:24 +04:00
}
return lvs ;
}
2005-10-28 01:51:28 +04:00
/*
* Fixup mirror pointers after single - pass segment import
*/
int fixup_imported_mirrors ( struct volume_group * vg )
{
struct lv_list * lvl ;
struct lv_segment * seg ;
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( lvl , & vg - > lvs ) {
dm_list_iterate_items ( seg , & lvl - > lv - > segments ) {
2005-10-28 01:51:28 +04:00
if ( seg - > segtype ! =
2015-09-22 21:04:12 +03:00
get_segtype_from_string ( vg - > cmd , SEG_TYPE_NAME_MIRROR ) )
2005-10-28 01:51:28 +04:00
continue ;
2008-01-16 22:00:59 +03:00
if ( seg - > log_lv & & ! add_seg_to_segs_using_this_lv ( seg - > log_lv , seg ) )
return_0 ;
2005-10-28 01:51:28 +04:00
}
}
2005-10-28 16:48:50 +04:00
return 1 ;
2005-10-28 01:51:28 +04:00
}
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
static int _add_mirrors_that_preserve_segments ( struct logical_volume * lv ,
uint32_t flags ,
uint32_t mirrors ,
uint32_t region_size ,
struct dm_list * allocatable_pvs ,
alloc_policy_t alloc )
2007-12-20 18:42:55 +03:00
{
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
struct cmd_context * cmd = lv - > vg - > cmd ;
2007-12-20 18:42:55 +03:00
struct alloc_handle * ah ;
const struct segment_type * segtype ;
2008-11-04 01:14:30 +03:00
struct dm_list * parallel_areas ;
2007-12-20 18:42:55 +03:00
uint32_t adjusted_region_size ;
2009-04-07 14:20:28 +04:00
int r = 1 ;
2007-12-20 18:42:55 +03:00
2014-06-26 06:20:41 +04:00
if ( ! ( parallel_areas = build_parallel_areas_from_lv ( lv , 1 , 0 ) ) )
2007-12-20 18:42:55 +03:00
return_0 ;
2015-09-22 21:04:12 +03:00
if ( ! ( segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_MIRROR ) ) )
2007-12-20 18:42:55 +03:00
return_0 ;
2018-04-20 11:07:42 +03:00
if ( ! ( adjusted_region_size = adjusted_mirror_region_size ( cmd ,
lv - > vg - > extent_size ,
lv - > le_count ,
region_size , 1 ,
vg_is_clustered ( lv - > vg ) ) ) )
return_0 ;
2007-12-20 18:42:55 +03:00
2008-12-19 18:24:52 +03:00
if ( ! ( ah = allocate_extents ( lv - > vg , NULL , segtype , 1 , mirrors , 0 , 0 ,
2014-02-14 07:10:28 +04:00
lv - > le_count , allocatable_pvs , alloc , 0 ,
2007-12-20 18:42:55 +03:00
parallel_areas ) ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Unable to allocate mirror extents for %s. " ,
display_lvname ( lv ) ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
if ( flags & MIRROR_BY_SEG ) {
if ( ! lv_add_mirror_areas ( ah , lv , 0 , adjusted_region_size ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed to add mirror areas to %s. " ,
display_lvname ( lv ) ) ;
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
r = 0 ;
}
} else if ( flags & MIRROR_BY_SEGMENTED_LV ) {
if ( ! lv_add_segmented_mirror_image ( ah , lv , 0 ,
adjusted_region_size ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Failed to add mirror areas to %s. " ,
display_lvname ( lv ) ) ;
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
r = 0 ;
}
} else {
2016-11-16 17:11:07 +03:00
log_error ( INTERNAL_ERROR " Unknown mirror flag. " ) ;
2009-04-07 14:20:28 +04:00
r = 0 ;
2007-12-20 18:42:55 +03:00
}
2009-04-07 14:20:28 +04:00
alloc_destroy ( ah ) ;
return r ;
2007-12-20 18:42:55 +03:00
}
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
/*
* Add mirrors to " linear " or " mirror " segments
*/
int add_mirrors_to_segments ( struct cmd_context * cmd , struct logical_volume * lv ,
uint32_t mirrors , uint32_t region_size ,
struct dm_list * allocatable_pvs , alloc_policy_t alloc )
{
return _add_mirrors_that_preserve_segments ( lv , MIRROR_BY_SEG ,
mirrors , region_size ,
allocatable_pvs , alloc ) ;
}
2007-12-20 18:42:55 +03:00
/*
* Convert mirror log
*
* FIXME : Can ' t handle segment - by - segment mirror ( like pvmove )
*/
int remove_mirror_log ( struct cmd_context * cmd ,
struct logical_volume * lv ,
2010-10-12 20:41:17 +04:00
struct dm_list * removable_pvs ,
int force )
2007-12-20 18:42:55 +03:00
{
2014-06-09 14:08:27 +04:00
dm_percent_t sync_percent ;
2008-06-27 03:05:11 +04:00
struct volume_group * vg = lv - > vg ;
2007-12-20 18:42:55 +03:00
/* Unimplemented features */
2008-11-04 01:14:30 +03:00
if ( dm_list_size ( & lv - > segments ) ! = 1 ) {
2016-11-16 17:11:07 +03:00
log_error ( " Multiple-segment mirror is not supported. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
/* Had disk log, switch to core. */
2013-05-15 05:13:31 +04:00
if ( lv_is_active_locally ( lv ) ) {
2009-10-01 04:35:29 +04:00
if ( ! lv_mirror_percent ( cmd , lv , 0 , & sync_percent ,
2010-11-30 14:53:31 +03:00
NULL ) ) {
2008-06-27 03:05:11 +04:00
log_error ( " Unable to determine mirror sync status. " ) ;
return 0 ;
}
2013-05-16 19:36:56 +04:00
} else if ( lv_is_active ( lv ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Unable to determine sync status of "
" remotely active mirror volume %s. " , display_lvname ( lv ) ) ;
2013-05-16 19:36:56 +04:00
return 0 ;
2008-06-27 03:05:11 +04:00
} else if ( vg_is_clustered ( vg ) ) {
2009-10-14 18:55:44 +04:00
log_error ( " Unable to convert the log of an inactive "
2016-11-16 17:11:07 +03:00
" cluster mirror volume %s. " , display_lvname ( lv ) ) ;
2008-06-27 03:05:11 +04:00
return 0 ;
2016-11-16 17:11:07 +03:00
} else if ( force | | yes_no_prompt ( " Full resync required to convert inactive "
" mirror volume %s to core log. "
" Proceed? [y/n]: " , display_lvname ( lv ) ) = = ' y ' )
2008-06-27 03:05:11 +04:00
sync_percent = 0 ;
2013-06-15 20:43:36 +04:00
else {
2016-11-16 17:11:07 +03:00
log_error ( " Logical volume %s NOT converted. " , display_lvname ( lv ) ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
2013-06-15 20:43:36 +04:00
}
2007-12-20 18:42:55 +03:00
2014-06-09 14:08:27 +04:00
if ( sync_percent = = DM_PERCENT_100 )
2007-12-20 18:42:55 +03:00
init_mirror_in_sync ( 1 ) ;
else {
/* A full resync will take place */
2011-03-29 16:51:57 +04:00
lv - > status & = ~ LV_NOTSYNCED ;
2007-12-20 18:42:55 +03:00
init_mirror_in_sync ( 0 ) ;
}
2007-12-20 21:55:46 +03:00
if ( ! remove_mirror_images ( lv , lv_mirror_count ( lv ) ,
2010-05-24 19:32:20 +04:00
is_mirror_image_removable , removable_pvs , 1U ) )
2007-12-20 18:42:55 +03:00
return_0 ;
return 1 ;
}
2007-12-21 01:37:42 +03:00
static struct logical_volume * _create_mirror_log ( struct logical_volume * lv ,
struct alloc_handle * ah ,
alloc_policy_t alloc ,
2007-12-22 05:13:00 +03:00
const char * lv_name ,
const char * suffix )
2007-12-20 18:42:55 +03:00
{
struct logical_volume * log_lv ;
2016-12-11 14:19:38 +03:00
char log_name [ NAME_LEN ] ;
2007-12-20 18:42:55 +03:00
2016-12-11 14:19:38 +03:00
if ( dm_snprintf ( log_name , sizeof ( log_name ) , " %s%s " , lv_name , suffix ) < 0 ) {
log_error ( " Failed to build new mirror log name for %s. " , lv_name ) ;
2007-12-20 18:42:55 +03:00
return NULL ;
}
if ( ! ( log_lv = lv_create_empty ( log_name , NULL ,
VISIBLE_LV | LVM_READ | LVM_WRITE ,
2009-05-14 01:28:31 +04:00
alloc , lv - > vg ) ) )
2007-12-20 18:42:55 +03:00
return_NULL ;
2010-03-27 01:15:43 +03:00
if ( ! lv_add_log_segment ( ah , 0 , log_lv , MIRROR_LOG ) )
2007-12-20 18:42:55 +03:00
return_NULL ;
return log_lv ;
}
2010-03-27 01:15:43 +03:00
/*
* Returns : 1 on success , 0 on error
*/
static int _form_mirror ( struct cmd_context * cmd , struct alloc_handle * ah ,
struct logical_volume * lv ,
2010-04-09 05:00:10 +04:00
uint32_t mirrors , uint32_t stripes ,
uint32_t stripe_size , uint32_t region_size , int log )
2010-03-27 01:15:43 +03:00
{
struct logical_volume * * img_lvs ;
/*
* insert a mirror layer
*/
if ( dm_list_size ( & lv - > segments ) ! = 1 | |
seg_type ( first_seg ( lv ) , 0 ) ! = AREA_LV )
if ( ! insert_layer_for_lv ( cmd , lv , 0 , " _mimage_%d " ) )
2016-11-23 12:30:52 +03:00
return_0 ;
2010-03-27 01:15:43 +03:00
/*
* create mirror image LVs
*/
2015-11-05 20:32:32 +03:00
img_lvs = alloca ( sizeof ( * img_lvs ) * mirrors ) ;
2010-03-27 01:15:43 +03:00
2010-04-09 05:00:10 +04:00
if ( ! _create_mimage_lvs ( ah , mirrors , stripes , stripe_size , lv , img_lvs , log ) )
2015-05-07 13:37:15 +03:00
return_0 ;
2010-03-27 01:15:43 +03:00
if ( ! lv_add_mirror_lvs ( lv , img_lvs , mirrors ,
2016-11-23 19:11:26 +03:00
/* Pass through MIRRORED & LOCKED status flag
* TODO : Any other would be needed ? ? */
MIRROR_IMAGE | ( lv - > status & ( MIRRORED | LOCKED ) ) ,
2010-03-27 01:15:43 +03:00
region_size ) ) {
log_error ( " Aborting. Failed to add mirror segment. "
" Remove new LV and retry. " ) ;
return 0 ;
}
return 1 ;
}
2007-12-20 18:42:55 +03:00
static struct logical_volume * _set_up_mirror_log ( struct cmd_context * cmd ,
struct alloc_handle * ah ,
struct logical_volume * lv ,
uint32_t log_count ,
2010-03-27 01:15:43 +03:00
uint32_t region_size ,
2007-12-20 18:42:55 +03:00
alloc_policy_t alloc ,
int in_sync )
{
struct logical_volume * log_lv ;
2011-02-18 17:47:28 +03:00
const char * suffix , * lv_name ;
char * tmp_name ;
2008-01-31 15:19:36 +03:00
size_t len ;
2007-12-22 15:13:29 +03:00
struct lv_segment * seg ;
2007-12-20 18:42:55 +03:00
init_mirror_in_sync ( in_sync ) ;
2008-01-31 15:19:36 +03:00
/* Mirror log name is lv_name + suffix, determined as the following:
* 1. suffix is :
* o " _mlog " for the original mirror LV .
* o " _mlogtmp_%d " for temporary mirror LV ,
* 2. lv_name is :
* o lv - > name , if the log is temporary
* o otherwise , the top - level LV name
*/
2007-12-22 15:13:29 +03:00
seg = first_seg ( lv ) ;
if ( seg_type ( seg , 0 ) = = AREA_LV & &
2008-01-31 15:19:36 +03:00
strstr ( seg_lv ( seg , 0 ) - > name , MIRROR_SYNC_LAYER ) ) {
lv_name = lv - > name ;
2007-12-22 15:13:29 +03:00
suffix = " _mlogtmp_%d " ;
2011-02-18 17:47:28 +03:00
} else if ( ( lv_name = strstr ( lv - > name , MIRROR_SYNC_LAYER ) ) ) {
2011-04-12 18:13:17 +04:00
len = lv_name - lv - > name ;
tmp_name = alloca ( len + 1 ) ;
tmp_name [ len ] = ' \0 ' ;
lv_name = strncpy ( tmp_name , lv - > name , len ) ;
2008-01-31 15:19:36 +03:00
suffix = " _mlog " ;
} else {
lv_name = lv - > name ;
2007-12-22 15:13:29 +03:00
suffix = " _mlog " ;
2008-01-31 15:19:36 +03:00
}
2007-12-22 15:13:29 +03:00
2011-02-18 17:47:28 +03:00
if ( ! ( log_lv = _create_mirror_log ( lv , ah , alloc , lv_name , suffix ) ) ) {
2007-12-20 18:42:55 +03:00
log_error ( " Failed to create mirror log. " ) ;
return NULL ;
}
2018-04-20 11:12:25 +03:00
if ( log_count > 1 ) {
/* Kernel requires a mirror to be at least 1 region large. */
if ( region_size > log_lv - > size ) {
region_size = UINT64_C ( 1 ) < < ( 31 - clz ( log_lv - > size ) ) ;
log_debug ( " Adjusting region_size to %s for mirrored log. " ,
display_size ( cmd , ( uint64_t ) region_size ) ) ;
}
if ( ! _form_mirror ( cmd , ah , log_lv , log_count - 1 , 1 , 0 , region_size , 2 ) ) {
log_error ( " Failed to form mirrored log. " ) ;
return NULL ;
}
2010-03-27 01:15:43 +03:00
}
2018-03-30 00:26:22 +03:00
if ( ! _init_mirror_log ( cmd , NULL , log_lv , in_sync , & lv - > tags , 1 ) ) {
2009-12-09 21:09:52 +03:00
log_error ( " Failed to initialise mirror log. " ) ;
2007-12-20 18:42:55 +03:00
return NULL ;
}
return log_lv ;
}
2008-01-26 03:25:04 +03:00
int attach_mirror_log ( struct lv_segment * seg , struct logical_volume * log_lv )
2007-12-20 18:42:55 +03:00
{
2008-01-26 03:25:04 +03:00
seg - > log_lv = log_lv ;
2007-12-20 18:42:55 +03:00
log_lv - > status | = MIRROR_LOG ;
2009-05-21 07:04:52 +04:00
lv_set_hidden ( log_lv ) ;
2008-01-26 03:25:04 +03:00
return add_seg_to_segs_using_this_lv ( log_lv , seg ) ;
2007-12-20 18:42:55 +03:00
}
2016-12-10 21:54:09 +03:00
/* Prepare disk mirror log for raid1->mirror conversion */
struct logical_volume * prepare_mirror_log ( struct logical_volume * lv ,
int in_sync , uint32_t region_size ,
struct dm_list * allocatable_pvs ,
alloc_policy_t alloc )
{
struct cmd_context * cmd = lv - > vg - > cmd ;
const struct segment_type * segtype ;
struct dm_list * parallel_areas ;
struct alloc_handle * ah ;
struct logical_volume * log_lv ;
if ( ! ( parallel_areas = build_parallel_areas_from_lv ( lv , 0 , 0 ) ) )
return_NULL ;
if ( ! ( segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_MIRROR ) ) )
return_NULL ;
/* Allocate destination extents */
if ( ! ( ah = allocate_extents ( lv - > vg , NULL , segtype ,
0 , 0 , 1 , region_size ,
lv - > le_count , allocatable_pvs ,
alloc , 0 , parallel_areas ) ) ) {
log_error ( " Unable to allocate extents for mirror log. " ) ;
return NULL ;
}
if ( ! ( log_lv = _create_mirror_log ( lv , ah , alloc , lv - > name , " _mlog " ) ) ) {
log_error ( " Failed to create mirror log. " ) ;
goto out ;
}
2018-03-30 00:26:22 +03:00
if ( ! _init_mirror_log ( cmd , NULL , log_lv , in_sync , & lv - > tags , 1 ) ) {
2016-12-10 21:54:09 +03:00
log_error ( " Failed to initialise mirror log. " ) ;
log_lv = NULL ;
goto out ;
}
out :
alloc_destroy ( ah ) ;
return log_lv ;
}
2008-06-27 03:05:11 +04:00
int add_mirror_log ( struct cmd_context * cmd , struct logical_volume * lv ,
uint32_t log_count , uint32_t region_size ,
2008-11-04 01:14:30 +03:00
struct dm_list * allocatable_pvs , alloc_policy_t alloc )
2007-12-20 18:42:55 +03:00
{
struct alloc_handle * ah ;
const struct segment_type * segtype ;
2008-11-04 01:14:30 +03:00
struct dm_list * parallel_areas ;
2014-06-09 14:08:27 +04:00
dm_percent_t sync_percent ;
2007-12-20 18:42:55 +03:00
int in_sync ;
struct logical_volume * log_lv ;
2011-04-08 18:40:18 +04:00
unsigned old_log_count ;
2009-04-07 14:20:28 +04:00
int r = 0 ;
2007-12-20 18:42:55 +03:00
2011-10-25 17:17:04 +04:00
if ( vg_is_clustered ( lv - > vg ) & & ( log_count > 1 ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Log type, \" mirrored \" , is unavailable to cluster mirrors. " ) ;
2011-10-25 17:17:04 +04:00
return 0 ;
}
2008-11-04 01:14:30 +03:00
if ( dm_list_size ( & lv - > segments ) ! = 1 ) {
2016-11-16 17:11:07 +03:00
log_error ( " Multiple-segment mirror is not supported. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
2011-06-23 01:31:21 +04:00
if ( lv_is_active_but_not_locally ( lv ) ) {
log_error ( " Unable to convert the log of a mirror, %s, that is "
2016-11-16 17:11:07 +03:00
" active remotely but not locally. " , display_lvname ( lv ) ) ;
2008-06-27 03:05:11 +04:00
return 0 ;
}
2011-01-11 20:05:08 +03:00
log_lv = first_seg ( lv ) - > log_lv ;
old_log_count = ( log_lv ) ? lv_mirror_count ( log_lv ) : 0 ;
if ( old_log_count = = log_count ) {
2016-11-16 17:11:07 +03:00
log_verbose ( " Mirror %s already has a %s log. " , display_lvname ( lv ) ,
2011-01-11 20:05:08 +03:00
! log_count ? " core " :
( log_count = = 1 ) ? " disk " : " mirrored " ) ;
return 1 ;
}
2018-02-14 14:46:08 +03:00
if ( log_count > 1 ) {
2018-02-15 15:49:45 +03:00
log_warn ( " WARNING: Log type \" mirrored \" is DEPRECATED and will be removed in the future. Use RAID1 LV or disk log instead. " ) ;
2018-02-14 14:46:08 +03:00
}
2014-06-26 06:20:41 +04:00
if ( ! ( parallel_areas = build_parallel_areas_from_lv ( lv , 0 , 0 ) ) )
2007-12-20 18:42:55 +03:00
return_0 ;
2015-09-22 21:04:12 +03:00
if ( ! ( segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_MIRROR ) ) )
2007-12-20 18:42:55 +03:00
return_0 ;
if ( activation ( ) & & segtype - > ops - > target_present & &
2009-02-28 23:04:24 +03:00
! segtype - > ops - > target_present ( cmd , NULL , NULL ) ) {
2007-12-20 18:42:55 +03:00
log_error ( " %s: Required device-mapper target(s) not "
2016-11-23 12:48:33 +03:00
" detected in your kernel. " , segtype - > name ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
/* allocate destination extents */
2016-11-23 12:48:33 +03:00
if ( ! ( ah = allocate_extents ( lv - > vg , NULL , segtype ,
0 , 0 , log_count - old_log_count , region_size ,
lv - > le_count , allocatable_pvs ,
alloc , 0 , parallel_areas ) ) ) {
2008-01-16 22:50:23 +03:00
log_error ( " Unable to allocate extents for mirror log. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
2011-01-11 20:05:08 +03:00
if ( old_log_count ) {
/* Converting from disk to mirrored log */
if ( ! _form_mirror ( cmd , ah , log_lv , log_count - 1 , 1 , 0 ,
region_size , 1 ) ) {
log_error ( " Failed to convert mirror log " ) ;
return 0 ;
}
r = 1 ;
goto out ;
}
2007-12-20 18:42:55 +03:00
/* check sync status */
2011-04-07 01:32:20 +04:00
if ( mirror_in_sync ( ) | |
( lv_mirror_percent ( cmd , lv , 0 , & sync_percent , NULL ) & &
2014-06-09 14:08:27 +04:00
( sync_percent = = DM_PERCENT_100 ) ) )
2007-12-20 18:42:55 +03:00
in_sync = 1 ;
else
in_sync = 0 ;
if ( ! ( log_lv = _set_up_mirror_log ( cmd , ah , lv , log_count ,
region_size , alloc , in_sync ) ) )
2009-04-07 14:20:28 +04:00
goto_out ;
2007-12-20 18:42:55 +03:00
2008-01-26 03:25:04 +03:00
if ( ! attach_mirror_log ( first_seg ( lv ) , log_lv ) )
2009-04-07 14:20:28 +04:00
goto_out ;
2007-12-20 18:42:55 +03:00
2009-04-07 14:20:28 +04:00
r = 1 ;
out :
2007-12-20 18:42:55 +03:00
alloc_destroy ( ah ) ;
2009-04-07 14:20:28 +04:00
return r ;
2007-12-20 18:42:55 +03:00
}
/*
* Convert " linear " LV to " mirror " .
*/
int add_mirror_images ( struct cmd_context * cmd , struct logical_volume * lv ,
2010-04-09 05:00:10 +04:00
uint32_t mirrors , uint32_t stripes ,
uint32_t stripe_size , uint32_t region_size ,
2008-11-04 01:14:30 +03:00
struct dm_list * allocatable_pvs , alloc_policy_t alloc ,
2007-12-20 18:42:55 +03:00
uint32_t log_count )
{
struct alloc_handle * ah ;
const struct segment_type * segtype ;
2008-11-04 01:14:30 +03:00
struct dm_list * parallel_areas ;
2008-06-13 16:15:55 +04:00
struct logical_volume * log_lv = NULL ;
2007-12-20 18:42:55 +03:00
/*
* allocate destination extents
*/
2014-06-26 06:20:41 +04:00
if ( ! ( parallel_areas = build_parallel_areas_from_lv ( lv , 0 , 0 ) ) )
2007-12-20 18:42:55 +03:00
return_0 ;
2015-09-22 21:04:12 +03:00
if ( ! ( segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_MIRROR ) ) )
2007-12-20 18:42:55 +03:00
return_0 ;
2016-11-23 12:48:33 +03:00
if ( ! ( ah = allocate_extents ( lv - > vg , NULL , segtype ,
stripes , mirrors , log_count , region_size , lv - > le_count ,
allocatable_pvs , alloc , 0 , parallel_areas ) ) ) {
2007-12-20 18:42:55 +03:00
log_error ( " Unable to allocate extents for mirror(s). " ) ;
return 0 ;
}
/*
* create and initialize mirror log
*/
if ( log_count & &
2010-06-28 18:19:41 +04:00
! ( log_lv = _set_up_mirror_log ( cmd , ah , lv , log_count ,
( region_size > lv - > vg - > extent_size ) ?
lv - > vg - > extent_size : region_size ,
2009-04-07 14:20:28 +04:00
alloc , mirror_in_sync ( ) ) ) ) {
stack ;
2009-05-21 07:04:52 +04:00
goto out_remove_images ;
2009-04-07 14:20:28 +04:00
}
2007-12-20 18:42:55 +03:00
/* The log initialization involves vg metadata commit.
So from here on , if failure occurs , the log must be explicitly
removed and the updated vg metadata should be committed . */
2010-04-09 05:00:10 +04:00
if ( ! _form_mirror ( cmd , ah , lv , mirrors , stripes , stripe_size , region_size , 0 ) )
2010-01-12 17:00:51 +03:00
goto out_remove_log ;
2008-01-26 03:25:04 +03:00
if ( log_count & & ! attach_mirror_log ( first_seg ( lv ) , log_lv ) )
stack ;
2007-12-20 18:42:55 +03:00
alloc_destroy ( ah ) ;
return 1 ;
out_remove_log :
2009-04-21 18:31:57 +04:00
if ( log_lv ) {
if ( ! lv_remove ( log_lv ) | |
! vg_write ( log_lv - > vg ) | |
! vg_commit ( log_lv - > vg ) )
log_error ( " Manual intervention may be required to remove "
" abandoned log LV before retrying. " ) ;
else
backup ( log_lv - > vg ) ;
}
2009-05-21 07:04:52 +04:00
out_remove_images :
2009-04-07 14:20:28 +04:00
alloc_destroy ( ah ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
/*
* Generic interface for adding mirror and / or mirror log .
* ' mirror ' is the number of mirrors to be added .
* ' pvs ' is either allocatable pvs .
*/
int lv_add_mirrors ( struct cmd_context * cmd , struct logical_volume * lv ,
2010-04-09 05:00:10 +04:00
uint32_t mirrors , uint32_t stripes , uint32_t stripe_size ,
2007-12-20 18:42:55 +03:00
uint32_t region_size , uint32_t log_count ,
2008-11-04 01:14:30 +03:00
struct dm_list * pvs , alloc_policy_t alloc , uint32_t flags )
2007-12-20 18:42:55 +03:00
{
if ( ! mirrors & & ! log_count ) {
2016-11-16 17:11:07 +03:00
log_error ( " No conversion is requested. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
2010-08-02 23:03:45 +04:00
if ( vg_is_clustered ( lv - > vg ) ) {
2012-03-23 20:28:40 +04:00
/* FIXME: move this test out of this function */
/* Skip test for pvmove mirrors, it can use local mirror */
2014-09-16 00:33:53 +04:00
if ( ! lv_is_pvmove ( lv ) & & ! lv_is_locked ( lv ) & &
2013-05-31 21:10:07 +04:00
lv_is_active ( lv ) & &
! lv_is_active_exclusive_locally ( lv ) & & /* lv_is_active_remotely */
2015-01-05 18:45:30 +03:00
! cluster_mirror_is_available ( lv - > vg - > cmd ) ) {
2010-08-02 23:03:45 +04:00
log_error ( " Shared cluster mirrors are not available. " ) ;
return 0 ;
}
/*
* No mirrored logs for cluster mirrors until
* log daemon is multi - threaded .
*/
if ( log_count > 1 ) {
2016-11-16 17:11:07 +03:00
log_error ( " Log type, \" mirrored \" , is unavailable to cluster mirrors. " ) ;
2010-08-02 23:03:45 +04:00
return 0 ;
}
2010-07-21 17:40:21 +04:00
}
2017-09-19 21:08:41 +03:00
if ( lv - > vg - > lock_type & & ! strcmp ( lv - > vg - > lock_type , " dlm " ) & & cmd - > lockd_lv_sh ) {
2017-09-19 19:52:36 +03:00
if ( ! cluster_mirror_is_available ( cmd ) ) {
log_error ( " Shared cluster mirrors are not available. " ) ;
return 0 ;
}
if ( log_count > 1 ) {
log_error ( " Log type, \" mirrored \" , is unavailable to cluster mirrors. " ) ;
return 0 ;
}
}
2008-01-10 21:35:51 +03:00
/* For corelog mirror, activation code depends on
* the global mirror_in_sync status . As we are adding
* a new mirror , it should be set as ' out - of - sync '
* so that the sync starts . */
2008-01-19 01:02:37 +03:00
/* However, MIRROR_SKIP_INIT_SYNC even overrides it. */
if ( flags & MIRROR_SKIP_INIT_SYNC )
init_mirror_in_sync ( 1 ) ;
else if ( ! log_count )
2008-01-10 21:35:51 +03:00
init_mirror_in_sync ( 0 ) ;
2007-12-20 18:42:55 +03:00
if ( flags & MIRROR_BY_SEG ) {
if ( log_count ) {
log_error ( " Persistent log is not supported on "
2016-11-16 17:11:07 +03:00
" segment-by-segment mirroring. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
if ( stripes > 1 ) {
log_error ( " Striped-mirroring is not supported on "
2016-11-16 17:11:07 +03:00
" segment-by-segment mirroring. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
return _add_mirrors_that_preserve_segments ( lv , MIRROR_BY_SEG ,
mirrors , region_size ,
pvs , alloc ) ;
2017-07-19 17:16:12 +03:00
}
if ( flags & MIRROR_BY_SEGMENTED_LV ) {
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
if ( stripes > 1 ) {
log_error ( " Striped-mirroring is not supported on "
2016-11-16 17:11:07 +03:00
" segment-by-segment mirroring. " ) ;
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that
lie within the specified PV range (e.g. /dev/sdb1:0-1000). When
moving more than one LV, the portions of those LVs that are in the
range to be moved are added to a new temporary pvmove LV. The LVs
then point to the range in the pvmove LV, rather than the PV
range.
Example 1:
We have two LVs in this example. After they were
created, the first LV was grown, yeilding two segments
in LV1. So, there are two LVs with a total of three
segments.
Before pvmove:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
After pvmove inserts the temporary pvmove LV:
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
-------------------------------------
PV | 000 - 255 | 256 - 511 | 512 - 767 |
-------------------------------------
Each of the affected LV segments now point to a
range of blocks in the pvmove LV, which purposefully
corresponds to the segments moved from the original
LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary
pvmove LV by segment. Further, as the pvmove LV is activated, only
one of its segments is actually mirrored (i.e. "moving") at a time.
The rest are either complete or not addressed yet. If the pvmove
is aborted, those segments that are completed will remain on the
destination and those that are not yet addressed or in the process
of moving will stay on the source PV. Thus, it is possible to have
a partially completed move - some LVs (or certain segments of LVs)
on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way
through the move.
--------- --------- ---------
| LV1s0 | | LV2s0 | | LV1s1 |
--------- --------- ---------
| | |
-------------------------------------
pvmove0 | seg 0 | seg 1 | seg 2 |
-------------------------------------
| | |
| -------------------------
source PV | | 256 - 511 | 512 - 767 |
| -------------------------
| ||
-------------------------
dest PV | 000 - 255 | 256 - 511 |
-------------------------
This update allows the user to specify that they would like the
pvmove mirror created "by LV" rather than "by segment". That is,
the pvmove LV becomes an image in an encapsulating mirror along
with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PV
The thing that differentiates a pvmove done in this way and a simple
"up-convert" from linear to mirror is the preservation of the
distinct segments. A normal up-convert would simply allocate the
necessary space with no regard for segment boundaries. The pvmove
operation must preserve the segments because they are the critical
boundary between the segments of the LVs being moved. So, when the
pvmove copy image is allocated, all corresponding segments must be
allocated. The code that merges ajoining segments that are part of
the same LV when the metadata is written must also be avoided in
this case. This method of mirroring is unique enough to warrant its
own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two
existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV
(for user created mirrors).
The advantages of performing pvmove in this way is that all of the
LVs affected can be moved together. It is an all-or-nothing approach
that leaves all LV segments on the source PV if the move is aborted.
Additionally, a mirror log can be used (in the future) to provide tracking
of progress; allowing the copy to continue where it left off in the event
there is a deactivation.
2014-06-18 07:59:36 +04:00
return 0 ;
}
return _add_mirrors_that_preserve_segments ( lv , MIRROR_BY_SEGMENTED_LV ,
mirrors , region_size ,
pvs , alloc ) ;
2017-07-19 17:16:12 +03:00
}
if ( flags & MIRROR_BY_LV ) {
2007-12-20 18:42:55 +03:00
if ( ! mirrors )
return add_mirror_log ( cmd , lv , log_count ,
region_size , pvs , alloc ) ;
return add_mirror_images ( cmd , lv , mirrors ,
2010-04-09 05:00:10 +04:00
stripes , stripe_size , region_size ,
2007-12-20 18:42:55 +03:00
pvs , alloc , log_count ) ;
}
2016-11-16 17:11:07 +03:00
log_error ( " Unsupported mirror conversion type. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
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
int lv_split_mirror_images ( struct logical_volume * lv , const char * split_name ,
uint32_t split_count , struct dm_list * removable_pvs )
{
2016-03-01 17:31:48 +03:00
int historical ;
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-03-01 17:31:48 +03:00
if ( lv_name_is_used_in_vg ( lv - > vg , split_name , & historical ) ) {
log_error ( " %sLogical Volume \" %s \" already exists in "
2016-11-16 17:11:07 +03:00
" volume group \" %s \" . " , historical ? " historical " : " " ,
2016-03-01 17:31:48 +03:00
split_name , lv - > vg - > name ) ;
2010-07-14 02:24:39 +04:00
return 0 ;
}
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
/* Can't split a mirror that is not in-sync... unless force? */
if ( ! _mirrored_lv_in_sync ( lv ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Unable to split mirror %s that is not in-sync. " ,
display_lvname ( lv ) ) ;
2012-02-24 02:24:47 +04:00
return 0 ;
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
}
/*
* FIXME : Generate default name when not supplied .
*
* If we were going to generate a default name , we would
* do it here . Better to wait for a decision on the form
* of the default name when ' - - track_deltas ' ( the ability
* to merge a split leg back in and only copy the changes )
* is being implemented . For now , we force the user to
* come up with a name for their LV .
*/
2016-11-23 12:48:33 +03:00
if ( ! _split_mirror_images ( lv , split_name , split_count , removable_pvs ) )
2014-05-20 14:53:51 +04:00
return_0 ;
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
return 1 ;
}
2007-12-20 18:42:55 +03:00
/*
* Generic interface for removing mirror and / or mirror log .
* ' mirror ' is the number of mirrors to be removed .
* ' pvs ' is removable pvs .
*/
2010-07-09 19:34:40 +04:00
int lv_remove_mirrors ( struct cmd_context * cmd __attribute__ ( ( unused ) ) ,
2007-12-21 01:37:42 +03:00
struct logical_volume * lv ,
2010-05-24 19:32:20 +04:00
uint32_t mirrors , uint32_t log_count ,
int ( * is_removable ) ( struct logical_volume * , void * ) ,
void * removable_baton ,
2009-11-25 01:55:55 +03:00
uint64_t status_mask )
2007-12-20 18:42:55 +03:00
{
uint32_t new_mirrors ;
struct lv_segment * seg ;
if ( ! mirrors & & ! log_count ) {
2016-11-16 17:11:07 +03:00
log_error ( " No conversion is requested. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
seg = first_seg ( lv ) ;
if ( ! seg_is_mirrored ( seg ) ) {
2016-11-16 17:11:07 +03:00
log_error ( " Not a mirror segment. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
2007-12-20 21:55:46 +03:00
if ( lv_mirror_count ( lv ) < = mirrors ) {
2016-11-16 17:11:07 +03:00
log_error ( " Removing more than existing: %d <= %d. " ,
2007-12-20 18:42:55 +03:00
seg - > area_count , mirrors ) ;
return 0 ;
}
2007-12-20 21:55:46 +03:00
new_mirrors = lv_mirror_count ( lv ) - mirrors - 1 ;
2007-12-20 18:42:55 +03:00
/* MIRROR_BY_LV */
if ( seg_type ( seg , 0 ) = = AREA_LV & &
2014-09-16 00:33:53 +04:00
lv_is_mirror_image ( seg_lv ( seg , 0 ) ) )
2007-12-20 21:55:46 +03:00
return remove_mirror_images ( lv , new_mirrors + 1 ,
2010-05-24 19:32:20 +04:00
is_removable , removable_baton ,
log_count ? 1U : 0 ) ;
2007-12-20 18:42:55 +03:00
/* MIRROR_BY_SEG */
if ( log_count ) {
log_error ( " Persistent log is not supported on "
2016-11-16 17:11:07 +03:00
" segment-by-segment mirroring. " ) ;
2007-12-20 18:42:55 +03:00
return 0 ;
}
return remove_mirrors_from_segments ( lv , new_mirrors , status_mask ) ;
}
2014-11-08 03:28:38 +03:00
int set_mirror_log_count ( int * log_count , const char * mirrorlog )
2014-10-22 23:02:29 +04:00
{
if ( ! strcmp ( " core " , mirrorlog ) )
* log_count = MIRROR_LOG_CORE ;
else if ( ! strcmp ( " disk " , mirrorlog ) )
* log_count = MIRROR_LOG_DISK ;
else if ( ! strcmp ( " mirrored " , mirrorlog ) )
* log_count = MIRROR_LOG_MIRRORED ;
else {
log_error ( " Mirror log type \" %s \" is unknown. " , mirrorlog ) ;
return 0 ;
}
return 1 ;
}
const char * get_mirror_log_name ( int log_count )
{
switch ( log_count ) {
case MIRROR_LOG_CORE : return " core " ;
case MIRROR_LOG_DISK : return " disk " ;
case MIRROR_LOG_MIRRORED : return " mirrored " ;
default :
log_error ( INTERNAL_ERROR " Unknown mirror log count %d. " , log_count ) ;
2014-11-08 03:28:38 +03:00
return NULL ;
2014-10-22 23:02:29 +04:00
}
}