Hi Matthew, Thanks for the report. Matthew Ruffell <matthew.ruffell@xxxxxxxxxxxxx> writes: > We have come across a problem where kernels 5.0-rc1 and onwards cannot mount > a multi tier DFS setup, while kernels 4.20 and below can mount the share fine. > > The DFS tiering structure looks like this: > > Domain virtual DFS (i.e. \\company.com\folders\share) > |-- Domain controller DFS (i.e. \\regional-dc.company.com\folders\share) > |-- Regional DFS Server (i.e. \\regional-dfs.company.com\folders\share) > |-- Actual file server (i.e. \\regional-svr.company.com\share) > > On the 5.x series kernels, after getting the DFS referrals list through to the > Regional DFS Server, which responds with the correct server/share, instead of > going to the Actual file server, the kernel backtracks from the Regional DFS > Server back to the Domain controller and requests the share there. Of course, > this share does not exist on the Domain controller, as it only exists on the > Actual file server, and the connection dies. I've got some DFS cache patches[1] and haven't sent them yet due to lack of time and testing. Those contain a lot of important fixes but none of them seem to fix the issue you're having -- thus I won't ask you to apply them on top. Instead, could you please try below changes? Thanks, Paulo [1] https://git.cjr.nz/linux.git/log/?h=cifs-dfscache diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 3991d6c8f255..9158d5d14ac9 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -4777,6 +4777,15 @@ static int is_path_remote(struct cifs_sb_info *cifs_sb, struct smb_vol *vol, } #ifdef CONFIG_CIFS_DFS_UPCALL +static inline void set_root_tcon(struct cifs_tcon *tcon, + struct cifs_tcon **root) +{ + spin_lock(&cifs_tcp_ses_lock); + tcon->tc_count++; + spin_unlock(&cifs_tcp_ses_lock); + *root = tcon; +} + int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol) { int rc = 0; @@ -4878,18 +4887,10 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol) /* Cache out resolved root server */ (void)dfs_cache_find(xid, ses, cifs_sb->local_nls, cifs_remap(cifs_sb), root_path + 1, NULL, NULL); - /* - * Save root tcon for additional DFS requests to update or create a new - * DFS cache entry, or even perform DFS failover. - */ - spin_lock(&cifs_tcp_ses_lock); - tcon->tc_count++; - tcon->dfs_path = root_path; + kfree(root_path); root_path = NULL; - tcon->remap = cifs_remap(cifs_sb); - spin_unlock(&cifs_tcp_ses_lock); - root_tcon = tcon; + set_root_tcon(tcon, &root_tcon); for (count = 1; ;) { if (!rc && tcon) { @@ -4926,6 +4927,15 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol) mount_put_conns(cifs_sb, xid, server, ses, tcon); rc = mount_get_conns(vol, cifs_sb, &xid, &server, &ses, &tcon); + /* + * Ensure that DFS referrals go through new root server. + */ + if (!rc && tcon && + (tcon->share_flags & (SHI1005_FLAGS_DFS | + SHI1005_FLAGS_DFS_ROOT))) { + cifs_put_tcon(root_tcon); + set_root_tcon(tcon, &root_tcon); + } } if (rc) { if (rc == -EACCES || rc == -EOPNOTSUPP)