Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Samuel Cabrero <scabrero@suse.com>
To: linux-cifs@vger.kernel.org
Cc: smfrench@gmail.com, pc@manguebit.com, ronniesahlberg@gmail.com,
	sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com,
	henrique.carvalho@suse.com, ematsumiya@suse.de,
	Samuel Cabrero <scabrero@suse.com>
Subject: [PATCH 18/18] smb:client: Avoid witness re-register if the address did not change
Date: Fri, 10 Jul 2026 11:16:37 +0200	[thread overview]
Message-ID: <20260710091637.58873-19-scabrero@suse.com> (raw)
In-Reply-To: <20260710091637.58873-1-scabrero@suse.com>

If received a client-move notification with a destination address
matching the current one, skip unregister and register to the same
address.

Signed-off-by: Samuel Cabrero <scabrero@suse.com>
---
 fs/smb/client/cifs_swn.c | 67 ++++++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 34 deletions(-)

diff --git a/fs/smb/client/cifs_swn.c b/fs/smb/client/cifs_swn.c
index a196b06c4b8c..fabde01d998a 100644
--- a/fs/smb/client/cifs_swn.c
+++ b/fs/smb/client/cifs_swn.c
@@ -626,7 +626,7 @@ static struct cifs_swn_reg *cifs_find_swn_reg(struct cifs_tcon *tcon)
 	return ERR_PTR(-ENOENT);
 }
 
-static void cifs_swn_resource_state_changed(struct cifs_tcon *tcon,
+static bool cifs_swn_resource_state_changed(struct cifs_tcon *tcon,
 					    const char *name, int state)
 {
 	switch (state) {
@@ -642,6 +642,9 @@ static void cifs_swn_resource_state_changed(struct cifs_tcon *tcon,
 		cifs_dbg(FYI, "%s: resource name '%s' changed to unknown state\n", __func__, name);
 		break;
 	}
+
+	/* Address has not changed */
+	return false;
 }
 
 static int cifs_swn_store_swn_addr(const struct sockaddr_storage *new,
@@ -678,21 +681,16 @@ static int cifs_swn_store_swn_addr(const struct sockaddr_storage *new,
 static bool cifs_swn_client_move(struct cifs_tcon *tcon,
 				 struct sockaddr_storage *addr)
 {
-	struct sockaddr_in *ipv4 = (struct sockaddr_in *)addr;
-	struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)addr;
 	int ret;
 
-	if (addr->ss_family == AF_INET)
-		cifs_dbg(FYI, "%s: move to %pI4\n", __func__, &ipv4->sin_addr);
-	else if (addr->ss_family == AF_INET6)
-		cifs_dbg(FYI, "%s: move to %pI6\n", __func__, &ipv6->sin6_addr);
-
 	if (cifs_match_ipaddr((struct sockaddr *)&tcon->ses->server->dstaddr,
 			      (struct sockaddr *)addr)) {
 		/* no-op */
 		return false;
 	}
 
+	cifs_dbg(FYI, "%s: move to %pISc\n", __func__, addr);
+
 	/* Store the reconnect address */
 	ret = cifs_swn_store_swn_addr(addr, &tcon->ses->server->dstaddr,
 				      &tcon->ses->server->swn_dstaddr);
@@ -705,6 +703,7 @@ static bool cifs_swn_client_move(struct cifs_tcon *tcon,
 
 	cifs_signal_cifsd_for_reconnect(tcon->ses->server, false);
 
+	/* Address changed */
 	return true;
 }
 
@@ -719,10 +718,9 @@ cifs_swn_handle_notification_tcon(const struct cifs_swn_notification *not,
 {
 	switch (not->type) {
 	case CIFS_SWN_NOTIFICATION_RESOURCE_CHANGE:
-		cifs_swn_resource_state_changed(
+		return cifs_swn_resource_state_changed(
 			tcon, not->data.resource_name_changed.name,
 			not->data.resource_name_changed.state);
-		return false;
 	case CIFS_SWN_NOTIFICATION_CLIENT_MOVE:
 		return cifs_swn_client_move(tcon, not->data.client_move.addr);
 	default:
@@ -743,6 +741,7 @@ static int cifs_swn_handle_notification(const struct cifs_swn_notification *not)
 	struct TCP_Server_Info *server;
 	struct cifs_ses *ses;
 	struct cifs_tcon *tcon;
+	bool addr_changed = false;
 	int ret;
 
 	/* Walk the tcons and apply the notification to matching ones */
@@ -761,7 +760,9 @@ static int cifs_swn_handle_notification(const struct cifs_swn_notification *not)
 					spin_unlock(&tcon->tc_lock);
 					continue;
 				}
-				cifs_swn_handle_notification_tcon(not, tcon);
+				addr_changed |=
+					cifs_swn_handle_notification_tcon(not,
+									  tcon);
 				spin_unlock(&tcon->tc_lock);
 			}
 		}
@@ -769,31 +770,29 @@ static int cifs_swn_handle_notification(const struct cifs_swn_notification *not)
 	}
 	spin_unlock(&cifs_tcp_ses_lock);
 
-	switch (not->type) {
-	case CIFS_SWN_NOTIFICATION_CLIENT_MOVE:
-		/* Unregister from the current address */
-		ret = cifs_swn_send_unregister_message(not->swnreg);
-		if (ret < 0) {
-			cifs_dbg(VFS,
-				 "%s: Failed to unregister for witness notifications: %d\n",
-				 __func__, ret);
-		}
+	if (!addr_changed)
+		return 0;
 
-		/* Store the new address */
-		not->swnreg->addr = *not->data.client_move.addr;
+	/*
+	 * If the address has changed, unregister from the previous and
+	 * register for the new one
+	 */
+	ret = cifs_swn_send_unregister_message(not->swnreg);
+	if (ret < 0) {
+		cifs_dbg(VFS,
+			"%s: Failed to unregister for witness notifications: %d\n",
+			__func__, ret);
+	}
 
-		/* Register for this new address */
-		ret = cifs_swn_send_register_message(not->swnreg);
-		if (ret < 0) {
-			cifs_dbg(VFS,
-				 "%s: Failed to register for witness notifications: %d\n",
-				 __func__, ret);
-		}
-		break;
-	default:
-		cifs_dbg(FYI, "%s: unknown notification type %d\n", __func__,
-			 not->type);
-		break;
+	/* Store the new address */
+	not->swnreg->addr = *not->data.client_move.addr;
+
+	/* Register for this new address */
+	ret = cifs_swn_send_register_message(not->swnreg);
+	if (ret < 0) {
+		cifs_dbg(VFS,
+			"%s: Failed to register for witness notifications: %d\n",
+			__func__, ret);
 	}
 
 	return 0;
-- 
2.54.0


  parent reply	other threads:[~2026-07-10  9:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  9:16 [PATCH 00/18] SWN: Decouple witness registrations and tcons Samuel Cabrero
2026-07-10  9:16 ` [PATCH 01/18] Revert "smb: client: resolve SWN tcon from live registrations" Samuel Cabrero
2026-07-10  9:16 ` [PATCH 02/18] smb:client: Adjust witness notification request Samuel Cabrero
2026-07-10  9:16 ` [PATCH 03/18] smb:client: Rename variable to match the rest of the code Samuel Cabrero
2026-07-10  9:16 ` [PATCH 04/18] smb:client: Split idr remove and release functions Samuel Cabrero
2026-07-10  9:16 ` [PATCH 05/18] smb:client: Add a specific task to refresh witness registrations Samuel Cabrero
2026-07-10  9:16 ` [PATCH 06/18] smb:client: Store the tcon dstaddr in the witness registration Samuel Cabrero
2026-07-10  9:16 ` [PATCH 07/18] smb:client: Fix printf format string Samuel Cabrero
2026-07-10  9:16 ` [PATCH 08/18] smb:client: Save memory allocations Samuel Cabrero
2026-07-10  9:16 ` [PATCH 09/18] smb:client: Use the correct return code Samuel Cabrero
2026-07-10  9:16 ` [PATCH 10/18] smb:client: Improve tcon matching logic Samuel Cabrero
2026-07-10  9:16 ` [PATCH 11/18] smb:client: Pass the tcon to cifs_swn_send_register_message Samuel Cabrero
2026-07-10  9:16 ` [PATCH 12/18] smb:client: Pass the tcon to notification handlers Samuel Cabrero
2026-07-10  9:16 ` [PATCH 13/18] smb:client: Introduce swn_notification struct Samuel Cabrero
2026-07-10  9:16 ` [PATCH 14/18] smb:client: Cache auth info Samuel Cabrero
2026-07-10  9:16 ` [PATCH 15/18] smb:client: Do not store the tcon reference, find a matching one Samuel Cabrero
2026-07-10  9:16 ` [PATCH 16/18] smb:client: Simplify registration creation Samuel Cabrero
2026-07-10  9:16 ` [PATCH 17/18] smb:client: Improve registration network and share names handling Samuel Cabrero
2026-07-10  9:16 ` Samuel Cabrero [this message]
2026-07-10 14:16 ` [PATCH 00/18] SWN: Decouple witness registrations and tcons Enzo Matsumiya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260710091637.58873-19-scabrero@suse.com \
    --to=scabrero@suse.com \
    --cc=bharathsm@microsoft.com \
    --cc=ematsumiya@suse.de \
    --cc=henrique.carvalho@suse.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=pc@manguebit.com \
    --cc=ronniesahlberg@gmail.com \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox