Commit b08d9b57 authored by Pavel Shilovsky's avatar Pavel Shilovsky Committed by Greg Kroah-Hartman

CIFS: Fix missing lease break

commit 933d4b36 upstream.

If a server sends a lease break to a connection that doesn't have
opens with a lease key specified in the server response, we can't
find an open file to send an ack. Fix this by walking through
all connections we have.
Signed-off-by: default avatarPavel Shilovsky <pshilovsky@samba.org>
Signed-off-by: default avatarSteve French <smfrench@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent af66f40c
...@@ -413,42 +413,22 @@ cifs_ses_oplock_break(struct work_struct *work) ...@@ -413,42 +413,22 @@ cifs_ses_oplock_break(struct work_struct *work)
} }
static bool static bool
smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server) smb2_tcon_has_lease(struct cifs_tcon *tcon, struct smb2_lease_break *rsp,
struct smb2_lease_break_work *lw)
{ {
struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer; bool found;
struct list_head *tmp, *tmp1, *tmp2; __u8 lease_state;
struct cifs_ses *ses; struct list_head *tmp;
struct cifs_tcon *tcon;
struct cifsInodeInfo *cinode;
struct cifsFileInfo *cfile; struct cifsFileInfo *cfile;
struct cifs_pending_open *open; struct cifs_pending_open *open;
struct smb2_lease_break_work *lw; struct cifsInodeInfo *cinode;
bool found;
int ack_req = le32_to_cpu(rsp->Flags & int ack_req = le32_to_cpu(rsp->Flags &
SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED); SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED);
lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL); lease_state = smb2_map_lease_to_oplock(rsp->NewLeaseState);
if (!lw)
return false;
INIT_WORK(&lw->lease_break, cifs_ses_oplock_break);
lw->lease_state = rsp->NewLeaseState;
cifs_dbg(FYI, "Checking for lease break\n");
/* look up tcon based on tid & uid */
spin_lock(&cifs_tcp_ses_lock);
list_for_each(tmp, &server->smb_ses_list) {
ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
spin_lock(&cifs_file_list_lock); list_for_each(tmp, &tcon->openFileList) {
list_for_each(tmp1, &ses->tcon_list) { cfile = list_entry(tmp, struct cifsFileInfo, tlist);
tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks);
list_for_each(tmp2, &tcon->openFileList) {
cfile = list_entry(tmp2, struct cifsFileInfo,
tlist);
cinode = CIFS_I(cfile->dentry->d_inode); cinode = CIFS_I(cfile->dentry->d_inode);
if (memcmp(cinode->lease_key, rsp->LeaseKey, if (memcmp(cinode->lease_key, rsp->LeaseKey,
...@@ -459,8 +439,7 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server) ...@@ -459,8 +439,7 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
cifs_dbg(FYI, "lease key match, lease break 0x%d\n", cifs_dbg(FYI, "lease key match, lease break 0x%d\n",
le32_to_cpu(rsp->NewLeaseState)); le32_to_cpu(rsp->NewLeaseState));
smb2_set_oplock_level(cinode, smb2_set_oplock_level(cinode, lease_state);
smb2_map_lease_to_oplock(rsp->NewLeaseState));
if (ack_req) if (ack_req)
cfile->oplock_break_cancelled = false; cfile->oplock_break_cancelled = false;
...@@ -468,10 +447,7 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server) ...@@ -468,10 +447,7 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
cfile->oplock_break_cancelled = true; cfile->oplock_break_cancelled = true;
queue_work(cifsiod_wq, &cfile->oplock_break); queue_work(cifsiod_wq, &cfile->oplock_break);
kfree(lw); kfree(lw);
spin_unlock(&cifs_file_list_lock);
spin_unlock(&cifs_tcp_ses_lock);
return true; return true;
} }
...@@ -486,18 +462,52 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server) ...@@ -486,18 +462,52 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
memcpy(lw->lease_key, open->lease_key, memcpy(lw->lease_key, open->lease_key,
SMB2_LEASE_KEY_SIZE); SMB2_LEASE_KEY_SIZE);
lw->tlink = cifs_get_tlink(open->tlink); lw->tlink = cifs_get_tlink(open->tlink);
queue_work(cifsiod_wq, queue_work(cifsiod_wq, &lw->lease_break);
&lw->lease_break);
} }
cifs_dbg(FYI, "found in the pending open list\n"); cifs_dbg(FYI, "found in the pending open list\n");
cifs_dbg(FYI, "lease key match, lease break 0x%d\n", cifs_dbg(FYI, "lease key match, lease break 0x%d\n",
le32_to_cpu(rsp->NewLeaseState)); le32_to_cpu(rsp->NewLeaseState));
open->oplock = open->oplock = lease_state;
smb2_map_lease_to_oplock(rsp->NewLeaseState);
} }
if (found) { return found;
}
static bool
smb2_is_valid_lease_break(char *buffer)
{
struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer;
struct list_head *tmp, *tmp1, *tmp2;
struct TCP_Server_Info *server;
struct cifs_ses *ses;
struct cifs_tcon *tcon;
struct smb2_lease_break_work *lw;
lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL);
if (!lw)
return false;
INIT_WORK(&lw->lease_break, cifs_ses_oplock_break);
lw->lease_state = rsp->NewLeaseState;
cifs_dbg(FYI, "Checking for lease break\n");
/* look up tcon based on tid & uid */
spin_lock(&cifs_tcp_ses_lock);
list_for_each(tmp, &cifs_tcp_ses_list) {
server = list_entry(tmp, struct TCP_Server_Info, tcp_ses_list);
list_for_each(tmp1, &server->smb_ses_list) {
ses = list_entry(tmp1, struct cifs_ses, smb_ses_list);
spin_lock(&cifs_file_list_lock);
list_for_each(tmp2, &ses->tcon_list) {
tcon = list_entry(tmp2, struct cifs_tcon,
tcon_list);
cifs_stats_inc(
&tcon->stats.cifs_stats.num_oplock_brks);
if (smb2_tcon_has_lease(tcon, rsp, lw)) {
spin_unlock(&cifs_file_list_lock); spin_unlock(&cifs_file_list_lock);
spin_unlock(&cifs_tcp_ses_lock); spin_unlock(&cifs_tcp_ses_lock);
return true; return true;
...@@ -505,6 +515,7 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server) ...@@ -505,6 +515,7 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
} }
spin_unlock(&cifs_file_list_lock); spin_unlock(&cifs_file_list_lock);
} }
}
spin_unlock(&cifs_tcp_ses_lock); spin_unlock(&cifs_tcp_ses_lock);
kfree(lw); kfree(lw);
cifs_dbg(FYI, "Can not process lease break - no lease matched\n"); cifs_dbg(FYI, "Can not process lease break - no lease matched\n");
...@@ -529,7 +540,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server) ...@@ -529,7 +540,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
if (rsp->StructureSize != if (rsp->StructureSize !=
smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) { smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) {
if (le16_to_cpu(rsp->StructureSize) == 44) if (le16_to_cpu(rsp->StructureSize) == 44)
return smb2_is_valid_lease_break(buffer, server); return smb2_is_valid_lease_break(buffer);
else else
return false; return false;
} }
......
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