Skip to content

Commit 51b78ff

Browse files
decarvSteve French
authored andcommitted
smb: client: add ParentLeaseKey support
According to MS-SMB2 3.2.4.3.8, when opening a file the client must lookup its parent directory, copy that entry’s LeaseKey into ParentLeaseKey, and set SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET. Extend lease context functions to carry a parent_lease_key and lease_flags and to add them to the lease context buffer accordingly in smb3_create_lease_buf. Also add a parent_lease_key field to struct cifs_fid and lease_flags to cifs_open_parms. Only applies to the SMB 3.x dialect family. Fixes: f047390 ("CIFS: Add create lease v2 context for SMB3") Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent a3e771a commit 51b78ff

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

fs/smb/client/cifsglob.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ struct smb_version_operations {
556556
void (*set_oplock_level)(struct cifsInodeInfo *cinode, __u32 oplock, __u16 epoch,
557557
bool *purge_cache);
558558
/* create lease context buffer for CREATE request */
559-
char * (*create_lease_buf)(u8 *lease_key, u8 oplock);
559+
char * (*create_lease_buf)(u8 *lease_key, u8 oplock, u8 *parent_lease_key, __le32 le_flags);
560560
/* parse lease context buffer and return oplock/epoch info */
561561
__u8 (*parse_lease_buf)(void *buf, __u16 *epoch, char *lkey);
562562
ssize_t (*copychunk_range)(const unsigned int,
@@ -1442,13 +1442,15 @@ struct cifs_open_parms {
14421442
bool reconnect:1;
14431443
bool replay:1; /* indicates that this open is for a replay */
14441444
struct kvec *ea_cctx;
1445+
__le32 lease_flags;
14451446
};
14461447

14471448
struct cifs_fid {
14481449
__u16 netfid;
14491450
__u64 persistent_fid; /* persist file id for smb2 */
14501451
__u64 volatile_fid; /* volatile file id for smb2 */
14511452
__u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for smb2 */
1453+
__u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
14521454
__u8 create_guid[16];
14531455
__u32 access;
14541456
struct cifs_pending_open *pending_open;

fs/smb/client/smb2ops.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4069,7 +4069,7 @@ map_oplock_to_lease(u8 oplock)
40694069
}
40704070

40714071
static char *
4072-
smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4072+
smb2_create_lease_buf(u8 *lease_key, u8 oplock, u8 *parent_lease_key, __le32 flags)
40734073
{
40744074
struct create_lease *buf;
40754075

@@ -4095,7 +4095,7 @@ smb2_create_lease_buf(u8 *lease_key, u8 oplock)
40954095
}
40964096

40974097
static char *
4098-
smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4098+
smb3_create_lease_buf(u8 *lease_key, u8 oplock, u8 *parent_lease_key, __le32 flags)
40994099
{
41004100
struct create_lease_v2 *buf;
41014101

@@ -4105,6 +4105,9 @@ smb3_create_lease_buf(u8 *lease_key, u8 oplock)
41054105

41064106
memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
41074107
buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4108+
buf->lcontext.LeaseFlags = flags;
4109+
if (flags & SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE)
4110+
memcpy(&buf->lcontext.ParentLeaseKey, parent_lease_key, SMB2_LEASE_KEY_SIZE);
41084111

41094112
buf->ccontext.DataOffset = cpu_to_le16(offsetof
41104113
(struct create_lease_v2, lcontext));

fs/smb/client/smb2pdu.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,11 +2392,16 @@ static int
23922392
add_lease_context(struct TCP_Server_Info *server,
23932393
struct smb2_create_req *req,
23942394
struct kvec *iov,
2395-
unsigned int *num_iovec, u8 *lease_key, __u8 *oplock)
2395+
unsigned int *num_iovec,
2396+
u8 *lease_key,
2397+
__u8 *oplock,
2398+
u8 *parent_lease_key,
2399+
__le32 flags)
23962400
{
23972401
unsigned int num = *num_iovec;
23982402

2399-
iov[num].iov_base = server->ops->create_lease_buf(lease_key, *oplock);
2403+
iov[num].iov_base = server->ops->create_lease_buf(lease_key, *oplock,
2404+
parent_lease_key, flags);
24002405
if (iov[num].iov_base == NULL)
24012406
return -ENOMEM;
24022407
iov[num].iov_len = server->vals->create_lease_size;
@@ -3069,7 +3074,9 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
30693074
req->RequestedOplockLevel = *oplock; /* no srv lease support */
30703075
else {
30713076
rc = add_lease_context(server, req, iov, &n_iov,
3072-
oparms->fid->lease_key, oplock);
3077+
oparms->fid->lease_key, oplock,
3078+
oparms->fid->parent_lease_key,
3079+
oparms->lease_flags);
30733080
if (rc)
30743081
return rc;
30753082
}

0 commit comments

Comments
 (0)