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 06/18] smb:client: Store the tcon dstaddr in the witness registration
Date: Fri, 10 Jul 2026 11:16:25 +0200 [thread overview]
Message-ID: <20260710091637.58873-7-scabrero@suse.com> (raw)
In-Reply-To: <20260710091637.58873-1-scabrero@suse.com>
Prepare to remove the tcon pointer from cifs_swn_reg struct.
Always use the address stored in the swnreg to send the register netlink
message.
To find the swnreg matching a tcon the stored address is compared to the
tcon dstaddr.
Signed-off-by: Samuel Cabrero <scabrero@suse.com>
---
fs/smb/client/cifs_swn.c | 125 ++++++++++++++++++---------------------
1 file changed, 56 insertions(+), 69 deletions(-)
diff --git a/fs/smb/client/cifs_swn.c b/fs/smb/client/cifs_swn.c
index 36e199eb04c1..a33caaf4aaf0 100644
--- a/fs/smb/client/cifs_swn.c
+++ b/fs/smb/client/cifs_swn.c
@@ -25,6 +25,7 @@ struct cifs_swn_reg {
const char *net_name;
const char *share_name;
+ struct sockaddr_storage addr;
bool net_name_notify;
bool share_name_notify;
bool ip_notify;
@@ -81,7 +82,6 @@ static int cifs_swn_send_register_message(struct cifs_swn_reg *swnreg)
struct sk_buff *skb;
struct genlmsghdr *hdr;
enum securityEnum authtype;
- struct sockaddr_storage *addr;
int ret;
skb = genlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
@@ -106,18 +106,8 @@ static int cifs_swn_send_register_message(struct cifs_swn_reg *swnreg)
if (ret < 0)
goto nlmsg_fail;
- /*
- * If there is an address stored use it instead of the server address, because we are
- * in the process of reconnecting to it after a share has been moved or we have been
- * told to switch to it (client move message). In these cases we unregister from the
- * server address and register to the new address when we receive the notification.
- */
- if (swnreg->tcon->ses->server->use_swn_dstaddr)
- addr = &swnreg->tcon->ses->server->swn_dstaddr;
- else
- addr = &swnreg->tcon->ses->server->dstaddr;
-
- ret = nla_put(skb, CIFS_GENL_ATTR_SWN_IP, sizeof(struct sockaddr_storage), addr);
+ ret = nla_put(skb, CIFS_GENL_ATTR_SWN_IP,
+ sizeof(struct sockaddr_storage), &swnreg->addr);
if (ret < 0)
goto nlmsg_fail;
@@ -207,8 +197,8 @@ static int cifs_swn_send_unregister_message(struct cifs_swn_reg *swnreg)
if (ret < 0)
goto nlmsg_fail;
- ret = nla_put(skb, CIFS_GENL_ATTR_SWN_IP, sizeof(struct sockaddr_storage),
- &swnreg->tcon->ses->server->dstaddr);
+ ret = nla_put(skb, CIFS_GENL_ATTR_SWN_IP,
+ sizeof(struct sockaddr_storage), &swnreg->addr);
if (ret < 0)
goto nlmsg_fail;
@@ -290,7 +280,6 @@ static void cifs_swn_reg_check(struct work_struct *work)
}
mutex_unlock(&cifs_swnreg_idr_mutex);
-
/*
* It is safe to send the registration message multiple times.
* The userspace client library tracks if registered or not
@@ -347,13 +336,23 @@ static struct cifs_swn_reg *cifs_find_swn_reg(struct cifs_tcon *tcon)
}
idr_for_each_entry(&cifs_swnreg_idr, swnreg, id) {
- if (strcasecmp(swnreg->net_name, net_name) != 0
- || strcasecmp(swnreg->share_name, share_name) != 0) {
+ struct sockaddr_storage *tcon_dstaddr;
+
+ if (tcon->ses->server->use_swn_dstaddr)
+ tcon_dstaddr = &tcon->ses->server->swn_dstaddr;
+ else
+ tcon_dstaddr = &tcon->ses->server->dstaddr;
+
+ if (strcasecmp(swnreg->net_name, net_name) != 0 ||
+ strcasecmp(swnreg->share_name, share_name) != 0 ||
+ !cifs_match_ipaddr((struct sockaddr *)&swnreg->addr,
+ (struct sockaddr *)tcon_dstaddr)) {
continue;
}
- cifs_dbg(FYI, "Existing swn registration for %s:%s found\n", swnreg->net_name,
- swnreg->share_name);
+ cifs_dbg(FYI,
+ "Existing swn registration for %pISc:%s:%s found\n",
+ &swnreg->addr, swnreg->net_name, swnreg->share_name);
kfree(net_name);
kfree(share_name);
@@ -416,6 +415,17 @@ static struct cifs_swn_reg *cifs_get_swn_reg(struct cifs_tcon *tcon)
goto fail_net_name;
}
+ /*
+ * If there is an address stored use it instead of the server address, because we are
+ * in the process of reconnecting to it after a share has been moved or we have been
+ * told to switch to it (client move message). In these cases we unregister from the
+ * server address and register to the new address when we receive the notification.
+ */
+ if (tcon->ses->server->use_swn_dstaddr)
+ swnreg->addr = tcon->ses->server->swn_dstaddr;
+ else
+ swnreg->addr = tcon->ses->server->dstaddr;
+
swnreg->net_name_notify = true;
swnreg->share_name_notify =
(tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC);
@@ -461,26 +471,6 @@ static int cifs_swn_resource_state_changed(struct cifs_swn_reg *swnreg, const ch
return 0;
}
-static bool cifs_sockaddr_equal(struct sockaddr_storage *addr1, struct sockaddr_storage *addr2)
-{
- if (addr1->ss_family != addr2->ss_family)
- return false;
-
- if (addr1->ss_family == AF_INET) {
- return (memcmp(&((const struct sockaddr_in *)addr1)->sin_addr,
- &((const struct sockaddr_in *)addr2)->sin_addr,
- sizeof(struct in_addr)) == 0);
- }
-
- if (addr1->ss_family == AF_INET6) {
- return (memcmp(&((const struct sockaddr_in6 *)addr1)->sin6_addr,
- &((const struct sockaddr_in6 *)addr2)->sin6_addr,
- sizeof(struct in6_addr)) == 0);
- }
-
- return false;
-}
-
static int cifs_swn_store_swn_addr(const struct sockaddr_storage *new,
const struct sockaddr_storage *old,
struct sockaddr_storage *dst)
@@ -516,18 +506,13 @@ static int cifs_swn_reconnect(struct cifs_tcon *tcon, struct sockaddr_storage *a
{
int ret = 0;
- /* Store the reconnect address */
cifs_server_lock(tcon->ses->server);
- if (cifs_sockaddr_equal(&tcon->ses->server->dstaddr, addr))
- goto unlock;
- ret = cifs_swn_store_swn_addr(addr, &tcon->ses->server->dstaddr,
- &tcon->ses->server->swn_dstaddr);
- if (ret < 0) {
- cifs_dbg(VFS, "%s: failed to store address: %d\n", __func__, ret);
+ if (cifs_match_ipaddr((struct sockaddr *)&tcon->ses->server->dstaddr,
+ (struct sockaddr *)addr)) {
+ /* no-op */
goto unlock;
}
- tcon->ses->server->use_swn_dstaddr = true;
/*
* Unregister to stop receiving notifications for the old IP address.
@@ -536,8 +521,23 @@ static int cifs_swn_reconnect(struct cifs_tcon *tcon, struct sockaddr_storage *a
if (ret < 0) {
cifs_dbg(VFS, "%s: Failed to unregister for witness notifications: %d\n",
__func__, ret);
+ /*
+ * Do not jump return on error, continue storing and registering for
+ * notifications for the new address. There will be a stale registration
+ * around running its periodic check task, which should cancel itself
+ * if no matching any tcon.
+ */
+ }
+
+ /* Store the reconnect address */
+ ret = cifs_swn_store_swn_addr(addr, &tcon->ses->server->dstaddr,
+ &tcon->ses->server->swn_dstaddr);
+ if (ret < 0) {
+ cifs_dbg(VFS, "%s: failed to store address: %d\n", __func__,
+ ret);
goto unlock;
}
+ tcon->ses->server->use_swn_dstaddr = true;
/*
* And register to receive notifications for the new IP address now that we have
@@ -681,33 +681,20 @@ int cifs_swn_unregister(struct cifs_tcon *tcon)
void cifs_swn_dump(struct seq_file *m)
{
struct cifs_swn_reg *swnreg;
- struct sockaddr_in *sa;
- struct sockaddr_in6 *sa6;
int id;
seq_puts(m, "Witness registrations:");
mutex_lock(&cifs_swnreg_idr_mutex);
idr_for_each_entry(&cifs_swnreg_idr, swnreg, id) {
- seq_printf(m, "\nId: %u Refs: %u Network name: '%s'%s Share name: '%s'%s Ip address: ",
- id, kref_read(&swnreg->ref_count),
- swnreg->net_name, swnreg->net_name_notify ? "(y)" : "(n)",
- swnreg->share_name, swnreg->share_name_notify ? "(y)" : "(n)");
- switch (swnreg->tcon->ses->server->dstaddr.ss_family) {
- case AF_INET:
- sa = (struct sockaddr_in *) &swnreg->tcon->ses->server->dstaddr;
- seq_printf(m, "%pI4", &sa->sin_addr.s_addr);
- break;
- case AF_INET6:
- sa6 = (struct sockaddr_in6 *) &swnreg->tcon->ses->server->dstaddr;
- seq_printf(m, "%pI6", &sa6->sin6_addr.s6_addr);
- if (sa6->sin6_scope_id)
- seq_printf(m, "%%%u", sa6->sin6_scope_id);
- break;
- default:
- seq_puts(m, "(unknown)");
- }
- seq_printf(m, "%s", swnreg->ip_notify ? "(y)" : "(n)");
+ seq_printf(
+ m,
+ "\nId: %u Refs: %u Network name: '%s'%s Share name: '%s'%s Ip address: '%pISc'%s",
+ id, kref_read(&swnreg->ref_count), swnreg->net_name,
+ swnreg->net_name_notify ? "(y)" : "(n)",
+ swnreg->share_name,
+ swnreg->share_name_notify ? "(y)" : "(n)",
+ &swnreg->addr, swnreg->ip_notify ? "(y)" : "(n)");
}
mutex_unlock(&cifs_swnreg_idr_mutex);
seq_puts(m, "\n");
--
2.54.0
next prev 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 ` Samuel Cabrero [this message]
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 ` [PATCH 18/18] smb:client: Avoid witness re-register if the address did not change Samuel Cabrero
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-7-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