Skip to content

Commit

Permalink
cifs: store the leaseKey in the fid on SMB2_open
Browse files Browse the repository at this point in the history
commit 96164ab upstream.

In SMB2_open(), if we got a lease we need to store this in the fid structure
or else we will never be able to map a lease break back to which file/fid
it applies to.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
Signed-off-by: Steve French <smfrench@gmail.com>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
  • Loading branch information
Ronnie Sahlberg authored and bwhacks committed Nov 20, 2018
1 parent 89eb260 commit ca33665
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion fs/cifs/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ struct smb_version_operations {
/* create lease context buffer for CREATE request */
char * (*create_lease_buf)(u8 *, u8);
/* parse lease context buffer and return oplock/epoch info */
__u8 (*parse_lease_buf)(void *, unsigned int *);
__u8 (*parse_lease_buf)(void *buf, unsigned int *epoch, char *lkey);
int (*clone_range)(const unsigned int, struct cifsFileInfo *src_file,
struct cifsFileInfo *target_file, u64 src_off, u64 len,
u64 dest_off);
Expand Down
7 changes: 5 additions & 2 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ smb3_create_lease_buf(u8 *lease_key, u8 oplock)
}

static __u8
smb2_parse_lease_buf(void *buf, unsigned int *epoch)
smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
{
struct create_lease *lc = (struct create_lease *)buf;

Expand All @@ -1129,13 +1129,16 @@ smb2_parse_lease_buf(void *buf, unsigned int *epoch)
}

static __u8
smb3_parse_lease_buf(void *buf, unsigned int *epoch)
smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
{
struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;

*epoch = le16_to_cpu(lc->lcontext.Epoch);
if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
return SMB2_OPLOCK_LEVEL_NOCHANGE;
if (lease_key)
memcpy(lease_key, &lc->lcontext.LeaseKeyLow,
SMB2_LEASE_KEY_SIZE);
return le32_to_cpu(lc->lcontext.LeaseState);
}

Expand Down
8 changes: 5 additions & 3 deletions fs/cifs/smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ create_reconnect_durable_buf(struct cifs_fid *fid)

static __u8
parse_lease_state(struct TCP_Server_Info *server, struct smb2_create_rsp *rsp,
unsigned int *epoch)
unsigned int *epoch, char *lease_key)
{
char *data_offset;
struct create_context *cc;
Expand All @@ -1069,7 +1069,8 @@ parse_lease_state(struct TCP_Server_Info *server, struct smb2_create_rsp *rsp,
name = le16_to_cpu(cc->NameOffset) + (char *)cc;
if (le16_to_cpu(cc->NameLength) == 4 &&
strncmp(name, "RqLs", 4) == 0)
return server->ops->parse_lease_buf(cc, epoch);
return server->ops->parse_lease_buf(cc, epoch,
lease_key);

next = le32_to_cpu(cc->Next);
if (!next)
Expand Down Expand Up @@ -1262,7 +1263,8 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
}

if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
*oplock = parse_lease_state(server, rsp, &oparms->fid->epoch);
*oplock = parse_lease_state(server, rsp, &oparms->fid->epoch,
oparms->fid->lease_key);
else
*oplock = rsp->OplockLevel;
creat_exit:
Expand Down

0 comments on commit ca33665

Please sign in to comment.