diff mbox series

cifs: include regular shares to the list of unshared tcp servers

Message ID 20210702171710.406-1-pc@cjr.nz (mailing list archive)
State New, archived
Headers show
Series cifs: include regular shares to the list of unshared tcp servers | expand

Commit Message

Paulo Alcantara July 2, 2021, 5:17 p.m. UTC
We need to make regular shares to also not share tcp servers because
we might have both regular and dfs mounts connecting to same server.

Fixes: f3c852b0b0fc ("cifs: do not share tcp servers with dfs mounts")
Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
---
 fs/cifs/connect.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Aurélien Aptel July 5, 2021, 10:51 a.m. UTC | #1
Paulo Alcantara <pc@cjr.nz> writes:
> We need to make regular shares to also not share tcp servers because
> we might have both regular and dfs mounts connecting to same server.

So with this change we never reuse tcp connections, and nosharesock
because the default mount option for all cases. We might as well remove
all the code for searching/matching/reusing tcp connection, smb session,
tree connects.

That doesn't seem good. If dfs connections are made with the nosharesock
flag they should not be reused already no?

Cheers,
Paulo Alcantara July 5, 2021, 2:37 p.m. UTC | #2
Aurélien Aptel <aaptel@suse.com> writes:

> Paulo Alcantara <pc@cjr.nz> writes:
>> We need to make regular shares to also not share tcp servers because
>> we might have both regular and dfs mounts connecting to same server.
>
> So with this change we never reuse tcp connections, and nosharesock
> because the default mount option for all cases. We might as well remove
> all the code for searching/matching/reusing tcp connection, smb session,
> tree connects.

Sounds like a good idea, yes.  Of course, if we really want to do this
regardless CONFIG_CIFS_DFS_UPCALL, it would probably be better off doing
it in a separate series.

> That doesn't seem good. If dfs connections are made with the nosharesock
> flag they should not be reused already no?

The previous version only made sure to not share tcp servers among DFS
shares, however, we must do it for all shares when we have
CONFIG_CIFS_DFS_UPCALL option enabled.

Without this change, the following would occur:

mount //dfsroot/dfs (new tcp)
mount //dfsroot/share (reuse tcp because


	rc = mount_get_conns(ctx, cifs_sb, &xid, &server, &ses, &tcon);
	/*
	 * If called with 'nodfs' mount option, then skip DFS resolving.  Otherwise unconditionally
	 * try to get an DFS referral (even cached) to determine whether it is an DFS mount.
	 *
	 * Skip prefix path to provide support for DFS referrals from w2k8 servers which don't seem
	 * to respond with PATH_NOT_COVERED to requests that include the prefix.
	 */
	if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS) ||
	    dfs_cache_find(xid, ses, cifs_sb->local_nls, cifs_remap(cifs_sb), ctx->UNC + 1, NULL,
			   NULL)) {
		if (rc)
			goto error;
		/* Check if it is fully accessible and then mount it */
		rc = is_path_remote(cifs_sb, ctx, xid, server, tcon);
		if (!rc)
			goto out;
		if (rc != -EREMOTE)
			goto error;
	}

would get executed in cifs_mount() and we only set nosharesock after that)

With this patch:

mount //dfsroot/dfs (new tcp)
mount //dfsroot/share (new tcp)
diff mbox series

Patch

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 944fb92f50c7..d9471575935f 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -3382,6 +3382,12 @@  int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 	char *oldmnt = NULL;
 	bool ref_server = false;
 
+	/*
+	 * Do not share tcp servers when CONFIG_CIFS_DFS_UPCALL option is enabled to properly handle
+	 * reconnect of regular and dfs shares when they were connected to same server.
+	 */
+	ctx->nosharesock = true;
+
 	rc = mount_get_conns(ctx, cifs_sb, &xid, &server, &ses, &tcon);
 	/*
 	 * If called with 'nodfs' mount option, then skip DFS resolving.  Otherwise unconditionally
@@ -3403,8 +3409,6 @@  int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 			goto error;
 	}
 
-	ctx->nosharesock = true;
-
 	/* Get path of DFS root */
 	ref_path = build_unc_path_to_root(ctx, cifs_sb, false);
 	if (IS_ERR(ref_path)) {