Skip to content

Commit c877ce4

Browse files
Paulo Alcantarasmfrench
authored andcommitted
cifs: reduce roundtrips on create/qinfo requests
To work around some Window servers that return STATUS_OBJECT_NAME_INVALID on query infos under DFS namespaces that contain non-ASCII characters, we started checking for -ENOENT on every file open, and if so, then send additional requests to figure out whether it is a DFS link or not. It means that all those requests will be sent to every non-existing file. So, in order to reduce the number of roundtrips, check earlier whether status code is STATUS_OBJECT_NAME_INVALID and tcon supports dfs, and if so, then map -ENOENT to -EREMOTE so mount or automount will take care of chasing the DFS link -- if it isn't an DFS link, then -ENOENT will be returned appropriately. Before patch SMB2 438 Create Request File: ada.test\dfs\foo;GetInfo Request... SMB2 310 Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND;... SMB2 228 Ioctl Request FSCTL_DFS_GET_REFERRALS, File: \ada.test\dfs\foo SMB2 143 Ioctl Response, Error: STATUS_OBJECT_PATH_NOT_FOUND SMB2 438 Create Request File: ada.test\dfs\foo;GetInfo Request... SMB2 310 Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND;... SMB2 228 Ioctl Request FSCTL_DFS_GET_REFERRALS, File: \ada.test\dfs\foo SMB2 143 Ioctl Response, Error: STATUS_OBJECT_PATH_NOT_FOUND After patch SMB2 438 Create Request File: ada.test\dfs\foo;GetInfo Request... SMB2 310 Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND;... SMB2 438 Create Request File: ada.test\dfs\foo;GetInfo Request... SMB2 310 Create Response, Error: STATUS_OBJECT_NAME_NOT_FOUND;... Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 86fe0fa commit c877ce4

File tree

5 files changed

+57
-84
lines changed

5 files changed

+57
-84
lines changed

fs/cifs/connect.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,9 +3547,6 @@ static int is_path_remote(struct mount_ctx *mnt_ctx)
35473547
struct cifs_tcon *tcon = mnt_ctx->tcon;
35483548
struct smb3_fs_context *ctx = mnt_ctx->fs_ctx;
35493549
char *full_path;
3550-
#ifdef CONFIG_CIFS_DFS_UPCALL
3551-
bool nodfs = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS;
3552-
#endif
35533550

35543551
if (!server->ops->is_path_accessible)
35553552
return -EOPNOTSUPP;
@@ -3566,19 +3563,6 @@ static int is_path_remote(struct mount_ctx *mnt_ctx)
35663563

35673564
rc = server->ops->is_path_accessible(xid, tcon, cifs_sb,
35683565
full_path);
3569-
#ifdef CONFIG_CIFS_DFS_UPCALL
3570-
if (nodfs) {
3571-
if (rc == -EREMOTE)
3572-
rc = -EOPNOTSUPP;
3573-
goto out;
3574-
}
3575-
3576-
/* path *might* exist with non-ASCII characters in DFS root
3577-
* try again with full path (only if nodfs is not set) */
3578-
if (rc == -ENOENT && is_tcon_dfs(tcon))
3579-
rc = cifs_dfs_query_info_nonascii_quirk(xid, tcon, cifs_sb,
3580-
full_path);
3581-
#endif
35823566
if (rc != 0 && rc != -EREMOTE)
35833567
goto out;
35843568

fs/cifs/inode.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -993,12 +993,6 @@ int cifs_get_inode_info(struct inode **inode, const char *full_path,
993993
}
994994
rc = server->ops->query_path_info(xid, tcon, cifs_sb, full_path, &tmp_data,
995995
&adjust_tz, &is_reparse_point);
996-
#ifdef CONFIG_CIFS_DFS_UPCALL
997-
if (rc == -ENOENT && is_tcon_dfs(tcon))
998-
rc = cifs_dfs_query_info_nonascii_quirk(xid, tcon,
999-
cifs_sb,
1000-
full_path);
1001-
#endif
1002996
data = &tmp_data;
1003997
}
1004998

fs/cifs/misc.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,49 +1314,4 @@ int cifs_update_super_prepath(struct cifs_sb_info *cifs_sb, char *prefix)
13141314
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH;
13151315
return 0;
13161316
}
1317-
1318-
/** cifs_dfs_query_info_nonascii_quirk
1319-
* Handle weird Windows SMB server behaviour. It responds with
1320-
* STATUS_OBJECT_NAME_INVALID code to SMB2 QUERY_INFO request
1321-
* for "\<server>\<dfsname>\<linkpath>" DFS reference,
1322-
* where <dfsname> contains non-ASCII unicode symbols.
1323-
*
1324-
* Check such DFS reference.
1325-
*/
1326-
int cifs_dfs_query_info_nonascii_quirk(const unsigned int xid,
1327-
struct cifs_tcon *tcon,
1328-
struct cifs_sb_info *cifs_sb,
1329-
const char *linkpath)
1330-
{
1331-
char *treename, *dfspath, sep;
1332-
int treenamelen, linkpathlen, rc;
1333-
1334-
treename = tcon->tree_name;
1335-
/* MS-DFSC: All paths in REQ_GET_DFS_REFERRAL and RESP_GET_DFS_REFERRAL
1336-
* messages MUST be encoded with exactly one leading backslash, not two
1337-
* leading backslashes.
1338-
*/
1339-
sep = CIFS_DIR_SEP(cifs_sb);
1340-
if (treename[0] == sep && treename[1] == sep)
1341-
treename++;
1342-
linkpathlen = strlen(linkpath);
1343-
treenamelen = strnlen(treename, MAX_TREE_SIZE + 1);
1344-
dfspath = kzalloc(treenamelen + linkpathlen + 1, GFP_KERNEL);
1345-
if (!dfspath)
1346-
return -ENOMEM;
1347-
if (treenamelen)
1348-
memcpy(dfspath, treename, treenamelen);
1349-
memcpy(dfspath + treenamelen, linkpath, linkpathlen);
1350-
rc = dfs_cache_find(xid, tcon->ses, cifs_sb->local_nls,
1351-
cifs_remap(cifs_sb), dfspath, NULL, NULL);
1352-
if (rc == 0) {
1353-
cifs_dbg(FYI, "DFS ref '%s' is found, emulate -EREMOTE\n",
1354-
dfspath);
1355-
rc = -EREMOTE;
1356-
} else {
1357-
cifs_dbg(FYI, "%s: dfs_cache_find returned %d\n", __func__, rc);
1358-
}
1359-
kfree(dfspath);
1360-
return rc;
1361-
}
13621317
#endif

fs/cifs/smb2inode.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -556,22 +556,42 @@ int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
556556
rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
557557
create_options, ACL_NO_MODE, data, SMB2_OP_QUERY_INFO, cfile,
558558
NULL, NULL, err_iov, err_buftype);
559-
if (rc == -EOPNOTSUPP) {
560-
if (err_iov[0].iov_base && err_buftype[0] != CIFS_NO_BUFFER &&
561-
((struct smb2_hdr *)err_iov[0].iov_base)->Command == SMB2_CREATE &&
562-
((struct smb2_hdr *)err_iov[0].iov_base)->Status == STATUS_STOPPED_ON_SYMLINK) {
563-
rc = smb2_parse_symlink_response(cifs_sb, err_iov, &data->symlink_target);
559+
if (rc) {
560+
struct smb2_hdr *hdr = err_iov[0].iov_base;
561+
562+
if (unlikely(!hdr || err_buftype[0] == CIFS_NO_BUFFER))
563+
goto out;
564+
if (rc == -EOPNOTSUPP && hdr->Command == SMB2_CREATE &&
565+
hdr->Status == STATUS_STOPPED_ON_SYMLINK) {
566+
rc = smb2_parse_symlink_response(cifs_sb, err_iov,
567+
&data->symlink_target);
564568
if (rc)
565569
goto out;
566-
}
567-
*reparse = true;
568-
create_options |= OPEN_REPARSE_POINT;
569570

570-
/* Failed on a symbolic link - query a reparse point info */
571-
cifs_get_readable_path(tcon, full_path, &cfile);
572-
rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES,
573-
FILE_OPEN, create_options, ACL_NO_MODE, data,
574-
SMB2_OP_QUERY_INFO, cfile, NULL, NULL, NULL, NULL);
571+
*reparse = true;
572+
create_options |= OPEN_REPARSE_POINT;
573+
574+
/* Failed on a symbolic link - query a reparse point info */
575+
cifs_get_readable_path(tcon, full_path, &cfile);
576+
rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
577+
FILE_READ_ATTRIBUTES, FILE_OPEN,
578+
create_options, ACL_NO_MODE, data,
579+
SMB2_OP_QUERY_INFO, cfile, NULL, NULL,
580+
NULL, NULL);
581+
goto out;
582+
} else if (rc != -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) &&
583+
hdr->Status == STATUS_OBJECT_NAME_INVALID) {
584+
/*
585+
* Handle weird Windows SMB server behaviour. It responds with
586+
* STATUS_OBJECT_NAME_INVALID code to SMB2 QUERY_INFO request
587+
* for "\<server>\<dfsname>\<linkpath>" DFS reference,
588+
* where <dfsname> contains non-ASCII unicode symbols.
589+
*/
590+
rc = -EREMOTE;
591+
}
592+
if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
593+
(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
594+
rc = -EOPNOTSUPP;
575595
}
576596

577597
out:

fs/cifs/smb2ops.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,9 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
796796
int rc;
797797
__le16 *utf16_path;
798798
__u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
799+
int err_buftype = CIFS_NO_BUFFER;
799800
struct cifs_open_parms oparms;
801+
struct kvec err_iov = {};
800802
struct cifs_fid fid;
801803
struct cached_fid *cfid;
802804

@@ -820,14 +822,32 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
820822
oparms.fid = &fid;
821823
oparms.reconnect = false;
822824

823-
rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
824-
NULL);
825+
rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
826+
&err_iov, &err_buftype);
825827
if (rc) {
826-
kfree(utf16_path);
827-
return rc;
828+
struct smb2_hdr *hdr = err_iov.iov_base;
829+
830+
if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
831+
goto out;
832+
/*
833+
* Handle weird Windows SMB server behaviour. It responds with
834+
* STATUS_OBJECT_NAME_INVALID code to SMB2 QUERY_INFO request
835+
* for "\<server>\<dfsname>\<linkpath>" DFS reference,
836+
* where <dfsname> contains non-ASCII unicode symbols.
837+
*/
838+
if (rc != -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) &&
839+
hdr->Status == STATUS_OBJECT_NAME_INVALID)
840+
rc = -EREMOTE;
841+
if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
842+
(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
843+
rc = -EOPNOTSUPP;
844+
goto out;
828845
}
829846

830847
rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
848+
849+
out:
850+
free_rsp_buf(err_buftype, err_iov.iov_base);
831851
kfree(utf16_path);
832852
return rc;
833853
}

0 commit comments

Comments
 (0)