'pvmove' support for RAID, mirror, and thin
cover 'pvmove' support for RAID, mirror, and thin
The following patches add support for 'pvmove'ing RAID, mirror and thin segments. Once applied, 'pvmove' will also handle moving portions of thin types that sit on RAID or mirror LVs.
I have noticed one annoyance when testing. In some cases, the metadata LV and the data LV for RAID can get switched around. That is, after being moved the RAID metadata area may come after the data area even though they were in the reverse position originally. This is simply a product of the way the LVs are iterated over. It is probably worth investigating a way to straighten this out.
Jonathan Brassow (6):
Misc: Make get_pv_list_for_lv() available to more than just RAID
RAID: Support moving RAID sub-LVs with pvmove
Mirror: Make 'get_pv_list_for_lv' work with mirrors
Thin: Make 'lv_is_on_pv(s)' and 'get_pv_list_for_lv' with with thin
types
Mirror: Support moving mirror sub-LVs with pvmove
Thin: Support moving thin sub-LVs with pvmove
lib/metadata/lv_manip.c | 120 ++++++++++++++++++++++++++++++++- lib/metadata/metadata-exported.h | 2 + lib/metadata/raid_manip.c | 59 +++++------------ man/pvmove.8.in | 4 +- tools/pvmove.c | 136 ++++++++++++++++++++++++++++---------- 5 files changed, 238 insertions(+), 83 deletions(-)
Signature · 1 line
1.7.7.6
PATCH 1/6 Misc: Make get_pv_list_for_lv() available to more than just RAID
The function 'get_pv_list_for_lv' will assemble all the PVs that are used by the specified LV.
--- lib/metadata/lv_manip.c | 76 ++++++++++++++++++++++++++++++++++++++ lib/metadata/metadata-exported.h | 2 + lib/metadata/raid_manip.c | 59 ++++++++--------------------- 3 files changed, 95 insertions(+), 42 deletions(-)
lib/metadata/lv_manip.c +76 -0
@@ -162,6 +162,82 @@ int lv_is_on_pvs(struct logical_volume *lv, struct dm_list *pvs) }/* +* get_pv_list_for_lv +* @mem - mempool to allocate the list from. +* @lv +* @pvs - The list to add pv_list items to. +* +* 'pvs' is filled with 'pv_list' items for PVs that compose the LV. +* If the 'pvs' list already has items in it, duplicates will not be +* added. So, it is safe to repeatedly call this function for different +* LVs and build up a list of PVs for them all. +* Currently handles: +* - linear +* - stripe +* - raid +* It is up to the caller to free the pv_list when they are finished +* with it. +* +* Returns: 1 on success, 0 on error +*/ +int get_pv_list_for_lv (struct dm_pool *mem, +struct logical_volume *lv,struct dm_list *pvs) +{ +int dup_found; +uint32_t s; +struct pv_list *pvl; +struct lv_segment *seg =first_seg (lv); + +log_debug_metadata ("Getting list of PVs that %s/%s is on:" , + lv->vg->name, lv->name); + + dm_list_iterate_items(seg, &lv->segments) { +for (s =0 ; s < seg->area_count; s++) { + dup_found =0 ; + +if (seg_is_raid (seg) &&/* RAID metadata areas */ + (seg_type (seg, s) ==AREA_LV ) && + !get_pv_list_for_lv (mem,seg_metalv (seg, s), pvs)) + return_0; + +if (seg_type (seg, s) ==AREA_LV ) {/* Recurse */ +if (!get_pv_list_for_lv (mem, +seg_lv (seg, s), pvs)) + return_0; +continue ; + } + +if (seg_type (seg, s) !=AREA_PV ) { +log_error (INTERNAL_ERROR +"Linear seg_type should be AREA_PV" ); +return 0 ; + } + +/* do not add duplicates */ + dm_list_iterate_items(pvl, pvs) +if (pvl->pv ==seg_pv (seg, s)) + dup_found =1 ; + +if (dup_found) +continue ; + +if (!(pvl =dm_pool_zalloc (mem,sizeof (*pvl)))) { +log_error ("Failed to allocate memory" ); +return 0 ; + } + + pvl->pv =seg_pv (seg, s); +log_debug_metadata (" %s/%s is on %s" , lv->vg->name, + lv->name,pv_dev_name (pvl->pv)); + +dm_list_add (pvs, &pvl->list); + } + } + +return 1 ; +} + +/* * get_default_region_size * @cmd *
lib/metadata/metadata-exported.h +2 -0
@@ -825,6 +825,8 @@ const char *find_vgname_from_pvid(struct cmd_context *cmd,int lv_is_on_pv (struct logical_volume *lv,struct physical_volume *pv);int lv_is_on_pvs (struct logical_volume *lv,struct dm_list *pvs); +int get_pv_list_for_lv (struct dm_pool *mem, +struct logical_volume *lv,struct dm_list *pvs);/* Find LV segment containing given LE */
lib/metadata/raid_manip.c +17 -42
105 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH 2/6 RAID: Support moving RAID sub-LVs with pvmove
In reply to Jonathan BrassowThis patch allows pvmove to operate on RAID logical volumes. The key component is the ability to avoid moving a RAID 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.
--- tools/pvmove.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 98 insertions(+), 13 deletions(-)
tools/pvmove.c +98 -13
@@ -16,6 +16,7 @@#include "tools.h" #include "polldaemon.h" #include "display.h" +#include "metadata-exported.h" /* for 'get_only_segment_using_this_lv' */ #define PVMOVE_FIRST_TIME 0x00000001/* Called for first time */ #define PVMOVE_EXCLUSIVE 0x00000002/* Require exclusive LV */
@@ -135,6 +136,47 @@ static struct dm_list *_get_allocatable_pvs(struct cmd_context *cmd, int argc, }/* +* _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) { +log_error (INTERNAL_ERROR "alloc_list is NULL" ); +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 ; +} + +/* * Replace any LV segments on given PV with temporary mirror. * Returns list of LVs changed. */
@@ -181,6 +223,8 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,struct logical_volume *lv_mirr, *lv;struct lv_segment *seg;struct lv_list *lvl; +struct pv_list *pvl, *tmp_pvl; +struct dm_list trim_list;uint32_t log_count =0 ;int lv_found =0 ;int lv_skipped =0 ;
@@ -204,7 +248,48 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,dm_list_init (*lvs_changed); -/* Find segments to be moved and set up mirrors */ +/* +* First, +* use top-level LVs (like RAID, mirror, or thin) +* to build a list of PVs that must be avoided due to +* the need to maintain redundancy (e.g. no two RAID images +* should be placed on the same device - unless ALLOC_ANYWHERE). +*/ + dm_list_iterate_items(lvl, &vg->lvs) { + lv = lvl->lv; +if (lv == lv_mirr) +continue ; + +if (lv_name &&strcmp (lv->name, lv_name)) +continue ; + +if (!lv_is_on_pvs (lv, source_pvl)) +continue ; + +dm_list_init (&trim_list); + +if (seg_is_raid (first_seg (lv))) { +if (!get_pv_list_for_lv (lv->vg->cmd->mem, + lv, &trim_list)) + return_NULL; + +if (!_trim_allocatable_pvs (allocatable_pvs, + &trim_list, alloc)) + return_NULL; + +/* Free list obtained from 'get_pv_list_for_lv' */ + dm_list_iterate_items_safe(pvl, tmp_pvl, &trim_list) { +dm_list_del (&pvl->list); +dm_pool_free (lv->vg->cmd->mem, pvl); + } + } + } + +/* +* Second, +* use bottom-level LVs (like *_mimage_*, *_mlog, *_rmeta_*, etc) +* to find segments to be moved and then set up mirrors. +*/ dm_list_iterate_items(lvl, &vg->lvs) { lv = lvl->lv;if (lv == lv_mirr)
@@ -214,23 +299,23 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,continue ; lv_found =1 ; } + +if (!lv_is_on_pvs (lv, source_pvl)) +continue ; +if (lv_is_origin (lv) ||lv_is_cow (lv)) { lv_skipped =1 ;log_print_unless_silent ("Skipping snapshot-related LV %s" , lv->name);continue ; } -if (lv_is_raid_type (lv)) { - seg =first_seg (lv); -if (seg_is_raid (seg)) { - lv_skipped =1 ; -log_print_unless_silent ("Skipping %s LV %s" , - seg->segtype->ops->name (seg), - lv->name); -continue ; - } - lv_skipped =1 ; -log_print_unless_silent ("Skipping RAID sub-LV %s" , - lv->name); + seg =first_seg (lv); +if (seg_is_raid (seg)) { +/* +* Pass over top-level LVs - they were handled. +* Allow sub-LVs to proceed. +*/ +log_debug ("Ignoring top-level %s LV, %s" , + seg->segtype->ops->name (seg), lv->name);continue ; }if (lv->status &MIRRORED ) {
Signature · 1 line
1.7.7.6
PATCH 3/6 Mirror: Make 'get_pv_list_for_lv' work with mirrors
In reply to Jonathan BrassowWe need to consider the possible mirror log when assembling the list of PVs for a mirror logical volume.
This is a prerequisite for having pvmove work on mirrors.
--- lib/metadata/lv_manip.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
lib/metadata/lv_manip.c +5 -0
@@ -175,6 +175,7 @@ int lv_is_on_pvs(struct logical_volume *lv, struct dm_list *pvs)* - linear * - stripe * - raid +* - mirror * It is up to the caller to free the pv_list when they are finished * with it. *
@@ -192,6 +193,10 @@ int get_pv_list_for_lv(struct dm_pool *mem, lv->vg->name, lv->name); dm_list_iterate_items(seg, &lv->segments) { +if (seg->log_lv &&/* Mirror logs */ + !get_pv_list_for_lv (mem, seg->log_lv, pvs)) + return_0; +for (s =0 ; s < seg->area_count; s++) { dup_found =0 ;
Signature · 1 line
1.7.7.6
PATCH 4/6 Thin: Make 'lv_is_on_pv(s)' and 'get_pv_list_for_lv' work with thin types
In reply to Jonathan BrassowThe pool metadata LV must be accounted for when determining what PVs are in a thin-pool. The pool LV must also be accounted for when checking thin volumes.
This is a prerequisite for pvmove working with thin types.
--- lib/metadata/lv_manip.c | 39 +++++++++++++++++++++++++++++++++++---- 1 files changed, 35 insertions(+), 4 deletions(-)
lib/metadata/lv_manip.c +35 -4
@@ -86,10 +86,13 @@ struct lv_names {* (or its metadata device) is on the PV, 1 would be returned for the * top-level LV. * If you wish to check the images themselves, you should pass them. -* -* FIXME: This should be made more generic, possibly use 'for_each_sub_lv'. -* 'for_each_sub_lv' does not yet allow us to short-circuit execution or -* pass back the values we need yet though... +* Currently handles: +* - linear +* - stripe +* - RAID +* - mirror +* - thin-pool +* - thin * * Returns: 1 if LV (or part of LV) is on PV, 0 otherwise */
@@ -110,6 +113,20 @@ int lv_is_on_pv(struct logical_volume *lv, struct physical_volume *pv)if (lv_is_on_pv (seg->log_lv, pv))return 1 ; +/* Check thin-pool metadata area */ +if (lv_is_on_pv (seg->metadata_lv, pv)) +return 1 ; + +/* Check thin volume's pool LV */ +if (lv_is_on_pv (seg->pool_lv, pv)) +return 1 ; + +/* +* Do _not_ check 'external_lv. We wouldn't count an origin's +* PVs as part of a snapshot, so we don't count external_origin's +* PVs as part of a thin-snap/LV +*/ +/* Check stack of LVs */ dm_list_iterate_items(seg, &lv->segments) {for (s =0 ; s < seg->area_count; s++) {
@@ -143,6 +160,8 @@ int lv_is_on_pv(struct logical_volume *lv, struct physical_volume *pv)* @lv * @pvs * +* Handles the segment types listed by 'lv_is_on_pv'. +* * Returns 1 if the LV (or part of the LV) is on any of the pvs * in the list, 0 otherwise. */
@@ -176,6 +195,8 @@ int lv_is_on_pvs(struct logical_volume *lv, struct dm_list *pvs)* - stripe * - raid * - mirror +* - thin-pool +* - thin (which is essentially the same as thin-pool) * It is up to the caller to free the pv_list when they are finished * with it. *
@@ -197,6 +218,16 @@ int get_pv_list_for_lv(struct dm_pool *mem, !get_pv_list_for_lv(mem, seg->log_lv, pvs)) return_0; +if (seg->metadata_lv &&/* Thin-pool metadata area */ + !get_pv_list_for_lv (mem, seg->metadata_lv, pvs)) + return_0; + +if (seg->pool_lv &&/* Check thin volume's pool LV */ + !get_pv_list_for_lv (mem, seg->pool_lv, pvs)) + return_0; + +/* An external origin's PVs do not count */ +for (s =0 ; s < seg->area_count; s++) { dup_found =0 ;
Signature · 1 line
1.7.7.6
PATCH 5/6 Mirror: Support moving mirror sub-LVs with pvmove
In reply to Jonathan BrassowAllow pvmove to process mirror sub-LVs while using the top-level mirror to inform it about which PVs should be avoided.
--- man/pvmove.8.in | 4 ++-- tools/pvmove.c | 20 +++----------------- 2 files changed, 5 insertions(+), 19 deletions(-)
man/pvmove.8.in +2 -2
@@ -75,7 +75,7 @@ is updated so that the Logical Volumes reflect the new data locations. Note that this new process cannot support the original LVM1 type of on-disk metadata. Metadata can be converted using \fBvgconvert\fP(8). -N.B. The moving of mirrors, snapshots and their origins is not yet supported. +N.B. The moving of snapshots and their origins is not yet supported. .SH OPTIONS See \fBlvm\fP(8) for common options.
@@ -109,7 +109,7 @@ To move all Physical Extents that are used by simple Logical Volumes on .sp .B pvmove /dev/sdb1 .P -Any mirrors, snapshots and their origins are left unchanged. +Any snapshots and their origins are left unchanged. .P Additionally, a specific destination device /dev/sdc1 can be specified like this:
tools/pvmove.c +3 -17
@@ -268,7 +268,8 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,dm_list_init (&trim_list); -if (seg_is_raid (first_seg (lv))) { +if (seg_is_raid (first_seg (lv)) || +seg_is_mirrored (first_seg (lv))) {if (!get_pv_list_for_lv (lv->vg->cmd->mem, lv, &trim_list)) return_NULL;
@@ -309,7 +310,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,continue ; } seg =first_seg (lv); -if (seg_is_raid (seg)) { +if (seg_is_raid (seg) ||seg_is_mirrored (seg)) {/* * Pass over top-level LVs - they were handled. * Allow sub-LVs to proceed.
@@ -318,21 +319,6 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd, seg->segtype->ops->name(seg), lv->name);continue ; } -if (lv->status &MIRRORED ) { - lv_skipped =1 ; -log_print_unless_silent ("Skipping mirror LV %s" , lv->name); -continue ; - } -if (lv->status &MIRROR_LOG ) { - lv_skipped =1 ; -log_print_unless_silent ("Skipping mirror log LV %s" , lv->name); -continue ; - } -if (lv->status &MIRROR_IMAGE ) { - lv_skipped =1 ; -log_print_unless_silent ("Skipping mirror image LV %s" , lv->name); -continue ; - }if (lv_is_thin_volume (lv) ||lv_is_thin_pool (lv)) { lv_skipped =1 ; log_print_unless_silent("Skipping thin%s LV %s",
Signature · 1 line
1.7.7.6
PATCH 6/6 Thin: Support moving thin sub-LVs with pvmove
In reply to Jonathan BrassowIgnore top-level thin LVs while allowing processing of bottom-level LVs. This patch also enables pvmove of thin types which may be on top of RAID or mirror LVs.
--- tools/pvmove.c | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-)
tools/pvmove.c +3 -8
@@ -310,7 +310,8 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,continue ; } seg =first_seg (lv); -if (seg_is_raid (seg) ||seg_is_mirrored (seg)) { +if (seg_is_raid (seg) ||seg_is_mirrored (seg) || +lv_is_thin_volume (lv) ||lv_is_thin_pool (lv)) {/* * Pass over top-level LVs - they were handled. * Allow sub-LVs to proceed.
@@ -319,13 +320,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd, seg->segtype->ops->name(seg), lv->name);continue ; } -if (lv_is_thin_volume (lv) ||lv_is_thin_pool (lv)) { - lv_skipped =1 ; -log_print_unless_silent ("Skipping thin%s LV %s" , -lv_is_thin_pool (lv) ?"-pool" :"" , - lv->name); -continue ; - } +if (lv->status &LOCKED ) { lv_skipped =1 ;log_print_unless_silent ("Skipping locked LV %s" , lv->name);
Signature · 1 line
1.7.7.6