Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2291021pxb; Sun, 3 Apr 2022 00:54:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeYUn5kD3C+qnUhJrQNzJ4NuxHfyR3mjhxAytbIFfcuguysNjxlz9/YpOvD0gtCAkf3mLL X-Received: by 2002:a17:907:da9:b0:6da:beb8:fdac with SMTP id go41-20020a1709070da900b006dabeb8fdacmr6301747ejc.364.1648972473974; Sun, 03 Apr 2022 00:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648972473; cv=none; d=google.com; s=arc-20160816; b=Hgaj1MA4QPFOJY1N5ZKhfc//49HFYb0/eNWUYJggW3ZMVXtcpxsnnfy7BgpwhjfVXP xCtwAcHWSVbWCTIc76nKNMjNVk+RPaJdpLgsrhMiyVM1EDi8MROlQDOeB5cAvBZ8aNqO +4mNG2OtgUWPvw49dPe4hssrAiEjeaTRk56pUMxEMSViQguwq4WuiLfNW1UaNExKzziI 7W7agJYs+l3QJNk9DS3A3tM09D/tQQnteIViBr2N/mdqgzkJuLYc9vuHiMm6NPTQ7pYl SBkqNXSf1yw+zAp49EHegF3wvNCX8BoYcm+yBdc6z0/Hy7ebCOB61MpbpCOgizpTmMi2 ZeWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=VweXxwD5UOtxfld+5NpLwvU8oBMF9ZQgz9KISghsqv4=; b=tfdzWer+JHKSyX8QrN06alpTEjG2IVD9jIin0TEYL4tkIc/ulSBipXEmewL3NV6bjW a4N2HJL3TJo40mdbNe3Ya8/1uwOJE9GaewOh+uLx0g2QIfLU/u5DXMZ/xt6eamDJ0pU/ zr9dpe/mZchIHyjT6ntkLAp8S2NtnVEGPQbONfc7q5fGKa3xSjMLVWT8q43f8kseRfO7 KTcHiwhdkdVx8F+T3fOAMffS2JjNRgP6soZUl2XU4qNdOayexZIwm4+2lwnxJRIcddP+ DMVAnME226xRgXe3Q9b+f6/2wA+8ikSbnQR2phWce/3S5O/ukU6xz63YDaNGDX5YbsQd BOFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DPYJcJML; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz25-20020a170906cd1900b006e7eee64ba4si78196ejb.111.2022.04.03.00.54.09; Sun, 03 Apr 2022 00:54:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DPYJcJML; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345602AbiDAPxi (ORCPT + 99 others); Fri, 1 Apr 2022 11:53:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353896AbiDAPuu (ORCPT ); Fri, 1 Apr 2022 11:50:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A71F43633E; Fri, 1 Apr 2022 08:23:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 39756612B9; Fri, 1 Apr 2022 15:23:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7308C2BBE4; Fri, 1 Apr 2022 15:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648826634; bh=xWcXQye1OTcqa40wP8K9l3+u3eD7fmDLyJj7urdTmaY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=DPYJcJMLE6W6curQMeYfdDhaZminHTICn5OWo5BncOHEinmeF4/zXesta30bj7pxZ zO20xAP5UYBZEnHZ58FBLnVR0ydYH86GMNtBONqiRPX6SK/7VILcxVinJi4e+hRIUt +POqaO3bvUg9hLZ6paBZC8U8BYeaTGLo7Tc/phLX19KTtUWVWO0rdVUQXY7w0LvT5a aDgTa4vKpuoO1J+WlvvGo2irGtnyjJJ0fgpwpSkcn/FNQqhgn/41YifTVGi6oGkC9f wDryZ+GzLzMoUBBfeu1K727FQsaFP7yCtawOvzqQTUSoFQ+uDXaqqhIy3e+yvnUyUY 0UMdFkMJnpsQg== Message-ID: Subject: Re: [PATCH 2/2] ceph: replace usage of found with dedicated list iterator variable From: Jeff Layton To: Jakob Koschel Cc: Ilya Dryomov , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." Date: Fri, 01 Apr 2022 11:23:52 -0400 In-Reply-To: <20220331215329.882411-2-jakobkoschel@gmail.com> References: <20220331215329.882411-1-jakobkoschel@gmail.com> <20220331215329.882411-2-jakobkoschel@gmail.com> Content-Type: text/plain; charset="ISO-8859-15" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-03-31 at 23:53 +0200, Jakob Koschel wrote: > To move the list iterator variable into the list_for_each_entry_*() > macro in the future it should be avoided to use the list iterator > variable after the loop body. > > To *never* use the list iterator variable after the loop it was > concluded to use a separate iterator variable instead of a > found boolean [1]. > > This removes the need to use a found variable and simply checking if > the variable was set, can determine if the break/goto was hit. > > Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] > Signed-off-by: Jakob Koschel > --- > fs/ceph/caps.c | 32 +++++++++++++++----------------- > 1 file changed, 15 insertions(+), 17 deletions(-) > > diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c > index 519750bc5a1a..70f9c5ffa9b7 100644 > --- a/fs/ceph/caps.c > +++ b/fs/ceph/caps.c > @@ -3179,10 +3179,9 @@ void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr, > struct ceph_snap_context *snapc) > { > struct inode *inode = &ci->vfs_inode; > - struct ceph_cap_snap *capsnap = NULL; > + struct ceph_cap_snap *capsnap = NULL, *iter; > int put = 0; > bool last = false; > - bool found = false; > bool flush_snaps = false; > bool complete_capsnap = false; > > @@ -3209,14 +3208,14 @@ void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr, > ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head, > last ? " LAST" : ""); > } else { > - list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { > - if (capsnap->context == snapc) { > - found = true; > + list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) { > + if (iter->context == snapc) { > + capsnap = iter; > break; > } > } > > - if (!found) { > + if (!capsnap) { > /* > * The capsnap should already be removed when removing > * auth cap in the case of a forced unmount. > @@ -3766,8 +3765,7 @@ static void handle_cap_flushsnap_ack(struct inode *inode, u64 flush_tid, > struct ceph_inode_info *ci = ceph_inode(inode); > struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; > u64 follows = le64_to_cpu(m->snap_follows); > - struct ceph_cap_snap *capsnap; > - bool flushed = false; > + struct ceph_cap_snap *capsnap = NULL, *iter; > bool wake_ci = false; > bool wake_mdsc = false; > > @@ -3775,26 +3773,26 @@ static void handle_cap_flushsnap_ack(struct inode *inode, u64 flush_tid, > inode, ci, session->s_mds, follows); > > spin_lock(&ci->i_ceph_lock); > - list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) { > - if (capsnap->follows == follows) { > - if (capsnap->cap_flush.tid != flush_tid) { > + list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) { > + if (iter->follows == follows) { > + if (iter->cap_flush.tid != flush_tid) { > dout(" cap_snap %p follows %lld tid %lld !=" > - " %lld\n", capsnap, follows, > - flush_tid, capsnap->cap_flush.tid); > + " %lld\n", iter, follows, > + flush_tid, iter->cap_flush.tid); > break; > } > - flushed = true; > + capsnap = iter; > break; > } else { > dout(" skipping cap_snap %p follows %lld\n", > - capsnap, capsnap->follows); > + iter, iter->follows); > } > } > - if (flushed) > + if (capsnap) > ceph_remove_capsnap(inode, capsnap, &wake_ci, &wake_mdsc); > spin_unlock(&ci->i_ceph_lock); > > - if (flushed) { > + if (capsnap) { > ceph_put_snap_context(capsnap->context); > ceph_put_cap_snap(capsnap); > if (wake_ci) Thanks Jakob, Both patches look fine. Applied to the ceph-client/testing branch. This should make v5.19 if there are no issues. Thanks! -- Jeff Layton