Commit 4f1fffa2 authored by Shyam Prasad N's avatar Shyam Prasad N Committed by Steve French

cifs: commands that are retried should have replay flag set

MS-SMB2 states that the header flag SMB2_FLAGS_REPLAY_OPERATION
needs to be set when a command needs to be retried, so that
the server is aware that this is a replay for an operation that
appeared before.

This can be very important, for example, for state changing
operations and opens which get retried following a reconnect;
since the client maybe unaware of the status of the previous
open.

This is particularly important for multichannel scenario, since
disconnection of one connection does not mean that the session
is lost. The requests can be replayed on another channel.

This change also makes use of exponential back-off before replays
and also limits the number of retries to "retrans" mount option
value.

Also, this change does not modify the read/write codepath.
Signed-off-by: default avatarShyam Prasad N <sprasad@microsoft.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 64cc377b
...@@ -145,21 +145,27 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, ...@@ -145,21 +145,27 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
struct cached_fid *cfid; struct cached_fid *cfid;
struct cached_fids *cfids; struct cached_fids *cfids;
const char *npath; const char *npath;
int retries = 0, cur_sleep = 1;
if (tcon == NULL || tcon->cfids == NULL || tcon->nohandlecache || if (tcon == NULL || tcon->cfids == NULL || tcon->nohandlecache ||
is_smb1_server(tcon->ses->server) || (dir_cache_timeout == 0)) is_smb1_server(tcon->ses->server) || (dir_cache_timeout == 0))
return -EOPNOTSUPP; return -EOPNOTSUPP;
ses = tcon->ses; ses = tcon->ses;
server = cifs_pick_channel(ses);
cfids = tcon->cfids; cfids = tcon->cfids;
if (!server->ops->new_lease_key)
return -EIO;
if (cifs_sb->root == NULL) if (cifs_sb->root == NULL)
return -ENOENT; return -ENOENT;
replay_again:
/* reinitialize for possible replay */
flags = 0;
oplock = SMB2_OPLOCK_LEVEL_II;
server = cifs_pick_channel(ses);
if (!server->ops->new_lease_key)
return -EIO;
utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
if (!utf16_path) if (!utf16_path)
return -ENOMEM; return -ENOMEM;
...@@ -268,6 +274,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, ...@@ -268,6 +274,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
*/ */
cfid->has_lease = true; cfid->has_lease = true;
if (retries) {
smb2_set_replay(server, &rqst[0]);
smb2_set_replay(server, &rqst[1]);
}
rc = compound_send_recv(xid, ses, server, rc = compound_send_recv(xid, ses, server,
flags, 2, rqst, flags, 2, rqst,
resp_buftype, rsp_iov); resp_buftype, rsp_iov);
...@@ -368,6 +379,10 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, ...@@ -368,6 +379,10 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
} }
kfree(utf16_path); kfree(utf16_path);
if (is_replayable_error(rc) &&
smb2_should_replay(tcon, &retries, &cur_sleep))
goto replay_again;
return rc; return rc;
} }
......
...@@ -49,6 +49,11 @@ ...@@ -49,6 +49,11 @@
*/ */
#define CIFS_DEF_ACTIMEO (1 * HZ) #define CIFS_DEF_ACTIMEO (1 * HZ)
/*
* max sleep time before retry to server
*/
#define CIFS_MAX_SLEEP 2000
/* /*
* max attribute cache timeout (jiffies) - 2^30 * max attribute cache timeout (jiffies) - 2^30
*/ */
......
...@@ -120,6 +120,14 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -120,6 +120,14 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
unsigned int size[2]; unsigned int size[2];
void *data[2]; void *data[2];
int len; int len;
int retries = 0, cur_sleep = 1;
replay_again:
/* reinitialize for possible replay */
flags = 0;
oplock = SMB2_OPLOCK_LEVEL_NONE;
num_rqst = 0;
server = cifs_pick_channel(ses);
vars = kzalloc(sizeof(*vars), GFP_ATOMIC); vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
if (vars == NULL) if (vars == NULL)
...@@ -127,8 +135,6 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -127,8 +135,6 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
rqst = &vars->rqst[0]; rqst = &vars->rqst[0];
rsp_iov = &vars->rsp_iov[0]; rsp_iov = &vars->rsp_iov[0];
server = cifs_pick_channel(ses);
if (smb3_encryption_required(tcon)) if (smb3_encryption_required(tcon))
flags |= CIFS_TRANSFORM_REQ; flags |= CIFS_TRANSFORM_REQ;
...@@ -463,15 +469,24 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -463,15 +469,24 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
num_rqst++; num_rqst++;
if (cfile) { if (cfile) {
if (retries)
for (i = 1; i < num_rqst - 2; i++)
smb2_set_replay(server, &rqst[i]);
rc = compound_send_recv(xid, ses, server, rc = compound_send_recv(xid, ses, server,
flags, num_rqst - 2, flags, num_rqst - 2,
&rqst[1], &resp_buftype[1], &rqst[1], &resp_buftype[1],
&rsp_iov[1]); &rsp_iov[1]);
} else } else {
if (retries)
for (i = 0; i < num_rqst; i++)
smb2_set_replay(server, &rqst[i]);
rc = compound_send_recv(xid, ses, server, rc = compound_send_recv(xid, ses, server,
flags, num_rqst, flags, num_rqst,
rqst, resp_buftype, rqst, resp_buftype,
rsp_iov); rsp_iov);
}
finished: finished:
num_rqst = 0; num_rqst = 0;
...@@ -620,9 +635,6 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -620,9 +635,6 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
} }
SMB2_close_free(&rqst[num_rqst]); SMB2_close_free(&rqst[num_rqst]);
if (cfile)
cifsFileInfo_put(cfile);
num_cmds += 2; num_cmds += 2;
if (out_iov && out_buftype) { if (out_iov && out_buftype) {
memcpy(out_iov, rsp_iov, num_cmds * sizeof(*out_iov)); memcpy(out_iov, rsp_iov, num_cmds * sizeof(*out_iov));
...@@ -632,7 +644,16 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -632,7 +644,16 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
for (i = 0; i < num_cmds; i++) for (i = 0; i < num_cmds; i++)
free_rsp_buf(resp_buftype[i], rsp_iov[i].iov_base); free_rsp_buf(resp_buftype[i], rsp_iov[i].iov_base);
} }
num_cmds -= 2; /* correct num_cmds as there could be a retry */
kfree(vars); kfree(vars);
if (is_replayable_error(rc) &&
smb2_should_replay(tcon, &retries, &cur_sleep))
goto replay_again;
if (cfile)
cifsFileInfo_put(cfile);
return rc; return rc;
} }
......
...@@ -1108,7 +1108,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -1108,7 +1108,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
{ {
struct smb2_compound_vars *vars; struct smb2_compound_vars *vars;
struct cifs_ses *ses = tcon->ses; struct cifs_ses *ses = tcon->ses;
struct TCP_Server_Info *server = cifs_pick_channel(ses); struct TCP_Server_Info *server;
struct smb_rqst *rqst; struct smb_rqst *rqst;
struct kvec *rsp_iov; struct kvec *rsp_iov;
__le16 *utf16_path = NULL; __le16 *utf16_path = NULL;
...@@ -1124,6 +1124,13 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -1124,6 +1124,13 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
struct smb2_file_full_ea_info *ea = NULL; struct smb2_file_full_ea_info *ea = NULL;
struct smb2_query_info_rsp *rsp; struct smb2_query_info_rsp *rsp;
int rc, used_len = 0; int rc, used_len = 0;
int retries = 0, cur_sleep = 1;
replay_again:
/* reinitialize for possible replay */
flags = CIFS_CP_CREATE_CLOSE_OP;
oplock = SMB2_OPLOCK_LEVEL_NONE;
server = cifs_pick_channel(ses);
if (smb3_encryption_required(tcon)) if (smb3_encryption_required(tcon))
flags |= CIFS_TRANSFORM_REQ; flags |= CIFS_TRANSFORM_REQ;
...@@ -1244,6 +1251,12 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -1244,6 +1251,12 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
goto sea_exit; goto sea_exit;
smb2_set_related(&rqst[2]); smb2_set_related(&rqst[2]);
if (retries) {
smb2_set_replay(server, &rqst[0]);
smb2_set_replay(server, &rqst[1]);
smb2_set_replay(server, &rqst[2]);
}
rc = compound_send_recv(xid, ses, server, rc = compound_send_recv(xid, ses, server,
flags, 3, rqst, flags, 3, rqst,
resp_buftype, rsp_iov); resp_buftype, rsp_iov);
...@@ -1260,6 +1273,11 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -1260,6 +1273,11 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
kfree(vars); kfree(vars);
out_free_path: out_free_path:
kfree(utf16_path); kfree(utf16_path);
if (is_replayable_error(rc) &&
smb2_should_replay(tcon, &retries, &cur_sleep))
goto replay_again;
return rc; return rc;
} }
#endif #endif
...@@ -1484,7 +1502,7 @@ smb2_ioctl_query_info(const unsigned int xid, ...@@ -1484,7 +1502,7 @@ smb2_ioctl_query_info(const unsigned int xid,
struct smb_rqst *rqst; struct smb_rqst *rqst;
struct kvec *rsp_iov; struct kvec *rsp_iov;
struct cifs_ses *ses = tcon->ses; struct cifs_ses *ses = tcon->ses;
struct TCP_Server_Info *server = cifs_pick_channel(ses); struct TCP_Server_Info *server;
char __user *arg = (char __user *)p; char __user *arg = (char __user *)p;
struct smb_query_info qi; struct smb_query_info qi;
struct smb_query_info __user *pqi; struct smb_query_info __user *pqi;
...@@ -1501,6 +1519,13 @@ smb2_ioctl_query_info(const unsigned int xid, ...@@ -1501,6 +1519,13 @@ smb2_ioctl_query_info(const unsigned int xid,
void *data[2]; void *data[2];
int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR; int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
void (*free_req1_func)(struct smb_rqst *r); void (*free_req1_func)(struct smb_rqst *r);
int retries = 0, cur_sleep = 1;
replay_again:
/* reinitialize for possible replay */
flags = CIFS_CP_CREATE_CLOSE_OP;
oplock = SMB2_OPLOCK_LEVEL_NONE;
server = cifs_pick_channel(ses);
vars = kzalloc(sizeof(*vars), GFP_ATOMIC); vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
if (vars == NULL) if (vars == NULL)
...@@ -1641,6 +1666,12 @@ smb2_ioctl_query_info(const unsigned int xid, ...@@ -1641,6 +1666,12 @@ smb2_ioctl_query_info(const unsigned int xid,
goto free_req_1; goto free_req_1;
smb2_set_related(&rqst[2]); smb2_set_related(&rqst[2]);
if (retries) {
smb2_set_replay(server, &rqst[0]);
smb2_set_replay(server, &rqst[1]);
smb2_set_replay(server, &rqst[2]);
}
rc = compound_send_recv(xid, ses, server, rc = compound_send_recv(xid, ses, server,
flags, 3, rqst, flags, 3, rqst,
resp_buftype, rsp_iov); resp_buftype, rsp_iov);
...@@ -1701,6 +1732,11 @@ smb2_ioctl_query_info(const unsigned int xid, ...@@ -1701,6 +1732,11 @@ smb2_ioctl_query_info(const unsigned int xid,
kfree(buffer); kfree(buffer);
free_vars: free_vars:
kfree(vars); kfree(vars);
if (is_replayable_error(rc) &&
smb2_should_replay(tcon, &retries, &cur_sleep))
goto replay_again;
return rc; return rc;
} }
...@@ -2227,8 +2263,14 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2227,8 +2263,14 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
struct cifs_open_parms oparms; struct cifs_open_parms oparms;
struct smb2_query_directory_rsp *qd_rsp = NULL; struct smb2_query_directory_rsp *qd_rsp = NULL;
struct smb2_create_rsp *op_rsp = NULL; struct smb2_create_rsp *op_rsp = NULL;
struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); struct TCP_Server_Info *server;
int retry_count = 0; int retries = 0, cur_sleep = 1;
replay_again:
/* reinitialize for possible replay */
flags = 0;
oplock = SMB2_OPLOCK_LEVEL_NONE;
server = cifs_pick_channel(tcon->ses);
utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
if (!utf16_path) if (!utf16_path)
...@@ -2278,14 +2320,15 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2278,14 +2320,15 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
smb2_set_related(&rqst[1]); smb2_set_related(&rqst[1]);
again: if (retries) {
smb2_set_replay(server, &rqst[0]);
smb2_set_replay(server, &rqst[1]);
}
rc = compound_send_recv(xid, tcon->ses, server, rc = compound_send_recv(xid, tcon->ses, server,
flags, 2, rqst, flags, 2, rqst,
resp_buftype, rsp_iov); resp_buftype, rsp_iov);
if (rc == -EAGAIN && retry_count++ < 10)
goto again;
/* If the open failed there is nothing to do */ /* If the open failed there is nothing to do */
op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base; op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) { if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
...@@ -2333,6 +2376,11 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2333,6 +2376,11 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
SMB2_query_directory_free(&rqst[1]); SMB2_query_directory_free(&rqst[1]);
free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
if (is_replayable_error(rc) &&
smb2_should_replay(tcon, &retries, &cur_sleep))
goto replay_again;
return rc; return rc;
} }
...@@ -2457,6 +2505,22 @@ smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid, ...@@ -2457,6 +2505,22 @@ smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
CIFS_CACHE_READ(cinode) ? 1 : 0); CIFS_CACHE_READ(cinode) ? 1 : 0);
} }
void
smb2_set_replay(struct TCP_Server_Info *server, struct smb_rqst *rqst)
{
struct smb2_hdr *shdr;
if (server->dialect < SMB30_PROT_ID)
return;
shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
if (shdr == NULL) {
cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
return;
}
shdr->Flags |= SMB2_FLAGS_REPLAY_OPERATION;
}
void void
smb2_set_related(struct smb_rqst *rqst) smb2_set_related(struct smb_rqst *rqst)
{ {
...@@ -2529,6 +2593,27 @@ smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst) ...@@ -2529,6 +2593,27 @@ smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
shdr->NextCommand = cpu_to_le32(len); shdr->NextCommand = cpu_to_le32(len);
} }
/*
* helper function for exponential backoff and check if replayable
*/
bool smb2_should_replay(struct cifs_tcon *tcon,
int *pretries,
int *pcur_sleep)
{
if (!pretries || !pcur_sleep)
return false;
if (tcon->retry || (*pretries)++ < tcon->ses->server->retrans) {
msleep(*pcur_sleep);
(*pcur_sleep) = ((*pcur_sleep) << 1);
if ((*pcur_sleep) > CIFS_MAX_SLEEP)
(*pcur_sleep) = CIFS_MAX_SLEEP;
return true;
}
return false;
}
/* /*
* Passes the query info response back to the caller on success. * Passes the query info response back to the caller on success.
* Caller need to free this with free_rsp_buf(). * Caller need to free this with free_rsp_buf().
...@@ -2542,7 +2627,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2542,7 +2627,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
{ {
struct smb2_compound_vars *vars; struct smb2_compound_vars *vars;
struct cifs_ses *ses = tcon->ses; struct cifs_ses *ses = tcon->ses;
struct TCP_Server_Info *server = cifs_pick_channel(ses); struct TCP_Server_Info *server;
int flags = CIFS_CP_CREATE_CLOSE_OP; int flags = CIFS_CP_CREATE_CLOSE_OP;
struct smb_rqst *rqst; struct smb_rqst *rqst;
int resp_buftype[3]; int resp_buftype[3];
...@@ -2553,6 +2638,13 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2553,6 +2638,13 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
int rc; int rc;
__le16 *utf16_path; __le16 *utf16_path;
struct cached_fid *cfid = NULL; struct cached_fid *cfid = NULL;
int retries = 0, cur_sleep = 1;
replay_again:
/* reinitialize for possible replay */
flags = CIFS_CP_CREATE_CLOSE_OP;
oplock = SMB2_OPLOCK_LEVEL_NONE;
server = cifs_pick_channel(ses);
if (!path) if (!path)
path = ""; path = "";
...@@ -2633,6 +2725,14 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2633,6 +2725,14 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
goto qic_exit; goto qic_exit;
smb2_set_related(&rqst[2]); smb2_set_related(&rqst[2]);
if (retries) {
if (!cfid) {
smb2_set_replay(server, &rqst[0]);
smb2_set_replay(server, &rqst[2]);
}
smb2_set_replay(server, &rqst[1]);
}
if (cfid) { if (cfid) {
rc = compound_send_recv(xid, ses, server, rc = compound_send_recv(xid, ses, server,
flags, 1, &rqst[1], flags, 1, &rqst[1],
...@@ -2665,6 +2765,11 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2665,6 +2765,11 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
kfree(vars); kfree(vars);
out_free_path: out_free_path:
kfree(utf16_path); kfree(utf16_path);
if (is_replayable_error(rc) &&
smb2_should_replay(tcon, &retries, &cur_sleep))
goto replay_again;
return rc; return rc;
} }
......
This diff is collapsed.
...@@ -122,6 +122,11 @@ extern unsigned long smb_rqst_len(struct TCP_Server_Info *server, ...@@ -122,6 +122,11 @@ extern unsigned long smb_rqst_len(struct TCP_Server_Info *server,
extern void smb2_set_next_command(struct cifs_tcon *tcon, extern void smb2_set_next_command(struct cifs_tcon *tcon,
struct smb_rqst *rqst); struct smb_rqst *rqst);
extern void smb2_set_related(struct smb_rqst *rqst); extern void smb2_set_related(struct smb_rqst *rqst);
extern void smb2_set_replay(struct TCP_Server_Info *server,
struct smb_rqst *rqst);
extern bool smb2_should_replay(struct cifs_tcon *tcon,
int *pretries,
int *pcur_sleep);
/* /*
* SMB2 Worker functions - most of protocol specific implementation details * SMB2 Worker functions - most of protocol specific implementation details
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment