From nobody Tue Dec 16 23:56:08 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C892CC4167B for ; Thu, 30 Nov 2023 11:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345291AbjK3L5d (ORCPT ); Thu, 30 Nov 2023 06:57:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345214AbjK3L5X (ORCPT ); Thu, 30 Nov 2023 06:57:23 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCA9599 for ; Thu, 30 Nov 2023 03:57:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701345449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=6RcSbHR7cFN6wAchAsaYdBBxf6WBZ1koqQk/TqaNhwk=; b=Xwupty/nMJJhM/yZticViVqt36a0O2GGZSLPnwYwxxdWGRjA1TMHB122zTXcg5hti9MwSY bHFWH/6m6a6H87MZCTi6aY+WEJENuH0Q59/ZCP5tVjDIgkVlJMoIGb3qAiikch1KHE5Q+U TTTr8k2Y/dBo6QagV4BsJAGNmwVfUzg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102-cbkPqBosOSuYjqSifHfZyA-1; Thu, 30 Nov 2023 06:57:25 -0500 X-MC-Unique: cbkPqBosOSuYjqSifHfZyA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4944238117F3; Thu, 30 Nov 2023 11:57:25 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.2]) by smtp.corp.redhat.com (Postfix) with SMTP id ED0951C060B1; Thu, 30 Nov 2023 11:57:23 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 30 Nov 2023 12:56:19 +0100 (CET) Date: Thu, 30 Nov 2023 12:56:17 +0100 From: Oleg Nesterov To: David Howells Cc: Al Viro , Marc Dionne , linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] afs: use read_seqbegin() in afs_check_validity() and afs_getattr() Message-ID: <20231130115617.GA21584@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231130115537.GA21550@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" David Howells says: (3) afs_check_validity(). (4) afs_getattr(). These are both pretty short, so your solution is probably good for the= m. That said, afs_vnode_commit_status() can spend a long time under the write lock - and pretty much every file RPC op returns a status update. Change these functions to use read_seqbegin(). This simplifies the code and doesn't change the current behaviour, the "seq" counter is always even so read_seqbegin_or_lock() can never take the lock. Signed-off-by: Oleg Nesterov --- fs/afs/inode.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 78efc9719349..a6ae74d5b698 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -629,10 +629,10 @@ bool afs_check_validity(struct afs_vnode *vnode) enum afs_cb_break_reason need_clear =3D afs_cb_break_no_break; time64_t now =3D ktime_get_real_seconds(); unsigned int cb_break; - int seq =3D 0; + int seq; =20 do { - read_seqbegin_or_lock(&vnode->cb_lock, &seq); + seq =3D read_seqbegin(&vnode->cb_lock); cb_break =3D vnode->cb_break; =20 if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { @@ -650,9 +650,7 @@ bool afs_check_validity(struct afs_vnode *vnode) need_clear =3D afs_cb_break_no_promise; } =20 - } while (need_seqretry(&vnode->cb_lock, seq)); - - done_seqretry(&vnode->cb_lock, seq); + } while (read_seqretry(&vnode->cb_lock, seq)); =20 if (need_clear =3D=3D afs_cb_break_no_break) return true; @@ -755,7 +753,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct p= ath *path, struct inode *inode =3D d_inode(path->dentry); struct afs_vnode *vnode =3D AFS_FS_I(inode); struct key *key; - int ret, seq =3D 0; + int ret, seq; =20 _enter("{ ino=3D%lu v=3D%u }", inode->i_ino, inode->i_generation); =20 @@ -772,7 +770,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct p= ath *path, } =20 do { - read_seqbegin_or_lock(&vnode->cb_lock, &seq); + seq =3D read_seqbegin(&vnode->cb_lock); generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat); if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) && stat->nlink > 0) @@ -784,9 +782,8 @@ int afs_getattr(struct mnt_idmap *idmap, const struct p= ath *path, */ if (S_ISDIR(inode->i_mode)) stat->size =3D vnode->netfs.remote_i_size; - } while (need_seqretry(&vnode->cb_lock, seq)); + } while (read_seqretry(&vnode->cb_lock, seq)); =20 - done_seqretry(&vnode->cb_lock, seq); return 0; } =20 --=20 2.25.1.362.g51ebf55