make mirror legs on different tag pvs
cover make mirror legs on different tag pvs
Hi,
With these patches, the mirror legs could be placed on the PVs(with different tags) from the other legs.
Guangliang Zhao (2):
mirror: make mirror legs on different tag pvs
mirror: improve mirror legs on different tag pvs
doc/example.conf.in | 17 ++++++++++++++ lib/config/defaults.h | 1 + lib/metadata/lv_manip.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ man/lvcreate.8.in | 3 +++ 4 files changed, 77 insertions(+)
Signature · 1 line
1.7.10.4
PATCH 1/2 mirror: make mirror legs on different tag pvs
The mirror legs could be placed on the PVs(with different tags) from the other mirror legs with this patch.
The lvcreate allocates the replica "randomly" when creating a mirrored logical volume now, so it could happen that both copies end up on the same array (or on the same site), clearly undesired.
We can't control the fist allocation, because didn't restrict the areas into parallel space. This patch add the limit when finding areas for parallel space, so that mirror legs will always be placed on pvs with differnt tags.
--- doc/example.conf.in | 17 +++++++++++++++++ lib/config/defaults.h | 1 + lib/metadata/lv_manip.c | 37 +++++++++++++++++++++++++++++++++++++ man/lvcreate.8.in | 3 +++ 4 files changed, 58 insertions(+)
doc/example.conf.in +17 -0
@@ -224,6 +224,23 @@ allocation { # algorithm. maximise_cling = 1 + # Set to 1 to guarantee that mirror leg will always be placed on + # different PVs(with different tags) from the other mirror legs. + # + # If you want to enable this feature, the following conditions + # must be met: + # 1) The mirror_legs_require_separate_pvs must be set to 1, the + # default value is 0. + # 2) The cling_tag_list must be activated. + # 3) The length of all pvs with same tag must greater than or equal + # to the mirror's. + + # This feature is only for the first allocation, on the other hand + # when creating new mirrored lvs. + # Please note that the commond may fail if the number of all tags + # on the pvs less than the mirror legs number. + mirror_legs_require_separate_pvs = 0 + # Set to 1 to guarantee that mirror logs will always be placed on # different PVs from the mirror images. This was the default # until version 2.02.85.
lib/config/defaults.h +1 -0
@@ -98,6 +98,7 @@#define DEFAULT_MAX_LV 0#define DEFAULT_ALLOC_POLICY ALLOC_NORMAL#define DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS 0 +#define DEFAULT_MIRROR_LEGS_REQUIRE_SEPARATE_PVS 0#define DEFAULT_MAXIMISE_CLING 1#define DEFAULT_CLUSTERED 0
lib/metadata/lv_manip.c +37 -0
@@ -684,6 +684,9 @@ struct alloc_handle {unsigned maximise_cling;unsigned mirror_logs_separate;/* Force mirror logs on separate PVs? */ +unsigned mirror_legs_separate;/* Force mirror *legs* on separate PVs*/ + +const struct segment_type *segtype;/* * RAID devices require a metadata area that accompanies each
@@ -868,6 +871,7 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd, ah->parity_count = parity_count; ah->region_size = region_size; ah->alloc = alloc; + ah->segtype = segtype;/* * For the purposes of allocation, area_count and parity_count are
@@ -879,6 +883,8 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd, ah->area_multiple =_calc_area_multiple (segtype, area_count + parity_count, stripes); ah->mirror_logs_separate =find_config_tree_bool (cmd,"allocation/mirror_logs_require_separate_pvs" ,DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS ); + ah->mirror_legs_separate =find_config_tree_bool (cmd,"allocation/mirror_legs_require_separate_pvs" , +DEFAULT_MIRROR_LEGS_REQUIRE_SEPARATE_PVS );if (segtype_is_raid (segtype)) {if (metadata_area_count) {
@@ -1725,6 +1731,33 @@ static void _report_needed_allocation_space(struct alloc_handle *ah,log_debug (" %" PRIu32" %ss of %" PRIu32" extents each" , metadata_count, metadata_type, metadata_size); } + +/* +* Return -1 if we don't need check tags, or there aren't any areas in alloc_status +* have the same tag with pva, the index otherwise. +*/ +static int check_areas_separate_tags (struct alloc_handle *ah, +struct alloc_state *alloc_state, +unsigned ix_start, +unsigned ix_end, +struct pv_area *pva) +{ +int i; + +if (!segtype_is_mirrored (ah->segtype) || + alloc_state->allocated || + !ah->mirror_legs_separate || + !ah->cling_tag_list_cn) +return -1 ; + +for (i = ix_start; i < ix_end; i++) +if (_pvs_have_matching_tag (ah->cling_tag_list_cn, + alloc_state->areas[i].pva->map->pv, + pva->map->pv)) +return i; +return -1 ; +} +/* * Returns 1 regardless of whether any space was found, except on error. */
@@ -1842,6 +1875,10 @@ static int _find_some_parallel_space(struct alloc_handle *ah, const struct alloccontinue ;case USE_AREA : +if (check_areas_separate_tags (ah, alloc_state, ix_offset, + ix + ix_offset, pva) >=0 ) + goto next_pv; +/* * Except with ALLOC_ANYWHERE, replace first area with this * one which is smaller but still big enough.
man/lvcreate.8.in +3 -0
@@ -205,6 +205,9 @@ will create a persistent log that is itself mirrored. The optional argument --corelog is equivalent to --mirrorlog core. +Every leg of the mirrored logical volume could be placed on the pvs with +same tag, see details(mirror_legs_require_separate_pvs) in lvm.conf. + .TP .IR \fB\-n ", " \fB\-\-name " " LogicalVolume { Name | Path } The name for the new logical volume.
Signature · 1 line
1.7.10.4
PATCH 2/2 mirror: improve mirror legs on different tag pvs
In reply to Guangliang ZhaoThis patch will find the biggest eligible area every time, and add it to the parallel areas.
The previous just find the different tag pv area with all found ones, if the new area's tag has appeared, just throw it. The new will compare the length, and choose the longer one.
--- lib/metadata/lv_manip.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
lib/metadata/lv_manip.c +22 -3
@@ -1658,6 +1658,21 @@ static uint32_t _calc_required_extents(struct alloc_handle *ah, struct pv_area *return required; } +static void _replace_required_area (struct alloc_handle *ah,uint32_t max_to_allocate, +unsigned ix_pva,struct pv_area *pva, +struct alloc_state *alloc_state,alloc_policy_t alloc) +{ +uint32_t required =_calc_required_extents (ah, pva, ix_pva, max_to_allocate, alloc); + +/* +* We don't worry about the area replaced, because _clear_areas() and +* _reset_unreserved() called by _find_some_parallel_space() will clear +* the alloc_state and reserved areas every time. +*/ +if (required > alloc_state->areas[ix_pva -1 ].used) +_reserve_area (&alloc_state->areas[ix_pva -1 ], pva, required, ix_pva, pva->unreserved); +} +static int _reserve_required_area (struct alloc_handle *ah,uint32_t max_to_allocate,unsigned ix_pva,struct pv_area *pva,struct alloc_state *alloc_state,alloc_policy_t alloc)
@@ -1767,6 +1782,7 @@ static int _find_some_parallel_space(struct alloc_handle *ah, const struct alloc {unsigned ix =0 ;unsigned last_ix; +int ret;struct pv_map *pvm;struct pv_area *pva;unsigned preferred_count =0 ;
@@ -1875,9 +1891,12 @@ static int _find_some_parallel_space(struct alloc_handle *ah, const struct alloccontinue ;case USE_AREA : -if (check_areas_separate_tags (ah, alloc_state, ix_offset, - ix + ix_offset, pva) >=0 ) - goto next_pv; +if ((ret =check_areas_separate_tags (ah, alloc_state, ix_offset, + ix + ix_offset, pva)) >=0 ) { +_replace_required_area (ah, max_to_allocate, ret +1 , + pva, alloc_state, alloc_parms->alloc); +continue ; + }/* * Except with ALLOC_ANYWHERE, replace first area with this
Signature · 1 line
1.7.10.4