From patchwork Wed Jan 9 06:24:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10753465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2033917D2 for ; Wed, 9 Jan 2019 06:26:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D80328E16 for ; Wed, 9 Jan 2019 06:26:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01D2E28E19; Wed, 9 Jan 2019 06:26:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 99A2628E16 for ; Wed, 9 Jan 2019 06:26:01 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 1CFEA681C33; Tue, 8 Jan 2019 22:26:01 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id D7912681C0F for ; Tue, 8 Jan 2019 22:25:59 -0800 (PST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1CA9BAF0B; Wed, 9 Jan 2019 06:25:59 +0000 (UTC) From: NeilBrown To: James Simmons , Oleg Drokin , Andreas Dilger Date: Wed, 09 Jan 2019 17:24:01 +1100 Message-ID: <154701504159.26726.15747465883750837429.stgit@noble> In-Reply-To: <154701488711.26726.17363928508883972338.stgit@noble> References: <154701488711.26726.17363928508883972338.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [lustre-devel] [PATCH 10/29] lustre: osc_cache: avoid list_for_each_entry_safe when clearing list. X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" X-Virus-Scanned: ClamAV using ClamSMTP When removing some items from a list, list_for_each_entry_safe() is a good choice. When removing all items, it is clearer to use a while loop that repeatedly removes the first element, until there are none left. This makes it obvious that the list ends up empty. Signed-off-by: NeilBrown Reviewed-by: Andreas Dilger --- drivers/staging/lustre/lustre/osc/osc_cache.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c index e65d917336b9..5cd3732101e7 100644 --- a/drivers/staging/lustre/lustre/osc/osc_cache.c +++ b/drivers/staging/lustre/lustre/osc/osc_cache.c @@ -869,7 +869,6 @@ int osc_extent_finish(const struct lu_env *env, struct osc_extent *ext, { struct client_obd *cli = osc_cli(ext->oe_obj); struct osc_async_page *oap; - struct osc_async_page *tmp; int nr_pages = ext->oe_nr_pages; int lost_grant = 0; int blocksize = cli->cl_import->imp_obd->obd_osfs.os_bsize ? : 4096; @@ -882,7 +881,9 @@ int osc_extent_finish(const struct lu_env *env, struct osc_extent *ext, EASSERT(ergo(rc == 0, ext->oe_state == OES_RPC), ext); osc_lru_add_batch(cli, &ext->oe_pages); - list_for_each_entry_safe(oap, tmp, &ext->oe_pages, oap_pending_item) { + while ((oap = list_first_entry_or_null(&ext->oe_pages, + struct osc_async_page, + oap_pending_item))) { list_del_init(&oap->oap_rpc_item); list_del_init(&oap->oap_pending_item); if (last_off <= oap->oap_obj_off) { @@ -1686,11 +1687,11 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli, /* caller must hold loi_list_lock */ void osc_wake_cache_waiters(struct client_obd *cli) { - struct list_head *l, *tmp; struct osc_cache_waiter *ocw; - list_for_each_safe(l, tmp, &cli->cl_cache_waiters) { - ocw = list_entry(l, struct osc_cache_waiter, ocw_entry); + while ((ocw = list_first_entry_or_null(&cli->cl_cache_waiters, + struct osc_cache_waiter, + ocw_entry))) { list_del_init(&ocw->ocw_entry); ocw->ocw_rc = -EDQUOT; @@ -2739,7 +2740,7 @@ int osc_queue_sync_pages(const struct lu_env *env, struct osc_object *obj, { struct client_obd *cli = osc_cli(obj); struct osc_extent *ext; - struct osc_async_page *oap, *tmp; + struct osc_async_page *oap; int page_count = 0; int mppr = cli->cl_max_pages_per_rpc; bool can_merge = true; @@ -2763,7 +2764,9 @@ int osc_queue_sync_pages(const struct lu_env *env, struct osc_object *obj, ext = osc_extent_alloc(obj); if (!ext) { - list_for_each_entry_safe(oap, tmp, list, oap_pending_item) { + while ((oap = list_first_entry_or_null(&oap->oap_pending_item, + struct osc_async_page, + oap_pending_item))) { list_del_init(&oap->oap_pending_item); osc_ap_completion(env, cli, oap, 0, -ENOMEM); } @@ -3093,11 +3096,12 @@ int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj, LASSERT(ergo(!discard, list_empty(&discard_list))); if (!list_empty(&discard_list)) { - struct osc_extent *tmp; int rc; osc_list_maint(osc_cli(obj), obj); - list_for_each_entry_safe(ext, tmp, &discard_list, oe_link) { + while ((ext = list_first_entry_or_null(&discard_list, + struct osc_extent, + oe_link))) { list_del_init(&ext->oe_link); EASSERT(ext->oe_state == OES_LOCKING, ext);