2003-04-30 19:28:17 +04:00
/*
2008-01-30 17:00:02 +03:00
* Copyright ( C ) 2003 - 2004 Sistina Software , Inc . All rights reserved .
2015-03-12 18:21:43 +03:00
* Copyright ( C ) 2004 - 2015 Red Hat , Inc . All rights reserved .
2003-04-30 19:28:17 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2003-04-30 19:28:17 +04:00
*
2004-03-30 23:35:44 +04:00
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2003-04-30 19:28:17 +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-04-30 19:28:17 +04:00
*/
# include "tools.h"
2015-07-06 19:30:18 +03:00
2018-05-14 12:30:20 +03:00
# include "lib/lvmpolld/polldaemon.h"
# include "lib/display/display.h"
2015-03-12 18:21:43 +03:00
# include "pvmove_poll.h"
2018-05-14 12:30:20 +03:00
# include "lib/lvmpolld/lvmpolld-client.h"
2008-04-07 14:23:47 +04:00
2015-03-16 22:23:58 +03:00
# define PVMOVE_FIRST_TIME 0x00000001 /* Called for first time */
2016-01-12 23:57:52 +03:00
struct pvmove_params {
char * pv_name_arg ; /* original unmodified arg */
char * lv_name_arg ; /* original unmodified arg */
alloc_policy_t alloc ;
int pv_count ;
char * * pv_names ;
union lvid * lvid ;
char * id_vg_name ;
char * id_lv_name ;
unsigned in_progress ;
int setup_result ;
int found_pv ;
} ;
2015-03-16 22:23:58 +03:00
static int _pvmove_target_present ( struct cmd_context * cmd , int clustered )
{
const struct segment_type * segtype ;
int found = 1 ;
2015-09-22 21:04:12 +03:00
if ( ! ( segtype = get_segtype_from_string ( cmd , SEG_TYPE_NAME_MIRROR ) ) )
2015-03-16 22:23:58 +03:00
return_0 ;
if ( activation ( ) & & segtype - > ops - > target_present & &
2019-10-11 19:12:11 +03:00
! segtype - > ops - > target_present ( cmd , NULL , NULL ) )
2015-03-16 22:23:58 +03:00
found = 0 ;
return found ;
}
2018-01-31 12:53:09 +03:00
static unsigned _pvmove_is_exclusive ( struct cmd_context * cmd ,
struct volume_group * vg )
{
return 0 ;
}
2003-04-30 19:28:17 +04:00
/* Allow /dev/vgname/lvname, vgname/lvname or lvname */
static const char * _extract_lvname ( struct cmd_context * cmd , const char * vgname ,
const char * arg )
{
const char * lvname ;
/* Is an lvname supplied directly? */
if ( ! strchr ( arg , ' / ' ) )
return arg ;
2007-03-09 23:47:41 +03:00
lvname = skip_dev_dir ( cmd , arg , NULL ) ;
2003-04-30 19:28:17 +04:00
while ( * lvname = = ' / ' )
lvname + + ;
if ( ! strchr ( lvname , ' / ' ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " --name takes a logical volume name. " ) ;
2003-04-30 19:28:17 +04:00
return NULL ;
}
if ( strncmp ( vgname , lvname , strlen ( vgname ) ) | |
( lvname + = strlen ( vgname ) , * lvname ! = ' / ' ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " Named LV and old PV must be in the same VG. " ) ;
2003-04-30 19:28:17 +04:00
return NULL ;
}
while ( * lvname = = ' / ' )
lvname + + ;
if ( ! * lvname ) {
2017-10-31 22:50:51 +03:00
log_error ( " Incomplete LV name supplied with --name. " ) ;
2003-04-30 19:28:17 +04:00
return NULL ;
}
return lvname ;
}
2003-05-06 16:20:11 +04:00
/* Create list of PVs for allocation of replacement extents */
2008-11-04 01:14:30 +03:00
static struct dm_list * _get_allocatable_pvs ( struct cmd_context * cmd , int argc ,
2003-05-06 16:20:11 +04:00
char * * argv , struct volume_group * vg ,
2004-09-14 17:59:17 +04:00
struct physical_volume * pv ,
alloc_policy_t alloc )
2003-05-06 16:20:11 +04:00
{
2008-11-04 01:14:30 +03:00
struct dm_list * allocatable_pvs , * pvht , * pvh ;
2003-05-06 16:20:11 +04:00
struct pv_list * pvl ;
2008-01-30 16:19:47 +03:00
if ( argc )
allocatable_pvs = create_pv_list ( cmd - > mem , vg , argc , argv , 1 ) ;
else
allocatable_pvs = clone_pv_list ( cmd - > mem , & vg - > pvs ) ;
if ( ! allocatable_pvs )
return_NULL ;
2003-04-30 19:28:17 +04:00
2008-11-04 01:14:30 +03:00
dm_list_iterate_safe ( pvh , pvht , allocatable_pvs ) {
pvl = dm_list_item ( pvh , struct pv_list ) ;
2004-09-14 17:59:17 +04:00
/* Don't allocate onto the PV we're clearing! */
2007-06-16 02:16:55 +04:00
if ( ( alloc ! = ALLOC_ANYWHERE ) & & ( pvl - > pv - > dev = = pv_dev ( pv ) ) ) {
2008-11-04 01:14:30 +03:00
dm_list_del ( & pvl - > list ) ;
2004-09-14 17:59:17 +04:00
continue ;
}
/* Remove PV if full */
2011-03-30 00:19:03 +04:00
if ( pvl - > pv - > pe_count = = pvl - > pv - > pe_alloc_count )
2008-11-04 01:14:30 +03:00
dm_list_del ( & pvl - > list ) ;
2003-04-30 19:28:17 +04:00
}
2008-11-04 01:14:30 +03:00
if ( dm_list_empty ( allocatable_pvs ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " No extents available for allocation. " ) ;
2003-05-06 16:20:11 +04:00
return NULL ;
2003-04-30 19:28:17 +04:00
}
2003-05-06 16:20:11 +04:00
return allocatable_pvs ;
}
2016-08-15 19:22:32 +03:00
/*
* If @ lv_name ' s a RAID SubLV , check for any PVs
* on @ trim_list holding it ' s sibling ( rimage / rmeta )
* and remove it from the @ trim_list in order to allow
* for pvmove collocation of DataLV / MetaLV pairs .
*/
static int _remove_sibling_pvs_from_trim_list ( struct logical_volume * lv ,
const char * lv_name ,
struct dm_list * trim_list )
{
2017-10-31 22:51:11 +03:00
char * idx , * suffix ;
2018-01-11 15:21:08 +03:00
const char * sibling ;
2017-10-31 22:51:11 +03:00
char sublv_name [ NAME_LEN ] ;
2023-09-19 15:36:30 +03:00
char idx_buf [ 16 ] ;
2016-08-15 19:22:32 +03:00
struct logical_volume * sublv ;
struct dm_list untrim_list , * pvh1 , * pvh2 ;
struct pv_list * pvl1 , * pvl2 ;
/* Give up with success unless @lv_name _and_ valid raid segment type */
if ( ! lv_name | | ! * lv_name | |
! seg_is_raid ( first_seg ( lv ) ) | |
2016-08-15 20:31:04 +03:00
seg_is_raid0 ( first_seg ( lv ) ) | |
! strcmp ( lv - > name , lv_name ) )
2016-08-15 19:22:32 +03:00
return 1 ;
dm_list_init ( & untrim_list ) ;
2024-04-04 19:42:24 +03:00
if ( ! _dm_strncpy ( sublv_name , lv_name , sizeof ( sublv_name ) ) ) {
2018-01-11 15:21:08 +03:00
log_error ( INTERNAL_ERROR " LV name %s is too long. " , lv_name ) ;
return 0 ;
}
if ( ( suffix = strstr ( sublv_name , " _rimage_ " ) ) )
sibling = " meta " ;
else if ( ( suffix = strstr ( sublv_name , " _rmeta_ " ) ) )
sibling = " image " ;
else {
2017-10-31 22:50:51 +03:00
log_error ( " Can't find rimage or rmeta suffix. " ) ;
2016-08-15 19:22:32 +03:00
return 0 ;
2017-10-31 22:50:51 +03:00
}
2016-08-15 19:22:32 +03:00
2017-10-31 22:51:11 +03:00
if ( ! ( idx = strchr ( suffix + 1 , ' _ ' ) ) ) {
log_error ( " Can't find '_' after suffix %s. " , suffix ) ;
2016-08-15 19:22:32 +03:00
return 0 ;
2017-10-31 22:51:11 +03:00
}
2016-08-15 19:22:32 +03:00
idx + + ;
2023-09-19 15:36:30 +03:00
/* Copy idx to local buffer */
2024-04-04 19:42:24 +03:00
if ( ! _dm_strncpy ( idx_buf , idx , sizeof ( idx_buf ) ) ) {
2023-09-19 15:36:30 +03:00
log_error ( INTERNAL_ERROR " Unexpected LV index %s. " , idx ) ;
return 0 ;
}
2016-08-15 19:22:32 +03:00
/* Create the siblings name (e.g. "raidlv_rmeta_N" -> "raidlv_rimage_N" */
2018-01-11 15:21:08 +03:00
if ( dm_snprintf ( suffix + 2 , sizeof ( sublv_name ) - 2 - ( suffix - sublv_name ) ,
2023-09-19 15:36:30 +03:00
" %s_%s " , sibling , idx_buf ) < 0 ) {
2017-10-31 22:51:11 +03:00
log_error ( " Raid sublv for name %s too long. " , lv_name ) ;
return 0 ;
}
2016-08-15 19:22:32 +03:00
if ( ! ( sublv = find_lv ( lv - > vg , sublv_name ) ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " Can't find sub LV %s. " , sublv_name ) ;
2016-11-25 15:46:06 +03:00
return 0 ;
2016-08-15 19:22:32 +03:00
}
if ( ! get_pv_list_for_lv ( lv - > vg - > cmd - > mem , sublv , & untrim_list ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " Can't find PVs for sub LV %s. " , sublv_name ) ;
2016-11-25 15:46:06 +03:00
return 0 ;
2016-08-15 19:22:32 +03:00
}
dm_list_iterate ( pvh1 , & untrim_list ) {
pvl1 = dm_list_item ( pvh1 , struct pv_list ) ;
dm_list_iterate ( pvh2 , trim_list ) {
pvl2 = dm_list_item ( pvh2 , struct pv_list ) ;
if ( pvl1 - > pv = = pvl2 - > pv ) {
2017-10-31 22:50:51 +03:00
log_debug ( " Removing PV %s from trim list. " ,
2016-08-15 19:22:32 +03:00
pvl2 - > pv - > dev - > pvid ) ;
dm_list_del ( & pvl2 - > list ) ;
break ;
}
}
}
return 1 ;
}
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
/*
* _trim_allocatable_pvs
* @ alloc_list
* @ trim_list
*
* Remove PVs in ' trim_list ' from ' alloc_list ' .
*
* Returns : 1 on success , 0 on error
*/
static int _trim_allocatable_pvs ( struct dm_list * alloc_list ,
struct dm_list * trim_list ,
alloc_policy_t alloc )
{
struct dm_list * pvht , * pvh , * trim_pvh ;
struct pv_list * pvl , * trim_pvl ;
if ( ! alloc_list ) {
2017-10-31 22:50:51 +03:00
log_error ( INTERNAL_ERROR " alloc_list is NULL. " ) ;
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
return 0 ;
}
if ( ! trim_list | | dm_list_empty ( trim_list ) )
return 1 ; /* alloc_list stays the same */
dm_list_iterate_safe ( pvh , pvht , alloc_list ) {
pvl = dm_list_item ( pvh , struct pv_list ) ;
dm_list_iterate ( trim_pvh , trim_list ) {
trim_pvl = dm_list_item ( trim_pvh , struct pv_list ) ;
/* Don't allocate onto a trim PV */
if ( ( alloc ! = ALLOC_ANYWHERE ) & &
( pvl - > pv = = trim_pvl - > pv ) ) {
dm_list_del ( & pvl - > list ) ;
break ; /* goto next in alloc_list */
}
}
}
return 1 ;
}
2007-12-20 18:42:55 +03:00
/*
* Replace any LV segments on given PV with temporary mirror .
* Returns list of LVs changed .
*/
static int _insert_pvmove_mirrors ( struct cmd_context * cmd ,
struct logical_volume * lv_mirr ,
2008-11-04 01:14:30 +03:00
struct dm_list * source_pvl ,
2007-12-20 18:42:55 +03:00
struct logical_volume * lv ,
2008-11-04 01:14:30 +03:00
struct dm_list * lvs_changed )
2007-12-20 18:42:55 +03:00
{
struct pv_list * pvl ;
uint32_t prev_le_count ;
/* Only 1 PV may feature in source_pvl */
2008-11-04 01:14:30 +03:00
pvl = dm_list_item ( source_pvl - > n , struct pv_list ) ;
2007-12-20 18:42:55 +03:00
prev_le_count = lv_mirr - > le_count ;
if ( ! insert_layer_for_segments_on_pv ( cmd , lv , lv_mirr , PVMOVE ,
pvl , lvs_changed ) )
return_0 ;
/* check if layer was inserted */
if ( lv_mirr - > le_count - prev_le_count ) {
lv - > status | = LOCKED ;
2017-10-31 22:50:51 +03:00
log_verbose ( " Moving %u extents of logical volume %s. " ,
2007-12-20 18:42:55 +03:00
lv_mirr - > le_count - prev_le_count ,
2017-10-31 22:50:51 +03:00
display_lvname ( lv ) ) ;
2007-12-20 18:42:55 +03:00
}
return 1 ;
}
2013-08-26 23:12:31 +04:00
/*
* Is ' lv ' a sub_lv of the LV by the name of ' lv_name ' ?
*
* Returns : 1 if true , 0 otherwise
*/
2017-10-18 17:57:46 +03:00
static int _sub_lv_of ( struct logical_volume * lv , const char * lv_name )
2013-08-26 23:12:31 +04:00
{
struct lv_segment * seg ;
/* Sub-LVs only ever have one segment using them */
if ( dm_list_size ( & lv - > segs_using_this_lv ) ! = 1 )
return 0 ;
if ( ! ( seg = get_only_segment_using_this_lv ( lv ) ) )
return_0 ;
if ( ! strcmp ( seg - > lv - > name , lv_name ) )
return 1 ;
/* Continue up the tree */
2017-10-18 17:57:46 +03:00
return _sub_lv_of ( seg - > lv , lv_name ) ;
2013-08-26 23:12:31 +04:00
}
2004-05-05 21:56:20 +04:00
/* Create new LV with mirror segments for the required copies */
2003-05-06 16:20:11 +04:00
static struct logical_volume * _set_up_pvmove_lv ( struct cmd_context * cmd ,
struct volume_group * vg ,
2008-11-04 01:14:30 +03:00
struct dm_list * source_pvl ,
2003-05-06 16:20:11 +04:00
const char * lv_name ,
2008-11-04 01:14:30 +03:00
struct dm_list * allocatable_pvs ,
2004-09-14 17:59:17 +04:00
alloc_policy_t alloc ,
2018-01-31 12:53:09 +03:00
struct dm_list * * lvs_changed ,
unsigned * exclusive )
2003-05-06 16:20:11 +04:00
{
struct logical_volume * lv_mirr , * lv ;
2012-12-05 03:47:47 +04:00
struct lv_segment * seg ;
2003-10-16 00:02:46 +04:00
struct lv_list * lvl ;
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
struct dm_list trim_list ;
2007-12-20 18:42:55 +03:00
uint32_t log_count = 0 ;
2008-04-04 15:59:31 +04:00
int lv_found = 0 ;
2009-12-04 17:03:18 +03:00
int lv_skipped = 0 ;
2018-02-15 15:39:58 +03:00
int needs_exclusive = * exclusive ;
const struct logical_volume * holder ;
2020-09-11 12:40:09 +03:00
const char * new_lv_name ;
2003-04-30 19:28:17 +04:00
2003-07-05 02:34:56 +04:00
/* FIXME Cope with non-contiguous => splitting existing segments */
2007-10-11 23:20:38 +04:00
if ( ! ( lv_mirr = lv_create_empty ( " pvmove%d " , NULL ,
2003-05-06 16:20:11 +04:00
LVM_READ | LVM_WRITE ,
2009-05-14 01:28:31 +04:00
ALLOC_CONTIGUOUS , vg ) ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " Creation of temporary pvmove LV failed. " ) ;
2003-05-06 16:20:11 +04:00
return NULL ;
2003-04-30 19:28:17 +04:00
}
2003-05-06 16:20:11 +04:00
lv_mirr - > status | = ( PVMOVE | LOCKED ) ;
2005-10-17 03:03:59 +04:00
if ( ! ( * lvs_changed = dm_pool_alloc ( cmd - > mem , sizeof ( * * lvs_changed ) ) ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " lvs_changed list struct allocation failed. " ) ;
2003-05-06 16:20:11 +04:00
return NULL ;
}
2008-11-04 01:14:30 +03:00
dm_list_init ( * lvs_changed ) ;
2003-04-30 19:28:17 +04:00
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
/*
* First ,
* use top - level RAID and mirror LVs to build a list of PVs
* that must be avoided during allocation . This is necessary
* to maintain redundancy of those targets , but it is also
* sub - optimal . Avoiding entire PVs in this way limits our
* ability to find space for other segment types . In the
* majority of cases , however , this method will suffice and
* in the cases where it does not , the user can issue the
* pvmove on a per - LV basis .
*
* FIXME : Eliminating entire PVs places too many restrictions
* on allocation .
*/
dm_list_iterate_items ( lvl , & vg - > lvs ) {
lv = lvl - > lv ;
if ( lv = = lv_mirr )
continue ;
2020-09-11 12:40:09 +03:00
if ( lv_name ) {
if ( ! ( new_lv_name = top_level_lv_name ( vg , lv_name ) ) )
return_NULL ;
if ( strcmp ( lv - > name , new_lv_name ) )
continue ;
}
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
if ( ! lv_is_on_pvs ( lv , source_pvl ) )
continue ;
2014-09-16 00:33:53 +04:00
if ( lv_is_converting ( lv ) | | lv_is_merging ( lv ) ) {
2018-01-11 12:46:04 +03:00
log_error ( " Unable to pvmove when %s volume %s is present. " ,
lv_is_converting ( lv ) ? " converting " : " merging " ,
display_lvname ( lv ) ) ;
2013-08-27 01:36:30 +04:00
return NULL ;
}
2020-02-04 00:59:12 +03:00
if ( lv_is_writecache_cachevol ( lv ) ) {
log_error ( " Unable to pvmove device used for writecache. " ) ;
return NULL ;
}
2021-06-02 19:12:20 +03:00
if ( lv_is_writecache ( lv ) ) {
struct logical_volume * lv_cachevol = first_seg ( lv ) - > writecache ;
if ( lv_is_on_pvs ( lv_cachevol , source_pvl ) ) {
log_error ( " Unable to move device used for writecache cachevol %s. " , display_lvname ( lv_cachevol ) ) ;
return NULL ;
}
}
2019-11-21 01:07:27 +03:00
if ( lv_is_raid ( lv ) & & lv_raid_has_integrity ( lv ) ) {
log_error ( " Unable to pvmove device used for raid with integrity. " ) ;
return NULL ;
}
2018-02-15 15:39:58 +03:00
seg = first_seg ( lv ) ;
2018-03-27 22:08:40 +03:00
if ( ! needs_exclusive ) {
/* Presence of exclusive LV decides whether pvmove must be also exclusive */
if ( ! seg_only_exclusive ( seg ) ) {
holder = lv_lock_holder ( lv ) ;
if ( seg_only_exclusive ( first_seg ( holder ) ) | | lv_is_origin ( holder ) | | lv_is_cow ( holder ) )
needs_exclusive = 1 ;
} else
needs_exclusive = 1 ;
}
2018-02-15 15:39:58 +03:00
if ( seg_is_raid ( seg ) | | seg_is_mirrored ( seg ) ) {
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
dm_list_init ( & trim_list ) ;
2016-08-15 19:22:32 +03:00
if ( ! get_pv_list_for_lv ( vg - > cmd - > mem , lv , & trim_list ) )
return_NULL ;
/*
2018-01-11 12:46:04 +03:00
* Remove any PVs holding SubLV siblings to allow
* for collocation ( e . g . * rmeta_0 - > * rimage_0 ) .
*
* Callee checks for lv_name and valid raid segment type .
*
* FIXME : don ' t rely on namespace
*/
2016-08-15 19:22:32 +03:00
if ( ! _remove_sibling_pvs_from_trim_list ( lv , lv_name , & trim_list ) )
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
return_NULL ;
if ( ! _trim_allocatable_pvs ( allocatable_pvs ,
& trim_list , alloc ) )
return_NULL ;
}
}
/*
* Second ,
* use bottom - level LVs ( like * _mimage_ * , * _mlog , * _rmeta_ * , etc )
* to find segments to be moved and then set up mirrors .
*/
2008-11-04 01:14:30 +03:00
dm_list_iterate_items ( lvl , & vg - > lvs ) {
2003-10-16 00:02:46 +04:00
lv = lvl - > lv ;
2011-03-30 00:19:03 +04:00
if ( lv = = lv_mirr )
2003-04-30 19:28:17 +04:00
continue ;
2016-08-15 19:22:32 +03:00
2008-04-04 15:59:31 +04:00
if ( lv_name ) {
2017-10-18 17:57:46 +03:00
if ( strcmp ( lv - > name , lv_name ) & & ! _sub_lv_of ( lv , lv_name ) )
2008-04-04 15:59:31 +04:00
continue ;
lv_found = 1 ;
}
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
2018-02-15 15:39:58 +03:00
seg = first_seg ( lv ) ;
if ( seg_is_cache ( seg ) | | seg_is_cache_pool ( seg ) | |
seg_is_mirrored ( seg ) | | seg_is_raid ( seg ) | |
seg_is_snapshot ( seg ) | |
seg_is_thin ( seg ) | | seg_is_thin_pool ( seg ) )
continue ; /* bottom-level LVs only... */
pvmove: Add support for RAID, mirror, and thin
This patch allows pvmove to operate on RAID, mirror and thin LVs.
The key component is the ability to avoid moving a RAID or mirror
sub-LV onto a PV that already has another RAID sub-LV on it.
(e.g. Avoid placing both images of a RAID1 LV on the same PV.)
Top-level LVs are processed to determine which PVs to avoid for
the sake of redundancy, while bottom-level LVs are processed
to determine which segments/extents to move.
This approach does have some drawbacks. By eliminating whole PVs
from the allocation list, we might miss the opportunity to perform
pvmove in some senarios. For example, if we have 3 devices and
a linear uses half of the first, a RAID1 uses half of the first and
half of the second, and a linear uses half of the third (FIGURE 1);
we should be able to pvmove the first device (FIGURE 2).
FIGURE 1:
[ linear ] [ -RAID- ] [ linear ]
[ -RAID- ] [ ] [ ]
FIGURE 2:
[ moved ] [ -RAID- ] [ linear ]
[ moved ] [ linear ] [ -RAID- ]
However, the approach we are using would eliminate the second
device from consideration and would leave us with too little space
for allocation. In these situations, the user does have the ability
to specify LVs and move them one at a time.
2013-08-23 17:57:16 +04:00
if ( ! lv_is_on_pvs ( lv , source_pvl ) )
continue ;
2014-09-16 00:33:53 +04:00
if ( lv_is_locked ( lv ) ) {
2009-12-04 17:03:18 +03:00
lv_skipped = 1 ;
2018-01-11 12:46:04 +03:00
log_print_unless_silent ( " Skipping locked LV %s. " , display_lvname ( lv ) ) ;
2003-05-06 16:20:11 +04:00
continue ;
}
2012-03-27 00:32:58 +04:00
2018-02-15 15:39:58 +03:00
holder = lv_lock_holder ( lv ) ;
2012-03-27 15:43:32 +04:00
2018-02-15 15:39:58 +03:00
if ( needs_exclusive ) {
/* With exclusive pvmove skip LV when:
* - is active remotely
* - is not active locally and cannot be activated exclusively locally
2018-03-27 22:08:20 +03:00
*
2018-02-15 15:39:58 +03:00
* Note : lvm2 can proceed with exclusive pvmove for ' just ' locally active LVs
* in the case it ' s NOT active anywhere else , since LOCKED LVs cannot be
* later activated by user .
2018-01-31 12:53:09 +03:00
*/
2018-06-05 21:21:28 +03:00
if ( ( ! lv_is_active ( holder ) & & ! activate_lv ( cmd , holder ) ) ) {
2018-02-15 15:39:58 +03:00
lv_skipped = 1 ;
log_print_unless_silent ( " Skipping LV %s which is not locally exclusive%s. " ,
display_lvname ( lv ) ,
/* Report missing cmirrord cases that matterd.
* With exclusive LV types cmirrord would not help . */
( * exclusive & &
! lv_is_origin ( holder ) & &
! seg_only_exclusive ( first_seg ( holder ) ) ) ?
" and clustered mirror (cmirror) not detected " : " " ) ;
continue ;
}
} else if ( ! activate_lv ( cmd , holder ) ) {
lv_skipped = 1 ;
log_print_unless_silent ( " Skipping LV %s which cannot be activated. " ,
display_lvname ( lv ) ) ;
2018-01-31 12:53:09 +03:00
continue ;
2018-02-15 15:39:58 +03:00
}
2018-01-31 12:53:09 +03:00
2007-12-20 18:42:55 +03:00
if ( ! _insert_pvmove_mirrors ( cmd , lv_mirr , source_pvl , lv ,
2008-01-30 16:19:47 +03:00
* lvs_changed ) )
return_NULL ;
2003-04-30 19:28:17 +04:00
}
2008-04-04 15:59:31 +04:00
if ( lv_name & & ! lv_found ) {
2017-09-27 14:20:25 +03:00
/* NOTE: Is this now an internal error? It is already checked in _pvmove_setup_single */
2008-04-04 15:59:31 +04:00
log_error ( " Logical volume %s not found. " , lv_name ) ;
return NULL ;
}
2004-05-05 22:33:01 +04:00
/* Is temporary mirror empty? */
2003-04-30 19:28:17 +04:00
if ( ! lv_mirr - > le_count ) {
2009-12-04 17:03:18 +03:00
if ( lv_skipped )
log_error ( " All data on source PV skipped. "
" It contains locked, hidden or "
" non-top level LVs only. " ) ;
2017-10-31 22:50:51 +03:00
log_error ( " No data to move for %s. " , vg - > name ) ;
2003-05-06 16:20:11 +04:00
return NULL ;
2003-04-30 19:28:17 +04:00
}
2018-04-20 11:07:42 +03:00
if ( ! lv_add_mirrors ( cmd , lv_mirr , 1 , 1 , 0 ,
get_default_region_size ( cmd ) ,
log_count , allocatable_pvs , alloc ,
2016-06-22 00:24:52 +03:00
( arg_is_set ( cmd , atomic_ARG ) ) ?
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
MIRROR_BY_SEGMENTED_LV : MIRROR_BY_SEG ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " Failed to convert pvmove LV to mirrored. " ) ;
return NULL ;
2007-12-20 18:42:55 +03:00
}
if ( ! split_parent_segments_for_layer ( cmd , lv_mirr ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " Failed to split segments being moved. " ) ;
return NULL ;
2007-12-20 18:42:55 +03:00
}
2007-12-06 01:11:20 +03:00
2018-02-15 15:39:58 +03:00
if ( needs_exclusive )
2018-01-31 12:53:09 +03:00
* exclusive = 1 ;
2003-05-06 16:20:11 +04:00
return lv_mirr ;
}
2018-01-31 12:53:09 +03:00
static int _activate_lv ( struct cmd_context * cmd , struct logical_volume * lv_mirr ,
unsigned exclusive )
{
int r = 0 ;
2018-06-05 21:21:28 +03:00
r = activate_lv ( cmd , lv_mirr ) ;
2018-01-31 12:53:09 +03:00
if ( ! r )
stack ;
return r ;
}
2015-03-16 22:23:58 +03:00
/*
* Called to set up initial pvmove LV only .
* ( Not called after first or any other section completes . )
*/
2017-11-14 13:46:43 +03:00
static int _update_metadata ( struct logical_volume * lv_mirr ,
2018-01-31 12:53:09 +03:00
struct dm_list * lvs_changed ,
unsigned exclusive )
2015-03-16 22:23:58 +03:00
{
2017-11-14 13:46:43 +03:00
struct lv_list * lvl ;
struct logical_volume * lv = lv_mirr ;
2015-03-16 22:23:58 +03:00
2017-11-14 13:46:43 +03:00
dm_list_iterate_items ( lvl , lvs_changed ) {
lv = lvl - > lv ;
break ;
2015-03-16 22:23:58 +03:00
}
2017-11-14 13:46:43 +03:00
if ( ! lv_update_and_reload ( lv ) )
return_0 ;
2015-03-16 22:23:58 +03:00
2017-11-14 13:46:43 +03:00
/* Ensure mirror LV is active */
2018-01-31 12:53:09 +03:00
if ( ! _activate_lv ( lv_mirr - > vg - > cmd , lv_mirr , exclusive ) ) {
2017-11-14 13:46:43 +03:00
if ( test_mode ( ) )
return 1 ;
2015-03-16 22:23:58 +03:00
/*
* FIXME Run - - abort internally here .
*/
log_error ( " ABORTING: Temporary pvmove mirror activation failed. Run pvmove --abort. " ) ;
2017-11-14 13:46:43 +03:00
return 0 ;
2015-03-16 22:23:58 +03:00
}
2017-11-14 13:46:43 +03:00
return 1 ;
2015-03-16 22:23:58 +03:00
}
2015-04-10 15:08:19 +03:00
static int _copy_id_components ( struct cmd_context * cmd ,
const struct logical_volume * lv , char * * vg_name ,
char * * lv_name , union lvid * lvid )
{
if ( ! ( * vg_name = dm_pool_strdup ( cmd - > mem , lv - > vg - > name ) ) | |
! ( * lv_name = dm_pool_strdup ( cmd - > mem , lv - > name ) ) ) {
log_error ( " Failed to clone VG or LV name. " ) ;
return 0 ;
}
* lvid = lv - > lvid ;
return 1 ;
}
2016-01-12 23:57:52 +03:00
static int _pvmove_setup_single ( struct cmd_context * cmd ,
struct volume_group * vg ,
struct physical_volume * pv ,
struct processing_handle * handle )
2003-05-06 16:20:11 +04:00
{
2016-01-12 23:57:52 +03:00
struct pvmove_params * pp = ( struct pvmove_params * ) handle - > custom_handle ;
2003-05-06 16:20:11 +04:00
const char * lv_name = NULL ;
2008-11-04 01:14:30 +03:00
struct dm_list * source_pvl ;
struct dm_list * allocatable_pvs ;
struct dm_list * lvs_changed ;
2003-05-06 16:20:11 +04:00
struct logical_volume * lv_mirr ;
2017-09-19 21:08:41 +03:00
struct logical_volume * lv = NULL ;
2018-02-15 15:39:58 +03:00
struct lv_list * lvl ;
const struct logical_volume * lvh ;
2016-01-12 23:57:52 +03:00
const char * pv_name = pv_dev_name ( pv ) ;
2012-03-27 00:31:01 +04:00
unsigned flags = PVMOVE_FIRST_TIME ;
2018-01-31 12:53:09 +03:00
unsigned exclusive ;
2009-04-10 14:01:38 +04:00
int r = ECMD_FAILED ;
2003-05-06 16:20:11 +04:00
2024-04-26 00:51:58 +03:00
if ( ! vg ) {
log_error ( INTERNAL_ERROR " Missing volume group. " ) ;
return r ;
}
2016-01-12 23:57:52 +03:00
pp - > found_pv = 1 ;
pp - > setup_result = ECMD_FAILED ;
2015-05-19 16:27:36 +03:00
2016-01-12 23:57:52 +03:00
if ( pp - > lv_name_arg ) {
if ( ! ( lv_name = _extract_lvname ( cmd , vg - > name , pp - > lv_name_arg ) ) ) {
log_error ( " Failed to find an LV name. " ) ;
pp - > setup_result = EINVALID_CMD_LINE ;
return ECMD_FAILED ;
2003-05-06 16:20:11 +04:00
}
2008-04-04 15:59:31 +04:00
if ( ! validate_name ( lv_name ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " Logical volume name %s is invalid. " , lv_name ) ;
2016-01-12 23:57:52 +03:00
pp - > setup_result = EINVALID_CMD_LINE ;
return ECMD_FAILED ;
2008-04-04 15:59:31 +04:00
}
2017-09-19 21:08:41 +03:00
if ( ! ( lv = find_lv ( vg , lv_name ) ) ) {
2017-09-27 14:20:25 +03:00
log_error ( " Logical volume %s not found. " , lv_name ) ;
2017-09-19 21:08:41 +03:00
return ECMD_FAILED ;
}
2020-02-04 00:59:12 +03:00
2019-11-21 01:07:27 +03:00
if ( lv_is_raid ( lv ) & & lv_raid_has_integrity ( lv ) ) {
log_error ( " pvmove not allowed on raid LV with integrity. " ) ;
return ECMD_FAILED ;
}
2023-03-18 00:39:48 +03:00
if ( lv_is_cache ( lv ) | | lv_is_writecache ( lv ) ) {
struct logical_volume * lv_orig = seg_lv ( first_seg ( lv ) , 0 ) ;
if ( lv_is_raid ( lv_orig ) & & lv_raid_has_integrity ( lv_orig ) ) {
log_error ( " pvmove not allowed on raid LV with integrity. " ) ;
return ECMD_FAILED ;
}
}
2003-05-06 16:20:11 +04:00
}
2016-01-12 20:51:12 +03:00
/*
2017-09-19 21:08:41 +03:00
* We would need to avoid any PEs used by LVs that are active ( ex ) on
* other hosts . For LVs that are active on multiple hosts ( sh ) , we
* would need to used cluster mirrors .
2016-01-12 20:51:12 +03:00
*/
2018-06-01 21:24:45 +03:00
if ( vg_is_shared ( vg ) ) {
2017-09-19 21:08:41 +03:00
if ( ! lv ) {
log_error ( " pvmove in a shared VG requires a named LV. " ) ;
return ECMD_FAILED ;
}
if ( lv_is_lockd_sanlock_lv ( lv ) ) {
log_error ( " pvmove not allowed on internal sanlock LV. " ) ;
return ECMD_FAILED ;
}
if ( ! lockd_lv ( cmd , lv , " ex " , LDLV_PERSISTENT ) ) {
log_error ( " pvmove in a shared VG requires exclusive lock on named LV. " ) ;
return ECMD_FAILED ;
2016-01-12 20:51:12 +03:00
}
}
2018-01-31 12:53:09 +03:00
exclusive = _pvmove_is_exclusive ( cmd , vg ) ;
2007-06-16 02:16:55 +04:00
if ( ( lv_mirr = find_pvmove_lv ( vg , pv_dev ( pv ) , PVMOVE ) ) ) {
2017-10-31 22:50:51 +03:00
log_print_unless_silent ( " Detected pvmove in progress for %s. " , pv_name ) ;
2016-01-12 23:57:52 +03:00
if ( pp - > pv_count | | lv_name )
2017-10-31 22:50:51 +03:00
log_warn ( " WARNING: Ignoring remaining command line arguments. " ) ;
2003-04-30 19:28:17 +04:00
2003-05-06 16:20:11 +04:00
if ( ! ( lvs_changed = lvs_using_lv ( cmd , vg , lv_mirr ) ) ) {
2017-10-31 22:50:51 +03:00
log_error ( " ABORTING: Failed to generate list of moving LVs. " ) ;
2009-04-10 14:01:38 +04:00
goto out ;
2003-05-06 16:20:11 +04:00
}
2003-04-30 19:28:17 +04:00
2018-02-15 15:39:58 +03:00
dm_list_iterate_items ( lvl , lvs_changed ) {
lvh = lv_lock_holder ( lvl - > lv ) ;
/* Exclusive LV decides whether pvmove must be also exclusive */
if ( lv_is_origin ( lvh ) | | seg_only_exclusive ( first_seg ( lvh ) ) )
exclusive = 1 ;
}
2003-07-05 02:34:56 +04:00
/* Ensure mirror LV is active */
2018-01-31 12:53:09 +03:00
if ( ! _activate_lv ( cmd , lv_mirr , exclusive ) ) {
2009-07-08 22:15:51 +04:00
log_error ( " ABORTING: Temporary mirror activation failed. " ) ;
2009-04-10 14:01:38 +04:00
goto out ;
2003-05-06 16:20:11 +04:00
}
2012-03-27 00:31:01 +04:00
flags & = ~ PVMOVE_FIRST_TIME ;
2003-05-06 16:20:11 +04:00
} else {
2004-08-18 02:09:02 +04:00
/* Determine PE ranges to be moved */
if ( ! ( source_pvl = create_pv_list ( cmd - > mem , vg , 1 ,
2016-01-12 23:57:52 +03:00
& pp - > pv_name_arg , 0 ) ) )
2009-04-10 14:01:38 +04:00
goto_out ;
2003-05-06 16:20:11 +04:00
2016-01-12 23:57:52 +03:00
if ( pp - > alloc = = ALLOC_INHERIT )
pp - > alloc = vg - > alloc ;
2004-09-14 17:59:17 +04:00
2004-05-05 22:33:01 +04:00
/* Get PVs we can use for allocation */
2016-01-12 23:57:52 +03:00
if ( ! ( allocatable_pvs = _get_allocatable_pvs ( cmd , pp - > pv_count , pp - > pv_names ,
vg , pv , pp - > alloc ) ) )
2009-04-10 14:01:38 +04:00
goto_out ;
2003-05-06 16:20:11 +04:00
2004-08-18 02:09:02 +04:00
if ( ! ( lv_mirr = _set_up_pvmove_lv ( cmd , vg , source_pvl , lv_name ,
2016-01-12 23:57:52 +03:00
allocatable_pvs , pp - > alloc ,
2018-01-31 12:53:09 +03:00
& lvs_changed , & exclusive ) ) )
2009-04-10 14:01:38 +04:00
goto_out ;
2003-05-06 16:20:11 +04:00
}
2008-04-09 16:56:34 +04:00
/* Lock lvs_changed and activate (with old metadata) */
2018-01-31 12:53:09 +03:00
if ( ! activate_lvs ( cmd , lvs_changed , exclusive ) )
2009-04-10 14:01:38 +04:00
goto_out ;
2003-04-30 19:28:17 +04:00
2004-05-05 22:33:01 +04:00
/* FIXME Presence of a mirror once set PVMOVE - now remove associated logic */
/* init_pvmove(1); */
/* vg->status |= PVMOVE; */
2016-01-12 23:57:52 +03:00
if ( ! _copy_id_components ( cmd , lv_mirr , & pp - > id_vg_name , & pp - > id_lv_name , pp - > lvid ) )
2015-05-15 18:06:14 +03:00
goto out ;
2015-03-16 22:23:58 +03:00
if ( flags & PVMOVE_FIRST_TIME )
2018-01-31 12:53:09 +03:00
if ( ! _update_metadata ( lv_mirr , lvs_changed , exclusive ) )
2009-04-10 14:01:38 +04:00
goto_out ;
2003-04-30 19:28:17 +04:00
2004-05-05 22:33:01 +04:00
/* LVs are all in status LOCKED */
2016-01-12 23:57:52 +03:00
pp - > setup_result = ECMD_PROCESSED ;
2009-04-10 14:01:38 +04:00
r = ECMD_PROCESSED ;
out :
return r ;
2003-05-06 16:20:11 +04:00
}
2003-04-30 19:28:17 +04:00
2016-01-12 23:57:52 +03:00
static int _pvmove_read_single ( struct cmd_context * cmd ,
struct volume_group * vg ,
struct physical_volume * pv ,
struct processing_handle * handle )
2015-04-10 15:08:19 +03:00
{
2016-01-12 23:57:52 +03:00
struct pvmove_params * pp = ( struct pvmove_params * ) handle - > custom_handle ;
2015-04-10 15:08:19 +03:00
struct logical_volume * lv ;
2016-01-12 23:57:52 +03:00
int ret = ECMD_FAILED ;
2015-04-10 15:08:19 +03:00
2024-04-26 00:51:58 +03:00
if ( ! vg ) {
log_error ( INTERNAL_ERROR " Missing volume group. " ) ;
return ret ;
}
2016-01-12 23:57:52 +03:00
pp - > found_pv = 1 ;
2015-04-10 15:08:19 +03:00
if ( ! ( lv = find_pvmove_lv ( vg , pv_dev ( pv ) , PVMOVE ) ) ) {
2015-05-09 02:59:18 +03:00
log_print_unless_silent ( " %s: No pvmove in progress - already finished or aborted. " ,
2016-01-12 23:57:52 +03:00
pv_dev_name ( pv ) ) ;
ret = ECMD_PROCESSED ;
pp - > in_progress = 0 ;
} else if ( _copy_id_components ( cmd , lv , & pp - > id_vg_name , & pp - > id_lv_name , pp - > lvid ) ) {
ret = ECMD_PROCESSED ;
pp - > in_progress = 1 ;
2015-04-10 15:08:19 +03:00
}
return ret ;
}
2024-05-03 15:01:59 +03:00
static const struct poll_functions _pvmove_fns = {
2006-05-10 01:23:51 +04:00
. get_copy_name_from_lv = get_pvmove_pvname_from_lv_mirr ,
2009-09-30 22:15:06 +04:00
. poll_progress = poll_mirror_progress ,
2015-03-12 18:21:43 +03:00
. update_metadata = pvmove_update_metadata ,
. finish_copy = pvmove_finish ,
2004-05-05 21:56:20 +04:00
} ;
2003-05-06 16:20:11 +04:00
2016-02-25 15:31:31 +03:00
static struct poll_operation_id * _pvmove_create_id ( struct cmd_context * cmd ,
const char * pv_name ,
const char * vg_name ,
const char * lv_name ,
const char * uuid )
2015-04-10 15:08:19 +03:00
{
2016-02-25 15:31:31 +03:00
struct poll_operation_id * id ;
2015-04-10 15:08:19 +03:00
2016-02-25 15:31:31 +03:00
if ( ! vg_name | | ! lv_name | | ! pv_name | | ! uuid ) {
log_error ( INTERNAL_ERROR " Wrong params for _pvmove_create_id. " ) ;
return NULL ;
}
2015-04-10 15:08:19 +03:00
2016-02-25 15:31:31 +03:00
if ( ! ( id = dm_pool_alloc ( cmd - > mem , sizeof ( * id ) ) ) ) {
2015-04-10 15:08:19 +03:00
log_error ( " Poll operation ID allocation failed. " ) ;
return NULL ;
}
2016-02-25 15:31:31 +03:00
if ( ! ( id - > vg_name = dm_pool_strdup ( cmd - > mem , vg_name ) ) | |
! ( id - > lv_name = dm_pool_strdup ( cmd - > mem , lv_name ) ) | |
! ( id - > display_name = dm_pool_strdup ( cmd - > mem , pv_name ) ) | |
! ( id - > uuid = dm_pool_strdup ( cmd - > mem , uuid ) ) ) {
2015-04-10 15:08:19 +03:00
log_error ( " Failed to copy one or more poll operation ID members. " ) ;
2016-02-25 15:31:31 +03:00
dm_pool_free ( cmd - > mem , id ) ;
return NULL ;
2015-04-10 15:08:19 +03:00
}
return id ;
}
2003-05-06 16:20:11 +04:00
int pvmove_poll ( struct cmd_context * cmd , const char * pv_name ,
2015-04-10 15:08:19 +03:00
const char * uuid , const char * vg_name ,
const char * lv_name , unsigned background )
2003-05-06 16:20:11 +04:00
{
2015-04-10 15:08:19 +03:00
struct poll_operation_id * id = NULL ;
2016-02-25 15:31:31 +03:00
if ( uuid & &
! ( id = _pvmove_create_id ( cmd , pv_name , vg_name , lv_name , uuid ) ) ) {
log_error ( " Failed to allocate poll identifier for pvmove. " ) ;
return ECMD_FAILED ;
2015-04-10 15:08:19 +03:00
}
2015-09-02 17:54:22 +03:00
if ( test_mode ( ) )
2016-02-25 15:31:31 +03:00
return ECMD_PROCESSED ;
2015-04-10 15:08:19 +03:00
2016-02-25 15:31:31 +03:00
return poll_daemon ( cmd , background , PVMOVE , & _pvmove_fns , " Moved " , id ) ;
2003-05-06 16:20:11 +04:00
}
int pvmove ( struct cmd_context * cmd , int argc , char * * argv )
{
2016-01-12 23:57:52 +03:00
struct pvmove_params pp = { 0 } ;
struct processing_handle * handle = NULL ;
2015-04-10 15:08:19 +03:00
union lvid * lvid = NULL ;
2016-01-12 23:57:52 +03:00
char * pv_name = NULL ;
char * colon ;
unsigned is_abort = arg_is_set ( cmd , abort_ARG ) ;
2007-12-20 18:42:55 +03:00
2008-04-09 16:56:34 +04:00
/* dm raid1 target must be present in every case */
2015-03-16 22:23:58 +03:00
if ( ! _pvmove_target_present ( cmd , 0 ) ) {
2008-04-09 16:56:34 +04:00
log_error ( " Required device-mapper target(s) not "
2017-10-31 22:50:51 +03:00
" detected in your kernel. " ) ;
2008-04-09 16:45:32 +04:00
return ECMD_FAILED ;
}
2003-05-06 16:20:11 +04:00
2015-03-05 23:00:44 +03:00
if ( lvmlockd_use ( ) & & ! lvmpolld_use ( ) ) {
/*
* Don ' t want to spend the time making lvmlockd
* work without lvmpolld .
*/
log_error ( " Enable lvmpolld when using lvmlockd. " ) ;
return ECMD_FAILED ;
}
if ( lvmlockd_use ( ) & & ! argc ) {
/*
* FIXME : move process_each_vg from polldaemon up to here ,
* then we can remove this limitation .
*/
log_error ( " Specify pvmove args when using lvmlockd. " ) ;
return ECMD_FAILED ;
}
2003-05-06 16:20:11 +04:00
if ( argc ) {
2015-04-10 15:08:19 +03:00
if ( ! ( lvid = dm_pool_alloc ( cmd - > mem , sizeof ( * lvid ) ) ) ) {
log_error ( " Failed to allocate lvid. " ) ;
return ECMD_FAILED ;
}
2016-01-12 23:57:52 +03:00
pp . lvid = lvid ;
if ( ! ( pp . pv_name_arg = dm_pool_strdup ( cmd - > mem , argv [ 0 ] ) ) ) {
log_error ( " Failed to clone PV name. " ) ;
return ECMD_FAILED ;
}
2015-04-10 15:08:19 +03:00
2010-09-23 16:02:33 +04:00
if ( ! ( pv_name = dm_pool_strdup ( cmd - > mem , argv [ 0 ] ) ) ) {
2015-04-10 15:08:19 +03:00
log_error ( " Failed to clone PV name. " ) ;
2010-09-23 16:02:33 +04:00
return ECMD_FAILED ;
}
2011-08-30 18:55:15 +04:00
dm_unescape_colons_and_at_signs ( pv_name , & colon , NULL ) ;
2004-08-18 02:09:02 +04:00
/* Drop any PE lists from PV name */
2010-09-23 16:02:33 +04:00
if ( colon )
* colon = ' \0 ' ;
2003-05-06 16:20:11 +04:00
2016-01-12 23:57:52 +03:00
argc - - ;
argv + + ;
pp . pv_count = argc ;
pp . pv_names = argv ;
2016-06-22 00:24:52 +03:00
if ( arg_is_set ( cmd , name_ARG ) ) {
2016-01-12 23:57:52 +03:00
if ( ! ( pp . lv_name_arg = dm_pool_strdup ( cmd - > mem , arg_value ( cmd , name_ARG ) ) ) ) {
log_error ( " Failed to clone LV name. " ) ;
return ECMD_FAILED ;
}
}
pp . alloc = ( alloc_policy_t ) arg_uint_value ( cmd , alloc_ARG , ALLOC_INHERIT ) ;
pp . in_progress = 1 ;
/* Normal pvmove setup requires ex lock from lvmlockd. */
if ( is_abort )
cmd - > lockd_vg_default_sh = 1 ;
2016-05-31 13:24:05 +03:00
if ( ! ( handle = init_processing_handle ( cmd , NULL ) ) ) {
2016-01-12 23:57:52 +03:00
log_error ( " Failed to initialize processing handle. " ) ;
2015-03-05 23:00:44 +03:00
return ECMD_FAILED ;
}
2016-01-12 23:57:52 +03:00
handle - > custom_handle = & pp ;
2016-02-16 23:15:24 +03:00
process_each_pv ( cmd , 1 , & pv_name , NULL , 0 ,
2016-01-12 23:57:52 +03:00
is_abort ? 0 : READ_FOR_UPDATE ,
handle ,
is_abort ? & _pvmove_read_single : & _pvmove_setup_single ) ;
destroy_processing_handle ( cmd , handle ) ;
if ( ! is_abort ) {
if ( ! pp . found_pv ) {
stack ;
return EINVALID_CMD_LINE ;
}
if ( pp . setup_result ! = ECMD_PROCESSED ) {
2015-04-10 15:08:19 +03:00
stack ;
2016-01-12 23:57:52 +03:00
return pp . setup_result ;
2015-04-10 15:08:19 +03:00
}
} else {
2016-01-12 23:57:52 +03:00
if ( ! pp . found_pv )
2015-04-10 15:08:19 +03:00
return_ECMD_FAILED ;
2016-01-12 23:57:52 +03:00
if ( ! pp . in_progress )
2015-04-10 15:08:19 +03:00
return ECMD_PROCESSED ;
2003-05-06 16:20:11 +04:00
}
2015-03-05 23:00:44 +03:00
/*
* The command may sit and report progress for some time ,
locking: unify global lock for flock and lockd
There have been two file locks used to protect lvm
"global state": "ORPHANS" and "GLOBAL".
Commands that used the ORPHAN flock in exclusive mode:
pvcreate, pvremove, vgcreate, vgextend, vgremove,
vgcfgrestore
Commands that used the ORPHAN flock in shared mode:
vgimportclone, pvs, pvscan, pvresize, pvmove,
pvdisplay, pvchange, fullreport
Commands that used the GLOBAL flock in exclusive mode:
pvchange, pvscan, vgimportclone, vgscan
Commands that used the GLOBAL flock in shared mode:
pvscan --cache, pvs
The ORPHAN lock covers the important cases of serializing
the use of orphan PVs. It also partially covers the
reporting of orphan PVs (although not correctly as
explained below.)
The GLOBAL lock doesn't seem to have a clear purpose
(it may have eroded over time.)
Neither lock correctly protects the VG namespace, or
orphan PV properties.
To simplify and correct these issues, the two separate
flocks are combined into the one GLOBAL flock, and this flock
is used from the locking sites that are in place for the
lvmlockd global lock.
The logic behind the lvmlockd (distributed) global lock is
that any command that changes "global state" needs to take
the global lock in ex mode. Global state in lvm is: the list
of VG names, the set of orphan PVs, and any properties of
orphan PVs. Reading this global state can use the global lock
in sh mode to ensure it doesn't change while being reported.
The locking of global state now looks like:
lockd_global()
previously named lockd_gl(), acquires the distributed
global lock through lvmlockd. This is unchanged.
It serializes distributed lvm commands that are changing
global state. This is a no-op when lvmlockd is not in use.
lockf_global()
acquires an flock on a local file. It serializes local lvm
commands that are changing global state.
lock_global()
first calls lockf_global() to acquire the local flock for
global state, and if this succeeds, it calls lockd_global()
to acquire the distributed lock for global state.
Replace instances of lockd_gl() with lock_global(), so that the
existing sites for lvmlockd global state locking are now also
used for local file locking of global state. Remove the previous
file locking calls lock_vol(GLOBAL) and lock_vol(ORPHAN).
The following commands which change global state are now
serialized with the exclusive global flock:
pvchange (of orphan), pvresize (of orphan), pvcreate, pvremove,
vgcreate, vgextend, vgremove, vgreduce, vgrename,
vgcfgrestore, vgimportclone, vgmerge, vgsplit
Commands that use a shared flock to read global state (and will
be serialized against the prior list) are those that use
process_each functions that are based on processing a list of
all VG names, or all PVs. The list of all VGs or all PVs is
global state and the shared lock prevents those lists from
changing while the command is processing them.
The ORPHAN lock previously attempted to produce an accurate
listing of orphan PVs, but it was only acquired at the end of
the command during the fake vg_read of the fake orphan vg.
This is not when orphan PVs were determined; they were
determined by elimination beforehand by processing all real
VGs, and subtracting the PVs in the real VGs from the list
of all PVs that had been identified during the initial scan.
This is fixed by holding the single global lock in shared mode
while processing all VGs to determine the list of orphan PVs.
2019-04-18 23:01:19 +03:00
* and we do not want or need the global lock held during
2015-03-05 23:00:44 +03:00
* that time .
*/
locking: unify global lock for flock and lockd
There have been two file locks used to protect lvm
"global state": "ORPHANS" and "GLOBAL".
Commands that used the ORPHAN flock in exclusive mode:
pvcreate, pvremove, vgcreate, vgextend, vgremove,
vgcfgrestore
Commands that used the ORPHAN flock in shared mode:
vgimportclone, pvs, pvscan, pvresize, pvmove,
pvdisplay, pvchange, fullreport
Commands that used the GLOBAL flock in exclusive mode:
pvchange, pvscan, vgimportclone, vgscan
Commands that used the GLOBAL flock in shared mode:
pvscan --cache, pvs
The ORPHAN lock covers the important cases of serializing
the use of orphan PVs. It also partially covers the
reporting of orphan PVs (although not correctly as
explained below.)
The GLOBAL lock doesn't seem to have a clear purpose
(it may have eroded over time.)
Neither lock correctly protects the VG namespace, or
orphan PV properties.
To simplify and correct these issues, the two separate
flocks are combined into the one GLOBAL flock, and this flock
is used from the locking sites that are in place for the
lvmlockd global lock.
The logic behind the lvmlockd (distributed) global lock is
that any command that changes "global state" needs to take
the global lock in ex mode. Global state in lvm is: the list
of VG names, the set of orphan PVs, and any properties of
orphan PVs. Reading this global state can use the global lock
in sh mode to ensure it doesn't change while being reported.
The locking of global state now looks like:
lockd_global()
previously named lockd_gl(), acquires the distributed
global lock through lvmlockd. This is unchanged.
It serializes distributed lvm commands that are changing
global state. This is a no-op when lvmlockd is not in use.
lockf_global()
acquires an flock on a local file. It serializes local lvm
commands that are changing global state.
lock_global()
first calls lockf_global() to acquire the local flock for
global state, and if this succeeds, it calls lockd_global()
to acquire the distributed lock for global state.
Replace instances of lockd_gl() with lock_global(), so that the
existing sites for lvmlockd global state locking are now also
used for local file locking of global state. Remove the previous
file locking calls lock_vol(GLOBAL) and lock_vol(ORPHAN).
The following commands which change global state are now
serialized with the exclusive global flock:
pvchange (of orphan), pvresize (of orphan), pvcreate, pvremove,
vgcreate, vgextend, vgremove, vgreduce, vgrename,
vgcfgrestore, vgimportclone, vgmerge, vgsplit
Commands that use a shared flock to read global state (and will
be serialized against the prior list) are those that use
process_each functions that are based on processing a list of
all VG names, or all PVs. The list of all VGs or all PVs is
global state and the shared lock prevents those lists from
changing while the command is processing them.
The ORPHAN lock previously attempted to produce an accurate
listing of orphan PVs, but it was only acquired at the end of
the command during the fake vg_read of the fake orphan vg.
This is not when orphan PVs were determined; they were
determined by elimination beforehand by processing all real
VGs, and subtracting the PVs in the real VGs from the list
of all PVs that had been identified during the initial scan.
This is fixed by holding the single global lock in shared mode
while processing all VGs to determine the list of orphan PVs.
2019-04-18 23:01:19 +03:00
lock_global ( cmd , " un " ) ;
2003-05-06 16:20:11 +04:00
}
2003-04-30 19:28:17 +04:00
2016-01-12 23:57:52 +03:00
return pvmove_poll ( cmd , pv_name , lvid ? lvid - > s : NULL ,
pp . id_vg_name , pp . id_lv_name ,
2015-04-10 15:08:19 +03:00
arg_is_set ( cmd , background_ARG ) ) ;
2003-04-30 19:28:17 +04:00
}