提交 933d4b36 编写于 作者: P Pavel Shilovsky 提交者: Steve French

CIFS: Fix missing lease break

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.

Cc: <stable@vger.kernel.org>
Signed-off-by: NPavel Shilovsky <pshilovsky@samba.org>
Signed-off-by: NSteve French <smfrench@gmail.com>
上级 1a05096d
...@@ -421,97 +421,108 @@ cifs_ses_oplock_break(struct work_struct *work) ...@@ -421,97 +421,108 @@ 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); list_for_each(tmp, &tcon->openFileList) {
lw->lease_state = rsp->NewLeaseState; cfile = list_entry(tmp, struct cifsFileInfo, tlist);
cinode = CIFS_I(cfile->dentry->d_inode);
cifs_dbg(FYI, "Checking for lease break\n"); if (memcmp(cinode->lease_key, rsp->LeaseKey,
SMB2_LEASE_KEY_SIZE))
continue;
/* look up tcon based on tid & uid */ cifs_dbg(FYI, "found in the open list\n");
spin_lock(&cifs_tcp_ses_lock); cifs_dbg(FYI, "lease key match, lease break 0x%d\n",
list_for_each(tmp, &server->smb_ses_list) { le32_to_cpu(rsp->NewLeaseState));
ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
spin_lock(&cifs_file_list_lock); smb2_set_oplock_level(cinode, lease_state);
list_for_each(tmp1, &ses->tcon_list) {
tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks); if (ack_req)
list_for_each(tmp2, &tcon->openFileList) { cfile->oplock_break_cancelled = false;
cfile = list_entry(tmp2, struct cifsFileInfo, else
tlist); cfile->oplock_break_cancelled = true;
cinode = CIFS_I(cfile->dentry->d_inode);
if (memcmp(cinode->lease_key, rsp->LeaseKey, queue_work(cifsiod_wq, &cfile->oplock_break);
SMB2_LEASE_KEY_SIZE)) kfree(lw);
continue; return true;
}
cifs_dbg(FYI, "found in the open list\n"); found = false;
cifs_dbg(FYI, "lease key match, lease break 0x%d\n", list_for_each_entry(open, &tcon->pending_opens, olist) {
le32_to_cpu(rsp->NewLeaseState)); if (memcmp(open->lease_key, rsp->LeaseKey,
SMB2_LEASE_KEY_SIZE))
continue;
if (!found && ack_req) {
found = true;
memcpy(lw->lease_key, open->lease_key,
SMB2_LEASE_KEY_SIZE);
lw->tlink = cifs_get_tlink(open->tlink);
queue_work(cifsiod_wq, &lw->lease_break);
}
smb2_set_oplock_level(cinode, cifs_dbg(FYI, "found in the pending open list\n");
smb2_map_lease_to_oplock(rsp->NewLeaseState)); cifs_dbg(FYI, "lease key match, lease break 0x%d\n",
le32_to_cpu(rsp->NewLeaseState));
if (ack_req) open->oplock = lease_state;
cfile->oplock_break_cancelled = false; }
else return found;
cfile->oplock_break_cancelled = true; }
queue_work(cifsiod_wq, &cfile->oplock_break); 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;
kfree(lw); lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL);
spin_unlock(&cifs_file_list_lock); if (!lw)
spin_unlock(&cifs_tcp_ses_lock); return false;
return true;
}
found = false; INIT_WORK(&lw->lease_break, cifs_ses_oplock_break);
list_for_each_entry(open, &tcon->pending_opens, olist) { lw->lease_state = rsp->NewLeaseState;
if (memcmp(open->lease_key, rsp->LeaseKey,
SMB2_LEASE_KEY_SIZE))
continue;
if (!found && ack_req) { cifs_dbg(FYI, "Checking for lease break\n");
found = true;
memcpy(lw->lease_key, open->lease_key, /* look up tcon based on tid & uid */
SMB2_LEASE_KEY_SIZE); spin_lock(&cifs_tcp_ses_lock);
lw->tlink = cifs_get_tlink(open->tlink); list_for_each(tmp, &cifs_tcp_ses_list) {
queue_work(cifsiod_wq, server = list_entry(tmp, struct TCP_Server_Info, tcp_ses_list);
&lw->lease_break);
}
cifs_dbg(FYI, "found in the pending open list\n"); list_for_each(tmp1, &server->smb_ses_list) {
cifs_dbg(FYI, "lease key match, lease break 0x%d\n", ses = list_entry(tmp1, struct cifs_ses, smb_ses_list);
le32_to_cpu(rsp->NewLeaseState));
open->oplock = spin_lock(&cifs_file_list_lock);
smb2_map_lease_to_oplock(rsp->NewLeaseState); list_for_each(tmp2, &ses->tcon_list) {
} tcon = list_entry(tmp2, struct cifs_tcon,
if (found) { tcon_list);
spin_unlock(&cifs_file_list_lock); cifs_stats_inc(
spin_unlock(&cifs_tcp_ses_lock); &tcon->stats.cifs_stats.num_oplock_brks);
return true; if (smb2_tcon_has_lease(tcon, rsp, lw)) {
spin_unlock(&cifs_file_list_lock);
spin_unlock(&cifs_tcp_ses_lock);
return true;
}
} }
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);
...@@ -537,7 +548,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server) ...@@ -537,7 +548,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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册