From nobody Mon Dec 15 21:24:35 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 35775C4167D for ; Wed, 13 Dec 2023 13:50:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379039AbjLMNuI (ORCPT ); Wed, 13 Dec 2023 08:50:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378960AbjLMNuG (ORCPT ); Wed, 13 Dec 2023 08:50:06 -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 B7C4A9C for ; Wed, 13 Dec 2023 05:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475412; 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=i4ME/XIpRFu9lqWi6l0Lhi5Qaw7MTTiMqknldjpYnCU=; b=cTWboUxL7kK5Hp1oFYGEdSqXcuNXQJsIfasMcEQZ0Sfpx3J4b7ncZ1f/PluD7B9n3W1ywI b7eeIeSuQGoXCH/GTgjczY3liDPDMM5BXVH6wKTPII180HdepwnMFxHx22OycFCbiJNd3N 3wt3u5ikb3bJFcGsgFMSYQZqSaxeMbg= 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-636-SYx12FEyMpiqyNK_cS8-rQ-1; Wed, 13 Dec 2023 08:50:08 -0500 X-MC-Unique: SYx12FEyMpiqyNK_cS8-rQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 7997185A597; Wed, 13 Dec 2023 13:50:08 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82A58C1596E; Wed, 13 Dec 2023 13:50:07 +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 01/40] afs: fix the usage of read_seqbegin_or_lock() in afs_lookup_volume_rcu() Date: Wed, 13 Dec 2023 13:49:23 +0000 Message-ID: <20231213135003.367397-2-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Oleg Nesterov David Howells says: (2) afs_lookup_volume_rcu(). There can be a lot of volumes known by a system. A thousand would require a 10-step walk and this is drivable by remote operation, so I think this should probably take a lock on the second pass too. Make the "seq" counter odd on the 2nd pass, otherwise read_seqbegin_or_lock= () never takes 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/20231130115606.GA21571@redhat.com/ --- fs/afs/callback.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/afs/callback.c b/fs/afs/callback.c index a484fa642808..90f9b2a46ff4 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c @@ -110,13 +110,14 @@ static struct afs_volume *afs_lookup_volume_rcu(struc= t afs_cell *cell, { struct afs_volume *volume =3D NULL; struct rb_node *p; - int seq =3D 0; + int seq =3D 1; =20 do { /* Unfortunately, rbtree walking doesn't give reliable results * under just the RCU read lock, so we have to check for * changes. */ + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&cell->volume_lock, &seq); =20 p =3D rcu_dereference_raw(cell->volumes.rb_node); From nobody Mon Dec 15 21:24:35 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 9EA11C4332F for ; Wed, 13 Dec 2023 13:50:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379063AbjLMNuR (ORCPT ); Wed, 13 Dec 2023 08:50:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378960AbjLMNuK (ORCPT ); Wed, 13 Dec 2023 08:50:10 -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 7AE4BD5 for ; Wed, 13 Dec 2023 05:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475415; 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=ExN3aXWl+sIeMUeAn84eZ7A4PvMHoy42dD/Wo7lzJak=; b=iKyTxqSmxZW4bLX5/AWuwgT4/6GQVx4jK3ncip00GAEh3L+PvmcmudSMrsoUoIdsvzZWsE R8CIM29dbb+vp3gB1FQvv+gOXdwNANLjSt3qcztsprzYJnx29cinm1eOS8QobJDfgZr0QW su2C/l1pINqYHC4OdQ83apSR6Zu3Jag= 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-627-lg-8yNpGM3GXbqS7N0i_IQ-1; Wed, 13 Dec 2023 08:50:10 -0500 X-MC-Unique: lg-8yNpGM3GXbqS7N0i_IQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 13EAE83718B; Wed, 13 Dec 2023 13:50:10 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2723840C6EBA; Wed, 13 Dec 2023 13:50:09 +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 02/40] afs: fix the usage of read_seqbegin_or_lock() in afs_find_server*() Date: Wed, 13 Dec 2023 13:49:24 +0000 Message-ID: <20231213135003.367397-3-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Oleg Nesterov David Howells says: (5) afs_find_server(). There could be a lot of servers in the list and each server can have multiple addresses, so I think this would be better with an exclusive second pass. The server list isn't likely to change all that often, but when it does change, there's a good chance several servers are going to be added/removed one after the other. Further, this is only going to be used for incoming cache management/callback requests from the server, which hopefully aren't going to happen too often - but it is remotely drivable. (6) afs_find_server_by_uuid(). Similarly to (5), there could be a lot of servers to search through, b= ut they are in a tree not a flat list, so it should be faster to process. Again, it's not likely to change that often and, again, when it does change it's likely to involve multiple changes. This can be driven remotely by an incoming cache management request but is mostly going to be driven by setting up or reconfiguring a volume's server list - something that also isn't likely to happen often. Make the "seq" counter odd on the 2nd pass, otherwise read_seqbegin_or_lock= () never takes 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/20231130115614.GA21581@redhat.com/ --- fs/afs/server.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/afs/server.c b/fs/afs/server.c index b5237206eac3..0bd2f5ba6900 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -27,7 +27,7 @@ struct afs_server *afs_find_server(struct afs_net *net, const struct afs_addr_list *alist; struct afs_server *server =3D NULL; unsigned int i; - int seq =3D 0, diff; + int seq =3D 1, diff; =20 rcu_read_lock(); =20 @@ -35,6 +35,7 @@ struct afs_server *afs_find_server(struct afs_net *net, if (server) afs_unuse_server_notime(net, server, afs_server_trace_put_find_rsq); server =3D NULL; + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&net->fs_addr_lock, &seq); =20 if (srx->transport.family =3D=3D AF_INET6) { @@ -90,7 +91,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net= *net, const uuid_t *uu { struct afs_server *server =3D NULL; struct rb_node *p; - int diff, seq =3D 0; + int diff, seq =3D 1; =20 _enter("%pU", uuid); =20 @@ -102,7 +103,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_n= et *net, const uuid_t *uu if (server) afs_unuse_server(net, server, afs_server_trace_put_uuid_rsq); server =3D NULL; - + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&net->fs_lock, &seq); =20 p =3D net->fs_servers.rb_node; From nobody Mon Dec 15 21:24:35 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 515A6C4332F for ; Wed, 13 Dec 2023 13:50:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379137AbjLMNuP (ORCPT ); Wed, 13 Dec 2023 08:50:15 -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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 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 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 =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; } From nobody Mon Dec 15 21:24:35 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 EAD75C4332F for ; Wed, 13 Dec 2023 13:50:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379177AbjLMNuT (ORCPT ); Wed, 13 Dec 2023 08:50:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379071AbjLMNuL (ORCPT ); Wed, 13 Dec 2023 08:50:11 -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 A132FE3 for ; Wed, 13 Dec 2023 05:50:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475416; 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=Fp8oJm4LequRc2I331reI5U2x+5CwUONNx70HoBczl8=; b=BaUZwVQSF5gxpnMaw2AXd5O0FWyAjiokabcaC5UdjCtXv2GEqCKaVCEuA3TaVgtCo3ZWvr g3k7aPCPFFbhDS1C4CrgQTT1E1ERvQO4A12vMTGl9pMk9Y7J19D7dyPG4/i0ZaSCOngxoI EDzPbCsF8dU497uThuISMMOioydawiE= 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-611-1I_O80NHO8G-cTi2fnRfDQ-1; Wed, 13 Dec 2023 08:50:13 -0500 X-MC-Unique: 1I_O80NHO8G-cTi2fnRfDQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 6006B8C46C8; Wed, 13 Dec 2023 13:50:13 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76F7840C6EB9; Wed, 13 Dec 2023 13:50:12 +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 04/40] rxrpc_find_service_conn_rcu: fix the usage of read_seqbegin_or_lock() Date: Wed, 13 Dec 2023 13:49:26 +0000 Message-ID: <20231213135003.367397-5-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Oleg Nesterov rxrpc_find_service_conn_rcu() should make the "seq" counter odd on the second pass, otherwise read_seqbegin_or_lock() never takes 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/20231117164846.GA10410@redhat.com/ --- net/rxrpc/conn_service.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c index 89ac05a711a4..39c908a3ca6e 100644 --- a/net/rxrpc/conn_service.c +++ b/net/rxrpc/conn_service.c @@ -25,7 +25,7 @@ struct rxrpc_connection *rxrpc_find_service_conn_rcu(stru= ct rxrpc_peer *peer, struct rxrpc_conn_proto k; struct rxrpc_skb_priv *sp =3D rxrpc_skb(skb); struct rb_node *p; - unsigned int seq =3D 0; + unsigned int seq =3D 1; =20 k.epoch =3D sp->hdr.epoch; k.cid =3D sp->hdr.cid & RXRPC_CIDMASK; @@ -35,6 +35,7 @@ struct rxrpc_connection *rxrpc_find_service_conn_rcu(stru= ct rxrpc_peer *peer, * under just the RCU read lock, so we have to check for * changes. */ + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&peer->service_conn_lock, &seq); =20 p =3D rcu_dereference_raw(peer->service_conns.rb_node); From nobody Mon Dec 15 21:24:35 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 BBF7EC4167D for ; Wed, 13 Dec 2023 13:50:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379306AbjLMNu3 (ORCPT ); Wed, 13 Dec 2023 08:50:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379130AbjLMNuR (ORCPT ); Wed, 13 Dec 2023 08:50:17 -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 24E0CEB for ; Wed, 13 Dec 2023 05:50:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475420; 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=QGV9zwfUrVu0dsuL3xE/RxLekmedlJaPz1QT5Dh/0EU=; b=G9JdWw+S0+mMKYduoURPlTuS+Mua0gDK9dA5mvp7mb673meLWeMBUPae/f1akCWV9WSCZD 41eTFAQYrNWykJc/Du7GQQjQW6lDdMXgeXxTCBwWjXYKSMHlprerqbp//WNr0U2RYE6sHL Rr2sOdRpcj/+hgkH9anhObCIaGsL5Io= 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-38-LTXDNqsoPDCG5ec_NM7MZA-1; Wed, 13 Dec 2023 08:50:15 -0500 X-MC-Unique: LTXDNqsoPDCG5ec_NM7MZA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 0091F3806707; Wed, 13 Dec 2023 13:50:15 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 168CC3C25; Wed, 13 Dec 2023 13:50:13 +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 Subject: [PATCH v2 05/40] afs: Remove whitespace before most ')' from the trace header Date: Wed, 13 Dec 2023 13:49:27 +0000 Message-ID: <20231213135003.367397-6-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" checkpatch objects to whitespace before ')', so remove most of it from the afs trace header. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- include/trace/events/afs.h | 242 ++++++++++++++++++------------------- 1 file changed, 121 insertions(+), 121 deletions(-) diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index e9d412d19dbb..cfcd6452c156 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -654,12 +654,12 @@ TRACE_EVENT(afs_receive_data, TP_ARGS(call, iter, want_more, ret), =20 TP_STRUCT__entry( - __field(loff_t, remain ) - __field(unsigned int, call ) - __field(enum afs_call_state, state ) - __field(unsigned short, unmarshall ) - __field(bool, want_more ) - __field(int, ret ) + __field(loff_t, remain) + __field(unsigned int, call) + __field(enum afs_call_state, state) + __field(unsigned short, unmarshall) + __field(bool, want_more) + __field(int, ret) ), =20 TP_fast_assign( @@ -686,9 +686,9 @@ TRACE_EVENT(afs_notify_call, TP_ARGS(rxcall, call), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(enum afs_call_state, state ) - __field(unsigned short, unmarshall ) + __field(unsigned int, call) + __field(enum afs_call_state, state) + __field(unsigned short, unmarshall) ), =20 TP_fast_assign( @@ -708,9 +708,9 @@ TRACE_EVENT(afs_cb_call, TP_ARGS(call), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(u32, op ) - __field(u16, service_id ) + __field(unsigned int, call) + __field(u32, op) + __field(u16, service_id) ), =20 TP_fast_assign( @@ -733,11 +733,11 @@ TRACE_EVENT(afs_call, TP_ARGS(call_debug_id, op, ref, outstanding, where), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(int, op ) - __field(int, ref ) - __field(int, outstanding ) - __field(const void *, where ) + __field(unsigned int, call) + __field(int, op) + __field(int, ref) + __field(int, outstanding) + __field(const void *, where) ), =20 TP_fast_assign( @@ -762,9 +762,9 @@ TRACE_EVENT(afs_make_fs_call, TP_ARGS(call, fid), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(enum afs_fs_operation, op ) - __field_struct(struct afs_fid, fid ) + __field(unsigned int, call) + __field(enum afs_fs_operation, op) + __field_struct(struct afs_fid, fid) ), =20 TP_fast_assign( @@ -794,10 +794,10 @@ TRACE_EVENT(afs_make_fs_calli, TP_ARGS(call, fid, i), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(unsigned int, i ) - __field(enum afs_fs_operation, op ) - __field_struct(struct afs_fid, fid ) + __field(unsigned int, call) + __field(unsigned int, i) + __field(enum afs_fs_operation, op) + __field_struct(struct afs_fid, fid) ), =20 TP_fast_assign( @@ -829,10 +829,10 @@ TRACE_EVENT(afs_make_fs_call1, TP_ARGS(call, fid, name), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(enum afs_fs_operation, op ) - __field_struct(struct afs_fid, fid ) - __array(char, name, 24 ) + __field(unsigned int, call) + __field(enum afs_fs_operation, op) + __field_struct(struct afs_fid, fid) + __array(char, name, 24) ), =20 TP_fast_assign( @@ -866,11 +866,11 @@ TRACE_EVENT(afs_make_fs_call2, TP_ARGS(call, fid, name, name2), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(enum afs_fs_operation, op ) - __field_struct(struct afs_fid, fid ) - __array(char, name, 24 ) - __array(char, name2, 24 ) + __field(unsigned int, call) + __field(enum afs_fs_operation, op) + __field_struct(struct afs_fid, fid) + __array(char, name, 24) + __array(char, name2, 24) ), =20 TP_fast_assign( @@ -907,8 +907,8 @@ TRACE_EVENT(afs_make_vl_call, TP_ARGS(call), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(enum afs_vl_operation, op ) + __field(unsigned int, call) + __field(enum afs_vl_operation, op) ), =20 TP_fast_assign( @@ -927,10 +927,10 @@ TRACE_EVENT(afs_call_done, TP_ARGS(call), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(struct rxrpc_call *, rx_call ) - __field(int, ret ) - __field(u32, abort_code ) + __field(unsigned int, call) + __field(struct rxrpc_call *, rx_call) + __field(int, ret) + __field(u32, abort_code) ), =20 TP_fast_assign( @@ -953,10 +953,10 @@ TRACE_EVENT(afs_send_data, TP_ARGS(call, msg), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(unsigned int, flags ) - __field(loff_t, offset ) - __field(loff_t, count ) + __field(unsigned int, call) + __field(unsigned int, flags) + __field(loff_t, offset) + __field(loff_t, count) ), =20 TP_fast_assign( @@ -977,10 +977,10 @@ TRACE_EVENT(afs_sent_data, TP_ARGS(call, msg, ret), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(int, ret ) - __field(loff_t, offset ) - __field(loff_t, count ) + __field(unsigned int, call) + __field(int, ret) + __field(loff_t, offset) + __field(loff_t, count) ), =20 TP_fast_assign( @@ -1001,9 +1001,9 @@ TRACE_EVENT(afs_dir_check_failed, TP_ARGS(vnode, off, i_size), =20 TP_STRUCT__entry( - __field(struct afs_vnode *, vnode ) - __field(loff_t, off ) - __field(loff_t, i_size ) + __field(struct afs_vnode *, vnode) + __field(loff_t, off) + __field(loff_t, i_size) ), =20 TP_fast_assign( @@ -1022,11 +1022,11 @@ TRACE_EVENT(afs_folio_dirty, TP_ARGS(vnode, where, folio), =20 TP_STRUCT__entry( - __field(struct afs_vnode *, vnode ) - __field(const char *, where ) - __field(pgoff_t, index ) - __field(unsigned long, from ) - __field(unsigned long, to ) + __field(struct afs_vnode *, vnode) + __field(const char *, where) + __field(pgoff_t, index) + __field(unsigned long, from) + __field(unsigned long, to) ), =20 TP_fast_assign( @@ -1056,11 +1056,11 @@ TRACE_EVENT(afs_call_state, TP_ARGS(call, from, to, ret, remote_abort), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(enum afs_call_state, from ) - __field(enum afs_call_state, to ) - __field(int, ret ) - __field(u32, abort ) + __field(unsigned int, call) + __field(enum afs_call_state, from) + __field(enum afs_call_state, to) + __field(int, ret) + __field(u32, abort) ), =20 TP_fast_assign( @@ -1084,9 +1084,9 @@ TRACE_EVENT(afs_lookup, TP_ARGS(dvnode, name, fid), =20 TP_STRUCT__entry( - __field_struct(struct afs_fid, dfid ) - __field_struct(struct afs_fid, fid ) - __array(char, name, 24 ) + __field_struct(struct afs_fid, dfid) + __field_struct(struct afs_fid, fid) + __array(char, name, 24) ), =20 TP_fast_assign( @@ -1116,15 +1116,15 @@ TRACE_EVENT(afs_edit_dir, TP_ARGS(dvnode, why, op, block, slot, f_vnode, f_unique, name), =20 TP_STRUCT__entry( - __field(unsigned int, vnode ) - __field(unsigned int, unique ) - __field(enum afs_edit_dir_reason, why ) - __field(enum afs_edit_dir_op, op ) - __field(unsigned int, block ) - __field(unsigned short, slot ) - __field(unsigned int, f_vnode ) - __field(unsigned int, f_unique ) - __array(char, name, 24 ) + __field(unsigned int, vnode) + __field(unsigned int, unique) + __field(enum afs_edit_dir_reason, why) + __field(enum afs_edit_dir_op, op) + __field(unsigned int, block) + __field(unsigned short, slot) + __field(unsigned int, f_vnode) + __field(unsigned int, f_unique) + __array(char, name, 24) ), =20 TP_fast_assign( @@ -1157,8 +1157,8 @@ TRACE_EVENT(afs_protocol_error, TP_ARGS(call, cause), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(enum afs_eproto_cause, cause ) + __field(unsigned int, call) + __field(enum afs_eproto_cause, cause) ), =20 TP_fast_assign( @@ -1177,9 +1177,9 @@ TRACE_EVENT(afs_io_error, TP_ARGS(call, error, where), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(int, error ) - __field(enum afs_io_error, where ) + __field(unsigned int, call) + __field(int, error) + __field(enum afs_io_error, where) ), =20 TP_fast_assign( @@ -1199,9 +1199,9 @@ TRACE_EVENT(afs_file_error, TP_ARGS(vnode, error, where), =20 TP_STRUCT__entry( - __field_struct(struct afs_fid, fid ) - __field(int, error ) - __field(enum afs_file_error, where ) + __field_struct(struct afs_fid, fid) + __field(int, error) + __field(enum afs_file_error, where) ), =20 TP_fast_assign( @@ -1222,9 +1222,9 @@ TRACE_EVENT(afs_cm_no_server, TP_ARGS(call, srx), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(unsigned int, op_id ) - __field_struct(struct sockaddr_rxrpc, srx ) + __field(unsigned int, call) + __field(unsigned int, op_id) + __field_struct(struct sockaddr_rxrpc, srx) ), =20 TP_fast_assign( @@ -1243,9 +1243,9 @@ TRACE_EVENT(afs_cm_no_server_u, TP_ARGS(call, uuid), =20 TP_STRUCT__entry( - __field(unsigned int, call ) - __field(unsigned int, op_id ) - __field_struct(uuid_t, uuid ) + __field(unsigned int, call) + __field(unsigned int, op_id) + __field_struct(uuid_t, uuid) ), =20 TP_fast_assign( @@ -1265,11 +1265,11 @@ TRACE_EVENT(afs_flock_ev, TP_ARGS(vnode, fl, event, error), =20 TP_STRUCT__entry( - __field_struct(struct afs_fid, fid ) - __field(enum afs_flock_event, event ) - __field(enum afs_lock_state, state ) - __field(int, error ) - __field(unsigned int, debug_id ) + __field_struct(struct afs_fid, fid) + __field(enum afs_flock_event, event) + __field(enum afs_lock_state, state) + __field(int, error) + __field(unsigned int, debug_id) ), =20 TP_fast_assign( @@ -1295,13 +1295,13 @@ TRACE_EVENT(afs_flock_op, TP_ARGS(vnode, fl, op), =20 TP_STRUCT__entry( - __field_struct(struct afs_fid, fid ) - __field(loff_t, from ) - __field(loff_t, len ) - __field(enum afs_flock_operation, op ) - __field(unsigned char, type ) - __field(unsigned int, flags ) - __field(unsigned int, debug_id ) + __field_struct(struct afs_fid, fid) + __field(loff_t, from) + __field(loff_t, len) + __field(enum afs_flock_operation, op) + __field(unsigned char, type) + __field(unsigned int, flags) + __field(unsigned int, debug_id) ), =20 TP_fast_assign( @@ -1328,7 +1328,7 @@ TRACE_EVENT(afs_reload_dir, TP_ARGS(vnode), =20 TP_STRUCT__entry( - __field_struct(struct afs_fid, fid ) + __field_struct(struct afs_fid, fid) ), =20 TP_fast_assign( @@ -1345,8 +1345,8 @@ TRACE_EVENT(afs_silly_rename, TP_ARGS(vnode, done), =20 TP_STRUCT__entry( - __field_struct(struct afs_fid, fid ) - __field(bool, done ) + __field_struct(struct afs_fid, fid) + __field(bool, done) ), =20 TP_fast_assign( @@ -1365,9 +1365,9 @@ TRACE_EVENT(afs_get_tree, TP_ARGS(cell, volume), =20 TP_STRUCT__entry( - __field(u64, vid ) - __array(char, cell, 24 ) - __array(char, volume, 24 ) + __field(u64, vid) + __array(char, cell, 24) + __array(char, volume, 24) ), =20 TP_fast_assign( @@ -1392,10 +1392,10 @@ TRACE_EVENT(afs_cb_break, TP_ARGS(fid, cb_break, reason, skipped), =20 TP_STRUCT__entry( - __field_struct(struct afs_fid, fid ) - __field(unsigned int, cb_break ) - __field(enum afs_cb_break_reason, reason ) - __field(bool, skipped ) + __field_struct(struct afs_fid, fid) + __field(unsigned int, cb_break) + __field(enum afs_cb_break_reason, reason) + __field(bool, skipped) ), =20 TP_fast_assign( @@ -1418,8 +1418,8 @@ TRACE_EVENT(afs_cb_miss, TP_ARGS(fid, reason), =20 TP_STRUCT__entry( - __field_struct(struct afs_fid, fid ) - __field(enum afs_cb_break_reason, reason ) + __field_struct(struct afs_fid, fid) + __field(enum afs_cb_break_reason, reason) ), =20 TP_fast_assign( @@ -1439,10 +1439,10 @@ TRACE_EVENT(afs_server, TP_ARGS(server_debug_id, ref, active, reason), =20 TP_STRUCT__entry( - __field(unsigned int, server ) - __field(int, ref ) - __field(int, active ) - __field(int, reason ) + __field(unsigned int, server) + __field(int, ref) + __field(int, active) + __field(int, reason) ), =20 TP_fast_assign( @@ -1465,9 +1465,9 @@ TRACE_EVENT(afs_volume, TP_ARGS(vid, ref, reason), =20 TP_STRUCT__entry( - __field(afs_volid_t, vid ) - __field(int, ref ) - __field(enum afs_volume_trace, reason ) + __field(afs_volid_t, vid) + __field(int, ref) + __field(enum afs_volume_trace, reason) ), =20 TP_fast_assign( @@ -1489,10 +1489,10 @@ TRACE_EVENT(afs_cell, TP_ARGS(cell_debug_id, ref, active, reason), =20 TP_STRUCT__entry( - __field(unsigned int, cell ) - __field(int, ref ) - __field(int, active ) - __field(int, reason ) + __field(unsigned int, cell) + __field(int, ref) + __field(int, active) + __field(int, reason) ), =20 TP_fast_assign( From nobody Mon Dec 15 21:24:35 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 88C4EC4332F for ; Wed, 13 Dec 2023 13:50:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379223AbjLMNuV (ORCPT ); Wed, 13 Dec 2023 08:50:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379122AbjLMNuP (ORCPT ); Wed, 13 Dec 2023 08:50:15 -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 ADBF3110 for ; Wed, 13 Dec 2023 05:50:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475420; 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=YLzCXJfM4N3Nxzt33NeDjgrD44Y0SC0g5t67rlILCHA=; b=LENQENNSx132Jwj96hFCC8H0c4MJBudnyuSTIdmHEQwOnGCF/PgJspDvM+kSc/FvVWEa8K 8XPNHPj+7nduJja7wFMybfrd1JITvn9KDnkomTSpifjRNJ6xEAce9WwAQT2GM3B9/bBQZM TDOWhBZj9N7DJjrNVEUS354aNOGKDME= 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-175-RpGSWDVXOciJDjyh_geknw-1; Wed, 13 Dec 2023 08:50:16 -0500 X-MC-Unique: RpGSWDVXOciJDjyh_geknw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 6E75C8828C5; Wed, 13 Dec 2023 13:50:16 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id A39B0492BE6; Wed, 13 Dec 2023 13:50:15 +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 Subject: [PATCH v2 06/40] afs: Automatically generate trace tag enums Date: Wed, 13 Dec 2023 13:49:28 +0000 Message-ID: <20231213135003.367397-7-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Automatically generate trace tag enums from the symbol -> string mapping tables rather than having the enums as well, thereby reducing duplicated data. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- include/trace/events/afs.h | 233 +++++-------------------------------- 1 file changed, 27 insertions(+), 206 deletions(-) diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index cfcd6452c156..597677acc6b1 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -18,97 +18,6 @@ #ifndef __AFS_DECLARE_TRACE_ENUMS_ONCE_ONLY #define __AFS_DECLARE_TRACE_ENUMS_ONCE_ONLY =20 -enum afs_call_trace { - afs_call_trace_alloc, - afs_call_trace_free, - afs_call_trace_get, - afs_call_trace_put, - afs_call_trace_wake, - afs_call_trace_work, -}; - -enum afs_server_trace { - afs_server_trace_alloc, - afs_server_trace_callback, - afs_server_trace_destroy, - afs_server_trace_free, - afs_server_trace_gc, - afs_server_trace_get_by_addr, - afs_server_trace_get_by_uuid, - afs_server_trace_get_caps, - afs_server_trace_get_install, - afs_server_trace_get_new_cbi, - afs_server_trace_get_probe, - afs_server_trace_give_up_cb, - afs_server_trace_purging, - afs_server_trace_put_call, - afs_server_trace_put_cbi, - afs_server_trace_put_find_rsq, - afs_server_trace_put_probe, - afs_server_trace_put_slist, - afs_server_trace_put_slist_isort, - afs_server_trace_put_uuid_rsq, - afs_server_trace_update, -}; - - -enum afs_volume_trace { - afs_volume_trace_alloc, - afs_volume_trace_free, - afs_volume_trace_get_alloc_sbi, - afs_volume_trace_get_cell_insert, - afs_volume_trace_get_new_op, - afs_volume_trace_get_query_alias, - afs_volume_trace_put_cell_dup, - afs_volume_trace_put_cell_root, - afs_volume_trace_put_destroy_sbi, - afs_volume_trace_put_free_fc, - afs_volume_trace_put_put_op, - afs_volume_trace_put_query_alias, - afs_volume_trace_put_validate_fc, - afs_volume_trace_remove, -}; - -enum afs_cell_trace { - afs_cell_trace_alloc, - afs_cell_trace_free, - afs_cell_trace_get_queue_dns, - afs_cell_trace_get_queue_manage, - afs_cell_trace_get_queue_new, - afs_cell_trace_get_vol, - afs_cell_trace_insert, - afs_cell_trace_manage, - afs_cell_trace_put_candidate, - afs_cell_trace_put_destroy, - afs_cell_trace_put_queue_fail, - afs_cell_trace_put_queue_work, - afs_cell_trace_put_vol, - afs_cell_trace_see_source, - afs_cell_trace_see_ws, - afs_cell_trace_unuse_alias, - afs_cell_trace_unuse_check_alias, - afs_cell_trace_unuse_delete, - afs_cell_trace_unuse_fc, - afs_cell_trace_unuse_lookup, - afs_cell_trace_unuse_mntpt, - afs_cell_trace_unuse_no_pin, - afs_cell_trace_unuse_parse, - afs_cell_trace_unuse_pin, - afs_cell_trace_unuse_probe, - afs_cell_trace_unuse_sbi, - afs_cell_trace_unuse_ws, - afs_cell_trace_use_alias, - afs_cell_trace_use_check_alias, - afs_cell_trace_use_fc, - afs_cell_trace_use_fc_alias, - afs_cell_trace_use_lookup, - afs_cell_trace_use_mntpt, - afs_cell_trace_use_pin, - afs_cell_trace_use_probe, - afs_cell_trace_use_sbi, - afs_cell_trace_wait, -}; - enum afs_fs_operation { afs_FS_FetchData =3D 130, /* AFS Fetch file data */ afs_FS_FetchACL =3D 131, /* AFS Fetch file ACL */ @@ -202,121 +111,6 @@ enum yfs_cm_operation { yfs_CB_CallBack =3D 64204, }; =20 -enum afs_edit_dir_op { - afs_edit_dir_create, - afs_edit_dir_create_error, - afs_edit_dir_create_inval, - afs_edit_dir_create_nospc, - afs_edit_dir_delete, - afs_edit_dir_delete_error, - afs_edit_dir_delete_inval, - afs_edit_dir_delete_noent, -}; - -enum afs_edit_dir_reason { - afs_edit_dir_for_create, - afs_edit_dir_for_link, - afs_edit_dir_for_mkdir, - afs_edit_dir_for_rename_0, - afs_edit_dir_for_rename_1, - afs_edit_dir_for_rename_2, - afs_edit_dir_for_rmdir, - afs_edit_dir_for_silly_0, - afs_edit_dir_for_silly_1, - afs_edit_dir_for_symlink, - afs_edit_dir_for_unlink, -}; - -enum afs_eproto_cause { - afs_eproto_bad_status, - afs_eproto_cb_count, - afs_eproto_cb_fid_count, - afs_eproto_cellname_len, - afs_eproto_file_type, - afs_eproto_ibulkst_cb_count, - afs_eproto_ibulkst_count, - afs_eproto_motd_len, - afs_eproto_offline_msg_len, - afs_eproto_volname_len, - afs_eproto_yvl_fsendpt4_len, - afs_eproto_yvl_fsendpt6_len, - afs_eproto_yvl_fsendpt_num, - afs_eproto_yvl_fsendpt_type, - afs_eproto_yvl_vlendpt4_len, - afs_eproto_yvl_vlendpt6_len, - afs_eproto_yvl_vlendpt_type, -}; - -enum afs_io_error { - afs_io_error_cm_reply, - afs_io_error_extract, - afs_io_error_fs_probe_fail, - afs_io_error_vl_lookup_fail, - afs_io_error_vl_probe_fail, -}; - -enum afs_file_error { - afs_file_error_dir_bad_magic, - afs_file_error_dir_big, - afs_file_error_dir_missing_page, - afs_file_error_dir_name_too_long, - afs_file_error_dir_over_end, - afs_file_error_dir_small, - afs_file_error_dir_unmarked_ext, - afs_file_error_mntpt, - afs_file_error_writeback_fail, -}; - -enum afs_flock_event { - afs_flock_acquired, - afs_flock_callback_break, - afs_flock_defer_unlock, - afs_flock_extend_fail, - afs_flock_fail_other, - afs_flock_fail_perm, - afs_flock_no_lockers, - afs_flock_release_fail, - afs_flock_silly_delete, - afs_flock_timestamp, - afs_flock_try_to_lock, - afs_flock_vfs_lock, - afs_flock_vfs_locking, - afs_flock_waited, - afs_flock_waiting, - afs_flock_work_extending, - afs_flock_work_retry, - afs_flock_work_unlocking, - afs_flock_would_block, -}; - -enum afs_flock_operation { - afs_flock_op_copy_lock, - afs_flock_op_flock, - afs_flock_op_grant, - afs_flock_op_lock, - afs_flock_op_release_lock, - afs_flock_op_return_ok, - afs_flock_op_return_eagain, - afs_flock_op_return_edeadlk, - afs_flock_op_return_error, - afs_flock_op_set_lock, - afs_flock_op_unlock, - afs_flock_op_wake, -}; - -enum afs_cb_break_reason { - afs_cb_break_no_break, - afs_cb_break_no_promise, - afs_cb_break_for_callback, - afs_cb_break_for_deleted, - afs_cb_break_for_lapsed, - afs_cb_break_for_s_reinit, - afs_cb_break_for_unlink, - afs_cb_break_for_v_break, - afs_cb_break_for_volume_callback, - afs_cb_break_for_zap, -}; - #endif /* end __AFS_DECLARE_TRACE_ENUMS_ONCE_ONLY */ =20 /* @@ -391,6 +185,7 @@ enum afs_cb_break_reason { EM(afs_cell_trace_unuse_fc, "UNU fc ") \ EM(afs_cell_trace_unuse_lookup, "UNU lookup") \ EM(afs_cell_trace_unuse_mntpt, "UNU mntpt ") \ + EM(afs_cell_trace_unuse_no_pin, "UNU no-pin") \ EM(afs_cell_trace_unuse_parse, "UNU parse ") \ EM(afs_cell_trace_unuse_pin, "UNU pin ") \ EM(afs_cell_trace_unuse_probe, "UNU probe ") \ @@ -614,6 +409,32 @@ enum afs_cb_break_reason { EM(afs_cb_break_for_volume_callback, "break-v-cb") \ E_(afs_cb_break_for_zap, "break-zap") =20 +/* + * Generate enums for tracing information. + */ +#ifndef __AFS_GENERATE_TRACE_ENUMS_ONCE_ONLY +#define __AFS_GENERATE_TRACE_ENUMS_ONCE_ONLY + +#undef EM +#undef E_ +#define EM(a, b) a, +#define E_(a, b) a + +enum afs_call_trace { afs_call_traces } __mode(byte); +enum afs_cb_break_reason { afs_cb_break_reasons } __mode(byte); +enum afs_cell_trace { afs_cell_traces } __mode(byte); +enum afs_edit_dir_op { afs_edit_dir_ops } __mode(byte); +enum afs_edit_dir_reason { afs_edit_dir_reasons } __mode(byte); +enum afs_eproto_cause { afs_eproto_causes } __mode(byte); +enum afs_file_error { afs_file_errors } __mode(byte); +enum afs_flock_event { afs_flock_events } __mode(byte); +enum afs_flock_operation { afs_flock_operations } __mode(byte); +enum afs_io_error { afs_io_errors } __mode(byte); +enum afs_server_trace { afs_server_traces } __mode(byte); +enum afs_volume_trace { afs_volume_traces } __mode(byte); + +#endif /* end __AFS_GENERATE_TRACE_ENUMS_ONCE_ONLY */ + /* * Export enum symbols via userspace. */ From nobody Mon Dec 15 21:24:35 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 5E952C4332F for ; Wed, 13 Dec 2023 13:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379169AbjLMNu1 (ORCPT ); Wed, 13 Dec 2023 08:50:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379131AbjLMNuR (ORCPT ); Wed, 13 Dec 2023 08:50:17 -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 7285DB2 for ; Wed, 13 Dec 2023 05:50:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475421; 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=UGRxelYCarwZFCdsruOcKzXx+k/Lsiw8QpTx9fiIyV8=; b=XcfflpopNYQdMtcKBlR5gkYM/0E2JHIHIyEU2Fn0mNoqPlrXtxXWX+XcewtQgOQSLm3A2O iZ9OVMuMnFwrynFQ3U5mMF02fZJ87VatPx9ltCy27/CYFyZQmUUqTKgTfCBa16m1cF/rU0 zQ8udcs1Dpf9KTGm9U/S6083HY8uqm8= 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-681--tjJTyOvNL-wvKFQeFZxRQ-1; Wed, 13 Dec 2023 08:50:18 -0500 X-MC-Unique: -tjJTyOvNL-wvKFQeFZxRQ-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 F1C7E85A589; Wed, 13 Dec 2023 13:50:17 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17E982166B31; Wed, 13 Dec 2023 13:50:16 +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, Jeffrey E Altman Subject: [PATCH v2 07/40] afs: Add comments on abort handling Date: Wed, 13 Dec 2023 13:49:29 +0000 Message-ID: <20231213135003.367397-8-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add some comments on AFS abort code handling in the rotation algorithm and adjust the errors produced to match. Reported-by: Jeffrey E Altman Signed-off-by: David Howells Reviewed-by: Jeffrey Altman cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/rotate.c | 101 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 11 deletions(-) diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index a840c3588ebb..a3d127953ac6 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -13,6 +13,7 @@ #include #include "internal.h" #include "afs_fs.h" +#include "protocol_uae.h" =20 /* * Begin iteration through a server list, starting with the vnode's last u= sed @@ -143,6 +144,11 @@ bool afs_select_fileserver(struct afs_operation *op) case -ECONNABORTED: /* The far side rejected the operation on some grounds. This * might involve the server being busy or the volume having been moved. + * + * Note that various V* errors should not be sent to a cache manager + * by a fileserver as they should be translated to more modern UAE* + * errors instead. IBM AFS and OpenAFS fileservers, however, do leak + * these abort codes. */ switch (op->ac.abort_code) { case VNOVOL: @@ -150,6 +156,11 @@ bool afs_select_fileserver(struct afs_operation *op) * - May indicate that the VL is wrong - retry once and compare * the results. * - May indicate that the fileserver couldn't attach to the vol. + * - The volume might have been temporarily removed so that it can + * be replaced by a volume restore. "vos" might have ended one + * transaction and has yet to create the next. + * - The volume might not be blessed or might not be in-service + * (administrative action). */ if (op->flags & AFS_OPERATION_VNOVOL) { op->error =3D -EREMOTEIO; @@ -183,16 +194,56 @@ bool afs_select_fileserver(struct afs_operation *op) _leave(" =3D t [vnovol]"); return true; =20 - case VSALVAGE: /* TODO: Should this return an error or iterate? */ case VVOLEXISTS: - case VNOSERVICE: case VONLINE: - case VDISKFULL: - case VOVERQUOTA: - op->error =3D afs_abort_to_error(op->ac.abort_code); + /* These should not be returned from the fileserver. */ + pr_warn("Fileserver returned unexpected abort %d\n", + op->ac.abort_code); + op->error =3D -EREMOTEIO; + goto next_server; + + case VNOSERVICE: + /* Prior to AFS 3.2 VNOSERVICE was returned from the fileserver + * if the volume was neither in-service nor administratively + * blessed. All usage was replaced by VNOVOL because AFS 3.1 and + * earlier cache managers did not handle VNOSERVICE and assumed + * it was the client OSes errno 105. + * + * Starting with OpenAFS 1.4.8 VNOSERVICE was repurposed as the + * fileserver idle dead time error which was sent in place of + * RX_CALL_TIMEOUT (-3). The error was intended to be sent if the + * fileserver took too long to send a reply to the client. + * RX_CALL_TIMEOUT would have caused the cache manager to mark the + * server down whereas VNOSERVICE since AFS 3.2 would cause cache + * manager to temporarily (up to 15 minutes) mark the volume + * instance as unusable. + * + * The idle dead logic resulted in cache inconsistency since a + * state changing call that the cache manager assumed was dead + * could still be processed to completion by the fileserver. This + * logic was removed in OpenAFS 1.8.0 and VNOSERVICE is no longer + * returned. However, many 1.4.8 through 1.6.24 fileservers are + * still in existence. + * + * AuriStorFS fileservers have never returned VNOSERVICE. + * + * VNOSERVICE should be treated as an alias for RX_CALL_TIMEOUT. + */ + case RX_CALL_TIMEOUT: + op->error =3D -ETIMEDOUT; goto next_server; =20 + case VSALVAGING: /* This error should not be leaked to cache managers + * but is from OpenAFS demand attach fileservers. + * It should be treated as an alias for VOFFLINE. + */ + case VSALVAGE: /* VSALVAGE should be treated as a synonym of VOFFLINE */ case VOFFLINE: + /* The volume is in use by the volserver or another volume utility + * for an operation that might alter the contents. The volume is + * expected to come back but it might take a long time (could be + * days). + */ if (!test_and_set_bit(AFS_VOLUME_OFFLINE, &op->volume->flags)) { afs_busy(op->volume, op->ac.abort_code); clear_bit(AFS_VOLUME_BUSY, &op->volume->flags); @@ -207,11 +258,20 @@ bool afs_select_fileserver(struct afs_operation *op) } goto busy; =20 - case VSALVAGING: - case VRESTARTING: + case VRESTARTING: /* The fileserver is either shutting down or starting = up. */ case VBUSY: - /* Retry after going round all the servers unless we - * have a file lock we need to maintain. + /* The volume is in use by the volserver or another volume + * utility for an operation that is not expected to alter the + * contents of the volume. VBUSY does not need to be returned + * for a ROVOL or BACKVOL bound to an ITBusy volserver + * transaction. The fileserver is permitted to continue serving + * content from ROVOLs and BACKVOLs during an ITBusy transaction + * because the content will not change. However, many fileserver + * releases do return VBUSY for ROVOL and BACKVOL instances under + * many circumstances. + * + * Retry after going round all the servers unless we have a file + * lock we need to maintain. */ if (op->flags & AFS_OPERATION_NO_VSLEEP) { op->error =3D -EBUSY; @@ -226,7 +286,7 @@ bool afs_select_fileserver(struct afs_operation *op) if (!afs_sleep_and_retry(op)) goto failed; =20 - /* Retry with same server & address */ + /* Retry with same server & address */ _leave(" =3D t [vbusy]"); return true; } @@ -270,10 +330,29 @@ bool afs_select_fileserver(struct afs_operation *op) =20 goto restart_from_beginning; =20 + case VDISKFULL: + case UAENOSPC: + /* The partition is full. Only applies to RWVOLs. + * Translate locally and return ENOSPC. + * No replicas to failover to. + */ + op->error =3D -ENOSPC; + goto failed_but_online; + + case VOVERQUOTA: + case UAEDQUOT: + /* Volume is full. Only applies to RWVOLs. + * Translate locally and return EDQUOT. + * No replicas to failover to. + */ + op->error =3D -EDQUOT; + goto failed_but_online; + default: + op->error =3D afs_abort_to_error(op->ac.abort_code); + failed_but_online: clear_bit(AFS_VOLUME_OFFLINE, &op->volume->flags); clear_bit(AFS_VOLUME_BUSY, &op->volume->flags); - op->error =3D afs_abort_to_error(op->ac.abort_code); goto failed; } From nobody Mon Dec 15 21:24:35 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 13CDAC3A59D for ; Wed, 13 Dec 2023 13:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379310AbjLMNuc (ORCPT ); Wed, 13 Dec 2023 08:50:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379133AbjLMNuR (ORCPT ); Wed, 13 Dec 2023 08:50:17 -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 8F351FE for ; Wed, 13 Dec 2023 05:50:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475421; 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=B0tMgPFMdZnzElIBiMPEpnzR3lMlt+7NJxrg0/TpAeY=; b=EGzSolqXX2Z1+PnZHK/LS0xlsvuN6/4f6kZp0aeoBs2qOtz+22b7NkSBItXZVBsAYSYS4B q2jpr2SvmuNv75aZivvxNUvrutfnBweyeptpJz4Q5RGD+s8ol2o6vLnZfGcYauRT0T3NQo 2KCs94Xm3aVTh4rFI4CUs8uv7SvJgf0= 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-391-0coyBbAONlKYFqHjiUsGdA-1; Wed, 13 Dec 2023 08:50:20 -0500 X-MC-Unique: 0coyBbAONlKYFqHjiUsGdA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 9F8A9185A785; Wed, 13 Dec 2023 13:50:19 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id B993251E3; Wed, 13 Dec 2023 13:50:18 +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 Subject: [PATCH v2 08/40] afs: Turn the afs_addr_list address array into an array of structs Date: Wed, 13 Dec 2023 13:49:30 +0000 Message-ID: <20231213135003.367397-9-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Turn the afs_addr_list address array into an array of structs, thereby allowing per-address (such as RTT) info to be added. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/addr_list.c | 10 +++++----- fs/afs/fs_probe.c | 6 +++--- fs/afs/internal.h | 6 +++++- fs/afs/proc.c | 4 ++-- fs/afs/rotate.c | 2 +- fs/afs/rxrpc.c | 4 ++-- fs/afs/server.c | 4 ++-- fs/afs/vl_alias.c | 4 ++-- fs/afs/vl_probe.c | 6 +++--- fs/afs/vl_rotate.c | 2 +- 10 files changed, 26 insertions(+), 22 deletions(-) diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index de1ae0bead3b..ac05a59e9d46 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -45,7 +45,7 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, alist->max_addrs =3D nr; =20 for (i =3D 0; i < nr; i++) { - struct sockaddr_rxrpc *srx =3D &alist->addrs[i]; + struct sockaddr_rxrpc *srx =3D &alist->addrs[i].srx; srx->srx_family =3D AF_RXRPC; srx->srx_service =3D service; srx->transport_type =3D SOCK_DGRAM; @@ -281,7 +281,7 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __= be32 xdr, u16 port) return; =20 for (i =3D 0; i < alist->nr_ipv4; i++) { - struct sockaddr_in *a =3D &alist->addrs[i].transport.sin; + struct sockaddr_in *a =3D &alist->addrs[i].srx.transport.sin; u32 a_addr =3D ntohl(a->sin_addr.s_addr); u16 a_port =3D ntohs(a->sin_port); =20 @@ -298,7 +298,7 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __= be32 xdr, u16 port) alist->addrs + i, sizeof(alist->addrs[0]) * (alist->nr_addrs - i)); =20 - srx =3D &alist->addrs[i]; + srx =3D &alist->addrs[i].srx; srx->srx_family =3D AF_RXRPC; srx->transport_type =3D SOCK_DGRAM; srx->transport_len =3D sizeof(srx->transport.sin); @@ -321,7 +321,7 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __= be32 *xdr, u16 port) return; =20 for (i =3D alist->nr_ipv4; i < alist->nr_addrs; i++) { - struct sockaddr_in6 *a =3D &alist->addrs[i].transport.sin6; + struct sockaddr_in6 *a =3D &alist->addrs[i].srx.transport.sin6; u16 a_port =3D ntohs(a->sin6_port); =20 diff =3D memcmp(xdr, &a->sin6_addr, 16); @@ -338,7 +338,7 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __= be32 *xdr, u16 port) alist->addrs + i, sizeof(alist->addrs[0]) * (alist->nr_addrs - i)); =20 - srx =3D &alist->addrs[i]; + srx =3D &alist->addrs[i].srx; srx->srx_family =3D AF_RXRPC; srx->transport_type =3D SOCK_DGRAM; srx->transport_len =3D sizeof(srx->transport.sin6); diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index daaf3810cc92..3dd24842f277 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -153,12 +153,12 @@ void afs_fileserver_probe_result(struct afs_call *cal= l) if (call->service_id =3D=3D YFS_FS_SERVICE) { server->probe.is_yfs =3D true; set_bit(AFS_SERVER_FL_IS_YFS, &server->flags); - alist->addrs[index].srx_service =3D call->service_id; + alist->addrs[index].srx.srx_service =3D call->service_id; } else { server->probe.not_yfs =3D true; if (!server->probe.is_yfs) { clear_bit(AFS_SERVER_FL_IS_YFS, &server->flags); - alist->addrs[index].srx_service =3D call->service_id; + alist->addrs[index].srx.srx_service =3D call->service_id; } cap0 =3D ntohl(call->tmp); if (cap0 & AFS3_VICED_CAPABILITY_64BITFILES) @@ -182,7 +182,7 @@ void afs_fileserver_probe_result(struct afs_call *call) spin_unlock(&server->probe_lock); =20 _debug("probe %pU [%u] %pISpc rtt=3D%u ret=3D%d", - &server->uuid, index, &alist->addrs[index].transport, + &server->uuid, index, &alist->addrs[index].srx.transport, rtt_us, ret); =20 return afs_done_one_fs_probe(call->net, server); diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 7385d62c8cf5..e2adb314ab6a 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -87,7 +87,9 @@ struct afs_addr_list { enum dns_lookup_status status:8; unsigned long failed; /* Mask of addrs that failed locally/ICMP */ unsigned long responded; /* Mask of addrs that responded */ - struct sockaddr_rxrpc addrs[] __counted_by(max_addrs); + struct { + struct sockaddr_rxrpc srx; + } addrs[] __counted_by(max_addrs); #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8)) }; =20 @@ -969,6 +971,8 @@ extern void afs_put_addrlist(struct afs_addr_list *); extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *, const char *, size_t, char, unsigned short, unsigned short); +bool afs_addr_list_same(const struct afs_addr_list *a, + const struct afs_addr_list *b); extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t= *); extern bool afs_iterate_addresses(struct afs_addr_cursor *); extern int afs_end_cursor(struct afs_addr_cursor *); diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 2a0c83d71565..ab9cd986cfd9 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -307,7 +307,7 @@ static int afs_proc_cell_vlservers_show(struct seq_file= *m, void *v) for (i =3D 0; i < alist->nr_addrs; i++) seq_printf(m, " %c %pISpc\n", alist->preferred =3D=3D i ? '>' : '-', - &alist->addrs[i].transport); + &alist->addrs[i].srx.transport); } seq_printf(m, " info: fl=3D%lx rtt=3D%d\n", vlserver->flags, vlserver->rt= t); seq_printf(m, " probe: fl=3D%x e=3D%d ac=3D%d out=3D%d\n", @@ -399,7 +399,7 @@ static int afs_proc_servers_show(struct seq_file *m, vo= id *v) alist->version, alist->responded, alist->failed); for (i =3D 0; i < alist->nr_addrs; i++) seq_printf(m, " [%x] %pISpc%s\n", - i, &alist->addrs[i].transport, + i, &alist->addrs[i].srx.transport, alist->preferred =3D=3D i ? "*" : ""); return 0; } diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index a3d127953ac6..46081e5da6f5 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -488,7 +488,7 @@ bool afs_select_fileserver(struct afs_operation *op) =20 _debug("address [%u] %u/%u %pISp", op->index, op->ac.index, op->ac.alist->nr_addrs, - &op->ac.alist->addrs[op->ac.index].transport); + &op->ac.alist->addrs[op->ac.index].srx.transport); =20 _leave(" =3D t"); return true; diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index d642d06a453b..181317126e43 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -296,7 +296,7 @@ static void afs_notify_end_request_tx(struct sock *sock, */ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_= t gfp) { - struct sockaddr_rxrpc *srx =3D &ac->alist->addrs[ac->index]; + struct sockaddr_rxrpc *srx =3D &ac->alist->addrs[ac->index].srx; struct rxrpc_call *rxcall; struct msghdr msg; struct kvec iov[1]; @@ -461,7 +461,7 @@ static void afs_log_error(struct afs_call *call, s32 re= mote_abort) max =3D m + 1; pr_notice("kAFS: Peer reported %s failure on %s [%pISp]\n", msg, call->type->name, - &call->alist->addrs[call->addr_ix].transport); + &call->alist->addrs[call->addr_ix].srx.transport); } } =20 diff --git a/fs/afs/server.c b/fs/afs/server.c index 0bd2f5ba6900..b8e2d211d4a1 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -43,7 +43,7 @@ struct afs_server *afs_find_server(struct afs_net *net, hlist_for_each_entry_rcu(server, &net->fs_addresses6, addr6_link) { alist =3D rcu_dereference(server->addresses); for (i =3D alist->nr_ipv4; i < alist->nr_addrs; i++) { - b =3D &alist->addrs[i].transport.sin6; + b =3D &alist->addrs[i].srx.transport.sin6; diff =3D ((u16 __force)a->sin6_port - (u16 __force)b->sin6_port); if (diff =3D=3D 0) @@ -59,7 +59,7 @@ struct afs_server *afs_find_server(struct afs_net *net, hlist_for_each_entry_rcu(server, &net->fs_addresses4, addr4_link) { alist =3D rcu_dereference(server->addresses); for (i =3D 0; i < alist->nr_ipv4; i++) { - b =3D &alist->addrs[i].transport.sin; + b =3D &alist->addrs[i].srx.transport.sin; diff =3D ((u16 __force)a->sin_port - (u16 __force)b->sin_port); if (diff =3D=3D 0) diff --git a/fs/afs/vl_alias.c b/fs/afs/vl_alias.c index f04a80e4f5c3..d3c0df70a1a5 100644 --- a/fs/afs/vl_alias.c +++ b/fs/afs/vl_alias.c @@ -94,8 +94,8 @@ static int afs_compare_fs_alists(const struct afs_server = *server_a, lb =3D rcu_dereference(server_b->addresses); =20 while (a < la->nr_addrs && b < lb->nr_addrs) { - const struct sockaddr_rxrpc *srx_a =3D &la->addrs[a]; - const struct sockaddr_rxrpc *srx_b =3D &lb->addrs[b]; + const struct sockaddr_rxrpc *srx_a =3D &la->addrs[a].srx; + const struct sockaddr_rxrpc *srx_b =3D &lb->addrs[b].srx; int diff =3D afs_compare_addrs(srx_a, srx_b); =20 if (diff < 0) { diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c index 58452b86e672..bdd9372e3fb2 100644 --- a/fs/afs/vl_probe.c +++ b/fs/afs/vl_probe.c @@ -106,12 +106,12 @@ void afs_vlserver_probe_result(struct afs_call *call) if (call->service_id =3D=3D YFS_VL_SERVICE) { server->probe.flags |=3D AFS_VLSERVER_PROBE_IS_YFS; set_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags); - alist->addrs[index].srx_service =3D call->service_id; + alist->addrs[index].srx.srx_service =3D call->service_id; } else { server->probe.flags |=3D AFS_VLSERVER_PROBE_NOT_YFS; if (!(server->probe.flags & AFS_VLSERVER_PROBE_IS_YFS)) { clear_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags); - alist->addrs[index].srx_service =3D call->service_id; + alist->addrs[index].srx.srx_service =3D call->service_id; } } =20 @@ -131,7 +131,7 @@ void afs_vlserver_probe_result(struct afs_call *call) spin_unlock(&server->probe_lock); =20 _debug("probe [%u][%u] %pISpc rtt=3D%u ret=3D%d", - server_index, index, &alist->addrs[index].transport, rtt_us, ret); + server_index, index, &alist->addrs[index].srx.transport, rtt_us, r= et); =20 afs_done_one_vl_probe(server, have_result); } diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index eb415ce56360..e52b9d4c8a0a 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -249,7 +249,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) =20 _debug("VL address %d/%d", vc->ac.index, vc->ac.alist->nr_addrs); =20 - _leave(" =3D t %pISpc", &vc->ac.alist->addrs[vc->ac.index].transport); + _leave(" =3D t %pISpc", &vc->ac.alist->addrs[vc->ac.index].srx.transport); return true; =20 next_server: From nobody Mon Dec 15 21:24:35 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 7C44EC4167B for ; Wed, 13 Dec 2023 13:51:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379336AbjLMNvD (ORCPT ); Wed, 13 Dec 2023 08:51:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379318AbjLMNue (ORCPT ); Wed, 13 Dec 2023 08:50:34 -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 CC5DF12C for ; Wed, 13 Dec 2023 05:50:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475427; 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=q6Lp8rfctSKWrF/kxpDTZ66NjpDrrMBQkxfGUgvl4+Q=; b=aBWnsyl6mtir47qPdsKVjsbyNx0UtTvgHeJeRrfdGK15K28t3U1eCe2878XpRBzy0Bhp3g aS676j48zKTHEoGND6Pd5tw9j+kStoLOHi5PduBr6FzKAU7qIRGNXz6qGNdc9Pt3Owckqr qpOKkLl6T2Y3Y9rBD/mOq3YLO0KeHDA= 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-404-CZPYmNY9NO2U5V9dt3ph4A-1; Wed, 13 Dec 2023 08:50:21 -0500 X-MC-Unique: CZPYmNY9NO2U5V9dt3ph4A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 79D423C2A1CD; Wed, 13 Dec 2023 13:50:21 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DA591121306; Wed, 13 Dec 2023 13:50:20 +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 Subject: [PATCH v2 09/40] rxrpc, afs: Allow afs to pin rxrpc_peer objects Date: Wed, 13 Dec 2023 13:49:31 +0000 Message-ID: <20231213135003.367397-10-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Change rxrpc's API such that: (1) A new function, rxrpc_kernel_lookup_peer(), is provided to look up an rxrpc_peer record for a remote address and a corresponding function, rxrpc_kernel_put_peer(), is provided to dispose of it again. (2) When setting up a call, the rxrpc_peer object used during a call is now passed in rather than being set up by rxrpc_connect_call(). For afs, this meenat passing it to rxrpc_kernel_begin_call() rather than the full address (the service ID then has to be passed in as a separate parameter). (3) A new function, rxrpc_kernel_remote_addr(), is added so that afs can get a pointer to the transport address for display purposed, and another, rxrpc_kernel_remote_srx(), to gain a pointer to the full rxrpc address. (4) The function to retrieve the RTT from a call, rxrpc_kernel_get_srtt(), is then altered to take a peer. This now returns the RTT or -1 if there are insufficient samples. (5) Rename rxrpc_kernel_get_peer() to rxrpc_kernel_call_get_peer(). (6) Provide a new function, rxrpc_kernel_get_peer(), to get a ref on a peer the caller already has. This allows the afs filesystem to pin the rxrpc_peer records that it is using, allowing faster lookups and pointer comparisons rather than comparing sockaddr_rxrpc contents. It also makes it easier to get hold of the RTT. The following changes are made to afs: (1) The addr_list struct's addrs[] elements now hold a peer struct pointer and a service ID rather than a sockaddr_rxrpc. (2) When displaying the transport address, rxrpc_kernel_remote_addr() is used. (3) The port arg is removed from afs_alloc_addrlist() since it's always overridden. (4) afs_merge_fs_addr4() and afs_merge_fs_addr6() do peer lookup and may now return an error that must be handled. (5) afs_find_server() now takes a peer pointer to specify the address. (6) afs_find_server(), afs_compare_fs_alists() and afs_merge_fs_addr[46]{} now do peer pointer comparison rather than address comparison. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- Notes: Changes =3D=3D=3D=3D=3D=3D=3D ver #2) - Add a couple of missing symbol exports. fs/afs/addr_list.c | 125 ++++++++++++++++++----------------- fs/afs/cmservice.c | 5 +- fs/afs/fs_probe.c | 11 +-- fs/afs/internal.h | 26 ++++---- fs/afs/proc.c | 9 +-- fs/afs/rotate.c | 6 +- fs/afs/rxrpc.c | 10 +-- fs/afs/server.c | 41 ++---------- fs/afs/vl_alias.c | 55 +-------------- fs/afs/vl_list.c | 15 +++-- fs/afs/vl_probe.c | 12 ++-- fs/afs/vl_rotate.c | 6 +- fs/afs/vlclient.c | 22 ++++-- include/net/af_rxrpc.h | 15 +++-- include/trace/events/rxrpc.h | 3 + net/rxrpc/af_rxrpc.c | 62 ++++++++++++++--- net/rxrpc/ar-internal.h | 2 +- net/rxrpc/call_object.c | 17 ++--- net/rxrpc/peer_object.c | 58 ++++++++++------ net/rxrpc/sendmsg.c | 11 ++- 20 files changed, 273 insertions(+), 238 deletions(-) diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index ac05a59e9d46..519821f5aedc 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -13,26 +13,33 @@ #include "internal.h" #include "afs_fs.h" =20 +static void afs_free_addrlist(struct rcu_head *rcu) +{ + struct afs_addr_list *alist =3D container_of(rcu, struct afs_addr_list, r= cu); + unsigned int i; + + for (i =3D 0; i < alist->nr_addrs; i++) + rxrpc_kernel_put_peer(alist->addrs[i].peer); +} + /* * Release an address list. */ void afs_put_addrlist(struct afs_addr_list *alist) { if (alist && refcount_dec_and_test(&alist->usage)) - kfree_rcu(alist, rcu); + call_rcu(&alist->rcu, afs_free_addrlist); } =20 /* * Allocate an address list. */ -struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, - unsigned short service, - unsigned short port) +struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id) { struct afs_addr_list *alist; unsigned int i; =20 - _enter("%u,%u,%u", nr, service, port); + _enter("%u,%u", nr, service_id); =20 if (nr > AFS_MAX_ADDRESSES) nr =3D AFS_MAX_ADDRESSES; @@ -44,16 +51,8 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, refcount_set(&alist->usage, 1); alist->max_addrs =3D nr; =20 - for (i =3D 0; i < nr; i++) { - struct sockaddr_rxrpc *srx =3D &alist->addrs[i].srx; - srx->srx_family =3D AF_RXRPC; - srx->srx_service =3D service; - srx->transport_type =3D SOCK_DGRAM; - srx->transport_len =3D sizeof(srx->transport.sin6); - srx->transport.sin6.sin6_family =3D AF_INET6; - srx->transport.sin6.sin6_port =3D htons(port); - } - + for (i =3D 0; i < nr; i++) + alist->addrs[i].service_id =3D service_id; return alist; } =20 @@ -126,7 +125,7 @@ struct afs_vlserver_list *afs_parse_text_addrs(struct a= fs_net *net, if (!vllist->servers[0].server) goto error_vl; =20 - alist =3D afs_alloc_addrlist(nr, service, AFS_VL_PORT); + alist =3D afs_alloc_addrlist(nr, service); if (!alist) goto error; =20 @@ -197,9 +196,11 @@ struct afs_vlserver_list *afs_parse_text_addrs(struct = afs_net *net, } =20 if (family =3D=3D AF_INET) - afs_merge_fs_addr4(alist, x[0], xport); + ret =3D afs_merge_fs_addr4(net, alist, x[0], xport); else - afs_merge_fs_addr6(alist, x, xport); + ret =3D afs_merge_fs_addr6(net, alist, x, xport); + if (ret < 0) + goto error; =20 } while (p < end); =20 @@ -271,25 +272,33 @@ struct afs_vlserver_list *afs_dns_query(struct afs_ce= ll *cell, time64_t *_expiry /* * Merge an IPv4 entry into a fileserver address list. */ -void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port) +int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *alist, + __be32 xdr, u16 port) { - struct sockaddr_rxrpc *srx; - u32 addr =3D ntohl(xdr); + struct sockaddr_rxrpc srx; + struct rxrpc_peer *peer; int i; =20 if (alist->nr_addrs >=3D alist->max_addrs) - return; + return 0; =20 - for (i =3D 0; i < alist->nr_ipv4; i++) { - struct sockaddr_in *a =3D &alist->addrs[i].srx.transport.sin; - u32 a_addr =3D ntohl(a->sin_addr.s_addr); - u16 a_port =3D ntohs(a->sin_port); + srx.srx_family =3D AF_RXRPC; + srx.transport_type =3D SOCK_DGRAM; + srx.transport_len =3D sizeof(srx.transport.sin); + srx.transport.sin.sin_family =3D AF_INET; + srx.transport.sin.sin_port =3D htons(port); + srx.transport.sin.sin_addr.s_addr =3D xdr; =20 - if (addr =3D=3D a_addr && port =3D=3D a_port) - return; - if (addr =3D=3D a_addr && port < a_port) - break; - if (addr < a_addr) + peer =3D rxrpc_kernel_lookup_peer(net->socket, &srx, GFP_KERNEL); + if (!peer) + return -ENOMEM; + + for (i =3D 0; i < alist->nr_ipv4; i++) { + if (peer =3D=3D alist->addrs[i].peer) { + rxrpc_kernel_put_peer(peer); + return 0; + } + if (peer <=3D alist->addrs[i].peer) break; } =20 @@ -298,38 +307,42 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, = __be32 xdr, u16 port) alist->addrs + i, sizeof(alist->addrs[0]) * (alist->nr_addrs - i)); =20 - srx =3D &alist->addrs[i].srx; - srx->srx_family =3D AF_RXRPC; - srx->transport_type =3D SOCK_DGRAM; - srx->transport_len =3D sizeof(srx->transport.sin); - srx->transport.sin.sin_family =3D AF_INET; - srx->transport.sin.sin_port =3D htons(port); - srx->transport.sin.sin_addr.s_addr =3D xdr; + alist->addrs[i].peer =3D peer; alist->nr_ipv4++; alist->nr_addrs++; + return 0; } =20 /* * Merge an IPv6 entry into a fileserver address list. */ -void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port) +int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *alist, + __be32 *xdr, u16 port) { - struct sockaddr_rxrpc *srx; - int i, diff; + struct sockaddr_rxrpc srx; + struct rxrpc_peer *peer; + int i; =20 if (alist->nr_addrs >=3D alist->max_addrs) - return; + return 0; =20 - for (i =3D alist->nr_ipv4; i < alist->nr_addrs; i++) { - struct sockaddr_in6 *a =3D &alist->addrs[i].srx.transport.sin6; - u16 a_port =3D ntohs(a->sin6_port); + srx.srx_family =3D AF_RXRPC; + srx.transport_type =3D SOCK_DGRAM; + srx.transport_len =3D sizeof(srx.transport.sin6); + srx.transport.sin6.sin6_family =3D AF_INET6; + srx.transport.sin6.sin6_port =3D htons(port); + memcpy(&srx.transport.sin6.sin6_addr, xdr, 16); =20 - diff =3D memcmp(xdr, &a->sin6_addr, 16); - if (diff =3D=3D 0 && port =3D=3D a_port) - return; - if (diff =3D=3D 0 && port < a_port) - break; - if (diff < 0) + peer =3D rxrpc_kernel_lookup_peer(net->socket, &srx, GFP_KERNEL); + if (!peer) + return -ENOMEM; + + for (i =3D alist->nr_ipv4; i < alist->nr_addrs; i++) { + if (peer =3D=3D alist->addrs[i].peer) { + rxrpc_kernel_put_peer(peer); + return 0; + } + if (peer <=3D alist->addrs[i].peer) break; } =20 @@ -337,15 +350,9 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, _= _be32 *xdr, u16 port) memmove(alist->addrs + i + 1, alist->addrs + i, sizeof(alist->addrs[0]) * (alist->nr_addrs - i)); - - srx =3D &alist->addrs[i].srx; - srx->srx_family =3D AF_RXRPC; - srx->transport_type =3D SOCK_DGRAM; - srx->transport_len =3D sizeof(srx->transport.sin6); - srx->transport.sin6.sin6_family =3D AF_INET6; - srx->transport.sin6.sin6_port =3D htons(port); - memcpy(&srx->transport.sin6.sin6_addr, xdr, 16); + alist->addrs[i].peer =3D peer; alist->nr_addrs++; + return 0; } =20 /* diff --git a/fs/afs/cmservice.c b/fs/afs/cmservice.c index d4ddb20d6732..99a3f20bc786 100644 --- a/fs/afs/cmservice.c +++ b/fs/afs/cmservice.c @@ -146,10 +146,11 @@ static int afs_find_cm_server_by_peer(struct afs_call= *call) { struct sockaddr_rxrpc srx; struct afs_server *server; + struct rxrpc_peer *peer; =20 - rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx); + peer =3D rxrpc_kernel_get_call_peer(call->net->socket, call->rxcall); =20 - server =3D afs_find_server(call->net, &srx); + server =3D afs_find_server(call->net, peer); if (!server) { trace_afs_cm_no_server(call, &srx); return 0; diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index 3dd24842f277..58d28b82571e 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -101,6 +101,7 @@ static void afs_fs_probe_not_done(struct afs_net *net, void afs_fileserver_probe_result(struct afs_call *call) { struct afs_addr_list *alist =3D call->alist; + struct afs_address *addr =3D &alist->addrs[call->addr_ix]; struct afs_server *server =3D call->server; unsigned int index =3D call->addr_ix; unsigned int rtt_us =3D 0, cap0; @@ -153,12 +154,12 @@ void afs_fileserver_probe_result(struct afs_call *cal= l) if (call->service_id =3D=3D YFS_FS_SERVICE) { server->probe.is_yfs =3D true; set_bit(AFS_SERVER_FL_IS_YFS, &server->flags); - alist->addrs[index].srx.srx_service =3D call->service_id; + addr->service_id =3D call->service_id; } else { server->probe.not_yfs =3D true; if (!server->probe.is_yfs) { clear_bit(AFS_SERVER_FL_IS_YFS, &server->flags); - alist->addrs[index].srx.srx_service =3D call->service_id; + addr->service_id =3D call->service_id; } cap0 =3D ntohl(call->tmp); if (cap0 & AFS3_VICED_CAPABILITY_64BITFILES) @@ -167,7 +168,7 @@ void afs_fileserver_probe_result(struct afs_call *call) clear_bit(AFS_SERVER_FL_HAS_FS64, &server->flags); } =20 - rxrpc_kernel_get_srtt(call->net->socket, call->rxcall, &rtt_us); + rtt_us =3D rxrpc_kernel_get_srtt(addr->peer); if (rtt_us < server->probe.rtt) { server->probe.rtt =3D rtt_us; server->rtt =3D rtt_us; @@ -181,8 +182,8 @@ void afs_fileserver_probe_result(struct afs_call *call) out: spin_unlock(&server->probe_lock); =20 - _debug("probe %pU [%u] %pISpc rtt=3D%u ret=3D%d", - &server->uuid, index, &alist->addrs[index].srx.transport, + _debug("probe %pU [%u] %pISpc rtt=3D%d ret=3D%d", + &server->uuid, index, rxrpc_kernel_remote_addr(alist->addrs[index]= .peer), rtt_us, ret); =20 return afs_done_one_fs_probe(call->net, server); diff --git a/fs/afs/internal.h b/fs/afs/internal.h index e2adb314ab6a..ec08b4a7e499 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -72,6 +72,11 @@ enum afs_call_state { AFS_CALL_COMPLETE, /* Completed or failed */ }; =20 +struct afs_address { + struct rxrpc_peer *peer; + u16 service_id; +}; + /* * List of server addresses. */ @@ -87,9 +92,7 @@ struct afs_addr_list { enum dns_lookup_status status:8; unsigned long failed; /* Mask of addrs that failed locally/ICMP */ unsigned long responded; /* Mask of addrs that responded */ - struct { - struct sockaddr_rxrpc srx; - } addrs[] __counted_by(max_addrs); + struct afs_address addrs[] __counted_by(max_addrs); #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8)) }; =20 @@ -420,7 +423,7 @@ struct afs_vlserver { atomic_t probe_outstanding; spinlock_t probe_lock; struct { - unsigned int rtt; /* RTT in uS */ + unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */ u32 abort_code; short error; unsigned short flags; @@ -537,7 +540,7 @@ struct afs_server { atomic_t probe_outstanding; spinlock_t probe_lock; struct { - unsigned int rtt; /* RTT in uS */ + unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */ u32 abort_code; short error; bool responded:1; @@ -964,9 +967,7 @@ static inline struct afs_addr_list *afs_get_addrlist(st= ruct afs_addr_list *alist refcount_inc(&alist->usage); return alist; } -extern struct afs_addr_list *afs_alloc_addrlist(unsigned int, - unsigned short, - unsigned short); +extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 servi= ce_id); extern void afs_put_addrlist(struct afs_addr_list *); extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *, const char *, size_t, char, @@ -977,8 +978,10 @@ extern struct afs_vlserver_list *afs_dns_query(struct = afs_cell *, time64_t *); extern bool afs_iterate_addresses(struct afs_addr_cursor *); extern int afs_end_cursor(struct afs_addr_cursor *); =20 -extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16); -extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16); +extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *a= ddr, + __be32 xdr, u16 port); +extern int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *a= ddr, + __be32 *xdr, u16 port); =20 /* * callback.c @@ -1405,8 +1408,7 @@ extern void __exit afs_clean_up_permit_cache(void); */ extern spinlock_t afs_server_peer_lock; =20 -extern struct afs_server *afs_find_server(struct afs_net *, - const struct sockaddr_rxrpc *); +extern struct afs_server *afs_find_server(struct afs_net *, const struct r= xrpc_peer *); extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const = uuid_t *); extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key = *, const uuid_t *, u32); extern struct afs_server *afs_get_server(struct afs_server *, enum afs_ser= ver_trace); diff --git a/fs/afs/proc.c b/fs/afs/proc.c index ab9cd986cfd9..8a65a06908d2 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -307,7 +307,7 @@ static int afs_proc_cell_vlservers_show(struct seq_file= *m, void *v) for (i =3D 0; i < alist->nr_addrs; i++) seq_printf(m, " %c %pISpc\n", alist->preferred =3D=3D i ? '>' : '-', - &alist->addrs[i].srx.transport); + rxrpc_kernel_remote_addr(alist->addrs[i].peer)); } seq_printf(m, " info: fl=3D%lx rtt=3D%d\n", vlserver->flags, vlserver->rt= t); seq_printf(m, " probe: fl=3D%x e=3D%d ac=3D%d out=3D%d\n", @@ -398,9 +398,10 @@ static int afs_proc_servers_show(struct seq_file *m, v= oid *v) seq_printf(m, " - ALIST v=3D%u rsp=3D%lx f=3D%lx\n", alist->version, alist->responded, alist->failed); for (i =3D 0; i < alist->nr_addrs; i++) - seq_printf(m, " [%x] %pISpc%s\n", - i, &alist->addrs[i].srx.transport, - alist->preferred =3D=3D i ? "*" : ""); + seq_printf(m, " [%x] %pISpc%s rtt=3D%d\n", + i, rxrpc_kernel_remote_addr(alist->addrs[i].peer), + alist->preferred =3D=3D i ? "*" : "", + rxrpc_kernel_get_srtt(alist->addrs[i].peer)); return 0; } =20 diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 46081e5da6f5..59aed7a6dd11 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -113,7 +113,7 @@ bool afs_select_fileserver(struct afs_operation *op) struct afs_server *server; struct afs_vnode *vnode =3D op->file[0].vnode; struct afs_error e; - u32 rtt; + unsigned int rtt; int error =3D op->ac.error, i; =20 _enter("%lx[%d],%lx[%d],%d,%d", @@ -420,7 +420,7 @@ bool afs_select_fileserver(struct afs_operation *op) } =20 op->index =3D -1; - rtt =3D U32_MAX; + rtt =3D UINT_MAX; for (i =3D 0; i < op->server_list->nr_servers; i++) { struct afs_server *s =3D op->server_list->servers[i].server; =20 @@ -488,7 +488,7 @@ bool afs_select_fileserver(struct afs_operation *op) =20 _debug("address [%u] %u/%u %pISp", op->index, op->ac.index, op->ac.alist->nr_addrs, - &op->ac.alist->addrs[op->ac.index].srx.transport); + rxrpc_kernel_remote_addr(op->ac.alist->addrs[op->ac.index].peer)); =20 _leave(" =3D t"); return true; diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index 181317126e43..2603db03b7ff 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -296,7 +296,8 @@ static void afs_notify_end_request_tx(struct sock *sock, */ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_= t gfp) { - struct sockaddr_rxrpc *srx =3D &ac->alist->addrs[ac->index].srx; + struct afs_address *addr =3D &ac->alist->addrs[ac->index]; + struct rxrpc_peer *peer =3D addr->peer; struct rxrpc_call *rxcall; struct msghdr msg; struct kvec iov[1]; @@ -304,7 +305,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) s64 tx_total_len; int ret; =20 - _enter(",{%pISp},", &srx->transport); + _enter(",{%pISp},", rxrpc_kernel_remote_addr(addr->peer)); =20 ASSERT(call->type !=3D NULL); ASSERT(call->type->name !=3D NULL); @@ -333,7 +334,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) } =20 /* create a call */ - rxcall =3D rxrpc_kernel_begin_call(call->net->socket, srx, call->key, + rxcall =3D rxrpc_kernel_begin_call(call->net->socket, peer, call->key, (unsigned long)call, tx_total_len, call->max_lifespan, @@ -341,6 +342,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) (call->async ? afs_wake_up_async_call : afs_wake_up_call_waiter), + addr->service_id, call->upgrade, (call->intr ? RXRPC_PREINTERRUPTIBLE : RXRPC_UNINTERRUPTIBLE), @@ -461,7 +463,7 @@ static void afs_log_error(struct afs_call *call, s32 re= mote_abort) max =3D m + 1; pr_notice("kAFS: Peer reported %s failure on %s [%pISp]\n", msg, call->type->name, - &call->alist->addrs[call->addr_ix].srx.transport); + rxrpc_kernel_remote_addr(call->alist->addrs[call->addr_ix].peer)); } } =20 diff --git a/fs/afs/server.c b/fs/afs/server.c index b8e2d211d4a1..5b5fa94005c9 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -21,13 +21,12 @@ static void __afs_put_server(struct afs_net *, struct a= fs_server *); /* * Find a server by one of its addresses. */ -struct afs_server *afs_find_server(struct afs_net *net, - const struct sockaddr_rxrpc *srx) +struct afs_server *afs_find_server(struct afs_net *net, const struct rxrpc= _peer *peer) { const struct afs_addr_list *alist; struct afs_server *server =3D NULL; unsigned int i; - int seq =3D 1, diff; + int seq =3D 1; =20 rcu_read_lock(); =20 @@ -38,37 +37,11 @@ struct afs_server *afs_find_server(struct afs_net *net, seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&net->fs_addr_lock, &seq); =20 - if (srx->transport.family =3D=3D AF_INET6) { - const struct sockaddr_in6 *a =3D &srx->transport.sin6, *b; - hlist_for_each_entry_rcu(server, &net->fs_addresses6, addr6_link) { - alist =3D rcu_dereference(server->addresses); - for (i =3D alist->nr_ipv4; i < alist->nr_addrs; i++) { - b =3D &alist->addrs[i].srx.transport.sin6; - diff =3D ((u16 __force)a->sin6_port - - (u16 __force)b->sin6_port); - if (diff =3D=3D 0) - diff =3D memcmp(&a->sin6_addr, - &b->sin6_addr, - sizeof(struct in6_addr)); - if (diff =3D=3D 0) - goto found; - } - } - } else { - const struct sockaddr_in *a =3D &srx->transport.sin, *b; - hlist_for_each_entry_rcu(server, &net->fs_addresses4, addr4_link) { - alist =3D rcu_dereference(server->addresses); - for (i =3D 0; i < alist->nr_ipv4; i++) { - b =3D &alist->addrs[i].srx.transport.sin; - diff =3D ((u16 __force)a->sin_port - - (u16 __force)b->sin_port); - if (diff =3D=3D 0) - diff =3D ((u32 __force)a->sin_addr.s_addr - - (u32 __force)b->sin_addr.s_addr); - if (diff =3D=3D 0) - goto found; - } - } + hlist_for_each_entry_rcu(server, &net->fs_addresses6, addr6_link) { + alist =3D rcu_dereference(server->addresses); + for (i =3D 0; i < alist->nr_addrs; i++) + if (alist->addrs[i].peer =3D=3D peer) + goto found; } =20 server =3D NULL; diff --git a/fs/afs/vl_alias.c b/fs/afs/vl_alias.c index d3c0df70a1a5..6fdf9f1bedc0 100644 --- a/fs/afs/vl_alias.c +++ b/fs/afs/vl_alias.c @@ -32,55 +32,6 @@ static struct afs_volume *afs_sample_volume(struct afs_c= ell *cell, struct key *k return volume; } =20 -/* - * Compare two addresses. - */ -static int afs_compare_addrs(const struct sockaddr_rxrpc *srx_a, - const struct sockaddr_rxrpc *srx_b) -{ - short port_a, port_b; - int addr_a, addr_b, diff; - - diff =3D (short)srx_a->transport_type - (short)srx_b->transport_type; - if (diff) - goto out; - - switch (srx_a->transport_type) { - case AF_INET: { - const struct sockaddr_in *a =3D &srx_a->transport.sin; - const struct sockaddr_in *b =3D &srx_b->transport.sin; - addr_a =3D ntohl(a->sin_addr.s_addr); - addr_b =3D ntohl(b->sin_addr.s_addr); - diff =3D addr_a - addr_b; - if (diff =3D=3D 0) { - port_a =3D ntohs(a->sin_port); - port_b =3D ntohs(b->sin_port); - diff =3D port_a - port_b; - } - break; - } - - case AF_INET6: { - const struct sockaddr_in6 *a =3D &srx_a->transport.sin6; - const struct sockaddr_in6 *b =3D &srx_b->transport.sin6; - diff =3D memcmp(&a->sin6_addr, &b->sin6_addr, 16); - if (diff =3D=3D 0) { - port_a =3D ntohs(a->sin6_port); - port_b =3D ntohs(b->sin6_port); - diff =3D port_a - port_b; - } - break; - } - - default: - WARN_ON(1); - diff =3D 1; - } - -out: - return diff; -} - /* * Compare the address lists of a pair of fileservers. */ @@ -94,9 +45,9 @@ static int afs_compare_fs_alists(const struct afs_server = *server_a, lb =3D rcu_dereference(server_b->addresses); =20 while (a < la->nr_addrs && b < lb->nr_addrs) { - const struct sockaddr_rxrpc *srx_a =3D &la->addrs[a].srx; - const struct sockaddr_rxrpc *srx_b =3D &lb->addrs[b].srx; - int diff =3D afs_compare_addrs(srx_a, srx_b); + unsigned long pa =3D (unsigned long)la->addrs[a].peer; + unsigned long pb =3D (unsigned long)lb->addrs[b].peer; + long diff =3D pa - pb; =20 if (diff < 0) { a++; diff --git a/fs/afs/vl_list.c b/fs/afs/vl_list.c index acc48216136a..ba89140eee9e 100644 --- a/fs/afs/vl_list.c +++ b/fs/afs/vl_list.c @@ -83,14 +83,15 @@ static u16 afs_extract_le16(const u8 **_b) /* * Build a VL server address list from a DNS queried server list. */ -static struct afs_addr_list *afs_extract_vl_addrs(const u8 **_b, const u8 = *end, +static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net, + const u8 **_b, const u8 *end, u8 nr_addrs, u16 port) { struct afs_addr_list *alist; const u8 *b =3D *_b; int ret =3D -EINVAL; =20 - alist =3D afs_alloc_addrlist(nr_addrs, VL_SERVICE, port); + alist =3D afs_alloc_addrlist(nr_addrs, VL_SERVICE); if (!alist) return ERR_PTR(-ENOMEM); if (nr_addrs =3D=3D 0) @@ -109,7 +110,9 @@ static struct afs_addr_list *afs_extract_vl_addrs(const= u8 **_b, const u8 *end, goto error; } memcpy(x, b, 4); - afs_merge_fs_addr4(alist, x[0], port); + ret =3D afs_merge_fs_addr4(net, alist, x[0], port); + if (ret < 0) + goto error; b +=3D 4; break; =20 @@ -119,7 +122,9 @@ static struct afs_addr_list *afs_extract_vl_addrs(const= u8 **_b, const u8 *end, goto error; } memcpy(x, b, 16); - afs_merge_fs_addr6(alist, x, port); + ret =3D afs_merge_fs_addr6(net, alist, x, port); + if (ret < 0) + goto error; b +=3D 16; break; =20 @@ -247,7 +252,7 @@ struct afs_vlserver_list *afs_extract_vlserver_list(str= uct afs_cell *cell, /* Extract the addresses - note that we can't skip this as we * have to advance the payload pointer. */ - addrs =3D afs_extract_vl_addrs(&b, end, bs.nr_addrs, bs.port); + addrs =3D afs_extract_vl_addrs(cell->net, &b, end, bs.nr_addrs, bs.port); if (IS_ERR(addrs)) { ret =3D PTR_ERR(addrs); goto error_2; diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c index bdd9372e3fb2..9551aef07cee 100644 --- a/fs/afs/vl_probe.c +++ b/fs/afs/vl_probe.c @@ -48,6 +48,7 @@ void afs_vlserver_probe_result(struct afs_call *call) { struct afs_addr_list *alist =3D call->alist; struct afs_vlserver *server =3D call->vlserver; + struct afs_address *addr =3D &alist->addrs[call->addr_ix]; unsigned int server_index =3D call->server_index; unsigned int rtt_us =3D 0; unsigned int index =3D call->addr_ix; @@ -106,16 +107,16 @@ void afs_vlserver_probe_result(struct afs_call *call) if (call->service_id =3D=3D YFS_VL_SERVICE) { server->probe.flags |=3D AFS_VLSERVER_PROBE_IS_YFS; set_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags); - alist->addrs[index].srx.srx_service =3D call->service_id; + addr->service_id =3D call->service_id; } else { server->probe.flags |=3D AFS_VLSERVER_PROBE_NOT_YFS; if (!(server->probe.flags & AFS_VLSERVER_PROBE_IS_YFS)) { clear_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags); - alist->addrs[index].srx.srx_service =3D call->service_id; + addr->service_id =3D call->service_id; } } =20 - rxrpc_kernel_get_srtt(call->net->socket, call->rxcall, &rtt_us); + rtt_us =3D rxrpc_kernel_get_srtt(addr->peer); if (rtt_us < server->probe.rtt) { server->probe.rtt =3D rtt_us; server->rtt =3D rtt_us; @@ -130,8 +131,9 @@ void afs_vlserver_probe_result(struct afs_call *call) out: spin_unlock(&server->probe_lock); =20 - _debug("probe [%u][%u] %pISpc rtt=3D%u ret=3D%d", - server_index, index, &alist->addrs[index].srx.transport, rtt_us, r= et); + _debug("probe [%u][%u] %pISpc rtt=3D%d ret=3D%d", + server_index, index, rxrpc_kernel_remote_addr(addr->peer), + rtt_us, ret); =20 afs_done_one_vl_probe(server, have_result); } diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index e52b9d4c8a0a..f8f255c966ae 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -92,7 +92,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) struct afs_addr_list *alist; struct afs_vlserver *vlserver; struct afs_error e; - u32 rtt; + unsigned int rtt; int error =3D vc->ac.error, i; =20 _enter("%lx[%d],%lx[%d],%d,%d", @@ -194,7 +194,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) goto selected_server; =20 vc->index =3D -1; - rtt =3D U32_MAX; + rtt =3D UINT_MAX; for (i =3D 0; i < vc->server_list->nr_servers; i++) { struct afs_vlserver *s =3D vc->server_list->servers[i].server; =20 @@ -249,7 +249,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) =20 _debug("VL address %d/%d", vc->ac.index, vc->ac.alist->nr_addrs); =20 - _leave(" =3D t %pISpc", &vc->ac.alist->addrs[vc->ac.index].srx.transport); + _leave(" =3D t %pISpc", rxrpc_kernel_remote_addr(vc->ac.alist->addrs[vc->= ac.index].peer)); return true; =20 next_server: diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index 00fca3c66ba6..41e7932d75c6 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -208,7 +208,7 @@ static int afs_deliver_vl_get_addrs_u(struct afs_call *= call) count =3D ntohl(*bp); =20 nentries =3D min(nentries, count); - alist =3D afs_alloc_addrlist(nentries, FS_SERVICE, AFS_FS_PORT); + alist =3D afs_alloc_addrlist(nentries, FS_SERVICE); if (!alist) return -ENOMEM; alist->version =3D uniquifier; @@ -230,9 +230,13 @@ static int afs_deliver_vl_get_addrs_u(struct afs_call = *call) alist =3D call->ret_alist; bp =3D call->buffer; count =3D min(call->count, 4U); - for (i =3D 0; i < count; i++) - if (alist->nr_addrs < call->count2) - afs_merge_fs_addr4(alist, *bp++, AFS_FS_PORT); + for (i =3D 0; i < count; i++) { + if (alist->nr_addrs < call->count2) { + ret =3D afs_merge_fs_addr4(call->net, alist, *bp++, AFS_FS_PORT); + if (ret < 0) + return ret; + } + } =20 call->count -=3D count; if (call->count > 0) @@ -450,7 +454,7 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_c= all *call) if (call->count > YFS_MAXENDPOINTS) return afs_protocol_error(call, afs_eproto_yvl_fsendpt_num); =20 - alist =3D afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT); + alist =3D afs_alloc_addrlist(call->count, FS_SERVICE); if (!alist) return -ENOMEM; alist->version =3D uniquifier; @@ -488,14 +492,18 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs= _call *call) if (ntohl(bp[0]) !=3D sizeof(__be32) * 2) return afs_protocol_error( call, afs_eproto_yvl_fsendpt4_len); - afs_merge_fs_addr4(alist, bp[1], ntohl(bp[2])); + ret =3D afs_merge_fs_addr4(call->net, alist, bp[1], ntohl(bp[2])); + if (ret < 0) + return ret; bp +=3D 3; break; case YFS_ENDPOINT_IPV6: if (ntohl(bp[0]) !=3D sizeof(__be32) * 5) return afs_protocol_error( call, afs_eproto_yvl_fsendpt6_len); - afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5])); + ret =3D afs_merge_fs_addr6(call->net, alist, bp + 1, ntohl(bp[5])); + if (ret < 0) + return ret; bp +=3D 6; break; default: diff --git a/include/net/af_rxrpc.h b/include/net/af_rxrpc.h index 5531dd08061e..0754c463224a 100644 --- a/include/net/af_rxrpc.h +++ b/include/net/af_rxrpc.h @@ -15,6 +15,7 @@ struct key; struct sock; struct socket; struct rxrpc_call; +struct rxrpc_peer; enum rxrpc_abort_reason; =20 enum rxrpc_interruptibility { @@ -41,13 +42,14 @@ void rxrpc_kernel_new_call_notification(struct socket *, rxrpc_notify_new_call_t, rxrpc_discard_new_call_t); struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, - struct sockaddr_rxrpc *srx, + struct rxrpc_peer *peer, struct key *key, unsigned long user_call_ID, s64 tx_total_len, u32 hard_timeout, gfp_t gfp, rxrpc_notify_rx_t notify_rx, + u16 service_id, bool upgrade, enum rxrpc_interruptibility interruptibility, unsigned int debug_id); @@ -60,9 +62,14 @@ bool rxrpc_kernel_abort_call(struct socket *, struct rxr= pc_call *, u32, int, enum rxrpc_abort_reason); void rxrpc_kernel_shutdown_call(struct socket *sock, struct rxrpc_call *ca= ll); void rxrpc_kernel_put_call(struct socket *sock, struct rxrpc_call *call); -void rxrpc_kernel_get_peer(struct socket *, struct rxrpc_call *, - struct sockaddr_rxrpc *); -bool rxrpc_kernel_get_srtt(struct socket *, struct rxrpc_call *, u32 *); +struct rxrpc_peer *rxrpc_kernel_lookup_peer(struct socket *sock, + struct sockaddr_rxrpc *srx, gfp_t gfp); +void rxrpc_kernel_put_peer(struct rxrpc_peer *peer); +struct rxrpc_peer *rxrpc_kernel_get_peer(struct rxrpc_peer *peer); +struct rxrpc_peer *rxrpc_kernel_get_call_peer(struct socket *sock, struct = rxrpc_call *call); +const struct sockaddr_rxrpc *rxrpc_kernel_remote_srx(const struct rxrpc_pe= er *peer); +const struct sockaddr *rxrpc_kernel_remote_addr(const struct rxrpc_peer *p= eer); +unsigned int rxrpc_kernel_get_srtt(const struct rxrpc_peer *); int rxrpc_kernel_charge_accept(struct socket *, rxrpc_notify_rx_t, rxrpc_user_attach_call_t, unsigned long, gfp_t, unsigned int); diff --git a/include/trace/events/rxrpc.h b/include/trace/events/rxrpc.h index f7e537f64db4..4c1ef7b3705c 100644 --- a/include/trace/events/rxrpc.h +++ b/include/trace/events/rxrpc.h @@ -178,7 +178,9 @@ #define rxrpc_peer_traces \ EM(rxrpc_peer_free, "FREE ") \ EM(rxrpc_peer_get_accept, "GET accept ") \ + EM(rxrpc_peer_get_application, "GET app ") \ EM(rxrpc_peer_get_bundle, "GET bundle ") \ + EM(rxrpc_peer_get_call, "GET call ") \ EM(rxrpc_peer_get_client_conn, "GET cln-conn") \ EM(rxrpc_peer_get_input, "GET input ") \ EM(rxrpc_peer_get_input_error, "GET inpt-err") \ @@ -187,6 +189,7 @@ EM(rxrpc_peer_get_service_conn, "GET srv-conn") \ EM(rxrpc_peer_new_client, "NEW client ") \ EM(rxrpc_peer_new_prealloc, "NEW prealloc") \ + EM(rxrpc_peer_put_application, "PUT app ") \ EM(rxrpc_peer_put_bundle, "PUT bundle ") \ EM(rxrpc_peer_put_call, "PUT call ") \ EM(rxrpc_peer_put_conn, "PUT conn ") \ diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c index fa8aec78f63d..465bfe5eb061 100644 --- a/net/rxrpc/af_rxrpc.c +++ b/net/rxrpc/af_rxrpc.c @@ -258,16 +258,62 @@ static int rxrpc_listen(struct socket *sock, int back= log) return ret; } =20 +/** + * rxrpc_kernel_lookup_peer - Obtain remote transport endpoint for an addr= ess + * @sock: The socket through which it will be accessed + * @srx: The network address + * @gfp: Allocation flags + * + * Lookup or create a remote transport endpoint record for the specified + * address and return it with a ref held. + */ +struct rxrpc_peer *rxrpc_kernel_lookup_peer(struct socket *sock, + struct sockaddr_rxrpc *srx, gfp_t gfp) +{ + struct rxrpc_sock *rx =3D rxrpc_sk(sock->sk); + int ret; + + ret =3D rxrpc_validate_address(rx, srx, sizeof(*srx)); + if (ret < 0) + return ERR_PTR(ret); + + return rxrpc_lookup_peer(rx->local, srx, gfp); +} +EXPORT_SYMBOL(rxrpc_kernel_lookup_peer); + +/** + * rxrpc_kernel_get_peer - Get a reference on a peer + * @peer: The peer to get a reference on. + * + * Get a record for the remote peer in a call. + */ +struct rxrpc_peer *rxrpc_kernel_get_peer(struct rxrpc_peer *peer) +{ + return peer ? rxrpc_get_peer(peer, rxrpc_peer_get_application) : NULL; +} +EXPORT_SYMBOL(rxrpc_kernel_get_peer); + +/** + * rxrpc_kernel_put_peer - Allow a kernel app to drop a peer reference + * @peer: The peer to drop a ref on + */ +void rxrpc_kernel_put_peer(struct rxrpc_peer *peer) +{ + rxrpc_put_peer(peer, rxrpc_peer_put_application); +} +EXPORT_SYMBOL(rxrpc_kernel_put_peer); + /** * rxrpc_kernel_begin_call - Allow a kernel service to begin a call * @sock: The socket on which to make the call - * @srx: The address of the peer to contact + * @peer: The peer to contact * @key: The security context to use (defaults to socket setting) * @user_call_ID: The ID to use * @tx_total_len: Total length of data to transmit during the call (or -1) * @hard_timeout: The maximum lifespan of the call in sec * @gfp: The allocation constraints * @notify_rx: Where to send notifications instead of socket queue + * @service_id: The ID of the service to contact * @upgrade: Request service upgrade for call * @interruptibility: The call is interruptible, or can be canceled. * @debug_id: The debug ID for tracing to be assigned to the call @@ -280,13 +326,14 @@ static int rxrpc_listen(struct socket *sock, int back= log) * supplying @srx and @key. */ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, - struct sockaddr_rxrpc *srx, + struct rxrpc_peer *peer, struct key *key, unsigned long user_call_ID, s64 tx_total_len, u32 hard_timeout, gfp_t gfp, rxrpc_notify_rx_t notify_rx, + u16 service_id, bool upgrade, enum rxrpc_interruptibility interruptibility, unsigned int debug_id) @@ -295,13 +342,11 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct soc= ket *sock, struct rxrpc_call_params p; struct rxrpc_call *call; struct rxrpc_sock *rx =3D rxrpc_sk(sock->sk); - int ret; =20 _enter(",,%x,%lx", key_serial(key), user_call_ID); =20 - ret =3D rxrpc_validate_address(rx, srx, sizeof(*srx)); - if (ret < 0) - return ERR_PTR(ret); + if (WARN_ON_ONCE(peer->local !=3D rx->local)) + return ERR_PTR(-EIO); =20 lock_sock(&rx->sk); =20 @@ -319,12 +364,13 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct soc= ket *sock, =20 memset(&cp, 0, sizeof(cp)); cp.local =3D rx->local; + cp.peer =3D peer; cp.key =3D key; cp.security_level =3D rx->min_sec_level; cp.exclusive =3D false; cp.upgrade =3D upgrade; - cp.service_id =3D srx->srx_service; - call =3D rxrpc_new_client_call(rx, &cp, srx, &p, gfp, debug_id); + cp.service_id =3D service_id; + call =3D rxrpc_new_client_call(rx, &cp, &p, gfp, debug_id); /* The socket has been unlocked. */ if (!IS_ERR(call)) { call->notify_rx =3D notify_rx; diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h index e8e14c6f904d..8eea7a487380 100644 --- a/net/rxrpc/ar-internal.h +++ b/net/rxrpc/ar-internal.h @@ -364,6 +364,7 @@ struct rxrpc_conn_proto { =20 struct rxrpc_conn_parameters { struct rxrpc_local *local; /* Representation of local endpoint */ + struct rxrpc_peer *peer; /* Representation of remote endpoint */ struct key *key; /* Security details */ bool exclusive; /* T if conn is exclusive */ bool upgrade; /* T if service ID can be upgraded */ @@ -867,7 +868,6 @@ struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rx= rpc_sock *, unsigned long struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned i= nt); struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, struct rxrpc_conn_parameters *, - struct sockaddr_rxrpc *, struct rxrpc_call_params *, gfp_t, unsigned int); void rxrpc_start_call_timer(struct rxrpc_call *call); diff --git a/net/rxrpc/call_object.c b/net/rxrpc/call_object.c index 773eecd1e979..beea25ac88f5 100644 --- a/net/rxrpc/call_object.c +++ b/net/rxrpc/call_object.c @@ -193,7 +193,6 @@ struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *= rx, gfp_t gfp, * Allocate a new client call. */ static struct rxrpc_call *rxrpc_alloc_client_call(struct rxrpc_sock *rx, - struct sockaddr_rxrpc *srx, struct rxrpc_conn_parameters *cp, struct rxrpc_call_params *p, gfp_t gfp, @@ -211,10 +210,12 @@ static struct rxrpc_call *rxrpc_alloc_client_call(str= uct rxrpc_sock *rx, now =3D ktime_get_real(); call->acks_latest_ts =3D now; call->cong_tstamp =3D now; - call->dest_srx =3D *srx; + call->dest_srx =3D cp->peer->srx; + call->dest_srx.srx_service =3D cp->service_id; call->interruptibility =3D p->interruptibility; call->tx_total_len =3D p->tx_total_len; call->key =3D key_get(cp->key); + call->peer =3D rxrpc_get_peer(cp->peer, rxrpc_peer_get_call); call->local =3D rxrpc_get_local(cp->local, rxrpc_local_get_call); call->security_level =3D cp->security_level; if (p->kernel) @@ -306,10 +307,6 @@ static int rxrpc_connect_call(struct rxrpc_call *call,= gfp_t gfp) =20 _enter("{%d,%lx},", call->debug_id, call->user_call_ID); =20 - call->peer =3D rxrpc_lookup_peer(local, &call->dest_srx, gfp); - if (!call->peer) - goto error; - ret =3D rxrpc_look_up_bundle(call, gfp); if (ret < 0) goto error; @@ -334,7 +331,6 @@ static int rxrpc_connect_call(struct rxrpc_call *call, = gfp_t gfp) */ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx, struct rxrpc_conn_parameters *cp, - struct sockaddr_rxrpc *srx, struct rxrpc_call_params *p, gfp_t gfp, unsigned int debug_id) @@ -349,13 +345,18 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc= _sock *rx, =20 _enter("%p,%lx", rx, p->user_call_ID); =20 + if (WARN_ON_ONCE(!cp->peer)) { + release_sock(&rx->sk); + return ERR_PTR(-EIO); + } + limiter =3D rxrpc_get_call_slot(p, gfp); if (!limiter) { release_sock(&rx->sk); return ERR_PTR(-ERESTARTSYS); } =20 - call =3D rxrpc_alloc_client_call(rx, srx, cp, p, gfp, debug_id); + call =3D rxrpc_alloc_client_call(rx, cp, p, gfp, debug_id); if (IS_ERR(call)) { release_sock(&rx->sk); up(limiter); diff --git a/net/rxrpc/peer_object.c b/net/rxrpc/peer_object.c index 8d7a715a0bb1..49dcda67a0d5 100644 --- a/net/rxrpc/peer_object.c +++ b/net/rxrpc/peer_object.c @@ -22,6 +22,8 @@ #include #include "ar-internal.h" =20 +static const struct sockaddr_rxrpc rxrpc_null_addr; + /* * Hash a peer key. */ @@ -457,39 +459,53 @@ void rxrpc_destroy_all_peers(struct rxrpc_net *rxnet) } =20 /** - * rxrpc_kernel_get_peer - Get the peer address of a call + * rxrpc_kernel_get_call_peer - Get the peer address of a call * @sock: The socket on which the call is in progress. * @call: The call to query - * @_srx: Where to place the result * - * Get the address of the remote peer in a call. + * Get a record for the remote peer in a call. */ -void rxrpc_kernel_get_peer(struct socket *sock, struct rxrpc_call *call, - struct sockaddr_rxrpc *_srx) +struct rxrpc_peer *rxrpc_kernel_get_call_peer(struct socket *sock, struct = rxrpc_call *call) { - *_srx =3D call->peer->srx; + return call->peer; } -EXPORT_SYMBOL(rxrpc_kernel_get_peer); +EXPORT_SYMBOL(rxrpc_kernel_get_call_peer); =20 /** * rxrpc_kernel_get_srtt - Get a call's peer smoothed RTT - * @sock: The socket on which the call is in progress. - * @call: The call to query - * @_srtt: Where to store the SRTT value. + * @peer: The peer to query * - * Get the call's peer smoothed RTT in uS. + * Get the call's peer smoothed RTT in uS or UINT_MAX if we have no sample= s. */ -bool rxrpc_kernel_get_srtt(struct socket *sock, struct rxrpc_call *call, - u32 *_srtt) +unsigned int rxrpc_kernel_get_srtt(const struct rxrpc_peer *peer) { - struct rxrpc_peer *peer =3D call->peer; + return peer->rtt_count > 0 ? peer->srtt_us >> 3 : UINT_MAX; +} +EXPORT_SYMBOL(rxrpc_kernel_get_srtt); =20 - if (peer->rtt_count =3D=3D 0) { - *_srtt =3D 1000000; /* 1S */ - return false; - } +/** + * rxrpc_kernel_remote_srx - Get the address of a peer + * @peer: The peer to query + * + * Get a pointer to the address from a peer record. The caller is respons= ible + * for making sure that the address is not deallocated. + */ +const struct sockaddr_rxrpc *rxrpc_kernel_remote_srx(const struct rxrpc_pe= er *peer) +{ + return peer ? &peer->srx : &rxrpc_null_addr; +} +EXPORT_SYMBOL(rxrpc_kernel_remote_srx); =20 - *_srtt =3D call->peer->srtt_us >> 3; - return true; +/** + * rxrpc_kernel_remote_addr - Get the peer transport address of a call + * @peer: The peer to query + * + * Get a pointer to the transport address from a peer record. The caller = is + * responsible for making sure that the address is not deallocated. + */ +const struct sockaddr *rxrpc_kernel_remote_addr(const struct rxrpc_peer *p= eer) +{ + return (const struct sockaddr *) + (peer ? &peer->srx.transport : &rxrpc_null_addr.transport); } -EXPORT_SYMBOL(rxrpc_kernel_get_srtt); +EXPORT_SYMBOL(rxrpc_kernel_remote_addr); diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c index 8e0b94714e84..5677d5690a02 100644 --- a/net/rxrpc/sendmsg.c +++ b/net/rxrpc/sendmsg.c @@ -572,6 +572,7 @@ rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx= , struct msghdr *msg, __acquires(&call->user_mutex) { struct rxrpc_conn_parameters cp; + struct rxrpc_peer *peer; struct rxrpc_call *call; struct key *key; =20 @@ -584,21 +585,29 @@ rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *= rx, struct msghdr *msg, return ERR_PTR(-EDESTADDRREQ); } =20 + peer =3D rxrpc_lookup_peer(rx->local, srx, GFP_KERNEL); + if (!peer) { + release_sock(&rx->sk); + return ERR_PTR(-ENOMEM); + } + key =3D rx->key; if (key && !rx->key->payload.data[0]) key =3D NULL; =20 memset(&cp, 0, sizeof(cp)); cp.local =3D rx->local; + cp.peer =3D peer; cp.key =3D rx->key; cp.security_level =3D rx->min_sec_level; cp.exclusive =3D rx->exclusive | p->exclusive; cp.upgrade =3D p->upgrade; cp.service_id =3D srx->srx_service; - call =3D rxrpc_new_client_call(rx, &cp, srx, &p->call, GFP_KERNEL, + call =3D rxrpc_new_client_call(rx, &cp, &p->call, GFP_KERNEL, atomic_inc_return(&rxrpc_debug_id)); /* The socket is now unlocked */ =20 + rxrpc_put_peer(peer, rxrpc_peer_put_application); _leave(" =3D %p\n", call); return call; } From nobody Mon Dec 15 21:24:35 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 E5831C4332F for ; Wed, 13 Dec 2023 13:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378970AbjLMNue (ORCPT ); Wed, 13 Dec 2023 08:50:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379265AbjLMNuX (ORCPT ); Wed, 13 Dec 2023 08:50:23 -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 DB310123 for ; Wed, 13 Dec 2023 05:50:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475426; 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=mwRJi2sCnG34wTz+6X85LZ5bO1xW/kuUkUV8gU/er0M=; b=GDKZcq/Ab4e3r6Bon3L+1dcaDDxJOKrj9c3FgI9WgIFapDGFJFIBIXX/zy3pKDBHd6dyF3 qwhzNlMSDPSeKFTxpT4acu0lvJ0leMem7o55t+G5JtHzgjYLxn/lzIoueabwFq40RtW8vx UFClue8rvMAcs7DxIggiiHe9ZsT8LSg= 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-325-cfUhRadEPFaaBvS2RUXciA-1; Wed, 13 Dec 2023 08:50:23 -0500 X-MC-Unique: cfUhRadEPFaaBvS2RUXciA-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 E4C068C46C2; Wed, 13 Dec 2023 13:50:22 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 278D72166B32; Wed, 13 Dec 2023 13:50:22 +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 Subject: [PATCH v2 10/40] afs: Don't skip server addresses for which we didn't get an RTT reading Date: Wed, 13 Dec 2023 13:49:32 +0000 Message-ID: <20231213135003.367397-11-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In the rotation algorithms for iterating over volume location servers and file servers, don't skip servers from which we got a valid response to a probe (either a reply DATA packet or an ABORT) even if we didn't manage to get an RTT reading. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/rotate.c | 2 +- fs/afs/vl_rotate.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 59aed7a6dd11..d420f073300b 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -427,7 +427,7 @@ bool afs_select_fileserver(struct afs_operation *op) if (!test_bit(i, &op->untried) || !test_bit(AFS_SERVER_FL_RESPONDING, &s->flags)) continue; - if (s->probe.rtt < rtt) { + if (s->probe.rtt <=3D rtt) { op->index =3D i; rtt =3D s->probe.rtt; } diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index f8f255c966ae..6aaa2e4733ec 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -201,7 +201,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) if (!test_bit(i, &vc->untried) || !test_bit(AFS_VLSERVER_FL_RESPONDING, &s->flags)) continue; - if (s->probe.rtt < rtt) { + if (s->probe.rtt <=3D rtt) { vc->index =3D i; rtt =3D s->probe.rtt; } From nobody Mon Dec 15 21:24:35 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 20B6FC4332F for ; Wed, 13 Dec 2023 13:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379265AbjLMNu4 (ORCPT ); Wed, 13 Dec 2023 08:50:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379296AbjLMNu1 (ORCPT ); Wed, 13 Dec 2023 08:50:27 -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 EE43F12E for ; Wed, 13 Dec 2023 05:50:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475428; 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=qxgWR+mMYbB63/GJ7cX9lmHqi8FmxBI8cumRvvcON7M=; b=ikFfrvJXIud+W7ULyRBoJ+OZEm/tdMeHMFwErncWicORdhfJvc08iJ5yGnGES8i6R338WQ HWp5gMO6Ud7QAz9FyTbVrJ1PX9YWd2wcfw0grtlFB7IVXbDX0DDa2s8376gT7mjhUGHuqx RcmlMjYwaEIn5H7TkqGt++wLGwv5cMQ= 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-477-uwecFDqTPsqsUgmHTmYwMA-1; Wed, 13 Dec 2023 08:50:24 -0500 X-MC-Unique: uwecFDqTPsqsUgmHTmYwMA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 56D5E101CC6B; Wed, 13 Dec 2023 13:50:24 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D43651E3; Wed, 13 Dec 2023 13:50:23 +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 Subject: [PATCH v2 11/40] afs: Rename addr_list::failed to probe_failed Date: Wed, 13 Dec 2023 13:49:33 +0000 Message-ID: <20231213135003.367397-12-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rename the failed member of struct addr_list to probe_failed as it's specifically related to probe failures. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/addr_list.c | 2 +- fs/afs/fs_probe.c | 6 +++--- fs/afs/internal.h | 2 +- fs/afs/proc.c | 2 +- fs/afs/rotate.c | 2 +- fs/afs/vl_probe.c | 4 ++-- fs/afs/vl_rotate.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index 519821f5aedc..b76abf500713 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -367,7 +367,7 @@ bool afs_iterate_addresses(struct afs_addr_cursor *ac) return false; =20 set =3D ac->alist->responded; - failed =3D ac->alist->failed; + failed =3D ac->alist->probe_failed; _enter("%lx-%lx-%lx,%d", set, failed, ac->tried, ac->index); =20 ac->nr_iterations++; diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index 58d28b82571e..fbb91ad775b9 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -88,7 +88,7 @@ static void afs_fs_probe_not_done(struct afs_net *net, if (server->probe.error =3D=3D 0) server->probe.error =3D -ENOMEM; =20 - set_bit(index, &alist->failed); + set_bit(index, &alist->probe_failed); =20 spin_unlock(&server->probe_lock); return afs_done_one_fs_probe(net, server); @@ -138,7 +138,7 @@ void afs_fileserver_probe_result(struct afs_call *call) case -ETIME: default: clear_bit(index, &alist->responded); - set_bit(index, &alist->failed); + set_bit(index, &alist->probe_failed); if (!server->probe.responded && (server->probe.error =3D=3D 0 || server->probe.error =3D=3D -ETIMEDOUT || @@ -149,7 +149,7 @@ void afs_fileserver_probe_result(struct afs_call *call) } =20 responded: - clear_bit(index, &alist->failed); + clear_bit(index, &alist->probe_failed); =20 if (call->service_id =3D=3D YFS_FS_SERVICE) { server->probe.is_yfs =3D true; diff --git a/fs/afs/internal.h b/fs/afs/internal.h index ec08b4a7e499..95bb37253cad 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -90,7 +90,7 @@ struct afs_addr_list { unsigned char nr_ipv4; /* Number of IPv4 addresses */ enum dns_record_source source:8; enum dns_lookup_status status:8; - unsigned long failed; /* Mask of addrs that failed locally/ICMP */ + unsigned long probe_failed; /* Mask of addrs that failed locally/ICMP */ unsigned long responded; /* Mask of addrs that responded */ struct afs_address addrs[] __counted_by(max_addrs); #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8)) diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 8a65a06908d2..16d93fa6396f 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -396,7 +396,7 @@ static int afs_proc_servers_show(struct seq_file *m, vo= id *v) (int)(jiffies - server->probed_at) / HZ, atomic_read(&server->probe_outstanding)); seq_printf(m, " - ALIST v=3D%u rsp=3D%lx f=3D%lx\n", - alist->version, alist->responded, alist->failed); + alist->version, alist->responded, alist->probe_failed); for (i =3D 0; i < alist->nr_addrs; i++) seq_printf(m, " [%x] %pISpc%s rtt=3D%d\n", i, rxrpc_kernel_remote_addr(alist->addrs[i].peer), diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index d420f073300b..13ec8ffa911a 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -583,7 +583,7 @@ void afs_dump_edestaddrreq(const struct afs_operation *= op) a->nr_ipv4, a->nr_addrs, a->max_addrs, a->preferred); pr_notice("FC: - R=3D%lx F=3D%lx\n", - a->responded, a->failed); + a->responded, a->probe_failed); if (a =3D=3D op->ac.alist) pr_notice("FC: - current\n"); } diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c index 9551aef07cee..44bff3a2a5ac 100644 --- a/fs/afs/vl_probe.c +++ b/fs/afs/vl_probe.c @@ -90,7 +90,7 @@ void afs_vlserver_probe_result(struct afs_call *call) case -ETIME: default: clear_bit(index, &alist->responded); - set_bit(index, &alist->failed); + set_bit(index, &alist->probe_failed); if (!(server->probe.flags & AFS_VLSERVER_PROBE_RESPONDED) && (server->probe.error =3D=3D 0 || server->probe.error =3D=3D -ETIMEDOUT || @@ -102,7 +102,7 @@ void afs_vlserver_probe_result(struct afs_call *call) =20 responded: set_bit(index, &alist->responded); - clear_bit(index, &alist->failed); + clear_bit(index, &alist->probe_failed); =20 if (call->service_id =3D=3D YFS_VL_SERVICE) { server->probe.flags |=3D AFS_VLSERVER_PROBE_IS_YFS; diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index 6aaa2e4733ec..01c890b3d18d 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -322,7 +322,7 @@ static void afs_vl_dump_edestaddrreq(const struct afs_v= l_cursor *vc) a->nr_ipv4, a->nr_addrs, a->max_addrs, a->preferred); pr_notice("VC: - R=3D%lx F=3D%lx\n", - a->responded, a->failed); + a->responded, a->probe_failed); if (a =3D=3D vc->ac.alist) pr_notice("VC: - current\n"); } From nobody Mon Dec 15 21:24:35 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 B9986C4332F for ; Wed, 13 Dec 2023 13:51:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379302AbjLMNvA (ORCPT ); Wed, 13 Dec 2023 08:51:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379214AbjLMNu2 (ORCPT ); Wed, 13 Dec 2023 08:50:28 -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 EE39318F for ; Wed, 13 Dec 2023 05:50:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475430; 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=z3fXIPXuGexzb3JH5UnibU+knvRn4aWjn9nvZHgRZUg=; b=bO2zIP4NzhJcdI+XmyhlwWevddlqgZHq2BRffFt02PV23xOjE2zsdQxpjd8yQ6p7nNB8kn cXJkZiED7BTMs4qv6/IqJV0h/MA8PCI2KIBPcbHsVO8+JuHJEJx4so+lWQLonNkohxPsUT et0DTnQ4u0ysj9bhb3PiwzZKQQtJbwg= 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-441-csY2hgwvOb-vxy8PjmHO1w-1; Wed, 13 Dec 2023 08:50:26 -0500 X-MC-Unique: csY2hgwvOb-vxy8PjmHO1w-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 DFC178828C6; Wed, 13 Dec 2023 13:50:25 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2160E1C060B1; Wed, 13 Dec 2023 13:50:25 +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 Subject: [PATCH v2 12/40] afs: Handle the VIO and UAEIO aborts explicitly Date: Wed, 13 Dec 2023 13:49:34 +0000 Message-ID: <20231213135003.367397-13-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: quoted-printable 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-Type: text/plain; charset="utf-8" When processing the result of a call, handle the VIO and UAEIO abort specifically rather than leaving it to a default case. Rather than erroring out unconditionally, see if there's another server if the volume has more than one server available, otherwise return -EREMOTEIO. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- Notes: Changes =3D=3D=3D=3D=3D=3D=3D ver #2) - Treat UAEIO as VIO too. fs/afs/rotate.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 13ec8ffa911a..0829933f4d9a 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -330,6 +330,13 @@ bool afs_select_fileserver(struct afs_operation *op) =20 goto restart_from_beginning; =20 + case UAEIO: + case VIO: + op->error =3D -EREMOTEIO; + if (op->volume->type !=3D AFSVL_RWVOL) + goto next_server; + goto failed; + case VDISKFULL: case UAENOSPC: /* The partition is full. Only applies to RWVOLs. From nobody Mon Dec 15 21:24:35 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 DD82CC4332F for ; Wed, 13 Dec 2023 13:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441800AbjLMNvM (ORCPT ); Wed, 13 Dec 2023 08:51:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379331AbjLMNum (ORCPT ); Wed, 13 Dec 2023 08:50:42 -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 B70F295 for ; Wed, 13 Dec 2023 05:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475432; 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=At55AdxI0EVqvLoVtG7qh0zVypL7yPQ0gJ4RwZozN0o=; b=NjAZXPDYIU5KkbzxAwQDnGdzjUKdte4XOKtteXXmXQ5+/04qe6IP7Z+LsdiRbQNVOwf8qU 7y0SW9/VY1oJ8+yPNh/wwwCEXk0dj0u2E2UVjZVh83/QWlRMkK3ZyqyRRBf7nzmDIUyjzW VN87BuoCZKKThJTE0YpeVFYq5vvws9A= 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-194-iTfH0SaSNVqQa9XMdNQ_yg-1; Wed, 13 Dec 2023 08:50:27 -0500 X-MC-Unique: iTfH0SaSNVqQa9XMdNQ_yg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 5862F3C2A1C3; Wed, 13 Dec 2023 13:50:27 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D38C1121306; Wed, 13 Dec 2023 13:50:26 +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 Subject: [PATCH v2 13/40] afs: Use op->nr_iterations=-1 to indicate to begin fileserver iteration Date: Wed, 13 Dec 2023 13:49:35 +0000 Message-ID: <20231213135003.367397-14-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Set op->nr_iterations to -1 to indicate that we need to begin fileserver iteration rather than setting error to SHRT_MAX. This makes it easier to eliminate the address cursor. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/fs_operation.c | 2 +- fs/afs/internal.h | 2 +- fs/afs/rotate.c | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 7a3803ce3a22..3e31fae9a149 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -41,7 +41,7 @@ struct afs_operation *afs_alloc_operation(struct key *key= , struct afs_volume *vo op->cb_v_break =3D volume->cb_v_break; op->debug_id =3D atomic_inc_return(&afs_operation_debug_counter); op->error =3D -EDESTADDRREQ; - op->ac.error =3D SHRT_MAX; + op->nr_iterations =3D -1; =20 _leave(" =3D [op=3D%08x]", op->debug_id); return op; diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 95bb37253cad..e43aef74c241 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -859,7 +859,7 @@ struct afs_operation { struct afs_call *call; unsigned long untried; /* Bitmask of untried servers */ short index; /* Current server */ - unsigned short nr_iterations; /* Number of server iterations */ + short nr_iterations; /* Number of server iterations */ =20 unsigned int flags; #define AFS_OPERATION_STOP 0x0001 /* Set to cease iteration */ diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 0829933f4d9a..4d2317a66385 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -116,7 +116,10 @@ bool afs_select_fileserver(struct afs_operation *op) unsigned int rtt; int error =3D op->ac.error, i; =20 - _enter("%lx[%d],%lx[%d],%d,%d", + op->nr_iterations++; + + _enter("OP=3D%x+%x,%llx,%lx[%d],%lx[%d],%d,%d", + op->debug_id, op->nr_iterations, op->volume->vid, op->untried, op->index, op->ac.tried, op->ac.index, error, op->ac.abort_code); @@ -126,13 +129,11 @@ bool afs_select_fileserver(struct afs_operation *op) return false; } =20 - op->nr_iterations++; + if (op->nr_iterations =3D=3D 0) + goto start; =20 /* Evaluate the result of the previous operation, if there was one. */ switch (error) { - case SHRT_MAX: - goto start; - case 0: default: /* Success or local failure. Stop. */ From nobody Mon Dec 15 21:24:35 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 F2A27C4332F for ; Wed, 13 Dec 2023 13:51:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441798AbjLMNvH (ORCPT ); Wed, 13 Dec 2023 08:51:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379335AbjLMNum (ORCPT ); Wed, 13 Dec 2023 08:50:42 -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 9972AF5 for ; Wed, 13 Dec 2023 05:50:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475431; 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=Qe0MNWQ7YUIkHCt9UWGU/J0OHy/mkGUzr/39SV/8Uy4=; b=VGbeTjHRIDNJ71mwEsWjBuGHhsabbF1sahpoIJy5+6opP4Fdf2nIKTn05699z8q9SnI0ED LNC7a+fJz+5d0OohVKp4INfGZoj9shB2rSPmcrtKc2KMJpGJR5aTyr6mBjrx2h3nxuYwWy 1YBDdOPwwUx+CP12Fyx0sjqXy92iycA= 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-26-WeVn4NThOq-Ih3BU-CT-IA-1; Wed, 13 Dec 2023 08:50:29 -0500 X-MC-Unique: WeVn4NThOq-Ih3BU-CT-IA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 E4ADA3C2A1C6; Wed, 13 Dec 2023 13:50:28 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0847E1121306; Wed, 13 Dec 2023 13:50:27 +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 Subject: [PATCH v2 14/40] afs: Wrap most op->error accesses with inline funcs Date: Wed, 13 Dec 2023 13:49:36 +0000 Message-ID: <20231213135003.367397-15-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Wrap most op->error accesses with inline funcs which will make it easier for a subsequent patch to replace op->error with something else. Two functions are added to this end: (1) afs_op_error() - Get the error code. (2) afs_op_set_error() - Set the error code. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/dir.c | 38 +++++++++++++++--------------- fs/afs/file.c | 4 ++-- fs/afs/fs_operation.c | 21 ++++++++++------- fs/afs/fsclient.c | 2 +- fs/afs/inode.c | 2 +- fs/afs/internal.h | 20 ++++++++++++---- fs/afs/rotate.c | 55 ++++++++++++++++++++++++------------------- fs/afs/server.c | 6 ++--- fs/afs/write.c | 6 ++--- 9 files changed, 87 insertions(+), 67 deletions(-) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 5219182e52e1..b40f7ae850a8 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -878,14 +878,14 @@ static struct inode *afs_do_lookup(struct inode *dir,= struct dentry *dentry, * lookups contained therein are stored in the reply without aborting * the whole operation. */ - op->error =3D -ENOTSUPP; + afs_op_set_error(op, -ENOTSUPP); if (!cookie->one_only) { op->ops =3D &afs_inline_bulk_status_operation; afs_begin_vnode_operation(op); afs_wait_for_operation(op); } =20 - if (op->error =3D=3D -ENOTSUPP) { + if (afs_op_error(op) =3D=3D -ENOTSUPP) { /* We could try FS.BulkStatus next, but this aborts the entire * op if any of the lookups fails - so, for the moment, revert * to FS.FetchStatus for op->file[1]. @@ -895,10 +895,10 @@ static struct inode *afs_do_lookup(struct inode *dir,= struct dentry *dentry, afs_begin_vnode_operation(op); afs_wait_for_operation(op); } - inode =3D ERR_PTR(op->error); + inode =3D ERR_PTR(afs_op_error(op)); =20 out_op: - if (op->error =3D=3D 0) { + if (!afs_op_error(op)) { inode =3D &op->file[1].vnode->netfs.inode; op->file[1].vnode =3D NULL; } @@ -1273,7 +1273,7 @@ static void afs_vnode_new_inode(struct afs_operation = *op) =20 _enter(""); =20 - ASSERTCMP(op->error, =3D=3D, 0); + ASSERTCMP(afs_op_error(op), =3D=3D, 0); =20 inode =3D afs_iget(op, vp); if (IS_ERR(inode)) { @@ -1286,7 +1286,7 @@ static void afs_vnode_new_inode(struct afs_operation = *op) =20 vnode =3D AFS_FS_I(inode); set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags); - if (!op->error) + if (!afs_op_error(op)) afs_cache_permit(vnode, op->key, vnode->cb_break, &vp->scb); d_instantiate(op->dentry, inode); } @@ -1320,7 +1320,7 @@ static void afs_create_put(struct afs_operation *op) { _enter("op=3D%08x", op->debug_id); =20 - if (op->error) + if (afs_op_error(op)) d_drop(op->dentry); } =20 @@ -1480,7 +1480,7 @@ static void afs_dir_remove_link(struct afs_operation = *op) struct dentry *dentry =3D op->dentry; int ret; =20 - if (op->error !=3D 0 || + if (afs_op_error(op) || (op->file[1].scb.have_status && op->file[1].scb.have_error)) return; if (d_really_is_positive(dentry)) @@ -1504,10 +1504,10 @@ static void afs_dir_remove_link(struct afs_operatio= n *op) =20 ret =3D afs_validate(vnode, op->key); if (ret !=3D -ESTALE) - op->error =3D ret; + afs_op_set_error(op, ret); } =20 - _debug("nlink %d [val %d]", vnode->netfs.inode.i_nlink, op->error); + _debug("nlink %d [val %d]", vnode->netfs.inode.i_nlink, afs_op_error(op)); } =20 static void afs_unlink_success(struct afs_operation *op) @@ -1538,7 +1538,7 @@ static void afs_unlink_edit_dir(struct afs_operation = *op) static void afs_unlink_put(struct afs_operation *op) { _enter("op=3D%08x", op->debug_id); - if (op->unlink.need_rehash && op->error < 0 && op->error !=3D -ENOENT) + if (op->unlink.need_rehash && afs_op_error(op) < 0 && afs_op_error(op) != =3D -ENOENT) d_rehash(op->dentry); } =20 @@ -1579,7 +1579,7 @@ static int afs_unlink(struct inode *dir, struct dentr= y *dentry) /* Try to make sure we have a callback promise on the victim. */ ret =3D afs_validate(vnode, op->key); if (ret < 0) { - op->error =3D ret; + afs_op_set_error(op, ret); goto error; } =20 @@ -1588,7 +1588,7 @@ static int afs_unlink(struct inode *dir, struct dentr= y *dentry) spin_unlock(&dentry->d_lock); /* Start asynchronous writeout of the inode */ write_inode_now(d_inode(dentry), 0); - op->error =3D afs_sillyrename(dvnode, vnode, dentry, op->key); + afs_op_set_error(op, afs_sillyrename(dvnode, vnode, dentry, op->key)); goto error; } if (!d_unhashed(dentry)) { @@ -1609,7 +1609,7 @@ static int afs_unlink(struct inode *dir, struct dentr= y *dentry) /* If there was a conflict with a third party, check the status of the * unlinked vnode. */ - if (op->error =3D=3D 0 && (op->flags & AFS_OPERATION_DIR_CONFLICT)) { + if (afs_op_error(op) =3D=3D 0 && (op->flags & AFS_OPERATION_DIR_CONFLICT)= ) { op->file[1].update_ctime =3D false; op->fetch_status.which =3D 1; op->ops =3D &afs_fetch_status_operation; @@ -1691,7 +1691,7 @@ static void afs_link_success(struct afs_operation *op) static void afs_link_put(struct afs_operation *op) { _enter("op=3D%08x", op->debug_id); - if (op->error) + if (afs_op_error(op)) d_drop(op->dentry); } =20 @@ -1889,7 +1889,7 @@ static void afs_rename_put(struct afs_operation *op) if (op->rename.rehash) d_rehash(op->rename.rehash); dput(op->rename.tmp); - if (op->error) + if (afs_op_error(op)) d_rehash(op->dentry); } =20 @@ -1934,7 +1934,7 @@ static int afs_rename(struct mnt_idmap *idmap, struct= inode *old_dir, return PTR_ERR(op); =20 ret =3D afs_validate(vnode, op->key); - op->error =3D ret; + afs_op_set_error(op, ret); if (ret < 0) goto error; =20 @@ -1971,7 +1971,7 @@ static int afs_rename(struct mnt_idmap *idmap, struct= inode *old_dir, op->rename.tmp =3D d_alloc(new_dentry->d_parent, &new_dentry->d_name); if (!op->rename.tmp) { - op->error =3D -ENOMEM; + afs_op_nomem(op); goto error; } =20 @@ -1979,7 +1979,7 @@ static int afs_rename(struct mnt_idmap *idmap, struct= inode *old_dir, AFS_FS_I(d_inode(new_dentry)), new_dentry, op->key); if (ret) { - op->error =3D ret; + afs_op_set_error(op, ret); goto error; } =20 diff --git a/fs/afs/file.c b/fs/afs/file.c index d37dd201752b..0c81c39c32f5 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -243,7 +243,7 @@ static void afs_fetch_data_notify(struct afs_operation = *op) { struct afs_read *req =3D op->fetch.req; struct netfs_io_subrequest *subreq =3D req->subreq; - int error =3D op->error; + int error =3D afs_op_error(op); =20 if (error =3D=3D -ECONNABORTED) error =3D afs_abort_to_error(op->ac.abort_code); @@ -271,7 +271,7 @@ static void afs_fetch_data_success(struct afs_operation= *op) =20 static void afs_fetch_data_put(struct afs_operation *op) { - op->fetch.req->error =3D op->error; + op->fetch.req->error =3D afs_op_error(op); afs_put_read(op->fetch.req); } =20 diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 3e31fae9a149..bfb9a7634bd9 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -40,8 +40,8 @@ struct afs_operation *afs_alloc_operation(struct key *key= , struct afs_volume *vo op->net =3D volume->cell->net; op->cb_v_break =3D volume->cb_v_break; op->debug_id =3D atomic_inc_return(&afs_operation_debug_counter); - op->error =3D -EDESTADDRREQ; op->nr_iterations =3D -1; + afs_op_set_error(op, -EDESTADDRREQ); =20 _leave(" =3D [op=3D%08x]", op->debug_id); return op; @@ -71,7 +71,7 @@ static bool afs_get_io_locks(struct afs_operation *op) swap(vnode, vnode2); =20 if (mutex_lock_interruptible(&vnode->io_lock) < 0) { - op->error =3D -ERESTARTSYS; + afs_op_set_error(op, -ERESTARTSYS); op->flags |=3D AFS_OPERATION_STOP; _leave(" =3D f [I 0]"); return false; @@ -80,7 +80,7 @@ static bool afs_get_io_locks(struct afs_operation *op) =20 if (vnode2) { if (mutex_lock_interruptible_nested(&vnode2->io_lock, 1) < 0) { - op->error =3D -ERESTARTSYS; + afs_op_set_error(op, -ERESTARTSYS); op->flags |=3D AFS_OPERATION_STOP; mutex_unlock(&vnode->io_lock); op->flags &=3D ~AFS_OPERATION_LOCK_0; @@ -159,11 +159,14 @@ static void afs_end_vnode_operation(struct afs_operat= ion *op) { _enter(""); =20 - if (op->error =3D=3D -EDESTADDRREQ || - op->error =3D=3D -EADDRNOTAVAIL || - op->error =3D=3D -ENETUNREACH || - op->error =3D=3D -EHOSTUNREACH) + switch (afs_op_error(op)) { + case -EDESTADDRREQ: + case -EADDRNOTAVAIL: + case -ENETUNREACH: + case -EHOSTUNREACH: afs_dump_edestaddrreq(op); + break; + } =20 afs_drop_io_locks(op); =20 @@ -209,7 +212,7 @@ void afs_wait_for_operation(struct afs_operation *op) =20 afs_end_vnode_operation(op); =20 - if (op->error =3D=3D 0 && op->ops->edit_dir) { + if (!afs_op_error(op) && op->ops->edit_dir) { _debug("edit_dir"); op->ops->edit_dir(op); } @@ -221,7 +224,7 @@ void afs_wait_for_operation(struct afs_operation *op) */ int afs_put_operation(struct afs_operation *op) { - int i, ret =3D op->error; + int i, ret =3D afs_op_error(op); =20 _enter("op=3D%08x,%d", op->debug_id, ret); =20 diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index 7d37f63ef0f0..6821ce0f9d63 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -1899,7 +1899,7 @@ void afs_fs_inline_bulk_status(struct afs_operation *= op) int i; =20 if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) { - op->error =3D -ENOTSUPP; + afs_op_set_error(op, -ENOTSUPP); return; } =20 diff --git a/fs/afs/inode.c b/fs/afs/inode.c index a6ae74d5b698..f44a8a48bf24 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -331,7 +331,7 @@ static void afs_fetch_status_success(struct afs_operati= on *op) =20 if (vnode->netfs.inode.i_state & I_NEW) { ret =3D afs_inode_init_from_status(op, vp, vnode); - op->error =3D ret; + afs_op_set_error(op, ret); if (ret =3D=3D 0) afs_cache_permit(vnode, op->key, vp->cb_break_before, &vp->scb); } else { diff --git a/fs/afs/internal.h b/fs/afs/internal.h index e43aef74c241..5c2d93023d17 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -1140,11 +1140,6 @@ extern bool afs_begin_vnode_operation(struct afs_ope= ration *); extern void afs_wait_for_operation(struct afs_operation *); extern int afs_do_sync_operation(struct afs_operation *); =20 -static inline void afs_op_nomem(struct afs_operation *op) -{ - op->error =3D -ENOMEM; -} - static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int= n, struct afs_vnode *vnode) { @@ -1238,6 +1233,21 @@ static inline void __afs_stat(atomic_t *s) extern int afs_abort_to_error(u32); extern void afs_prioritise_error(struct afs_error *, int, u32); =20 +static inline void afs_op_nomem(struct afs_operation *op) +{ + op->error =3D -ENOMEM; +} + +static inline int afs_op_error(const struct afs_operation *op) +{ + return op->error; +} + +static inline int afs_op_set_error(struct afs_operation *op, int error) +{ + return op->error =3D error; +} + /* * mntpt.c */ diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 4d2317a66385..965ee8f0804a 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -51,7 +51,7 @@ static bool afs_start_fs_iteration(struct afs_operation *= op, * and have to return an error. */ if (op->flags & AFS_OPERATION_CUR_ONLY) { - op->error =3D -ESTALE; + afs_op_set_error(op, -ESTALE); return false; } =20 @@ -93,7 +93,7 @@ static bool afs_sleep_and_retry(struct afs_operation *op) if (!(op->flags & AFS_OPERATION_UNINTR)) { msleep_interruptible(1000); if (signal_pending(current)) { - op->error =3D -ERESTARTSYS; + afs_op_set_error(op, -ERESTARTSYS); return false; } } else { @@ -137,7 +137,7 @@ bool afs_select_fileserver(struct afs_operation *op) case 0: default: /* Success or local failure. Stop. */ - op->error =3D error; + afs_op_set_error(op, error); op->flags |=3D AFS_OPERATION_STOP; _leave(" =3D f [okay/local %d]", error); return false; @@ -174,11 +174,13 @@ bool afs_select_fileserver(struct afs_operation *op) =20 set_bit(AFS_VOLUME_NEEDS_UPDATE, &op->volume->flags); error =3D afs_check_volume_status(op->volume, op); - if (error < 0) - goto failed_set_error; + if (error < 0) { + afs_op_set_error(op, error); + goto failed; + } =20 if (test_bit(AFS_VOLUME_DELETED, &op->volume->flags)) { - op->error =3D -ENOMEDIUM; + afs_op_set_error(op, -ENOMEDIUM); goto failed; } =20 @@ -250,11 +252,11 @@ bool afs_select_fileserver(struct afs_operation *op) clear_bit(AFS_VOLUME_BUSY, &op->volume->flags); } if (op->flags & AFS_OPERATION_NO_VSLEEP) { - op->error =3D -EADV; + afs_op_set_error(op, -EADV); goto failed; } if (op->flags & AFS_OPERATION_CUR_ONLY) { - op->error =3D -ESTALE; + afs_op_set_error(op, -ESTALE); goto failed; } goto busy; @@ -275,7 +277,7 @@ bool afs_select_fileserver(struct afs_operation *op) * lock we need to maintain. */ if (op->flags & AFS_OPERATION_NO_VSLEEP) { - op->error =3D -EBUSY; + afs_op_set_error(op, -EBUSY); goto failed; } if (!test_and_set_bit(AFS_VOLUME_BUSY, &op->volume->flags)) { @@ -304,7 +306,7 @@ bool afs_select_fileserver(struct afs_operation *op) * honour, just in case someone sets up a loop. */ if (op->flags & AFS_OPERATION_VMOVED) { - op->error =3D -EREMOTEIO; + afs_op_set_error(op, -EREMOTEIO); goto failed; } op->flags |=3D AFS_OPERATION_VMOVED; @@ -312,8 +314,10 @@ bool afs_select_fileserver(struct afs_operation *op) set_bit(AFS_VOLUME_WAIT, &op->volume->flags); set_bit(AFS_VOLUME_NEEDS_UPDATE, &op->volume->flags); error =3D afs_check_volume_status(op->volume, op); - if (error < 0) - goto failed_set_error; + if (error < 0) { + afs_op_set_error(op, error); + goto failed; + } =20 /* If the server list didn't change, then the VLDB is * out of sync with the fileservers. This is hopefully @@ -344,7 +348,7 @@ bool afs_select_fileserver(struct afs_operation *op) * Translate locally and return ENOSPC. * No replicas to failover to. */ - op->error =3D -ENOSPC; + afs_op_set_error(op, -ENOSPC); goto failed_but_online; =20 case VOVERQUOTA: @@ -353,7 +357,7 @@ bool afs_select_fileserver(struct afs_operation *op) * Translate locally and return EDQUOT. * No replicas to failover to. */ - op->error =3D -EDQUOT; + afs_op_set_error(op, -EDQUOT); goto failed_but_online; =20 default: @@ -366,7 +370,7 @@ bool afs_select_fileserver(struct afs_operation *op) =20 case -ETIMEDOUT: case -ETIME: - if (op->error !=3D -EDESTADDRREQ) + if (afs_op_error(op) !=3D -EDESTADDRREQ) goto iterate_address; fallthrough; case -ERFKILL: @@ -385,7 +389,7 @@ bool afs_select_fileserver(struct afs_operation *op) fallthrough; case -ECONNRESET: _debug("call reset"); - op->error =3D error; + afs_op_set_error(op, error); goto failed; } =20 @@ -401,8 +405,10 @@ bool afs_select_fileserver(struct afs_operation *op) * volume may have moved or even have been deleted. */ error =3D afs_check_volume_status(op->volume, op); - if (error < 0) - goto failed_set_error; + if (error < 0) { + afs_op_set_error(op, error); + goto failed; + } =20 if (!afs_start_fs_iteration(op, vnode)) goto failed; @@ -413,8 +419,10 @@ bool afs_select_fileserver(struct afs_operation *op) _debug("pick [%lx]", op->untried); =20 error =3D afs_wait_for_fs_probes(op->server_list, op->untried); - if (error < 0) - goto failed_set_error; + if (error < 0) { + afs_op_set_error(op, error); + goto failed; + } =20 /* Pick the untried server with the lowest RTT. If we have outstanding * callbacks, we stick with the server we're already using if we can. @@ -515,7 +523,8 @@ bool afs_select_fileserver(struct afs_operation *op) op->flags &=3D ~AFS_OPERATION_RETRY_SERVER; goto retry_server; case -ERESTARTSYS: - goto failed_set_error; + afs_op_set_error(op, error); + goto failed; case -ETIME: case -EDESTADDRREQ: goto next_server; @@ -544,13 +553,11 @@ bool afs_select_fileserver(struct afs_operation *op) } =20 error =3D e.error; - -failed_set_error: op->error =3D error; failed: op->flags |=3D AFS_OPERATION_STOP; afs_end_cursor(&op->ac); - _leave(" =3D f [failed %d]", op->error); + _leave(" =3D f [failed %d]", afs_op_error(op)); return false; } =20 diff --git a/fs/afs/server.c b/fs/afs/server.c index 5b5fa94005c9..2826e6eced71 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -629,8 +629,8 @@ static noinline bool afs_update_server_record(struct af= s_operation *op, _leave(" =3D t [intr]"); return true; } - op->error =3D PTR_ERR(alist); - _leave(" =3D f [%d]", op->error); + afs_op_set_error(op, PTR_ERR(alist)); + _leave(" =3D f [%d]", afs_op_error(op)); return false; } =20 @@ -684,7 +684,7 @@ bool afs_check_server_record(struct afs_operation *op, = struct afs_server *server (op->flags & AFS_OPERATION_UNINTR) ? TASK_UNINTERRUPTIBLE : TASK_INTERRUPTIBLE); if (ret =3D=3D -ERESTARTSYS) { - op->error =3D ret; + afs_op_set_error(op, ret); _leave(" =3D f [intr]"); return false; } diff --git a/fs/afs/write.c b/fs/afs/write.c index 4a168781936b..9f90d8970ce9 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -366,7 +366,7 @@ static void afs_store_data_success(struct afs_operation= *op) =20 op->ctime =3D op->file[0].scb.status.mtime_client; afs_vnode_commit_status(op, &op->file[0]); - if (op->error =3D=3D 0) { + if (!afs_op_error(op)) { if (!op->store.laundering) afs_pages_written_back(vnode, op->store.pos, op->store.size); afs_stat_v(vnode, n_stores); @@ -428,7 +428,7 @@ static int afs_store_data(struct afs_vnode *vnode, stru= ct iov_iter *iter, loff_t =20 afs_wait_for_operation(op); =20 - switch (op->error) { + switch (afs_op_error(op)) { case -EACCES: case -EPERM: case -ENOKEY: @@ -447,7 +447,7 @@ static int afs_store_data(struct afs_vnode *vnode, stru= ct iov_iter *iter, loff_t } =20 afs_put_wb_key(wbk); - _leave(" =3D %d", op->error); + _leave(" =3D %d", afs_op_error(op)); return afs_put_operation(op); } From nobody Mon Dec 15 21:24:35 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 3E018C4167D for ; Wed, 13 Dec 2023 13:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441812AbjLMNvR (ORCPT ); Wed, 13 Dec 2023 08:51:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441804AbjLMNup (ORCPT ); Wed, 13 Dec 2023 08:50:45 -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 81C591B5 for ; Wed, 13 Dec 2023 05:50:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475436; 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=Ufx1iRRlt2u1PjpDhur3EzIQG4NmaubyjaVGI5F0Lt0=; b=abUygyNLSHiSxKTuc4xs1wearRH/dCRMwlQZNqdITxOuygzngxfXsQb5XBq1UINi0cJbGE fJI8aOUDoEqLLwZoV2aBvkQBY2VIFzTYClf1fYfLgWBI0UyGtzDST29lTL3e7iOHJc+DAm 4Qu6nDM+y18jqABYCrIJVQuU6B6NS/w= 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-417-saXax80HN_eJ0FJpa-iEMQ-1; Wed, 13 Dec 2023 08:50:31 -0500 X-MC-Unique: saXax80HN_eJ0FJpa-iEMQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 998A1837182; Wed, 13 Dec 2023 13:50:30 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 906DE3C25; Wed, 13 Dec 2023 13:50:29 +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 Subject: [PATCH v2 15/40] afs: Don't put afs_call in afs_wait_for_call_to_complete() Date: Wed, 13 Dec 2023 13:49:37 +0000 Message-ID: <20231213135003.367397-16-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Don't put the afs_call struct in afs_wait_for_call_to_complete() but rather have the caller do it. This will allow the caller to fish stuff out of the afs_call struct rather than the afs_addr_cursor struct, thereby allowing a subsequent patch to subsume it. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/fs_operation.c | 7 +++-- fs/afs/fsclient.c | 5 ++- fs/afs/internal.h | 2 +- fs/afs/rxrpc.c | 73 ++++++++++++++++--------------------------- fs/afs/vlclient.c | 64 ++++++++++++++++++++++--------------- 5 files changed, 75 insertions(+), 76 deletions(-) diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index bfb9a7634bd9..1c22d6e77846 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -191,8 +191,11 @@ void afs_wait_for_operation(struct afs_operation *op) else op->ac.error =3D -ENOTSUPP; =20 - if (op->call) - op->error =3D afs_wait_for_call_to_complete(op->call, &op->ac); + if (op->call) { + afs_wait_for_call_to_complete(op->call, &op->ac); + op->error =3D op->ac.error; + afs_put_call(op->call); + } } =20 switch (op->error) { diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index 6821ce0f9d63..020073387111 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -1612,6 +1612,7 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, { struct afs_call *call; __be32 *bp; + int ret; =20 _enter(""); =20 @@ -1627,7 +1628,9 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, =20 call->server =3D afs_use_server(server, afs_server_trace_give_up_cb); afs_make_call(ac, call, GFP_NOFS); - return afs_wait_for_call_to_complete(call, ac); + afs_wait_for_call_to_complete(call, ac); + afs_put_call(call); + return ret; } =20 /* diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 5c2d93023d17..1bc69a115223 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -1291,7 +1291,7 @@ extern void __net_exit afs_close_socket(struct afs_ne= t *); extern void afs_charge_preallocation(struct work_struct *); extern void afs_put_call(struct afs_call *); extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp= _t); -extern long afs_wait_for_call_to_complete(struct afs_call *, struct afs_ad= dr_cursor *); +void afs_wait_for_call_to_complete(struct afs_call *call, struct afs_addr_= cursor *ac); extern struct afs_call *afs_alloc_flat_call(struct afs_net *, const struct afs_call_type *, size_t, size_t); diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index 2603db03b7ff..dad8efadbc44 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -575,48 +575,44 @@ static void afs_deliver_to_call(struct afs_call *call) /* * Wait synchronously for a call to complete and clean up the call struct. */ -long afs_wait_for_call_to_complete(struct afs_call *call, - struct afs_addr_cursor *ac) +void afs_wait_for_call_to_complete(struct afs_call *call, struct afs_addr_= cursor *ac) { - long ret; bool rxrpc_complete =3D false; =20 - DECLARE_WAITQUEUE(myself, current); - _enter(""); =20 - ret =3D call->error; - if (ret < 0) - goto out; + if (!afs_check_call_state(call, AFS_CALL_COMPLETE)) { + DECLARE_WAITQUEUE(myself, current); + + add_wait_queue(&call->waitq, &myself); + for (;;) { + set_current_state(TASK_UNINTERRUPTIBLE); + + /* deliver any messages that are in the queue */ + if (!afs_check_call_state(call, AFS_CALL_COMPLETE) && + call->need_attention) { + call->need_attention =3D false; + __set_current_state(TASK_RUNNING); + afs_deliver_to_call(call); + continue; + } =20 - add_wait_queue(&call->waitq, &myself); - for (;;) { - set_current_state(TASK_UNINTERRUPTIBLE); - - /* deliver any messages that are in the queue */ - if (!afs_check_call_state(call, AFS_CALL_COMPLETE) && - call->need_attention) { - call->need_attention =3D false; - __set_current_state(TASK_RUNNING); - afs_deliver_to_call(call); - continue; - } + if (afs_check_call_state(call, AFS_CALL_COMPLETE)) + break; =20 - if (afs_check_call_state(call, AFS_CALL_COMPLETE)) - break; + if (!rxrpc_kernel_check_life(call->net->socket, call->rxcall)) { + /* rxrpc terminated the call. */ + rxrpc_complete =3D true; + break; + } =20 - if (!rxrpc_kernel_check_life(call->net->socket, call->rxcall)) { - /* rxrpc terminated the call. */ - rxrpc_complete =3D true; - break; + schedule(); } =20 - schedule(); + remove_wait_queue(&call->waitq, &myself); + __set_current_state(TASK_RUNNING); } =20 - remove_wait_queue(&call->waitq, &myself); - __set_current_state(TASK_RUNNING); - if (!afs_check_call_state(call, AFS_CALL_COMPLETE)) { if (rxrpc_complete) { afs_set_call_complete(call, call->error, call->abort_code); @@ -635,23 +631,8 @@ long afs_wait_for_call_to_complete(struct afs_call *ca= ll, ac->error =3D call->error; spin_unlock_bh(&call->state_lock); =20 - ret =3D ac->error; - switch (ret) { - case 0: - ret =3D call->ret0; - call->ret0 =3D 0; - - fallthrough; - case -ECONNABORTED: + if (call->error =3D=3D 0 || call->error =3D=3D -ECONNABORTED) ac->responded =3D true; - break; - } - -out: - _debug("call complete"); - afs_put_call(call); - _leave(" =3D %p", (void *)ret); - return ret; } =20 /* diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index 41e7932d75c6..650534892a20 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -106,12 +106,6 @@ static int afs_deliver_vl_get_entry_by_name_u(struct a= fs_call *call) return 0; } =20 -static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call) -{ - kfree(call->ret_vldb); - afs_flat_call_destructor(call); -} - /* * VL.GetEntryByNameU operation type. */ @@ -119,7 +113,7 @@ static const struct afs_call_type afs_RXVLGetEntryByNam= eU =3D { .name =3D "VL.GetEntryByNameU", .op =3D afs_VL_GetEntryByNameU, .deliver =3D afs_deliver_vl_get_entry_by_name_u, - .destructor =3D afs_destroy_vl_get_entry_by_name_u, + .destructor =3D afs_flat_call_destructor, }; =20 /* @@ -166,7 +160,13 @@ struct afs_vldb_entry *afs_vl_get_entry_by_name_u(stru= ct afs_vl_cursor *vc, =20 trace_afs_make_vl_call(call); afs_make_call(&vc->ac, call, GFP_KERNEL); - return (struct afs_vldb_entry *)afs_wait_for_call_to_complete(call, &vc->= ac); + afs_wait_for_call_to_complete(call, &vc->ac); + afs_put_call(call); + if (vc->ac.error) { + kfree(entry); + return ERR_PTR(vc->ac.error); + } + return entry; } =20 /* @@ -249,12 +249,6 @@ static int afs_deliver_vl_get_addrs_u(struct afs_call = *call) return 0; } =20 -static void afs_vl_get_addrs_u_destructor(struct afs_call *call) -{ - afs_put_addrlist(call->ret_alist); - return afs_flat_call_destructor(call); -} - /* * VL.GetAddrsU operation type. */ @@ -262,7 +256,7 @@ static const struct afs_call_type afs_RXVLGetAddrsU =3D= { .name =3D "VL.GetAddrsU", .op =3D afs_VL_GetAddrsU, .deliver =3D afs_deliver_vl_get_addrs_u, - .destructor =3D afs_vl_get_addrs_u_destructor, + .destructor =3D afs_flat_call_destructor, }; =20 /* @@ -273,6 +267,7 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_= cursor *vc, const uuid_t *uuid) { struct afs_ListAddrByAttributes__xdr *r; + struct afs_addr_list *alist; const struct afs_uuid *u =3D (const struct afs_uuid *)uuid; struct afs_call *call; struct afs_net *net =3D vc->cell->net; @@ -309,7 +304,14 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl= _cursor *vc, =20 trace_afs_make_vl_call(call); afs_make_call(&vc->ac, call, GFP_KERNEL); - return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->a= c); + afs_wait_for_call_to_complete(call, &vc->ac); + alist =3D call->ret_alist; + afs_put_call(call); + if (vc->ac.error) { + afs_put_addrlist(alist); + return ERR_PTR(vc->ac.error); + } + return alist; } =20 /* @@ -618,7 +620,7 @@ static const struct afs_call_type afs_YFSVLGetEndpoints= =3D { .name =3D "YFSVL.GetEndpoints", .op =3D afs_YFSVL_GetEndpoints, .deliver =3D afs_deliver_yfsvl_get_endpoints, - .destructor =3D afs_vl_get_addrs_u_destructor, + .destructor =3D afs_flat_call_destructor, }; =20 /* @@ -628,6 +630,7 @@ static const struct afs_call_type afs_YFSVLGetEndpoints= =3D { struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc, const uuid_t *uuid) { + struct afs_addr_list *alist; struct afs_call *call; struct afs_net *net =3D vc->cell->net; __be32 *bp; @@ -652,7 +655,14 @@ struct afs_addr_list *afs_yfsvl_get_endpoints(struct a= fs_vl_cursor *vc, =20 trace_afs_make_vl_call(call); afs_make_call(&vc->ac, call, GFP_KERNEL); - return (struct afs_addr_list *)afs_wait_for_call_to_complete(call, &vc->a= c); + afs_wait_for_call_to_complete(call, &vc->ac); + alist =3D call->ret_alist; + afs_put_call(call); + if (vc->ac.error) { + afs_put_addrlist(alist); + return ERR_PTR(vc->ac.error); + } + return alist; } =20 /* @@ -717,12 +727,6 @@ static int afs_deliver_yfsvl_get_cell_name(struct afs_= call *call) return 0; } =20 -static void afs_destroy_yfsvl_get_cell_name(struct afs_call *call) -{ - kfree(call->ret_str); - afs_flat_call_destructor(call); -} - /* * VL.GetCapabilities operation type */ @@ -730,7 +734,7 @@ static const struct afs_call_type afs_YFSVLGetCellName = =3D { .name =3D "YFSVL.GetCellName", .op =3D afs_YFSVL_GetCellName, .deliver =3D afs_deliver_yfsvl_get_cell_name, - .destructor =3D afs_destroy_yfsvl_get_cell_name, + .destructor =3D afs_flat_call_destructor, }; =20 /* @@ -745,6 +749,7 @@ char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc) struct afs_call *call; struct afs_net *net =3D vc->cell->net; __be32 *bp; + char *cellname; =20 _enter(""); =20 @@ -763,5 +768,12 @@ char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc) /* Can't take a ref on server */ trace_afs_make_vl_call(call); afs_make_call(&vc->ac, call, GFP_KERNEL); - return (char *)afs_wait_for_call_to_complete(call, &vc->ac); + afs_wait_for_call_to_complete(call, &vc->ac); + cellname =3D call->ret_str; + afs_put_call(call); + if (vc->ac.error) { + kfree(cellname); + return ERR_PTR(vc->ac.error); + } + return cellname; } From nobody Mon Dec 15 21:24:35 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 8D0AEC4332F for ; Wed, 13 Dec 2023 13:51:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441816AbjLMNvU (ORCPT ); Wed, 13 Dec 2023 08:51:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441827AbjLMNus (ORCPT ); Wed, 13 Dec 2023 08:50:48 -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 EBB92124 for ; Wed, 13 Dec 2023 05:50:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475434; 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=rt4G7Zdcwt/ScaeTO4LIplOYZNojSp7bG7fdUXxFL/Y=; b=ecLUlYWeLC2zqDAFfkwMhSAEaQSMtSROiLQ/x+hrl5dqSo0zQe4mRpvdfAI6curlWZRvrj uZT1DgWg4Q/z8MLzvn4r79T7cX8q5Q9J+W2oHBdqs4KJy1GXf10aluqFxp6Tp0YXoyCl6L CBNocc6RD3Dg3w61Bi54Tpk+Ogu7XV8= 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-510-8ZAkYcsyP2yV0EB1WBezRA-1; Wed, 13 Dec 2023 08:50:33 -0500 X-MC-Unique: 8ZAkYcsyP2yV0EB1WBezRA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 9FB8C837182; Wed, 13 Dec 2023 13:50:32 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FA7FC159B0; Wed, 13 Dec 2023 13:50:31 +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 Subject: [PATCH v2 16/40] afs: Simplify error handling Date: Wed, 13 Dec 2023 13:49:38 +0000 Message-ID: <20231213135003.367397-17-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Simplify error handling a bit by moving it from the afs_addr_cursor struct to the afs_operation and afs_vl_cursor structs and using the error prioritisation function for accumulating errors from multiple sources (AFS tries to rotate between multiple fileservers, some of which may be inaccessible or in some state of offlinedness). Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/addr_list.c | 8 ++-- fs/afs/dir.c | 14 ++++--- fs/afs/dir_silly.c | 2 +- fs/afs/file.c | 3 -- fs/afs/fs_operation.c | 24 +++++------ fs/afs/fsclient.c | 1 + fs/afs/internal.h | 44 +++++++++++++++------ fs/afs/misc.c | 10 ++++- fs/afs/rotate.c | 58 ++++++++++++++------------- fs/afs/rxrpc.c | 17 ++++---- fs/afs/server.c | 1 - fs/afs/vl_alias.c | 2 +- fs/afs/vl_probe.c | 7 ++-- fs/afs/vl_rotate.c | 92 +++++++++++++++++++++---------------------- fs/afs/vlclient.c | 34 ++++++++++------ 15 files changed, 174 insertions(+), 143 deletions(-) diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index b76abf500713..a1f3c995e328 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -386,26 +386,24 @@ bool afs_iterate_addresses(struct afs_addr_cursor *ac) selected: ac->index =3D index; set_bit(index, &ac->tried); - ac->responded =3D false; + ac->call_responded =3D false; return true; } =20 /* * Release an address list cursor. */ -int afs_end_cursor(struct afs_addr_cursor *ac) +void afs_end_cursor(struct afs_addr_cursor *ac) { struct afs_addr_list *alist; =20 alist =3D ac->alist; if (alist) { - if (ac->responded && + if (ac->call_responded && ac->index !=3D alist->preferred && test_bit(ac->alist->preferred, &ac->tried)) WRITE_ONCE(alist->preferred, ac->index); afs_put_addrlist(alist); ac->alist =3D NULL; } - - return ac->error; } diff --git a/fs/afs/dir.c b/fs/afs/dir.c index b40f7ae850a8..ecb889a269fb 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -693,8 +693,9 @@ static void afs_do_lookup_success(struct afs_operation = *op) vp =3D &op->file[0]; abort_code =3D vp->scb.status.abort_code; if (abort_code !=3D 0) { - op->ac.abort_code =3D abort_code; - op->error =3D afs_abort_to_error(abort_code); + op->call_abort_code =3D abort_code; + afs_op_set_error(op, afs_abort_to_error(abort_code)); + op->cumul_error.abort_code =3D abort_code; } break; =20 @@ -846,13 +847,14 @@ static struct inode *afs_do_lookup(struct inode *dir,= struct dentry *dentry, _debug("nr_files %u", op->nr_files); =20 /* Need space for examining all the selected files */ - op->error =3D -ENOMEM; if (op->nr_files > 2) { op->more_files =3D kvcalloc(op->nr_files - 2, sizeof(struct afs_vnode_param), GFP_KERNEL); - if (!op->more_files) + if (!op->more_files) { + afs_op_nomem(op); goto out_op; + } =20 for (i =3D 2; i < op->nr_files; i++) { vp =3D &op->more_files[i - 2]; @@ -1255,7 +1257,7 @@ void afs_check_for_remote_deletion(struct afs_operati= on *op) { struct afs_vnode *vnode =3D op->file[0].vnode; =20 - switch (op->ac.abort_code) { + switch (afs_op_abort_code(op)) { case VNOVNODE: set_bit(AFS_VNODE_DELETED, &vnode->flags); afs_break_callback(vnode, afs_cb_break_for_deleted); @@ -1280,7 +1282,7 @@ static void afs_vnode_new_inode(struct afs_operation = *op) /* ENOMEM or EINTR at a really inconvenient time - just abandon * the new directory on the server. */ - op->error =3D PTR_ERR(inode); + afs_op_accumulate_error(op, PTR_ERR(inode), 0); return; } =20 diff --git a/fs/afs/dir_silly.c b/fs/afs/dir_silly.c index bb5807e87fa4..a1e581946b93 100644 --- a/fs/afs/dir_silly.c +++ b/fs/afs/dir_silly.c @@ -218,7 +218,7 @@ static int afs_do_silly_unlink(struct afs_vnode *dvnode= , struct afs_vnode *vnode /* If there was a conflict with a third party, check the status of the * unlinked vnode. */ - if (op->error =3D=3D 0 && (op->flags & AFS_OPERATION_DIR_CONFLICT)) { + if (op->cumul_error.error =3D=3D 0 && (op->flags & AFS_OPERATION_DIR_CONF= LICT)) { op->file[1].update_ctime =3D false; op->fetch_status.which =3D 1; op->ops =3D &afs_fetch_status_operation; diff --git a/fs/afs/file.c b/fs/afs/file.c index 0c81c39c32f5..8f9b42427569 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -245,10 +245,7 @@ static void afs_fetch_data_notify(struct afs_operation= *op) struct netfs_io_subrequest *subreq =3D req->subreq; int error =3D afs_op_error(op); =20 - if (error =3D=3D -ECONNABORTED) - error =3D afs_abort_to_error(op->ac.abort_code); req->error =3D error; - if (subreq) { __set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags); netfs_subreq_terminated(subreq, error ?: req->actual_len, false); diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 1c22d6e77846..cebe4fad8192 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -169,9 +169,6 @@ static void afs_end_vnode_operation(struct afs_operatio= n *op) } =20 afs_drop_io_locks(op); - - if (op->error =3D=3D -ECONNABORTED) - op->error =3D afs_abort_to_error(op->ac.abort_code); } =20 /* @@ -182,6 +179,8 @@ void afs_wait_for_operation(struct afs_operation *op) _enter(""); =20 while (afs_select_fileserver(op)) { + op->call_error =3D 0; + op->call_abort_code =3D 0; op->cb_s_break =3D op->server->cb_s_break; if (test_bit(AFS_SERVER_FL_IS_YFS, &op->server->flags) && op->ops->issue_yfs_rpc) @@ -189,28 +188,29 @@ void afs_wait_for_operation(struct afs_operation *op) else if (op->ops->issue_afs_rpc) op->ops->issue_afs_rpc(op); else - op->ac.error =3D -ENOTSUPP; + op->call_error =3D -ENOTSUPP; =20 if (op->call) { afs_wait_for_call_to_complete(op->call, &op->ac); - op->error =3D op->ac.error; + op->call_abort_code =3D op->call->abort_code; + op->call_error =3D op->call->error; + op->call_responded =3D op->call->responded; + op->ac.call_responded =3D true; + WRITE_ONCE(op->ac.alist->addrs[op->ac.index].last_error, + op->call_error); afs_put_call(op->call); } } =20 - switch (op->error) { - case 0: + if (!afs_op_error(op)) { _debug("success"); op->ops->success(op); - break; - case -ECONNABORTED: + } else if (op->cumul_error.aborted) { if (op->ops->aborted) op->ops->aborted(op); - fallthrough; - default: + } else { if (op->ops->failed) op->ops->failed(op); - break; } =20 afs_end_vnode_operation(op); diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index 020073387111..2a56dea22519 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -1629,6 +1629,7 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, call->server =3D afs_use_server(server, afs_server_trace_give_up_cb); afs_make_call(ac, call, GFP_NOFS); afs_wait_for_call_to_complete(call, ac); + ret =3D call->error; afs_put_call(call); return ret; } diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 1bc69a115223..d67c75d4d2bd 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -75,6 +75,7 @@ enum afs_call_state { struct afs_address { struct rxrpc_peer *peer; u16 service_id; + short last_error; /* Last error from this address */ }; =20 /* @@ -121,7 +122,6 @@ struct afs_call { }; void *buffer; /* reply receive buffer */ union { - long ret0; /* Value to reply with instead of 0 */ struct afs_addr_list *ret_alist; struct afs_vldb_entry *ret_vldb; char *ret_str; @@ -145,6 +145,7 @@ struct afs_call { bool upgrade; /* T to request service upgrade */ bool intr; /* T if interruptible */ bool unmarshalling_error; /* T if an unmarshalling error occurred */ + bool responded; /* Got a response from the call (may be abort) */ u16 service_id; /* Actual service ID (after upgrade) */ unsigned int debug_id; /* Trace ID */ u32 operation_ID; /* operation ID for an incoming call */ @@ -719,8 +720,10 @@ struct afs_permits { * Error prioritisation and accumulation. */ struct afs_error { - short error; /* Accumulated error */ + s32 abort_code; /* Cumulative abort code */ + short error; /* Cumulative error */ bool responded; /* T if server responded */ + bool aborted; /* T if ->error is from an abort */ }; =20 /* @@ -730,10 +733,8 @@ struct afs_addr_cursor { struct afs_addr_list *alist; /* Current address list (pins ref) */ unsigned long tried; /* Tried addresses */ signed char index; /* Current address */ - bool responded; /* T if the current address responded */ unsigned short nr_iterations; /* Number of address iterations */ - short error; - u32 abort_code; + bool call_responded; }; =20 /* @@ -746,13 +747,16 @@ struct afs_vl_cursor { struct afs_vlserver *server; /* Server on which this resides */ struct key *key; /* Key for the server */ unsigned long untried; /* Bitmask of untried servers */ + struct afs_error cumul_error; /* Cumulative error */ + s32 call_abort_code; short index; /* Current server */ - short error; + short call_error; /* Error from single call */ unsigned short flags; #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */ #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */ #define AFS_VL_CURSOR_RETRIED 0x0004 /* Set if started a retry */ - unsigned short nr_iterations; /* Number of server iterations */ + short nr_iterations; /* Number of server iterations */ + bool call_responded; /* T if the current address responded */ }; =20 /* @@ -803,8 +807,10 @@ struct afs_operation { struct dentry *dentry_2; /* Second dentry to be altered */ struct timespec64 mtime; /* Modification time to record */ struct timespec64 ctime; /* Change time to set */ + struct afs_error cumul_error; /* Cumulative error */ short nr_files; /* Number of entries in file[], more_files */ - short error; + short call_error; /* Error from single call */ + s32 call_abort_code; /* Abort code from single call */ unsigned int debug_id; =20 unsigned int cb_v_break; /* Volume break counter before op */ @@ -860,6 +866,8 @@ struct afs_operation { unsigned long untried; /* Bitmask of untried servers */ short index; /* Current server */ short nr_iterations; /* Number of server iterations */ + bool call_responded; /* T if the current address responded */ + =20 unsigned int flags; #define AFS_OPERATION_STOP 0x0001 /* Set to cease iteration */ @@ -976,7 +984,7 @@ bool afs_addr_list_same(const struct afs_addr_list *a, const struct afs_addr_list *b); extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t= *); extern bool afs_iterate_addresses(struct afs_addr_cursor *); -extern int afs_end_cursor(struct afs_addr_cursor *); +extern void afs_end_cursor(struct afs_addr_cursor *ac); =20 extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *a= ddr, __be32 xdr, u16 port); @@ -1235,17 +1243,27 @@ extern void afs_prioritise_error(struct afs_error *= , int, u32); =20 static inline void afs_op_nomem(struct afs_operation *op) { - op->error =3D -ENOMEM; + op->cumul_error.error =3D -ENOMEM; } =20 static inline int afs_op_error(const struct afs_operation *op) { - return op->error; + return op->cumul_error.error; +} + +static inline s32 afs_op_abort_code(const struct afs_operation *op) +{ + return op->cumul_error.abort_code; } =20 static inline int afs_op_set_error(struct afs_operation *op, int error) { - return op->error =3D error; + return op->cumul_error.error =3D error; +} + +static inline void afs_op_accumulate_error(struct afs_operation *op, int e= rror, s32 abort_code) +{ + afs_prioritise_error(&op->cumul_error, error, abort_code); } =20 /* @@ -1619,7 +1637,7 @@ static inline void afs_update_dentry_version(struct a= fs_operation *op, struct afs_vnode_param *dir_vp, struct dentry *dentry) { - if (!op->error) + if (!op->cumul_error.error) dentry->d_fsdata =3D (void *)(unsigned long)dir_vp->scb.status.data_version; } diff --git a/fs/afs/misc.c b/fs/afs/misc.c index 805328ca5428..b8180bf2281f 100644 --- a/fs/afs/misc.c +++ b/fs/afs/misc.c @@ -116,6 +116,8 @@ void afs_prioritise_error(struct afs_error *e, int erro= r, u32 abort_code) { switch (error) { case 0: + e->aborted =3D false; + e->error =3D 0; return; default: if (e->error =3D=3D -ETIMEDOUT || @@ -161,12 +163,16 @@ void afs_prioritise_error(struct afs_error *e, int er= ror, u32 abort_code) if (e->responded) return; e->error =3D error; + e->aborted =3D false; return; =20 case -ECONNABORTED: - error =3D afs_abort_to_error(abort_code); - fallthrough; + e->error =3D afs_abort_to_error(abort_code); + e->aborted =3D true; + e->responded =3D true; + return; case -ENETRESET: /* Responded, but we seem to have changed address */ + e->aborted =3D false; e->responded =3D true; e->error =3D error; return; diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 965ee8f0804a..a778d53681fe 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -112,9 +112,9 @@ bool afs_select_fileserver(struct afs_operation *op) struct afs_addr_list *alist; struct afs_server *server; struct afs_vnode *vnode =3D op->file[0].vnode; - struct afs_error e; unsigned int rtt; - int error =3D op->ac.error, i; + s32 abort_code =3D op->call_abort_code; + int error =3D op->call_error, i; =20 op->nr_iterations++; =20 @@ -122,7 +122,7 @@ bool afs_select_fileserver(struct afs_operation *op) op->debug_id, op->nr_iterations, op->volume->vid, op->untried, op->index, op->ac.tried, op->ac.index, - error, op->ac.abort_code); + error, abort_code); =20 if (op->flags & AFS_OPERATION_STOP) { _leave(" =3D f [stopped]"); @@ -133,8 +133,10 @@ bool afs_select_fileserver(struct afs_operation *op) goto start; =20 /* Evaluate the result of the previous operation, if there was one. */ - switch (error) { + switch (op->call_error) { case 0: + op->cumul_error.responded =3D true; + fallthrough; default: /* Success or local failure. Stop. */ afs_op_set_error(op, error); @@ -151,7 +153,8 @@ bool afs_select_fileserver(struct afs_operation *op) * errors instead. IBM AFS and OpenAFS fileservers, however, do leak * these abort codes. */ - switch (op->ac.abort_code) { + op->cumul_error.responded =3D true; + switch (abort_code) { case VNOVOL: /* This fileserver doesn't know about the volume. * - May indicate that the VL is wrong - retry once and compare @@ -164,7 +167,7 @@ bool afs_select_fileserver(struct afs_operation *op) * (administrative action). */ if (op->flags & AFS_OPERATION_VNOVOL) { - op->error =3D -EREMOTEIO; + afs_op_accumulate_error(op, -EREMOTEIO, abort_code); goto next_server; } =20 @@ -188,7 +191,7 @@ bool afs_select_fileserver(struct afs_operation *op) * it's the fileserver having trouble. */ if (rcu_access_pointer(op->volume->servers) =3D=3D op->server_list) { - op->error =3D -EREMOTEIO; + afs_op_accumulate_error(op, -EREMOTEIO, abort_code); goto next_server; } =20 @@ -201,8 +204,8 @@ bool afs_select_fileserver(struct afs_operation *op) case VONLINE: /* These should not be returned from the fileserver. */ pr_warn("Fileserver returned unexpected abort %d\n", - op->ac.abort_code); - op->error =3D -EREMOTEIO; + abort_code); + afs_op_accumulate_error(op, -EREMOTEIO, abort_code); goto next_server; =20 case VNOSERVICE: @@ -233,7 +236,7 @@ bool afs_select_fileserver(struct afs_operation *op) * VNOSERVICE should be treated as an alias for RX_CALL_TIMEOUT. */ case RX_CALL_TIMEOUT: - op->error =3D -ETIMEDOUT; + afs_op_accumulate_error(op, -ETIMEDOUT, abort_code); goto next_server; =20 case VSALVAGING: /* This error should not be leaked to cache managers @@ -248,7 +251,7 @@ bool afs_select_fileserver(struct afs_operation *op) * days). */ if (!test_and_set_bit(AFS_VOLUME_OFFLINE, &op->volume->flags)) { - afs_busy(op->volume, op->ac.abort_code); + afs_busy(op->volume, abort_code); clear_bit(AFS_VOLUME_BUSY, &op->volume->flags); } if (op->flags & AFS_OPERATION_NO_VSLEEP) { @@ -281,7 +284,7 @@ bool afs_select_fileserver(struct afs_operation *op) goto failed; } if (!test_and_set_bit(AFS_VOLUME_BUSY, &op->volume->flags)) { - afs_busy(op->volume, op->ac.abort_code); + afs_busy(op->volume, abort_code); clear_bit(AFS_VOLUME_OFFLINE, &op->volume->flags); } busy: @@ -329,7 +332,7 @@ bool afs_select_fileserver(struct afs_operation *op) * TODO: Retry a few times with sleeps. */ if (rcu_access_pointer(op->volume->servers) =3D=3D op->server_list) { - op->error =3D -ENOMEDIUM; + afs_op_accumulate_error(op, -ENOMEDIUM, abort_code); goto failed; } =20 @@ -337,7 +340,7 @@ bool afs_select_fileserver(struct afs_operation *op) =20 case UAEIO: case VIO: - op->error =3D -EREMOTEIO; + afs_op_accumulate_error(op, -EREMOTEIO, abort_code); if (op->volume->type !=3D AFSVL_RWVOL) goto next_server; goto failed; @@ -361,7 +364,7 @@ bool afs_select_fileserver(struct afs_operation *op) goto failed_but_online; =20 default: - op->error =3D afs_abort_to_error(op->ac.abort_code); + afs_op_accumulate_error(op, error, abort_code); failed_but_online: clear_bit(AFS_VOLUME_OFFLINE, &op->volume->flags); clear_bit(AFS_VOLUME_BUSY, &op->volume->flags); @@ -380,7 +383,7 @@ bool afs_select_fileserver(struct afs_operation *op) case -EHOSTDOWN: case -ECONNREFUSED: _debug("no conn"); - op->error =3D error; + afs_op_accumulate_error(op, error, 0); goto iterate_address; =20 case -ENETRESET: @@ -506,6 +509,7 @@ bool afs_select_fileserver(struct afs_operation *op) op->index, op->ac.index, op->ac.alist->nr_addrs, rxrpc_kernel_remote_addr(op->ac.alist->addrs[op->ac.index].peer)); =20 + op->call_responded =3D false; _leave(" =3D t"); return true; =20 @@ -543,17 +547,14 @@ bool afs_select_fileserver(struct afs_operation *op) if (op->flags & AFS_OPERATION_VBUSY) goto restart_from_beginning; =20 - e.error =3D -EDESTADDRREQ; - e.responded =3D false; for (i =3D 0; i < op->server_list->nr_servers; i++) { struct afs_server *s =3D op->server_list->servers[i].server; =20 - afs_prioritise_error(&e, READ_ONCE(s->probe.error), - s->probe.abort_code); + error =3D READ_ONCE(s->probe.error); + if (error < 0) + afs_op_accumulate_error(op, error, s->probe.abort_code); } =20 - error =3D e.error; - op->error =3D error; failed: op->flags |=3D AFS_OPERATION_STOP; afs_end_cursor(&op->ac); @@ -576,11 +577,13 @@ void afs_dump_edestaddrreq(const struct afs_operation= *op) rcu_read_lock(); =20 pr_notice("EDESTADDR occurred\n"); - pr_notice("FC: cbb=3D%x cbb2=3D%x fl=3D%x err=3D%hd\n", + pr_notice("OP: cbb=3D%x cbb2=3D%x fl=3D%x err=3D%hd\n", op->file[0].cb_break_before, - op->file[1].cb_break_before, op->flags, op->error); - pr_notice("FC: ut=3D%lx ix=3D%d ni=3D%u\n", + op->file[1].cb_break_before, op->flags, op->cumul_error.error); + pr_notice("OP: ut=3D%lx ix=3D%d ni=3D%u\n", op->untried, op->index, op->nr_iterations); + pr_notice("OP: call er=3D%d ac=3D%d r=3D%u\n", + op->call_error, op->call_abort_code, op->call_responded); =20 if (op->server_list) { const struct afs_server_list *sl =3D op->server_list; @@ -605,8 +608,7 @@ void afs_dump_edestaddrreq(const struct afs_operation *= op) } } =20 - pr_notice("AC: t=3D%lx ax=3D%u ac=3D%d er=3D%d r=3D%u ni=3D%u\n", - op->ac.tried, op->ac.index, op->ac.abort_code, op->ac.error, - op->ac.responded, op->ac.nr_iterations); + pr_notice("AC: t=3D%lx ax=3D%u ni=3D%u\n", + op->ac.tried, op->ac.index, op->ac.nr_iterations); rcu_read_unlock(); } diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index dad8efadbc44..0b3e2f20b0e0 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -408,8 +408,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) rxrpc_kernel_recv_data(call->net->socket, rxcall, &msg.msg_iter, &len, false, &call->abort_code, &call->service_id); - ac->abort_code =3D call->abort_code; - ac->responded =3D true; + call->responded =3D true; } call->error =3D ret; trace_afs_call_done(call); @@ -429,7 +428,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) afs_set_call_complete(call, ret, 0); } =20 - ac->error =3D ret; + call->error =3D ret; call->state =3D AFS_CALL_COMPLETE; _leave(" =3D %d", ret); } @@ -510,6 +509,7 @@ static void afs_deliver_to_call(struct afs_call *call) ret =3D -EBADMSG; switch (ret) { case 0: + call->responded =3D true; afs_queue_call_work(call); if (state =3D=3D AFS_CALL_CL_PROC_REPLY) { if (call->op) @@ -524,9 +524,11 @@ static void afs_deliver_to_call(struct afs_call *call) goto out; case -ECONNABORTED: ASSERTCMP(state, =3D=3D, AFS_CALL_COMPLETE); + call->responded =3D true; afs_log_error(call, call->abort_code); goto done; case -ENOTSUPP: + call->responded =3D true; abort_code =3D RXGEN_OPCODE; rxrpc_kernel_abort_call(call->net->socket, call->rxcall, abort_code, ret, @@ -573,7 +575,7 @@ static void afs_deliver_to_call(struct afs_call *call) } =20 /* - * Wait synchronously for a call to complete and clean up the call struct. + * Wait synchronously for a call to complete. */ void afs_wait_for_call_to_complete(struct afs_call *call, struct afs_addr_= cursor *ac) { @@ -626,13 +628,8 @@ void afs_wait_for_call_to_complete(struct afs_call *ca= ll, struct afs_addr_cursor } } =20 - spin_lock_bh(&call->state_lock); - ac->abort_code =3D call->abort_code; - ac->error =3D call->error; - spin_unlock_bh(&call->state_lock); - if (call->error =3D=3D 0 || call->error =3D=3D -ECONNABORTED) - ac->responded =3D true; + call->responded =3D true; } =20 /* diff --git a/fs/afs/server.c b/fs/afs/server.c index 2826e6eced71..f7791ef13618 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -437,7 +437,6 @@ static void afs_give_up_callbacks(struct afs_net *net, = struct afs_server *server struct afs_addr_cursor ac =3D { .alist =3D alist, .index =3D alist->preferred, - .error =3D 0, }; =20 afs_fs_give_up_all_callbacks(net, server, &ac, NULL); diff --git a/fs/afs/vl_alias.c b/fs/afs/vl_alias.c index 6fdf9f1bedc0..89cadd9a69e1 100644 --- a/fs/afs/vl_alias.c +++ b/fs/afs/vl_alias.c @@ -236,7 +236,7 @@ static char *afs_vl_get_cell_name(struct afs_cell *cell= , struct key *key) =20 while (afs_select_vlserver(&vc)) { if (!test_bit(AFS_VLSERVER_FL_IS_YFS, &vc.server->flags)) { - vc.ac.error =3D -EOPNOTSUPP; + vc.call_error =3D -EOPNOTSUPP; skipped =3D true; continue; } diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c index 44bff3a2a5ac..138f5715619d 100644 --- a/fs/afs/vl_probe.c +++ b/fs/afs/vl_probe.c @@ -169,10 +169,11 @@ static bool afs_do_probe_vlserver(struct afs_net *net, call =3D afs_vl_get_capabilities(net, &ac, key, server, server_index); if (!IS_ERR(call)) { + afs_prioritise_error(_e, call->error, call->abort_code); afs_put_call(call); in_progress =3D true; } else { - afs_prioritise_error(_e, PTR_ERR(call), ac.abort_code); + afs_prioritise_error(_e, PTR_ERR(call), 0); afs_done_one_vl_probe(server, false); } } @@ -187,12 +188,10 @@ int afs_send_vl_probes(struct afs_net *net, struct ke= y *key, struct afs_vlserver_list *vllist) { struct afs_vlserver *server; - struct afs_error e; + struct afs_error e =3D {}; bool in_progress =3D false; int i; =20 - e.error =3D 0; - e.responded =3D false; for (i =3D 0; i < vllist->nr_servers; i++) { server =3D vllist->servers[i].server; if (test_bit(AFS_VLSERVER_FL_PROBED, &server->flags)) diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index 01c890b3d18d..7ae73418697d 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -20,11 +20,11 @@ bool afs_begin_vlserver_operation(struct afs_vl_cursor = *vc, struct afs_cell *cel memset(vc, 0, sizeof(*vc)); vc->cell =3D cell; vc->key =3D key; - vc->error =3D -EDESTADDRREQ; - vc->ac.error =3D SHRT_MAX; + vc->cumul_error.error =3D -EDESTADDRREQ; + vc->nr_iterations =3D -1; =20 if (signal_pending(current)) { - vc->error =3D -EINTR; + vc->cumul_error.error =3D -EINTR; vc->flags |=3D AFS_VL_CURSOR_STOP; return false; } @@ -52,7 +52,7 @@ static bool afs_start_vl_iteration(struct afs_vl_cursor *= vc) &cell->dns_lookup_count, smp_load_acquire(&cell->dns_lookup_count) !=3D dns_lookup_count) < 0) { - vc->error =3D -ERESTARTSYS; + vc->cumul_error.error =3D -ERESTARTSYS; return false; } } @@ -60,12 +60,12 @@ static bool afs_start_vl_iteration(struct afs_vl_cursor= *vc) /* Status load is ordered after lookup counter load */ if (cell->dns_status =3D=3D DNS_LOOKUP_GOT_NOT_FOUND) { pr_warn("No record of cell %s\n", cell->name); - vc->error =3D -ENOENT; + vc->cumul_error.error =3D -ENOENT; return false; } =20 if (cell->dns_source =3D=3D DNS_RECORD_UNAVAILABLE) { - vc->error =3D -EDESTADDRREQ; + vc->cumul_error.error =3D -EDESTADDRREQ; return false; } } @@ -91,52 +91,52 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) { struct afs_addr_list *alist; struct afs_vlserver *vlserver; - struct afs_error e; unsigned int rtt; - int error =3D vc->ac.error, i; + s32 abort_code =3D vc->call_abort_code; + int error =3D vc->call_error, i; + + vc->nr_iterations++; =20 _enter("%lx[%d],%lx[%d],%d,%d", vc->untried, vc->index, vc->ac.tried, vc->ac.index, - error, vc->ac.abort_code); + error, abort_code); =20 if (vc->flags & AFS_VL_CURSOR_STOP) { _leave(" =3D f [stopped]"); return false; } =20 - vc->nr_iterations++; + if (vc->nr_iterations =3D=3D 0) + goto start; =20 /* Evaluate the result of the previous operation, if there was one. */ switch (error) { - case SHRT_MAX: - goto start; - default: case 0: /* Success or local failure. Stop. */ - vc->error =3D error; + vc->cumul_error.error =3D error; vc->flags |=3D AFS_VL_CURSOR_STOP; - _leave(" =3D f [okay/local %d]", vc->ac.error); + _leave(" =3D f [okay/local %d]", vc->cumul_error.error); return false; =20 case -ECONNABORTED: /* The far side rejected the operation on some grounds. This * might involve the server being busy or the volume having been moved. */ - switch (vc->ac.abort_code) { + switch (abort_code) { case AFSVL_IO: case AFSVL_BADVOLOPER: case AFSVL_NOMEM: /* The server went weird. */ - vc->error =3D -EREMOTEIO; + afs_prioritise_error(&vc->cumul_error, -EREMOTEIO, abort_code); //write_lock(&vc->cell->vl_servers_lock); //vc->server_list->weird_mask |=3D 1 << vc->index; //write_unlock(&vc->cell->vl_servers_lock); goto next_server; =20 default: - vc->error =3D afs_abort_to_error(vc->ac.abort_code); + afs_prioritise_error(&vc->cumul_error, error, abort_code); goto failed; } =20 @@ -149,12 +149,12 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) case -ETIMEDOUT: case -ETIME: _debug("no conn %d", error); - vc->error =3D error; + afs_prioritise_error(&vc->cumul_error, error, 0); goto iterate_address; =20 case -ECONNRESET: _debug("call reset"); - vc->error =3D error; + afs_prioritise_error(&vc->cumul_error, error, 0); vc->flags |=3D AFS_VL_CURSOR_RETRY; goto next_server; =20 @@ -178,15 +178,19 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) goto failed; =20 error =3D afs_send_vl_probes(vc->cell->net, vc->key, vc->server_list); - if (error < 0) - goto failed_set_error; + if (error < 0) { + afs_prioritise_error(&vc->cumul_error, error, 0); + goto failed; + } =20 pick_server: _debug("pick [%lx]", vc->untried); =20 error =3D afs_wait_for_vl_probes(vc->server_list, vc->untried); - if (error < 0) - goto failed_set_error; + if (error < 0) { + afs_prioritise_error(&vc->cumul_error, error, 0); + goto failed; + } =20 /* Pick the untried server with the lowest RTT. */ vc->index =3D vc->server_list->preferred; @@ -249,6 +253,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) =20 _debug("VL address %d/%d", vc->ac.index, vc->ac.alist->nr_addrs); =20 + vc->call_responded =3D false; _leave(" =3D t %pISpc", rxrpc_kernel_remote_addr(vc->ac.alist->addrs[vc->= ac.index].peer)); return true; =20 @@ -264,25 +269,19 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) if (vc->flags & AFS_VL_CURSOR_RETRY) goto restart_from_beginning; =20 - e.error =3D -EDESTADDRREQ; - e.responded =3D false; for (i =3D 0; i < vc->server_list->nr_servers; i++) { struct afs_vlserver *s =3D vc->server_list->servers[i].server; =20 if (test_bit(AFS_VLSERVER_FL_RESPONDING, &s->flags)) - e.responded =3D true; - afs_prioritise_error(&e, READ_ONCE(s->probe.error), + vc->cumul_error.responded =3D true; + afs_prioritise_error(&vc->cumul_error, READ_ONCE(s->probe.error), s->probe.abort_code); } =20 - error =3D e.error; - -failed_set_error: - vc->error =3D error; failed: vc->flags |=3D AFS_VL_CURSOR_STOP; afs_end_cursor(&vc->ac); - _leave(" =3D f [failed %d]", vc->error); + _leave(" =3D f [failed %d]", vc->cumul_error.error); return false; } =20 @@ -305,7 +304,10 @@ static void afs_vl_dump_edestaddrreq(const struct afs_= vl_cursor *vc) pr_notice("DNS: src=3D%u st=3D%u lc=3D%x\n", cell->dns_source, cell->dns_status, cell->dns_lookup_count); pr_notice("VC: ut=3D%lx ix=3D%u ni=3D%hu fl=3D%hx err=3D%hd\n", - vc->untried, vc->index, vc->nr_iterations, vc->flags, vc->error); + vc->untried, vc->index, vc->nr_iterations, vc->flags, + vc->cumul_error.error); + pr_notice("VC: call er=3D%d ac=3D%d r=3D%u\n", + vc->call_error, vc->call_abort_code, vc->call_responded); =20 if (vc->server_list) { const struct afs_vlserver_list *sl =3D vc->server_list; @@ -329,9 +331,8 @@ static void afs_vl_dump_edestaddrreq(const struct afs_v= l_cursor *vc) } } =20 - pr_notice("AC: t=3D%lx ax=3D%u ac=3D%d er=3D%d r=3D%u ni=3D%u\n", - vc->ac.tried, vc->ac.index, vc->ac.abort_code, vc->ac.error, - vc->ac.responded, vc->ac.nr_iterations); + pr_notice("AC: t=3D%lx ax=3D%u ni=3D%u\n", + vc->ac.tried, vc->ac.index, vc->ac.nr_iterations); rcu_read_unlock(); } =20 @@ -342,17 +343,16 @@ int afs_end_vlserver_operation(struct afs_vl_cursor *= vc) { struct afs_net *net =3D vc->cell->net; =20 - if (vc->error =3D=3D -EDESTADDRREQ || - vc->error =3D=3D -EADDRNOTAVAIL || - vc->error =3D=3D -ENETUNREACH || - vc->error =3D=3D -EHOSTUNREACH) + switch (vc->cumul_error.error) { + case -EDESTADDRREQ: + case -EADDRNOTAVAIL: + case -ENETUNREACH: + case -EHOSTUNREACH: afs_vl_dump_edestaddrreq(vc); + break; + } =20 afs_end_cursor(&vc->ac); afs_put_vlserverlist(net, vc->server_list); - - if (vc->error =3D=3D -ECONNABORTED) - vc->error =3D afs_abort_to_error(vc->ac.abort_code); - - return vc->error; + return vc->cumul_error.error; } diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index 650534892a20..db7e94584e87 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -161,10 +161,13 @@ struct afs_vldb_entry *afs_vl_get_entry_by_name_u(str= uct afs_vl_cursor *vc, trace_afs_make_vl_call(call); afs_make_call(&vc->ac, call, GFP_KERNEL); afs_wait_for_call_to_complete(call, &vc->ac); + vc->call_abort_code =3D call->abort_code; + vc->call_error =3D call->error; + vc->call_responded =3D call->responded; afs_put_call(call); - if (vc->ac.error) { + if (vc->call_error) { kfree(entry); - return ERR_PTR(vc->ac.error); + return ERR_PTR(vc->call_error); } return entry; } @@ -305,11 +308,14 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_v= l_cursor *vc, trace_afs_make_vl_call(call); afs_make_call(&vc->ac, call, GFP_KERNEL); afs_wait_for_call_to_complete(call, &vc->ac); - alist =3D call->ret_alist; + vc->call_abort_code =3D call->abort_code; + vc->call_error =3D call->error; + vc->call_responded =3D call->responded; + alist =3D call->ret_alist; afs_put_call(call); - if (vc->ac.error) { + if (vc->call_error) { afs_put_addrlist(alist); - return ERR_PTR(vc->ac.error); + return ERR_PTR(vc->call_error); } return alist; } @@ -656,11 +662,14 @@ struct afs_addr_list *afs_yfsvl_get_endpoints(struct = afs_vl_cursor *vc, trace_afs_make_vl_call(call); afs_make_call(&vc->ac, call, GFP_KERNEL); afs_wait_for_call_to_complete(call, &vc->ac); - alist =3D call->ret_alist; + vc->call_abort_code =3D call->abort_code; + vc->call_error =3D call->error; + vc->call_responded =3D call->responded; + alist =3D call->ret_alist; afs_put_call(call); - if (vc->ac.error) { + if (vc->call_error) { afs_put_addrlist(alist); - return ERR_PTR(vc->ac.error); + return ERR_PTR(vc->call_error); } return alist; } @@ -769,11 +778,14 @@ char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *v= c) trace_afs_make_vl_call(call); afs_make_call(&vc->ac, call, GFP_KERNEL); afs_wait_for_call_to_complete(call, &vc->ac); - cellname =3D call->ret_str; + vc->call_abort_code =3D call->abort_code; + vc->call_error =3D call->error; + vc->call_responded =3D call->responded; + cellname =3D call->ret_str; afs_put_call(call); - if (vc->ac.error) { + if (vc->call_error) { kfree(cellname); - return ERR_PTR(vc->ac.error); + return ERR_PTR(vc->call_error); } return cellname; } From nobody Mon Dec 15 21:24:35 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 E9EA1C4332F for ; Wed, 13 Dec 2023 13:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379197AbjLMNv2 (ORCPT ); Wed, 13 Dec 2023 08:51:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441854AbjLMNut (ORCPT ); Wed, 13 Dec 2023 08:50:49 -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 3D93AD51 for ; Wed, 13 Dec 2023 05:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475440; 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=ilVhciIr/zJntY+SWgt0NsMblkInASK+jgWxf84YTc8=; b=NtrOCQBciwNTiORoTYkvdTB9mwHrKp7lTuMh0Lv9KRvzEOpw7TKqlesfLhXWuJTvQSYbHZ MLfWhikcMFD9DKNWG8o8zv8XiKw3P5H+QXk7vYV9YpTRC5wqBqQ7jZ62uuXNRbIru5RdZx k3dGdN337Dqpw957A7UhVINub0cI6Mg= 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-70-IKiB_2ndPR2GE8dDXUYRoA-1; Wed, 13 Dec 2023 08:50:34 -0500 X-MC-Unique: IKiB_2ndPR2GE8dDXUYRoA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 36E2829AC037; Wed, 13 Dec 2023 13:50:34 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47DED40C6EB9; Wed, 13 Dec 2023 13:50:33 +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 Subject: [PATCH v2 17/40] afs: Add a tracepoint for struct afs_addr_list Date: Wed, 13 Dec 2023 13:49:39 +0000 Message-ID: <20231213135003.367397-18-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a tracepoint to track the lifetime of the afs_addr_list struct. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/addr_list.c | 33 ++++++++++++++++++++++---- fs/afs/fs_probe.c | 4 ++-- fs/afs/internal.h | 10 +++----- fs/afs/rotate.c | 4 ++-- fs/afs/rxrpc.c | 4 ++-- fs/afs/server.c | 9 ++++---- fs/afs/vl_list.c | 11 +++++---- fs/afs/vl_rotate.c | 9 ++------ fs/afs/vlclient.c | 4 ++-- include/trace/events/afs.h | 47 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 100 insertions(+), 35 deletions(-) diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index a1f3c995e328..41ef0c879239 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -20,17 +20,39 @@ static void afs_free_addrlist(struct rcu_head *rcu) =20 for (i =3D 0; i < alist->nr_addrs; i++) rxrpc_kernel_put_peer(alist->addrs[i].peer); + trace_afs_alist(alist->debug_id, refcount_read(&alist->usage), afs_alist_= trace_free); + kfree(alist); } =20 /* * Release an address list. */ -void afs_put_addrlist(struct afs_addr_list *alist) +void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_trace re= ason) { - if (alist && refcount_dec_and_test(&alist->usage)) + unsigned int debug_id; + bool dead; + int r; + + if (!alist) + return; + debug_id =3D alist->debug_id; + dead =3D __refcount_dec_and_test(&alist->usage, &r); + trace_afs_alist(debug_id, r - 1, reason); + if (dead) call_rcu(&alist->rcu, afs_free_addrlist); } =20 +struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum a= fs_alist_trace reason) +{ + int r; + + if (alist) { + __refcount_inc(&alist->usage, &r); + trace_afs_alist(alist->debug_id, r + 1, reason); + } + return alist; +} + /* * Allocate an address list. */ @@ -38,6 +60,7 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr,= u16 service_id) { struct afs_addr_list *alist; unsigned int i; + static atomic_t debug_id; =20 _enter("%u,%u", nr, service_id); =20 @@ -50,9 +73,11 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr= , u16 service_id) =20 refcount_set(&alist->usage, 1); alist->max_addrs =3D nr; + alist->debug_id =3D atomic_inc_return(&debug_id); =20 for (i =3D 0; i < nr; i++) alist->addrs[i].service_id =3D service_id; + trace_afs_alist(alist->debug_id, 1, afs_alist_trace_alloc); return alist; } =20 @@ -217,7 +242,7 @@ struct afs_vlserver_list *afs_parse_text_addrs(struct a= fs_net *net, problem, p - text, (int)len, (int)len, text); ret =3D -EINVAL; error: - afs_put_addrlist(alist); + afs_put_addrlist(alist, afs_alist_trace_put_parse_error); error_vl: afs_put_vlserverlist(net, vllist); return ERR_PTR(ret); @@ -403,7 +428,7 @@ void afs_end_cursor(struct afs_addr_cursor *ac) ac->index !=3D alist->preferred && test_bit(ac->alist->preferred, &ac->tried)) WRITE_ONCE(alist->preferred, ac->index); - afs_put_addrlist(alist); + afs_put_addrlist(alist, afs_alist_trace_put_end_cursor); ac->alist =3D NULL; } } diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index fbb91ad775b9..18891492c0b4 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -205,7 +205,7 @@ void afs_fs_probe_fileserver(struct afs_net *net, struc= t afs_server *server, read_lock(&server->fs_lock); ac.alist =3D rcu_dereference_protected(server->addresses, lockdep_is_held(&server->fs_lock)); - afs_get_addrlist(ac.alist); + afs_get_addrlist(ac.alist, afs_alist_trace_get_probe); read_unlock(&server->fs_lock); =20 server->probed_at =3D jiffies; @@ -226,7 +226,7 @@ void afs_fs_probe_fileserver(struct afs_net *net, struc= t afs_server *server, afs_fs_probe_not_done(net, server, &ac); } =20 - afs_put_addrlist(ac.alist); + afs_put_addrlist(ac.alist, afs_alist_trace_put_probe); } =20 /* diff --git a/fs/afs/internal.h b/fs/afs/internal.h index d67c75d4d2bd..d00fda99f401 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -85,6 +85,7 @@ struct afs_addr_list { struct rcu_head rcu; refcount_t usage; u32 version; /* Version */ + unsigned int debug_id; unsigned char max_addrs; unsigned char nr_addrs; unsigned char preferred; /* Preferred address */ @@ -969,14 +970,9 @@ static inline bool afs_is_folio_dirty_mmapped(unsigned= long priv) /* * addr_list.c */ -static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list = *alist) -{ - if (alist) - refcount_inc(&alist->usage); - return alist; -} +struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum a= fs_alist_trace reason); extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 servi= ce_id); -extern void afs_put_addrlist(struct afs_addr_list *); +extern void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_t= race reason); extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *, const char *, size_t, char, unsigned short, unsigned short); diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index a778d53681fe..fa2ba45a5941 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -484,7 +484,7 @@ bool afs_select_fileserver(struct afs_operation *op) read_lock(&server->fs_lock); alist =3D rcu_dereference_protected(server->addresses, lockdep_is_held(&server->fs_lock)); - afs_get_addrlist(alist); + afs_get_addrlist(alist, afs_alist_trace_get_fsrotate_set); read_unlock(&server->fs_lock); =20 retry_server: @@ -493,7 +493,7 @@ bool afs_select_fileserver(struct afs_operation *op) if (!op->ac.alist) op->ac.alist =3D alist; else - afs_put_addrlist(alist); + afs_put_addrlist(alist, afs_alist_trace_put_retry_server); =20 op->ac.index =3D -1; =20 diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index 0b3e2f20b0e0..5bbf5a23af85 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -187,7 +187,7 @@ void afs_put_call(struct afs_call *call) call->type->destructor(call); =20 afs_unuse_server_notime(call->net, call->server, afs_server_trace_put_ca= ll); - afs_put_addrlist(call->alist); + afs_put_addrlist(call->alist, afs_alist_trace_put_call); kfree(call->request); =20 trace_afs_call(call->debug_id, afs_call_trace_free, 0, o, @@ -315,7 +315,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) atomic_read(&call->net->nr_outstanding_calls)); =20 call->addr_ix =3D ac->index; - call->alist =3D afs_get_addrlist(ac->alist); + call->alist =3D afs_get_addrlist(ac->alist, afs_alist_trace_get_make_call= ); =20 /* Work out the length we're going to transmit. This is awkward for * calls such as FS.StoreData where there's an extra injection of data diff --git a/fs/afs/server.c b/fs/afs/server.c index f7791ef13618..6c13f00b10d8 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -275,13 +275,13 @@ struct afs_server *afs_lookup_server(struct afs_cell = *cell, struct key *key, =20 candidate =3D afs_alloc_server(cell, uuid, alist); if (!candidate) { - afs_put_addrlist(alist); + afs_put_addrlist(alist, afs_alist_trace_put_server_oom); return ERR_PTR(-ENOMEM); } =20 server =3D afs_install_server(cell, candidate); if (server !=3D candidate) { - afs_put_addrlist(alist); + afs_put_addrlist(alist, afs_alist_trace_put_server_dup); kfree(candidate); } else { /* Immediately dispatch an asynchronous probe to each interface @@ -421,7 +421,8 @@ static void afs_server_rcu(struct rcu_head *rcu) =20 trace_afs_server(server->debug_id, refcount_read(&server->ref), atomic_read(&server->active), afs_server_trace_free); - afs_put_addrlist(rcu_access_pointer(server->addresses)); + afs_put_addrlist(rcu_access_pointer(server->addresses), + afs_alist_trace_put_server); kfree(server); } =20 @@ -643,7 +644,7 @@ static noinline bool afs_update_server_record(struct af= s_operation *op, write_unlock(&server->fs_lock); } =20 - afs_put_addrlist(discard); + afs_put_addrlist(discard, afs_alist_trace_put_server_update); _leave(" =3D t"); return true; } diff --git a/fs/afs/vl_list.c b/fs/afs/vl_list.c index ba89140eee9e..3a2875933261 100644 --- a/fs/afs/vl_list.c +++ b/fs/afs/vl_list.c @@ -33,7 +33,8 @@ static void afs_vlserver_rcu(struct rcu_head *rcu) { struct afs_vlserver *vlserver =3D container_of(rcu, struct afs_vlserver, = rcu); =20 - afs_put_addrlist(rcu_access_pointer(vlserver->addresses)); + afs_put_addrlist(rcu_access_pointer(vlserver->addresses), + afs_alist_trace_put_vlserver); kfree_rcu(vlserver, rcu); } =20 @@ -145,7 +146,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struc= t afs_net *net, =20 error: *_b =3D b; - afs_put_addrlist(alist); + afs_put_addrlist(alist, afs_alist_trace_put_parse_error); return ERR_PTR(ret); } =20 @@ -260,7 +261,7 @@ struct afs_vlserver_list *afs_extract_vlserver_list(str= uct afs_cell *cell, =20 if (vllist->nr_servers >=3D nr_servers) { _debug("skip %u >=3D %u", vllist->nr_servers, nr_servers); - afs_put_addrlist(addrs); + afs_put_addrlist(addrs, afs_alist_trace_put_parse_empty); afs_put_vlserver(cell->net, server); continue; } @@ -269,7 +270,7 @@ struct afs_vlserver_list *afs_extract_vlserver_list(str= uct afs_cell *cell, addrs->status =3D bs.status; =20 if (addrs->nr_addrs =3D=3D 0) { - afs_put_addrlist(addrs); + afs_put_addrlist(addrs, afs_alist_trace_put_parse_empty); if (!rcu_access_pointer(server->addresses)) { afs_put_vlserver(cell->net, server); continue; @@ -281,7 +282,7 @@ struct afs_vlserver_list *afs_extract_vlserver_list(str= uct afs_cell *cell, old =3D rcu_replace_pointer(server->addresses, old, lockdep_is_held(&server->lock)); write_unlock(&server->lock); - afs_put_addrlist(old); + afs_put_addrlist(old, afs_alist_trace_put_vlserver_old); } =20 =20 diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index 7ae73418697d..e8fbbeb551bb 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -231,16 +231,11 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) read_lock(&vlserver->lock); alist =3D rcu_dereference_protected(vlserver->addresses, lockdep_is_held(&vlserver->lock)); - afs_get_addrlist(alist); + afs_get_addrlist(alist, afs_alist_trace_get_vlrotate_set); read_unlock(&vlserver->lock); =20 memset(&vc->ac, 0, sizeof(vc->ac)); - - if (!vc->ac.alist) - vc->ac.alist =3D alist; - else - afs_put_addrlist(alist); - + vc->ac.alist =3D alist; vc->ac.index =3D -1; =20 iterate_address: diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index db7e94584e87..8dea7b56b75a 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -314,7 +314,7 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_= cursor *vc, alist =3D call->ret_alist; afs_put_call(call); if (vc->call_error) { - afs_put_addrlist(alist); + afs_put_addrlist(alist, afs_alist_trace_put_getaddru); return ERR_PTR(vc->call_error); } return alist; @@ -668,7 +668,7 @@ struct afs_addr_list *afs_yfsvl_get_endpoints(struct af= s_vl_cursor *vc, alist =3D call->ret_alist; afs_put_call(call); if (vc->call_error) { - afs_put_addrlist(alist); + afs_put_addrlist(alist, afs_alist_trace_put_getaddru); return ERR_PTR(vc->call_error); } return alist; diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index 597677acc6b1..ed91666ca4cc 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -202,6 +202,27 @@ enum yfs_cm_operation { EM(afs_cell_trace_use_sbi, "USE sbi ") \ E_(afs_cell_trace_wait, "WAIT ") =20 +#define afs_alist_traces \ + EM(afs_alist_trace_alloc, "ALLOC ") \ + EM(afs_alist_trace_get_fsrotate_set, "GET fs-rot") \ + EM(afs_alist_trace_get_make_call, "GET mkcall") \ + EM(afs_alist_trace_get_probe, "GET probe ") \ + EM(afs_alist_trace_get_vlrotate_set, "GET vl-rot") \ + EM(afs_alist_trace_put_call, "PUT call ") \ + EM(afs_alist_trace_put_end_cursor, "PUT endcur") \ + EM(afs_alist_trace_put_getaddru, "PUT GtAdrU") \ + EM(afs_alist_trace_put_parse_empty, "PUT p-empt") \ + EM(afs_alist_trace_put_parse_error, "PUT p-err ") \ + EM(afs_alist_trace_put_probe, "PUT probe ") \ + EM(afs_alist_trace_put_retry_server, "PUT retry ") \ + EM(afs_alist_trace_put_server, "PUT server") \ + EM(afs_alist_trace_put_server_dup, "PUT sv-dup") \ + EM(afs_alist_trace_put_server_oom, "PUT sv-oom") \ + EM(afs_alist_trace_put_server_update, "PUT sv-upd") \ + EM(afs_alist_trace_put_vlserver, "PUT vlsrvr") \ + EM(afs_alist_trace_put_vlserver_old, "PUT vs-old") \ + E_(afs_alist_trace_free, "FREE ") + #define afs_fs_operations \ EM(afs_FS_FetchData, "FS.FetchData") \ EM(afs_FS_FetchStatus, "FS.FetchStatus") \ @@ -420,6 +441,7 @@ enum yfs_cm_operation { #define EM(a, b) a, #define E_(a, b) a =20 +enum afs_alist_trace { afs_alist_traces } __mode(byte); enum afs_call_trace { afs_call_traces } __mode(byte); enum afs_cb_break_reason { afs_cb_break_reasons } __mode(byte); enum afs_cell_trace { afs_cell_traces } __mode(byte); @@ -443,6 +465,7 @@ enum afs_volume_trace { afs_volume_traces } __mode(byt= e); #define EM(a, b) TRACE_DEFINE_ENUM(a); #define E_(a, b) TRACE_DEFINE_ENUM(a); =20 +afs_alist_traces; afs_call_traces; afs_server_traces; afs_cell_traces; @@ -1330,6 +1353,30 @@ TRACE_EVENT(afs_cell, __entry->active) ); =20 +TRACE_EVENT(afs_alist, + TP_PROTO(unsigned int alist_debug_id, int ref, enum afs_alist_trace r= eason), + + TP_ARGS(alist_debug_id, ref, reason), + + TP_STRUCT__entry( + __field(unsigned int, alist) + __field(int, ref) + __field(int, active) + __field(int, reason) + ), + + TP_fast_assign( + __entry->alist =3D alist_debug_id; + __entry->ref =3D ref; + __entry->reason =3D reason; + ), + + TP_printk("AL=3D%08x %s r=3D%d", + __entry->alist, + __print_symbolic(__entry->reason, afs_alist_traces), + __entry->ref) + ); + #endif /* _TRACE_AFS_H */ =20 /* This part must be outside protection */ From nobody Mon Dec 15 21:24:35 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 9A79FC4167D for ; Wed, 13 Dec 2023 13:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379354AbjLMNvY (ORCPT ); Wed, 13 Dec 2023 08:51:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441846AbjLMNut (ORCPT ); Wed, 13 Dec 2023 08:50:49 -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 297DFD5A for ; Wed, 13 Dec 2023 05:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475441; 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=7xzcS2NI7S1ySO2ne1rnZ89Eygq6I+3plk47rD6c6MM=; b=Svs3BP94N1zpJkJFnDnf6hAYVIbf5+SjkOcbpUXWpVymFY5QxSOnq7tBFPTw+f7548L/jL ikIvdLDGc+P2ShLEntSmn+Qr+um4C89t45u/gWLJwU4OX59sPVopOYMRwqO2XeFbT0ysu+ 9NHw3IfQp0Tj+86Lwr6o8dIV27mrFMw= 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-240-5vQ5-NYQMeKSZu0dQMsy4A-1; Wed, 13 Dec 2023 08:50:36 -0500 X-MC-Unique: 5vQ5-NYQMeKSZu0dQMsy4A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 BD1598828C6; Wed, 13 Dec 2023 13:50:35 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id D773040C6EB9; Wed, 13 Dec 2023 13:50:34 +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 Subject: [PATCH v2 18/40] afs: Rename some fields Date: Wed, 13 Dec 2023 13:49:40 +0000 Message-ID: <20231213135003.367397-19-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rename the ->index and ->untried fields of the afs_vl_cursor and afs_operation struct to ->server_index and ->untried_servers to avoid confusion with address iteration fields when those get folded in. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/internal.h | 8 ++++---- fs/afs/rotate.c | 36 ++++++++++++++++++------------------ fs/afs/vl_rotate.c | 32 ++++++++++++++++---------------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/fs/afs/internal.h b/fs/afs/internal.h index d00fda99f401..a321fb83aba1 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -747,11 +747,11 @@ struct afs_vl_cursor { struct afs_vlserver_list *server_list; /* Current server list (pins ref) = */ struct afs_vlserver *server; /* Server on which this resides */ struct key *key; /* Key for the server */ - unsigned long untried; /* Bitmask of untried servers */ + unsigned long untried_servers; /* Bitmask of untried servers */ struct afs_error cumul_error; /* Cumulative error */ s32 call_abort_code; - short index; /* Current server */ short call_error; /* Error from single call */ + short server_index; /* Current server */ unsigned short flags; #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */ #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */ @@ -864,8 +864,8 @@ struct afs_operation { struct afs_server_list *server_list; /* Current server list (pins ref) */ struct afs_server *server; /* Server we're using (ref pinned by server_li= st) */ struct afs_call *call; - unsigned long untried; /* Bitmask of untried servers */ - short index; /* Current server */ + unsigned long untried_servers; /* Bitmask of untried servers */ + short server_index; /* Current server */ short nr_iterations; /* Number of server iterations */ bool call_responded; /* T if the current address responded */ =20 diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index fa2ba45a5941..6c1aa9bafc82 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -32,8 +32,8 @@ static bool afs_start_fs_iteration(struct afs_operation *= op, lockdep_is_held(&op->volume->servers_lock))); read_unlock(&op->volume->servers_lock); =20 - op->untried =3D (1UL << op->server_list->nr_servers) - 1; - op->index =3D READ_ONCE(op->server_list->preferred); + op->untried_servers =3D (1UL << op->server_list->nr_servers) - 1; + op->server_index =3D READ_ONCE(op->server_list->preferred); =20 cb_server =3D vnode->cb_server; if (cb_server) { @@ -41,7 +41,7 @@ static bool afs_start_fs_iteration(struct afs_operation *= op, for (i =3D 0; i < op->server_list->nr_servers; i++) { server =3D op->server_list->servers[i].server; if (server =3D=3D cb_server) { - op->index =3D i; + op->server_index =3D i; goto found_interest; } } @@ -120,7 +120,7 @@ bool afs_select_fileserver(struct afs_operation *op) =20 _enter("OP=3D%x+%x,%llx,%lx[%d],%lx[%d],%d,%d", op->debug_id, op->nr_iterations, op->volume->vid, - op->untried, op->index, + op->untried_servers, op->server_index, op->ac.tried, op->ac.index, error, abort_code); =20 @@ -172,7 +172,7 @@ bool afs_select_fileserver(struct afs_operation *op) } =20 write_lock(&op->volume->servers_lock); - op->server_list->vnovol_mask |=3D 1 << op->index; + op->server_list->vnovol_mask |=3D 1 << op->server_index; write_unlock(&op->volume->servers_lock); =20 set_bit(AFS_VOLUME_NEEDS_UPDATE, &op->volume->flags); @@ -419,9 +419,9 @@ bool afs_select_fileserver(struct afs_operation *op) _debug("__ VOL %llx __", op->volume->vid); =20 pick_server: - _debug("pick [%lx]", op->untried); + _debug("pick [%lx]", op->untried_servers); =20 - error =3D afs_wait_for_fs_probes(op->server_list, op->untried); + error =3D afs_wait_for_fs_probes(op->server_list, op->untried_servers); if (error < 0) { afs_op_set_error(op, error); goto failed; @@ -431,40 +431,40 @@ bool afs_select_fileserver(struct afs_operation *op) * callbacks, we stick with the server we're already using if we can. */ if (op->server) { - _debug("server %u", op->index); - if (test_bit(op->index, &op->untried)) + _debug("server %u", op->server_index); + if (test_bit(op->server_index, &op->untried_servers)) goto selected_server; op->server =3D NULL; _debug("no server"); } =20 - op->index =3D -1; + op->server_index =3D -1; rtt =3D UINT_MAX; for (i =3D 0; i < op->server_list->nr_servers; i++) { struct afs_server *s =3D op->server_list->servers[i].server; =20 - if (!test_bit(i, &op->untried) || + if (!test_bit(i, &op->untried_servers) || !test_bit(AFS_SERVER_FL_RESPONDING, &s->flags)) continue; if (s->probe.rtt <=3D rtt) { - op->index =3D i; + op->server_index =3D i; rtt =3D s->probe.rtt; } } =20 - if (op->index =3D=3D -1) + if (op->server_index =3D=3D -1) goto no_more_servers; =20 selected_server: - _debug("use %d", op->index); - __clear_bit(op->index, &op->untried); + _debug("use %d", op->server_index); + __clear_bit(op->server_index, &op->untried_servers); =20 /* We're starting on a different fileserver from the list. We need to * check it, create a callback intercept, find its address list and * probe its capabilities before we use it. */ ASSERTCMP(op->ac.alist, =3D=3D, NULL); - server =3D op->server_list->servers[op->index].server; + server =3D op->server_list->servers[op->server_index].server; =20 if (!afs_check_server_record(op, server)) goto failed; @@ -506,7 +506,7 @@ bool afs_select_fileserver(struct afs_operation *op) goto out_of_addresses; =20 _debug("address [%u] %u/%u %pISp", - op->index, op->ac.index, op->ac.alist->nr_addrs, + op->server_index, op->ac.index, op->ac.alist->nr_addrs, rxrpc_kernel_remote_addr(op->ac.alist->addrs[op->ac.index].peer)); =20 op->call_responded =3D false; @@ -581,7 +581,7 @@ void afs_dump_edestaddrreq(const struct afs_operation *= op) op->file[0].cb_break_before, op->file[1].cb_break_before, op->flags, op->cumul_error.error); pr_notice("OP: ut=3D%lx ix=3D%d ni=3D%u\n", - op->untried, op->index, op->nr_iterations); + op->untried_servers, op->server_index, op->nr_iterations); pr_notice("OP: call er=3D%d ac=3D%d r=3D%u\n", op->call_error, op->call_abort_code, op->call_responded); =20 diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index e8fbbeb551bb..f895eb94129e 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -78,8 +78,8 @@ static bool afs_start_vl_iteration(struct afs_vl_cursor *= vc) if (!vc->server_list->nr_servers) return false; =20 - vc->untried =3D (1UL << vc->server_list->nr_servers) - 1; - vc->index =3D -1; + vc->untried_servers =3D (1UL << vc->server_list->nr_servers) - 1; + vc->server_index =3D -1; return true; } =20 @@ -98,7 +98,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) vc->nr_iterations++; =20 _enter("%lx[%d],%lx[%d],%d,%d", - vc->untried, vc->index, + vc->untried_servers, vc->server_index, vc->ac.tried, vc->ac.index, error, abort_code); =20 @@ -131,7 +131,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) /* The server went weird. */ afs_prioritise_error(&vc->cumul_error, -EREMOTEIO, abort_code); //write_lock(&vc->cell->vl_servers_lock); - //vc->server_list->weird_mask |=3D 1 << vc->index; + //vc->server_list->weird_mask |=3D 1 << vc->server_index; //write_unlock(&vc->cell->vl_servers_lock); goto next_server; =20 @@ -184,46 +184,46 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) } =20 pick_server: - _debug("pick [%lx]", vc->untried); + _debug("pick [%lx]", vc->untried_servers); =20 - error =3D afs_wait_for_vl_probes(vc->server_list, vc->untried); + error =3D afs_wait_for_vl_probes(vc->server_list, vc->untried_servers); if (error < 0) { afs_prioritise_error(&vc->cumul_error, error, 0); goto failed; } =20 /* Pick the untried server with the lowest RTT. */ - vc->index =3D vc->server_list->preferred; - if (test_bit(vc->index, &vc->untried)) + vc->server_index =3D vc->server_list->preferred; + if (test_bit(vc->server_index, &vc->untried_servers)) goto selected_server; =20 - vc->index =3D -1; + vc->server_index =3D -1; rtt =3D UINT_MAX; for (i =3D 0; i < vc->server_list->nr_servers; i++) { struct afs_vlserver *s =3D vc->server_list->servers[i].server; =20 - if (!test_bit(i, &vc->untried) || + if (!test_bit(i, &vc->untried_servers) || !test_bit(AFS_VLSERVER_FL_RESPONDING, &s->flags)) continue; if (s->probe.rtt <=3D rtt) { - vc->index =3D i; + vc->server_index =3D i; rtt =3D s->probe.rtt; } } =20 - if (vc->index =3D=3D -1) + if (vc->server_index =3D=3D -1) goto no_more_servers; =20 selected_server: - _debug("use %d", vc->index); - __clear_bit(vc->index, &vc->untried); + _debug("use %d", vc->server_index); + __clear_bit(vc->server_index, &vc->untried_servers); =20 /* We're starting on a different vlserver from the list. We need to * check it, find its address list and probe its capabilities before we * use it. */ ASSERTCMP(vc->ac.alist, =3D=3D, NULL); - vlserver =3D vc->server_list->servers[vc->index].server; + vlserver =3D vc->server_list->servers[vc->server_index].server; vc->server =3D vlserver; =20 _debug("USING VLSERVER: %s", vlserver->name); @@ -299,7 +299,7 @@ static void afs_vl_dump_edestaddrreq(const struct afs_v= l_cursor *vc) pr_notice("DNS: src=3D%u st=3D%u lc=3D%x\n", cell->dns_source, cell->dns_status, cell->dns_lookup_count); pr_notice("VC: ut=3D%lx ix=3D%u ni=3D%hu fl=3D%hx err=3D%hd\n", - vc->untried, vc->index, vc->nr_iterations, vc->flags, + vc->untried_servers, vc->server_index, vc->nr_iterations, vc->flags, vc->cumul_error.error); pr_notice("VC: call er=3D%d ac=3D%d r=3D%u\n", vc->call_error, vc->call_abort_code, vc->call_responded); From nobody Mon Dec 15 21:24:35 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 06CE8C4332F for ; Wed, 13 Dec 2023 13:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379388AbjLMNvg (ORCPT ); Wed, 13 Dec 2023 08:51:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441867AbjLMNuu (ORCPT ); Wed, 13 Dec 2023 08:50:50 -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 A3ED2D67 for ; Wed, 13 Dec 2023 05:50:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475441; 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=Hjib9QLALMAPiIUWhwPhaMFho7TCZU0gCuU1atCayiM=; b=aRYVmbc/TYfABRyrEdDbLcU6QaCaB+/P0usDYwghf72PZGMLZHXll+faQknRmhP0TBFZyd Zx9BVas5KfpseqDCUfH+lCQDrcFJJrGU3NWGyYvLGagukVIicnW7Dh4TBEiJeS8GByuL6C gLJIe2f521zrTAD89Z04iMX/lwK6VA4= 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-589-esSdtdwpOPKPHkQjb-ABwQ-1; Wed, 13 Dec 2023 08:50:37 -0500 X-MC-Unique: esSdtdwpOPKPHkQjb-ABwQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 52A843C2A1D4; Wed, 13 Dec 2023 13:50:37 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C3A43C25; Wed, 13 Dec 2023 13:50:36 +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 Subject: [PATCH v2 19/40] afs: Use peer + service_id as call address Date: Wed, 13 Dec 2023 13:49:41 +0000 Message-ID: <20231213135003.367397-20-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the rxrpc_peer plus the service ID as the call address instead of passing in a sockaddr_srx down to rxrpc. The peer record is obtained by using rxrpc_kernel_get_peer(). This avoids the need to repeatedly look up the peer and allows rxrpc to hold on to resources for it. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/addr_list.c | 10 +++------- fs/afs/fs_probe.c | 4 ++-- fs/afs/fsclient.c | 14 +++++++++----- fs/afs/internal.h | 18 +++++++++++------- fs/afs/rxrpc.c | 12 ++++++------ fs/afs/server.c | 1 + fs/afs/vl_list.c | 3 ++- fs/afs/vl_probe.c | 4 ++-- fs/afs/vlclient.c | 14 ++++++++++++-- 9 files changed, 48 insertions(+), 32 deletions(-) diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index 41ef0c879239..032e6963c5d8 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -56,13 +56,12 @@ struct afs_addr_list *afs_get_addrlist(struct afs_addr_= list *alist, enum afs_ali /* * Allocate an address list. */ -struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id) +struct afs_addr_list *afs_alloc_addrlist(unsigned int nr) { struct afs_addr_list *alist; - unsigned int i; static atomic_t debug_id; =20 - _enter("%u,%u", nr, service_id); + _enter("%u", nr); =20 if (nr > AFS_MAX_ADDRESSES) nr =3D AFS_MAX_ADDRESSES; @@ -74,9 +73,6 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr,= u16 service_id) refcount_set(&alist->usage, 1); alist->max_addrs =3D nr; alist->debug_id =3D atomic_inc_return(&debug_id); - - for (i =3D 0; i < nr; i++) - alist->addrs[i].service_id =3D service_id; trace_afs_alist(alist->debug_id, 1, afs_alist_trace_alloc); return alist; } @@ -150,7 +146,7 @@ struct afs_vlserver_list *afs_parse_text_addrs(struct a= fs_net *net, if (!vllist->servers[0].server) goto error_vl; =20 - alist =3D afs_alloc_addrlist(nr, service); + alist =3D afs_alloc_addrlist(nr); if (!alist) goto error; =20 diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index 18891492c0b4..337673e65f87 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -154,12 +154,12 @@ void afs_fileserver_probe_result(struct afs_call *cal= l) if (call->service_id =3D=3D YFS_FS_SERVICE) { server->probe.is_yfs =3D true; set_bit(AFS_SERVER_FL_IS_YFS, &server->flags); - addr->service_id =3D call->service_id; + server->service_id =3D call->service_id; } else { server->probe.not_yfs =3D true; if (!server->probe.is_yfs) { clear_bit(AFS_SERVER_FL_IS_YFS, &server->flags); - addr->service_id =3D call->service_id; + server->service_id =3D call->service_id; } cap0 =3D ntohl(call->tmp); if (cap0 & AFS3_VICED_CAPABILITY_64BITFILES) diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index 2a56dea22519..2b64641b20a4 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -1620,7 +1620,9 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, if (!call) return -ENOMEM; =20 - call->key =3D key; + call->key =3D key; + call->peer =3D rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer); + call->service_id =3D server->service_id; =20 /* marshall the parameters */ bp =3D call->request; @@ -1722,10 +1724,12 @@ bool afs_fs_get_capabilities(struct afs_net *net, s= truct afs_server *server, if (!call) return false; =20 - call->key =3D key; - call->server =3D afs_use_server(server, afs_server_trace_get_caps); - call->upgrade =3D true; - call->async =3D true; + call->key =3D key; + call->server =3D afs_use_server(server, afs_server_trace_get_caps); + call->peer =3D rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer); + call->service_id =3D server->service_id; + call->upgrade =3D true; + call->async =3D true; call->max_lifespan =3D AFS_PROBE_MAX_LIFESPAN; =20 /* marshall the parameters */ diff --git a/fs/afs/internal.h b/fs/afs/internal.h index a321fb83aba1..3a2aa2af072a 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -74,7 +74,6 @@ enum afs_call_state { =20 struct afs_address { struct rxrpc_peer *peer; - u16 service_id; short last_error; /* Last error from this address */ }; =20 @@ -108,6 +107,7 @@ struct afs_call { struct work_struct async_work; /* async I/O processor */ struct work_struct work; /* actual work processor */ struct rxrpc_call *rxcall; /* RxRPC call handle */ + struct rxrpc_peer *peer; /* Remote endpoint */ struct key *key; /* security for this call */ struct afs_net *net; /* The network namespace */ struct afs_server *server; /* The fileserver record if fs op (pins ref) */ @@ -435,6 +435,7 @@ struct afs_vlserver { #define AFS_VLSERVER_PROBE_LOCAL_FAILURE 0x08 /* A local failure prevented= a probe */ } probe; =20 + u16 service_id; /* Service ID we're using */ u16 port; u16 name_len; /* Length of name */ char name[]; /* Server name, case-flattened */ @@ -527,6 +528,7 @@ struct afs_server { refcount_t ref; /* Object refcount */ atomic_t active; /* Active user count */ u32 addr_version; /* Address list version */ + u16 service_id; /* Service ID we're using. */ unsigned int rtt; /* Server's current RTT in uS */ unsigned int debug_id; /* Debugging ID for traces */ =20 @@ -971,7 +973,7 @@ static inline bool afs_is_folio_dirty_mmapped(unsigned = long priv) * addr_list.c */ struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum a= fs_alist_trace reason); -extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 servi= ce_id); +extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr); extern void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_t= race reason); extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *, const char *, size_t, char, @@ -1318,11 +1320,13 @@ extern int afs_protocol_error(struct afs_call *, en= um afs_eproto_cause); static inline void afs_make_op_call(struct afs_operation *op, struct afs_c= all *call, gfp_t gfp) { - op->call =3D call; - op->type =3D call->type; - call->op =3D op; - call->key =3D op->key; - call->intr =3D !(op->flags & AFS_OPERATION_UNINTR); + op->call =3D call; + op->type =3D call->type; + call->op =3D op; + call->key =3D op->key; + call->intr =3D !(op->flags & AFS_OPERATION_UNINTR); + call->peer =3D rxrpc_kernel_get_peer(op->ac.alist->addrs[op->ac.index].pe= er); + call->service_id =3D op->server->service_id; afs_make_call(&op->ac, call, gfp); } =20 diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index 5bbf5a23af85..e8490b3e9d37 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -178,6 +178,8 @@ void afs_put_call(struct afs_call *call) ASSERT(!work_pending(&call->async_work)); ASSERT(call->type->name !=3D NULL); =20 + rxrpc_kernel_put_peer(call->peer); + if (call->rxcall) { rxrpc_kernel_shutdown_call(net->socket, call->rxcall); rxrpc_kernel_put_call(net->socket, call->rxcall); @@ -296,8 +298,6 @@ static void afs_notify_end_request_tx(struct sock *sock, */ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_= t gfp) { - struct afs_address *addr =3D &ac->alist->addrs[ac->index]; - struct rxrpc_peer *peer =3D addr->peer; struct rxrpc_call *rxcall; struct msghdr msg; struct kvec iov[1]; @@ -305,7 +305,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) s64 tx_total_len; int ret; =20 - _enter(",{%pISp},", rxrpc_kernel_remote_addr(addr->peer)); + _enter(",{%pISp+%u},", rxrpc_kernel_remote_addr(call->peer), call->servic= e_id); =20 ASSERT(call->type !=3D NULL); ASSERT(call->type->name !=3D NULL); @@ -334,7 +334,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) } =20 /* create a call */ - rxcall =3D rxrpc_kernel_begin_call(call->net->socket, peer, call->key, + rxcall =3D rxrpc_kernel_begin_call(call->net->socket, call->peer, call->k= ey, (unsigned long)call, tx_total_len, call->max_lifespan, @@ -342,7 +342,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) (call->async ? afs_wake_up_async_call : afs_wake_up_call_waiter), - addr->service_id, + call->service_id, call->upgrade, (call->intr ? RXRPC_PREINTERRUPTIBLE : RXRPC_UNINTERRUPTIBLE), @@ -462,7 +462,7 @@ static void afs_log_error(struct afs_call *call, s32 re= mote_abort) max =3D m + 1; pr_notice("kAFS: Peer reported %s failure on %s [%pISp]\n", msg, call->type->name, - rxrpc_kernel_remote_addr(call->alist->addrs[call->addr_ix].peer)); + rxrpc_kernel_remote_addr(call->peer)); } } =20 diff --git a/fs/afs/server.c b/fs/afs/server.c index 6c13f00b10d8..e2c7f65eea33 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -215,6 +215,7 @@ static struct afs_server *afs_alloc_server(struct afs_c= ell *cell, spin_lock_init(&server->probe_lock); server->cell =3D cell; server->rtt =3D UINT_MAX; + server->service_id =3D FS_SERVICE; =20 afs_inc_servers_outstanding(net); trace_afs_server(server->debug_id, 1, 1, afs_server_trace_alloc); diff --git a/fs/afs/vl_list.c b/fs/afs/vl_list.c index 3a2875933261..5c4cd71caccf 100644 --- a/fs/afs/vl_list.c +++ b/fs/afs/vl_list.c @@ -23,6 +23,7 @@ struct afs_vlserver *afs_alloc_vlserver(const char *name,= size_t name_len, spin_lock_init(&vlserver->probe_lock); vlserver->rtt =3D UINT_MAX; vlserver->name_len =3D name_len; + vlserver->service_id =3D VL_SERVICE; vlserver->port =3D port; memcpy(vlserver->name, name, name_len); } @@ -92,7 +93,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct = afs_net *net, const u8 *b =3D *_b; int ret =3D -EINVAL; =20 - alist =3D afs_alloc_addrlist(nr_addrs, VL_SERVICE); + alist =3D afs_alloc_addrlist(nr_addrs); if (!alist) return ERR_PTR(-ENOMEM); if (nr_addrs =3D=3D 0) diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c index 138f5715619d..d9a99ba9fc78 100644 --- a/fs/afs/vl_probe.c +++ b/fs/afs/vl_probe.c @@ -107,12 +107,12 @@ void afs_vlserver_probe_result(struct afs_call *call) if (call->service_id =3D=3D YFS_VL_SERVICE) { server->probe.flags |=3D AFS_VLSERVER_PROBE_IS_YFS; set_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags); - addr->service_id =3D call->service_id; + server->service_id =3D call->service_id; } else { server->probe.flags |=3D AFS_VLSERVER_PROBE_NOT_YFS; if (!(server->probe.flags & AFS_VLSERVER_PROBE_IS_YFS)) { clear_bit(AFS_VLSERVER_FL_IS_YFS, &server->flags); - addr->service_id =3D call->service_id; + server->service_id =3D call->service_id; } } =20 diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index 8dea7b56b75a..4bf98a38c3a1 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -149,6 +149,8 @@ struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struc= t afs_vl_cursor *vc, call->key =3D vc->key; call->ret_vldb =3D entry; call->max_lifespan =3D AFS_VL_MAX_LIFESPAN; + call->peer =3D rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].pe= er); + call->service_id =3D vc->server->service_id; =20 /* Marshall the parameters */ bp =3D call->request; @@ -211,7 +213,7 @@ static int afs_deliver_vl_get_addrs_u(struct afs_call *= call) count =3D ntohl(*bp); =20 nentries =3D min(nentries, count); - alist =3D afs_alloc_addrlist(nentries, FS_SERVICE); + alist =3D afs_alloc_addrlist(nentries); if (!alist) return -ENOMEM; alist->version =3D uniquifier; @@ -288,6 +290,8 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_= cursor *vc, call->key =3D vc->key; call->ret_alist =3D NULL; call->max_lifespan =3D AFS_VL_MAX_LIFESPAN; + call->peer =3D rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].pe= er); + call->service_id =3D vc->server->service_id; =20 /* Marshall the parameters */ bp =3D call->request; @@ -407,6 +411,8 @@ struct afs_call *afs_vl_get_capabilities(struct afs_net= *net, call->key =3D key; call->vlserver =3D afs_get_vlserver(server); call->server_index =3D server_index; + call->peer =3D rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer); + call->service_id =3D server->service_id; call->upgrade =3D true; call->async =3D true; call->max_lifespan =3D AFS_PROBE_MAX_LIFESPAN; @@ -462,7 +468,7 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_c= all *call) if (call->count > YFS_MAXENDPOINTS) return afs_protocol_error(call, afs_eproto_yvl_fsendpt_num); =20 - alist =3D afs_alloc_addrlist(call->count, FS_SERVICE); + alist =3D afs_alloc_addrlist(call->count); if (!alist) return -ENOMEM; alist->version =3D uniquifier; @@ -652,6 +658,8 @@ struct afs_addr_list *afs_yfsvl_get_endpoints(struct af= s_vl_cursor *vc, call->key =3D vc->key; call->ret_alist =3D NULL; call->max_lifespan =3D AFS_VL_MAX_LIFESPAN; + call->peer =3D rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].pe= er); + call->service_id =3D vc->server->service_id; =20 /* Marshall the parameters */ bp =3D call->request; @@ -769,6 +777,8 @@ char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc) call->key =3D vc->key; call->ret_str =3D NULL; call->max_lifespan =3D AFS_VL_MAX_LIFESPAN; + call->peer =3D rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].pe= er); + call->service_id =3D vc->server->service_id; =20 /* marshall the parameters */ bp =3D call->request; From nobody Mon Dec 15 21:24:35 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 C24E7C4332F for ; Wed, 13 Dec 2023 13:52:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441844AbjLMNvx (ORCPT ); Wed, 13 Dec 2023 08:51:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379073AbjLMNuz (ORCPT ); Wed, 13 Dec 2023 08:50:55 -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 E6219D72 for ; Wed, 13 Dec 2023 05:50:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475442; 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=V56lkL4K1DOKJM1gg69OrG+ZBlyPTtK87EWqP0nAyjU=; b=Dfts4+MmYdCn2TD4IICP842EpCde0ZJrEiWntJixMDdCrQ1xyk8+Pv9lQf4dloeVx80rUK 0Wi5ZXccilUrDoOQ/WMLeISi93EDP0sISTUwE7ghAGit84LcyBTI4KDIjoUOpPEAstS+Vr CL0J785nSjg8GTu9JxNt+393z5jdEE8= 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-35-hFdqovoEOLWpnr9tXic20w-1; Wed, 13 Dec 2023 08:50:39 -0500 X-MC-Unique: hFdqovoEOLWpnr9tXic20w-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 3ABDF8828C4; Wed, 13 Dec 2023 13:50:39 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DDD82166B31; Wed, 13 Dec 2023 13:50:38 +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 Subject: [PATCH v2 20/40] afs: Fold the afs_addr_cursor struct in Date: Wed, 13 Dec 2023 13:49:42 +0000 Message-ID: <20231213135003.367397-21-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fold the afs_addr_cursor struct into the afs_operation struct and the afs_vl_cursor struct and fold its operations into their callers also. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/addr_list.c | 53 ----------------------- fs/afs/fs_operation.c | 21 +++++++-- fs/afs/fs_probe.c | 41 ++++++++---------- fs/afs/fsclient.c | 31 +++++++++----- fs/afs/internal.h | 58 ++++++++++++------------- fs/afs/rotate.c | 71 ++++++++++++++++++------------ fs/afs/rxrpc.c | 13 ++---- fs/afs/server.c | 6 +-- fs/afs/vl_probe.c | 23 +++++----- fs/afs/vl_rotate.c | 88 ++++++++++++++++++++++++++++---------- fs/afs/vlclient.c | 34 ++++++++------- include/trace/events/afs.h | 18 ++++++-- 12 files changed, 243 insertions(+), 214 deletions(-) diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index 032e6963c5d8..18c286efa3a5 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -375,56 +375,3 @@ int afs_merge_fs_addr6(struct afs_net *net, struct afs= _addr_list *alist, alist->nr_addrs++; return 0; } - -/* - * Get an address to try. - */ -bool afs_iterate_addresses(struct afs_addr_cursor *ac) -{ - unsigned long set, failed; - int index; - - if (!ac->alist) - return false; - - set =3D ac->alist->responded; - failed =3D ac->alist->probe_failed; - _enter("%lx-%lx-%lx,%d", set, failed, ac->tried, ac->index); - - ac->nr_iterations++; - - set &=3D ~(failed | ac->tried); - - if (!set) - return false; - - index =3D READ_ONCE(ac->alist->preferred); - if (test_bit(index, &set)) - goto selected; - - index =3D __ffs(set); - -selected: - ac->index =3D index; - set_bit(index, &ac->tried); - ac->call_responded =3D false; - return true; -} - -/* - * Release an address list cursor. - */ -void afs_end_cursor(struct afs_addr_cursor *ac) -{ - struct afs_addr_list *alist; - - alist =3D ac->alist; - if (alist) { - if (ac->call_responded && - ac->index !=3D alist->preferred && - test_bit(ac->alist->preferred, &ac->tried)) - WRITE_ONCE(alist->preferred, ac->index); - afs_put_addrlist(alist, afs_alist_trace_put_end_cursor); - ac->alist =3D NULL; - } -} diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index cebe4fad8192..00e22259be36 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -179,6 +179,7 @@ void afs_wait_for_operation(struct afs_operation *op) _enter(""); =20 while (afs_select_fileserver(op)) { + op->call_responded =3D false; op->call_error =3D 0; op->call_abort_code =3D 0; op->cb_s_break =3D op->server->cb_s_break; @@ -191,17 +192,19 @@ void afs_wait_for_operation(struct afs_operation *op) op->call_error =3D -ENOTSUPP; =20 if (op->call) { - afs_wait_for_call_to_complete(op->call, &op->ac); + afs_wait_for_call_to_complete(op->call); op->call_abort_code =3D op->call->abort_code; op->call_error =3D op->call->error; op->call_responded =3D op->call->responded; - op->ac.call_responded =3D true; - WRITE_ONCE(op->ac.alist->addrs[op->ac.index].last_error, + WRITE_ONCE(op->alist->addrs[op->addr_index].last_error, op->call_error); afs_put_call(op->call); } } =20 + if (op->call_responded) + set_bit(AFS_SERVER_FL_RESPONDING, &op->server->flags); + if (!afs_op_error(op)) { _debug("success"); op->ops->success(op); @@ -227,6 +230,7 @@ void afs_wait_for_operation(struct afs_operation *op) */ int afs_put_operation(struct afs_operation *op) { + struct afs_addr_list *alist; int i, ret =3D afs_op_error(op); =20 _enter("op=3D%08x,%d", op->debug_id, ret); @@ -249,7 +253,16 @@ int afs_put_operation(struct afs_operation *op) kfree(op->more_files); } =20 - afs_end_cursor(&op->ac); + alist =3D op->alist; + if (alist) { + if (op->call_responded && + op->addr_index !=3D alist->preferred && + test_bit(alist->preferred, &op->addr_tried)) + WRITE_ONCE(alist->preferred, op->addr_index); + afs_put_addrlist(alist, afs_alist_trace_put_operation); + op->alist =3D NULL; + } + afs_put_serverlist(op->net, op->server_list); afs_put_volume(op->net, op->volume, afs_volume_trace_put_put_op); key_put(op->key); diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index 337673e65f87..aef16ac3f577 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -74,11 +74,9 @@ static void afs_done_one_fs_probe(struct afs_net *net, s= truct afs_server *server */ static void afs_fs_probe_not_done(struct afs_net *net, struct afs_server *server, - struct afs_addr_cursor *ac) + struct afs_addr_list *alist, + int index) { - struct afs_addr_list *alist =3D ac->alist; - unsigned int index =3D ac->index; - _enter(""); =20 trace_afs_io_error(0, -ENOMEM, afs_io_error_fs_probe_fail); @@ -100,10 +98,10 @@ static void afs_fs_probe_not_done(struct afs_net *net, */ void afs_fileserver_probe_result(struct afs_call *call) { - struct afs_addr_list *alist =3D call->alist; - struct afs_address *addr =3D &alist->addrs[call->addr_ix]; + struct afs_addr_list *alist =3D call->probe_alist; + struct afs_address *addr =3D &alist->addrs[call->probe_index]; struct afs_server *server =3D call->server; - unsigned int index =3D call->addr_ix; + unsigned int index =3D call->probe_index; unsigned int rtt_us =3D 0, cap0; int ret =3D call->error; =20 @@ -196,37 +194,36 @@ void afs_fileserver_probe_result(struct afs_call *cal= l) void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *serve= r, struct key *key, bool all) { - struct afs_addr_cursor ac =3D { - .index =3D 0, - }; + struct afs_addr_list *alist; + unsigned int index; =20 _enter("%pU", &server->uuid); =20 read_lock(&server->fs_lock); - ac.alist =3D rcu_dereference_protected(server->addresses, - lockdep_is_held(&server->fs_lock)); - afs_get_addrlist(ac.alist, afs_alist_trace_get_probe); + alist =3D rcu_dereference_protected(server->addresses, + lockdep_is_held(&server->fs_lock)); + afs_get_addrlist(alist, afs_alist_trace_get_probe); read_unlock(&server->fs_lock); =20 server->probed_at =3D jiffies; - atomic_set(&server->probe_outstanding, all ? ac.alist->nr_addrs : 1); + atomic_set(&server->probe_outstanding, all ? alist->nr_addrs : 1); memset(&server->probe, 0, sizeof(server->probe)); server->probe.rtt =3D UINT_MAX; =20 - ac.index =3D ac.alist->preferred; - if (ac.index < 0 || ac.index >=3D ac.alist->nr_addrs) + index =3D alist->preferred; + if (index < 0 || index >=3D alist->nr_addrs) all =3D true; =20 if (all) { - for (ac.index =3D 0; ac.index < ac.alist->nr_addrs; ac.index++) - if (!afs_fs_get_capabilities(net, server, &ac, key)) - afs_fs_probe_not_done(net, server, &ac); + for (index =3D 0; index < alist->nr_addrs; index++) + if (!afs_fs_get_capabilities(net, server, alist, index, key)) + afs_fs_probe_not_done(net, server, alist, index); } else { - if (!afs_fs_get_capabilities(net, server, &ac, key)) - afs_fs_probe_not_done(net, server, &ac); + if (!afs_fs_get_capabilities(net, server, alist, index, key)) + afs_fs_probe_not_done(net, server, alist, index); } =20 - afs_put_addrlist(ac.alist, afs_alist_trace_put_probe); + afs_put_addrlist(alist, afs_alist_trace_put_probe); } =20 /* diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index 2b64641b20a4..4f98b43b0dde 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -1605,10 +1605,8 @@ static const struct afs_call_type afs_RXFSGiveUpAllC= allBacks =3D { /* * Flush all the callbacks we have on a server. */ -int afs_fs_give_up_all_callbacks(struct afs_net *net, - struct afs_server *server, - struct afs_addr_cursor *ac, - struct key *key) +int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *s= erver, + struct afs_address *addr, struct key *key) { struct afs_call *call; __be32 *bp; @@ -1621,7 +1619,7 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, return -ENOMEM; =20 call->key =3D key; - call->peer =3D rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer); + call->peer =3D rxrpc_kernel_get_peer(addr->peer); call->service_id =3D server->service_id; =20 /* marshall the parameters */ @@ -1629,9 +1627,11 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, *bp++ =3D htonl(FSGIVEUPALLCALLBACKS); =20 call->server =3D afs_use_server(server, afs_server_trace_give_up_cb); - afs_make_call(ac, call, GFP_NOFS); - afs_wait_for_call_to_complete(call, ac); + afs_make_call(call, GFP_NOFS); + afs_wait_for_call_to_complete(call); ret =3D call->error; + if (call->responded) + set_bit(AFS_SERVER_FL_RESPONDING, &server->flags); afs_put_call(call); return ret; } @@ -1695,6 +1695,12 @@ static int afs_deliver_fs_get_capabilities(struct af= s_call *call) return 0; } =20 +static void afs_fs_get_capabilities_destructor(struct afs_call *call) +{ + afs_put_addrlist(call->probe_alist, afs_alist_trace_put_getcaps); + afs_flat_call_destructor(call); +} + /* * FS.GetCapabilities operation type */ @@ -1703,7 +1709,7 @@ static const struct afs_call_type afs_RXFSGetCapabili= ties =3D { .op =3D afs_FS_GetCapabilities, .deliver =3D afs_deliver_fs_get_capabilities, .done =3D afs_fileserver_probe_result, - .destructor =3D afs_flat_call_destructor, + .destructor =3D afs_fs_get_capabilities_destructor, }; =20 /* @@ -1713,7 +1719,8 @@ static const struct afs_call_type afs_RXFSGetCapabili= ties =3D { * ->done() - otherwise we return false to indicate we didn't even try. */ bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *serve= r, - struct afs_addr_cursor *ac, struct key *key) + struct afs_addr_list *alist, unsigned int addr_index, + struct key *key) { struct afs_call *call; __be32 *bp; @@ -1726,7 +1733,9 @@ bool afs_fs_get_capabilities(struct afs_net *net, str= uct afs_server *server, =20 call->key =3D key; call->server =3D afs_use_server(server, afs_server_trace_get_caps); - call->peer =3D rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer); + call->peer =3D rxrpc_kernel_get_peer(alist->addrs[addr_index].peer); + call->probe_alist =3D afs_get_addrlist(alist, afs_alist_trace_get_getcaps= ); + call->probe_index =3D addr_index; call->service_id =3D server->service_id; call->upgrade =3D true; call->async =3D true; @@ -1737,7 +1746,7 @@ bool afs_fs_get_capabilities(struct afs_net *net, str= uct afs_server *server, *bp++ =3D htonl(FSGETCAPABILITIES); =20 trace_afs_make_fs_call(call, NULL); - afs_make_call(ac, call, GFP_NOFS); + afs_make_call(call, GFP_NOFS); afs_put_call(call); return true; } diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 3a2aa2af072a..ae33dd8ae49b 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -102,7 +102,6 @@ struct afs_addr_list { */ struct afs_call { const struct afs_call_type *type; /* type of call */ - struct afs_addr_list *alist; /* Address is alist[addr_ix] */ wait_queue_head_t waitq; /* processes awaiting completion */ struct work_struct async_work; /* async I/O processor */ struct work_struct work; /* actual work processor */ @@ -123,6 +122,10 @@ struct afs_call { }; void *buffer; /* reply receive buffer */ union { + struct { + struct afs_addr_list *probe_alist; + unsigned char probe_index; /* Address in ->probe_alist */ + }; struct afs_addr_list *ret_alist; struct afs_vldb_entry *ret_vldb; char *ret_str; @@ -139,7 +142,6 @@ struct afs_call { unsigned reply_max; /* maximum size of reply */ unsigned count2; /* count used in unmarshalling */ unsigned char unmarshall; /* unmarshalling phase */ - unsigned char addr_ix; /* Address in ->alist */ bool drop_ref; /* T if need to drop ref for incoming call */ bool need_attention; /* T if RxRPC poked us */ bool async; /* T if asynchronous */ @@ -729,31 +731,23 @@ struct afs_error { bool aborted; /* T if ->error is from an abort */ }; =20 -/* - * Cursor for iterating over a server's address list. - */ -struct afs_addr_cursor { - struct afs_addr_list *alist; /* Current address list (pins ref) */ - unsigned long tried; /* Tried addresses */ - signed char index; /* Current address */ - unsigned short nr_iterations; /* Number of address iterations */ - bool call_responded; -}; - /* * Cursor for iterating over a set of volume location servers. */ struct afs_vl_cursor { - struct afs_addr_cursor ac; struct afs_cell *cell; /* The cell we're querying */ struct afs_vlserver_list *server_list; /* Current server list (pins ref) = */ struct afs_vlserver *server; /* Server on which this resides */ + struct afs_addr_list *alist; /* Current address list (pins ref) */ struct key *key; /* Key for the server */ unsigned long untried_servers; /* Bitmask of untried servers */ + unsigned long addr_tried; /* Tried addresses */ struct afs_error cumul_error; /* Cumulative error */ + unsigned int debug_id; s32 call_abort_code; short call_error; /* Error from single call */ short server_index; /* Current server */ + signed char addr_index; /* Current address */ unsigned short flags; #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */ #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */ @@ -812,8 +806,6 @@ struct afs_operation { struct timespec64 ctime; /* Change time to set */ struct afs_error cumul_error; /* Cumulative error */ short nr_files; /* Number of entries in file[], more_files */ - short call_error; /* Error from single call */ - s32 call_abort_code; /* Abort code from single call */ unsigned int debug_id; =20 unsigned int cb_v_break; /* Volume break counter before op */ @@ -862,16 +854,19 @@ struct afs_operation { }; =20 /* Fileserver iteration state */ - struct afs_addr_cursor ac; struct afs_server_list *server_list; /* Current server list (pins ref) */ struct afs_server *server; /* Server we're using (ref pinned by server_li= st) */ + struct afs_addr_list *alist; /* Current address list (pins ref) */ struct afs_call *call; unsigned long untried_servers; /* Bitmask of untried servers */ + unsigned long addr_tried; /* Tried addresses */ + s32 call_abort_code; /* Abort code from single call */ + short call_error; /* Error from single call */ short server_index; /* Current server */ short nr_iterations; /* Number of server iterations */ + signed char addr_index; /* Current address */ bool call_responded; /* T if the current address responded */ =20 - unsigned int flags; #define AFS_OPERATION_STOP 0x0001 /* Set to cease iteration */ #define AFS_OPERATION_VBUSY 0x0002 /* Set if seen VBUSY */ @@ -981,8 +976,6 @@ extern struct afs_vlserver_list *afs_parse_text_addrs(s= truct afs_net *, bool afs_addr_list_same(const struct afs_addr_list *a, const struct afs_addr_list *b); extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t= *); -extern bool afs_iterate_addresses(struct afs_addr_cursor *); -extern void afs_end_cursor(struct afs_addr_cursor *ac); =20 extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *a= ddr, __be32 xdr, u16 port); @@ -1123,10 +1116,11 @@ extern void afs_fs_get_volume_status(struct afs_ope= ration *); extern void afs_fs_set_lock(struct afs_operation *); extern void afs_fs_extend_lock(struct afs_operation *); extern void afs_fs_release_lock(struct afs_operation *); -extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_serve= r *, - struct afs_addr_cursor *, struct key *); -extern bool afs_fs_get_capabilities(struct afs_net *, struct afs_server *, - struct afs_addr_cursor *, struct key *); +int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *s= erver, + struct afs_address *addr, struct key *key); +bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *serve= r, + struct afs_addr_list *alist, unsigned int addr_index, + struct key *key); extern void afs_fs_inline_bulk_status(struct afs_operation *); =20 struct afs_acl { @@ -1306,8 +1300,8 @@ extern int __net_init afs_open_socket(struct afs_net = *); extern void __net_exit afs_close_socket(struct afs_net *); extern void afs_charge_preallocation(struct work_struct *); extern void afs_put_call(struct afs_call *); -extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp= _t); -void afs_wait_for_call_to_complete(struct afs_call *call, struct afs_addr_= cursor *ac); +void afs_make_call(struct afs_call *call, gfp_t gfp); +void afs_wait_for_call_to_complete(struct afs_call *call); extern struct afs_call *afs_alloc_flat_call(struct afs_net *, const struct afs_call_type *, size_t, size_t); @@ -1325,9 +1319,9 @@ static inline void afs_make_op_call(struct afs_operat= ion *op, struct afs_call *c call->op =3D op; call->key =3D op->key; call->intr =3D !(op->flags & AFS_OPERATION_UNINTR); - call->peer =3D rxrpc_kernel_get_peer(op->ac.alist->addrs[op->ac.index].pe= er); + call->peer =3D rxrpc_kernel_get_peer(op->alist->addrs[op->addr_index].pee= r); call->service_id =3D op->server->service_id; - afs_make_call(&op->ac, call, gfp); + afs_make_call(call, gfp); } =20 static inline void afs_extract_begin(struct afs_call *call, void *buf, siz= e_t size) @@ -1493,8 +1487,12 @@ extern void afs_fs_exit(void); extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cur= sor *, const char *, int); extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, co= nst uuid_t *); -extern struct afs_call *afs_vl_get_capabilities(struct afs_net *, struct a= fs_addr_cursor *, - struct key *, struct afs_vlserver *, unsigned int); +struct afs_call *afs_vl_get_capabilities(struct afs_net *net, + struct afs_addr_list *alist, + unsigned int addr_index, + struct key *key, + struct afs_vlserver *server, + unsigned int server_index); extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor = *, const uuid_t *); extern char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *); =20 diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 6c1aa9bafc82..a6bda8f44c0f 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -109,19 +109,20 @@ static bool afs_sleep_and_retry(struct afs_operation = *op) */ bool afs_select_fileserver(struct afs_operation *op) { - struct afs_addr_list *alist; + struct afs_addr_list *alist =3D op->alist; struct afs_server *server; struct afs_vnode *vnode =3D op->file[0].vnode; + unsigned long set; unsigned int rtt; s32 abort_code =3D op->call_abort_code; - int error =3D op->call_error, i; + int error =3D op->call_error, addr_index, i; =20 op->nr_iterations++; =20 - _enter("OP=3D%x+%x,%llx,%lx[%d],%lx[%d],%d,%d", + _enter("OP=3D%x+%x,%llx,%u{%lx},%u{%lx},%d,%d", op->debug_id, op->nr_iterations, op->volume->vid, - op->untried_servers, op->server_index, - op->ac.tried, op->ac.index, + op->server_index, op->untried_servers, + op->addr_index, op->addr_tried, error, abort_code); =20 if (op->flags & AFS_OPERATION_STOP) { @@ -398,12 +399,14 @@ bool afs_select_fileserver(struct afs_operation *op) =20 restart_from_beginning: _debug("restart"); - afs_end_cursor(&op->ac); + afs_put_addrlist(alist, afs_alist_trace_put_restart_rotate); + alist =3D op->alist =3D NULL; op->server =3D NULL; afs_put_serverlist(op->net, op->server_list); op->server_list =3D NULL; start: _debug("start"); + ASSERTCMP(alist, =3D=3D, NULL); /* See if we need to do an update of the volume record. Note that the * volume may have moved or even have been deleted. */ @@ -420,6 +423,7 @@ bool afs_select_fileserver(struct afs_operation *op) =20 pick_server: _debug("pick [%lx]", op->untried_servers); + ASSERTCMP(alist, =3D=3D, NULL); =20 error =3D afs_wait_for_fs_probes(op->server_list, op->untried_servers); if (error < 0) { @@ -463,7 +467,7 @@ bool afs_select_fileserver(struct afs_operation *op) * check it, create a callback intercept, find its address list and * probe its capabilities before we use it. */ - ASSERTCMP(op->ac.alist, =3D=3D, NULL); + ASSERTCMP(alist, =3D=3D, NULL); server =3D op->server_list->servers[op->server_index].server; =20 if (!afs_check_server_record(op, server)) @@ -484,32 +488,34 @@ bool afs_select_fileserver(struct afs_operation *op) read_lock(&server->fs_lock); alist =3D rcu_dereference_protected(server->addresses, lockdep_is_held(&server->fs_lock)); - afs_get_addrlist(alist, afs_alist_trace_get_fsrotate_set); + op->alist =3D afs_get_addrlist(alist, afs_alist_trace_get_fsrotate_set); read_unlock(&server->fs_lock); =20 retry_server: - memset(&op->ac, 0, sizeof(op->ac)); - - if (!op->ac.alist) - op->ac.alist =3D alist; - else - afs_put_addrlist(alist, afs_alist_trace_put_retry_server); - - op->ac.index =3D -1; + op->addr_tried =3D 0; + op->addr_index =3D -1; =20 iterate_address: - ASSERT(op->ac.alist); /* Iterate over the current server's address list to try and find an * address on which it will respond to us. */ - if (!afs_iterate_addresses(&op->ac)) + set =3D READ_ONCE(alist->responded); + set &=3D ~(READ_ONCE(alist->probe_failed) | op->addr_tried); + if (!set) goto out_of_addresses; =20 - _debug("address [%u] %u/%u %pISp", - op->server_index, op->ac.index, op->ac.alist->nr_addrs, - rxrpc_kernel_remote_addr(op->ac.alist->addrs[op->ac.index].peer)); + addr_index =3D READ_ONCE(alist->preferred); + if (!test_bit(addr_index, &set)) + addr_index =3D __ffs(set); + + op->addr_index =3D addr_index; + set_bit(addr_index, &op->addr_tried); + op->alist =3D alist; =20 op->call_responded =3D false; + _debug("address [%u] %u/%u %pISp", + op->server_index, addr_index, alist->nr_addrs, + rxrpc_kernel_remote_addr(alist->addrs[op->addr_index].peer)); _leave(" =3D t"); return true; =20 @@ -519,7 +525,6 @@ bool afs_select_fileserver(struct afs_operation *op) */ afs_probe_fileserver(op->net, op->server); if (op->flags & AFS_OPERATION_RETRY_SERVER) { - alist =3D op->ac.alist; error =3D afs_wait_for_one_fs_probe( op->server, !(op->flags & AFS_OPERATION_UNINTR)); switch (error) { @@ -537,7 +542,13 @@ bool afs_select_fileserver(struct afs_operation *op) =20 next_server: _debug("next"); - afs_end_cursor(&op->ac); + ASSERT(alist); + if (op->call_responded && + op->addr_index !=3D READ_ONCE(alist->preferred) && + test_bit(alist->preferred, &op->addr_tried)) + WRITE_ONCE(alist->preferred, op->addr_index); + afs_put_addrlist(alist, afs_alist_trace_put_next_server); + alist =3D op->alist =3D NULL; goto pick_server; =20 no_more_servers: @@ -557,7 +568,14 @@ bool afs_select_fileserver(struct afs_operation *op) =20 failed: op->flags |=3D AFS_OPERATION_STOP; - afs_end_cursor(&op->ac); + if (alist) { + if (op->call_responded && + op->addr_index !=3D READ_ONCE(alist->preferred) && + test_bit(alist->preferred, &op->addr_tried)) + WRITE_ONCE(alist->preferred, op->addr_index); + afs_put_addrlist(alist, afs_alist_trace_put_op_failed); + op->alist =3D NULL; + } _leave(" =3D f [failed %d]", afs_op_error(op)); return false; } @@ -602,13 +620,12 @@ void afs_dump_edestaddrreq(const struct afs_operation= *op) a->preferred); pr_notice("FC: - R=3D%lx F=3D%lx\n", a->responded, a->probe_failed); - if (a =3D=3D op->ac.alist) + if (a =3D=3D op->alist) pr_notice("FC: - current\n"); } } } =20 - pr_notice("AC: t=3D%lx ax=3D%u ni=3D%u\n", - op->ac.tried, op->ac.index, op->ac.nr_iterations); + pr_notice("AC: t=3D%lx ax=3D%u\n", op->addr_tried, op->addr_index); rcu_read_unlock(); } diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index e8490b3e9d37..81013bc8bbfd 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -189,7 +189,6 @@ void afs_put_call(struct afs_call *call) call->type->destructor(call); =20 afs_unuse_server_notime(call->net, call->server, afs_server_trace_put_ca= ll); - afs_put_addrlist(call->alist, afs_alist_trace_put_call); kfree(call->request); =20 trace_afs_call(call->debug_id, afs_call_trace_free, 0, o, @@ -296,7 +295,7 @@ static void afs_notify_end_request_tx(struct sock *sock, * Initiate a call and synchronously queue up the parameters for dispatch.= Any * error is stored into the call struct, which the caller must check for. */ -void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_= t gfp) +void afs_make_call(struct afs_call *call, gfp_t gfp) { struct rxrpc_call *rxcall; struct msghdr msg; @@ -314,9 +313,6 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) call, call->type->name, key_serial(call->key), atomic_read(&call->net->nr_outstanding_calls)); =20 - call->addr_ix =3D ac->index; - call->alist =3D afs_get_addrlist(ac->alist, afs_alist_trace_get_make_call= ); - /* Work out the length we're going to transmit. This is awkward for * calls such as FS.StoreData where there's an extra injection of data * after the initial fixed part. @@ -392,7 +388,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct a= fs_call *call, gfp_t gfp) /* Note that at this point, we may have received the reply or an abort * - and an asynchronous call may already have completed. * - * afs_wait_for_call_to_complete(call, ac) + * afs_wait_for_call_to_complete(call) * must be called to synchronously clean up. */ return; @@ -577,7 +573,7 @@ static void afs_deliver_to_call(struct afs_call *call) /* * Wait synchronously for a call to complete. */ -void afs_wait_for_call_to_complete(struct afs_call *call, struct afs_addr_= cursor *ac) +void afs_wait_for_call_to_complete(struct afs_call *call) { bool rxrpc_complete =3D false; =20 @@ -627,9 +623,6 @@ void afs_wait_for_call_to_complete(struct afs_call *cal= l, struct afs_addr_cursor afs_set_call_complete(call, -EINTR, 0); } } - - if (call->error =3D=3D 0 || call->error =3D=3D -ECONNABORTED) - call->responded =3D true; } =20 /* diff --git a/fs/afs/server.c b/fs/afs/server.c index e2c7f65eea33..62d453365689 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -436,12 +436,8 @@ static void __afs_put_server(struct afs_net *net, stru= ct afs_server *server) static void afs_give_up_callbacks(struct afs_net *net, struct afs_server *= server) { struct afs_addr_list *alist =3D rcu_access_pointer(server->addresses); - struct afs_addr_cursor ac =3D { - .alist =3D alist, - .index =3D alist->preferred, - }; =20 - afs_fs_give_up_all_callbacks(net, server, &ac, NULL); + afs_fs_give_up_all_callbacks(net, server, &alist->addrs[alist->preferred]= , NULL); } =20 /* diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c index d9a99ba9fc78..f868ae5d40e5 100644 --- a/fs/afs/vl_probe.c +++ b/fs/afs/vl_probe.c @@ -46,12 +46,12 @@ static void afs_done_one_vl_probe(struct afs_vlserver *= server, bool wake_up) */ void afs_vlserver_probe_result(struct afs_call *call) { - struct afs_addr_list *alist =3D call->alist; + struct afs_addr_list *alist =3D call->probe_alist; struct afs_vlserver *server =3D call->vlserver; - struct afs_address *addr =3D &alist->addrs[call->addr_ix]; + struct afs_address *addr =3D &alist->addrs[call->probe_index]; unsigned int server_index =3D call->server_index; unsigned int rtt_us =3D 0; - unsigned int index =3D call->addr_ix; + unsigned int index =3D call->probe_index; bool have_result =3D false; int ret =3D call->error; =20 @@ -148,25 +148,25 @@ static bool afs_do_probe_vlserver(struct afs_net *net, unsigned int server_index, struct afs_error *_e) { - struct afs_addr_cursor ac =3D { - .index =3D 0, - }; + struct afs_addr_list *alist; struct afs_call *call; + unsigned int index; bool in_progress =3D false; =20 _enter("%s", server->name); =20 read_lock(&server->lock); - ac.alist =3D rcu_dereference_protected(server->addresses, - lockdep_is_held(&server->lock)); + alist =3D rcu_dereference_protected(server->addresses, + lockdep_is_held(&server->lock)); + afs_get_addrlist(alist, afs_alist_trace_get_vlprobe); read_unlock(&server->lock); =20 - atomic_set(&server->probe_outstanding, ac.alist->nr_addrs); + atomic_set(&server->probe_outstanding, alist->nr_addrs); memset(&server->probe, 0, sizeof(server->probe)); server->probe.rtt =3D UINT_MAX; =20 - for (ac.index =3D 0; ac.index < ac.alist->nr_addrs; ac.index++) { - call =3D afs_vl_get_capabilities(net, &ac, key, server, + for (index =3D 0; index < alist->nr_addrs; index++) { + call =3D afs_vl_get_capabilities(net, alist, index, key, server, server_index); if (!IS_ERR(call)) { afs_prioritise_error(_e, call->error, call->abort_code); @@ -178,6 +178,7 @@ static bool afs_do_probe_vlserver(struct afs_net *net, } } =20 + afs_put_addrlist(alist, afs_alist_trace_put_vlprobe); return in_progress; } =20 diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index f895eb94129e..91168528179c 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -17,6 +17,8 @@ bool afs_begin_vlserver_operation(struct afs_vl_cursor *vc, struct afs_cel= l *cell, struct key *key) { + static atomic_t debug_ids; + memset(vc, 0, sizeof(*vc)); vc->cell =3D cell; vc->key =3D key; @@ -29,6 +31,7 @@ bool afs_begin_vlserver_operation(struct afs_vl_cursor *v= c, struct afs_cell *cel return false; } =20 + vc->debug_id =3D atomic_inc_return(&debug_ids); return true; } =20 @@ -89,17 +92,18 @@ static bool afs_start_vl_iteration(struct afs_vl_cursor= *vc) */ bool afs_select_vlserver(struct afs_vl_cursor *vc) { - struct afs_addr_list *alist; + struct afs_addr_list *alist =3D vc->alist; struct afs_vlserver *vlserver; + unsigned long set, failed; unsigned int rtt; s32 abort_code =3D vc->call_abort_code; int error =3D vc->call_error, i; =20 vc->nr_iterations++; =20 - _enter("%lx[%d],%lx[%d],%d,%d", - vc->untried_servers, vc->server_index, - vc->ac.tried, vc->ac.index, + _enter("VC=3D%x+%x,%d{%lx},%d{%lx},%d,%d", + vc->debug_id, vc->nr_iterations, vc->server_index, vc->untried_ser= vers, + vc->addr_index, vc->addr_tried, error, abort_code); =20 if (vc->flags & AFS_VL_CURSOR_STOP) { @@ -165,7 +169,13 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) =20 restart_from_beginning: _debug("restart"); - afs_end_cursor(&vc->ac); + if (vc->call_responded && + vc->addr_index !=3D vc->alist->preferred && + test_bit(alist->preferred, &vc->addr_tried)) + WRITE_ONCE(alist->preferred, vc->addr_index); + afs_put_addrlist(alist, afs_alist_trace_put_vlrotate_restart); + alist =3D vc->alist =3D NULL; + afs_put_vlserverlist(vc->cell->net, vc->server_list); vc->server_list =3D NULL; if (vc->flags & AFS_VL_CURSOR_RETRIED) @@ -173,6 +183,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) vc->flags |=3D AFS_VL_CURSOR_RETRIED; start: _debug("start"); + ASSERTCMP(alist, =3D=3D, NULL); =20 if (!afs_start_vl_iteration(vc)) goto failed; @@ -185,6 +196,7 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) =20 pick_server: _debug("pick [%lx]", vc->untried_servers); + ASSERTCMP(alist, =3D=3D, NULL); =20 error =3D afs_wait_for_vl_probes(vc->server_list, vc->untried_servers); if (error < 0) { @@ -222,7 +234,6 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) * check it, find its address list and probe its capabilities before we * use it. */ - ASSERTCMP(vc->ac.alist, =3D=3D, NULL); vlserver =3D vc->server_list->servers[vc->server_index].server; vc->server =3D vlserver; =20 @@ -231,30 +242,48 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) read_lock(&vlserver->lock); alist =3D rcu_dereference_protected(vlserver->addresses, lockdep_is_held(&vlserver->lock)); - afs_get_addrlist(alist, afs_alist_trace_get_vlrotate_set); + vc->alist =3D afs_get_addrlist(alist, afs_alist_trace_get_vlrotate_set); read_unlock(&vlserver->lock); =20 - memset(&vc->ac, 0, sizeof(vc->ac)); - vc->ac.alist =3D alist; - vc->ac.index =3D -1; + vc->addr_tried =3D 0; + vc->addr_index =3D -1; =20 iterate_address: - ASSERT(vc->ac.alist); /* Iterate over the current server's address list to try and find an * address on which it will respond to us. */ - if (!afs_iterate_addresses(&vc->ac)) + set =3D READ_ONCE(alist->responded); + failed =3D READ_ONCE(alist->probe_failed); + vc->addr_index =3D READ_ONCE(alist->preferred); + + _debug("%lx-%lx-%lx,%d", set, failed, vc->addr_tried, vc->addr_index); + + set &=3D ~(failed | vc->addr_tried); + + if (!set) goto next_server; =20 - _debug("VL address %d/%d", vc->ac.index, vc->ac.alist->nr_addrs); + if (!test_bit(vc->addr_index, &set)) + vc->addr_index =3D __ffs(set); + + set_bit(vc->addr_index, &vc->addr_tried); + vc->alist =3D alist; + + _debug("VL address %d/%d", vc->addr_index, alist->nr_addrs); =20 vc->call_responded =3D false; - _leave(" =3D t %pISpc", rxrpc_kernel_remote_addr(vc->ac.alist->addrs[vc->= ac.index].peer)); + _leave(" =3D t %pISpc", rxrpc_kernel_remote_addr(alist->addrs[vc->addr_in= dex].peer)); return true; =20 next_server: _debug("next"); - afs_end_cursor(&vc->ac); + ASSERT(alist); + if (vc->call_responded && + vc->addr_index !=3D alist->preferred && + test_bit(alist->preferred, &vc->addr_tried)) + WRITE_ONCE(alist->preferred, vc->addr_index); + afs_put_addrlist(alist, afs_alist_trace_put_vlrotate_next); + alist =3D vc->alist =3D NULL; goto pick_server; =20 no_more_servers: @@ -274,8 +303,15 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) } =20 failed: + if (alist) { + if (vc->call_responded && + vc->addr_index !=3D alist->preferred && + test_bit(alist->preferred, &vc->addr_tried)) + WRITE_ONCE(alist->preferred, vc->addr_index); + afs_put_addrlist(alist, afs_alist_trace_put_vlrotate_fail); + alist =3D vc->alist =3D NULL; + } vc->flags |=3D AFS_VL_CURSOR_STOP; - afs_end_cursor(&vc->ac); _leave(" =3D f [failed %d]", vc->cumul_error.error); return false; } @@ -299,8 +335,8 @@ static void afs_vl_dump_edestaddrreq(const struct afs_v= l_cursor *vc) pr_notice("DNS: src=3D%u st=3D%u lc=3D%x\n", cell->dns_source, cell->dns_status, cell->dns_lookup_count); pr_notice("VC: ut=3D%lx ix=3D%u ni=3D%hu fl=3D%hx err=3D%hd\n", - vc->untried_servers, vc->server_index, vc->nr_iterations, vc->flags, - vc->cumul_error.error); + vc->untried_servers, vc->server_index, vc->nr_iterations, + vc->flags, vc->cumul_error.error); pr_notice("VC: call er=3D%d ac=3D%d r=3D%u\n", vc->call_error, vc->call_abort_code, vc->call_responded); =20 @@ -320,14 +356,13 @@ static void afs_vl_dump_edestaddrreq(const struct afs= _vl_cursor *vc) a->preferred); pr_notice("VC: - R=3D%lx F=3D%lx\n", a->responded, a->probe_failed); - if (a =3D=3D vc->ac.alist) + if (a =3D=3D vc->alist) pr_notice("VC: - current\n"); } } } =20 - pr_notice("AC: t=3D%lx ax=3D%u ni=3D%u\n", - vc->ac.tried, vc->ac.index, vc->ac.nr_iterations); + pr_notice("AC: t=3D%lx ax=3D%u\n", vc->addr_tried, vc->addr_index); rcu_read_unlock(); } =20 @@ -338,6 +373,8 @@ int afs_end_vlserver_operation(struct afs_vl_cursor *vc) { struct afs_net *net =3D vc->cell->net; =20 + _enter("VC=3D%x+%x", vc->debug_id, vc->nr_iterations); + switch (vc->cumul_error.error) { case -EDESTADDRREQ: case -EADDRNOTAVAIL: @@ -347,7 +384,14 @@ int afs_end_vlserver_operation(struct afs_vl_cursor *v= c) break; } =20 - afs_end_cursor(&vc->ac); + if (vc->alist) { + if (vc->call_responded && + vc->addr_index !=3D vc->alist->preferred && + test_bit(vc->alist->preferred, &vc->addr_tried)) + WRITE_ONCE(vc->alist->preferred, vc->addr_index); + afs_put_addrlist(vc->alist, afs_alist_trace_put_vlrotate_end); + vc->alist =3D NULL; + } afs_put_vlserverlist(net, vc->server_list); return vc->cumul_error.error; } diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index 4bf98a38c3a1..39a0b7614d05 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -149,7 +149,7 @@ struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struc= t afs_vl_cursor *vc, call->key =3D vc->key; call->ret_vldb =3D entry; call->max_lifespan =3D AFS_VL_MAX_LIFESPAN; - call->peer =3D rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].pe= er); + call->peer =3D rxrpc_kernel_get_peer(vc->alist->addrs[vc->addr_index].pee= r); call->service_id =3D vc->server->service_id; =20 /* Marshall the parameters */ @@ -161,8 +161,8 @@ struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struc= t afs_vl_cursor *vc, memset((void *)bp + volnamesz, 0, padsz); =20 trace_afs_make_vl_call(call); - afs_make_call(&vc->ac, call, GFP_KERNEL); - afs_wait_for_call_to_complete(call, &vc->ac); + afs_make_call(call, GFP_KERNEL); + afs_wait_for_call_to_complete(call); vc->call_abort_code =3D call->abort_code; vc->call_error =3D call->error; vc->call_responded =3D call->responded; @@ -290,7 +290,7 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_= cursor *vc, call->key =3D vc->key; call->ret_alist =3D NULL; call->max_lifespan =3D AFS_VL_MAX_LIFESPAN; - call->peer =3D rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].pe= er); + call->peer =3D rxrpc_kernel_get_peer(vc->alist->addrs[vc->addr_index].pee= r); call->service_id =3D vc->server->service_id; =20 /* Marshall the parameters */ @@ -310,8 +310,8 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_= cursor *vc, r->uuid.node[i] =3D htonl(u->node[i]); =20 trace_afs_make_vl_call(call); - afs_make_call(&vc->ac, call, GFP_KERNEL); - afs_wait_for_call_to_complete(call, &vc->ac); + afs_make_call(call, GFP_KERNEL); + afs_wait_for_call_to_complete(call); vc->call_abort_code =3D call->abort_code; vc->call_error =3D call->error; vc->call_responded =3D call->responded; @@ -371,6 +371,7 @@ static int afs_deliver_vl_get_capabilities(struct afs_c= all *call) =20 static void afs_destroy_vl_get_capabilities(struct afs_call *call) { + afs_put_addrlist(call->probe_alist, afs_alist_trace_put_vlgetcaps); afs_put_vlserver(call->net, call->vlserver); afs_flat_call_destructor(call); } @@ -394,7 +395,8 @@ static const struct afs_call_type afs_RXVLGetCapabiliti= es =3D { * other end supports. */ struct afs_call *afs_vl_get_capabilities(struct afs_net *net, - struct afs_addr_cursor *ac, + struct afs_addr_list *alist, + unsigned int addr_index, struct key *key, struct afs_vlserver *server, unsigned int server_index) @@ -411,7 +413,9 @@ struct afs_call *afs_vl_get_capabilities(struct afs_net= *net, call->key =3D key; call->vlserver =3D afs_get_vlserver(server); call->server_index =3D server_index; - call->peer =3D rxrpc_kernel_get_peer(ac->alist->addrs[ac->index].peer); + call->peer =3D rxrpc_kernel_get_peer(alist->addrs[addr_index].peer); + call->probe_alist =3D afs_get_addrlist(alist, afs_alist_trace_get_vlgetca= ps); + call->probe_index =3D addr_index; call->service_id =3D server->service_id; call->upgrade =3D true; call->async =3D true; @@ -423,7 +427,7 @@ struct afs_call *afs_vl_get_capabilities(struct afs_net= *net, =20 /* Can't take a ref on server */ trace_afs_make_vl_call(call); - afs_make_call(ac, call, GFP_KERNEL); + afs_make_call(call, GFP_KERNEL); return call; } =20 @@ -658,7 +662,7 @@ struct afs_addr_list *afs_yfsvl_get_endpoints(struct af= s_vl_cursor *vc, call->key =3D vc->key; call->ret_alist =3D NULL; call->max_lifespan =3D AFS_VL_MAX_LIFESPAN; - call->peer =3D rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].pe= er); + call->peer =3D rxrpc_kernel_get_peer(vc->alist->addrs[vc->addr_index].pee= r); call->service_id =3D vc->server->service_id; =20 /* Marshall the parameters */ @@ -668,8 +672,8 @@ struct afs_addr_list *afs_yfsvl_get_endpoints(struct af= s_vl_cursor *vc, memcpy(bp, uuid, sizeof(*uuid)); /* Type opr_uuid */ =20 trace_afs_make_vl_call(call); - afs_make_call(&vc->ac, call, GFP_KERNEL); - afs_wait_for_call_to_complete(call, &vc->ac); + afs_make_call(call, GFP_KERNEL); + afs_wait_for_call_to_complete(call); vc->call_abort_code =3D call->abort_code; vc->call_error =3D call->error; vc->call_responded =3D call->responded; @@ -777,7 +781,7 @@ char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc) call->key =3D vc->key; call->ret_str =3D NULL; call->max_lifespan =3D AFS_VL_MAX_LIFESPAN; - call->peer =3D rxrpc_kernel_get_peer(vc->ac.alist->addrs[vc->ac.index].pe= er); + call->peer =3D rxrpc_kernel_get_peer(vc->alist->addrs[vc->addr_index].pee= r); call->service_id =3D vc->server->service_id; =20 /* marshall the parameters */ @@ -786,8 +790,8 @@ char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *vc) =20 /* Can't take a ref on server */ trace_afs_make_vl_call(call); - afs_make_call(&vc->ac, call, GFP_KERNEL); - afs_wait_for_call_to_complete(call, &vc->ac); + afs_make_call(call, GFP_KERNEL); + afs_wait_for_call_to_complete(call); vc->call_abort_code =3D call->abort_code; vc->call_error =3D call->error; vc->call_responded =3D call->responded; diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index ed91666ca4cc..0f68d67f52c8 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -204,21 +204,31 @@ enum yfs_cm_operation { =20 #define afs_alist_traces \ EM(afs_alist_trace_alloc, "ALLOC ") \ + EM(afs_alist_trace_get_getcaps, "GET getcap") \ EM(afs_alist_trace_get_fsrotate_set, "GET fs-rot") \ - EM(afs_alist_trace_get_make_call, "GET mkcall") \ EM(afs_alist_trace_get_probe, "GET probe ") \ + EM(afs_alist_trace_get_vlgetcaps, "GET vgtcap") \ + EM(afs_alist_trace_get_vlprobe, "GET vprobe") \ EM(afs_alist_trace_get_vlrotate_set, "GET vl-rot") \ - EM(afs_alist_trace_put_call, "PUT call ") \ - EM(afs_alist_trace_put_end_cursor, "PUT endcur") \ EM(afs_alist_trace_put_getaddru, "PUT GtAdrU") \ + EM(afs_alist_trace_put_getcaps, "PUT getcap") \ + EM(afs_alist_trace_put_next_server, "PUT nx-srv") \ + EM(afs_alist_trace_put_op_failed, "PUT op-fai") \ + EM(afs_alist_trace_put_operation, "PUT op ") \ EM(afs_alist_trace_put_parse_empty, "PUT p-empt") \ EM(afs_alist_trace_put_parse_error, "PUT p-err ") \ EM(afs_alist_trace_put_probe, "PUT probe ") \ - EM(afs_alist_trace_put_retry_server, "PUT retry ") \ + EM(afs_alist_trace_put_restart_rotate, "PUT rstrot") \ EM(afs_alist_trace_put_server, "PUT server") \ EM(afs_alist_trace_put_server_dup, "PUT sv-dup") \ EM(afs_alist_trace_put_server_oom, "PUT sv-oom") \ EM(afs_alist_trace_put_server_update, "PUT sv-upd") \ + EM(afs_alist_trace_put_vlgetcaps, "PUT vgtcap") \ + EM(afs_alist_trace_put_vlprobe, "PUT vprobe") \ + EM(afs_alist_trace_put_vlrotate_end, "PUT vr-end") \ + EM(afs_alist_trace_put_vlrotate_fail, "PUT vr-fai") \ + EM(afs_alist_trace_put_vlrotate_next, "PUT vr-nxt") \ + EM(afs_alist_trace_put_vlrotate_restart,"PUT vr-rst") \ EM(afs_alist_trace_put_vlserver, "PUT vlsrvr") \ EM(afs_alist_trace_put_vlserver_old, "PUT vs-old") \ E_(afs_alist_trace_free, "FREE ") From nobody Mon Dec 15 21:24:35 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 B12ABC4332F for ; Wed, 13 Dec 2023 13:51:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379198AbjLMNvr (ORCPT ); Wed, 13 Dec 2023 08:51:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441913AbjLMNuy (ORCPT ); Wed, 13 Dec 2023 08:50:54 -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 7A29B10E6 for ; Wed, 13 Dec 2023 05:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475446; 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=IQYJ9RXWQFDz937vpFGQ9JrCjfZ3A06FDJnr0rYbbpw=; b=CNwLAz7iUwFeKUQR+J7AMmPfnJSFDAmhjGFb7uDWGk0mOrwD15W62E/ZmYGi6wjlXtfAem Ttmea8fIKpThCcJex5RDIhuHlfERK0quh6yaKw8hmPWPiDB1YOucDbeITjGU/3Ikd2VNUg 5Ng9HpiOyHqUSrWjP76aD5gpnfhsWWQ= 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-374-fWH0lE0TOtydjl50slfC9A-1; Wed, 13 Dec 2023 08:50:41 -0500 X-MC-Unique: fWH0lE0TOtydjl50slfC9A-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 A803A10193A6; Wed, 13 Dec 2023 13:50:40 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC4611C060B1; Wed, 13 Dec 2023 13:50:39 +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 Subject: [PATCH v2 21/40] rxrpc: Create a procfile to display outstanding client conn bundles Date: Wed, 13 Dec 2023 13:49:43 +0000 Message-ID: <20231213135003.367397-22-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: quoted-printable 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-Type: text/plain; charset="utf-8" Create /proc/net/rxrpc/bundles to display outstanding rxrpc client connection bundles. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- net/rxrpc/ar-internal.h | 4 +++ net/rxrpc/conn_client.c | 10 ++++++ net/rxrpc/net_ns.c | 4 +++ net/rxrpc/proc.c | 76 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h index 8eea7a487380..2f8b39a614c3 100644 --- a/net/rxrpc/ar-internal.h +++ b/net/rxrpc/ar-internal.h @@ -68,6 +68,7 @@ struct rxrpc_net { atomic_t nr_calls; /* Count of allocated calls */ =20 atomic_t nr_conns; + struct list_head bundle_proc_list; /* List of bundles for proc */ struct list_head conn_proc_list; /* List of conns in this namespace for p= roc */ struct list_head service_conns; /* Service conns in this namespace */ rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */ @@ -432,6 +433,7 @@ struct rxrpc_bundle { struct rxrpc_local *local; /* Representation of local endpoint */ struct rxrpc_peer *peer; /* Remote endpoint */ struct key *key; /* Security details */ + struct list_head proc_link; /* Link in net->bundle_proc_list */ const struct rxrpc_security *security; /* applied security module */ refcount_t ref; atomic_t active; /* Number of active users */ @@ -445,6 +447,7 @@ struct rxrpc_bundle { struct rb_node local_node; /* Node in local->client_conns */ struct list_head waiting_calls; /* Calls waiting for channels */ unsigned long avail_chans; /* Mask of available channels */ + unsigned int conn_ids[4]; /* Connection IDs. */ struct rxrpc_connection *conns[4]; /* The connections in the bundle (max = 4) */ }; =20 @@ -1167,6 +1170,7 @@ void rxrpc_put_peer(struct rxrpc_peer *, enum rxrpc_p= eer_trace); */ extern const struct seq_operations rxrpc_call_seq_ops; extern const struct seq_operations rxrpc_connection_seq_ops; +extern const struct seq_operations rxrpc_bundle_seq_ops; extern const struct seq_operations rxrpc_peer_seq_ops; extern const struct seq_operations rxrpc_local_seq_ops; =20 diff --git a/net/rxrpc/conn_client.c b/net/rxrpc/conn_client.c index 1d95f8bc769f..3b9b267a4431 100644 --- a/net/rxrpc/conn_client.c +++ b/net/rxrpc/conn_client.c @@ -91,6 +91,10 @@ static struct rxrpc_bundle *rxrpc_alloc_bundle(struct rx= rpc_call *call, atomic_set(&bundle->active, 1); INIT_LIST_HEAD(&bundle->waiting_calls); trace_rxrpc_bundle(bundle->debug_id, 1, rxrpc_bundle_new); + + write_lock(&bundle->local->rxnet->conn_lock); + list_add_tail(&bundle->proc_link, &bundle->local->rxnet->bundle_proc_lis= t); + write_unlock(&bundle->local->rxnet->conn_lock); } return bundle; } @@ -109,6 +113,9 @@ static void rxrpc_free_bundle(struct rxrpc_bundle *bund= le) { trace_rxrpc_bundle(bundle->debug_id, refcount_read(&bundle->ref), rxrpc_bundle_free); + write_lock(&bundle->local->rxnet->conn_lock); + list_del(&bundle->proc_link); + write_unlock(&bundle->local->rxnet->conn_lock); rxrpc_put_peer(bundle->peer, rxrpc_peer_put_bundle); key_put(bundle->key); kfree(bundle); @@ -338,6 +345,7 @@ static bool rxrpc_add_conn_to_bundle(struct rxrpc_bundl= e *bundle, old =3D bundle->conns[slot]; if (old) { bundle->conns[slot] =3D NULL; + bundle->conn_ids[slot] =3D 0; trace_rxrpc_client(old, -1, rxrpc_client_replace); rxrpc_put_connection(old, rxrpc_conn_put_noreuse); } @@ -351,6 +359,7 @@ static bool rxrpc_add_conn_to_bundle(struct rxrpc_bundl= e *bundle, rxrpc_activate_bundle(bundle); conn->bundle_shift =3D shift; bundle->conns[slot] =3D conn; + bundle->conn_ids[slot] =3D conn->debug_id; for (i =3D 0; i < RXRPC_MAXCALLS; i++) set_bit(shift + i, &bundle->avail_chans); return true; @@ -671,6 +680,7 @@ static void rxrpc_unbundle_conn(struct rxrpc_connection= *conn) if (bundle->conns[bindex] =3D=3D conn) { _debug("clear slot %u", bindex); bundle->conns[bindex] =3D NULL; + bundle->conn_ids[bindex] =3D 0; for (i =3D 0; i < RXRPC_MAXCALLS; i++) clear_bit(conn->bundle_shift + i, &bundle->avail_chans); rxrpc_put_client_connection_id(bundle->local, conn); diff --git a/net/rxrpc/net_ns.c b/net/rxrpc/net_ns.c index a0319c040c25..a4c135d0fbcc 100644 --- a/net/rxrpc/net_ns.c +++ b/net/rxrpc/net_ns.c @@ -45,6 +45,7 @@ static __net_init int rxrpc_init_net(struct net *net) atomic_set(&rxnet->nr_calls, 1); =20 atomic_set(&rxnet->nr_conns, 1); + INIT_LIST_HEAD(&rxnet->bundle_proc_list); INIT_LIST_HEAD(&rxnet->conn_proc_list); INIT_LIST_HEAD(&rxnet->service_conns); rwlock_init(&rxnet->conn_lock); @@ -78,6 +79,9 @@ static __net_init int rxrpc_init_net(struct net *net) proc_create_net("conns", 0444, rxnet->proc_net, &rxrpc_connection_seq_ops, sizeof(struct seq_net_private)); + proc_create_net("bundles", 0444, rxnet->proc_net, + &rxrpc_bundle_seq_ops, + sizeof(struct seq_net_private)); proc_create_net("peers", 0444, rxnet->proc_net, &rxrpc_peer_seq_ops, sizeof(struct seq_net_private)); diff --git a/net/rxrpc/proc.c b/net/rxrpc/proc.c index 682636d3b060..6c86cbb98d1d 100644 --- a/net/rxrpc/proc.c +++ b/net/rxrpc/proc.c @@ -198,6 +198,82 @@ const struct seq_operations rxrpc_connection_seq_ops = =3D { .show =3D rxrpc_connection_seq_show, }; =20 +/* + * generate a list of extant virtual bundles in /proc/net/rxrpc/bundles + */ +static void *rxrpc_bundle_seq_start(struct seq_file *seq, loff_t *_pos) + __acquires(rxnet->conn_lock) +{ + struct rxrpc_net *rxnet =3D rxrpc_net(seq_file_net(seq)); + + read_lock(&rxnet->conn_lock); + return seq_list_start_head(&rxnet->bundle_proc_list, *_pos); +} + +static void *rxrpc_bundle_seq_next(struct seq_file *seq, void *v, + loff_t *pos) +{ + struct rxrpc_net *rxnet =3D rxrpc_net(seq_file_net(seq)); + + return seq_list_next(v, &rxnet->bundle_proc_list, pos); +} + +static void rxrpc_bundle_seq_stop(struct seq_file *seq, void *v) + __releases(rxnet->conn_lock) +{ + struct rxrpc_net *rxnet =3D rxrpc_net(seq_file_net(seq)); + + read_unlock(&rxnet->conn_lock); +} + +static int rxrpc_bundle_seq_show(struct seq_file *seq, void *v) +{ + struct rxrpc_bundle *bundle; + struct rxrpc_net *rxnet =3D rxrpc_net(seq_file_net(seq)); + char lbuff[50], rbuff[50]; + + if (v =3D=3D &rxnet->bundle_proc_list) { + seq_puts(seq, + "Proto Local " + " Remote " + " SvID Ref Act Flg Key |" + " Bundle Conn_0 Conn_1 Conn_2 Conn_3\n" + ); + return 0; + } + + bundle =3D list_entry(v, struct rxrpc_bundle, proc_link); + + sprintf(lbuff, "%pISpc", &bundle->local->srx.transport); + sprintf(rbuff, "%pISpc", &bundle->peer->srx.transport); + seq_printf(seq, + "UDP %-47.47s %-47.47s %4x %3u %3d" + " %c%c%c %08x | %08x %08x %08x %08x %08x\n", + lbuff, + rbuff, + bundle->service_id, + refcount_read(&bundle->ref), + atomic_read(&bundle->active), + bundle->try_upgrade ? 'U' : '-', + bundle->exclusive ? 'e' : '-', + bundle->upgrade ? 'u' : '-', + key_serial(bundle->key), + bundle->debug_id, + bundle->conn_ids[0], + bundle->conn_ids[1], + bundle->conn_ids[2], + bundle->conn_ids[3]); + + return 0; +} + +const struct seq_operations rxrpc_bundle_seq_ops =3D { + .start =3D rxrpc_bundle_seq_start, + .next =3D rxrpc_bundle_seq_next, + .stop =3D rxrpc_bundle_seq_stop, + .show =3D rxrpc_bundle_seq_show, +}; + /* * generate a list of extant virtual peers in /proc/net/rxrpc/peers */ From nobody Mon Dec 15 21:24:35 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 4A122C4332F for ; Wed, 13 Dec 2023 13:52:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441852AbjLMNv7 (ORCPT ); Wed, 13 Dec 2023 08:51:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379292AbjLMNu5 (ORCPT ); Wed, 13 Dec 2023 08:50:57 -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 6986010F for ; Wed, 13 Dec 2023 05:50:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475448; 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=cmTCmlX4lZl7P2Vj72SHk6r4dvh7rcubOpN6X02yzKI=; b=SaM6q/k6jtuq+PLQVrBRQQUookWoS054CnkUxUtB2JeBiAgD2Oa8fjrt2/XIVXRJgjYTyC Supn6PwYIWmQa4lthTZ/daJ7rpfLuGOE/lmxQYEH3P0m/BRwkJoiSIuQt2dhJYcPdgfftJ DR4sWBjWpSokhb6d0ubqjtwtfFprvT0= 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-578-rOMX1xUVPMmZgouvnKpkTQ-1; Wed, 13 Dec 2023 08:50:43 -0500 X-MC-Unique: rOMX1xUVPMmZgouvnKpkTQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 213B8185A782; Wed, 13 Dec 2023 13:50:42 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5667E40C6EB9; Wed, 13 Dec 2023 13:50:41 +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 Subject: [PATCH v2 22/40] afs: Add some more info to /proc/net/afs/servers Date: Wed, 13 Dec 2023 13:49:44 +0000 Message-ID: <20231213135003.367397-23-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In /proc/net/afs/servers, show the cell name and the last error for each address in the server's list. cc: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/fs_operation.c | 2 -- fs/afs/fs_probe.c | 2 ++ fs/afs/proc.c | 24 ++++++++++++++++-------- fs/afs/rotate.c | 2 ++ fs/afs/vl_rotate.c | 2 ++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 00e22259be36..e760e11d5bcb 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -196,8 +196,6 @@ void afs_wait_for_operation(struct afs_operation *op) op->call_abort_code =3D op->call->abort_code; op->call_error =3D op->call->error; op->call_responded =3D op->call->responded; - WRITE_ONCE(op->alist->addrs[op->addr_index].last_error, - op->call_error); afs_put_call(op->call); } } diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index aef16ac3f577..8008d3ecabab 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -107,6 +107,8 @@ void afs_fileserver_probe_result(struct afs_call *call) =20 _enter("%pU,%u", &server->uuid, index); =20 + WRITE_ONCE(addr->last_error, ret); + spin_lock(&server->probe_lock); =20 switch (ret) { diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 16d93fa6396f..0b43bb9b0260 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -377,31 +377,39 @@ static int afs_proc_servers_show(struct seq_file *m, = void *v) { struct afs_server *server; struct afs_addr_list *alist; + unsigned long failed; int i; =20 if (v =3D=3D SEQ_START_TOKEN) { - seq_puts(m, "UUID REF ACT\n"); + seq_puts(m, "UUID REF ACT CELL\n"); return 0; } =20 server =3D list_entry(v, struct afs_server, proc_link); alist =3D rcu_dereference(server->addresses); - seq_printf(m, "%pU %3d %3d\n", + seq_printf(m, "%pU %3d %3d %s\n", &server->uuid, refcount_read(&server->ref), - atomic_read(&server->active)); + atomic_read(&server->active), + server->cell->name); seq_printf(m, " - info: fl=3D%lx rtt=3D%u brk=3D%x\n", server->flags, server->rtt, server->cb_s_break); seq_printf(m, " - probe: last=3D%d out=3D%d\n", (int)(jiffies - server->probed_at) / HZ, atomic_read(&server->probe_outstanding)); + failed =3D alist->probe_failed; seq_printf(m, " - ALIST v=3D%u rsp=3D%lx f=3D%lx\n", alist->version, alist->responded, alist->probe_failed); - for (i =3D 0; i < alist->nr_addrs; i++) - seq_printf(m, " [%x] %pISpc%s rtt=3D%d\n", - i, rxrpc_kernel_remote_addr(alist->addrs[i].peer), - alist->preferred =3D=3D i ? "*" : "", - rxrpc_kernel_get_srtt(alist->addrs[i].peer)); + for (i =3D 0; i < alist->nr_addrs; i++) { + const struct afs_address *addr =3D &alist->addrs[i]; + + seq_printf(m, " [%x] %pISpc%s rtt=3D%d err=3D%d\n", + i, rxrpc_kernel_remote_addr(addr->peer), + alist->preferred =3D=3D i ? "*" : + test_bit(i, &failed) ? "!" : "", + rxrpc_kernel_get_srtt(addr->peer), + addr->last_error); + } return 0; } =20 diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index a6bda8f44c0f..5423ac80f4e0 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -133,6 +133,8 @@ bool afs_select_fileserver(struct afs_operation *op) if (op->nr_iterations =3D=3D 0) goto start; =20 + WRITE_ONCE(alist->addrs[op->addr_index].last_error, error); + /* Evaluate the result of the previous operation, if there was one. */ switch (op->call_error) { case 0: diff --git a/fs/afs/vl_rotate.c b/fs/afs/vl_rotate.c index 91168528179c..d8f79f6ada3d 100644 --- a/fs/afs/vl_rotate.c +++ b/fs/afs/vl_rotate.c @@ -114,6 +114,8 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc) if (vc->nr_iterations =3D=3D 0) goto start; =20 + WRITE_ONCE(alist->addrs[vc->addr_index].last_error, error); + /* Evaluate the result of the previous operation, if there was one. */ switch (error) { default: From nobody Mon Dec 15 21:24:35 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 E0929C4332F for ; Wed, 13 Dec 2023 13:51:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379304AbjLMNvu (ORCPT ); Wed, 13 Dec 2023 08:51:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441914AbjLMNuy (ORCPT ); Wed, 13 Dec 2023 08:50:54 -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 B37FB10F4 for ; Wed, 13 Dec 2023 05:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475446; 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=ldTnN6NaoKpn3Pzj4ymAXo4AbMSJji+PzTFvbDmK2dY=; b=S9OMfbcklWnYkUbRUPqPSOG4l9dgrgI6UveZm5iUduvXSHnIUAASbmd0Wt60YyVmZFtzV7 +8PMQVAmWS/Tsj3kZMWocVEXg2uB3d5A/oQ+JVHLwmSDW2bM031/9DlrB9MPSGjqa8bp0/ TMEvSLxaErlwQEfX9pgUgrN5PKvPdwI= 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-204-YEpkbhlmOCyZaM5FVkfGtA-1; Wed, 13 Dec 2023 08:50:44 -0500 X-MC-Unique: YEpkbhlmOCyZaM5FVkfGtA-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 8EDBD29AC03C; Wed, 13 Dec 2023 13:50:43 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id C56791C060B1; Wed, 13 Dec 2023 13:50:42 +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 Subject: [PATCH v2 23/40] afs: Remove the unimplemented afs_cmp_addr_list() Date: Wed, 13 Dec 2023 13:49:45 +0000 Message-ID: <20231213135003.367397-24-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: quoted-printable 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-Type: text/plain; charset="utf-8" Remove afs_cmp_addr_list() as it was never implemented. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/addr_list.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c index 18c286efa3a5..6d42f85c6be5 100644 --- a/fs/afs/addr_list.c +++ b/fs/afs/addr_list.c @@ -244,19 +244,6 @@ struct afs_vlserver_list *afs_parse_text_addrs(struct = afs_net *net, return ERR_PTR(ret); } =20 -/* - * Compare old and new address lists to see if there's been any change. - * - How to do this in better than O(Nlog(N)) time? - * - We don't really want to sort the address list, but would rather tak= e the - * list as we got it so as not to undo record rotation by the DNS serv= er. - */ -#if 0 -static int afs_cmp_addr_list(const struct afs_addr_list *a1, - const struct afs_addr_list *a2) -{ -} -#endif - /* * Perform a DNS query for VL servers and build a up an address list. */ From nobody Mon Dec 15 21:24:35 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 9F658C4167D for ; Wed, 13 Dec 2023 13:52:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379328AbjLMNv4 (ORCPT ); Wed, 13 Dec 2023 08:51:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379289AbjLMNu5 (ORCPT ); Wed, 13 Dec 2023 08:50:57 -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 4F1E110FE for ; Wed, 13 Dec 2023 05:50:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475447; 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=GcWGCKLyPfse4wDaE+KAhQsj0lGRfM8k4vhEemK4IBQ=; b=TLEu1TP3BhBrdiF67+h3LRQWRLHxn0/IdHUzyD56QAYU0jajSmbNUP0CoVDRaNi2jDL1lm S7qUG4kNo8PPS0iI9/aManl2fYktxEUr9y9/Bc26HCbLwGAS8vrzmaPCQKWWJKcblcupty 3tO4hxMspe0zam8kkspuiRGS+wu2pWs= 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-519-J_A65qURMsmMFdRPvp7ULw-1; Wed, 13 Dec 2023 08:50:45 -0500 X-MC-Unique: J_A65qURMsmMFdRPvp7ULw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 45A2F101A551; Wed, 13 Dec 2023 13:50:45 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EB123C25; Wed, 13 Dec 2023 13:50:44 +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 Subject: [PATCH v2 24/40] afs: Provide a way to configure address priorities Date: Wed, 13 Dec 2023 13:49:46 +0000 Message-ID: <20231213135003.367397-25-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" AFS servers may have multiple addresses, but the client can't easily judge between them as to which one is best. For instance, an address that has a larger RTT might actually have a better bandwidth because it goes through a switch rather than being directly connected - but we can't work this out dynamically unless we push through sufficient data that we can measure it. To allow the administrator to configure this, add a list of preference weightings for server addresses by IPv4/IPv6 address or subnet and allow this to be viewed through a procfile and altered by writing text commands to that same file. Preference rules can be added/updated by: echo "add [/] " >/proc/fs/afs/addr_prefs echo "add udp 1.2.3.4 1000" >/proc/fs/afs/addr_prefs echo "add udp 192.168.0.0/16 3000" >/proc/fs/afs/addr_prefs echo "add udp 1001:2002:0:6::/64 4000" >/proc/fs/afs/addr_prefs and removed by: echo "del [/]" >/proc/fs/afs/addr_prefs echo "del udp 1.2.3.4" >/proc/fs/afs/addr_prefs where the priority is a number between 0 and 65535. The list is split between IPv4 and IPv6 addresses and each sublist is kept in numerical order, with rules that would otherwise match but have different subnet masking being ordered with the most specific submatch first. A subsequent patch will apply these rules. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/Makefile | 1 + fs/afs/addr_prefs.c | 449 ++++++++++++++++++++++++++++++++++++++++++++ fs/afs/internal.h | 29 +++ fs/afs/main.c | 1 + fs/afs/proc.c | 55 +++++- 5 files changed, 534 insertions(+), 1 deletion(-) create mode 100644 fs/afs/addr_prefs.c diff --git a/fs/afs/Makefile b/fs/afs/Makefile index e8956b65d7ff..b3849bea0553 100644 --- a/fs/afs/Makefile +++ b/fs/afs/Makefile @@ -5,6 +5,7 @@ =20 kafs-y :=3D \ addr_list.o \ + addr_prefs.o \ callback.o \ cell.o \ cmservice.o \ diff --git a/fs/afs/addr_prefs.c b/fs/afs/addr_prefs.c new file mode 100644 index 000000000000..c6dcff4f8aa1 --- /dev/null +++ b/fs/afs/addr_prefs.c @@ -0,0 +1,449 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Address preferences management + * + * Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowells@redhat.com) + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": addr_prefs: " fmt +#include +#include +#include +#include +#include +#include "internal.h" + +static inline struct afs_net *afs_seq2net_single(struct seq_file *m) +{ + return afs_net(seq_file_single_net(m)); +} + +/* + * Split a NUL-terminated string up to the first newline around spaces. T= he + * source string will be modified to have NUL-terminations inserted. + */ +static int afs_split_string(char **pbuf, char *strv[], unsigned int maxstr= v) +{ + unsigned int count =3D 0; + char *p =3D *pbuf; + + maxstrv--; /* Allow for terminal NULL */ + for (;;) { + /* Skip over spaces */ + while (isspace(*p)) { + if (*p =3D=3D '\n') { + p++; + break; + } + p++; + } + if (!*p) + break; + + /* Mark start of word */ + if (count >=3D maxstrv) { + pr_warn("Too many elements in string\n"); + return -EINVAL; + } + strv[count++] =3D p; + + /* Skip over word */ + while (!isspace(*p)) + p++; + if (!*p) + break; + + /* Mark end of word */ + if (*p =3D=3D '\n') { + *p++ =3D 0; + break; + } + *p++ =3D 0; + } + + *pbuf =3D p; + strv[count] =3D NULL; + return count; +} + +/* + * Parse an address with an optional subnet mask. + */ +static int afs_parse_address(char *p, struct afs_addr_preference *pref) +{ + const char *stop; + unsigned long mask, tmp; + char *end =3D p + strlen(p); + bool bracket =3D false; + + if (*p =3D=3D '[') { + p++; + bracket =3D true; + } + +#if 0 + if (*p =3D=3D '[') { + p++; + q =3D memchr(p, ']', end - p); + if (!q) { + pr_warn("Can't find closing ']'\n"); + return -EINVAL; + } + } else { + for (q =3D p; q < end; q++) + if (*q =3D=3D '/') + break; + } +#endif + + if (in4_pton(p, end - p, (u8 *)&pref->ipv4_addr, -1, &stop)) { + pref->family =3D AF_INET; + mask =3D 32; + } else if (in6_pton(p, end - p, (u8 *)&pref->ipv6_addr, -1, &stop)) { + pref->family =3D AF_INET6; + mask =3D 128; + } else { + pr_warn("Can't determine address family\n"); + return -EINVAL; + } + + p =3D (char *)stop; + if (bracket) { + if (*p !=3D ']') { + pr_warn("Can't find closing ']'\n"); + return -EINVAL; + } + p++; + } + + if (*p =3D=3D '/') { + p++; + tmp =3D simple_strtoul(p, &p, 10); + if (tmp > mask) { + pr_warn("Subnet mask too large\n"); + return -EINVAL; + } + if (tmp =3D=3D 0) { + pr_warn("Subnet mask too small\n"); + return -EINVAL; + } + mask =3D tmp; + } + + if (*p) { + pr_warn("Invalid address\n"); + return -EINVAL; + } + + pref->subnet_mask =3D mask; + return 0; +} + +enum cmp_ret { + CONTINUE_SEARCH, + INSERT_HERE, + EXACT_MATCH, + SUBNET_MATCH, +}; + +/* + * See if a candidate address matches a listed address. + */ +static enum cmp_ret afs_cmp_address_pref(const struct afs_addr_preference = *a, + const struct afs_addr_preference *b) +{ + int subnet =3D min(a->subnet_mask, b->subnet_mask); + const __be32 *pa, *pb; + u32 mask, na, nb; + int diff; + + if (a->family !=3D b->family) + return INSERT_HERE; + + switch (a->family) { + case AF_INET6: + pa =3D a->ipv6_addr.s6_addr32; + pb =3D b->ipv6_addr.s6_addr32; + break; + case AF_INET: + pa =3D &a->ipv4_addr.s_addr; + pb =3D &b->ipv4_addr.s_addr; + break; + } + + while (subnet > 32) { + diff =3D ntohl(*pa++) - ntohl(*pb++); + if (diff < 0) + return INSERT_HERE; /* a 0) + return CONTINUE_SEARCH; /* a>b */ + subnet -=3D 32; + } + + if (subnet =3D=3D 0) + return EXACT_MATCH; + + mask =3D 0xffffffffU << (32 - subnet); + na =3D ntohl(*pa); + nb =3D ntohl(*pb); + diff =3D (na & mask) - (nb & mask); + //kdebug("diff %08x %08x %08x %d", na, nb, mask, diff); + if (diff < 0) + return INSERT_HERE; /* a 0) + return CONTINUE_SEARCH; /* a>b */ + if (a->subnet_mask =3D=3D b->subnet_mask) + return EXACT_MATCH; + if (a->subnet_mask > b->subnet_mask) + return SUBNET_MATCH; /* a binds tighter than b */ + return CONTINUE_SEARCH; /* b binds tighter than a */ +} + +/* + * Insert an address preference. + */ +static int afs_insert_address_pref(struct afs_addr_preference_list **_pref= list, + struct afs_addr_preference *pref, + int index) +{ + struct afs_addr_preference_list *preflist =3D *_preflist, *old =3D prefli= st; + size_t size, max_prefs; + + _enter("{%u/%u/%u},%u", preflist->ipv6_off, preflist->nr, preflist->max_p= refs, index); + + if (preflist->nr =3D=3D 255) + return -ENOSPC; + if (preflist->nr >=3D preflist->max_prefs) { + max_prefs =3D preflist->max_prefs + 1; + size =3D struct_size(preflist, prefs, max_prefs); + size =3D roundup_pow_of_two(size); + max_prefs =3D min_t(size_t, (size - sizeof(*preflist)) / sizeof(*pref), = 255); + preflist =3D kmalloc(size, GFP_KERNEL); + if (!preflist) + return -ENOMEM; + *preflist =3D **_preflist; + preflist->max_prefs =3D max_prefs; + *_preflist =3D preflist; + + if (index < preflist->nr) + memcpy(preflist->prefs + index + 1, old->prefs + index, + sizeof(*pref) * (preflist->nr - index)); + if (index > 0) + memcpy(preflist->prefs, old->prefs, sizeof(*pref) * index); + } else { + if (index < preflist->nr) + memmove(preflist->prefs + index + 1, preflist->prefs + index, + sizeof(*pref) * (preflist->nr - index)); + } + + preflist->prefs[index] =3D *pref; + preflist->nr++; + if (pref->family =3D=3D AF_INET) + preflist->ipv6_off++; + return 0; +} + +/* + * Add an address preference. + * echo "add [/] " >/proc/fs/afs/addr_prefs + */ +static int afs_add_address_pref(struct afs_net *net, struct afs_addr_prefe= rence_list **_preflist, + int argc, char **argv) +{ + struct afs_addr_preference_list *preflist =3D *_preflist; + struct afs_addr_preference pref; + enum cmp_ret cmp; + int ret, i, stop; + + if (argc !=3D 3) { + pr_warn("Wrong number of params\n"); + return -EINVAL; + } + + if (strcmp(argv[0], "udp") !=3D 0) { + pr_warn("Unsupported protocol\n"); + return -EINVAL; + } + + ret =3D afs_parse_address(argv[1], &pref); + if (ret < 0) + return ret; + + ret =3D kstrtou16(argv[2], 10, &pref.prio); + if (ret < 0) { + pr_warn("Invalid priority\n"); + return ret; + } + + if (pref.family =3D=3D AF_INET) { + i =3D 0; + stop =3D preflist->ipv6_off; + } else { + i =3D preflist->ipv6_off; + stop =3D preflist->nr; + } + + for (; i < stop; i++) { + cmp =3D afs_cmp_address_pref(&pref, &preflist->prefs[i]); + switch (cmp) { + case CONTINUE_SEARCH: + continue; + case INSERT_HERE: + case SUBNET_MATCH: + return afs_insert_address_pref(_preflist, &pref, i); + case EXACT_MATCH: + preflist->prefs[i].prio =3D pref.prio; + return 0; + } + } + + return afs_insert_address_pref(_preflist, &pref, i); +} + +/* + * Delete an address preference. + */ +static int afs_delete_address_pref(struct afs_addr_preference_list **_pref= list, + int index) +{ + struct afs_addr_preference_list *preflist =3D *_preflist; + + _enter("{%u/%u/%u},%u", preflist->ipv6_off, preflist->nr, preflist->max_p= refs, index); + + if (preflist->nr =3D=3D 0) + return -ENOENT; + + if (index < preflist->nr - 1) + memmove(preflist->prefs + index, preflist->prefs + index + 1, + sizeof(preflist->prefs[0]) * (preflist->nr - index - 1)); + + if (index < preflist->ipv6_off) + preflist->ipv6_off--; + preflist->nr--; + return 0; +} + +/* + * Delete an address preference. + * echo "del [/]" >/proc/fs/afs/addr_prefs + */ +static int afs_del_address_pref(struct afs_net *net, struct afs_addr_prefe= rence_list **_preflist, + int argc, char **argv) +{ + struct afs_addr_preference_list *preflist =3D *_preflist; + struct afs_addr_preference pref; + enum cmp_ret cmp; + int ret, i, stop; + + if (argc !=3D 2) { + pr_warn("Wrong number of params\n"); + return -EINVAL; + } + + if (strcmp(argv[0], "udp") !=3D 0) { + pr_warn("Unsupported protocol\n"); + return -EINVAL; + } + + ret =3D afs_parse_address(argv[1], &pref); + if (ret < 0) + return ret; + + if (pref.family =3D=3D AF_INET) { + i =3D 0; + stop =3D preflist->ipv6_off; + } else { + i =3D preflist->ipv6_off; + stop =3D preflist->nr; + } + + for (; i < stop; i++) { + cmp =3D afs_cmp_address_pref(&pref, &preflist->prefs[i]); + switch (cmp) { + case CONTINUE_SEARCH: + continue; + case INSERT_HERE: + case SUBNET_MATCH: + return 0; + case EXACT_MATCH: + return afs_delete_address_pref(_preflist, i); + } + } + + return -ENOANO; +} + +/* + * Handle writes to /proc/fs/afs/addr_prefs + */ +int afs_proc_addr_prefs_write(struct file *file, char *buf, size_t size) +{ + struct afs_addr_preference_list *preflist, *old; + struct seq_file *m =3D file->private_data; + struct afs_net *net =3D afs_seq2net_single(m); + size_t psize; + char *argv[5]; + int ret, argc, max_prefs; + + inode_lock(file_inode(file)); + + /* Allocate a candidate new list and initialise it from the old. */ + old =3D rcu_dereference_protected(net->address_prefs, + lockdep_is_held(&file_inode(file)->i_rwsem)); + + if (old) + max_prefs =3D old->nr + 1; + else + max_prefs =3D 1; + + psize =3D struct_size(old, prefs, max_prefs); + psize =3D roundup_pow_of_two(psize); + max_prefs =3D min_t(size_t, (psize - sizeof(*old)) / sizeof(old->prefs[0]= ), 255); + + ret =3D -ENOMEM; + preflist =3D kmalloc(struct_size(preflist, prefs, max_prefs), GFP_KERNEL); + if (!preflist) + goto done; + + if (old) + memcpy(preflist, old, struct_size(preflist, prefs, old->nr)); + else + memset(preflist, 0, sizeof(*preflist)); + preflist->max_prefs =3D max_prefs; + + do { + argc =3D afs_split_string(&buf, argv, ARRAY_SIZE(argv)); + if (argc < 0) + return argc; + if (argc < 2) + goto inval; + + if (strcmp(argv[0], "add") =3D=3D 0) + ret =3D afs_add_address_pref(net, &preflist, argc - 1, argv + 1); + else if (strcmp(argv[0], "del") =3D=3D 0) + ret =3D afs_del_address_pref(net, &preflist, argc - 1, argv + 1); + else + goto inval; + if (ret < 0) + goto done; + } while (*buf); + + preflist->version++; + rcu_assign_pointer(net->address_prefs, preflist); + /* Store prefs before version */ + smp_store_release(&net->address_pref_version, preflist->version); + kfree_rcu(old, rcu); + preflist =3D NULL; + ret =3D 0; + +done: + kfree(preflist); + inode_unlock(file_inode(file)); + _leave(" =3D %d", ret); + return ret; + +inval: + pr_warn("Invalid Command\n"); + ret =3D -EINVAL; + goto done; +} diff --git a/fs/afs/internal.h b/fs/afs/internal.h index ae33dd8ae49b..4445c734cdcd 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -72,6 +72,28 @@ enum afs_call_state { AFS_CALL_COMPLETE, /* Completed or failed */ }; =20 +/* + * Address preferences. + */ +struct afs_addr_preference { + union { + struct in_addr ipv4_addr; /* AF_INET address to compare against */ + struct in6_addr ipv6_addr; /* AF_INET6 address to compare against */ + }; + sa_family_t family; /* Which address to use */ + u16 prio; /* Priority */ + u8 subnet_mask; /* How many bits to compare */ +}; + +struct afs_addr_preference_list { + struct rcu_head rcu; + u16 version; /* Incremented when prefs list changes */ + u8 ipv6_off; /* Offset of IPv6 addresses */ + u8 nr; /* Number of addresses in total */ + u8 max_prefs; /* Number of prefs allocated */ + struct afs_addr_preference prefs[] __counted_by(max_prefs); +}; + struct afs_address { struct rxrpc_peer *peer; short last_error; /* Last error from this address */ @@ -315,6 +337,8 @@ struct afs_net { struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */ struct afs_sysnames *sysnames; rwlock_t sysnames_lock; + struct afs_addr_preference_list __rcu *address_prefs; + u16 address_pref_version; =20 /* Statistics counters */ atomic_t n_lookup; /* Number of lookups done */ @@ -982,6 +1006,11 @@ extern int afs_merge_fs_addr4(struct afs_net *net, st= ruct afs_addr_list *addr, extern int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *a= ddr, __be32 *xdr, u16 port); =20 +/* + * addr_prefs.c + */ +int afs_proc_addr_prefs_write(struct file *file, char *buf, size_t size); + /* * callback.c */ diff --git a/fs/afs/main.c b/fs/afs/main.c index 6425c81d07de..1b3bd21c168a 100644 --- a/fs/afs/main.c +++ b/fs/afs/main.c @@ -156,6 +156,7 @@ static void __net_exit afs_net_exit(struct net *net_ns) afs_close_socket(net); afs_proc_cleanup(net); afs_put_sysnames(net->sysnames); + kfree_rcu(rcu_access_pointer(net->address_prefs), rcu); } =20 static struct pernet_operations afs_net_ops =3D { diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 0b43bb9b0260..2e63c99a4f1e 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -146,6 +146,55 @@ static int afs_proc_cells_write(struct file *file, cha= r *buf, size_t size) goto done; } =20 +/* + * Display the list of addr_prefs known to the namespace. + */ +static int afs_proc_addr_prefs_show(struct seq_file *m, void *v) +{ + struct afs_addr_preference_list *preflist; + struct afs_addr_preference *pref; + struct afs_net *net =3D afs_seq2net_single(m); + union { + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + } addr; + unsigned int i; + char buf[44]; /* Maximum ipv6 + max subnet is 43 */ + + rcu_read_lock(); + preflist =3D rcu_dereference(net->address_prefs); + + if (!preflist) { + seq_puts(m, "NO PREFS\n"); + return 0; + } + + seq_printf(m, "PROT SUBNET PRIOR (v= =3D%u n=3D%u/%u/%u)\n", + preflist->version, preflist->ipv6_off, preflist->nr, preflist->max_pr= efs); + + memset(&addr, 0, sizeof(addr)); + + for (i =3D 0; i < preflist->nr; i++) { + pref =3D &preflist->prefs[i]; + + addr.sin.sin_family =3D pref->family; + if (pref->family =3D=3D AF_INET) { + memcpy(&addr.sin.sin_addr, &pref->ipv4_addr, + sizeof(addr.sin.sin_addr)); + snprintf(buf, sizeof(buf), "%pISc/%u", &addr.sin, pref->subnet_mask); + seq_printf(m, "UDP %-43.43s %5u\n", buf, pref->prio); + } else { + memcpy(&addr.sin6.sin6_addr, &pref->ipv6_addr, + sizeof(addr.sin6.sin6_addr)); + snprintf(buf, sizeof(buf), "%pISc/%u", &addr.sin6, pref->subnet_mask); + seq_printf(m, "UDP %-43.43s %5u\n", buf, pref->prio); + } + } + + rcu_read_lock(); + return 0; +} + /* * Display the name of the current workstation cell. */ @@ -690,7 +739,11 @@ int afs_proc_init(struct afs_net *net) &afs_proc_sysname_ops, afs_proc_sysname_write, sizeof(struct seq_net_private), - NULL)) + NULL) || + !proc_create_net_single_write("addr_prefs", 0644, p, + afs_proc_addr_prefs_show, + afs_proc_addr_prefs_write, + NULL)) goto error_tree; =20 net->proc_afs =3D p; From nobody Mon Dec 15 21:24:35 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 2CCBFC4332F for ; Wed, 13 Dec 2023 13:52:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441861AbjLMNwC (ORCPT ); Wed, 13 Dec 2023 08:52:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379313AbjLMNvB (ORCPT ); Wed, 13 Dec 2023 08:51:01 -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 CB20A12B for ; Wed, 13 Dec 2023 05:50:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475451; 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=KxknlvC/si6svtnBVShJ/D8TPx6S78MICdfSTIeGIDk=; b=Ed+SP3adio7qlHsCRyCTs1bpN5v1U8MBbCThjyIw0oAf8BiX0iZA0aNycvZZAHMCm0ybJY LPX8VdNG8A4IMSWBizKr4le1FpKt348fiiDCRiU+YygZgoO+OSCFFGC8kAtbt86bFBrX/C DHMiW8TEw7TomOvGONEcdXOCvuytIys= 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-659-dLyoTIeVP4iDT8venuAoPw-1; Wed, 13 Dec 2023 08:50:47 -0500 X-MC-Unique: dLyoTIeVP4iDT8venuAoPw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 B21DC837193; Wed, 13 Dec 2023 13:50:46 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6D933C25; Wed, 13 Dec 2023 13:50:45 +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 Subject: [PATCH v2 25/40] afs: Mark address lists with configured priorities Date: Wed, 13 Dec 2023 13:49:47 +0000 Message-ID: <20231213135003.367397-26-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a field to each address in an address list (afs_addr_list struct) that records the current priority for that address according to the address preference table. We don't want to do this every time we use an address list, so the version number of the address preference table is recorded in the address list too and we only re-mark the list when we see the version change. These numbers are then displayed through /proc/net/afs/servers. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/addr_prefs.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ fs/afs/internal.h | 4 +++ fs/afs/proc.c | 9 ++--- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/fs/afs/addr_prefs.c b/fs/afs/addr_prefs.c index c6dcff4f8aa1..a189ff8a5034 100644 --- a/fs/afs/addr_prefs.c +++ b/fs/afs/addr_prefs.c @@ -447,3 +447,85 @@ int afs_proc_addr_prefs_write(struct file *file, char = *buf, size_t size) ret =3D -EINVAL; goto done; } + +/* + * Mark the priorities on an address list if the address preferences table= has + * changed. The caller must hold the RCU read lock. + */ +void afs_get_address_preferences_rcu(struct afs_net *net, struct afs_addr_= list *alist) +{ + const struct afs_addr_preference_list *preflist =3D + rcu_dereference(net->address_prefs); + const struct sockaddr_in6 *sin6; + const struct sockaddr_in *sin; + const struct sockaddr *sa; + struct afs_addr_preference test; + enum cmp_ret cmp; + int i, j; + + if (!preflist || !preflist->nr || !alist->nr_addrs || + smp_load_acquire(&alist->addr_pref_version) =3D=3D preflist->version) + return; + + test.family =3D AF_INET; + test.subnet_mask =3D 32; + test.prio =3D 0; + for (i =3D 0; i < alist->nr_ipv4; i++) { + sa =3D rxrpc_kernel_remote_addr(alist->addrs[i].peer); + sin =3D (const struct sockaddr_in *)sa; + test.ipv4_addr =3D sin->sin_addr; + for (j =3D 0; j < preflist->ipv6_off; j++) { + cmp =3D afs_cmp_address_pref(&test, &preflist->prefs[j]); + switch (cmp) { + case CONTINUE_SEARCH: + continue; + case INSERT_HERE: + break; + case EXACT_MATCH: + case SUBNET_MATCH: + WRITE_ONCE(alist->addrs[i].prio, preflist->prefs[j].prio); + break; + } + } + } + + test.family =3D AF_INET6; + test.subnet_mask =3D 128; + test.prio =3D 0; + for (; i < alist->nr_addrs; i++) { + sa =3D rxrpc_kernel_remote_addr(alist->addrs[i].peer); + sin6 =3D (const struct sockaddr_in6 *)sa; + test.ipv6_addr =3D sin6->sin6_addr; + for (j =3D preflist->ipv6_off; j < preflist->nr; j++) { + cmp =3D afs_cmp_address_pref(&test, &preflist->prefs[j]); + switch (cmp) { + case CONTINUE_SEARCH: + continue; + case INSERT_HERE: + break; + case EXACT_MATCH: + case SUBNET_MATCH: + WRITE_ONCE(alist->addrs[i].prio, preflist->prefs[j].prio); + break; + } + } + } + + smp_store_release(&alist->addr_pref_version, preflist->version); +} + +/* + * Mark the priorities on an address list if the address preferences table= has + * changed. Avoid taking the RCU read lock if we can. + */ +void afs_get_address_preferences(struct afs_net *net, struct afs_addr_list= *alist) +{ + if (!net->address_prefs || + /* Load version before prefs */ + smp_load_acquire(&net->address_pref_version) =3D=3D alist->addr_pref_= version) + return; + + rcu_read_lock(); + afs_get_address_preferences_rcu(net, alist); + rcu_read_unlock(); +} diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 4445c734cdcd..9a1e151e77e7 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -97,6 +97,7 @@ struct afs_addr_preference_list { struct afs_address { struct rxrpc_peer *peer; short last_error; /* Last error from this address */ + u16 prio; /* Address priority */ }; =20 /* @@ -107,6 +108,7 @@ struct afs_addr_list { refcount_t usage; u32 version; /* Version */ unsigned int debug_id; + unsigned int addr_pref_version; /* Version of address preference list */ unsigned char max_addrs; unsigned char nr_addrs; unsigned char preferred; /* Preferred address */ @@ -1010,6 +1012,8 @@ extern int afs_merge_fs_addr6(struct afs_net *net, st= ruct afs_addr_list *addr, * addr_prefs.c */ int afs_proc_addr_prefs_write(struct file *file, char *buf, size_t size); +void afs_get_address_preferences_rcu(struct afs_net *net, struct afs_addr_= list *alist); +void afs_get_address_preferences(struct afs_net *net, struct afs_addr_list= *alist); =20 /* * callback.c diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 2e63c99a4f1e..944eb51e75a1 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -447,17 +447,18 @@ static int afs_proc_servers_show(struct seq_file *m, = void *v) (int)(jiffies - server->probed_at) / HZ, atomic_read(&server->probe_outstanding)); failed =3D alist->probe_failed; - seq_printf(m, " - ALIST v=3D%u rsp=3D%lx f=3D%lx\n", - alist->version, alist->responded, alist->probe_failed); + seq_printf(m, " - ALIST v=3D%u rsp=3D%lx f=3D%lx ap=3D%u\n", + alist->version, alist->responded, alist->probe_failed, + alist->addr_pref_version); for (i =3D 0; i < alist->nr_addrs; i++) { const struct afs_address *addr =3D &alist->addrs[i]; =20 - seq_printf(m, " [%x] %pISpc%s rtt=3D%d err=3D%d\n", + seq_printf(m, " [%x] %pISpc%s rtt=3D%d err=3D%d p=3D%u\n", i, rxrpc_kernel_remote_addr(addr->peer), alist->preferred =3D=3D i ? "*" : test_bit(i, &failed) ? "!" : "", rxrpc_kernel_get_srtt(addr->peer), - addr->last_error); + addr->last_error, addr->prio); } return 0; } From nobody Mon Dec 15 21:24:35 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 C734BC4332F for ; Wed, 13 Dec 2023 13:52:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379267AbjLMNwN (ORCPT ); Wed, 13 Dec 2023 08:52:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379316AbjLMNvR (ORCPT ); Wed, 13 Dec 2023 08:51:17 -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 A4E0EEA for ; Wed, 13 Dec 2023 05:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475455; 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=0G9cfB/SMcsuQUP6NSXMvLH/gTThJ4V8NgpcMlTJhZ4=; b=aH2PyinF6UOUhs8mnrGTnJFmkfEvnPeG7/Ma3KJLZQNbhHX2lkcgbSOcnob0+jorXbZs3Q c6PYvHmJ06JCWnH7IhtFfyfWF2NUPrPIwcLi0vAdg9N3Cwt9Waoo7OVTkEmQo/hJ8Cg/hk NbS+8INlR37pT1/rCcL/2LbslH9RNl4= 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-385-FYgpMzeqMsCvhG2fnYPSqw-1; Wed, 13 Dec 2023 08:50:48 -0500 X-MC-Unique: FYgpMzeqMsCvhG2fnYPSqw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 259D483718B; Wed, 13 Dec 2023 13:50:48 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C96D3C25; Wed, 13 Dec 2023 13:50:47 +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 Subject: [PATCH v2 26/40] afs: Dispatch fileserver probes in priority order Date: Wed, 13 Dec 2023 13:49:48 +0000 Message-ID: <20231213135003.367397-27-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When probing all the addresses for a fileserver, dispatch them in order of descending priority to try and get back highest priority one first. Also add a tracepoint to show the transmission and completion of the probes. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/fs_probe.c | 25 +++++++++++++++++++++++-- include/trace/events/afs.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index 8008d3ecabab..c5702698b18b 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -102,7 +102,7 @@ void afs_fileserver_probe_result(struct afs_call *call) struct afs_address *addr =3D &alist->addrs[call->probe_index]; struct afs_server *server =3D call->server; unsigned int index =3D call->probe_index; - unsigned int rtt_us =3D 0, cap0; + unsigned int rtt_us =3D -1, cap0; int ret =3D call->error; =20 _enter("%pU,%u", &server->uuid, index); @@ -182,6 +182,7 @@ void afs_fileserver_probe_result(struct afs_call *call) out: spin_unlock(&server->probe_lock); =20 + trace_afs_fs_probe(server, false, alist, index, call->error, call->abort_= code, rtt_us); _debug("probe %pU [%u] %pISpc rtt=3D%d ret=3D%d", &server->uuid, index, rxrpc_kernel_remote_addr(alist->addrs[index]= .peer), rtt_us, ret); @@ -207,6 +208,8 @@ void afs_fs_probe_fileserver(struct afs_net *net, struc= t afs_server *server, afs_get_addrlist(alist, afs_alist_trace_get_probe); read_unlock(&server->fs_lock); =20 + afs_get_address_preferences(net, alist); + server->probed_at =3D jiffies; atomic_set(&server->probe_outstanding, all ? alist->nr_addrs : 1); memset(&server->probe, 0, sizeof(server->probe)); @@ -217,10 +220,28 @@ void afs_fs_probe_fileserver(struct afs_net *net, str= uct afs_server *server, all =3D true; =20 if (all) { - for (index =3D 0; index < alist->nr_addrs; index++) + unsigned long unprobed =3D (1UL << alist->nr_addrs) - 1; + unsigned int i; + int best_prio; + + while (unprobed) { + best_prio =3D -1; + index =3D 0; + for (i =3D 0; i < alist->nr_addrs; i++) { + if (test_bit(i, &unprobed) && + alist->addrs[i].prio > best_prio) { + index =3D i; + best_prio =3D alist->addrs[i].prio; + } + } + __clear_bit(index, &unprobed); + + trace_afs_fs_probe(server, true, alist, index, 0, 0, 0); if (!afs_fs_get_capabilities(net, server, alist, index, key)) afs_fs_probe_not_done(net, server, alist, index); + } } else { + trace_afs_fs_probe(server, true, alist, index, 0, 0, 0); if (!afs_fs_get_capabilities(net, server, alist, index, key)) afs_fs_probe_not_done(net, server, alist, index); } diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index 0f68d67f52c8..81eb87fbcfa7 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -1387,6 +1387,39 @@ TRACE_EVENT(afs_alist, __entry->ref) ); =20 +TRACE_EVENT(afs_fs_probe, + TP_PROTO(struct afs_server *server, bool tx, struct afs_addr_list *al= ist, + unsigned int addr_index, int error, s32 abort_code, unsigned int rt= t_us), + + TP_ARGS(server, tx, alist, addr_index, error, abort_code, rtt_us), + + TP_STRUCT__entry( + __field(unsigned int, server) + __field(bool, tx) + __field(u16, addr_index) + __field(short, error) + __field(s32, abort_code) + __field(unsigned int, rtt_us) + __field_struct(struct sockaddr_rxrpc, srx) + ), + + TP_fast_assign( + __entry->server =3D server->debug_id; + __entry->tx =3D tx; + __entry->addr_index =3D addr_index; + __entry->error =3D error; + __entry->abort_code =3D abort_code; + __entry->rtt_us =3D rtt_us; + memcpy(&__entry->srx, rxrpc_kernel_remote_srx(alist->addrs[addr_inde= x].peer), + sizeof(__entry->srx)); + ), + + TP_printk("s=3D%08x %s ax=3D%u e=3D%d ac=3D%d rtt=3D%d %pISpc", + __entry->server, __entry->tx ? "tx" : "rx", __entry->addr_index, + __entry->error, __entry->abort_code, __entry->rtt_us, + &__entry->srx.transport) + ); + #endif /* _TRACE_AFS_H */ =20 /* This part must be outside protection */ From nobody Mon Dec 15 21:24:35 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 E653BC4167D for ; Wed, 13 Dec 2023 13:52:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379356AbjLMNwK (ORCPT ); Wed, 13 Dec 2023 08:52:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379338AbjLMNvD (ORCPT ); Wed, 13 Dec 2023 08:51:03 -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 D626412D for ; Wed, 13 Dec 2023 05:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475453; 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=9uxlhhzYOJGE/EnjwXuTD2EVqz5vY7VT/PkRDYqehTo=; b=X/zPZk+Yb9HwOsmmfAVdTE7026F6eSHai62SiEHrlfEkEbTLKJbAEshQB3jNW7SVCZPSam muYvvctR+QXjG5FA5CTXU/H9sYfZqXTiASAhhCqTMcdkNeIpoVnXKgKFk0ji5Gk22k0H0L Hps6D6gtcS9FUhSb7SvjBjN+sBEF96s= 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-638-uz8qfnuzN8GJS4LAl_yvKg-1; Wed, 13 Dec 2023 08:50:49 -0500 X-MC-Unique: uz8qfnuzN8GJS4LAl_yvKg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 9371C185A785; Wed, 13 Dec 2023 13:50:49 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id C77C740C6EBA; Wed, 13 Dec 2023 13:50:48 +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 Subject: [PATCH v2 27/40] afs: Dispatch vlserver probes in priority order Date: Wed, 13 Dec 2023 13:49:49 +0000 Message-ID: <20231213135003.367397-28-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When probing all the addresses for a volume location server, dispatch them in order of descending priority to try and get back highest priority one first. Also add a tracepoint to show the transmission and completion of the probes. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/internal.h | 1 + fs/afs/vl_list.c | 2 ++ fs/afs/vl_probe.c | 20 ++++++++++++++++++-- include/trace/events/afs.h | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 9a1e151e77e7..88db04220773 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -447,6 +447,7 @@ struct afs_vlserver { rwlock_t lock; /* Lock on addresses */ refcount_t ref; unsigned int rtt; /* Server's current RTT in uS */ + unsigned int debug_id; =20 /* Probe state */ wait_queue_head_t probe_wq; diff --git a/fs/afs/vl_list.c b/fs/afs/vl_list.c index 5c4cd71caccf..9b1c20daac53 100644 --- a/fs/afs/vl_list.c +++ b/fs/afs/vl_list.c @@ -13,6 +13,7 @@ struct afs_vlserver *afs_alloc_vlserver(const char *name,= size_t name_len, unsigned short port) { struct afs_vlserver *vlserver; + static atomic_t debug_ids; =20 vlserver =3D kzalloc(struct_size(vlserver, name, name_len + 1), GFP_KERNEL); @@ -21,6 +22,7 @@ struct afs_vlserver *afs_alloc_vlserver(const char *name,= size_t name_len, rwlock_init(&vlserver->lock); init_waitqueue_head(&vlserver->probe_wq); spin_lock_init(&vlserver->probe_lock); + vlserver->debug_id =3D atomic_inc_return(&debug_ids); vlserver->rtt =3D UINT_MAX; vlserver->name_len =3D name_len; vlserver->service_id =3D VL_SERVICE; diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c index f868ae5d40e5..b128dc3d8af7 100644 --- a/fs/afs/vl_probe.c +++ b/fs/afs/vl_probe.c @@ -131,6 +131,7 @@ void afs_vlserver_probe_result(struct afs_call *call) out: spin_unlock(&server->probe_lock); =20 + trace_afs_vl_probe(server, false, alist, index, call->error, call->abort_= code, rtt_us); _debug("probe [%u][%u] %pISpc rtt=3D%d ret=3D%d", server_index, index, rxrpc_kernel_remote_addr(addr->peer), rtt_us, ret); @@ -150,8 +151,10 @@ static bool afs_do_probe_vlserver(struct afs_net *net, { struct afs_addr_list *alist; struct afs_call *call; - unsigned int index; + unsigned long unprobed; + unsigned int index, i; bool in_progress =3D false; + int best_prio; =20 _enter("%s", server->name); =20 @@ -165,7 +168,20 @@ static bool afs_do_probe_vlserver(struct afs_net *net, memset(&server->probe, 0, sizeof(server->probe)); server->probe.rtt =3D UINT_MAX; =20 - for (index =3D 0; index < alist->nr_addrs; index++) { + unprobed =3D (1UL << alist->nr_addrs) - 1; + while (unprobed) { + best_prio =3D -1; + index =3D 0; + for (i =3D 0; i < alist->nr_addrs; i++) { + if (test_bit(i, &unprobed) && + alist->addrs[i].prio > best_prio) { + index =3D i; + best_prio =3D alist->addrs[i].prio; + } + } + __clear_bit(index, &unprobed); + + trace_afs_vl_probe(server, true, alist, index, 0, 0, 0); call =3D afs_vl_get_capabilities(net, alist, index, key, server, server_index); if (!IS_ERR(call)) { diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index 81eb87fbcfa7..f1815b3dafb0 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -1420,6 +1420,40 @@ TRACE_EVENT(afs_fs_probe, &__entry->srx.transport) ); =20 +TRACE_EVENT(afs_vl_probe, + TP_PROTO(struct afs_vlserver *server, bool tx, struct afs_addr_list *= alist, + unsigned int addr_index, int error, s32 abort_code, unsigned int rt= t_us), + + TP_ARGS(server, tx, alist, addr_index, error, abort_code, rtt_us), + + TP_STRUCT__entry( + __field(unsigned int, server) + __field(bool, tx) + __field(unsigned short, flags) + __field(u16, addr_index) + __field(short, error) + __field(s32, abort_code) + __field(unsigned int, rtt_us) + __field_struct(struct sockaddr_rxrpc, srx) + ), + + TP_fast_assign( + __entry->server =3D server->debug_id; + __entry->tx =3D tx; + __entry->addr_index =3D addr_index; + __entry->error =3D error; + __entry->abort_code =3D abort_code; + __entry->rtt_us =3D rtt_us; + memcpy(&__entry->srx, rxrpc_kernel_remote_srx(alist->addrs[addr_inde= x].peer), + sizeof(__entry->srx)); + ), + + TP_printk("vl=3D%08x %s ax=3D%u e=3D%d ac=3D%d rtt=3D%d %pISpc", + __entry->server, __entry->tx ? "tx" : "rx", __entry->addr_index, + __entry->error, __entry->abort_code, __entry->rtt_us, + &__entry->srx.transport) + ); + #endif /* _TRACE_AFS_H */ =20 /* This part must be outside protection */ From nobody Mon Dec 15 21:24:35 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 707EEC4332F for ; Wed, 13 Dec 2023 13:52:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441876AbjLMNwf (ORCPT ); Wed, 13 Dec 2023 08:52:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379396AbjLMNvh (ORCPT ); Wed, 13 Dec 2023 08:51:37 -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 B2015DC for ; Wed, 13 Dec 2023 05:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475457; 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=rh4qbkDsLwX6d4hR6qGSDOd9w/xYHcjQ66/NZZW4aHU=; b=L3AORoka5l4+FNFQdlb3oEiYtzZ9Fwrr7YpRPT/2cbHz1fLvBpbB/0WlVPh0laxuN7G4nV RNu04FTSkM5qnqoeAhRCBR/G4W0LSnRchbDsb8jCYkBc1k30LMwxmZNg0eWxvGpWSoQL+z dgFuKi/5LSlJmMRiIU5iMzh/ivnnzNI= 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-217-giC_5n8NOKKsqCyMQW914Q-1; Wed, 13 Dec 2023 08:50:51 -0500 X-MC-Unique: giC_5n8NOKKsqCyMQW914Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 7C0B43869149; Wed, 13 Dec 2023 13:50:51 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5876DC1596E; Wed, 13 Dec 2023 13:50:50 +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 Subject: [PATCH v2 28/40] afs: Keep a record of the current fileserver endpoint state Date: Wed, 13 Dec 2023 13:49:50 +0000 Message-ID: <20231213135003.367397-29-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Keep a record of the current fileserver endpoint state, including the probe state, and replace it when a new probe is started rather than just squelching the old state and overwriting it. Clearance of the old state can cause a race if there's another thread also currently trying to communicate with that server. It appears that this race might be the culprit for some occasions where kafs complains about invalid data in the RPC reply because the rotation algorithm fell all the way through without actually issuing an RPC call and the error return got filled in from the probe state (which has a zero error recorded). Whatever happens to be in the caller's reply buffer is then taken as the response. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/fs_operation.c | 19 +-- fs/afs/fs_probe.c | 235 ++++++++++++++++++++++--------------- fs/afs/fsclient.c | 8 +- fs/afs/internal.h | 66 +++++++---- fs/afs/proc.c | 21 ++-- fs/afs/rotate.c | 80 +++++++------ fs/afs/server.c | 69 +++++++---- fs/afs/vl_alias.c | 4 +- fs/afs/vl_probe.c | 2 +- fs/afs/vlclient.c | 4 +- include/trace/events/afs.h | 69 ++++++++--- 11 files changed, 366 insertions(+), 211 deletions(-) diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index e760e11d5bcb..8c6d827f999d 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -228,6 +228,7 @@ void afs_wait_for_operation(struct afs_operation *op) */ int afs_put_operation(struct afs_operation *op) { + struct afs_endpoint_state *estate =3D op->estate; struct afs_addr_list *alist; int i, ret =3D afs_op_error(op); =20 @@ -251,14 +252,16 @@ int afs_put_operation(struct afs_operation *op) kfree(op->more_files); } =20 - alist =3D op->alist; - if (alist) { - if (op->call_responded && - op->addr_index !=3D alist->preferred && - test_bit(alist->preferred, &op->addr_tried)) - WRITE_ONCE(alist->preferred, op->addr_index); - afs_put_addrlist(alist, afs_alist_trace_put_operation); - op->alist =3D NULL; + if (estate) { + alist =3D estate->addresses; + if (alist) { + if (op->call_responded && + op->addr_index !=3D alist->preferred && + test_bit(alist->preferred, &op->addr_tried)) + WRITE_ONCE(alist->preferred, op->addr_index); + } + afs_put_endpoint_state(estate, afs_estate_trace_put_operation); + op->estate =3D NULL; } =20 afs_put_serverlist(op->net, op->server_list); diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index c5702698b18b..a669aee033c5 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -15,6 +15,42 @@ static unsigned int afs_fs_probe_fast_poll_interval =3D 30 * HZ; static unsigned int afs_fs_probe_slow_poll_interval =3D 5 * 60 * HZ; =20 +struct afs_endpoint_state *afs_get_endpoint_state(struct afs_endpoint_stat= e *estate, + enum afs_estate_trace where) +{ + if (estate) { + int r; + + __refcount_inc(&estate->ref, &r); + trace_afs_estate(estate->server_id, estate->probe_seq, r, where); + } + return estate; +} + +static void afs_endpoint_state_rcu(struct rcu_head *rcu) +{ + struct afs_endpoint_state *estate =3D container_of(rcu, struct afs_endpoi= nt_state, rcu); + + trace_afs_estate(estate->server_id, estate->probe_seq, refcount_read(&est= ate->ref), + afs_estate_trace_free); + afs_put_addrlist(estate->addresses, afs_alist_trace_put_estate); + kfree(estate); +} + +void afs_put_endpoint_state(struct afs_endpoint_state *estate, enum afs_es= tate_trace where) +{ + if (estate) { + unsigned int server_id =3D estate->server_id, probe_seq =3D estate->prob= e_seq; + bool dead; + int r; + + dead =3D __refcount_dec_and_test(&estate->ref, &r); + trace_afs_estate(server_id, probe_seq, r, where); + if (dead) + call_rcu(&estate->rcu, afs_endpoint_state_rcu); + } +} + /* * Start the probe polling timer. We have to supply it with an inc on the * outstanding server count. @@ -38,9 +74,10 @@ static void afs_schedule_fs_probe(struct afs_net *net, /* * Handle the completion of a set of probes. */ -static void afs_finished_fs_probe(struct afs_net *net, struct afs_server *= server) +static void afs_finished_fs_probe(struct afs_net *net, struct afs_server *= server, + struct afs_endpoint_state *estate) { - bool responded =3D server->probe.responded; + bool responded =3D estate->responded; =20 write_seqlock(&net->fs_lock); if (responded) { @@ -50,6 +87,7 @@ static void afs_finished_fs_probe(struct afs_net *net, st= ruct afs_server *server clear_bit(AFS_SERVER_FL_RESPONDING, &server->flags); list_add_tail(&server->probe_link, &net->fs_probe_fast); } + write_sequnlock(&net->fs_lock); =20 afs_schedule_fs_probe(net, server, !responded); @@ -58,12 +96,13 @@ static void afs_finished_fs_probe(struct afs_net *net, = struct afs_server *server /* * Handle the completion of a probe. */ -static void afs_done_one_fs_probe(struct afs_net *net, struct afs_server *= server) +static void afs_done_one_fs_probe(struct afs_net *net, struct afs_server *= server, + struct afs_endpoint_state *estate) { _enter(""); =20 - if (atomic_dec_and_test(&server->probe_outstanding)) - afs_finished_fs_probe(net, server); + if (atomic_dec_and_test(&estate->nr_probing)) + afs_finished_fs_probe(net, server, estate); =20 wake_up_all(&server->probe_wq); } @@ -74,7 +113,7 @@ static void afs_done_one_fs_probe(struct afs_net *net, s= truct afs_server *server */ static void afs_fs_probe_not_done(struct afs_net *net, struct afs_server *server, - struct afs_addr_list *alist, + struct afs_endpoint_state *estate, int index) { _enter(""); @@ -82,14 +121,14 @@ static void afs_fs_probe_not_done(struct afs_net *net, trace_afs_io_error(0, -ENOMEM, afs_io_error_fs_probe_fail); spin_lock(&server->probe_lock); =20 - server->probe.local_failure =3D true; - if (server->probe.error =3D=3D 0) - server->probe.error =3D -ENOMEM; + estate->local_failure =3D true; + if (estate->error =3D=3D 0) + estate->error =3D -ENOMEM; =20 - set_bit(index, &alist->probe_failed); + set_bit(index, &estate->failed_set); =20 spin_unlock(&server->probe_lock); - return afs_done_one_fs_probe(net, server); + return afs_done_one_fs_probe(net, server, estate); } =20 /* @@ -98,7 +137,8 @@ static void afs_fs_probe_not_done(struct afs_net *net, */ void afs_fileserver_probe_result(struct afs_call *call) { - struct afs_addr_list *alist =3D call->probe_alist; + struct afs_endpoint_state *estate =3D call->probe; + struct afs_addr_list *alist =3D estate->addresses; struct afs_address *addr =3D &alist->addrs[call->probe_index]; struct afs_server *server =3D call->server; unsigned int index =3D call->probe_index; @@ -113,18 +153,18 @@ void afs_fileserver_probe_result(struct afs_call *cal= l) =20 switch (ret) { case 0: - server->probe.error =3D 0; + estate->error =3D 0; goto responded; case -ECONNABORTED: - if (!server->probe.responded) { - server->probe.abort_code =3D call->abort_code; - server->probe.error =3D ret; + if (!estate->responded) { + estate->abort_code =3D call->abort_code; + estate->error =3D ret; } goto responded; case -ENOMEM: case -ENONET: - clear_bit(index, &alist->responded); - server->probe.local_failure =3D true; + clear_bit(index, &estate->responsive_set); + estate->local_failure =3D true; trace_afs_io_error(call->debug_id, ret, afs_io_error_fs_probe_fail); goto out; case -ECONNRESET: /* Responded, but call expired. */ @@ -137,28 +177,28 @@ void afs_fileserver_probe_result(struct afs_call *cal= l) case -ETIMEDOUT: case -ETIME: default: - clear_bit(index, &alist->responded); - set_bit(index, &alist->probe_failed); - if (!server->probe.responded && - (server->probe.error =3D=3D 0 || - server->probe.error =3D=3D -ETIMEDOUT || - server->probe.error =3D=3D -ETIME)) - server->probe.error =3D ret; + clear_bit(index, &estate->responsive_set); + set_bit(index, &estate->failed_set); + if (!estate->responded && + (estate->error =3D=3D 0 || + estate->error =3D=3D -ETIMEDOUT || + estate->error =3D=3D -ETIME)) + estate->error =3D ret; trace_afs_io_error(call->debug_id, ret, afs_io_error_fs_probe_fail); goto out; } =20 responded: - clear_bit(index, &alist->probe_failed); + clear_bit(index, &estate->failed_set); =20 if (call->service_id =3D=3D YFS_FS_SERVICE) { - server->probe.is_yfs =3D true; + estate->is_yfs =3D true; set_bit(AFS_SERVER_FL_IS_YFS, &server->flags); server->service_id =3D call->service_id; } else { - server->probe.not_yfs =3D true; - if (!server->probe.is_yfs) { - clear_bit(AFS_SERVER_FL_IS_YFS, &server->flags); + estate->not_yfs =3D true; + if (!estate->is_yfs) { + estate->is_yfs =3D false; server->service_id =3D call->service_id; } cap0 =3D ntohl(call->tmp); @@ -169,84 +209,90 @@ void afs_fileserver_probe_result(struct afs_call *cal= l) } =20 rtt_us =3D rxrpc_kernel_get_srtt(addr->peer); - if (rtt_us < server->probe.rtt) { - server->probe.rtt =3D rtt_us; + if (rtt_us < estate->rtt) { + estate->rtt =3D rtt_us; server->rtt =3D rtt_us; alist->preferred =3D index; } =20 smp_wmb(); /* Set rtt before responded. */ - server->probe.responded =3D true; - set_bit(index, &alist->responded); + estate->responded =3D true; + set_bit(index, &estate->responsive_set); set_bit(AFS_SERVER_FL_RESPONDING, &server->flags); out: spin_unlock(&server->probe_lock); =20 - trace_afs_fs_probe(server, false, alist, index, call->error, call->abort_= code, rtt_us); - _debug("probe %pU [%u] %pISpc rtt=3D%d ret=3D%d", - &server->uuid, index, rxrpc_kernel_remote_addr(alist->addrs[index]= .peer), + trace_afs_fs_probe(server, false, estate, index, call->error, call->abort= _code, rtt_us); + _debug("probe[%x] %pU [%u] %pISpc rtt=3D%d ret=3D%d", + estate->probe_seq, &server->uuid, index, + rxrpc_kernel_remote_addr(alist->addrs[index].peer), rtt_us, ret); =20 - return afs_done_one_fs_probe(call->net, server); + return afs_done_one_fs_probe(call->net, server, estate); } =20 /* - * Probe one or all of a fileserver's addresses to find out the best route= and - * to query its capabilities. + * Probe all of a fileserver's addresses to find out the best route and to + * query its capabilities. */ void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *serve= r, - struct key *key, bool all) + struct afs_addr_list *new_alist, struct key *key) { + struct afs_endpoint_state *estate, *old; struct afs_addr_list *alist; - unsigned int index; + unsigned long unprobed; =20 _enter("%pU", &server->uuid); =20 - read_lock(&server->fs_lock); - alist =3D rcu_dereference_protected(server->addresses, - lockdep_is_held(&server->fs_lock)); - afs_get_addrlist(alist, afs_alist_trace_get_probe); - read_unlock(&server->fs_lock); + estate =3D kzalloc(sizeof(*estate), GFP_KERNEL); + if (!estate) + return; + + refcount_set(&estate->ref, 1); + estate->server_id =3D server->debug_id; + estate->rtt =3D UINT_MAX; + + write_lock(&server->fs_lock); + + old =3D rcu_dereference_protected(server->endpoint_state, + lockdep_is_held(&server->fs_lock)); + estate->responsive_set =3D old->responsive_set; + estate->addresses =3D afs_get_addrlist(new_alist ?: old->addresses, + afs_alist_trace_get_estate); + alist =3D estate->addresses; + estate->probe_seq =3D ++server->probe_counter; + atomic_set(&estate->nr_probing, alist->nr_addrs); + + rcu_assign_pointer(server->endpoint_state, estate); + old->superseded =3D true; + write_unlock(&server->fs_lock); + + trace_afs_estate(estate->server_id, estate->probe_seq, refcount_read(&est= ate->ref), + afs_estate_trace_alloc_probe); =20 afs_get_address_preferences(net, alist); =20 server->probed_at =3D jiffies; - atomic_set(&server->probe_outstanding, all ? alist->nr_addrs : 1); - memset(&server->probe, 0, sizeof(server->probe)); - server->probe.rtt =3D UINT_MAX; - - index =3D alist->preferred; - if (index < 0 || index >=3D alist->nr_addrs) - all =3D true; - - if (all) { - unsigned long unprobed =3D (1UL << alist->nr_addrs) - 1; - unsigned int i; - int best_prio; - - while (unprobed) { - best_prio =3D -1; - index =3D 0; - for (i =3D 0; i < alist->nr_addrs; i++) { - if (test_bit(i, &unprobed) && - alist->addrs[i].prio > best_prio) { - index =3D i; - best_prio =3D alist->addrs[i].prio; - } + unprobed =3D (1UL << alist->nr_addrs) - 1; + while (unprobed) { + unsigned int index =3D 0, i; + int best_prio =3D -1; + + for (i =3D 0; i < alist->nr_addrs; i++) { + if (test_bit(i, &unprobed) && + alist->addrs[i].prio > best_prio) { + index =3D i; + best_prio =3D alist->addrs[i].prio; } - __clear_bit(index, &unprobed); - - trace_afs_fs_probe(server, true, alist, index, 0, 0, 0); - if (!afs_fs_get_capabilities(net, server, alist, index, key)) - afs_fs_probe_not_done(net, server, alist, index); } - } else { - trace_afs_fs_probe(server, true, alist, index, 0, 0, 0); - if (!afs_fs_get_capabilities(net, server, alist, index, key)) - afs_fs_probe_not_done(net, server, alist, index); + __clear_bit(index, &unprobed); + + trace_afs_fs_probe(server, true, estate, index, 0, 0, 0); + if (!afs_fs_get_capabilities(net, server, estate, index, key)) + afs_fs_probe_not_done(net, server, estate, index); } =20 - afs_put_addrlist(alist, afs_alist_trace_put_probe); + afs_put_endpoint_state(old, afs_estate_trace_put_probe); } =20 /* @@ -254,6 +300,7 @@ void afs_fs_probe_fileserver(struct afs_net *net, struc= t afs_server *server, */ int afs_wait_for_fs_probes(struct afs_server_list *slist, unsigned long un= tried) { + struct afs_endpoint_state *estate; struct wait_queue_entry *waits; struct afs_server *server; unsigned int rtt =3D UINT_MAX, rtt_s; @@ -263,15 +310,18 @@ int afs_wait_for_fs_probes(struct afs_server_list *sl= ist, unsigned long untried) _enter("%u,%lx", slist->nr_servers, untried); =20 /* Only wait for servers that have a probe outstanding. */ + rcu_read_lock(); for (i =3D 0; i < slist->nr_servers; i++) { if (test_bit(i, &untried)) { server =3D slist->servers[i].server; - if (!atomic_read(&server->probe_outstanding)) + estate =3D rcu_dereference(server->endpoint_state); + if (!atomic_read(&estate->nr_probing)) __clear_bit(i, &untried); - if (server->probe.responded) + if (estate->responded) have_responders =3D true; } } + rcu_read_unlock(); if (have_responders || !untried) return 0; =20 @@ -294,9 +344,9 @@ int afs_wait_for_fs_probes(struct afs_server_list *slis= t, unsigned long untried) for (i =3D 0; i < slist->nr_servers; i++) { if (test_bit(i, &untried)) { server =3D slist->servers[i].server; - if (server->probe.responded) + if (estate->responded) goto stop; - if (atomic_read(&server->probe_outstanding)) + if (atomic_read(&estate->nr_probing)) still_probing =3D true; } } @@ -348,7 +398,7 @@ void afs_fs_probe_timer(struct timer_list *timer) /* * Dispatch a probe to a server. */ -static void afs_dispatch_fs_probe(struct afs_net *net, struct afs_server *= server, bool all) +static void afs_dispatch_fs_probe(struct afs_net *net, struct afs_server *= server) __releases(&net->fs_lock) { struct key *key =3D NULL; @@ -361,7 +411,7 @@ static void afs_dispatch_fs_probe(struct afs_net *net, = struct afs_server *server afs_get_server(server, afs_server_trace_get_probe); write_sequnlock(&net->fs_lock); =20 - afs_fs_probe_fileserver(net, server, key, all); + afs_fs_probe_fileserver(net, server, NULL, key); afs_put_server(net, server, afs_server_trace_put_probe); } =20 @@ -373,7 +423,7 @@ void afs_probe_fileserver(struct afs_net *net, struct a= fs_server *server) { write_seqlock(&net->fs_lock); if (!list_empty(&server->probe_link)) - return afs_dispatch_fs_probe(net, server, true); + return afs_dispatch_fs_probe(net, server); write_sequnlock(&net->fs_lock); } =20 @@ -433,7 +483,7 @@ void afs_fs_probe_dispatcher(struct work_struct *work) _debug("probe %pU", &server->uuid); =20 if (server && (first_pass || !need_resched())) { - afs_dispatch_fs_probe(net, server, server =3D=3D fast); + afs_dispatch_fs_probe(net, server); first_pass =3D false; goto again; } @@ -457,12 +507,13 @@ void afs_fs_probe_dispatcher(struct work_struct *work) /* * Wait for a probe on a particular fileserver to complete for 2s. */ -int afs_wait_for_one_fs_probe(struct afs_server *server, bool is_intr) +int afs_wait_for_one_fs_probe(struct afs_server *server, struct afs_endpoi= nt_state *estate, + bool is_intr) { struct wait_queue_entry wait; unsigned long timo =3D 2 * HZ; =20 - if (atomic_read(&server->probe_outstanding) =3D=3D 0) + if (atomic_read(&estate->nr_probing) =3D=3D 0) goto dont_wait; =20 init_wait_entry(&wait, 0); @@ -470,8 +521,8 @@ int afs_wait_for_one_fs_probe(struct afs_server *server= , bool is_intr) prepare_to_wait_event(&server->probe_wq, &wait, is_intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); if (timo =3D=3D 0 || - server->probe.responded || - atomic_read(&server->probe_outstanding) =3D=3D 0 || + estate->responded || + atomic_read(&estate->nr_probing) =3D=3D 0 || (is_intr && signal_pending(current))) break; timo =3D schedule_timeout(timo); @@ -480,7 +531,7 @@ int afs_wait_for_one_fs_probe(struct afs_server *server= , bool is_intr) finish_wait(&server->probe_wq, &wait); =20 dont_wait: - if (server->probe.responded) + if (estate->responded) return 0; if (is_intr && signal_pending(current)) return -ERESTARTSYS; diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index 4f98b43b0dde..f1f879ba9cf7 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -1697,7 +1697,7 @@ static int afs_deliver_fs_get_capabilities(struct afs= _call *call) =20 static void afs_fs_get_capabilities_destructor(struct afs_call *call) { - afs_put_addrlist(call->probe_alist, afs_alist_trace_put_getcaps); + afs_put_endpoint_state(call->probe, afs_estate_trace_put_getcaps); afs_flat_call_destructor(call); } =20 @@ -1719,7 +1719,7 @@ static const struct afs_call_type afs_RXFSGetCapabili= ties =3D { * ->done() - otherwise we return false to indicate we didn't even try. */ bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *serve= r, - struct afs_addr_list *alist, unsigned int addr_index, + struct afs_endpoint_state *estate, unsigned int addr_index, struct key *key) { struct afs_call *call; @@ -1733,8 +1733,8 @@ bool afs_fs_get_capabilities(struct afs_net *net, str= uct afs_server *server, =20 call->key =3D key; call->server =3D afs_use_server(server, afs_server_trace_get_caps); - call->peer =3D rxrpc_kernel_get_peer(alist->addrs[addr_index].peer); - call->probe_alist =3D afs_get_addrlist(alist, afs_alist_trace_get_getcaps= ); + call->peer =3D rxrpc_kernel_get_peer(estate->addresses->addrs[addr_index]= .peer); + call->probe =3D afs_get_endpoint_state(estate, afs_estate_trace_get_getca= ps); call->probe_index =3D addr_index; call->service_id =3D server->service_id; call->upgrade =3D true; diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 88db04220773..4d42f84a8da4 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -33,6 +33,7 @@ struct pagevec; struct afs_call; struct afs_vnode; +struct afs_server_probe; =20 /* * Partial file-locking emulation mode. (The problem being that AFS3 only @@ -146,14 +147,13 @@ struct afs_call { }; void *buffer; /* reply receive buffer */ union { - struct { - struct afs_addr_list *probe_alist; - unsigned char probe_index; /* Address in ->probe_alist */ - }; + struct afs_endpoint_state *probe; + struct afs_addr_list *vl_probe; struct afs_addr_list *ret_alist; struct afs_vldb_entry *ret_vldb; char *ret_str; }; + unsigned char probe_index; /* Address in ->probe_alist */ struct afs_operation *op; unsigned int server_index; refcount_t ref; @@ -520,6 +520,32 @@ struct afs_vldb_entry { u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */ }; =20 +/* + * Fileserver endpoint state. The records the addresses of a fileserver's + * endpoints and the state and result of a round of probing on them. This + * allows the rotation algorithm to access those results without them being + * erased by a subsequent round of probing. + */ +struct afs_endpoint_state { + struct rcu_head rcu; + struct afs_addr_list *addresses; /* The addresses being probed */ + unsigned long responsive_set; /* Bitset of responsive endpoints */ + unsigned long failed_set; /* Bitset of endpoints we failed to probe */ + refcount_t ref; + unsigned int server_id; /* Debug ID of server */ + unsigned int probe_seq; /* Probe sequence (from server::probe_counter) */ + + atomic_t nr_probing; /* Number of outstanding probes */ + unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */ + s32 abort_code; + short error; + bool responded:1; + bool is_yfs:1; + bool not_yfs:1; + bool local_failure:1; + bool superseded:1; /* Set if has been superseded */ +}; + /* * Record of fileserver with which we're actively communicating. */ @@ -530,7 +556,6 @@ struct afs_server { struct afs_uuid _uuid; }; =20 - struct afs_addr_list __rcu *addresses; struct afs_cell *cell; /* Cell to which belongs (pins ref) */ struct rb_node uuid_rb; /* Link in net->fs_servers */ struct afs_server __rcu *uuid_next; /* Next server with same UUID */ @@ -568,19 +593,11 @@ struct afs_server { unsigned cb_s_break; /* Break-everything counter. */ =20 /* Probe state */ + struct afs_endpoint_state __rcu *endpoint_state; /* Latest endpoint/probe= state */ unsigned long probed_at; /* Time last probe was dispatched (jiffies) */ wait_queue_head_t probe_wq; - atomic_t probe_outstanding; + unsigned int probe_counter; /* Number of probes issued */ spinlock_t probe_lock; - struct { - unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */ - u32 abort_code; - short error; - bool responded:1; - bool is_yfs:1; - bool not_yfs:1; - bool local_failure:1; - } probe; }; =20 /* @@ -883,7 +900,7 @@ struct afs_operation { /* Fileserver iteration state */ struct afs_server_list *server_list; /* Current server list (pins ref) */ struct afs_server *server; /* Server we're using (ref pinned by server_li= st) */ - struct afs_addr_list *alist; /* Current address list (pins ref) */ + struct afs_endpoint_state *estate; /* Current endpoint state (pins ref) */ struct afs_call *call; unsigned long untried_servers; /* Bitmask of untried servers */ unsigned long addr_tried; /* Tried addresses */ @@ -1153,7 +1170,7 @@ extern void afs_fs_release_lock(struct afs_operation = *); int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *s= erver, struct afs_address *addr, struct key *key); bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *serve= r, - struct afs_addr_list *alist, unsigned int addr_index, + struct afs_endpoint_state *estate, unsigned int addr_index, struct key *key); extern void afs_fs_inline_bulk_status(struct afs_operation *); =20 @@ -1190,12 +1207,17 @@ static inline void afs_op_set_fid(struct afs_operat= ion *op, unsigned int n, /* * fs_probe.c */ +struct afs_endpoint_state *afs_get_endpoint_state(struct afs_endpoint_stat= e *estate, + enum afs_estate_trace where); +void afs_put_endpoint_state(struct afs_endpoint_state *estate, enum afs_es= tate_trace where); extern void afs_fileserver_probe_result(struct afs_call *); -extern void afs_fs_probe_fileserver(struct afs_net *, struct afs_server *,= struct key *, bool); +void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *serve= r, + struct afs_addr_list *new_addrs, struct key *key); extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long); extern void afs_probe_fileserver(struct afs_net *, struct afs_server *); extern void afs_fs_probe_dispatcher(struct work_struct *); -extern int afs_wait_for_one_fs_probe(struct afs_server *, bool); +int afs_wait_for_one_fs_probe(struct afs_server *server, struct afs_endpoi= nt_state *estate, + bool is_intr); extern void afs_fs_probe_cleanup(struct afs_net *); =20 /* @@ -1348,12 +1370,14 @@ extern int afs_protocol_error(struct afs_call *, en= um afs_eproto_cause); static inline void afs_make_op_call(struct afs_operation *op, struct afs_c= all *call, gfp_t gfp) { + struct afs_addr_list *alist =3D op->estate->addresses; + op->call =3D call; op->type =3D call->type; call->op =3D op; call->key =3D op->key; call->intr =3D !(op->flags & AFS_OPERATION_UNINTR); - call->peer =3D rxrpc_kernel_get_peer(op->alist->addrs[op->addr_index].pee= r); + call->peer =3D rxrpc_kernel_get_peer(alist->addrs[op->addr_index].peer); call->service_id =3D op->server->service_id; afs_make_call(call, gfp); } @@ -1476,7 +1500,7 @@ extern void afs_manage_servers(struct work_struct *); extern void afs_servers_timer(struct timer_list *); extern void afs_fs_probe_timer(struct timer_list *); extern void __net_exit afs_purge_servers(struct afs_net *); -extern bool afs_check_server_record(struct afs_operation *, struct afs_ser= ver *); +bool afs_check_server_record(struct afs_operation *op, struct afs_server *= server, struct key *key); =20 static inline void afs_inc_servers_outstanding(struct afs_net *net) { diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 944eb51e75a1..a138022d8e0d 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -424,8 +424,9 @@ static const struct seq_operations afs_proc_cell_vlserv= ers_ops =3D { */ static int afs_proc_servers_show(struct seq_file *m, void *v) { - struct afs_server *server; + struct afs_endpoint_state *estate; struct afs_addr_list *alist; + struct afs_server *server; unsigned long failed; int i; =20 @@ -435,7 +436,8 @@ static int afs_proc_servers_show(struct seq_file *m, vo= id *v) } =20 server =3D list_entry(v, struct afs_server, proc_link); - alist =3D rcu_dereference(server->addresses); + estate =3D rcu_dereference(server->endpoint_state); + alist =3D estate->addresses; seq_printf(m, "%pU %3d %3d %s\n", &server->uuid, refcount_read(&server->ref), @@ -443,13 +445,14 @@ static int afs_proc_servers_show(struct seq_file *m, = void *v) server->cell->name); seq_printf(m, " - info: fl=3D%lx rtt=3D%u brk=3D%x\n", server->flags, server->rtt, server->cb_s_break); - seq_printf(m, " - probe: last=3D%d out=3D%d\n", - (int)(jiffies - server->probed_at) / HZ, - atomic_read(&server->probe_outstanding)); - failed =3D alist->probe_failed; - seq_printf(m, " - ALIST v=3D%u rsp=3D%lx f=3D%lx ap=3D%u\n", - alist->version, alist->responded, alist->probe_failed, - alist->addr_pref_version); + seq_printf(m, " - probe: last=3D%d\n", + (int)(jiffies - server->probed_at) / HZ); + failed =3D estate->failed_set; + seq_printf(m, " - ESTATE pq=3D%x np=3D%u rsp=3D%lx f=3D%lx\n", + estate->probe_seq, atomic_read(&estate->nr_probing), + estate->responsive_set, estate->failed_set); + seq_printf(m, " - ALIST v=3D%u ap=3D%u\n", + alist->version, alist->addr_pref_version); for (i =3D 0; i < alist->nr_addrs; i++) { const struct afs_address *addr =3D &alist->addrs[i]; =20 diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 5423ac80f4e0..e8635f60b97d 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -109,10 +109,11 @@ static bool afs_sleep_and_retry(struct afs_operation = *op) */ bool afs_select_fileserver(struct afs_operation *op) { - struct afs_addr_list *alist =3D op->alist; + struct afs_endpoint_state *estate =3D op->estate; + struct afs_addr_list *alist; struct afs_server *server; struct afs_vnode *vnode =3D op->file[0].vnode; - unsigned long set; + unsigned long set, failed; unsigned int rtt; s32 abort_code =3D op->call_abort_code; int error =3D op->call_error, addr_index, i; @@ -133,7 +134,7 @@ bool afs_select_fileserver(struct afs_operation *op) if (op->nr_iterations =3D=3D 0) goto start; =20 - WRITE_ONCE(alist->addrs[op->addr_index].last_error, error); + WRITE_ONCE(estate->addresses->addrs[op->addr_index].last_error, error); =20 /* Evaluate the result of the previous operation, if there was one. */ switch (op->call_error) { @@ -401,14 +402,14 @@ bool afs_select_fileserver(struct afs_operation *op) =20 restart_from_beginning: _debug("restart"); - afs_put_addrlist(alist, afs_alist_trace_put_restart_rotate); - alist =3D op->alist =3D NULL; + afs_put_endpoint_state(estate, afs_estate_trace_put_restart_rotate); + estate =3D op->estate =3D NULL; op->server =3D NULL; afs_put_serverlist(op->net, op->server_list); op->server_list =3D NULL; start: _debug("start"); - ASSERTCMP(alist, =3D=3D, NULL); + ASSERTCMP(estate, =3D=3D, NULL); /* See if we need to do an update of the volume record. Note that the * volume may have moved or even have been deleted. */ @@ -425,7 +426,7 @@ bool afs_select_fileserver(struct afs_operation *op) =20 pick_server: _debug("pick [%lx]", op->untried_servers); - ASSERTCMP(alist, =3D=3D, NULL); + ASSERTCMP(estate, =3D=3D, NULL); =20 error =3D afs_wait_for_fs_probes(op->server_list, op->untried_servers); if (error < 0) { @@ -452,9 +453,9 @@ bool afs_select_fileserver(struct afs_operation *op) if (!test_bit(i, &op->untried_servers) || !test_bit(AFS_SERVER_FL_RESPONDING, &s->flags)) continue; - if (s->probe.rtt <=3D rtt) { + if (s->rtt <=3D rtt) { op->server_index =3D i; - rtt =3D s->probe.rtt; + rtt =3D s->rtt; } } =20 @@ -469,10 +470,10 @@ bool afs_select_fileserver(struct afs_operation *op) * check it, create a callback intercept, find its address list and * probe its capabilities before we use it. */ - ASSERTCMP(alist, =3D=3D, NULL); + ASSERTCMP(estate, =3D=3D, NULL); server =3D op->server_list->servers[op->server_index].server; =20 - if (!afs_check_server_record(op, server)) + if (!afs_check_server_record(op, server, op->key)) goto failed; =20 _debug("USING SERVER: %pU", &server->uuid); @@ -488,9 +489,9 @@ bool afs_select_fileserver(struct afs_operation *op) } =20 read_lock(&server->fs_lock); - alist =3D rcu_dereference_protected(server->addresses, - lockdep_is_held(&server->fs_lock)); - op->alist =3D afs_get_addrlist(alist, afs_alist_trace_get_fsrotate_set); + estate =3D rcu_dereference_protected(server->endpoint_state, + lockdep_is_held(&server->fs_lock)); + op->estate =3D afs_get_endpoint_state(estate, afs_estate_trace_get_fsrota= te_set); read_unlock(&server->fs_lock); =20 retry_server: @@ -501,18 +502,20 @@ bool afs_select_fileserver(struct afs_operation *op) /* Iterate over the current server's address list to try and find an * address on which it will respond to us. */ - set =3D READ_ONCE(alist->responded); - set &=3D ~(READ_ONCE(alist->probe_failed) | op->addr_tried); + set =3D READ_ONCE(estate->responsive_set); + failed =3D READ_ONCE(estate->failed_set); + _debug("iterate ES=3D%x rs=3D%lx fs=3D%lx", estate->probe_seq, set, faile= d); + set &=3D ~(failed | op->addr_tried); if (!set) goto out_of_addresses; =20 + alist =3D estate->addresses; addr_index =3D READ_ONCE(alist->preferred); if (!test_bit(addr_index, &set)) addr_index =3D __ffs(set); =20 op->addr_index =3D addr_index; set_bit(addr_index, &op->addr_tried); - op->alist =3D alist; =20 op->call_responded =3D false; _debug("address [%u] %u/%u %pISp", @@ -527,8 +530,8 @@ bool afs_select_fileserver(struct afs_operation *op) */ afs_probe_fileserver(op->net, op->server); if (op->flags & AFS_OPERATION_RETRY_SERVER) { - error =3D afs_wait_for_one_fs_probe( - op->server, !(op->flags & AFS_OPERATION_UNINTR)); + error =3D afs_wait_for_one_fs_probe(op->server, estate, + !(op->flags & AFS_OPERATION_UNINTR)); switch (error) { case 0: op->flags &=3D ~AFS_OPERATION_RETRY_SERVER; @@ -544,13 +547,14 @@ bool afs_select_fileserver(struct afs_operation *op) =20 next_server: _debug("next"); - ASSERT(alist); + ASSERT(estate); + alist =3D estate->addresses; if (op->call_responded && op->addr_index !=3D READ_ONCE(alist->preferred) && test_bit(alist->preferred, &op->addr_tried)) WRITE_ONCE(alist->preferred, op->addr_index); - afs_put_addrlist(alist, afs_alist_trace_put_next_server); - alist =3D op->alist =3D NULL; + afs_put_endpoint_state(estate, afs_estate_trace_put_next_server); + estate =3D op->estate =3D NULL; goto pick_server; =20 no_more_servers: @@ -560,23 +564,28 @@ bool afs_select_fileserver(struct afs_operation *op) if (op->flags & AFS_OPERATION_VBUSY) goto restart_from_beginning; =20 + rcu_read_lock(); for (i =3D 0; i < op->server_list->nr_servers; i++) { + struct afs_endpoint_state *estate; struct afs_server *s =3D op->server_list->servers[i].server; =20 - error =3D READ_ONCE(s->probe.error); + estate =3D rcu_dereference(s->endpoint_state); + error =3D READ_ONCE(estate->error); if (error < 0) - afs_op_accumulate_error(op, error, s->probe.abort_code); + afs_op_accumulate_error(op, error, estate->abort_code); } + rcu_read_unlock(); =20 failed: op->flags |=3D AFS_OPERATION_STOP; - if (alist) { + if (estate) { + alist =3D estate->addresses; if (op->call_responded && op->addr_index !=3D READ_ONCE(alist->preferred) && test_bit(alist->preferred, &op->addr_tried)) WRITE_ONCE(alist->preferred, op->addr_index); - afs_put_addrlist(alist, afs_alist_trace_put_op_failed); - op->alist =3D NULL; + afs_put_endpoint_state(estate, afs_estate_trace_put_op_failed); + op->estate =3D NULL; } _leave(" =3D f [failed %d]", afs_op_error(op)); return false; @@ -607,27 +616,30 @@ void afs_dump_edestaddrreq(const struct afs_operation= *op) =20 if (op->server_list) { const struct afs_server_list *sl =3D op->server_list; + pr_notice("FC: SL nr=3D%u pr=3D%u vnov=3D%hx\n", sl->nr_servers, sl->preferred, sl->vnovol_mask); for (i =3D 0; i < sl->nr_servers; i++) { const struct afs_server *s =3D sl->servers[i].server; + const struct afs_endpoint_state *e =3D + rcu_dereference(s->endpoint_state); + const struct afs_addr_list *a =3D e->addresses; + pr_notice("FC: server fl=3D%lx av=3D%u %pU\n", s->flags, s->addr_version, &s->uuid); - if (s->addresses) { - const struct afs_addr_list *a =3D - rcu_dereference(s->addresses); + pr_notice("FC: - pq=3D%x R=3D%lx F=3D%lx\n", + e->probe_seq, e->responsive_set, e->failed_set); + if (a) { pr_notice("FC: - av=3D%u nr=3D%u/%u/%u pr=3D%u\n", a->version, a->nr_ipv4, a->nr_addrs, a->max_addrs, a->preferred); - pr_notice("FC: - R=3D%lx F=3D%lx\n", - a->responded, a->probe_failed); - if (a =3D=3D op->alist) + if (a =3D=3D e->addresses) pr_notice("FC: - current\n"); } } } =20 - pr_notice("AC: t=3D%lx ax=3D%u\n", op->addr_tried, op->addr_index); + pr_notice("AC: t=3D%lx ax=3D%d\n", op->addr_tried, op->addr_index); rcu_read_unlock(); } diff --git a/fs/afs/server.c b/fs/afs/server.c index 62d453365689..281625c71aff 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -23,6 +23,7 @@ static void __afs_put_server(struct afs_net *, struct afs= _server *); */ struct afs_server *afs_find_server(struct afs_net *net, const struct rxrpc= _peer *peer) { + const struct afs_endpoint_state *estate; const struct afs_addr_list *alist; struct afs_server *server =3D NULL; unsigned int i; @@ -38,7 +39,8 @@ struct afs_server *afs_find_server(struct afs_net *net, c= onst struct rxrpc_peer read_seqbegin_or_lock(&net->fs_addr_lock, &seq); =20 hlist_for_each_entry_rcu(server, &net->fs_addresses6, addr6_link) { - alist =3D rcu_dereference(server->addresses); + estate =3D rcu_dereference(server->endpoint_state); + alist =3D estate->addresses; for (i =3D 0; i < alist->nr_addrs; i++) if (alist->addrs[i].peer =3D=3D peer) goto found; @@ -111,6 +113,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_n= et *net, const uuid_t *uu static struct afs_server *afs_install_server(struct afs_cell *cell, struct afs_server *candidate) { + const struct afs_endpoint_state *estate; const struct afs_addr_list *alist; struct afs_server *server, *next; struct afs_net *net =3D cell->net; @@ -162,8 +165,9 @@ static struct afs_server *afs_install_server(struct afs= _cell *cell, =20 added_dup: write_seqlock(&net->fs_addr_lock); - alist =3D rcu_dereference_protected(server->addresses, - lockdep_is_held(&net->fs_addr_lock.lock)); + estate =3D rcu_dereference_protected(server->endpoint_state, + lockdep_is_held(&net->fs_addr_lock.lock)); + alist =3D estate->addresses; =20 /* Secondly, if the server has any IPv4 and/or IPv6 addresses, install * it in the IPv4 and/or IPv6 reverse-map lists. @@ -193,6 +197,7 @@ static struct afs_server *afs_alloc_server(struct afs_c= ell *cell, const uuid_t *uuid, struct afs_addr_list *alist) { + struct afs_endpoint_state *estate; struct afs_server *server; struct afs_net *net =3D cell->net; =20 @@ -202,10 +207,13 @@ static struct afs_server *afs_alloc_server(struct afs= _cell *cell, if (!server) goto enomem; =20 + estate =3D kzalloc(sizeof(struct afs_endpoint_state), GFP_KERNEL); + if (!estate) + goto enomem_server; + refcount_set(&server->ref, 1); atomic_set(&server->active, 1); server->debug_id =3D atomic_inc_return(&afs_server_debug_id); - RCU_INIT_POINTER(server->addresses, alist); server->addr_version =3D alist->version; server->uuid =3D *uuid; rwlock_init(&server->fs_lock); @@ -217,11 +225,23 @@ static struct afs_server *afs_alloc_server(struct afs= _cell *cell, server->rtt =3D UINT_MAX; server->service_id =3D FS_SERVICE; =20 + server->probe_counter =3D 1; + server->probed_at =3D jiffies - LONG_MAX / 2; + refcount_set(&estate->ref, 1); + estate->addresses =3D alist; + estate->server_id =3D server->debug_id; + estate->probe_seq =3D 1; + rcu_assign_pointer(server->endpoint_state, estate); + afs_inc_servers_outstanding(net); trace_afs_server(server->debug_id, 1, 1, afs_server_trace_alloc); + trace_afs_estate(estate->server_id, estate->probe_seq, refcount_read(&est= ate->ref), + afs_estate_trace_alloc_server); _leave(" =3D %p", server); return server; =20 +enomem_server: + kfree(server); enomem: _leave(" =3D NULL [nomem]"); return NULL; @@ -289,7 +309,7 @@ struct afs_server *afs_lookup_server(struct afs_cell *c= ell, struct key *key, * on the fileserver. This will make sure the repeat-probing * service is started. */ - afs_fs_probe_fileserver(cell->net, server, key, true); + afs_fs_probe_fileserver(cell->net, server, alist, key); } =20 return server; @@ -422,8 +442,8 @@ static void afs_server_rcu(struct rcu_head *rcu) =20 trace_afs_server(server->debug_id, refcount_read(&server->ref), atomic_read(&server->active), afs_server_trace_free); - afs_put_addrlist(rcu_access_pointer(server->addresses), - afs_alist_trace_put_server); + afs_put_endpoint_state(rcu_access_pointer(server->endpoint_state), + afs_estate_trace_put_server); kfree(server); } =20 @@ -435,7 +455,8 @@ static void __afs_put_server(struct afs_net *net, struc= t afs_server *server) =20 static void afs_give_up_callbacks(struct afs_net *net, struct afs_server *= server) { - struct afs_addr_list *alist =3D rcu_access_pointer(server->addresses); + struct afs_endpoint_state *estate =3D rcu_access_pointer(server->endpoint= _state); + struct afs_addr_list *alist =3D estate->addresses; =20 afs_fs_give_up_all_callbacks(net, server, &alist->addrs[alist->preferred]= , NULL); } @@ -607,9 +628,12 @@ void afs_purge_servers(struct afs_net *net) * Get an update for a server's address list. */ static noinline bool afs_update_server_record(struct afs_operation *op, - struct afs_server *server) + struct afs_server *server, + struct key *key) { - struct afs_addr_list *alist, *discard; + struct afs_endpoint_state *estate; + struct afs_addr_list *alist; + bool has_addrs; =20 _enter(""); =20 @@ -619,10 +643,15 @@ static noinline bool afs_update_server_record(struct = afs_operation *op, =20 alist =3D afs_vl_lookup_addrs(op->volume->cell, op->key, &server->uuid); if (IS_ERR(alist)) { + rcu_read_lock(); + estate =3D rcu_dereference(server->endpoint_state); + has_addrs =3D estate->addresses; + rcu_read_unlock(); + if ((PTR_ERR(alist) =3D=3D -ERESTARTSYS || PTR_ERR(alist) =3D=3D -EINTR) && (op->flags & AFS_OPERATION_UNINTR) && - server->addresses) { + has_addrs) { _leave(" =3D t [intr]"); return true; } @@ -631,17 +660,10 @@ static noinline bool afs_update_server_record(struct = afs_operation *op, return false; } =20 - discard =3D alist; - if (server->addr_version !=3D alist->version) { - write_lock(&server->fs_lock); - discard =3D rcu_dereference_protected(server->addresses, - lockdep_is_held(&server->fs_lock)); - rcu_assign_pointer(server->addresses, alist); - server->addr_version =3D alist->version; - write_unlock(&server->fs_lock); - } + if (server->addr_version !=3D alist->version) + afs_fs_probe_fileserver(op->net, server, alist, key); =20 - afs_put_addrlist(discard, afs_alist_trace_put_server_update); + afs_put_addrlist(alist, afs_alist_trace_put_server_update); _leave(" =3D t"); return true; } @@ -649,7 +671,8 @@ static noinline bool afs_update_server_record(struct af= s_operation *op, /* * See if a server's address list needs updating. */ -bool afs_check_server_record(struct afs_operation *op, struct afs_server *= server) +bool afs_check_server_record(struct afs_operation *op, struct afs_server *= server, + struct key *key) { bool success; int ret, retries =3D 0; @@ -669,7 +692,7 @@ bool afs_check_server_record(struct afs_operation *op, = struct afs_server *server update: if (!test_and_set_bit_lock(AFS_SERVER_FL_UPDATING, &server->flags)) { clear_bit(AFS_SERVER_FL_NEEDS_UPDATE, &server->flags); - success =3D afs_update_server_record(op, server); + success =3D afs_update_server_record(op, server, key); clear_bit_unlock(AFS_SERVER_FL_UPDATING, &server->flags); wake_up_bit(&server->flags, AFS_SERVER_FL_UPDATING); _leave(" =3D %d", success); diff --git a/fs/afs/vl_alias.c b/fs/afs/vl_alias.c index 89cadd9a69e1..43788d0c18e8 100644 --- a/fs/afs/vl_alias.c +++ b/fs/afs/vl_alias.c @@ -41,8 +41,8 @@ static int afs_compare_fs_alists(const struct afs_server = *server_a, const struct afs_addr_list *la, *lb; int a =3D 0, b =3D 0, addr_matches =3D 0; =20 - la =3D rcu_dereference(server_a->addresses); - lb =3D rcu_dereference(server_b->addresses); + la =3D rcu_dereference(server_a->endpoint_state)->addresses; + lb =3D rcu_dereference(server_b->endpoint_state)->addresses; =20 while (a < la->nr_addrs && b < lb->nr_addrs) { unsigned long pa =3D (unsigned long)la->addrs[a].peer; diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c index b128dc3d8af7..3d2e0c925460 100644 --- a/fs/afs/vl_probe.c +++ b/fs/afs/vl_probe.c @@ -46,7 +46,7 @@ static void afs_done_one_vl_probe(struct afs_vlserver *se= rver, bool wake_up) */ void afs_vlserver_probe_result(struct afs_call *call) { - struct afs_addr_list *alist =3D call->probe_alist; + struct afs_addr_list *alist =3D call->vl_probe; struct afs_vlserver *server =3D call->vlserver; struct afs_address *addr =3D &alist->addrs[call->probe_index]; unsigned int server_index =3D call->server_index; diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index 39a0b7614d05..cef02a265edc 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -371,7 +371,7 @@ static int afs_deliver_vl_get_capabilities(struct afs_c= all *call) =20 static void afs_destroy_vl_get_capabilities(struct afs_call *call) { - afs_put_addrlist(call->probe_alist, afs_alist_trace_put_vlgetcaps); + afs_put_addrlist(call->vl_probe, afs_alist_trace_put_vlgetcaps); afs_put_vlserver(call->net, call->vlserver); afs_flat_call_destructor(call); } @@ -414,7 +414,7 @@ struct afs_call *afs_vl_get_capabilities(struct afs_net= *net, call->vlserver =3D afs_get_vlserver(server); call->server_index =3D server_index; call->peer =3D rxrpc_kernel_get_peer(alist->addrs[addr_index].peer); - call->probe_alist =3D afs_get_addrlist(alist, afs_alist_trace_get_vlgetca= ps); + call->vl_probe =3D afs_get_addrlist(alist, afs_alist_trace_get_vlgetcaps); call->probe_index =3D addr_index; call->service_id =3D server->service_id; call->upgrade =3D true; diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index f1815b3dafb0..cf2fa4fddd5b 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -204,22 +204,14 @@ enum yfs_cm_operation { =20 #define afs_alist_traces \ EM(afs_alist_trace_alloc, "ALLOC ") \ - EM(afs_alist_trace_get_getcaps, "GET getcap") \ - EM(afs_alist_trace_get_fsrotate_set, "GET fs-rot") \ - EM(afs_alist_trace_get_probe, "GET probe ") \ + EM(afs_alist_trace_get_estate, "GET estate") \ EM(afs_alist_trace_get_vlgetcaps, "GET vgtcap") \ EM(afs_alist_trace_get_vlprobe, "GET vprobe") \ EM(afs_alist_trace_get_vlrotate_set, "GET vl-rot") \ + EM(afs_alist_trace_put_estate, "PUT estate") \ EM(afs_alist_trace_put_getaddru, "PUT GtAdrU") \ - EM(afs_alist_trace_put_getcaps, "PUT getcap") \ - EM(afs_alist_trace_put_next_server, "PUT nx-srv") \ - EM(afs_alist_trace_put_op_failed, "PUT op-fai") \ - EM(afs_alist_trace_put_operation, "PUT op ") \ EM(afs_alist_trace_put_parse_empty, "PUT p-empt") \ EM(afs_alist_trace_put_parse_error, "PUT p-err ") \ - EM(afs_alist_trace_put_probe, "PUT probe ") \ - EM(afs_alist_trace_put_restart_rotate, "PUT rstrot") \ - EM(afs_alist_trace_put_server, "PUT server") \ EM(afs_alist_trace_put_server_dup, "PUT sv-dup") \ EM(afs_alist_trace_put_server_oom, "PUT sv-oom") \ EM(afs_alist_trace_put_server_update, "PUT sv-upd") \ @@ -233,6 +225,20 @@ enum yfs_cm_operation { EM(afs_alist_trace_put_vlserver_old, "PUT vs-old") \ E_(afs_alist_trace_free, "FREE ") =20 +#define afs_estate_traces \ + EM(afs_estate_trace_alloc_probe, "ALLOC prob") \ + EM(afs_estate_trace_alloc_server, "ALLOC srvr") \ + EM(afs_estate_trace_get_fsrotate_set, "GET fs-rot") \ + EM(afs_estate_trace_get_getcaps, "GET getcap") \ + EM(afs_estate_trace_put_getcaps, "PUT getcap") \ + EM(afs_estate_trace_put_next_server, "PUT nx-srv") \ + EM(afs_estate_trace_put_op_failed, "PUT op-fai") \ + EM(afs_estate_trace_put_operation, "PUT op ") \ + EM(afs_estate_trace_put_probe, "PUT probe ") \ + EM(afs_estate_trace_put_restart_rotate, "PUT rstrot") \ + EM(afs_estate_trace_put_server, "PUT server") \ + E_(afs_estate_trace_free, "FREE ") + #define afs_fs_operations \ EM(afs_FS_FetchData, "FS.FetchData") \ EM(afs_FS_FetchStatus, "FS.FetchStatus") \ @@ -458,6 +464,7 @@ enum afs_cell_trace { afs_cell_traces } __mode(byte); enum afs_edit_dir_op { afs_edit_dir_ops } __mode(byte); enum afs_edit_dir_reason { afs_edit_dir_reasons } __mode(byte); enum afs_eproto_cause { afs_eproto_causes } __mode(byte); +enum afs_estate_trace { afs_estate_traces } __mode(byte); enum afs_file_error { afs_file_errors } __mode(byte); enum afs_flock_event { afs_flock_events } __mode(byte); enum afs_flock_operation { afs_flock_operations } __mode(byte); @@ -486,6 +493,7 @@ yfs_cm_operations; afs_edit_dir_ops; afs_edit_dir_reasons; afs_eproto_causes; +afs_estate_traces; afs_io_errors; afs_file_errors; afs_flock_types; @@ -1387,14 +1395,43 @@ TRACE_EVENT(afs_alist, __entry->ref) ); =20 +TRACE_EVENT(afs_estate, + TP_PROTO(unsigned int server_debug_id, unsigned int estate_debug_id, + int ref, enum afs_estate_trace reason), + + TP_ARGS(server_debug_id, estate_debug_id, ref, reason), + + TP_STRUCT__entry( + __field(unsigned int, server) + __field(unsigned int, estate) + __field(int, ref) + __field(int, active) + __field(int, reason) + ), + + TP_fast_assign( + __entry->server =3D server_debug_id; + __entry->estate =3D estate_debug_id; + __entry->ref =3D ref; + __entry->reason =3D reason; + ), + + TP_printk("ES=3D%08x[%x] %s r=3D%d", + __entry->server, + __entry->estate, + __print_symbolic(__entry->reason, afs_estate_traces), + __entry->ref) + ); + TRACE_EVENT(afs_fs_probe, - TP_PROTO(struct afs_server *server, bool tx, struct afs_addr_list *al= ist, + TP_PROTO(struct afs_server *server, bool tx, struct afs_endpoint_stat= e *estate, unsigned int addr_index, int error, s32 abort_code, unsigned int rt= t_us), =20 - TP_ARGS(server, tx, alist, addr_index, error, abort_code, rtt_us), + TP_ARGS(server, tx, estate, addr_index, error, abort_code, rtt_us), =20 TP_STRUCT__entry( __field(unsigned int, server) + __field(unsigned int, estate) __field(bool, tx) __field(u16, addr_index) __field(short, error) @@ -1404,7 +1441,9 @@ TRACE_EVENT(afs_fs_probe, ), =20 TP_fast_assign( + struct afs_addr_list *alist =3D estate->addresses; __entry->server =3D server->debug_id; + __entry->estate =3D estate->probe_seq; __entry->tx =3D tx; __entry->addr_index =3D addr_index; __entry->error =3D error; @@ -1414,9 +1453,9 @@ TRACE_EVENT(afs_fs_probe, sizeof(__entry->srx)); ), =20 - TP_printk("s=3D%08x %s ax=3D%u e=3D%d ac=3D%d rtt=3D%d %pISpc", - __entry->server, __entry->tx ? "tx" : "rx", __entry->addr_index, - __entry->error, __entry->abort_code, __entry->rtt_us, + TP_printk("s=3D%08x %s pq=3D%x ax=3D%u e=3D%d ac=3D%d rtt=3D%d %pISpc= ", + __entry->server, __entry->tx ? "tx" : "rx", __entry->estate, + __entry->addr_index, __entry->error, __entry->abort_code, __entry-= >rtt_us, &__entry->srx.transport) ); From nobody Mon Dec 15 21:24:35 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 CBC69C4332F for ; Wed, 13 Dec 2023 13:52:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379394AbjLMNw2 (ORCPT ); Wed, 13 Dec 2023 08:52:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379340AbjLMNvf (ORCPT ); Wed, 13 Dec 2023 08:51:35 -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 8A156D5D for ; Wed, 13 Dec 2023 05:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475458; 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=opKh9OQ+SZyyTWeahPHV3sMgxBB7G/9x2ua+B2R2PzA=; b=hA2Odo+F0qa8r6qhxmwUtv8u/XqmGwz2B8GShvHnNRDiQzUUyB73lBkbR9TJX5txK4cdMO z3+hUTbUqY0WgGT5nWIzfONdrcgN9+34V184aHCEw+2pMNT1H0B+HUbqkOJRK0eQpXQcky FIRYwaolqeJys1O0X8m+ACa4l9yo4bg= 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-616-AWp5BQAIMaq7AOiKaEhetw-1; Wed, 13 Dec 2023 08:50:53 -0500 X-MC-Unique: AWp5BQAIMaq7AOiKaEhetw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 E79F91C05EB5; Wed, 13 Dec 2023 13:50:52 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29D3A492BE6; Wed, 13 Dec 2023 13:50:52 +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 Subject: [PATCH v2 29/40] afs: Combine the endpoint state bools into a bitmask Date: Wed, 13 Dec 2023 13:49:51 +0000 Message-ID: <20231213135003.367397-30-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Combine the endpoint state bool-type members into a bitmask so that some of them can be waited upon more easily. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/fs_probe.c | 30 +++++++++++++++--------------- fs/afs/internal.h | 12 ++++++------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index a669aee033c5..c00d38b98a67 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -77,7 +77,7 @@ static void afs_schedule_fs_probe(struct afs_net *net, static void afs_finished_fs_probe(struct afs_net *net, struct afs_server *= server, struct afs_endpoint_state *estate) { - bool responded =3D estate->responded; + bool responded =3D test_bit(AFS_ESTATE_RESPONDED, &estate->flags); =20 write_seqlock(&net->fs_lock); if (responded) { @@ -121,7 +121,7 @@ static void afs_fs_probe_not_done(struct afs_net *net, trace_afs_io_error(0, -ENOMEM, afs_io_error_fs_probe_fail); spin_lock(&server->probe_lock); =20 - estate->local_failure =3D true; + set_bit(AFS_ESTATE_LOCAL_FAILURE, &estate->flags); if (estate->error =3D=3D 0) estate->error =3D -ENOMEM; =20 @@ -156,7 +156,7 @@ void afs_fileserver_probe_result(struct afs_call *call) estate->error =3D 0; goto responded; case -ECONNABORTED: - if (!estate->responded) { + if (!test_bit(AFS_ESTATE_RESPONDED, &estate->flags)) { estate->abort_code =3D call->abort_code; estate->error =3D ret; } @@ -164,7 +164,7 @@ void afs_fileserver_probe_result(struct afs_call *call) case -ENOMEM: case -ENONET: clear_bit(index, &estate->responsive_set); - estate->local_failure =3D true; + set_bit(AFS_ESTATE_LOCAL_FAILURE, &estate->flags); trace_afs_io_error(call->debug_id, ret, afs_io_error_fs_probe_fail); goto out; case -ECONNRESET: /* Responded, but call expired. */ @@ -179,7 +179,7 @@ void afs_fileserver_probe_result(struct afs_call *call) default: clear_bit(index, &estate->responsive_set); set_bit(index, &estate->failed_set); - if (!estate->responded && + if (!test_bit(AFS_ESTATE_RESPONDED, &estate->flags) && (estate->error =3D=3D 0 || estate->error =3D=3D -ETIMEDOUT || estate->error =3D=3D -ETIME)) @@ -192,13 +192,13 @@ void afs_fileserver_probe_result(struct afs_call *cal= l) clear_bit(index, &estate->failed_set); =20 if (call->service_id =3D=3D YFS_FS_SERVICE) { - estate->is_yfs =3D true; + set_bit(AFS_ESTATE_IS_YFS, &estate->flags); set_bit(AFS_SERVER_FL_IS_YFS, &server->flags); server->service_id =3D call->service_id; } else { - estate->not_yfs =3D true; - if (!estate->is_yfs) { - estate->is_yfs =3D false; + set_bit(AFS_ESTATE_NOT_YFS, &estate->flags); + if (!test_bit(AFS_ESTATE_IS_YFS, &estate->flags)) { + clear_bit(AFS_SERVER_FL_IS_YFS, &server->flags); server->service_id =3D call->service_id; } cap0 =3D ntohl(call->tmp); @@ -216,7 +216,7 @@ void afs_fileserver_probe_result(struct afs_call *call) } =20 smp_wmb(); /* Set rtt before responded. */ - estate->responded =3D true; + set_bit(AFS_ESTATE_RESPONDED, &estate->flags); set_bit(index, &estate->responsive_set); set_bit(AFS_SERVER_FL_RESPONDING, &server->flags); out: @@ -264,7 +264,7 @@ void afs_fs_probe_fileserver(struct afs_net *net, struc= t afs_server *server, atomic_set(&estate->nr_probing, alist->nr_addrs); =20 rcu_assign_pointer(server->endpoint_state, estate); - old->superseded =3D true; + set_bit(AFS_ESTATE_SUPERSEDED, &old->flags); write_unlock(&server->fs_lock); =20 trace_afs_estate(estate->server_id, estate->probe_seq, refcount_read(&est= ate->ref), @@ -317,7 +317,7 @@ int afs_wait_for_fs_probes(struct afs_server_list *slis= t, unsigned long untried) estate =3D rcu_dereference(server->endpoint_state); if (!atomic_read(&estate->nr_probing)) __clear_bit(i, &untried); - if (estate->responded) + if (test_bit(AFS_ESTATE_RESPONDED, &estate->flags)) have_responders =3D true; } } @@ -344,7 +344,7 @@ int afs_wait_for_fs_probes(struct afs_server_list *slis= t, unsigned long untried) for (i =3D 0; i < slist->nr_servers; i++) { if (test_bit(i, &untried)) { server =3D slist->servers[i].server; - if (estate->responded) + if (test_bit(AFS_ESTATE_RESPONDED, &estate->flags)) goto stop; if (atomic_read(&estate->nr_probing)) still_probing =3D true; @@ -521,7 +521,7 @@ int afs_wait_for_one_fs_probe(struct afs_server *server= , struct afs_endpoint_sta prepare_to_wait_event(&server->probe_wq, &wait, is_intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); if (timo =3D=3D 0 || - estate->responded || + test_bit(AFS_ESTATE_RESPONDED, &estate->flags) || atomic_read(&estate->nr_probing) =3D=3D 0 || (is_intr && signal_pending(current))) break; @@ -531,7 +531,7 @@ int afs_wait_for_one_fs_probe(struct afs_server *server= , struct afs_endpoint_sta finish_wait(&server->probe_wq, &wait); =20 dont_wait: - if (estate->responded) + if (test_bit(AFS_ESTATE_RESPONDED, &estate->flags)) return 0; if (is_intr && signal_pending(current)) return -ERESTARTSYS; diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 4d42f84a8da4..96c1074fe78d 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -534,16 +534,16 @@ struct afs_endpoint_state { refcount_t ref; unsigned int server_id; /* Debug ID of server */ unsigned int probe_seq; /* Probe sequence (from server::probe_counter) */ - atomic_t nr_probing; /* Number of outstanding probes */ unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */ s32 abort_code; short error; - bool responded:1; - bool is_yfs:1; - bool not_yfs:1; - bool local_failure:1; - bool superseded:1; /* Set if has been superseded */ + unsigned long flags; +#define AFS_ESTATE_RESPONDED 0 /* Set if the server responded */ +#define AFS_ESTATE_SUPERSEDED 1 /* Set if this record has been superseded= */ +#define AFS_ESTATE_IS_YFS 2 /* Set if probe upgraded to YFS */ +#define AFS_ESTATE_NOT_YFS 3 /* Set if probe didn't upgrade to YFS */ +#define AFS_ESTATE_LOCAL_FAILURE 4 /* Set if there was a local failure (e= g. ENOMEM) */ }; =20 /* From nobody Mon Dec 15 21:24:35 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 1E9C5C4332F for ; Wed, 13 Dec 2023 13:52:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379391AbjLMNwX (ORCPT ); Wed, 13 Dec 2023 08:52:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379385AbjLMNvf (ORCPT ); Wed, 13 Dec 2023 08:51:35 -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 EA41AD5 for ; Wed, 13 Dec 2023 05:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475458; 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=me5zgkH5dFArJGbdvmvfmpSDWioSmQChzjo7Z9vM/Ao=; b=UTroCpPzrIvXeTD5Q8OpedBMkGGDlvEf8/kk42bPi5+lZH11FKntK2M/vOFi2V24SIUsNq PhG1dOG6sfhEWCBhDLV4ZHXn9T7wUaxeNiAMOyWUhwRlgH2fp7H8E+9/DltD1gprOZ6WIe q3C6Oo3UmpA00QVnyxwrWuk2HHg+PE4= 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-110-WwpT5-LDNOW-84qphPWsRA-1; Wed, 13 Dec 2023 08:50:54 -0500 X-MC-Unique: WwpT5-LDNOW-84qphPWsRA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 86A7E3869143; Wed, 13 Dec 2023 13:50:54 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96F7A51E3; Wed, 13 Dec 2023 13:50:53 +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 Subject: [PATCH v2 30/40] afs: Make it possible to find the volumes that are using a server Date: Wed, 13 Dec 2023 13:49:52 +0000 Message-ID: <20231213135003.367397-31-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make it possible to find the afs_volume structs that are using an afs_server struct to aid in breaking volume callbacks. The way this is done is that each afs_volume already has an array of afs_server_entry records that point to the servers where that volume might be found. An afs_volume backpointer and a list node is added to each entry and each entry is then added to an RCU-traversable list on the afs_server to which it points. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/cell.c | 1 + fs/afs/internal.h | 23 +++++---- fs/afs/server.c | 1 + fs/afs/server_list.c | 112 +++++++++++++++++++++++++++++++++++++++---- fs/afs/vl_alias.c | 2 +- fs/afs/volume.c | 36 ++++++++------ 6 files changed, 143 insertions(+), 32 deletions(-) diff --git a/fs/afs/cell.c b/fs/afs/cell.c index 988c2ac7cece..69716fc0ee36 100644 --- a/fs/afs/cell.c +++ b/fs/afs/cell.c @@ -161,6 +161,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *= net, refcount_set(&cell->ref, 1); atomic_set(&cell->active, 0); INIT_WORK(&cell->manager, afs_manage_cell_work); + spin_lock_init(&cell->vs_lock); cell->volumes =3D RB_ROOT; INIT_HLIST_HEAD(&cell->proc_volumes); seqlock_init(&cell->volume_lock); diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 96c1074fe78d..0b726bd2cf8c 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -414,6 +414,7 @@ struct afs_cell { unsigned int debug_id; =20 /* The volumes belonging to this cell */ + spinlock_t vs_lock; /* Lock for server->volumes */ struct rb_root volumes; /* Tree of volumes on this server */ struct hlist_head proc_volumes; /* procfs volume list */ seqlock_t volume_lock; /* For volumes */ @@ -564,6 +565,7 @@ struct afs_server { struct hlist_node addr4_link; /* Link in net->fs_addresses4 */ struct hlist_node addr6_link; /* Link in net->fs_addresses6 */ struct hlist_node proc_link; /* Link in net->fs_proc */ + struct list_head volumes; /* RCU list of afs_server_entry objects */ struct work_struct initcb_work; /* Work for CB.InitCallBackState* */ struct afs_server *gc_next; /* Next server in manager's list */ time64_t unuse_time; /* Time at which last unused */ @@ -605,12 +607,14 @@ struct afs_server { */ struct afs_server_entry { struct afs_server *server; + struct afs_volume *volume; + struct list_head slink; /* Link in server->volumes */ }; =20 struct afs_server_list { struct rcu_head rcu; - afs_volid_t vids[AFS_MAXTYPES]; /* Volume IDs */ refcount_t usage; + bool attached; /* T if attached to servers */ unsigned char nr_servers; unsigned char preferred; /* Preferred server */ unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */ @@ -623,10 +627,9 @@ struct afs_server_list { * Live AFS volume management. */ struct afs_volume { - union { - struct rcu_head rcu; - afs_volid_t vid; /* volume ID */ - }; + struct rcu_head rcu; + afs_volid_t vid; /* The volume ID of this volume */ + afs_volid_t vids[AFS_MAXTYPES]; /* All associated volume IDs */ refcount_t ref; time64_t update_at; /* Time at which to next update */ struct afs_cell *cell; /* Cell to which belongs (pins ref) */ @@ -1528,10 +1531,14 @@ static inline struct afs_server_list *afs_get_serve= rlist(struct afs_server_list } =20 extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *); -extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, st= ruct key *, - struct afs_vldb_entry *, - u8); +struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume, + struct key *key, + struct afs_vldb_entry *vldb); extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_= server_list *); +void afs_attach_volume_to_servers(struct afs_volume *volume, struct afs_se= rver_list *slist); +void afs_reattach_volume_to_servers(struct afs_volume *volume, struct afs_= server_list *slist, + struct afs_server_list *old); +void afs_detach_volume_from_servers(struct afs_volume *volume, struct afs_= server_list *slist); =20 /* * super.c diff --git a/fs/afs/server.c b/fs/afs/server.c index 281625c71aff..db2f66b11b40 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -217,6 +217,7 @@ static struct afs_server *afs_alloc_server(struct afs_c= ell *cell, server->addr_version =3D alist->version; server->uuid =3D *uuid; rwlock_init(&server->fs_lock); + INIT_LIST_HEAD(&server->volumes); INIT_WORK(&server->initcb_work, afs_server_init_callback_work); init_waitqueue_head(&server->probe_wq); INIT_LIST_HEAD(&server->probe_link); diff --git a/fs/afs/server_list.c b/fs/afs/server_list.c index b59896b1de0a..4d6369477f54 100644 --- a/fs/afs/server_list.c +++ b/fs/afs/server_list.c @@ -24,13 +24,13 @@ void afs_put_serverlist(struct afs_net *net, struct afs= _server_list *slist) /* * Build a server list from a VLDB record. */ -struct afs_server_list *afs_alloc_server_list(struct afs_cell *cell, +struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume, struct key *key, - struct afs_vldb_entry *vldb, - u8 type_mask) + struct afs_vldb_entry *vldb) { struct afs_server_list *slist; struct afs_server *server; + unsigned int type_mask =3D 1 << volume->type; int ret =3D -ENOMEM, nr_servers =3D 0, i, j; =20 for (i =3D 0; i < vldb->nr_servers; i++) @@ -44,15 +44,12 @@ struct afs_server_list *afs_alloc_server_list(struct af= s_cell *cell, refcount_set(&slist->usage, 1); rwlock_init(&slist->lock); =20 - for (i =3D 0; i < AFS_MAXTYPES; i++) - slist->vids[i] =3D vldb->vid[i]; - /* Make sure a records exists for each server in the list. */ for (i =3D 0; i < vldb->nr_servers; i++) { if (!(vldb->fs_mask[i] & type_mask)) continue; =20 - server =3D afs_lookup_server(cell, key, &vldb->fs_server[i], + server =3D afs_lookup_server(volume->cell, key, &vldb->fs_server[i], vldb->addr_version[i]); if (IS_ERR(server)) { ret =3D PTR_ERR(server); @@ -70,7 +67,7 @@ struct afs_server_list *afs_alloc_server_list(struct afs_= cell *cell, break; if (j < slist->nr_servers) { if (slist->servers[j].server =3D=3D server) { - afs_put_server(cell->net, server, + afs_put_server(volume->cell->net, server, afs_server_trace_put_slist_isort); continue; } @@ -81,6 +78,7 @@ struct afs_server_list *afs_alloc_server_list(struct afs_= cell *cell, } =20 slist->servers[j].server =3D server; + slist->servers[j].volume =3D volume; slist->nr_servers++; } =20 @@ -92,7 +90,7 @@ struct afs_server_list *afs_alloc_server_list(struct afs_= cell *cell, return slist; =20 error_2: - afs_put_serverlist(cell->net, slist); + afs_put_serverlist(volume->cell->net, slist); error: return ERR_PTR(ret); } @@ -127,3 +125,99 @@ bool afs_annotate_server_list(struct afs_server_list *= new, =20 return true; } + +/* + * Attach a volume to the servers it is going to use. + */ +void afs_attach_volume_to_servers(struct afs_volume *volume, struct afs_se= rver_list *slist) +{ + struct afs_server_entry *se, *pe; + struct afs_server *server; + struct list_head *p; + unsigned int i; + + spin_lock(&volume->cell->vs_lock); + + for (i =3D 0; i < slist->nr_servers; i++) { + se =3D &slist->servers[i]; + server =3D se->server; + + list_for_each(p, &server->volumes) { + pe =3D list_entry(p, struct afs_server_entry, slink); + if (volume->vid <=3D pe->volume->vid) + break; + } + list_add_tail_rcu(&se->slink, p); + } + + slist->attached =3D true; + spin_unlock(&volume->cell->vs_lock); +} + +/* + * Reattach a volume to the servers it is going to use when server list is + * replaced. We try to switch the attachment points to avoid rewalking the + * lists. + */ +void afs_reattach_volume_to_servers(struct afs_volume *volume, struct afs_= server_list *new, + struct afs_server_list *old) +{ + unsigned int n =3D 0, o =3D 0; + + spin_lock(&volume->cell->vs_lock); + + while (n < new->nr_servers || o < old->nr_servers) { + struct afs_server_entry *pn =3D n < new->nr_servers ? &new->servers[n] := NULL; + struct afs_server_entry *po =3D o < old->nr_servers ? &old->servers[o] := NULL; + struct afs_server_entry *s; + struct list_head *p; + int diff; + + if (pn && po && pn->server =3D=3D po->server) { + list_replace_rcu(&po->slink, &pn->slink); + n++; + o++; + continue; + } + + if (pn && po) + diff =3D memcmp(&pn->server->uuid, &po->server->uuid, + sizeof(pn->server->uuid)); + else + diff =3D pn ? -1 : 1; + + if (diff < 0) { + list_for_each(p, &pn->server->volumes) { + s =3D list_entry(p, struct afs_server_entry, slink); + if (volume->vid <=3D s->volume->vid) + break; + } + list_add_tail_rcu(&pn->slink, p); + n++; + } else { + list_del_rcu(&po->slink); + o++; + } + } + + spin_unlock(&volume->cell->vs_lock); +} + +/* + * Detach a volume from the servers it has been using. + */ +void afs_detach_volume_from_servers(struct afs_volume *volume, struct afs_= server_list *slist) +{ + unsigned int i; + + if (!slist->attached) + return; + + spin_lock(&volume->cell->vs_lock); + + for (i =3D 0; i < slist->nr_servers; i++) + list_del_rcu(&slist->servers[i].slink); + + slist->attached =3D false; + spin_unlock(&volume->cell->vs_lock); +} diff --git a/fs/afs/vl_alias.c b/fs/afs/vl_alias.c index 43788d0c18e8..63e7ed324af9 100644 --- a/fs/afs/vl_alias.c +++ b/fs/afs/vl_alias.c @@ -77,7 +77,7 @@ static int afs_compare_volume_slists(const struct afs_vol= ume *vol_a, lb =3D rcu_dereference(vol_b->servers); =20 for (i =3D 0; i < AFS_MAXTYPES; i++) - if (la->vids[i] !=3D lb->vids[i]) + if (vol_a->vids[i] !=3D vol_b->vids[i]) return 0; =20 while (a < la->nr_servers && b < lb->nr_servers) { diff --git a/fs/afs/volume.c b/fs/afs/volume.c index 115c081a8e2c..aefb982dee9a 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -72,11 +72,11 @@ static void afs_remove_volume_from_cell(struct afs_volu= me *volume) */ static struct afs_volume *afs_alloc_volume(struct afs_fs_context *params, struct afs_vldb_entry *vldb, - unsigned long type_mask) + struct afs_server_list **_slist) { struct afs_server_list *slist; struct afs_volume *volume; - int ret =3D -ENOMEM; + int ret =3D -ENOMEM, i; =20 volume =3D kzalloc(sizeof(struct afs_volume), GFP_KERNEL); if (!volume) @@ -95,13 +95,16 @@ static struct afs_volume *afs_alloc_volume(struct afs_f= s_context *params, rwlock_init(&volume->cb_v_break_lock); memcpy(volume->name, vldb->name, vldb->name_len + 1); =20 - slist =3D afs_alloc_server_list(params->cell, params->key, vldb, type_mas= k); + for (i =3D 0; i < AFS_MAXTYPES; i++) + volume->vids[i] =3D vldb->vid[i]; + + slist =3D afs_alloc_server_list(volume, params->key, vldb); if (IS_ERR(slist)) { ret =3D PTR_ERR(slist); goto error_1; } =20 - refcount_set(&slist->usage, 1); + *_slist =3D slist; rcu_assign_pointer(volume->servers, slist); trace_afs_volume(volume->vid, 1, afs_volume_trace_alloc); return volume; @@ -117,17 +120,19 @@ static struct afs_volume *afs_alloc_volume(struct afs= _fs_context *params, * Look up or allocate a volume record. */ static struct afs_volume *afs_lookup_volume(struct afs_fs_context *params, - struct afs_vldb_entry *vldb, - unsigned long type_mask) + struct afs_vldb_entry *vldb) { + struct afs_server_list *slist; struct afs_volume *candidate, *volume; =20 - candidate =3D afs_alloc_volume(params, vldb, type_mask); + candidate =3D afs_alloc_volume(params, vldb, &slist); if (IS_ERR(candidate)) return candidate; =20 volume =3D afs_insert_volume_into_cell(params->cell, candidate); - if (volume !=3D candidate) + if (volume =3D=3D candidate) + afs_attach_volume_to_servers(volume, slist); + else afs_put_volume(params->net, candidate, afs_volume_trace_put_cell_dup); return volume; } @@ -208,8 +213,7 @@ struct afs_volume *afs_create_volume(struct afs_fs_cont= ext *params) goto error; } =20 - type_mask =3D 1UL << params->type; - volume =3D afs_lookup_volume(params, vldb, type_mask); + volume =3D afs_lookup_volume(params, vldb); =20 error: kfree(vldb); @@ -221,14 +225,17 @@ struct afs_volume *afs_create_volume(struct afs_fs_co= ntext *params) */ static void afs_destroy_volume(struct afs_net *net, struct afs_volume *vol= ume) { + struct afs_server_list *slist =3D rcu_access_pointer(volume->servers); + _enter("%p", volume); =20 #ifdef CONFIG_AFS_FSCACHE ASSERTCMP(volume->cache, =3D=3D, NULL); #endif =20 + afs_detach_volume_from_servers(volume, slist); afs_remove_volume_from_cell(volume); - afs_put_serverlist(net, rcu_access_pointer(volume->servers)); + afs_put_serverlist(net, slist); afs_put_cell(volume->cell, afs_cell_trace_put_vol); trace_afs_volume(volume->vid, refcount_read(&volume->ref), afs_volume_trace_free); @@ -362,8 +369,7 @@ static int afs_update_volume_status(struct afs_volume *= volume, struct key *key) } =20 /* See if the volume's server list got updated. */ - new =3D afs_alloc_server_list(volume->cell, key, - vldb, (1 << volume->type)); + new =3D afs_alloc_server_list(volume, key, vldb); if (IS_ERR(new)) { ret =3D PTR_ERR(new); goto error_vldb; @@ -384,9 +390,11 @@ static int afs_update_volume_status(struct afs_volume = *volume, struct key *key) =20 volume->update_at =3D ktime_get_real_seconds() + afs_volume_record_life; write_unlock(&volume->servers_lock); - ret =3D 0; =20 + if (discard =3D=3D old) + afs_reattach_volume_to_servers(volume, new, old); afs_put_serverlist(volume->cell->net, discard); + ret =3D 0; error_vldb: kfree(vldb); error: From nobody Mon Dec 15 21:24:35 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 AC1BAC4332F for ; Wed, 13 Dec 2023 13:52:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379368AbjLMNwc (ORCPT ); Wed, 13 Dec 2023 08:52:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379333AbjLMNvg (ORCPT ); Wed, 13 Dec 2023 08:51:36 -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 EAC19D69 for ; Wed, 13 Dec 2023 05:51:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475459; 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=N54RfssiyMrCSUQUUjNs2/hJPSr7YiGFMmK5Pu5ovDQ=; b=Saj3f8KOXbR6vdw0W10RCL6yIW2Xtxzi2r9De6sf7lQCa+gWCZ3Byn9Q5cbKbRUJWffZRu 7GS0Se+fKjh0B9Ui6SzWVLp260DhG80lYMK2Ce29nhBkJtEJPUI1uddGU/WrJ6dEutHUms evKrQ1XF/H1NBLLAjkiQaqjW0BxDGDs= 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-417-6zP04VebOQuW8m8cO5Ymlg-1; Wed, 13 Dec 2023 08:50:56 -0500 X-MC-Unique: 6zP04VebOQuW8m8cO5Ymlg-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 014DE29AC03A; Wed, 13 Dec 2023 13:50:56 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 352591C060B1; Wed, 13 Dec 2023 13:50:55 +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 Subject: [PATCH v2 31/40] afs: Defer volume record destruction to a workqueue Date: Wed, 13 Dec 2023 13:49:53 +0000 Message-ID: <20231213135003.367397-32-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: quoted-printable 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-Type: text/plain; charset="utf-8" Defer volume record destruction to a workqueue so that afs_put_volume() isn't going to run the destruction process in the callback workqueue whilst the server is holding up other clients whilst waiting for us to reply to a CB.CallBack notification RPC. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/cell.c | 2 +- fs/afs/fs_operation.c | 2 +- fs/afs/internal.h | 3 ++- fs/afs/super.c | 7 +++---- fs/afs/vl_alias.c | 6 +++--- fs/afs/volume.c | 15 +++++++++------ 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/fs/afs/cell.c b/fs/afs/cell.c index 69716fc0ee36..6b389f2bcd0c 100644 --- a/fs/afs/cell.c +++ b/fs/afs/cell.c @@ -816,7 +816,7 @@ static void afs_manage_cell(struct afs_cell *cell) =20 final_destruction: /* The root volume is pinning the cell */ - afs_put_volume(cell->net, cell->root_volume, afs_volume_trace_put_cell_ro= ot); + afs_put_volume(cell->root_volume, afs_volume_trace_put_cell_root); cell->root_volume =3D NULL; afs_put_cell(cell, afs_cell_trace_put_destroy); } diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 8c6d827f999d..10137681aa7d 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -265,7 +265,7 @@ int afs_put_operation(struct afs_operation *op) } =20 afs_put_serverlist(op->net, op->server_list); - afs_put_volume(op->net, op->volume, afs_volume_trace_put_put_op); + afs_put_volume(op->volume, afs_volume_trace_put_put_op); key_put(op->key); kfree(op); return ret; diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 0b726bd2cf8c..a50dfb2f8d7d 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -636,6 +636,7 @@ struct afs_volume { struct rb_node cell_node; /* Link in cell->volumes */ struct hlist_node proc_link; /* Link in cell->proc_volumes */ struct super_block __rcu *sb; /* Superblock on which inodes reside */ + struct work_struct destructor; /* Deferred destructor */ unsigned long flags; #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */ #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */ @@ -1613,7 +1614,7 @@ extern int afs_activate_volume(struct afs_volume *); extern void afs_deactivate_volume(struct afs_volume *); bool afs_try_get_volume(struct afs_volume *volume, enum afs_volume_trace r= eason); extern struct afs_volume *afs_get_volume(struct afs_volume *, enum afs_vol= ume_trace); -extern void afs_put_volume(struct afs_net *, struct afs_volume *, enum afs= _volume_trace); +void afs_put_volume(struct afs_volume *volume, enum afs_volume_trace reaso= n); extern int afs_check_volume_status(struct afs_volume *, struct afs_operati= on *); =20 /* diff --git a/fs/afs/super.c b/fs/afs/super.c index a01a0fb2cdbb..ae2d66a52add 100644 --- a/fs/afs/super.c +++ b/fs/afs/super.c @@ -381,8 +381,7 @@ static int afs_validate_fc(struct fs_context *fc) ctx->key =3D key; =20 if (ctx->volume) { - afs_put_volume(ctx->net, ctx->volume, - afs_volume_trace_put_validate_fc); + afs_put_volume(ctx->volume, afs_volume_trace_put_validate_fc); ctx->volume =3D NULL; } =20 @@ -529,7 +528,7 @@ static void afs_destroy_sbi(struct afs_super_info *as) { if (as) { struct afs_net *net =3D afs_net(as->net_ns); - afs_put_volume(net, as->volume, afs_volume_trace_put_destroy_sbi); + afs_put_volume(as->volume, afs_volume_trace_put_destroy_sbi); afs_unuse_cell(net, as->cell, afs_cell_trace_unuse_sbi); put_net(as->net_ns); kfree(as); @@ -615,7 +614,7 @@ static void afs_free_fc(struct fs_context *fc) struct afs_fs_context *ctx =3D fc->fs_private; =20 afs_destroy_sbi(fc->s_fs_info); - afs_put_volume(ctx->net, ctx->volume, afs_volume_trace_put_free_fc); + afs_put_volume(ctx->volume, afs_volume_trace_put_free_fc); afs_unuse_cell(ctx->net, ctx->cell, afs_cell_trace_unuse_fc); key_put(ctx->key); kfree(ctx); diff --git a/fs/afs/vl_alias.c b/fs/afs/vl_alias.c index 63e7ed324af9..9f36e14f1c2d 100644 --- a/fs/afs/vl_alias.c +++ b/fs/afs/vl_alias.c @@ -156,7 +156,7 @@ static int afs_query_for_alias_one(struct afs_cell *cel= l, struct key *key, /* And see if it's in the new cell. */ volume =3D afs_sample_volume(cell, key, pvol->name, pvol->name_len); if (IS_ERR(volume)) { - afs_put_volume(cell->net, pvol, afs_volume_trace_put_query_alias); + afs_put_volume(pvol, afs_volume_trace_put_query_alias); if (PTR_ERR(volume) !=3D -ENOMEDIUM) return PTR_ERR(volume); /* That volume is not in the new cell, so not an alias */ @@ -174,8 +174,8 @@ static int afs_query_for_alias_one(struct afs_cell *cel= l, struct key *key, rcu_read_unlock(); } =20 - afs_put_volume(cell->net, volume, afs_volume_trace_put_query_alias); - afs_put_volume(cell->net, pvol, afs_volume_trace_put_query_alias); + afs_put_volume(volume, afs_volume_trace_put_query_alias); + afs_put_volume(pvol, afs_volume_trace_put_query_alias); return ret; } =20 diff --git a/fs/afs/volume.c b/fs/afs/volume.c index aefb982dee9a..4982fce25057 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -11,6 +11,8 @@ =20 static unsigned __read_mostly afs_volume_record_life =3D 60 * 60; =20 +static void afs_destroy_volume(struct work_struct *work); + /* * Insert a volume into a cell. If there's an existing volume record, tha= t is * returned instead with a ref held. @@ -91,6 +93,7 @@ static struct afs_volume *afs_alloc_volume(struct afs_fs_= context *params, =20 refcount_set(&volume->ref, 1); INIT_HLIST_NODE(&volume->proc_link); + INIT_WORK(&volume->destructor, afs_destroy_volume); rwlock_init(&volume->servers_lock); rwlock_init(&volume->cb_v_break_lock); memcpy(volume->name, vldb->name, vldb->name_len + 1); @@ -133,7 +136,7 @@ static struct afs_volume *afs_lookup_volume(struct afs_= fs_context *params, if (volume =3D=3D candidate) afs_attach_volume_to_servers(volume, slist); else - afs_put_volume(params->net, candidate, afs_volume_trace_put_cell_dup); + afs_put_volume(candidate, afs_volume_trace_put_cell_dup); return volume; } =20 @@ -223,8 +226,9 @@ struct afs_volume *afs_create_volume(struct afs_fs_cont= ext *params) /* * Destroy a volume record */ -static void afs_destroy_volume(struct afs_net *net, struct afs_volume *vol= ume) +static void afs_destroy_volume(struct work_struct *work) { + struct afs_volume *volume =3D container_of(work, struct afs_volume, destr= uctor); struct afs_server_list *slist =3D rcu_access_pointer(volume->servers); =20 _enter("%p", volume); @@ -235,7 +239,7 @@ static void afs_destroy_volume(struct afs_net *net, str= uct afs_volume *volume) =20 afs_detach_volume_from_servers(volume, slist); afs_remove_volume_from_cell(volume); - afs_put_serverlist(net, slist); + afs_put_serverlist(volume->cell->net, slist); afs_put_cell(volume->cell, afs_cell_trace_put_vol); trace_afs_volume(volume->vid, refcount_read(&volume->ref), afs_volume_trace_free); @@ -277,8 +281,7 @@ struct afs_volume *afs_get_volume(struct afs_volume *vo= lume, /* * Drop a reference on a volume record. */ -void afs_put_volume(struct afs_net *net, struct afs_volume *volume, - enum afs_volume_trace reason) +void afs_put_volume(struct afs_volume *volume, enum afs_volume_trace reaso= n) { if (volume) { afs_volid_t vid =3D volume->vid; @@ -288,7 +291,7 @@ void afs_put_volume(struct afs_net *net, struct afs_vol= ume *volume, zero =3D __refcount_dec_and_test(&volume->ref, &r); trace_afs_volume(vid, r - 1, reason); if (zero) - afs_destroy_volume(net, volume); + schedule_work(&volume->destructor); } } From nobody Mon Dec 15 21:24:35 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 9F098C4167D for ; Wed, 13 Dec 2023 13:52:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441862AbjLMNw3 (ORCPT ); Wed, 13 Dec 2023 08:52:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379387AbjLMNvg (ORCPT ); Wed, 13 Dec 2023 08:51:36 -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 22EEB19B for ; Wed, 13 Dec 2023 05:51:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475459; 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=Gt+qb4YpAajMbQL9rvZ8Y9MPqmE5bMZVduZ1rQOTpmc=; b=GMAgv4D9ZVgJtNaz7lRlqPVFwN7q1jVLRQky38HMn7ahhLSo6wLTvf5woQqigfDUTA8+2m i1R9XbR6UqjBaHIFZhLet3NV+xgQLwir0eF/UGAfJk8mCZ7O7mI2u7yn/79QraWc1hfGX9 FfW6rmIm5mTqw0w6YSmYrst7JV3n0Lc= 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-670-j_ZxgNeUMBOFLTHSBwLmGw-1; Wed, 13 Dec 2023 08:50:58 -0500 X-MC-Unique: j_ZxgNeUMBOFLTHSBwLmGw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 A24FA8828C9; Wed, 13 Dec 2023 13:50:57 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id B903A51E3; Wed, 13 Dec 2023 13:50:56 +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 Subject: [PATCH v2 32/40] afs: Move the vnode/volume validity checking code into its own file Date: Wed, 13 Dec 2023 13:49:54 +0000 Message-ID: <20231213135003.367397-33-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move the code that does validity checking of vnodes and volumes with respect to third-party changes into its own file. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/Makefile | 1 + fs/afs/inode.c | 172 ----------------------------------------- fs/afs/internal.h | 10 ++- fs/afs/validation.c | 183 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+), 175 deletions(-) create mode 100644 fs/afs/validation.c diff --git a/fs/afs/Makefile b/fs/afs/Makefile index b3849bea0553..dcdc0f1bb76f 100644 --- a/fs/afs/Makefile +++ b/fs/afs/Makefile @@ -28,6 +28,7 @@ kafs-y :=3D \ server.o \ server_list.o \ super.o \ + validation.o \ vlclient.o \ vl_alias.o \ vl_list.o \ diff --git a/fs/afs/inode.c b/fs/afs/inode.c index f44a8a48bf24..102e7c37d33c 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -572,178 +572,6 @@ struct inode *afs_root_iget(struct super_block *sb, s= truct key *key) return ERR_PTR(ret); } =20 -/* - * mark the data attached to an inode as obsolete due to a write on the se= rver - * - might also want to ditch all the outstanding writes and dirty pages - */ -static void afs_zap_data(struct afs_vnode *vnode) -{ - _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode); - - afs_invalidate_cache(vnode, 0); - - /* nuke all the non-dirty pages that aren't locked, mapped or being - * written back in a regular file and completely discard the pages in a - * directory or symlink */ - if (S_ISREG(vnode->netfs.inode.i_mode)) - invalidate_remote_inode(&vnode->netfs.inode); - else - invalidate_inode_pages2(vnode->netfs.inode.i_mapping); -} - -/* - * Check to see if we have a server currently serving this volume and that= it - * hasn't been reinitialised or dropped from the list. - */ -static bool afs_check_server_good(struct afs_vnode *vnode) -{ - struct afs_server_list *slist; - struct afs_server *server; - bool good; - int i; - - if (vnode->cb_fs_s_break =3D=3D atomic_read(&vnode->volume->cell->fs_s_br= eak)) - return true; - - rcu_read_lock(); - - slist =3D rcu_dereference(vnode->volume->servers); - for (i =3D 0; i < slist->nr_servers; i++) { - server =3D slist->servers[i].server; - if (server =3D=3D vnode->cb_server) { - good =3D (vnode->cb_s_break =3D=3D server->cb_s_break); - rcu_read_unlock(); - return good; - } - } - - rcu_read_unlock(); - return false; -} - -/* - * Check the validity of a vnode/inode. - */ -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; - - do { - seq =3D read_seqbegin(&vnode->cb_lock); - cb_break =3D vnode->cb_break; - - if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { - if (vnode->cb_v_break !=3D vnode->volume->cb_v_break) - need_clear =3D afs_cb_break_for_v_break; - else if (!afs_check_server_good(vnode)) - need_clear =3D afs_cb_break_for_s_reinit; - else if (test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) - need_clear =3D afs_cb_break_for_zap; - else if (vnode->cb_expires_at - 10 <=3D now) - need_clear =3D afs_cb_break_for_lapsed; - } else if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { - ; - } else { - need_clear =3D afs_cb_break_no_promise; - } - - } while (read_seqretry(&vnode->cb_lock, seq)); - - if (need_clear =3D=3D afs_cb_break_no_break) - return true; - - write_seqlock(&vnode->cb_lock); - if (need_clear =3D=3D afs_cb_break_no_promise) - vnode->cb_v_break =3D vnode->volume->cb_v_break; - else if (cb_break =3D=3D vnode->cb_break) - __afs_break_callback(vnode, need_clear); - else - trace_afs_cb_miss(&vnode->fid, need_clear); - write_sequnlock(&vnode->cb_lock); - return false; -} - -/* - * Returns true if the pagecache is still valid. Does not sleep. - */ -bool afs_pagecache_valid(struct afs_vnode *vnode) -{ - if (unlikely(test_bit(AFS_VNODE_DELETED, &vnode->flags))) { - if (vnode->netfs.inode.i_nlink) - clear_nlink(&vnode->netfs.inode); - return true; - } - - if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags) && - afs_check_validity(vnode)) - return true; - - return false; -} - -/* - * validate a vnode/inode - * - there are several things we need to check - * - parent dir data changes (rm, rmdir, rename, mkdir, create, link, - * symlink) - * - parent dir metadata changed (security changes) - * - dentry data changed (write, truncate) - * - dentry metadata changed (security changes) - */ -int afs_validate(struct afs_vnode *vnode, struct key *key) -{ - int ret; - - _enter("{v=3D{%llx:%llu} fl=3D%lx},%x", - vnode->fid.vid, vnode->fid.vnode, vnode->flags, - key_serial(key)); - - if (afs_pagecache_valid(vnode)) - goto valid; - - down_write(&vnode->validate_lock); - - /* if the promise has expired, we need to check the server again to get - * a new promise - note that if the (parent) directory's metadata was - * changed then the security may be different and we may no longer have - * access */ - if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { - _debug("not promised"); - ret =3D afs_fetch_status(vnode, key, false, NULL); - if (ret < 0) { - if (ret =3D=3D -ENOENT) { - set_bit(AFS_VNODE_DELETED, &vnode->flags); - ret =3D -ESTALE; - } - goto error_unlock; - } - _debug("new promise [fl=3D%lx]", vnode->flags); - } - - if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { - _debug("file already deleted"); - ret =3D -ESTALE; - goto error_unlock; - } - - /* if the vnode's data version number changed then its contents are - * different */ - if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) - afs_zap_data(vnode); - up_write(&vnode->validate_lock); -valid: - _leave(" =3D 0"); - return 0; - -error_unlock: - up_write(&vnode->validate_lock); - _leave(" =3D %d", ret); - return ret; -} - /* * read the attributes of an inode */ diff --git a/fs/afs/internal.h b/fs/afs/internal.h index a50dfb2f8d7d..4a3d946b1d2a 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -1235,9 +1235,6 @@ extern int afs_ilookup5_test_by_fid(struct inode *, v= oid *); extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool); extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_par= am *); extern struct inode *afs_root_iget(struct super_block *, struct key *); -extern bool afs_check_validity(struct afs_vnode *); -extern int afs_validate(struct afs_vnode *, struct key *); -bool afs_pagecache_valid(struct afs_vnode *); extern int afs_getattr(struct mnt_idmap *idmap, const struct path *, struct kstat *, u32, unsigned int); extern int afs_setattr(struct mnt_idmap *idmap, struct dentry *, struct ia= ttr *); @@ -1547,6 +1544,13 @@ void afs_detach_volume_from_servers(struct afs_volum= e *volume, struct afs_server extern int __init afs_fs_init(void); extern void afs_fs_exit(void); =20 +/* + * validation.c + */ +bool afs_check_validity(struct afs_vnode *vnode); +bool afs_pagecache_valid(struct afs_vnode *vnode); +int afs_validate(struct afs_vnode *vnode, struct key *key); + /* * vlclient.c */ diff --git a/fs/afs/validation.c b/fs/afs/validation.c new file mode 100644 index 000000000000..18ba2c5e8ead --- /dev/null +++ b/fs/afs/validation.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* vnode and volume validity verification. + * + * Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowells@redhat.com) + */ + +#include +#include +#include +#include "internal.h" + +/* + * mark the data attached to an inode as obsolete due to a write on the se= rver + * - might also want to ditch all the outstanding writes and dirty pages + */ +static void afs_zap_data(struct afs_vnode *vnode) +{ + _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode); + + afs_invalidate_cache(vnode, 0); + + /* nuke all the non-dirty pages that aren't locked, mapped or being + * written back in a regular file and completely discard the pages in a + * directory or symlink */ + if (S_ISREG(vnode->netfs.inode.i_mode)) + invalidate_remote_inode(&vnode->netfs.inode); + else + invalidate_inode_pages2(vnode->netfs.inode.i_mapping); +} + +/* + * Check to see if we have a server currently serving this volume and that= it + * hasn't been reinitialised or dropped from the list. + */ +static bool afs_check_server_good(struct afs_vnode *vnode) +{ + struct afs_server_list *slist; + struct afs_server *server; + bool good; + int i; + + if (vnode->cb_fs_s_break =3D=3D atomic_read(&vnode->volume->cell->fs_s_br= eak)) + return true; + + rcu_read_lock(); + + slist =3D rcu_dereference(vnode->volume->servers); + for (i =3D 0; i < slist->nr_servers; i++) { + server =3D slist->servers[i].server; + if (server =3D=3D vnode->cb_server) { + good =3D (vnode->cb_s_break =3D=3D server->cb_s_break); + rcu_read_unlock(); + return good; + } + } + + rcu_read_unlock(); + return false; +} + +/* + * Check the validity of a vnode/inode. + */ +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; + + do { + seq =3D read_seqbegin(&vnode->cb_lock); + cb_break =3D vnode->cb_break; + + if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { + if (vnode->cb_v_break !=3D vnode->volume->cb_v_break) + need_clear =3D afs_cb_break_for_v_break; + else if (!afs_check_server_good(vnode)) + need_clear =3D afs_cb_break_for_s_reinit; + else if (test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) + need_clear =3D afs_cb_break_for_zap; + else if (vnode->cb_expires_at - 10 <=3D now) + need_clear =3D afs_cb_break_for_lapsed; + } else if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { + ; + } else { + need_clear =3D afs_cb_break_no_promise; + } + + } while (read_seqretry(&vnode->cb_lock, seq)); + + if (need_clear =3D=3D afs_cb_break_no_break) + return true; + + write_seqlock(&vnode->cb_lock); + if (need_clear =3D=3D afs_cb_break_no_promise) + vnode->cb_v_break =3D vnode->volume->cb_v_break; + else if (cb_break =3D=3D vnode->cb_break) + __afs_break_callback(vnode, need_clear); + else + trace_afs_cb_miss(&vnode->fid, need_clear); + write_sequnlock(&vnode->cb_lock); + return false; +} + +/* + * Returns true if the pagecache is still valid. Does not sleep. + */ +bool afs_pagecache_valid(struct afs_vnode *vnode) +{ + if (unlikely(test_bit(AFS_VNODE_DELETED, &vnode->flags))) { + if (vnode->netfs.inode.i_nlink) + clear_nlink(&vnode->netfs.inode); + return true; + } + + if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags) && + afs_check_validity(vnode)) + return true; + + return false; +} + +/* + * validate a vnode/inode + * - there are several things we need to check + * - parent dir data changes (rm, rmdir, rename, mkdir, create, link, + * symlink) + * - parent dir metadata changed (security changes) + * - dentry data changed (write, truncate) + * - dentry metadata changed (security changes) + */ +int afs_validate(struct afs_vnode *vnode, struct key *key) +{ + int ret; + + _enter("{v=3D{%llx:%llu} fl=3D%lx},%x", + vnode->fid.vid, vnode->fid.vnode, vnode->flags, + key_serial(key)); + + if (afs_pagecache_valid(vnode)) + goto valid; + + down_write(&vnode->validate_lock); + + /* if the promise has expired, we need to check the server again to get + * a new promise - note that if the (parent) directory's metadata was + * changed then the security may be different and we may no longer have + * access */ + if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { + _debug("not promised"); + ret =3D afs_fetch_status(vnode, key, false, NULL); + if (ret < 0) { + if (ret =3D=3D -ENOENT) { + set_bit(AFS_VNODE_DELETED, &vnode->flags); + ret =3D -ESTALE; + } + goto error_unlock; + } + _debug("new promise [fl=3D%lx]", vnode->flags); + } + + if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { + _debug("file already deleted"); + ret =3D -ESTALE; + goto error_unlock; + } + + /* if the vnode's data version number changed then its contents are + * different */ + if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) + afs_zap_data(vnode); + up_write(&vnode->validate_lock); +valid: + _leave(" =3D 0"); + return 0; + +error_unlock: + up_write(&vnode->validate_lock); + _leave(" =3D %d", ret); + return ret; +} From nobody Mon Dec 15 21:24:35 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 9B087C4167B for ; Wed, 13 Dec 2023 13:52:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441882AbjLMNwh (ORCPT ); Wed, 13 Dec 2023 08:52:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235395AbjLMNvm (ORCPT ); Wed, 13 Dec 2023 08:51:42 -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 C1498E8 for ; Wed, 13 Dec 2023 05:51:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475462; 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=g2GWhe9FZEsJl5IpiJcmjxtT2QQDd4kAj0w10I5PhSo=; b=cydvdzOdYJlnwVn5PDlSn1u66zhf7uTSoaSqKqgZ0V9mxmVv0AZr512lDn/036dAULPssz 5XsPtmtvTjJOTtyhlM77USmz/MIwXBlN3UDLyZQcYzGxyCBaflGB4Prb9KMQyqKjve0pTx beI8i73y529ZTwFnQhHGy9SSDOmxRao= 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-79-QHbI7rmhMOqpjfSVUp3aXw-1; Wed, 13 Dec 2023 08:50:59 -0500 X-MC-Unique: QHbI7rmhMOqpjfSVUp3aXw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 1BA0B185A782; Wed, 13 Dec 2023 13:50:59 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5113851E3; Wed, 13 Dec 2023 13:50:58 +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 Subject: [PATCH v2 33/40] afs: Apply server breaks to mmap'd files in the call processor Date: Wed, 13 Dec 2023 13:49:55 +0000 Message-ID: <20231213135003.367397-34-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Apply server breaks to mmap'd files that are being used from that server from the call processor work function rather than punting it off to a workqueue. The work item, afs_server_init_callback(), then bumps each individual inode off to its own work item introducing a potentially lengthy delay. This reduces that delay at the cost of extending the amount of time we delay replying to the CB.InitCallBack3 notification RPC from the server. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/callback.c | 33 +++++++++++++++++++-------------- fs/afs/cell.c | 2 +- fs/afs/internal.h | 4 +--- fs/afs/server.c | 2 -- fs/afs/server_list.c | 22 +++++++++++----------- include/trace/events/afs.h | 2 ++ 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/fs/afs/callback.c b/fs/afs/callback.c index 90f9b2a46ff4..f67e88076761 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c @@ -33,9 +33,8 @@ void afs_invalidate_mmap_work(struct work_struct *work) unmap_mapping_pages(vnode->netfs.inode.i_mapping, 0, 0, false); } =20 -void afs_server_init_callback_work(struct work_struct *work) +static void afs_server_init_callback(struct afs_server *server) { - struct afs_server *server =3D container_of(work, struct afs_server, initc= b_work); struct afs_vnode *vnode; struct afs_cell *cell =3D server->cell; =20 @@ -57,15 +56,19 @@ void afs_server_init_callback_work(struct work_struct *= work) */ void afs_init_callback_state(struct afs_server *server) { - rcu_read_lock(); + struct afs_cell *cell =3D server->cell; + + down_read(&cell->vs_lock); + do { server->cb_s_break++; atomic_inc(&server->cell->fs_s_break); if (!list_empty(&server->cell->fs_open_mmaps)) - queue_work(system_unbound_wq, &server->initcb_work); + afs_server_init_callback(server); =20 } while ((server =3D rcu_dereference(server->uuid_next))); - rcu_read_unlock(); + + up_read(&cell->vs_lock); } =20 /* @@ -112,7 +115,7 @@ static struct afs_volume *afs_lookup_volume_rcu(struct = afs_cell *cell, struct rb_node *p; int seq =3D 1; =20 - do { + for (;;) { /* Unfortunately, rbtree walking doesn't give reliable results * under just the RCU read lock, so we have to check for * changes. @@ -133,7 +136,12 @@ static struct afs_volume *afs_lookup_volume_rcu(struct= afs_cell *cell, volume =3D NULL; } =20 - } while (need_seqretry(&cell->volume_lock, seq)); + if (volume && afs_try_get_volume(volume, afs_volume_trace_get_callback)) + break; + if (!need_seqretry(&cell->volume_lock, seq)) + break; + seq |=3D 1; /* Want a lock next time */ + } =20 done_seqretry(&cell->volume_lock, seq); return volume; @@ -188,12 +196,11 @@ static void afs_break_some_callbacks(struct afs_serve= r *server, afs_volid_t vid =3D cbb->fid.vid; size_t i; =20 + rcu_read_lock(); volume =3D afs_lookup_volume_rcu(server->cell, vid); - /* TODO: Find all matching volumes if we couldn't match the server and * break them anyway. */ - for (i =3D *_count; i > 0; cbb++, i--) { if (cbb->fid.vid =3D=3D vid) { _debug("- Fid { vl=3D%08llx n=3D%llu u=3D%u }", @@ -207,6 +214,9 @@ static void afs_break_some_callbacks(struct afs_server = *server, *residue++ =3D *cbb; } } + + rcu_read_unlock(); + afs_put_volume(volume, afs_volume_trace_put_callback); } =20 /* @@ -219,11 +229,6 @@ void afs_break_callbacks(struct afs_server *server, si= ze_t count, =20 ASSERT(server !=3D NULL); =20 - rcu_read_lock(); - while (count > 0) afs_break_some_callbacks(server, callbacks, &count); - - rcu_read_unlock(); - return; } diff --git a/fs/afs/cell.c b/fs/afs/cell.c index 6b389f2bcd0c..1e5cb0f6ee07 100644 --- a/fs/afs/cell.c +++ b/fs/afs/cell.c @@ -161,7 +161,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *= net, refcount_set(&cell->ref, 1); atomic_set(&cell->active, 0); INIT_WORK(&cell->manager, afs_manage_cell_work); - spin_lock_init(&cell->vs_lock); + init_rwsem(&cell->vs_lock); cell->volumes =3D RB_ROOT; INIT_HLIST_HEAD(&cell->proc_volumes); seqlock_init(&cell->volume_lock); diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 4a3d946b1d2a..5ae4ca999d65 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -414,7 +414,7 @@ struct afs_cell { unsigned int debug_id; =20 /* The volumes belonging to this cell */ - spinlock_t vs_lock; /* Lock for server->volumes */ + struct rw_semaphore vs_lock; /* Lock for server->volumes */ struct rb_root volumes; /* Tree of volumes on this server */ struct hlist_head proc_volumes; /* procfs volume list */ seqlock_t volume_lock; /* For volumes */ @@ -566,7 +566,6 @@ struct afs_server { struct hlist_node addr6_link; /* Link in net->fs_addresses6 */ struct hlist_node proc_link; /* Link in net->fs_proc */ struct list_head volumes; /* RCU list of afs_server_entry objects */ - struct work_struct initcb_work; /* Work for CB.InitCallBackState* */ struct afs_server *gc_next; /* Next server in manager's list */ time64_t unuse_time; /* Time at which last unused */ unsigned long flags; @@ -1041,7 +1040,6 @@ void afs_get_address_preferences(struct afs_net *net,= struct afs_addr_list *alis * callback.c */ extern void afs_invalidate_mmap_work(struct work_struct *); -extern void afs_server_init_callback_work(struct work_struct *work); extern void afs_init_callback_state(struct afs_server *); extern void __afs_break_callback(struct afs_vnode *, enum afs_cb_break_rea= son); extern void afs_break_callback(struct afs_vnode *, enum afs_cb_break_reaso= n); diff --git a/fs/afs/server.c b/fs/afs/server.c index db2f66b11b40..e169121f603e 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -218,7 +218,6 @@ static struct afs_server *afs_alloc_server(struct afs_c= ell *cell, server->uuid =3D *uuid; rwlock_init(&server->fs_lock); INIT_LIST_HEAD(&server->volumes); - INIT_WORK(&server->initcb_work, afs_server_init_callback_work); init_waitqueue_head(&server->probe_wq); INIT_LIST_HEAD(&server->probe_link); spin_lock_init(&server->probe_lock); @@ -470,7 +469,6 @@ static void afs_destroy_server(struct afs_net *net, str= uct afs_server *server) if (test_bit(AFS_SERVER_FL_MAY_HAVE_CB, &server->flags)) afs_give_up_callbacks(net, server); =20 - flush_work(&server->initcb_work); afs_put_server(net, server, afs_server_trace_destroy); } =20 diff --git a/fs/afs/server_list.c b/fs/afs/server_list.c index 4d6369477f54..cfd900eb09ed 100644 --- a/fs/afs/server_list.c +++ b/fs/afs/server_list.c @@ -136,7 +136,7 @@ void afs_attach_volume_to_servers(struct afs_volume *vo= lume, struct afs_server_l struct list_head *p; unsigned int i; =20 - spin_lock(&volume->cell->vs_lock); + down_write(&volume->cell->vs_lock); =20 for (i =3D 0; i < slist->nr_servers; i++) { se =3D &slist->servers[i]; @@ -147,11 +147,11 @@ void afs_attach_volume_to_servers(struct afs_volume *= volume, struct afs_server_l if (volume->vid <=3D pe->volume->vid) break; } - list_add_tail_rcu(&se->slink, p); + list_add_tail(&se->slink, p); } =20 slist->attached =3D true; - spin_unlock(&volume->cell->vs_lock); + up_write(&volume->cell->vs_lock); } =20 /* @@ -164,7 +164,7 @@ void afs_reattach_volume_to_servers(struct afs_volume *= volume, struct afs_server { unsigned int n =3D 0, o =3D 0; =20 - spin_lock(&volume->cell->vs_lock); + down_write(&volume->cell->vs_lock); =20 while (n < new->nr_servers || o < old->nr_servers) { struct afs_server_entry *pn =3D n < new->nr_servers ? &new->servers[n] := NULL; @@ -174,7 +174,7 @@ void afs_reattach_volume_to_servers(struct afs_volume *= volume, struct afs_server int diff; =20 if (pn && po && pn->server =3D=3D po->server) { - list_replace_rcu(&po->slink, &pn->slink); + list_replace(&po->slink, &pn->slink); n++; o++; continue; @@ -192,15 +192,15 @@ void afs_reattach_volume_to_servers(struct afs_volume= *volume, struct afs_server if (volume->vid <=3D s->volume->vid) break; } - list_add_tail_rcu(&pn->slink, p); + list_add_tail(&pn->slink, p); n++; } else { - list_del_rcu(&po->slink); + list_del(&po->slink); o++; } } =20 - spin_unlock(&volume->cell->vs_lock); + up_write(&volume->cell->vs_lock); } =20 /* @@ -213,11 +213,11 @@ void afs_detach_volume_from_servers(struct afs_volume= *volume, struct afs_server if (!slist->attached) return; =20 - spin_lock(&volume->cell->vs_lock); + down_write(&volume->cell->vs_lock); =20 for (i =3D 0; i < slist->nr_servers; i++) - list_del_rcu(&slist->servers[i].slink); + list_del(&slist->servers[i].slink); =20 slist->attached =3D false; - spin_unlock(&volume->cell->vs_lock); + up_write(&volume->cell->vs_lock); } diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index cf2fa4fddd5b..63ab23876be8 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -151,9 +151,11 @@ enum yfs_cm_operation { EM(afs_volume_trace_alloc, "ALLOC ") \ EM(afs_volume_trace_free, "FREE ") \ EM(afs_volume_trace_get_alloc_sbi, "GET sbi-alloc ") \ + EM(afs_volume_trace_get_callback, "GET callback ") \ EM(afs_volume_trace_get_cell_insert, "GET cell-insrt") \ EM(afs_volume_trace_get_new_op, "GET op-new ") \ EM(afs_volume_trace_get_query_alias, "GET cell-alias") \ + EM(afs_volume_trace_put_callback, "PUT callback ") \ EM(afs_volume_trace_put_cell_dup, "PUT cell-dup ") \ EM(afs_volume_trace_put_cell_root, "PUT cell-root ") \ EM(afs_volume_trace_put_destroy_sbi, "PUT sbi-destry") \ From nobody Mon Dec 15 21:24:35 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 DC884C4332F for ; Wed, 13 Dec 2023 13:53:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441804AbjLMNx0 (ORCPT ); Wed, 13 Dec 2023 08:53:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379366AbjLMNwW (ORCPT ); Wed, 13 Dec 2023 08:52:22 -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 39E6E1986 for ; Wed, 13 Dec 2023 05:51:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475479; 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=Mrk0toX4iy+sa30+IfYuhvEvlz4UbttXs26cFwhG3jo=; b=RRBSVNas4VQS2xXAQYZFaK+7ccF7wjmBQMmLfG7IopwgbpOYsJF4iQrtWakM16/pks6+/+ /98zuqcSJdKMJipgJGI7fnnS5OgR1PYqLX2UZ/OD/mMQlHHl4+aR5eSCU5m6/Tf5kR1Xgn LjSfDoCujJ47k1WyAJgpJykBrgBKQRU= 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-434-mlXMGZtnM8ijtuYFgUI6Jw-1; Wed, 13 Dec 2023 08:51:16 -0500 X-MC-Unique: mlXMGZtnM8ijtuYFgUI6Jw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 83EFE101CFB6; Wed, 13 Dec 2023 13:51:00 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9F73492BF0; Wed, 13 Dec 2023 13:50:59 +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 Subject: [PATCH v2 34/40] afs: Fix comment in afs_do_lookup() Date: Wed, 13 Dec 2023 13:49:56 +0000 Message-ID: <20231213135003.367397-35-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix the comment in afs_do_lookup() that says that slot 0 is used for the fid being looked up and slot 1 is used for the directory. It's actually done the other way round. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index ecb889a269fb..e232f713ece1 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -807,8 +807,8 @@ static struct inode *afs_do_lookup(struct inode *dir, s= truct dentry *dentry, cookie->fids[i].vid =3D dvnode->fid.vid; cookie->ctx.actor =3D afs_lookup_filldir; cookie->name =3D dentry->d_name; - cookie->nr_fids =3D 2; /* slot 0 is saved for the fid we actually want - * and slot 1 for the directory */ + cookie->nr_fids =3D 2; /* slot 1 is saved for the fid we actually want + * and slot 0 for the directory */ =20 if (!afs_server_supports_ibulk(dvnode)) cookie->one_only =3D true; From nobody Mon Dec 15 21:24:35 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 47D19C4332F for ; Wed, 13 Dec 2023 13:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379317AbjLMNwt (ORCPT ); Wed, 13 Dec 2023 08:52:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235428AbjLMNvp (ORCPT ); Wed, 13 Dec 2023 08:51:45 -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 9B9511B5 for ; Wed, 13 Dec 2023 05:51:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475465; 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=trkSrGHpwGl5JYVXDr68Z3gnjh2gsPsj3d8uQgvQ/lQ=; b=SLMh0n0kfxkoWBB7u0XekSfZXa67+MGwfOfyfOzsJ7bjnRQKwzwrmW2Ht2I7esoZxpz7Rf zv3Te2EP+xS7/JHuOeRgMdd/5HjGH3JggHn8n6s5mTRky1ZcdDfuOlqZed00wGkwfoL6Pi gOxP18IcZFZRGnPhVfOExx0+RM2vp0g= 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-496-nfKa3B1kMgqg5m6UPIpeCA-1; Wed, 13 Dec 2023 08:51:02 -0500 X-MC-Unique: nfKa3B1kMgqg5m6UPIpeCA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 0259A185A784; Wed, 13 Dec 2023 13:51:02 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 309181121306; Wed, 13 Dec 2023 13:51:01 +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 Subject: [PATCH v2 35/40] afs: Don't leave DONTUSE/NEWREPSITE servers out of server list Date: Wed, 13 Dec 2023 13:49:57 +0000 Message-ID: <20231213135003.367397-36-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Don't leave servers that are marked VLSF_DONTUSE or VLSF_NEWREPSITE out of the server list for a volume; rather, mark DONTUSE ones excluded and mark either NEWREPSITE excluded if the number of updated servers is <50% of the usable servers or mark !NEWREPSITE excluded otherwise. Mark the server list as a whole with a 3-state flag to indicate whether we think the RW volume is being replicated to the RO volume, and, if so, whether we should switch to using updated replication sites (VLSF_NEWREPSITE) or stick with the old for now. This processing is pushed up from the VLDB RPC reply parser to the code that generates the server list from that information. Doing this allows the old list to be kept with just the exclusion flags replaced and to keep the server records pinned and maintained. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/internal.h | 10 ++++++++ fs/afs/rotate.c | 4 +++- fs/afs/server_list.c | 54 ++++++++++++++++++++++++++++++++++++-------- fs/afs/vlclient.c | 19 +++------------- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 5ae4ca999d65..3d90415c2527 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -515,6 +515,7 @@ struct afs_vldb_entry { #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on = this server) */ #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on = this server) */ #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available = (on this server) */ + u8 vlsf_flags[AFS_NMAXNSERVERS]; short error; u8 nr_servers; /* Number of server records */ u8 name_len; @@ -601,6 +602,12 @@ struct afs_server { spinlock_t probe_lock; }; =20 +enum afs_ro_replicating { + AFS_RO_NOT_REPLICATING, /* Not doing replication */ + AFS_RO_REPLICATING_USE_OLD, /* Replicating; use old version */ + AFS_RO_REPLICATING_USE_NEW, /* Replicating; switch to new version */ +} __mode(byte); + /* * Replaceable volume server list. */ @@ -608,12 +615,15 @@ struct afs_server_entry { struct afs_server *server; struct afs_volume *volume; struct list_head slink; /* Link in server->volumes */ + unsigned long flags; +#define AFS_SE_EXCLUDED 0 /* Set if server is to be excluded in rotation= */ }; =20 struct afs_server_list { struct rcu_head rcu; refcount_t usage; bool attached; /* T if attached to servers */ + enum afs_ro_replicating ro_replicating; /* RW->RO update (probably) in pr= ogress */ unsigned char nr_servers; unsigned char preferred; /* Preferred server */ unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */ diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index e8635f60b97d..3ab85a907a1d 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -448,9 +448,11 @@ bool afs_select_fileserver(struct afs_operation *op) op->server_index =3D -1; rtt =3D UINT_MAX; for (i =3D 0; i < op->server_list->nr_servers; i++) { - struct afs_server *s =3D op->server_list->servers[i].server; + struct afs_server_entry *se =3D &op->server_list->servers[i]; + struct afs_server *s =3D se->server; =20 if (!test_bit(i, &op->untried_servers) || + test_bit(AFS_SE_EXCLUDED, &se->flags) || !test_bit(AFS_SERVER_FL_RESPONDING, &s->flags)) continue; if (s->rtt <=3D rtt) { diff --git a/fs/afs/server_list.c b/fs/afs/server_list.c index cfd900eb09ed..fb0f4afcb304 100644 --- a/fs/afs/server_list.c +++ b/fs/afs/server_list.c @@ -31,23 +31,53 @@ struct afs_server_list *afs_alloc_server_list(struct af= s_volume *volume, struct afs_server_list *slist; struct afs_server *server; unsigned int type_mask =3D 1 << volume->type; - int ret =3D -ENOMEM, nr_servers =3D 0, i, j; - - for (i =3D 0; i < vldb->nr_servers; i++) - if (vldb->fs_mask[i] & type_mask) - nr_servers++; + bool use_newrepsites =3D false; + int ret =3D -ENOMEM, nr_servers =3D 0, newrep =3D 0, i, j, usable =3D 0; + + /* Work out if we're going to restrict to NEWREPSITE-marked servers or + * not. If at least one site is marked as NEWREPSITE, then it's likely + * that "vos release" is busy updating RO sites. We cut over from one + * to the other when >=3D50% of the sites have been updated. Sites that + * are in the process of being updated are marked DONTUSE. + */ + for (i =3D 0; i < vldb->nr_servers; i++) { + if (!(vldb->fs_mask[i] & type_mask)) + continue; + nr_servers++; + if (vldb->vlsf_flags[i] & AFS_VLSF_DONTUSE) + continue; + usable++; + if (vldb->vlsf_flags[i] & AFS_VLSF_NEWREPSITE) + newrep++; + } =20 slist =3D kzalloc(struct_size(slist, servers, nr_servers), GFP_KERNEL); if (!slist) goto error; =20 + if (newrep) { + if (newrep < usable / 2) { + slist->ro_replicating =3D AFS_RO_REPLICATING_USE_OLD; + } else { + slist->ro_replicating =3D AFS_RO_REPLICATING_USE_NEW; + use_newrepsites =3D true; + } + } + refcount_set(&slist->usage, 1); rwlock_init(&slist->lock); =20 /* Make sure a records exists for each server in the list. */ for (i =3D 0; i < vldb->nr_servers; i++) { + unsigned long se_flags =3D 0; + bool newrepsite =3D vldb->vlsf_flags[i] & AFS_VLSF_NEWREPSITE; + if (!(vldb->fs_mask[i] & type_mask)) continue; + if (vldb->vlsf_flags[i] & AFS_VLSF_DONTUSE) + __set_bit(AFS_SE_EXCLUDED, &se_flags); + if (newrep && (newrepsite ^ use_newrepsites)) + __set_bit(AFS_SE_EXCLUDED, &se_flags); =20 server =3D afs_lookup_server(volume->cell, key, &vldb->fs_server[i], vldb->addr_version[i]); @@ -79,6 +109,7 @@ struct afs_server_list *afs_alloc_server_list(struct afs= _volume *volume, =20 slist->servers[j].server =3D server; slist->servers[j].volume =3D volume; + slist->servers[j].flags =3D se_flags; slist->nr_servers++; } =20 @@ -101,16 +132,20 @@ struct afs_server_list *afs_alloc_server_list(struct = afs_volume *volume, bool afs_annotate_server_list(struct afs_server_list *new, struct afs_server_list *old) { + unsigned long mask =3D 1UL << AFS_SE_EXCLUDED; struct afs_server *cur; int i, j; =20 - if (old->nr_servers !=3D new->nr_servers) + if (old->nr_servers !=3D new->nr_servers || + old->ro_replicating !=3D new->ro_replicating) goto changed; =20 - for (i =3D 0; i < old->nr_servers; i++) + for (i =3D 0; i < old->nr_servers; i++) { if (old->servers[i].server !=3D new->servers[i].server) goto changed; - + if ((old->servers[i].flags & mask) !=3D (new->servers[i].flags & mask)) + goto changed; + } return false; =20 changed: @@ -118,7 +153,8 @@ bool afs_annotate_server_list(struct afs_server_list *n= ew, cur =3D old->servers[old->preferred].server; for (j =3D 0; j < new->nr_servers; j++) { if (new->servers[j].server =3D=3D cur) { - new->preferred =3D j; + if (!test_bit(AFS_SE_EXCLUDED, &new->servers[j].flags)) + new->preferred =3D j; break; } } diff --git a/fs/afs/vlclient.c b/fs/afs/vlclient.c index cef02a265edc..cac75f89b64a 100644 --- a/fs/afs/vlclient.c +++ b/fs/afs/vlclient.c @@ -18,8 +18,7 @@ static int afs_deliver_vl_get_entry_by_name_u(struct afs_= call *call) { struct afs_uvldbentry__xdr *uvldb; struct afs_vldb_entry *entry; - bool new_only =3D false; - u32 tmp, nr_servers, vlflags; + u32 nr_servers, vlflags; int i, ret; =20 _enter(""); @@ -41,27 +40,14 @@ static int afs_deliver_vl_get_entry_by_name_u(struct af= s_call *call) entry->name[i] =3D 0; entry->name_len =3D strlen(entry->name); =20 - /* If there is a new replication site that we can use, ignore all the - * sites that aren't marked as new. - */ - for (i =3D 0; i < nr_servers; i++) { - tmp =3D ntohl(uvldb->serverFlags[i]); - if (!(tmp & AFS_VLSF_DONTUSE) && - (tmp & AFS_VLSF_NEWREPSITE)) - new_only =3D true; - } - vlflags =3D ntohl(uvldb->flags); for (i =3D 0; i < nr_servers; i++) { struct afs_uuid__xdr *xdr; struct afs_uuid *uuid; + u32 tmp =3D ntohl(uvldb->serverFlags[i]); int j; int n =3D entry->nr_servers; =20 - tmp =3D ntohl(uvldb->serverFlags[i]); - if (tmp & AFS_VLSF_DONTUSE || - (new_only && !(tmp & AFS_VLSF_NEWREPSITE))) - continue; if (tmp & AFS_VLSF_RWVOL) { entry->fs_mask[n] |=3D AFS_VOL_VTM_RW; if (vlflags & AFS_VLF_BACKEXISTS) @@ -82,6 +68,7 @@ static int afs_deliver_vl_get_entry_by_name_u(struct afs_= call *call) for (j =3D 0; j < 6; j++) uuid->node[j] =3D (u8)ntohl(xdr->node[j]); =20 + entry->vlsf_flags[n] =3D tmp; entry->addr_version[n] =3D ntohl(uvldb->serverUnique[i]); entry->nr_servers++; } From nobody Mon Dec 15 21:24:35 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 998FCC4332F for ; Wed, 13 Dec 2023 13:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441794AbjLMNw5 (ORCPT ); Wed, 13 Dec 2023 08:52:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379334AbjLMNwH (ORCPT ); Wed, 13 Dec 2023 08:52:07 -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 A5ED61711 for ; Wed, 13 Dec 2023 05:51:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475469; 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=6YTTsK/AJL0ANW0loPNDoe7NHrb8y0i3Fu3adda/S2U=; b=OomN+/7m51JTtRpv11cA/ffto9tE955X3xoAVdzFyrNkeeXV7mrU+7K81D9eEUYyXseWCe D2EuRdn4dnfuMB0eDmvtRMJWQV8UuOFyEFGR7034M6kCYokOCwSgvhSvvi8KOQg8gY8hWP i9DQFPVKGD2QF8W88/m3sXu//RtIsNs= 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-665-81LEWHC9Ow234AAFtNmmlA-1; Wed, 13 Dec 2023 08:51:04 -0500 X-MC-Unique: 81LEWHC9Ow234AAFtNmmlA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 A26D83869143; Wed, 13 Dec 2023 13:51:03 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB51540C6EB9; Wed, 13 Dec 2023 13:51:02 +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 Subject: [PATCH v2 36/40] afs: Parse the VolSync record in the reply of a number of RPC ops Date: Wed, 13 Dec 2023 13:49:58 +0000 Message-ID: <20231213135003.367397-37-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A number of fileserver RPC operations return a VolSync record as part of their reply that gives some information about the state of the volume being accessed, including: (1) A volume Creation timestamp. For an RW volume, this is the time at which the volume was created; if it changes, the RW volume was presumably restored from a backup and all cached data should be scrubbed as Data Version numbers could regress on the files in the volume. For an RO volume, this is the time it was last snapshotted from the RW volume. It is expected to advance each time this happens; if it regresses, cached data should be scrubbed. (2) A volume Update timestamp (Auristor only). For an RW volume, this is updated any time any change is made to a volume or its contents. If it regresses, all cached data must be scrubbed. For an RO volume, this is a copy of the RW volume's Update timestamp at the point of snapshotting. It can be used as a version number when checking to see if a callback on a RO volume was due to a snapshot. If it regresses, all cached data must be scrubbed. but this is currently not made use of by the in-kernel afs filesystem. Make the afs filesystem use this by: (1) Add an update time field to the afs_volsync struct and use a value of TIME64_MIN in both that and the creation time to indicate that they are unset. (2) Add creation and update time fields to the afs_volume struct and use this to track the two timestamps. (3) Add a volsync_lock mutex to the afs_volume struct to control modification access for when we detect a change in these values. (3) Add a 'pre-op volsync' struct to the afs_operation struct to record the state of the volume tracking before the op. (4) Add a new counter, cb_scrub, to the afs_volume struct to count events that require all data to be scrubbed. A copy is placed in the afs_vnode struct (inode) and if they no longer match, a scrub takes place. (5) When the result of an operation is being parsed, parse the VolSync data too, if it is provided. Note that the two timestamps are handled separately, since they don't work in quite the same way. - If the afs_volume tracking is unset, just set it and do nothing else. - If the result timestamps are the same as the ones in afs_volume, do nothing. - If the timestamps regress, increment cb_scrub if not already done so. - If the creation timestamp on a RW volume changes, increment cb_scrub if not already done so. - If the creation timestamp on a RO volume advances, update the server list and see if the current server has been excluded, if so reissue the op. Once over half of the replication sites have been updated, increment cb_ro_snapshot to indicate updates may be required and switch over to excluding unupdated replication sites. - If the creation timestamp on a Backup volume advances, just increment cb_ro_snapshot to trigger updates. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/afs.h | 3 +- fs/afs/callback.c | 7 +- fs/afs/fs_operation.c | 14 +-- fs/afs/fsclient.c | 5 +- fs/afs/inode.c | 2 +- fs/afs/internal.h | 16 ++- fs/afs/rotate.c | 4 +- fs/afs/validation.c | 199 ++++++++++++++++++++++++++++++++++++- fs/afs/volume.c | 3 + fs/afs/yfsclient.c | 5 +- include/trace/events/afs.h | 30 +++++- 11 files changed, 268 insertions(+), 20 deletions(-) diff --git a/fs/afs/afs.h b/fs/afs/afs.h index 81815724db6c..b488072aee87 100644 --- a/fs/afs/afs.h +++ b/fs/afs/afs.h @@ -165,7 +165,8 @@ struct afs_status_cb { * AFS volume synchronisation information */ struct afs_volsync { - time64_t creation; /* volume creation time */ + time64_t creation; /* Volume creation time (or TIME64_MIN) */ + time64_t update; /* Volume update time (or TIME64_MIN) */ }; =20 /* diff --git a/fs/afs/callback.c b/fs/afs/callback.c index f67e88076761..8ddc99c9c16b 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c @@ -81,7 +81,7 @@ void __afs_break_callback(struct afs_vnode *vnode, enum a= fs_cb_break_reason reas clear_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags); if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { vnode->cb_break++; - vnode->cb_v_break =3D vnode->volume->cb_v_break; + vnode->cb_v_break =3D atomic_read(&vnode->volume->cb_v_break); afs_clear_permits(vnode); =20 if (vnode->lock_state =3D=3D AFS_VNODE_LOCK_WAITING_FOR_CB) @@ -159,12 +159,13 @@ static void afs_break_one_callback(struct afs_volume = *volume, struct super_block *sb; struct afs_vnode *vnode; struct inode *inode; + unsigned int cb_v_break; =20 if (fid->vnode =3D=3D 0 && fid->unique =3D=3D 0) { /* The callback break applies to an entire volume. */ write_lock(&volume->cb_v_break_lock); - volume->cb_v_break++; - trace_afs_cb_break(fid, volume->cb_v_break, + cb_v_break =3D atomic_inc_return(&volume->cb_v_break); + trace_afs_cb_break(fid, cb_v_break, afs_cb_break_for_volume_callback, false); write_unlock(&volume->cb_v_break_lock); return; diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 10137681aa7d..99d1e649e929 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -35,11 +35,13 @@ struct afs_operation *afs_alloc_operation(struct key *k= ey, struct afs_volume *vo key_get(key); } =20 - op->key =3D key; - op->volume =3D afs_get_volume(volume, afs_volume_trace_get_new_op); - op->net =3D volume->cell->net; - op->cb_v_break =3D volume->cb_v_break; - op->debug_id =3D atomic_inc_return(&afs_operation_debug_counter); + op->key =3D key; + op->volume =3D afs_get_volume(volume, afs_volume_trace_get_new_op); + op->net =3D volume->cell->net; + op->cb_v_break =3D atomic_read(&volume->cb_v_break); + op->pre_volsync.creation =3D volume->creation_time; + op->pre_volsync.update =3D volume->update_time; + op->debug_id =3D atomic_inc_return(&afs_operation_debug_counter); op->nr_iterations =3D -1; afs_op_set_error(op, -EDESTADDRREQ); =20 @@ -147,7 +149,7 @@ bool afs_begin_vnode_operation(struct afs_operation *op) =20 afs_prepare_vnode(op, &op->file[0], 0); afs_prepare_vnode(op, &op->file[1], 1); - op->cb_v_break =3D op->volume->cb_v_break; + op->cb_v_break =3D atomic_read(&op->volume->cb_v_break); _leave(" =3D true"); return true; } diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index f1f879ba9cf7..80f7d9e796e3 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -1870,7 +1870,10 @@ static int afs_deliver_fs_inline_bulk_status(struct = afs_call *call) return ret; =20 bp =3D call->buffer; - xdr_decode_AFSVolSync(&bp, &op->volsync); + /* Unfortunately, prior to OpenAFS-1.6, volsync here is filled + * with rubbish. + */ + xdr_decode_AFSVolSync(&bp, NULL); =20 call->unmarshall++; fallthrough; diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 102e7c37d33c..df3d37577b5b 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -542,7 +542,7 @@ struct inode *afs_root_iget(struct super_block *sb, str= uct key *key) BUG_ON(!(inode->i_state & I_NEW)); =20 vnode =3D AFS_FS_I(inode); - vnode->cb_v_break =3D as->volume->cb_v_break, + vnode->cb_v_break =3D atomic_read(&as->volume->cb_v_break), afs_set_netfs_context(vnode); =20 op =3D afs_alloc_operation(key, as->volume); diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 3d90415c2527..4b730cbcf63e 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -662,7 +662,15 @@ struct afs_volume { rwlock_t servers_lock; /* Lock for ->servers */ unsigned int servers_seq; /* Incremented each time ->servers changes */ =20 - unsigned cb_v_break; /* Break-everything counter. */ + /* RO release tracking */ + struct mutex volsync_lock; /* Time/state evaluation lock */ + time64_t creation_time; /* Volume creation time (or TIME64_MIN) */ + time64_t update_time; /* Volume update time (or TIME64_MIN) */ + + /* Callback management */ + atomic_t cb_ro_snapshot; /* RO volume update-from-snapshot counter */ + atomic_t cb_v_break; /* Volume-break event counter. */ + atomic_t cb_scrub; /* Scrub-all-data event counter. */ rwlock_t cb_v_break_lock; =20 afs_voltype_t type; /* type of volume */ @@ -856,7 +864,8 @@ struct afs_operation { struct afs_volume *volume; /* Volume being accessed */ struct afs_vnode_param file[2]; struct afs_vnode_param *more_files; - struct afs_volsync volsync; + struct afs_volsync pre_volsync; /* Volsync before op */ + struct afs_volsync volsync; /* Volsync returned by op */ struct dentry *dentry; /* Dentry to be altered */ struct dentry *dentry_2; /* Second dentry to be altered */ struct timespec64 mtime; /* Modification time to record */ @@ -1063,7 +1072,7 @@ static inline unsigned int afs_calc_vnode_cb_break(st= ruct afs_vnode *vnode) static inline bool afs_cb_is_broken(unsigned int cb_break, const struct afs_vnode *vnode) { - return cb_break !=3D (vnode->cb_break + vnode->volume->cb_v_break); + return cb_break !=3D (vnode->cb_break + atomic_read(&vnode->volume->cb_v_= break)); } =20 /* @@ -1555,6 +1564,7 @@ extern void afs_fs_exit(void); /* * validation.c */ +int afs_update_volume_state(struct afs_operation *op); bool afs_check_validity(struct afs_vnode *vnode); bool afs_pagecache_valid(struct afs_vnode *vnode); int afs_validate(struct afs_vnode *vnode, struct key *key); diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 3ab85a907a1d..5c50c9aa1f87 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -486,7 +486,7 @@ bool afs_select_fileserver(struct afs_operation *op) vnode->cb_server =3D server; vnode->cb_s_break =3D server->cb_s_break; vnode->cb_fs_s_break =3D atomic_read(&server->cell->fs_s_break); - vnode->cb_v_break =3D vnode->volume->cb_v_break; + vnode->cb_v_break =3D atomic_read(&vnode->volume->cb_v_break); clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); } =20 @@ -519,6 +519,8 @@ bool afs_select_fileserver(struct afs_operation *op) op->addr_index =3D addr_index; set_bit(addr_index, &op->addr_tried); =20 + op->volsync.creation =3D TIME64_MIN; + op->volsync.update =3D TIME64_MIN; op->call_responded =3D false; _debug("address [%u] %u/%u %pISp", op->server_index, addr_index, alist->nr_addrs, diff --git a/fs/afs/validation.c b/fs/afs/validation.c index 18ba2c5e8ead..6aadd5e075e4 100644 --- a/fs/afs/validation.c +++ b/fs/afs/validation.c @@ -10,6 +10,201 @@ #include #include "internal.h" =20 +/* + * See if the server we've just talked to is currently excluded. + */ +static bool __afs_is_server_excluded(struct afs_operation *op, struct afs_= volume *volume) +{ + const struct afs_server_entry *se; + const struct afs_server_list *slist; + bool is_excluded =3D true; + int i; + + rcu_read_lock(); + + slist =3D rcu_dereference(volume->servers); + for (i =3D 0; i < slist->nr_servers; i++) { + se =3D &slist->servers[i]; + if (op->server =3D=3D se->server) { + is_excluded =3D test_bit(AFS_SE_EXCLUDED, &se->flags); + break; + } + } + + rcu_read_unlock(); + return is_excluded; +} + +/* + * Update the volume's server list when the creation time changes and see = if + * the server we've just talked to is currently excluded. + */ +static int afs_is_server_excluded(struct afs_operation *op, struct afs_vol= ume *volume) +{ + int ret; + + if (__afs_is_server_excluded(op, volume)) + return 1; + + set_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags); + ret =3D afs_check_volume_status(op->volume, op); + if (ret < 0) + return ret; + + return __afs_is_server_excluded(op, volume); +} + +/* + * Handle a change to the volume creation time in the VolSync record. + */ +static int afs_update_volume_creation_time(struct afs_operation *op, struc= t afs_volume *volume) +{ + unsigned int snap; + time64_t cur =3D volume->creation_time; + time64_t old =3D op->pre_volsync.creation; + time64_t new =3D op->volsync.creation; + int ret; + + _enter("%llx,%llx,%llx->%llx", volume->vid, cur, old, new); + + if (cur =3D=3D TIME64_MIN) { + volume->creation_time =3D new; + return 0; + } + + if (new =3D=3D cur) + return 0; + + /* Try to advance the creation timestamp from what we had before the + * operation to what we got back from the server. This should + * hopefully ensure that in a race between multiple operations only one + * of them will do this. + */ + if (cur !=3D old) + return 0; + + /* If the creation time changes in an unexpected way, we need to scrub + * our caches. For a RW vol, this will only change if the volume is + * restored from a backup; for a RO/Backup vol, this will advance when + * the volume is updated to a new snapshot (eg. "vos release"). + */ + if (volume->type =3D=3D AFSVL_RWVOL) + goto regressed; + if (volume->type =3D=3D AFSVL_BACKVOL) { + if (new < old) + goto regressed; + goto advance; + } + + /* We have an RO volume, we need to query the VL server and look at the + * server flags to see if RW->RO replication is in progress. + */ + ret =3D afs_is_server_excluded(op, volume); + if (ret < 0) + return ret; + if (ret > 0) { + snap =3D atomic_read(&volume->cb_ro_snapshot); + trace_afs_cb_v_break(volume->vid, snap, afs_cb_break_volume_excluded); + return ret; + } + +advance: + snap =3D atomic_inc_return(&volume->cb_ro_snapshot); + trace_afs_cb_v_break(volume->vid, snap, afs_cb_break_for_vos_release); + volume->creation_time =3D new; + return 0; + +regressed: + atomic_inc(&volume->cb_scrub); + trace_afs_cb_v_break(volume->vid, 0, afs_cb_break_for_creation_regress); + volume->creation_time =3D new; + return 0; +} + +/* + * Handle a change to the volume update time in the VolSync record. + */ +static void afs_update_volume_update_time(struct afs_operation *op, struct= afs_volume *volume) +{ + enum afs_cb_break_reason reason =3D afs_cb_break_no_break; + time64_t cur =3D volume->update_time; + time64_t old =3D op->pre_volsync.update; + time64_t new =3D op->volsync.update; + + _enter("%llx,%llx,%llx->%llx", volume->vid, cur, old, new); + + if (cur =3D=3D TIME64_MIN) { + volume->update_time =3D new; + return; + } + + if (new =3D=3D cur) + return; + + /* If the volume update time changes in an unexpected way, we need to + * scrub our caches. For a RW vol, this will advance on every + * modification op; for a RO/Backup vol, this will advance when the + * volume is updated to a new snapshot (eg. "vos release"). + */ + if (new < old) + reason =3D afs_cb_break_for_update_regress; + + /* Try to advance the update timestamp from what we had before the + * operation to what we got back from the server. This should + * hopefully ensure that in a race between multiple operations only one + * of them will do this. + */ + if (cur =3D=3D old) { + if (reason =3D=3D afs_cb_break_for_update_regress) { + atomic_inc(&volume->cb_scrub); + trace_afs_cb_v_break(volume->vid, 0, reason); + } + volume->update_time =3D new; + } +} + +static int afs_update_volume_times(struct afs_operation *op, struct afs_vo= lume *volume) +{ + int ret =3D 0; + + if (likely(op->volsync.creation =3D=3D volume->creation_time && + op->volsync.update =3D=3D volume->update_time)) + return 0; + + mutex_lock(&volume->volsync_lock); + if (op->volsync.creation !=3D volume->creation_time) { + ret =3D afs_update_volume_creation_time(op, volume); + if (ret < 0) + goto out; + } + if (op->volsync.update !=3D volume->update_time) + afs_update_volume_update_time(op, volume); +out: + mutex_unlock(&volume->volsync_lock); + return ret; +} + +/* + * Update the state of a volume. Returns 1 to redo the operation from the= start. + */ +int afs_update_volume_state(struct afs_operation *op) +{ + struct afs_volume *volume =3D op->volume; + int ret; + + _enter("%llx", op->volume->vid); + + if (op->volsync.creation !=3D TIME64_MIN || op->volsync.update !=3D TIME6= 4_MIN) { + ret =3D afs_update_volume_times(op, volume); + if (ret !=3D 0) { + _leave(" =3D %d", ret); + return ret; + } + } + + return 0; +} + /* * mark the data attached to an inode as obsolete due to a write on the se= rver * - might also want to ditch all the outstanding writes and dirty pages @@ -74,7 +269,7 @@ bool afs_check_validity(struct afs_vnode *vnode) cb_break =3D vnode->cb_break; =20 if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { - if (vnode->cb_v_break !=3D vnode->volume->cb_v_break) + if (vnode->cb_v_break !=3D atomic_read(&vnode->volume->cb_v_break)) need_clear =3D afs_cb_break_for_v_break; else if (!afs_check_server_good(vnode)) need_clear =3D afs_cb_break_for_s_reinit; @@ -95,7 +290,7 @@ bool afs_check_validity(struct afs_vnode *vnode) =20 write_seqlock(&vnode->cb_lock); if (need_clear =3D=3D afs_cb_break_no_promise) - vnode->cb_v_break =3D vnode->volume->cb_v_break; + vnode->cb_v_break =3D atomic_read(&vnode->volume->cb_v_break); else if (cb_break =3D=3D vnode->cb_break) __afs_break_callback(vnode, need_clear); else diff --git a/fs/afs/volume.c b/fs/afs/volume.c index 4982fce25057..41ab1d3ff3ea 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -90,11 +90,14 @@ static struct afs_volume *afs_alloc_volume(struct afs_f= s_context *params, volume->type =3D params->type; volume->type_force =3D params->force; volume->name_len =3D vldb->name_len; + volume->creation_time =3D TIME64_MIN; + volume->update_time =3D TIME64_MIN; =20 refcount_set(&volume->ref, 1); INIT_HLIST_NODE(&volume->proc_link); INIT_WORK(&volume->destructor, afs_destroy_volume); rwlock_init(&volume->servers_lock); + mutex_init(&volume->volsync_lock); rwlock_init(&volume->cb_v_break_lock); memcpy(volume->name, vldb->name, vldb->name_len + 1); =20 diff --git a/fs/afs/yfsclient.c b/fs/afs/yfsclient.c index 11571cca86c1..2d6943f05ea5 100644 --- a/fs/afs/yfsclient.c +++ b/fs/afs/yfsclient.c @@ -245,12 +245,15 @@ static void xdr_decode_YFSVolSync(const __be32 **_bp, struct afs_volsync *volsync) { struct yfs_xdr_YFSVolSync *x =3D (void *)*_bp; - u64 creation; + u64 creation, update; =20 if (volsync) { creation =3D xdr_to_u64(x->vol_creation_date); do_div(creation, 10 * 1000 * 1000); volsync->creation =3D creation; + update =3D xdr_to_u64(x->vol_update_date); + do_div(update, 10 * 1000 * 1000); + volsync->update =3D update; } =20 *_bp +=3D xdr_size(x); diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index 63ab23876be8..bbe8dcab4b32 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -440,13 +440,17 @@ enum yfs_cm_operation { EM(afs_cb_break_no_break, "no-break") \ EM(afs_cb_break_no_promise, "no-promise") \ EM(afs_cb_break_for_callback, "break-cb") \ + EM(afs_cb_break_for_creation_regress, "creation-regress") \ EM(afs_cb_break_for_deleted, "break-del") \ EM(afs_cb_break_for_lapsed, "break-lapsed") \ EM(afs_cb_break_for_s_reinit, "s-reinit") \ EM(afs_cb_break_for_unlink, "break-unlink") \ + EM(afs_cb_break_for_update_regress, "update-regress") \ EM(afs_cb_break_for_v_break, "break-v") \ EM(afs_cb_break_for_volume_callback, "break-v-cb") \ - E_(afs_cb_break_for_zap, "break-zap") + EM(afs_cb_break_for_vos_release, "break-vos-release") \ + EM(afs_cb_break_for_zap, "break-zap") \ + E_(afs_cb_break_volume_excluded, "vol-excluded") =20 /* * Generate enums for tracing information. @@ -1249,6 +1253,30 @@ TRACE_EVENT(afs_get_tree, __entry->cell, __entry->volume, __entry->vid) ); =20 +TRACE_EVENT(afs_cb_v_break, + TP_PROTO(afs_volid_t vid, unsigned int cb_v_break, + enum afs_cb_break_reason reason), + + TP_ARGS(vid, cb_v_break, reason), + + TP_STRUCT__entry( + __field(afs_volid_t, vid) + __field(unsigned int, cb_v_break) + __field(enum afs_cb_break_reason, reason) + ), + + TP_fast_assign( + __entry->vid =3D vid; + __entry->cb_v_break =3D cb_v_break; + __entry->reason =3D reason; + ), + + TP_printk("%llx vb=3D%x %s", + __entry->vid, + __entry->cb_v_break, + __print_symbolic(__entry->reason, afs_cb_break_reasons)) + ); + TRACE_EVENT(afs_cb_break, TP_PROTO(struct afs_fid *fid, unsigned int cb_break, enum afs_cb_break_reason reason, bool skipped), From nobody Mon Dec 15 21:24:35 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 62443C4167B for ; Wed, 13 Dec 2023 13:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235401AbjLMNxU (ORCPT ); Wed, 13 Dec 2023 08:53:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379307AbjLMNwV (ORCPT ); Wed, 13 Dec 2023 08:52:21 -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 5C9A7D57 for ; Wed, 13 Dec 2023 05:51:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475471; 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=YdbrznxoeP8yIf0wk1cWrsrMGzm+B2XkO70g6tFDSn8=; b=Ec6aGskABWcToMoHnWfDgj+kR027i/+1ffHn3QAX101nwXwZ0G+Geiliwc2aAr+GHsdTpG UUGI0nQzCOxr8LaVMkpcQRMgYlv0lITNjwUOBVxLPvuaQknNKgi+qZq3UHHIQLxC3Wy/lY iU6Vb22A5tKBxFBPzYP2TliCkTrZaxk= 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-679-EHPgFXP_NImH-2qPIgsFgw-1; Wed, 13 Dec 2023 08:51:05 -0500 X-MC-Unique: EHPgFXP_NImH-2qPIgsFgw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 77ACB3C2A1CD; Wed, 13 Dec 2023 13:51:05 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5483CC15968; Wed, 13 Dec 2023 13:51:04 +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 Subject: [PATCH v2 37/40] afs: Overhaul invalidation handling to better support RO volumes Date: Wed, 13 Dec 2023 13:49:59 +0000 Message-ID: <20231213135003.367397-38-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Overhaul the third party-induced invalidation handling, making use of the previously added volume-level event counters (cb_scrub and cb_ro_snapshot) that are now being parsed out of the VolSync record returned by the fileserver in many of its replies. This allows better handling of RO (and Backup) volumes. Since these are snapshot of a RW volume that are updated atomically simultantanously across all servers that host them, they only require a single callback promise for the entire volume. The currently upstream code assumes that RO volumes operate in the same manner as RW volumes, and that each file has its own individual callback - which means that it does a status fetch for *every* file in a RO volume, whether or not the volume got "released" (volume callback breaks can occur for other reasons too, such as the volumeserver taking ownership of a volume from a fileserver). To this end, make the following changes: (1) Change the meaning of the volume's cb_v_break counter so that it is now a hint that we need to issue a status fetch to work out the state of a volume. cb_v_break is incremented by volume break callbacks and by server initialisation callbacks. (2) Add a second counter, cb_v_check, to the afs_volume struct such that if this differs from cb_v_break, we need to do a check. When the check is complete, cb_v_check is advanced to what cb_v_break was at the start of the status fetch. (3) Move the list of mmap'd vnodes to the volume and trigger removal of PTEs that map to files on a volume break rather than on a server break. (4) When a server reinitialisation callback comes in, use the server-to-volume reverse mapping added in a preceding patch to iterate over all the volumes using that server and clear the volume callback promises for that server and the general volume promise as a whole to trigger reanalysis. (5) Replace the AFS_VNODE_CB_PROMISED flag with an AFS_NO_CB_PROMISE (TIME64_MIN) value in the cb_expires_at field, reducing the number of checks we need to make. (6) Change afs_check_validity() to quickly see if various event counters have been incremented or if the vnode or volume callback promise is due to expire/has expired without making any changes to the state. That is now left to afs_validate() as this may get more complicated in future as we may have to examine server records too. (7) Overhaul afs_validate() so that it does a single status fetch if we need to check the state of either the vnode or the volume - and do so under appropriate locking. The function does the following steps: (A) If the vnode/volume is no longer seen as valid, then we take the vnode validation lock and, if the volume promise has expired, the volume check lock also. The latter prevents redundant checks being made to find out if a new version of the volume got released. (B) If a previous RPC call found that the volsync changed unexpectedly or that a RO volume was updated, then we unmap all PTEs pointing to the file to stop mmap being used for access. (C) If the vnode is still seen to be of uncertain validity, then we perform an FS.FetchStatus RPC op to jointly update the volume status and the vnode status. This assessment is done as part of parsing the reply: If the RO volume creation timestamp advances, cb_ro_snapshot is incremented; if either the creation or update timestamps changes in an unexpected way, the cb_scrub counter is incremented If the Data Version returned doesn't match the copy we have locally, then we ask for the pagecache to be zapped. This takes care of handling RO update. (D) If cb_scrub differs between volume and vnode, the vnode's pagecache is zapped and the vnode's cb_scrub is updated unless the file is marked as having been deleted. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/callback.c | 122 +++++++++------ fs/afs/cell.c | 2 - fs/afs/dir.c | 3 +- fs/afs/file.c | 13 +- fs/afs/fs_operation.c | 3 +- fs/afs/inode.c | 21 ++- fs/afs/internal.h | 34 ++--- fs/afs/proc.c | 4 +- fs/afs/rotate.c | 8 +- fs/afs/server_list.c | 2 + fs/afs/validation.c | 299 ++++++++++++++++++++++++------------- fs/afs/volume.c | 3 + include/trace/events/afs.h | 4 - 13 files changed, 316 insertions(+), 202 deletions(-) diff --git a/fs/afs/callback.c b/fs/afs/callback.c index 8ddc99c9c16b..99b2c8172021 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c @@ -33,21 +33,20 @@ void afs_invalidate_mmap_work(struct work_struct *work) unmap_mapping_pages(vnode->netfs.inode.i_mapping, 0, 0, false); } =20 -static void afs_server_init_callback(struct afs_server *server) +static void afs_volume_init_callback(struct afs_volume *volume) { struct afs_vnode *vnode; - struct afs_cell *cell =3D server->cell; =20 - down_read(&cell->fs_open_mmaps_lock); + down_read(&volume->open_mmaps_lock); =20 - list_for_each_entry(vnode, &cell->fs_open_mmaps, cb_mmap_link) { - if (vnode->cb_server =3D=3D server) { - clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); + list_for_each_entry(vnode, &volume->open_mmaps, cb_mmap_link) { + if (vnode->cb_v_check !=3D atomic_read(&volume->cb_v_break)) { + atomic64_set(&vnode->cb_expires_at, AFS_NO_CB_PROMISE); queue_work(system_unbound_wq, &vnode->cb_work); } } =20 - up_read(&cell->fs_open_mmaps_lock); + up_read(&volume->open_mmaps_lock); } =20 /* @@ -56,19 +55,20 @@ static void afs_server_init_callback(struct afs_server = *server) */ void afs_init_callback_state(struct afs_server *server) { - struct afs_cell *cell =3D server->cell; + struct afs_server_entry *se; =20 - down_read(&cell->vs_lock); + down_read(&server->cell->vs_lock); =20 - do { - server->cb_s_break++; - atomic_inc(&server->cell->fs_s_break); - if (!list_empty(&server->cell->fs_open_mmaps)) - afs_server_init_callback(server); - - } while ((server =3D rcu_dereference(server->uuid_next))); + list_for_each_entry(se, &server->volumes, slink) { + se->cb_expires_at =3D AFS_NO_CB_PROMISE; + se->volume->cb_expires_at =3D AFS_NO_CB_PROMISE; + trace_afs_cb_v_break(se->volume->vid, atomic_read(&se->volume->cb_v_brea= k), + afs_cb_break_for_s_reinit); + if (!list_empty(&se->volume->open_mmaps)) + afs_volume_init_callback(se->volume); + } =20 - up_read(&cell->vs_lock); + up_read(&server->cell->vs_lock); } =20 /* @@ -79,9 +79,9 @@ void __afs_break_callback(struct afs_vnode *vnode, enum a= fs_cb_break_reason reas _enter(""); =20 clear_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags); - if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { + if (atomic64_xchg(&vnode->cb_expires_at, AFS_NO_CB_PROMISE) !=3D AFS_NO_C= B_PROMISE) { vnode->cb_break++; - vnode->cb_v_break =3D atomic_read(&vnode->volume->cb_v_break); + vnode->cb_v_check =3D atomic_read(&vnode->volume->cb_v_break); afs_clear_permits(vnode); =20 if (vnode->lock_state =3D=3D AFS_VNODE_LOCK_WAITING_FOR_CB) @@ -147,29 +147,51 @@ static struct afs_volume *afs_lookup_volume_rcu(struc= t afs_cell *cell, return volume; } =20 +/* + * Allow the fileserver to break callbacks at the volume-level. This is + * typically done when, for example, a R/W volume is snapshotted to a R/O + * volume (the only way to change an R/O volume). It may also, however, h= appen + * when a volserver takes control of a volume (offlining it, moving it, et= c.). + * + * Every file in that volume will need to be reevaluated. + */ +static void afs_break_volume_callback(struct afs_server *server, + struct afs_volume *volume) + __releases(RCU) +{ + struct afs_server_list *slist =3D rcu_dereference(volume->servers); + unsigned int i, cb_v_break; + + write_lock(&volume->cb_v_break_lock); + + for (i =3D 0; i < slist->nr_servers; i++) + if (slist->servers[i].server =3D=3D server) + slist->servers[i].cb_expires_at =3D AFS_NO_CB_PROMISE; + volume->cb_expires_at =3D AFS_NO_CB_PROMISE; + + cb_v_break =3D atomic_inc_return_release(&volume->cb_v_break); + trace_afs_cb_v_break(volume->vid, cb_v_break, afs_cb_break_for_volume_cal= lback); + + write_unlock(&volume->cb_v_break_lock); + rcu_read_unlock(); + + if (!list_empty(&volume->open_mmaps)) + afs_volume_init_callback(volume); +} + /* * allow the fileserver to explicitly break one callback * - happens when * - the backing file is changed * - a lock is released */ -static void afs_break_one_callback(struct afs_volume *volume, +static void afs_break_one_callback(struct afs_server *server, + struct afs_volume *volume, struct afs_fid *fid) { struct super_block *sb; struct afs_vnode *vnode; struct inode *inode; - unsigned int cb_v_break; - - if (fid->vnode =3D=3D 0 && fid->unique =3D=3D 0) { - /* The callback break applies to an entire volume. */ - write_lock(&volume->cb_v_break_lock); - cb_v_break =3D atomic_inc_return(&volume->cb_v_break); - trace_afs_cb_break(fid, cb_v_break, - afs_cb_break_for_volume_callback, false); - write_unlock(&volume->cb_v_break_lock); - return; - } =20 /* See if we can find a matching inode - even an I_NEW inode needs to * be marked as it can have its callback broken before we finish @@ -199,24 +221,32 @@ static void afs_break_some_callbacks(struct afs_serve= r *server, =20 rcu_read_lock(); volume =3D afs_lookup_volume_rcu(server->cell, vid); - /* TODO: Find all matching volumes if we couldn't match the server and - * break them anyway. - */ - for (i =3D *_count; i > 0; cbb++, i--) { - if (cbb->fid.vid =3D=3D vid) { - _debug("- Fid { vl=3D%08llx n=3D%llu u=3D%u }", - cbb->fid.vid, - cbb->fid.vnode, - cbb->fid.unique); - --*_count; - if (volume) - afs_break_one_callback(volume, &cbb->fid); - } else { - *residue++ =3D *cbb; + if (cbb->fid.vnode =3D=3D 0 && cbb->fid.unique =3D=3D 0) { + afs_break_volume_callback(server, volume); + *_count -=3D 1; + if (*_count) + memmove(cbb, cbb + 1, sizeof(*cbb) * *_count); + } else { + /* TODO: Find all matching volumes if we couldn't match the server and + * break them anyway. + */ + + for (i =3D *_count; i > 0; cbb++, i--) { + if (cbb->fid.vid =3D=3D vid) { + _debug("- Fid { vl=3D%08llx n=3D%llu u=3D%u }", + cbb->fid.vid, + cbb->fid.vnode, + cbb->fid.unique); + --*_count; + if (volume) + afs_break_one_callback(server, volume, &cbb->fid); + } else { + *residue++ =3D *cbb; + } } + rcu_read_unlock(); } =20 - rcu_read_unlock(); afs_put_volume(volume, afs_volume_trace_put_callback); } =20 diff --git a/fs/afs/cell.c b/fs/afs/cell.c index 1e5cb0f6ee07..ed990e2934a0 100644 --- a/fs/afs/cell.c +++ b/fs/afs/cell.c @@ -167,8 +167,6 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *= net, seqlock_init(&cell->volume_lock); cell->fs_servers =3D RB_ROOT; seqlock_init(&cell->fs_lock); - INIT_LIST_HEAD(&cell->fs_open_mmaps); - init_rwsem(&cell->fs_open_mmaps_lock); rwlock_init(&cell->vl_servers_lock); cell->flags =3D (1 << AFS_CELL_FL_CHECK_ALIAS); =20 diff --git a/fs/afs/dir.c b/fs/afs/dir.c index e232f713ece1..ed5bcb5d8895 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -1260,6 +1260,7 @@ void afs_check_for_remote_deletion(struct afs_operati= on *op) switch (afs_op_abort_code(op)) { case VNOVNODE: set_bit(AFS_VNODE_DELETED, &vnode->flags); + clear_nlink(&vnode->netfs.inode); afs_break_callback(vnode, afs_cb_break_for_deleted); } } @@ -1375,7 +1376,7 @@ static void afs_dir_remove_subdir(struct dentry *dent= ry) =20 clear_nlink(&vnode->netfs.inode); set_bit(AFS_VNODE_DELETED, &vnode->flags); - clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); + atomic64_set(&vnode->cb_expires_at, AFS_NO_CB_PROMISE); clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags); } } diff --git a/fs/afs/file.c b/fs/afs/file.c index 8f9b42427569..30914e0d9cb2 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -514,13 +514,12 @@ static bool afs_release_folio(struct folio *folio, gf= p_t gfp) static void afs_add_open_mmap(struct afs_vnode *vnode) { if (atomic_inc_return(&vnode->cb_nr_mmap) =3D=3D 1) { - down_write(&vnode->volume->cell->fs_open_mmaps_lock); + down_write(&vnode->volume->open_mmaps_lock); =20 if (list_empty(&vnode->cb_mmap_link)) - list_add_tail(&vnode->cb_mmap_link, - &vnode->volume->cell->fs_open_mmaps); + list_add_tail(&vnode->cb_mmap_link, &vnode->volume->open_mmaps); =20 - up_write(&vnode->volume->cell->fs_open_mmaps_lock); + up_write(&vnode->volume->open_mmaps_lock); } } =20 @@ -529,12 +528,12 @@ static void afs_drop_open_mmap(struct afs_vnode *vnod= e) if (!atomic_dec_and_test(&vnode->cb_nr_mmap)) return; =20 - down_write(&vnode->volume->cell->fs_open_mmaps_lock); + down_write(&vnode->volume->open_mmaps_lock); =20 if (atomic_read(&vnode->cb_nr_mmap) =3D=3D 0) list_del_init(&vnode->cb_mmap_link); =20 - up_write(&vnode->volume->cell->fs_open_mmaps_lock); + up_write(&vnode->volume->open_mmaps_lock); flush_work(&vnode->cb_work); } =20 @@ -570,7 +569,7 @@ static vm_fault_t afs_vm_map_pages(struct vm_fault *vmf= , pgoff_t start_pgoff, pg { struct afs_vnode *vnode =3D AFS_FS_I(file_inode(vmf->vma->vm_file)); =20 - if (afs_pagecache_valid(vnode)) + if (afs_check_validity(vnode)) return filemap_map_pages(vmf, start_pgoff, end_pgoff); return 0; } diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index 99d1e649e929..cecc44af6a5f 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -42,7 +42,7 @@ struct afs_operation *afs_alloc_operation(struct key *key= , struct afs_volume *vo op->pre_volsync.creation =3D volume->creation_time; op->pre_volsync.update =3D volume->update_time; op->debug_id =3D atomic_inc_return(&afs_operation_debug_counter); - op->nr_iterations =3D -1; + op->nr_iterations =3D -1; afs_op_set_error(op, -EDESTADDRREQ); =20 _leave(" =3D [op=3D%08x]", op->debug_id); @@ -184,7 +184,6 @@ void afs_wait_for_operation(struct afs_operation *op) op->call_responded =3D false; op->call_error =3D 0; op->call_abort_code =3D 0; - op->cb_s_break =3D op->server->cb_s_break; if (test_bit(AFS_SERVER_FL_IS_YFS, &op->server->flags) && op->ops->issue_yfs_rpc) op->ops->issue_yfs_rpc(op); diff --git a/fs/afs/inode.c b/fs/afs/inode.c index df3d37577b5b..4f04f6f33f46 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -85,8 +85,7 @@ static int afs_inode_init_from_status(struct afs_operatio= n *op, =20 write_seqlock(&vnode->cb_lock); =20 - vnode->cb_v_break =3D op->cb_v_break; - vnode->cb_s_break =3D op->cb_s_break; + vnode->cb_v_check =3D op->cb_v_break; vnode->status =3D *status; =20 t =3D status->mtime_client; @@ -146,11 +145,10 @@ static int afs_inode_init_from_status(struct afs_oper= ation *op, if (!vp->scb.have_cb) { /* it's a symlink we just created (the fileserver * didn't give us a callback) */ - vnode->cb_expires_at =3D ktime_get_real_seconds(); + atomic64_set(&vnode->cb_expires_at, AFS_NO_CB_PROMISE); } else { - vnode->cb_expires_at =3D vp->scb.callback.expires_at; vnode->cb_server =3D op->server; - set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); + atomic64_set(&vnode->cb_expires_at, vp->scb.callback.expires_at); } =20 write_sequnlock(&vnode->cb_lock); @@ -214,7 +212,8 @@ static void afs_apply_status(struct afs_operation *op, vnode->status =3D *status; =20 if (vp->dv_before + vp->dv_delta !=3D status->data_version) { - if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) + if (vnode->cb_ro_snapshot =3D=3D atomic_read(&vnode->volume->cb_ro_snaps= hot) && + atomic64_read(&vnode->cb_expires_at) !=3D AFS_NO_CB_PROMISE) pr_warn("kAFS: vnode modified {%llx:%llu} %llx->%llx %s (op=3D%x)\n", vnode->fid.vid, vnode->fid.vnode, (unsigned long long)vp->dv_before + vp->dv_delta, @@ -268,9 +267,9 @@ static void afs_apply_callback(struct afs_operation *op, struct afs_vnode *vnode =3D vp->vnode; =20 if (!afs_cb_is_broken(vp->cb_break_before, vnode)) { - vnode->cb_expires_at =3D cb->expires_at; - vnode->cb_server =3D op->server; - set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); + if (op->volume->type =3D=3D AFSVL_RWVOL) + vnode->cb_server =3D op->server; + atomic64_set(&vnode->cb_expires_at, cb->expires_at); } } =20 @@ -542,7 +541,7 @@ struct inode *afs_root_iget(struct super_block *sb, str= uct key *key) BUG_ON(!(inode->i_state & I_NEW)); =20 vnode =3D AFS_FS_I(inode); - vnode->cb_v_break =3D atomic_read(&as->volume->cb_v_break), + vnode->cb_v_check =3D atomic_read(&as->volume->cb_v_break), afs_set_netfs_context(vnode); =20 op =3D afs_alloc_operation(key, as->volume); @@ -587,7 +586,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct p= ath *path, =20 if (vnode->volume && !(query_flags & AT_STATX_DONT_SYNC) && - !test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { + atomic64_read(&vnode->cb_expires_at) =3D=3D AFS_NO_CB_PROMISE) { key =3D afs_request_key(vnode->volume->cell); if (IS_ERR(key)) return PTR_ERR(key); diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 4b730cbcf63e..6d0cd886b548 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -422,9 +422,6 @@ struct afs_cell { /* Active fileserver interaction state. */ struct rb_root fs_servers; /* afs_server (by server UUID) */ seqlock_t fs_lock; /* For fs_servers */ - struct rw_semaphore fs_open_mmaps_lock; - struct list_head fs_open_mmaps; /* List of vnodes that are mmapped */ - atomic_t fs_s_break; /* Counter of CB.InitCallBackState messages */ =20 /* VL server list. */ rwlock_t vl_servers_lock; /* Lock on vl_servers */ @@ -591,9 +588,6 @@ struct afs_server { /* file service access */ rwlock_t fs_lock; /* access lock */ =20 - /* callback promise management */ - unsigned cb_s_break; /* Break-everything counter. */ - /* Probe state */ struct afs_endpoint_state __rcu *endpoint_state; /* Latest endpoint/probe= state */ unsigned long probed_at; /* Time last probe was dispatched (jiffies) */ @@ -615,6 +609,7 @@ struct afs_server_entry { struct afs_server *server; struct afs_volume *volume; struct list_head slink; /* Link in server->volumes */ + time64_t cb_expires_at; /* Time at which volume-level callback expires */ unsigned long flags; #define AFS_SE_EXCLUDED 0 /* Set if server is to be excluded in rotation= */ }; @@ -668,10 +663,15 @@ struct afs_volume { time64_t update_time; /* Volume update time (or TIME64_MIN) */ =20 /* Callback management */ + struct mutex cb_check_lock; /* Lock to control race to check after v_bre= ak */ + time64_t cb_expires_at; /* Earliest volume callback expiry time */ atomic_t cb_ro_snapshot; /* RO volume update-from-snapshot counter */ atomic_t cb_v_break; /* Volume-break event counter. */ + atomic_t cb_v_check; /* Volume-break has-been-checked counter. */ atomic_t cb_scrub; /* Scrub-all-data event counter. */ rwlock_t cb_v_break_lock; + struct rw_semaphore open_mmaps_lock; + struct list_head open_mmaps; /* List of vnodes that are mmapped */ =20 afs_voltype_t type; /* type of volume */ char type_force; /* force volume type (suppress R/O -> R/W) */ @@ -710,7 +710,6 @@ struct afs_vnode { spinlock_t wb_lock; /* lock for wb_keys */ spinlock_t lock; /* waitqueue/flags lock */ unsigned long flags; -#define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */ #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */ #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */ #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated= */ @@ -736,13 +735,14 @@ struct afs_vnode { struct list_head cb_mmap_link; /* Link in cell->fs_open_mmaps */ void *cb_server; /* Server with callback/filelock */ atomic_t cb_nr_mmap; /* Number of mmaps */ - unsigned int cb_fs_s_break; /* Mass server break counter (cell->fs_s_bre= ak) */ - unsigned int cb_s_break; /* Mass break counter on ->server */ - unsigned int cb_v_break; /* Mass break counter on ->volume */ + unsigned int cb_ro_snapshot; /* RO volume release counter on ->volume */ + unsigned int cb_scrub; /* Scrub counter on ->volume */ unsigned int cb_break; /* Break counter on vnode */ + unsigned int cb_v_check; /* Break check counter on ->volume */ seqlock_t cb_lock; /* Lock for ->cb_server, ->status, ->cb_*break */ =20 - time64_t cb_expires_at; /* time at which callback expires */ + atomic64_t cb_expires_at; /* time at which callback expires */ +#define AFS_NO_CB_PROMISE TIME64_MIN }; =20 static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vno= de) @@ -839,7 +839,7 @@ struct afs_vnode_param { struct afs_fid fid; /* Fid to access */ struct afs_status_cb scb; /* Returned status and callback promise */ afs_dataversion_t dv_before; /* Data version before the call */ - unsigned int cb_break_before; /* cb_break + cb_s_break before the call */ + unsigned int cb_break_before; /* cb_break before the call */ u8 dv_delta; /* Expected change in data version */ bool put_vnode:1; /* T if we have a ref on the vnode */ bool need_io_lock:1; /* T if we need the I/O lock on this */ @@ -875,7 +875,6 @@ struct afs_operation { unsigned int debug_id; =20 unsigned int cb_v_break; /* Volume break counter before op */ - unsigned int cb_s_break; /* Server break counter before op */ =20 union { struct { @@ -1066,13 +1065,15 @@ extern void afs_break_callbacks(struct afs_server *= , size_t, struct afs_callback =20 static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode) { - return vnode->cb_break + vnode->cb_v_break; + return vnode->cb_break + vnode->cb_ro_snapshot + vnode->cb_scrub; } =20 static inline bool afs_cb_is_broken(unsigned int cb_break, const struct afs_vnode *vnode) { - return cb_break !=3D (vnode->cb_break + atomic_read(&vnode->volume->cb_v_= break)); + return cb_break !=3D (vnode->cb_break + + atomic_read(&vnode->volume->cb_ro_snapshot) + + atomic_read(&vnode->volume->cb_scrub)); } =20 /* @@ -1564,9 +1565,8 @@ extern void afs_fs_exit(void); /* * validation.c */ +bool afs_check_validity(const struct afs_vnode *vnode); int afs_update_volume_state(struct afs_operation *op); -bool afs_check_validity(struct afs_vnode *vnode); -bool afs_pagecache_valid(struct afs_vnode *vnode); int afs_validate(struct afs_vnode *vnode, struct key *key); =20 /* diff --git a/fs/afs/proc.c b/fs/afs/proc.c index a138022d8e0d..3bd02571f30d 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c @@ -443,8 +443,8 @@ static int afs_proc_servers_show(struct seq_file *m, vo= id *v) refcount_read(&server->ref), atomic_read(&server->active), server->cell->name); - seq_printf(m, " - info: fl=3D%lx rtt=3D%u brk=3D%x\n", - server->flags, server->rtt, server->cb_s_break); + seq_printf(m, " - info: fl=3D%lx rtt=3D%u\n", + server->flags, server->rtt); seq_printf(m, " - probe: last=3D%d\n", (int)(jiffies - server->probed_at) / HZ); failed =3D estate->failed_set; diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index 5c50c9aa1f87..a5222acf0add 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -59,7 +59,7 @@ static bool afs_start_fs_iteration(struct afs_operation *= op, write_seqlock(&vnode->cb_lock); ASSERTCMP(cb_server, =3D=3D, vnode->cb_server); vnode->cb_server =3D NULL; - if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) + if (atomic64_xchg(&vnode->cb_expires_at, AFS_NO_CB_PROMISE) !=3D AFS_NO_= CB_PROMISE) vnode->cb_break++; write_sequnlock(&vnode->cb_lock); } @@ -484,10 +484,8 @@ bool afs_select_fileserver(struct afs_operation *op) op->server =3D server; if (vnode->cb_server !=3D server) { vnode->cb_server =3D server; - vnode->cb_s_break =3D server->cb_s_break; - vnode->cb_fs_s_break =3D atomic_read(&server->cell->fs_s_break); - vnode->cb_v_break =3D atomic_read(&vnode->volume->cb_v_break); - clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); + vnode->cb_v_check =3D atomic_read(&vnode->volume->cb_v_break); + atomic64_set(&vnode->cb_expires_at, AFS_NO_CB_PROMISE); } =20 read_lock(&server->fs_lock); diff --git a/fs/afs/server_list.c b/fs/afs/server_list.c index fb0f4afcb304..ac4a7afff45e 100644 --- a/fs/afs/server_list.c +++ b/fs/afs/server_list.c @@ -110,6 +110,7 @@ struct afs_server_list *afs_alloc_server_list(struct af= s_volume *volume, slist->servers[j].server =3D server; slist->servers[j].volume =3D volume; slist->servers[j].flags =3D se_flags; + slist->servers[j].cb_expires_at =3D AFS_NO_CB_PROMISE; slist->nr_servers++; } =20 @@ -210,6 +211,7 @@ void afs_reattach_volume_to_servers(struct afs_volume *= volume, struct afs_server int diff; =20 if (pn && po && pn->server =3D=3D po->server) { + pn->cb_expires_at =3D po->cb_expires_at; list_replace(&po->slink, &pn->slink); n++; o++; diff --git a/fs/afs/validation.c b/fs/afs/validation.c index 6aadd5e075e4..13e9a87ac5c6 100644 --- a/fs/afs/validation.c +++ b/fs/afs/validation.c @@ -10,6 +10,131 @@ #include #include "internal.h" =20 +/* + * Data validation is managed through a number of mechanisms from the serv= er: + * + * (1) On first contact with a server (such as if it has just been reboot= ed), + * the server sends us a CB.InitCallBackState* request. + * + * (2) On a RW volume, in response to certain vnode (inode)-accessing RPC + * calls, the server maintains a time-limited per-vnode promise that = it + * will send us a CB.CallBack request if a third party alters the vno= des + * accessed. + * + * Note that a vnode-level callbacks may also be sent for other reaso= ns, + * such as filelock release. + * + * (3) On a RO (or Backup) volume, in response to certain vnode-accessing= RPC + * calls, each server maintains a time-limited per-volume promise tha= t it + * will send us a CB.CallBack request if the RO volume is updated to a + * snapshot of the RW volume ("vos release"). This is an atomic event + * that cuts over all instances of the RO volume across multiple serv= ers + * simultaneously. + * + * Note that a volume-level callbacks may also be sent for other reasons, + * such as the volumeserver taking over control of the volume from the + * fileserver. + * + * Note also that each server maintains an independent time limit on an + * independent callback. + * + * (4) Certain RPC calls include a volume information record "VolSync" in + * their reply. This contains a creation date for the volume that sh= ould + * remain unchanged for a RW volume (but will be changed if the volum= e is + * restored from backup) or will be bumped to the time of snapshotting + * when a RO volume is released. + * + * In order to track this events, the following are provided: + * + * ->cb_v_break. A counter of events that might mean that the contents of + * a volume have been altered since we last checked a vnode. + * + * ->cb_v_check. A counter of the number of events that we've sent a + * query to the server for. Everything's up to date if this equals + * cb_v_break. + * + * ->cb_scrub. A counter of the number of regression events for which we + * have to completely wipe the cache. + * + * ->cb_ro_snapshot. A counter of the number of times that we've + * recognised that a RO volume has been updated. + * + * ->cb_break. A counter of events that might mean that the contents of a + * vnode have been altered. + * + * ->cb_expires_at. The time at which the callback promise expires or + * AFS_NO_CB_PROMISE if we have no promise. + * + * The way we manage things is: + * + * (1) When a volume-level CB.CallBack occurs, we increment ->cb_v_break = on + * the volume and reset ->cb_expires_at (ie. set AFS_NO_CB_PROMISE) o= n the + * volume and volume's server record. + * + * (2) When a CB.InitCallBackState occurs, we treat this as a volume-level + * callback break on all the volumes that have been using that volume + * (ie. increment ->cb_v_break and reset ->cb_expires_at). + * + * (3) When a vnode-level CB.CallBack occurs, we increment ->cb_break on = the + * vnode and reset its ->cb_expires_at. If the vnode is mmapped, we also + * dispatch a work item to unmap all PTEs to the vnode's pagecache to + * force reentry to the filesystem for revalidation. + * + * (4) When entering the filesystem, we call afs_validate() to check the + * validity of a vnode. This first checks to see if ->cb_v_check and + * ->cb_v_break match, and if they don't, we lock volume->cb_check_lock + * exclusively and perform an FS.FetchStatus on the vnode. + * + * After checking the volume, we check the vnode. If there's a mismatch + * between the volume counters and the vnode's mirrors of those counters, + * we lock vnode->validate_lock and issue an FS.FetchStatus on the vnode. + * + * (5) When the reply from FS.FetchStatus arrives, the VolSync record is + * parsed: + * + * (A) If the Creation timestamp has changed on a RW volume or regressed + * on a RO volume, we try to increment ->cb_scrub; if it advances on a + * RO volume, we assume "vos release" happened and try to increment + * ->cb_ro_snapshot. + * + * (B) If the Update timestamp has regressed, we try to increment + * ->cb_scrub. + * + * Note that in both of these cases, we only do the increment if we c= an + * cmpxchg the value of the timestamp from the value we noted before = the + * op. This tries to prevent parallel ops from fighting one another. + * + * volume->cb_v_check is then set to ->cb_v_break. + * + * (6) The AFSCallBack record included in the FS.FetchStatus reply is also + * parsed and used to set the promise in ->cb_expires_at for the vnode, + * the volume and the volume's server record. + * + * (7) If ->cb_scrub is seen to have advanced, we invalidate the pagecach= e for + * the vnode. + */ + +/* + * Check the validity of a vnode/inode and its parent volume. + */ +bool afs_check_validity(const struct afs_vnode *vnode) +{ + const struct afs_volume *volume =3D vnode->volume; + time64_t deadline =3D ktime_get_real_seconds() + 10; + + if (atomic_read(&volume->cb_v_check) !=3D atomic_read(&volume->cb_v_break= ) || + atomic64_read(&vnode->cb_expires_at) <=3D deadline || + volume->cb_expires_at <=3D deadline || + vnode->cb_ro_snapshot !=3D atomic_read(&volume->cb_ro_snapshot) || + vnode->cb_scrub !=3D atomic_read(&volume->cb_scrub) || + test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) { + _debug("inval"); + return false; + } + + return true; +} + /* * See if the server we've just talked to is currently excluded. */ @@ -185,11 +310,17 @@ static int afs_update_volume_times(struct afs_operati= on *op, struct afs_volume * } =20 /* - * Update the state of a volume. Returns 1 to redo the operation from the= start. + * Update the state of a volume, including recording the expiration time o= f the + * callback promise. Returns 1 to redo the operation from the start. */ int afs_update_volume_state(struct afs_operation *op) { + struct afs_server_list *slist =3D op->server_list; + struct afs_server_entry *se =3D &slist->servers[op->server_index]; + struct afs_callback *cb =3D &op->file[0].scb.callback; struct afs_volume *volume =3D op->volume; + unsigned int cb_v_break =3D atomic_read(&volume->cb_v_break); + unsigned int cb_v_check =3D atomic_read(&volume->cb_v_check); int ret; =20 _enter("%llx", op->volume->vid); @@ -202,6 +333,12 @@ int afs_update_volume_state(struct afs_operation *op) } } =20 + if (op->cb_v_break =3D=3D cb_v_break) { + se->cb_expires_at =3D cb->expires_at; + volume->cb_expires_at =3D cb->expires_at; + } + if (cb_v_check < op->cb_v_break) + atomic_cmpxchg(&volume->cb_v_check, cb_v_check, op->cb_v_break); return 0; } =20 @@ -224,99 +361,6 @@ static void afs_zap_data(struct afs_vnode *vnode) invalidate_inode_pages2(vnode->netfs.inode.i_mapping); } =20 -/* - * Check to see if we have a server currently serving this volume and that= it - * hasn't been reinitialised or dropped from the list. - */ -static bool afs_check_server_good(struct afs_vnode *vnode) -{ - struct afs_server_list *slist; - struct afs_server *server; - bool good; - int i; - - if (vnode->cb_fs_s_break =3D=3D atomic_read(&vnode->volume->cell->fs_s_br= eak)) - return true; - - rcu_read_lock(); - - slist =3D rcu_dereference(vnode->volume->servers); - for (i =3D 0; i < slist->nr_servers; i++) { - server =3D slist->servers[i].server; - if (server =3D=3D vnode->cb_server) { - good =3D (vnode->cb_s_break =3D=3D server->cb_s_break); - rcu_read_unlock(); - return good; - } - } - - rcu_read_unlock(); - return false; -} - -/* - * Check the validity of a vnode/inode. - */ -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; - - do { - seq =3D read_seqbegin(&vnode->cb_lock); - cb_break =3D vnode->cb_break; - - if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { - if (vnode->cb_v_break !=3D atomic_read(&vnode->volume->cb_v_break)) - need_clear =3D afs_cb_break_for_v_break; - else if (!afs_check_server_good(vnode)) - need_clear =3D afs_cb_break_for_s_reinit; - else if (test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) - need_clear =3D afs_cb_break_for_zap; - else if (vnode->cb_expires_at - 10 <=3D now) - need_clear =3D afs_cb_break_for_lapsed; - } else if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { - ; - } else { - need_clear =3D afs_cb_break_no_promise; - } - - } while (read_seqretry(&vnode->cb_lock, seq)); - - if (need_clear =3D=3D afs_cb_break_no_break) - return true; - - write_seqlock(&vnode->cb_lock); - if (need_clear =3D=3D afs_cb_break_no_promise) - vnode->cb_v_break =3D atomic_read(&vnode->volume->cb_v_break); - else if (cb_break =3D=3D vnode->cb_break) - __afs_break_callback(vnode, need_clear); - else - trace_afs_cb_miss(&vnode->fid, need_clear); - write_sequnlock(&vnode->cb_lock); - return false; -} - -/* - * Returns true if the pagecache is still valid. Does not sleep. - */ -bool afs_pagecache_valid(struct afs_vnode *vnode) -{ - if (unlikely(test_bit(AFS_VNODE_DELETED, &vnode->flags))) { - if (vnode->netfs.inode.i_nlink) - clear_nlink(&vnode->netfs.inode); - return true; - } - - if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags) && - afs_check_validity(vnode)) - return true; - - return false; -} - /* * validate a vnode/inode * - there are several things we need to check @@ -328,23 +372,48 @@ bool afs_pagecache_valid(struct afs_vnode *vnode) */ int afs_validate(struct afs_vnode *vnode, struct key *key) { + struct afs_volume *volume =3D vnode->volume; + unsigned int cb_ro_snapshot, cb_scrub; + time64_t deadline =3D ktime_get_real_seconds() + 10; + bool zap =3D false, locked_vol =3D false; int ret; =20 _enter("{v=3D{%llx:%llu} fl=3D%lx},%x", vnode->fid.vid, vnode->fid.vnode, vnode->flags, key_serial(key)); =20 - if (afs_pagecache_valid(vnode)) - goto valid; + if (afs_check_validity(vnode)) + return 0; + + ret =3D down_write_killable(&vnode->validate_lock); + if (ret < 0) + goto error; =20 - down_write(&vnode->validate_lock); + /* Validate a volume after the v_break has changed or the volume + * callback expired. We only want to do this once per volume per + * v_break change. The actual work will be done when parsing the + * status fetch reply. + */ + if (volume->cb_expires_at <=3D deadline || + atomic_read(&volume->cb_v_check) !=3D atomic_read(&volume->cb_v_break= )) { + ret =3D mutex_lock_interruptible(&volume->cb_check_lock); + if (ret < 0) + goto error_unlock; + locked_vol =3D true; + } =20 - /* if the promise has expired, we need to check the server again to get - * a new promise - note that if the (parent) directory's metadata was - * changed then the security may be different and we may no longer have - * access */ - if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { - _debug("not promised"); + cb_ro_snapshot =3D atomic_read(&volume->cb_ro_snapshot); + cb_scrub =3D atomic_read(&volume->cb_scrub); + if (vnode->cb_ro_snapshot !=3D cb_ro_snapshot || + vnode->cb_scrub !=3D cb_scrub) + unmap_mapping_pages(vnode->netfs.inode.i_mapping, 0, 0, false); + + if (vnode->cb_ro_snapshot !=3D cb_ro_snapshot || + vnode->cb_scrub !=3D cb_scrub || + volume->cb_expires_at <=3D deadline || + atomic_read(&volume->cb_v_check) !=3D atomic_read(&volume->cb_v_break= ) || + atomic64_read(&vnode->cb_expires_at) <=3D deadline + ) { ret =3D afs_fetch_status(vnode, key, false, NULL); if (ret < 0) { if (ret =3D=3D -ENOENT) { @@ -353,9 +422,26 @@ int afs_validate(struct afs_vnode *vnode, struct key *= key) } goto error_unlock; } + _debug("new promise [fl=3D%lx]", vnode->flags); } =20 + /* We can drop the volume lock now as. */ + if (locked_vol) { + mutex_unlock(&volume->cb_check_lock); + locked_vol =3D false; + } + + cb_ro_snapshot =3D atomic_read(&volume->cb_ro_snapshot); + cb_scrub =3D atomic_read(&volume->cb_scrub); + _debug("vnode inval %x=3D=3D%x %x=3D=3D%x", + vnode->cb_ro_snapshot, cb_ro_snapshot, + vnode->cb_scrub, cb_scrub); + if (vnode->cb_scrub !=3D cb_scrub) + zap =3D true; + vnode->cb_ro_snapshot =3D cb_ro_snapshot; + vnode->cb_scrub =3D cb_scrub; + if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { _debug("file already deleted"); ret =3D -ESTALE; @@ -364,15 +450,18 @@ int afs_validate(struct afs_vnode *vnode, struct key = *key) =20 /* if the vnode's data version number changed then its contents are * different */ - if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) + zap |=3D test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags); + if (zap) afs_zap_data(vnode); up_write(&vnode->validate_lock); -valid: _leave(" =3D 0"); return 0; =20 error_unlock: + if (locked_vol) + mutex_unlock(&volume->cb_check_lock); up_write(&vnode->validate_lock); +error: _leave(" =3D %d", ret); return ret; } diff --git a/fs/afs/volume.c b/fs/afs/volume.c index 41ab1d3ff3ea..cc207dca1b21 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -98,7 +98,10 @@ static struct afs_volume *afs_alloc_volume(struct afs_fs= _context *params, INIT_WORK(&volume->destructor, afs_destroy_volume); rwlock_init(&volume->servers_lock); mutex_init(&volume->volsync_lock); + mutex_init(&volume->cb_check_lock); rwlock_init(&volume->cb_v_break_lock); + INIT_LIST_HEAD(&volume->open_mmaps); + init_rwsem(&volume->open_mmaps_lock); memcpy(volume->name, vldb->name, vldb->name_len + 1); =20 for (i =3D 0; i < AFS_MAXTYPES; i++) diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index bbe8dcab4b32..2df7d0fd3f21 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -438,18 +438,14 @@ enum yfs_cm_operation { =20 #define afs_cb_break_reasons \ EM(afs_cb_break_no_break, "no-break") \ - EM(afs_cb_break_no_promise, "no-promise") \ EM(afs_cb_break_for_callback, "break-cb") \ EM(afs_cb_break_for_creation_regress, "creation-regress") \ EM(afs_cb_break_for_deleted, "break-del") \ - EM(afs_cb_break_for_lapsed, "break-lapsed") \ EM(afs_cb_break_for_s_reinit, "s-reinit") \ EM(afs_cb_break_for_unlink, "break-unlink") \ EM(afs_cb_break_for_update_regress, "update-regress") \ - EM(afs_cb_break_for_v_break, "break-v") \ EM(afs_cb_break_for_volume_callback, "break-v-cb") \ EM(afs_cb_break_for_vos_release, "break-vos-release") \ - EM(afs_cb_break_for_zap, "break-zap") \ E_(afs_cb_break_volume_excluded, "vol-excluded") =20 /* From nobody Mon Dec 15 21:24:35 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 21B7AC4332F for ; Wed, 13 Dec 2023 13:53:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379381AbjLMNxR (ORCPT ); Wed, 13 Dec 2023 08:53:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379319AbjLMNwS (ORCPT ); Wed, 13 Dec 2023 08:52:18 -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 AA853D5A for ; Wed, 13 Dec 2023 05:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475471; 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=VC4mGprCPORqSyBZv089neT6dWP9qekDHP/NUrkNAcc=; b=BfktzqKBJhbO+udKwETLjauzW1CJky6EFiQR/JuHBSd7lQL/eocrgZbKvhYzVK8bRozADH 7+4+jQzQPXvvNtFSAOtDaJDIhtWjMBpFD8Ykt8N4j8y9QfIcj0p79vW+Ftq2jMDpozrTqJ OQketceZ3ZjpfeheFCGJ5v8JCayVZRc= 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-208-Tl9NWo91NtWg7O3r_0S4xw-1; Wed, 13 Dec 2023 08:51:07 -0500 X-MC-Unique: Tl9NWo91NtWg7O3r_0S4xw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 2A76B837194; Wed, 13 Dec 2023 13:51:07 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28CFE51E3; Wed, 13 Dec 2023 13:51:06 +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 Subject: [PATCH v2 38/40] afs: Fix fileserver rotation Date: Wed, 13 Dec 2023 13:50:00 +0000 Message-ID: <20231213135003.367397-39-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix the fileserver rotation so that it doesn't use RTT as the basis for deciding which server and address to use as this doesn't necessarily give a good indication of the best path. Instead, use the configurable preference list in conjunction with whatever probes have succeeded at the time of looking. To this end, make the following changes: (1) Keep an array of "server states" to track what addresses we've tried on each server and move the waitqueue entries there that we'll need for probing. (2) Each afs_server_state struct is made to pin the corresponding server's endpoint state rather than the afs_operation struct carrying a pin on the server we're currently looking at. (3) Drop the server list preference; we now always rescan the server list. (4) afs_wait_for_probes() now uses the server state list to guide it in what it waits for (and to provide the waitqueue entries) and returns an indication of whether we'd got a response, run out of responsive addresses or the endpoint state had been superseded and we need to restart the iteration. (5) Call afs_get_address_preferences*() occasionally to refresh the preference values. (6) When picking a server, scan the addresses of the servers for which we have as-yet untested communications, looking for the highest priority one and use that instead of trying all the addresses for a particular server in ascending-RTT order. (7) When a Busy or Offline state is seen across all available servers, do a short sleep. (8) If we detect that we accessed a future RO volume version whilst it is undergoing replication, reissue the op against the older version until at least half of the servers are replicated. (9) Whilst RO replication is ongoing, increase the frequency of Volume Location server checks for that volume to every ten minutes instead of hourly. Also add a tracepoint to track progress through the rotation algorithm. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/fs_operation.c | 8 +- fs/afs/fs_probe.c | 103 ++++++++------------ fs/afs/internal.h | 23 ++++- fs/afs/rotate.c | 194 ++++++++++++++++++++++++++++--------- fs/afs/server_list.c | 14 +-- fs/afs/volume.c | 6 +- include/trace/events/afs.h | 81 +++++++++++++--- 7 files changed, 283 insertions(+), 146 deletions(-) diff --git a/fs/afs/fs_operation.c b/fs/afs/fs_operation.c index cecc44af6a5f..3546b087e791 100644 --- a/fs/afs/fs_operation.c +++ b/fs/afs/fs_operation.c @@ -229,7 +229,6 @@ void afs_wait_for_operation(struct afs_operation *op) */ int afs_put_operation(struct afs_operation *op) { - struct afs_endpoint_state *estate =3D op->estate; struct afs_addr_list *alist; int i, ret =3D afs_op_error(op); =20 @@ -253,18 +252,17 @@ int afs_put_operation(struct afs_operation *op) kfree(op->more_files); } =20 - if (estate) { - alist =3D estate->addresses; + if (op->estate) { + alist =3D op->estate->addresses; if (alist) { if (op->call_responded && op->addr_index !=3D alist->preferred && test_bit(alist->preferred, &op->addr_tried)) WRITE_ONCE(alist->preferred, op->addr_index); } - afs_put_endpoint_state(estate, afs_estate_trace_put_operation); - op->estate =3D NULL; } =20 + afs_clear_server_states(op); afs_put_serverlist(op->net, op->server_list); afs_put_volume(op->volume, afs_volume_trace_put_put_op); key_put(op->key); diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c index c00d38b98a67..580de4adaaf6 100644 --- a/fs/afs/fs_probe.c +++ b/fs/afs/fs_probe.c @@ -296,58 +296,48 @@ void afs_fs_probe_fileserver(struct afs_net *net, str= uct afs_server *server, } =20 /* - * Wait for the first as-yet untried fileserver to respond. + * Wait for the first as-yet untried fileserver to respond, for the probe = state + * to be superseded or for all probes to finish. */ -int afs_wait_for_fs_probes(struct afs_server_list *slist, unsigned long un= tried) +int afs_wait_for_fs_probes(struct afs_operation *op, struct afs_server_sta= te *states, bool intr) { struct afs_endpoint_state *estate; - struct wait_queue_entry *waits; - struct afs_server *server; - unsigned int rtt =3D UINT_MAX, rtt_s; - bool have_responders =3D false; - int pref =3D -1, i; + struct afs_server_list *slist =3D op->server_list; + bool still_probing =3D true; + int ret =3D 0, i; =20 - _enter("%u,%lx", slist->nr_servers, untried); + _enter("%u", slist->nr_servers); =20 - /* Only wait for servers that have a probe outstanding. */ - rcu_read_lock(); for (i =3D 0; i < slist->nr_servers; i++) { - if (test_bit(i, &untried)) { - server =3D slist->servers[i].server; - estate =3D rcu_dereference(server->endpoint_state); - if (!atomic_read(&estate->nr_probing)) - __clear_bit(i, &untried); - if (test_bit(AFS_ESTATE_RESPONDED, &estate->flags)) - have_responders =3D true; - } + estate =3D states[i].endpoint_state; + if (test_bit(AFS_ESTATE_SUPERSEDED, &estate->flags)) + return 2; + if (atomic_read(&estate->nr_probing)) + still_probing =3D true; + if (estate->responsive_set & states[i].untried_addrs) + return 1; } - rcu_read_unlock(); - if (have_responders || !untried) + if (!still_probing) return 0; =20 - waits =3D kmalloc(array_size(slist->nr_servers, sizeof(*waits)), GFP_KERN= EL); - if (!waits) - return -ENOMEM; - - for (i =3D 0; i < slist->nr_servers; i++) { - if (test_bit(i, &untried)) { - server =3D slist->servers[i].server; - init_waitqueue_entry(&waits[i], current); - add_wait_queue(&server->probe_wq, &waits[i]); - } - } + for (i =3D 0; i < slist->nr_servers; i++) + add_wait_queue(&slist->servers[i].server->probe_wq, &states[i].probe_wai= ter); =20 for (;;) { - bool still_probing =3D false; + still_probing =3D false; =20 - set_current_state(TASK_INTERRUPTIBLE); + set_current_state(intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); for (i =3D 0; i < slist->nr_servers; i++) { - if (test_bit(i, &untried)) { - server =3D slist->servers[i].server; - if (test_bit(AFS_ESTATE_RESPONDED, &estate->flags)) - goto stop; - if (atomic_read(&estate->nr_probing)) - still_probing =3D true; + estate =3D states[i].endpoint_state; + if (test_bit(AFS_ESTATE_SUPERSEDED, &estate->flags)) { + ret =3D 2; + goto stop; + } + if (atomic_read(&estate->nr_probing)) + still_probing =3D true; + if (estate->responsive_set & states[i].untried_addrs) { + ret =3D 1; + goto stop; } } =20 @@ -359,28 +349,12 @@ int afs_wait_for_fs_probes(struct afs_server_list *sl= ist, unsigned long untried) stop: set_current_state(TASK_RUNNING); =20 - for (i =3D 0; i < slist->nr_servers; i++) { - if (test_bit(i, &untried)) { - server =3D slist->servers[i].server; - rtt_s =3D READ_ONCE(server->rtt); - if (test_bit(AFS_SERVER_FL_RESPONDING, &server->flags) && - rtt_s < rtt) { - pref =3D i; - rtt =3D rtt_s; - } - - remove_wait_queue(&server->probe_wq, &waits[i]); - } - } - - kfree(waits); - - if (pref =3D=3D -1 && signal_pending(current)) - return -ERESTARTSYS; + for (i =3D 0; i < slist->nr_servers; i++) + remove_wait_queue(&slist->servers[i].server->probe_wq, &states[i].probe_= waiter); =20 - if (pref >=3D 0) - slist->preferred =3D pref; - return 0; + if (!ret && signal_pending(current)) + ret =3D -ERESTARTSYS; + return ret; } =20 /* @@ -508,7 +482,7 @@ void afs_fs_probe_dispatcher(struct work_struct *work) * Wait for a probe on a particular fileserver to complete for 2s. */ int afs_wait_for_one_fs_probe(struct afs_server *server, struct afs_endpoi= nt_state *estate, - bool is_intr) + unsigned long exclude, bool is_intr) { struct wait_queue_entry wait; unsigned long timo =3D 2 * HZ; @@ -521,7 +495,8 @@ int afs_wait_for_one_fs_probe(struct afs_server *server= , struct afs_endpoint_sta prepare_to_wait_event(&server->probe_wq, &wait, is_intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); if (timo =3D=3D 0 || - test_bit(AFS_ESTATE_RESPONDED, &estate->flags) || + test_bit(AFS_ESTATE_SUPERSEDED, &estate->flags) || + (estate->responsive_set & ~exclude) || atomic_read(&estate->nr_probing) =3D=3D 0 || (is_intr && signal_pending(current))) break; @@ -531,7 +506,9 @@ int afs_wait_for_one_fs_probe(struct afs_server *server= , struct afs_endpoint_sta finish_wait(&server->probe_wq, &wait); =20 dont_wait: - if (test_bit(AFS_ESTATE_RESPONDED, &estate->flags)) + if (estate->responsive_set & ~exclude) + return 1; + if (test_bit(AFS_ESTATE_SUPERSEDED, &estate->flags)) return 0; if (is_intr && signal_pending(current)) return -ERESTARTSYS; diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 6d0cd886b548..e3e373c1fecf 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -620,7 +620,6 @@ struct afs_server_list { bool attached; /* T if attached to servers */ enum afs_ro_replicating ro_replicating; /* RW->RO update (probably) in pr= ogress */ unsigned char nr_servers; - unsigned char preferred; /* Preferred server */ unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */ unsigned int seq; /* Set to ->servers_seq when installed */ rwlock_t lock; @@ -821,6 +820,20 @@ struct afs_vl_cursor { bool call_responded; /* T if the current address responded */ }; =20 +/* + * Fileserver state tracking for an operation. An array of these is kept, + * indexed by server index. + */ +struct afs_server_state { + /* Tracking of fileserver probe state. Other operations may interfere + * by probing a fileserver when accessing other volumes. + */ + unsigned int probe_seq; + unsigned long untried_addrs; /* Addresses we haven't tried yet */ + struct wait_queue_entry probe_waiter; + struct afs_endpoint_state *endpoint_state; /* Endpoint state being monito= red */ +}; + /* * Fileserver operation methods. */ @@ -921,7 +934,8 @@ struct afs_operation { /* Fileserver iteration state */ struct afs_server_list *server_list; /* Current server list (pins ref) */ struct afs_server *server; /* Server we're using (ref pinned by server_li= st) */ - struct afs_endpoint_state *estate; /* Current endpoint state (pins ref) */ + struct afs_endpoint_state *estate; /* Current endpoint state (doesn't pin= ref) */ + struct afs_server_state *server_states; /* States of the servers involved= */ struct afs_call *call; unsigned long untried_servers; /* Bitmask of untried servers */ unsigned long addr_tried; /* Tried addresses */ @@ -1235,11 +1249,11 @@ void afs_put_endpoint_state(struct afs_endpoint_sta= te *estate, enum afs_estate_t extern void afs_fileserver_probe_result(struct afs_call *); void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *serve= r, struct afs_addr_list *new_addrs, struct key *key); -extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long); +int afs_wait_for_fs_probes(struct afs_operation *op, struct afs_server_sta= te *states, bool intr); extern void afs_probe_fileserver(struct afs_net *, struct afs_server *); extern void afs_fs_probe_dispatcher(struct work_struct *); int afs_wait_for_one_fs_probe(struct afs_server *server, struct afs_endpoi= nt_state *estate, - bool is_intr); + unsigned long exclude, bool is_intr); extern void afs_fs_probe_cleanup(struct afs_net *); =20 /* @@ -1363,6 +1377,7 @@ static inline void afs_put_sysnames(struct afs_sysnam= es *sysnames) {} /* * rotate.c */ +void afs_clear_server_states(struct afs_operation *op); extern bool afs_select_fileserver(struct afs_operation *); extern void afs_dump_edestaddrreq(const struct afs_operation *); =20 diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index a5222acf0add..ef7fe70777be 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -15,6 +15,18 @@ #include "afs_fs.h" #include "protocol_uae.h" =20 +void afs_clear_server_states(struct afs_operation *op) +{ + unsigned int i; + + if (op->server_states) { + for (i =3D 0; i < op->server_list->nr_servers; i++) + afs_put_endpoint_state(op->server_states[i].endpoint_state, + afs_estate_trace_put_server_state); + kfree(op->server_states); + } +} + /* * Begin iteration through a server list, starting with the vnode's last u= sed * server if possible, or the last recorded good server if not. @@ -26,14 +38,41 @@ static bool afs_start_fs_iteration(struct afs_operation= *op, void *cb_server; int i; =20 + trace_afs_rotate(op, afs_rotate_trace_start, 0); + read_lock(&op->volume->servers_lock); op->server_list =3D afs_get_serverlist( rcu_dereference_protected(op->volume->servers, lockdep_is_held(&op->volume->servers_lock))); read_unlock(&op->volume->servers_lock); =20 + op->server_states =3D kcalloc(op->server_list->nr_servers, sizeof(op->ser= ver_states[0]), + GFP_KERNEL); + if (!op->server_states) { + afs_op_nomem(op); + trace_afs_rotate(op, afs_rotate_trace_nomem, 0); + return false; + } + + rcu_read_lock(); + for (i =3D 0; i < op->server_list->nr_servers; i++) { + struct afs_endpoint_state *estate; + struct afs_server_state *s =3D &op->server_states[i]; + + server =3D op->server_list->servers[i].server; + estate =3D rcu_dereference(server->endpoint_state); + s->endpoint_state =3D afs_get_endpoint_state(estate, + afs_estate_trace_get_server_state); + s->probe_seq =3D estate->probe_seq; + s->untried_addrs =3D (1UL << estate->addresses->nr_addrs) - 1; + init_waitqueue_entry(&s->probe_waiter, current); + afs_get_address_preferences(op->net, estate->addresses); + } + rcu_read_unlock(); + + op->untried_servers =3D (1UL << op->server_list->nr_servers) - 1; - op->server_index =3D READ_ONCE(op->server_list->preferred); + op->server_index =3D -1; =20 cb_server =3D vnode->cb_server; if (cb_server) { @@ -52,6 +91,7 @@ static bool afs_start_fs_iteration(struct afs_operation *= op, */ if (op->flags & AFS_OPERATION_CUR_ONLY) { afs_op_set_error(op, -ESTALE); + trace_afs_rotate(op, afs_rotate_trace_stale_lock, 0); return false; } =20 @@ -90,6 +130,7 @@ static void afs_busy(struct afs_volume *volume, u32 abor= t_code) */ static bool afs_sleep_and_retry(struct afs_operation *op) { + trace_afs_rotate(op, afs_rotate_trace_busy_sleep, 0); if (!(op->flags & AFS_OPERATION_UNINTR)) { msleep_interruptible(1000); if (signal_pending(current)) { @@ -109,14 +150,13 @@ static bool afs_sleep_and_retry(struct afs_operation = *op) */ bool afs_select_fileserver(struct afs_operation *op) { - struct afs_endpoint_state *estate =3D op->estate; struct afs_addr_list *alist; struct afs_server *server; struct afs_vnode *vnode =3D op->file[0].vnode; unsigned long set, failed; - unsigned int rtt; s32 abort_code =3D op->call_abort_code; - int error =3D op->call_error, addr_index, i; + int best_prio =3D 0; + int error =3D op->call_error, addr_index, i, j; =20 op->nr_iterations++; =20 @@ -127,6 +167,7 @@ bool afs_select_fileserver(struct afs_operation *op) error, abort_code); =20 if (op->flags & AFS_OPERATION_STOP) { + trace_afs_rotate(op, afs_rotate_trace_stopped, 0); _leave(" =3D f [stopped]"); return false; } @@ -134,17 +175,35 @@ bool afs_select_fileserver(struct afs_operation *op) if (op->nr_iterations =3D=3D 0) goto start; =20 - WRITE_ONCE(estate->addresses->addrs[op->addr_index].last_error, error); + WRITE_ONCE(op->estate->addresses->addrs[op->addr_index].last_error, error= ); + trace_afs_rotate(op, afs_rotate_trace_iter, op->call_error); =20 /* Evaluate the result of the previous operation, if there was one. */ switch (op->call_error) { case 0: op->cumul_error.responded =3D true; + + /* We succeeded, but we may need to redo the op from another + * server if we're looking at a set of RO volumes where some of + * the servers have not yet been brought up to date lest we + * regress the data. We only switch to the new version once + * >=3D50% of the servers are updated. + */ + error =3D afs_update_volume_state(op); + if (error !=3D 0) { + if (error =3D=3D 1) { + afs_sleep_and_retry(op); + goto restart_from_beginning; + } + afs_op_set_error(op, error); + goto failed; + } fallthrough; default: /* Success or local failure. Stop. */ afs_op_set_error(op, error); op->flags |=3D AFS_OPERATION_STOP; + trace_afs_rotate(op, afs_rotate_trace_stop, error); _leave(" =3D f [okay/local %d]", error); return false; =20 @@ -157,6 +216,7 @@ bool afs_select_fileserver(struct afs_operation *op) * errors instead. IBM AFS and OpenAFS fileservers, however, do leak * these abort codes. */ + trace_afs_rotate(op, afs_rotate_trace_aborted, abort_code); op->cumul_error.responded =3D true; switch (abort_code) { case VNOVOL: @@ -262,10 +322,6 @@ bool afs_select_fileserver(struct afs_operation *op) afs_op_set_error(op, -EADV); goto failed; } - if (op->flags & AFS_OPERATION_CUR_ONLY) { - afs_op_set_error(op, -ESTALE); - goto failed; - } goto busy; =20 case VRESTARTING: /* The fileserver is either shutting down or starting = up. */ @@ -401,19 +457,22 @@ bool afs_select_fileserver(struct afs_operation *op) } =20 restart_from_beginning: + trace_afs_rotate(op, afs_rotate_trace_restart, 0); _debug("restart"); - afs_put_endpoint_state(estate, afs_estate_trace_put_restart_rotate); - estate =3D op->estate =3D NULL; + op->estate =3D NULL; op->server =3D NULL; + afs_clear_server_states(op); + op->server_states =3D NULL; afs_put_serverlist(op->net, op->server_list); op->server_list =3D NULL; start: _debug("start"); - ASSERTCMP(estate, =3D=3D, NULL); + ASSERTCMP(op->estate, =3D=3D, NULL); /* See if we need to do an update of the volume record. Note that the * volume may have moved or even have been deleted. */ error =3D afs_check_volume_status(op->volume, op); + trace_afs_rotate(op, afs_rotate_trace_check_vol_status, error); if (error < 0) { afs_op_set_error(op, error); goto failed; @@ -426,16 +485,29 @@ bool afs_select_fileserver(struct afs_operation *op) =20 pick_server: _debug("pick [%lx]", op->untried_servers); - ASSERTCMP(estate, =3D=3D, NULL); + ASSERTCMP(op->estate, =3D=3D, NULL); =20 - error =3D afs_wait_for_fs_probes(op->server_list, op->untried_servers); - if (error < 0) { + error =3D afs_wait_for_fs_probes(op, op->server_states, + !(op->flags & AFS_OPERATION_UNINTR)); + switch (error) { + case 0: /* No untried responsive servers and no outstanding probes */ + trace_afs_rotate(op, afs_rotate_trace_probe_none, 0); + goto no_more_servers; + case 1: /* Got a response */ + trace_afs_rotate(op, afs_rotate_trace_probe_response, 0); + break; + case 2: /* Probe data superseded */ + trace_afs_rotate(op, afs_rotate_trace_probe_superseded, 0); + goto restart_from_beginning; + default: + trace_afs_rotate(op, afs_rotate_trace_probe_error, error); afs_op_set_error(op, error); goto failed; } =20 - /* Pick the untried server with the lowest RTT. If we have outstanding - * callbacks, we stick with the server we're already using if we can. + /* Pick the untried server with the highest priority untried endpoint. + * If we have outstanding callbacks, we stick with the server we're + * already using if we can. */ if (op->server) { _debug("server %u", op->server_index); @@ -445,34 +517,47 @@ bool afs_select_fileserver(struct afs_operation *op) _debug("no server"); } =20 + rcu_read_lock(); op->server_index =3D -1; - rtt =3D UINT_MAX; + best_prio =3D -1; for (i =3D 0; i < op->server_list->nr_servers; i++) { + struct afs_endpoint_state *es; struct afs_server_entry *se =3D &op->server_list->servers[i]; + struct afs_addr_list *sal; struct afs_server *s =3D se->server; =20 if (!test_bit(i, &op->untried_servers) || test_bit(AFS_SE_EXCLUDED, &se->flags) || !test_bit(AFS_SERVER_FL_RESPONDING, &s->flags)) continue; - if (s->rtt <=3D rtt) { - op->server_index =3D i; - rtt =3D s->rtt; + es =3D op->server_states->endpoint_state; + sal =3D es->addresses; + + afs_get_address_preferences_rcu(op->net, sal); + for (j =3D 0; j < sal->nr_addrs; j++) { + if (!sal->addrs[j].peer) + continue; + if (sal->addrs[j].prio > best_prio) { + op->server_index =3D i; + best_prio =3D sal->addrs[j].prio; + } } } + rcu_read_unlock(); =20 if (op->server_index =3D=3D -1) goto no_more_servers; =20 selected_server: - _debug("use %d", op->server_index); + trace_afs_rotate(op, afs_rotate_trace_selected_server, best_prio); + _debug("use %d prio %u", op->server_index, best_prio); __clear_bit(op->server_index, &op->untried_servers); =20 /* We're starting on a different fileserver from the list. We need to * check it, create a callback intercept, find its address list and * probe its capabilities before we use it. */ - ASSERTCMP(estate, =3D=3D, NULL); + ASSERTCMP(op->estate, =3D=3D, NULL); server =3D op->server_list->servers[op->server_index].server; =20 if (!afs_check_server_record(op, server, op->key)) @@ -488,12 +573,6 @@ bool afs_select_fileserver(struct afs_operation *op) atomic64_set(&vnode->cb_expires_at, AFS_NO_CB_PROMISE); } =20 - read_lock(&server->fs_lock); - estate =3D rcu_dereference_protected(server->endpoint_state, - lockdep_is_held(&server->fs_lock)); - op->estate =3D afs_get_endpoint_state(estate, afs_estate_trace_get_fsrota= te_set); - read_unlock(&server->fs_lock); - retry_server: op->addr_tried =3D 0; op->addr_index =3D -1; @@ -502,14 +581,23 @@ bool afs_select_fileserver(struct afs_operation *op) /* Iterate over the current server's address list to try and find an * address on which it will respond to us. */ - set =3D READ_ONCE(estate->responsive_set); - failed =3D READ_ONCE(estate->failed_set); - _debug("iterate ES=3D%x rs=3D%lx fs=3D%lx", estate->probe_seq, set, faile= d); + op->estate =3D op->server_states[op->server_index].endpoint_state; + set =3D READ_ONCE(op->estate->responsive_set); + failed =3D READ_ONCE(op->estate->failed_set); + _debug("iterate ES=3D%x rs=3D%lx fs=3D%lx", op->estate->probe_seq, set, f= ailed); set &=3D ~(failed | op->addr_tried); + trace_afs_rotate(op, afs_rotate_trace_iterate_addr, set); if (!set) - goto out_of_addresses; + goto wait_for_more_probe_results; + + alist =3D op->estate->addresses; + for (i =3D 0; i < alist->nr_addrs; i++) { + if (alist->addrs[i].prio > best_prio) { + addr_index =3D i; + best_prio =3D alist->addrs[i].prio; + } + } =20 - alist =3D estate->addresses; addr_index =3D READ_ONCE(alist->preferred); if (!test_bit(addr_index, &set)) addr_index =3D __ffs(set); @@ -526,17 +614,24 @@ bool afs_select_fileserver(struct afs_operation *op) _leave(" =3D t"); return true; =20 -out_of_addresses: +wait_for_more_probe_results: + error =3D afs_wait_for_one_fs_probe(op->server, op->estate, op->addr_trie= d, + !(op->flags & AFS_OPERATION_UNINTR)); + if (!error) + goto iterate_address; + /* We've now had a failure to respond on all of a server's addresses - * immediately probe them again and consider retrying the server. */ + trace_afs_rotate(op, afs_rotate_trace_probe_fileserver, 0); afs_probe_fileserver(op->net, op->server); if (op->flags & AFS_OPERATION_RETRY_SERVER) { - error =3D afs_wait_for_one_fs_probe(op->server, estate, + error =3D afs_wait_for_one_fs_probe(op->server, op->estate, op->addr_tri= ed, !(op->flags & AFS_OPERATION_UNINTR)); switch (error) { case 0: op->flags &=3D ~AFS_OPERATION_RETRY_SERVER; + trace_afs_rotate(op, afs_rotate_trace_retry_server, 0); goto retry_server; case -ERESTARTSYS: afs_op_set_error(op, error); @@ -548,30 +643,33 @@ bool afs_select_fileserver(struct afs_operation *op) } =20 next_server: + trace_afs_rotate(op, afs_rotate_trace_next_server, 0); _debug("next"); - ASSERT(estate); - alist =3D estate->addresses; + ASSERT(op->estate); + alist =3D op->estate->addresses; if (op->call_responded && op->addr_index !=3D READ_ONCE(alist->preferred) && test_bit(alist->preferred, &op->addr_tried)) WRITE_ONCE(alist->preferred, op->addr_index); - afs_put_endpoint_state(estate, afs_estate_trace_put_next_server); - estate =3D op->estate =3D NULL; + op->estate =3D NULL; goto pick_server; =20 no_more_servers: /* That's all the servers poked to no good effect. Try again if some * of them were busy. */ - if (op->flags & AFS_OPERATION_VBUSY) + trace_afs_rotate(op, afs_rotate_trace_no_more_servers, 0); + if (op->flags & AFS_OPERATION_VBUSY) { + afs_sleep_and_retry(op); + op->flags &=3D ~AFS_OPERATION_VBUSY; goto restart_from_beginning; + } =20 rcu_read_lock(); for (i =3D 0; i < op->server_list->nr_servers; i++) { struct afs_endpoint_state *estate; - struct afs_server *s =3D op->server_list->servers[i].server; =20 - estate =3D rcu_dereference(s->endpoint_state); + estate =3D op->server_states->endpoint_state; error =3D READ_ONCE(estate->error); if (error < 0) afs_op_accumulate_error(op, error, estate->abort_code); @@ -579,14 +677,14 @@ bool afs_select_fileserver(struct afs_operation *op) rcu_read_unlock(); =20 failed: + trace_afs_rotate(op, afs_rotate_trace_failed, 0); op->flags |=3D AFS_OPERATION_STOP; - if (estate) { - alist =3D estate->addresses; + if (op->estate) { + alist =3D op->estate->addresses; if (op->call_responded && op->addr_index !=3D READ_ONCE(alist->preferred) && test_bit(alist->preferred, &op->addr_tried)) WRITE_ONCE(alist->preferred, op->addr_index); - afs_put_endpoint_state(estate, afs_estate_trace_put_op_failed); op->estate =3D NULL; } _leave(" =3D f [failed %d]", afs_op_error(op)); @@ -619,8 +717,8 @@ void afs_dump_edestaddrreq(const struct afs_operation *= op) if (op->server_list) { const struct afs_server_list *sl =3D op->server_list; =20 - pr_notice("FC: SL nr=3D%u pr=3D%u vnov=3D%hx\n", - sl->nr_servers, sl->preferred, sl->vnovol_mask); + pr_notice("FC: SL nr=3D%u vnov=3D%hx\n", + sl->nr_servers, sl->vnovol_mask); for (i =3D 0; i < sl->nr_servers; i++) { const struct afs_server *s =3D sl->servers[i].server; const struct afs_endpoint_state *e =3D diff --git a/fs/afs/server_list.c b/fs/afs/server_list.c index ac4a7afff45e..7e7e567a7f8a 100644 --- a/fs/afs/server_list.c +++ b/fs/afs/server_list.c @@ -134,8 +134,7 @@ bool afs_annotate_server_list(struct afs_server_list *n= ew, struct afs_server_list *old) { unsigned long mask =3D 1UL << AFS_SE_EXCLUDED; - struct afs_server *cur; - int i, j; + int i; =20 if (old->nr_servers !=3D new->nr_servers || old->ro_replicating !=3D new->ro_replicating) @@ -148,18 +147,7 @@ bool afs_annotate_server_list(struct afs_server_list *= new, goto changed; } return false; - changed: - /* Maintain the same preferred server as before if possible. */ - cur =3D old->servers[old->preferred].server; - for (j =3D 0; j < new->nr_servers; j++) { - if (new->servers[j].server =3D=3D cur) { - if (!test_bit(AFS_SE_EXCLUDED, &new->servers[j].flags)) - new->preferred =3D j; - break; - } - } - return true; } =20 diff --git a/fs/afs/volume.c b/fs/afs/volume.c index cc207dca1b21..020ecd45e476 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -397,7 +397,11 @@ static int afs_update_volume_status(struct afs_volume = *volume, struct key *key) discard =3D old; } =20 - volume->update_at =3D ktime_get_real_seconds() + afs_volume_record_life; + /* Check more often if replication is ongoing. */ + if (new->ro_replicating) + volume->update_at =3D ktime_get_real_seconds() + 10 * 60; + else + volume->update_at =3D ktime_get_real_seconds() + afs_volume_record_life; write_unlock(&volume->servers_lock); =20 if (discard =3D=3D old) diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index 2df7d0fd3f21..b2e0847eca47 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -230,15 +230,12 @@ enum yfs_cm_operation { #define afs_estate_traces \ EM(afs_estate_trace_alloc_probe, "ALLOC prob") \ EM(afs_estate_trace_alloc_server, "ALLOC srvr") \ - EM(afs_estate_trace_get_fsrotate_set, "GET fs-rot") \ + EM(afs_estate_trace_get_server_state, "GET srv-st") \ EM(afs_estate_trace_get_getcaps, "GET getcap") \ EM(afs_estate_trace_put_getcaps, "PUT getcap") \ - EM(afs_estate_trace_put_next_server, "PUT nx-srv") \ - EM(afs_estate_trace_put_op_failed, "PUT op-fai") \ - EM(afs_estate_trace_put_operation, "PUT op ") \ EM(afs_estate_trace_put_probe, "PUT probe ") \ - EM(afs_estate_trace_put_restart_rotate, "PUT rstrot") \ EM(afs_estate_trace_put_server, "PUT server") \ + EM(afs_estate_trace_put_server_state, "PUT srv-st") \ E_(afs_estate_trace_free, "FREE ") =20 #define afs_fs_operations \ @@ -448,6 +445,29 @@ enum yfs_cm_operation { EM(afs_cb_break_for_vos_release, "break-vos-release") \ E_(afs_cb_break_volume_excluded, "vol-excluded") =20 +#define afs_rotate_traces \ + EM(afs_rotate_trace_aborted, "Abortd") \ + EM(afs_rotate_trace_busy_sleep, "BsySlp") \ + EM(afs_rotate_trace_check_vol_status, "VolStt") \ + EM(afs_rotate_trace_failed, "Failed") \ + EM(afs_rotate_trace_iter, "Iter ") \ + EM(afs_rotate_trace_iterate_addr, "ItAddr") \ + EM(afs_rotate_trace_next_server, "NextSv") \ + EM(afs_rotate_trace_no_more_servers, "NoMore") \ + EM(afs_rotate_trace_nomem, "Nomem ") \ + EM(afs_rotate_trace_probe_error, "PrbErr") \ + EM(afs_rotate_trace_probe_fileserver, "PrbFsv") \ + EM(afs_rotate_trace_probe_none, "PrbNon") \ + EM(afs_rotate_trace_probe_response, "PrbRsp") \ + EM(afs_rotate_trace_probe_superseded, "PrbSup") \ + EM(afs_rotate_trace_restart, "Rstart") \ + EM(afs_rotate_trace_retry_server, "RtrySv") \ + EM(afs_rotate_trace_selected_server, "SlctSv") \ + EM(afs_rotate_trace_stale_lock, "StlLck") \ + EM(afs_rotate_trace_start, "Start ") \ + EM(afs_rotate_trace_stop, "Stop ") \ + E_(afs_rotate_trace_stopped, "Stoppd") + /* * Generate enums for tracing information. */ @@ -471,6 +491,7 @@ enum afs_file_error { afs_file_errors } __mode(byte); enum afs_flock_event { afs_flock_events } __mode(byte); enum afs_flock_operation { afs_flock_operations } __mode(byte); enum afs_io_error { afs_io_errors } __mode(byte); +enum afs_rotate_trace { afs_rotate_traces } __mode(byte); enum afs_server_trace { afs_server_traces } __mode(byte); enum afs_volume_trace { afs_volume_traces } __mode(byte); =20 @@ -486,21 +507,22 @@ enum afs_volume_trace { afs_volume_traces } __mode(b= yte); =20 afs_alist_traces; afs_call_traces; -afs_server_traces; +afs_cb_break_reasons; afs_cell_traces; -afs_fs_operations; -afs_vl_operations; afs_cm_operations; -yfs_cm_operations; afs_edit_dir_ops; afs_edit_dir_reasons; afs_eproto_causes; afs_estate_traces; -afs_io_errors; afs_file_errors; -afs_flock_types; afs_flock_operations; -afs_cb_break_reasons; +afs_flock_types; +afs_fs_operations; +afs_io_errors; +afs_rotate_traces; +afs_server_traces; +afs_vl_operations; +yfs_cm_operations; =20 /* * Now redefine the EM() and E_() macros to map the enums to the strings t= hat @@ -1519,6 +1541,41 @@ TRACE_EVENT(afs_vl_probe, &__entry->srx.transport) ); =20 +TRACE_EVENT(afs_rotate, + TP_PROTO(struct afs_operation *op, enum afs_rotate_trace reason, unsi= gned int extra), + + TP_ARGS(op, reason, extra), + + TP_STRUCT__entry( + __field(unsigned int, op) + __field(unsigned int, flags) + __field(unsigned int, extra) + __field(unsigned short, iteration) + __field(short, server_index) + __field(short, addr_index) + __field(enum afs_rotate_trace, reason) + ), + + TP_fast_assign( + __entry->op =3D op->debug_id; + __entry->flags =3D op->flags; + __entry->iteration =3D op->nr_iterations; + __entry->server_index =3D op->server_index; + __entry->addr_index =3D op->addr_index; + __entry->reason =3D reason; + __entry->extra =3D extra; + ), + + TP_printk("OP=3D%08x it=3D%02x %s fl=3D%x sx=3D%d ax=3D%d ext=3D%d", + __entry->op, + __entry->iteration, + __print_symbolic(__entry->reason, afs_rotate_traces), + __entry->flags, + __entry->server_index, + __entry->addr_index, + __entry->extra) + ); + #endif /* _TRACE_AFS_H */ =20 /* This part must be outside protection */ From nobody Mon Dec 15 21:24:35 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 4539DC4332F for ; Wed, 13 Dec 2023 13:53:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379338AbjLMNxC (ORCPT ); Wed, 13 Dec 2023 08:53:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379362AbjLMNwK (ORCPT ); Wed, 13 Dec 2023 08:52:10 -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 64E0C1725 for ; Wed, 13 Dec 2023 05:51:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475473; 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=Q6hid3YRr4Ej4toqLI+tj94dzeJmRJqcEJFRHPpyqoA=; b=QnUwwWl7O0sUh9cqEj7DRCxXqS8SfhNmFdpL0yPKOxXd85K8Lp8vBawYXndIg6uYDts8G3 le1YKGyhT2GEVxtsjTbPmjjB8PuGnXCavFCL/MD2X3zlHkixVBtrnf6XOQImPEOmNdfSY8 yUrWU2Vcb/nVAAIq2d6C4Pjchjj119I= 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-422-iVedxFAsO4SnDiTzLb4Iew-1; Wed, 13 Dec 2023 08:51:09 -0500 X-MC-Unique: iVedxFAsO4SnDiTzLb4Iew-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 B316D3C2A1CD; Wed, 13 Dec 2023 13:51:08 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id E88792166B31; Wed, 13 Dec 2023 13:51:07 +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 Subject: [PATCH v2 39/40] afs: Fix offline and busy message emission Date: Wed, 13 Dec 2023 13:50:01 +0000 Message-ID: <20231213135003.367397-40-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current code assumes that offline and busy volume states apply to all instances of a volume, not just the one on the server that returned VOFFLINE or VBUSY and will emit a notice to dmesg suggesting that the entire volume is unavailable. Fix that by moving the flags recording this to the afs_server_entry struct that is used to represent a particular instance of a volume on a specific server. The notice is altered to include the server UUID also. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/internal.h | 8 ++++---- fs/afs/rotate.c | 31 +++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/fs/afs/internal.h b/fs/afs/internal.h index e3e373c1fecf..a6a4fc417dba 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -612,6 +612,8 @@ struct afs_server_entry { time64_t cb_expires_at; /* Time at which volume-level callback expires */ unsigned long flags; #define AFS_SE_EXCLUDED 0 /* Set if server is to be excluded in rotation= */ +#define AFS_SE_VOLUME_OFFLINE 1 /* Set if volume offline notice given */ +#define AFS_SE_VOLUME_BUSY 2 /* Set if volume busy notice given */ }; =20 struct afs_server_list { @@ -645,10 +647,8 @@ struct afs_volume { #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */ #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */ #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */ -#define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */ -#define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */ -#define AFS_VOLUME_MAYBE_NO_IBULK 6 /* - T if some servers don't have Inli= neBulkStatus */ -#define AFS_VOLUME_RM_TREE 7 /* - Set if volume removed from cell->volumes= */ +#define AFS_VOLUME_MAYBE_NO_IBULK 4 /* - T if some servers don't have Inli= neBulkStatus */ +#define AFS_VOLUME_RM_TREE 5 /* - Set if volume removed from cell->volumes= */ #ifdef CONFIG_AFS_FSCACHE struct fscache_volume *cache; /* Caching cookie */ #endif diff --git a/fs/afs/rotate.c b/fs/afs/rotate.c index ef7fe70777be..700a27bc8c25 100644 --- a/fs/afs/rotate.c +++ b/fs/afs/rotate.c @@ -111,7 +111,7 @@ static bool afs_start_fs_iteration(struct afs_operation= *op, /* * Post volume busy note. */ -static void afs_busy(struct afs_volume *volume, u32 abort_code) +static void afs_busy(struct afs_operation *op, u32 abort_code) { const char *m; =20 @@ -122,7 +122,8 @@ static void afs_busy(struct afs_volume *volume, u32 abo= rt_code) default: m =3D "busy"; break; } =20 - pr_notice("kAFS: Volume %llu '%s' is %s\n", volume->vid, volume->name, m); + pr_notice("kAFS: Volume %llu '%s' on server %pU is %s\n", + op->volume->vid, op->volume->name, &op->server->uuid, m); } =20 /* @@ -181,6 +182,10 @@ bool afs_select_fileserver(struct afs_operation *op) /* Evaluate the result of the previous operation, if there was one. */ switch (op->call_error) { case 0: + clear_bit(AFS_SE_VOLUME_OFFLINE, + &op->server_list->servers[op->server_index].flags); + clear_bit(AFS_SE_VOLUME_BUSY, + &op->server_list->servers[op->server_index].flags); op->cumul_error.responded =3D true; =20 /* We succeeded, but we may need to redo the op from another @@ -314,9 +319,11 @@ bool afs_select_fileserver(struct afs_operation *op) * expected to come back but it might take a long time (could be * days). */ - if (!test_and_set_bit(AFS_VOLUME_OFFLINE, &op->volume->flags)) { - afs_busy(op->volume, abort_code); - clear_bit(AFS_VOLUME_BUSY, &op->volume->flags); + if (!test_and_set_bit(AFS_SE_VOLUME_OFFLINE, + &op->server_list->servers[op->server_index].flags)) { + afs_busy(op, abort_code); + clear_bit(AFS_SE_VOLUME_BUSY, + &op->server_list->servers[op->server_index].flags); } if (op->flags & AFS_OPERATION_NO_VSLEEP) { afs_op_set_error(op, -EADV); @@ -343,9 +350,11 @@ bool afs_select_fileserver(struct afs_operation *op) afs_op_set_error(op, -EBUSY); goto failed; } - if (!test_and_set_bit(AFS_VOLUME_BUSY, &op->volume->flags)) { - afs_busy(op->volume, abort_code); - clear_bit(AFS_VOLUME_OFFLINE, &op->volume->flags); + if (!test_and_set_bit(AFS_SE_VOLUME_BUSY, + &op->server_list->servers[op->server_index].flags)) { + afs_busy(op, abort_code); + clear_bit(AFS_SE_VOLUME_OFFLINE, + &op->server_list->servers[op->server_index].flags); } busy: if (op->flags & AFS_OPERATION_CUR_ONLY) { @@ -426,8 +435,10 @@ bool afs_select_fileserver(struct afs_operation *op) default: afs_op_accumulate_error(op, error, abort_code); failed_but_online: - clear_bit(AFS_VOLUME_OFFLINE, &op->volume->flags); - clear_bit(AFS_VOLUME_BUSY, &op->volume->flags); + clear_bit(AFS_SE_VOLUME_OFFLINE, + &op->server_list->servers[op->server_index].flags); + clear_bit(AFS_SE_VOLUME_BUSY, + &op->server_list->servers[op->server_index].flags); goto failed; } From nobody Mon Dec 15 21:24:35 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 39CF7C4332F for ; Wed, 13 Dec 2023 13:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441855AbjLMNxI (ORCPT ); Wed, 13 Dec 2023 08:53:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441801AbjLMNwL (ORCPT ); Wed, 13 Dec 2023 08:52:11 -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 17B44194 for ; Wed, 13 Dec 2023 05:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475472; 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=K2ZPB2Sqot0p4TOyHCibD/tw6vL1F8SxZQh+gHOn/Ek=; b=IHYmn01lMEpimi2uOEbdsKWdNhN6bgavhLrSiqwHWKYJuvKiWNewco0B88Nzzz6/9FlNxX 7goxAAuU4YijuC51plCMU3XHYMZwxDZv9PtcSCyqZFyeyrpFTslx5CvSQSnFWjK36g38ba HN9ZYFdtnBwQ2oW3pAR8BPvcQGO0j6g= 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-185-7mEwBPkDN8ifMnrgBIHurg-1; Wed, 13 Dec 2023 08:51:10 -0500 X-MC-Unique: 7mEwBPkDN8ifMnrgBIHurg-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 66700837193; Wed, 13 Dec 2023 13:51:10 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71A462166B31; Wed, 13 Dec 2023 13:51:09 +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 Subject: [PATCH v2 40/40] afs: trace: Log afs_make_call(), including server address Date: Wed, 13 Dec 2023 13:50:02 +0000 Message-ID: <20231213135003.367397-41-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a tracepoint to log calls to afs_make_call(), including the destination server address. Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/fsclient.c | 22 ++++++++++++++++++++++ fs/afs/internal.h | 1 + fs/afs/rxrpc.c | 2 ++ fs/afs/yfsclient.c | 20 ++++++++++++++++++++ include/trace/events/afs.h | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+) diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c index 80f7d9e796e3..79cd30775b7a 100644 --- a/fs/afs/fsclient.c +++ b/fs/afs/fsclient.c @@ -290,6 +290,7 @@ void afs_fs_fetch_status(struct afs_operation *op) bp[2] =3D htonl(vp->fid.vnode); bp[3] =3D htonl(vp->fid.unique); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -442,6 +443,7 @@ static void afs_fs_fetch_data64(struct afs_operation *o= p) bp[6] =3D 0; bp[7] =3D htonl(lower_32_bits(req->len)); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -476,6 +478,7 @@ void afs_fs_fetch_data(struct afs_operation *op) bp[4] =3D htonl(lower_32_bits(req->pos)); bp[5] =3D htonl(lower_32_bits(req->len)); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -559,6 +562,7 @@ void afs_fs_create_file(struct afs_operation *op) *bp++ =3D htonl(op->create.mode & S_IALLUGO); /* unix mode */ *bp++ =3D 0; /* segment size */ =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -612,6 +616,7 @@ void afs_fs_make_dir(struct afs_operation *op) *bp++ =3D htonl(op->create.mode & S_IALLUGO); /* unix mode */ *bp++ =3D 0; /* segment size */ =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -685,6 +690,7 @@ void afs_fs_remove_file(struct afs_operation *op) bp =3D (void *) bp + padsz; } =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -732,6 +738,7 @@ void afs_fs_remove_dir(struct afs_operation *op) bp =3D (void *) bp + padsz; } =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -812,6 +819,7 @@ void afs_fs_link(struct afs_operation *op) *bp++ =3D htonl(vp->fid.vnode); *bp++ =3D htonl(vp->fid.unique); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call1(call, &vp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -907,6 +915,7 @@ void afs_fs_symlink(struct afs_operation *op) *bp++ =3D htonl(S_IRWXUGO); /* unix mode */ *bp++ =3D 0; /* segment size */ =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -1003,6 +1012,7 @@ void afs_fs_rename(struct afs_operation *op) bp =3D (void *) bp + n_padsz; } =20 + call->fid =3D orig_dvp->fid; trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name); afs_make_op_call(op, call, GFP_NOFS); } @@ -1090,6 +1100,7 @@ static void afs_fs_store_data64(struct afs_operation = *op) *bp++ =3D htonl(upper_32_bits(op->store.i_size)); *bp++ =3D htonl(lower_32_bits(op->store.i_size)); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1140,6 +1151,7 @@ void afs_fs_store_data(struct afs_operation *op) *bp++ =3D htonl(lower_32_bits(op->store.size)); *bp++ =3D htonl(lower_32_bits(op->store.i_size)); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1206,6 +1218,7 @@ static void afs_fs_setattr_size64(struct afs_operatio= n *op) *bp++ =3D htonl(upper_32_bits(attr->ia_size)); /* new file length */ *bp++ =3D htonl(lower_32_bits(attr->ia_size)); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1247,6 +1260,7 @@ static void afs_fs_setattr_size(struct afs_operation = *op) *bp++ =3D 0; /* size of write */ *bp++ =3D htonl(attr->ia_size); /* new file length */ =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1283,6 +1297,7 @@ void afs_fs_setattr(struct afs_operation *op) =20 xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1446,6 +1461,7 @@ void afs_fs_get_volume_status(struct afs_operation *o= p) bp[0] =3D htonl(FSGETVOLUMESTATUS); bp[1] =3D htonl(vp->fid.vid); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1528,6 +1544,7 @@ void afs_fs_set_lock(struct afs_operation *op) *bp++ =3D htonl(vp->fid.unique); *bp++ =3D htonl(op->lock.type); =20 + call->fid =3D vp->fid; trace_afs_make_fs_calli(call, &vp->fid, op->lock.type); afs_make_op_call(op, call, GFP_NOFS); } @@ -1554,6 +1571,7 @@ void afs_fs_extend_lock(struct afs_operation *op) *bp++ =3D htonl(vp->fid.vnode); *bp++ =3D htonl(vp->fid.unique); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1580,6 +1598,7 @@ void afs_fs_release_lock(struct afs_operation *op) *bp++ =3D htonl(vp->fid.vnode); *bp++ =3D htonl(vp->fid.unique); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1948,6 +1967,7 @@ void afs_fs_inline_bulk_status(struct afs_operation *= op) *bp++ =3D htonl(op->more_files[i].fid.unique); } =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -2053,6 +2073,7 @@ void afs_fs_fetch_acl(struct afs_operation *op) bp[2] =3D htonl(vp->fid.vnode); bp[3] =3D htonl(vp->fid.unique); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_KERNEL); } @@ -2098,6 +2119,7 @@ void afs_fs_store_acl(struct afs_operation *op) if (acl->size !=3D size) memset((void *)&bp[5] + acl->size, 0, size - acl->size); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_KERNEL); } diff --git a/fs/afs/internal.h b/fs/afs/internal.h index a6a4fc417dba..e33ace259cc6 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -153,6 +153,7 @@ struct afs_call { struct afs_vldb_entry *ret_vldb; char *ret_str; }; + struct afs_fid fid; /* Primary vnode ID (or all zeroes) */ unsigned char probe_index; /* Address in ->probe_alist */ struct afs_operation *op; unsigned int server_index; diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c index 81013bc8bbfd..c453428f3c8b 100644 --- a/fs/afs/rxrpc.c +++ b/fs/afs/rxrpc.c @@ -313,6 +313,8 @@ void afs_make_call(struct afs_call *call, gfp_t gfp) call, call->type->name, key_serial(call->key), atomic_read(&call->net->nr_outstanding_calls)); =20 + trace_afs_make_call(call); + /* Work out the length we're going to transmit. This is awkward for * calls such as FS.StoreData where there's an extra injection of data * after the initial fixed part. diff --git a/fs/afs/yfsclient.c b/fs/afs/yfsclient.c index 2d6943f05ea5..f521e66d3bf6 100644 --- a/fs/afs/yfsclient.c +++ b/fs/afs/yfsclient.c @@ -493,6 +493,7 @@ void yfs_fs_fetch_data(struct afs_operation *op) bp =3D xdr_encode_u64(bp, req->len); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -575,6 +576,7 @@ void yfs_fs_create_file(struct afs_operation *op) bp =3D xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */ yfs_check_req(call, bp); =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -623,6 +625,7 @@ void yfs_fs_make_dir(struct afs_operation *op) bp =3D xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime); yfs_check_req(call, bp); =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -707,6 +710,7 @@ void yfs_fs_remove_file2(struct afs_operation *op) bp =3D xdr_encode_name(bp, name); yfs_check_req(call, bp); =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -776,6 +780,7 @@ void yfs_fs_remove_file(struct afs_operation *op) bp =3D xdr_encode_name(bp, name); yfs_check_req(call, bp); =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -817,6 +822,7 @@ void yfs_fs_remove_dir(struct afs_operation *op) bp =3D xdr_encode_name(bp, name); yfs_check_req(call, bp); =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -890,6 +896,7 @@ void yfs_fs_link(struct afs_operation *op) bp =3D xdr_encode_YFSFid(bp, &vp->fid); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call1(call, &vp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -971,6 +978,7 @@ void yfs_fs_symlink(struct afs_operation *op) bp =3D xdr_encode_YFSStoreStatus(bp, &mode, &op->mtime); yfs_check_req(call, bp); =20 + call->fid =3D dvp->fid; trace_afs_make_fs_call1(call, &dvp->fid, name); afs_make_op_call(op, call, GFP_NOFS); } @@ -1050,6 +1058,7 @@ void yfs_fs_rename(struct afs_operation *op) bp =3D xdr_encode_name(bp, new_name); yfs_check_req(call, bp); =20 + call->fid =3D orig_dvp->fid; trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name); afs_make_op_call(op, call, GFP_NOFS); } @@ -1105,6 +1114,7 @@ void yfs_fs_store_data(struct afs_operation *op) bp =3D xdr_encode_u64(bp, op->store.i_size); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1161,6 +1171,7 @@ static void yfs_fs_setattr_size(struct afs_operation = *op) bp =3D xdr_encode_u64(bp, attr->ia_size); /* new file length */ yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1199,6 +1210,7 @@ void yfs_fs_setattr(struct afs_operation *op) bp =3D xdr_encode_YFS_StoreStatus(bp, attr); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1369,6 +1381,7 @@ void yfs_fs_get_volume_status(struct afs_operation *o= p) bp =3D xdr_encode_u64(bp, vp->fid.vid); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1433,6 +1446,7 @@ void yfs_fs_set_lock(struct afs_operation *op) bp =3D xdr_encode_u32(bp, op->lock.type); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_calli(call, &vp->fid, op->lock.type); afs_make_op_call(op, call, GFP_NOFS); } @@ -1463,6 +1477,7 @@ void yfs_fs_extend_lock(struct afs_operation *op) bp =3D xdr_encode_YFSFid(bp, &vp->fid); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1493,6 +1508,7 @@ void yfs_fs_release_lock(struct afs_operation *op) bp =3D xdr_encode_YFSFid(bp, &vp->fid); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1559,6 +1575,7 @@ void yfs_fs_fetch_status(struct afs_operation *op) bp =3D xdr_encode_YFSFid(bp, &vp->fid); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1739,6 +1756,7 @@ void yfs_fs_inline_bulk_status(struct afs_operation *= op) bp =3D xdr_encode_YFSFid(bp, &op->more_files[i].fid); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_NOFS); } @@ -1901,6 +1919,7 @@ void yfs_fs_fetch_opaque_acl(struct afs_operation *op) bp =3D xdr_encode_YFSFid(bp, &vp->fid); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_KERNEL); } @@ -1951,6 +1970,7 @@ void yfs_fs_store_opaque_acl2(struct afs_operation *o= p) bp +=3D size / sizeof(__be32); yfs_check_req(call, bp); =20 + call->fid =3D vp->fid; trace_afs_make_fs_call(call, &vp->fid); afs_make_op_call(op, call, GFP_KERNEL); } diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index b2e0847eca47..5194b7e6dc8d 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -1576,6 +1576,42 @@ TRACE_EVENT(afs_rotate, __entry->extra) ); =20 +TRACE_EVENT(afs_make_call, + TP_PROTO(struct afs_call *call), + + TP_ARGS(call), + + TP_STRUCT__entry( + __field(unsigned int, call) + __field(bool, is_vl) + __field(enum afs_fs_operation, op) + __field_struct(struct afs_fid, fid) + __field_struct(struct sockaddr_rxrpc, srx) + ), + + TP_fast_assign( + __entry->call =3D call->debug_id; + __entry->op =3D call->operation_ID; + __entry->fid =3D call->fid; + memcpy(&__entry->srx, rxrpc_kernel_remote_srx(call->peer), + sizeof(__entry->srx)); + __entry->srx.srx_service =3D call->service_id; + __entry->is_vl =3D (__entry->srx.srx_service =3D=3D VL_SERVICE || + __entry->srx.srx_service =3D=3D YFS_VL_SERVICE); + ), + + TP_printk("c=3D%08x %pISpc+%u %s %llx:%llx:%x", + __entry->call, + &__entry->srx.transport, + __entry->srx.srx_service, + __entry->is_vl ? + __print_symbolic(__entry->op, afs_vl_operations) : + __print_symbolic(__entry->op, afs_fs_operations), + __entry->fid.vid, + __entry->fid.vnode, + __entry->fid.unique) + ); + #endif /* _TRACE_AFS_H */ =20 /* This part must be outside protection */