Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5326072rdb; Wed, 13 Dec 2023 05:51:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDT1Q36FKyU3YcrCtqP5QOT6lV/bw9Bh/kJMK91pstmaOari/jhIEcvgUgpkgZtH1tTDHx X-Received: by 2002:a17:902:7d8e:b0:1d3:45b7:bc09 with SMTP id a14-20020a1709027d8e00b001d345b7bc09mr1712897plm.55.1702475478321; Wed, 13 Dec 2023 05:51:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702475478; cv=none; d=google.com; s=arc-20160816; b=lLKREoo+sa2fdqJWe//TlzNv70L4vJJBRdC32TYS5ndCH/1HM39GL4ITkCKAUqAsGs hjOkCdo3iHtJkYw/BMlxo7MrJp51mpQ4xdexcmGb6mriXwQX7lvt0/mTJuj+6ZsKjTCk /4l/NcXbQM4Y65V4VwyHSDAeINg/EGwndzADftDzppESQamUgFdsbhjGhbexPJAb43cs pGD/N33e2u0dSCAnovmsVKZhsoCFFHOh7Th65b9TNXVHyeFXHV50VMMQI5PEWYFnC9DN pO6lXX5JBwS2bpErDi82OExPWr+PF6VQ15eb0bJzicnJeU/fcuLzPHnP2BylcYQ6Ip6G aZMw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T1V5XWZwi8Si/Pu2Wz1ewFIvsN/YxVBeWmgh8/pdp+g=; fh=9eDgTo8aIuwg9MpGeudPwJT3CA93x8I1cKC8E1Wz3RU=; b=qT4P5DgXVMraJVYk9w/gSi1nbbiV3tVcHFfOqGkVf1iYZImy5OQD5uKac3u2ONbVwo WXwwqkTWoNNJ99jwGoOR5muTvmDvoiPbYvBhUUbyaHVoI6uEiZ/C3QtRgQCNH462mLDp SPxWNnphettnEacJo/6u2nm5jm7slC6jo3h22f4Mq9Ai6jfHZwybSmRBNFw56Ysiekan 9aWQAfM6J8NXA8hgzCsUTW1hJB2PO6qtYEn+PtQ305EiriSTtwQGglOMcDuL89tJsQZG FBpWU7oZCxg2QHH9oLB/FBuSGltTCbCtBswCzGt+HSQ9KDl6Kc/Ydv0bPcsQTk8Loq0u OT/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e64gtR3E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t4-20020a170902e84400b001d09c96ba02si9809713plg.124.2023.12.13.05.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 05:51:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e64gtR3E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F161C807214B; Wed, 13 Dec 2023 05:50:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379073AbjLMNuO (ORCPT + 99 others); Wed, 13 Dec 2023 08:50:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379056AbjLMNuI (ORCPT ); Wed, 13 Dec 2023 08:50:08 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE7D4CD for ; Wed, 13 Dec 2023 05:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T1V5XWZwi8Si/Pu2Wz1ewFIvsN/YxVBeWmgh8/pdp+g=; b=e64gtR3EgPg8kmqW+lMEMtmcEhjgsulWOg2bgehogikTcFBJ+O3+GVy0qIusqTOkXRIMHi +sjE1UigNok205CUoSWYBdpiEXvTl4Wu2ZOvSKZsNv5V2qHYTTuhVSvp60QQQSe27XIqcQ 876KL4BFizalJZqLeYF+xbZFLi5AGno= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-mdSN0jaCN_qTHYeXXvf08A-1; Wed, 13 Dec 2023 08:50:12 -0500 X-MC-Unique: mdSN0jaCN_qTHYeXXvf08A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 AE063185A785; Wed, 13 Dec 2023 13:50:11 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF75B2166B31; Wed, 13 Dec 2023 13:50:10 +0000 (UTC) From: David Howells To: Marc Dionne Cc: David Howells , linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Oleg Nesterov Subject: [PATCH v2 03/40] afs: use read_seqbegin() in afs_check_validity() and afs_getattr() Date: Wed, 13 Dec 2023 13:49:25 +0000 Message-ID: <20231213135003.367397-4-dhowells@redhat.com> In-Reply-To: <20231213135003.367397-1-dhowells@redhat.com> References: <20231213135003.367397-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 05:50:31 -0800 (PST) From: Oleg Nesterov David Howells says: (3) afs_check_validity(). (4) afs_getattr(). These are both pretty short, so your solution is probably good for them. 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 Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org Link: https://lore.kernel.org/r/20231130115617.GA21584@redhat.com/ --- 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 = afs_cb_break_no_break; time64_t now = ktime_get_real_seconds(); unsigned int cb_break; - int seq = 0; + int seq; do { - read_seqbegin_or_lock(&vnode->cb_lock, &seq); + seq = read_seqbegin(&vnode->cb_lock); cb_break = vnode->cb_break; if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { @@ -650,9 +650,7 @@ bool afs_check_validity(struct afs_vnode *vnode) need_clear = afs_cb_break_no_promise; } - } while (need_seqretry(&vnode->cb_lock, seq)); - - done_seqretry(&vnode->cb_lock, seq); + } while (read_seqretry(&vnode->cb_lock, seq)); if (need_clear == afs_cb_break_no_break) return true; @@ -755,7 +753,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path, struct inode *inode = d_inode(path->dentry); struct afs_vnode *vnode = AFS_FS_I(inode); struct key *key; - int ret, seq = 0; + int ret, seq; _enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation); @@ -772,7 +770,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path, } do { - read_seqbegin_or_lock(&vnode->cb_lock, &seq); + seq = 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 path *path, */ if (S_ISDIR(inode->i_mode)) stat->size = vnode->netfs.remote_i_size; - } while (need_seqretry(&vnode->cb_lock, seq)); + } while (read_seqretry(&vnode->cb_lock, seq)); - done_seqretry(&vnode->cb_lock, seq); return 0; }