From ce429225a557a0529ca578fab528631cb3ea80eb Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 13 Dec 2018 11:00:38 +1100 Subject: [PATCH] LU-9679 osc: convert a while loop to for This loop uses 'continue' in several places, and each one is proceeded by ext = next_extent(ext) which also appears at the end. This is exactly the pattern that a 'for' loop simplifies. So change to a for loop. Linux-Commit 9083b739197b ("lustre: osc: convert a while loop to for") Reviewed-by: Andreas Dilger Signed-off-by: Mr NeilBrown Change-Id: Ie622690134f9b3ee829255bcf997d06289abd6e6 Reviewed-on: https://review.whamcloud.com/37606 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Shaun Tancheff Reviewed-by: Oleg Drokin --- lustre/osc/osc_cache.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/lustre/osc/osc_cache.c b/lustre/osc/osc_cache.c index 38a64d1..917ed96 100644 --- a/lustre/osc/osc_cache.c +++ b/lustre/osc/osc_cache.c @@ -692,11 +692,11 @@ static struct osc_extent *osc_extent_find(const struct lu_env *env, restart: osc_object_lock(obj); ext = osc_extent_search(obj, cur->oe_start); - if (ext == NULL) + if (!ext) ext = first_extent(obj); - while (ext != NULL) { + for (; ext; ext = next_extent(ext)) { pgoff_t ext_chk_start = ext->oe_start >> ppc_bits; - pgoff_t ext_chk_end = ext->oe_end >> ppc_bits; + pgoff_t ext_chk_end = ext->oe_end >> ppc_bits; LASSERT(sanity_check_nolock(ext) == 0); if (chunk > ext_chk_end + 1 || chunk < ext_chk_start) @@ -707,15 +707,12 @@ restart: EASSERTF(!overlapped(ext, cur), ext, EXTSTR"\n", EXTPARA(cur)); - ext = next_extent(ext); continue; } /* discontiguous chunks? */ - if (chunk + 1 < ext_chk_start) { - ext = next_extent(ext); + if (chunk + 1 < ext_chk_start) continue; - } /* ok, from now on, ext and cur have these attrs: * 1. covered by the same lock @@ -740,30 +737,24 @@ restart: } /* non-overlapped extent */ - if (ext->oe_state != OES_CACHE || ext->oe_fsync_wait) { + if (ext->oe_state != OES_CACHE || ext->oe_fsync_wait) /* we can't do anything for a non OES_CACHE extent, or * if there is someone waiting for this extent to be * flushed, try next one. */ - ext = next_extent(ext); continue; - } /* check if they belong to the same rpc slot before trying to * merge. the extents are not overlapped and contiguous at * chunk level to get here. */ - if (ext->oe_max_end != max_end) { + if (ext->oe_max_end != max_end) /* if they don't belong to the same RPC slot or * max_pages_per_rpc has ever changed, do not merge. */ - ext = next_extent(ext); continue; - } /* check whether maximum extent size will be hit */ if ((ext_chk_end - ext_chk_start + 1 + 1) << ppc_bits > - cli->cl_max_extent_pages) { - ext = next_extent(ext); + cli->cl_max_extent_pages) continue; - } /* it's required that an extent must be contiguous at chunk * level so that we know the whole extent is covered by grant @@ -800,8 +791,6 @@ restart: } if (found != NULL) break; - - ext = next_extent(ext); } osc_extent_tree_dump(D_CACHE, obj); -- 1.8.3.1