Skip to content

Commit 0f220d3

Browse files
decarvSteve French
authored andcommitted
smb: client: use ParentLeaseKey in open_cached_dir
Implement ParentLeaseKey logic in open_cached_dir() by looking up the parent cfid, copying its lease key into the fid struct, and setting the appropriate lease flag. 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 51b78ff commit 0f220d3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

fs/smb/client/cached_dir.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
154154
struct cached_fids *cfids;
155155
const char *npath;
156156
int retries = 0, cur_sleep = 1;
157+
__le32 lease_flags = 0;
157158

158159
if (cifs_sb->root == NULL)
159160
return -ENOENT;
@@ -200,6 +201,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
200201
}
201202
spin_unlock(&cfids->cfid_list_lock);
202203

204+
pfid = &cfid->fid;
205+
203206
/*
204207
* Skip any prefix paths in @path as lookup_positive_unlocked() ends up
205208
* calling ->lookup() which already adds those through
@@ -221,6 +224,25 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
221224
rc = -ENOENT;
222225
goto out;
223226
}
227+
if (dentry->d_parent && server->dialect >= SMB30_PROT_ID) {
228+
struct cached_fid *parent_cfid;
229+
230+
spin_lock(&cfids->cfid_list_lock);
231+
list_for_each_entry(parent_cfid, &cfids->entries, entry) {
232+
if (parent_cfid->dentry == dentry->d_parent) {
233+
cifs_dbg(FYI, "found a parent cached file handle\n");
234+
if (parent_cfid->has_lease && parent_cfid->time) {
235+
lease_flags
236+
|= SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE;
237+
memcpy(pfid->parent_lease_key,
238+
parent_cfid->fid.lease_key,
239+
SMB2_LEASE_KEY_SIZE);
240+
}
241+
break;
242+
}
243+
}
244+
spin_unlock(&cfids->cfid_list_lock);
245+
}
224246
}
225247
cfid->dentry = dentry;
226248
cfid->tcon = tcon;
@@ -235,7 +257,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
235257
if (smb3_encryption_required(tcon))
236258
flags |= CIFS_TRANSFORM_REQ;
237259

238-
pfid = &cfid->fid;
239260
server->ops->new_lease_key(pfid);
240261

241262
memset(rqst, 0, sizeof(rqst));
@@ -255,6 +276,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
255276
FILE_READ_EA,
256277
.disposition = FILE_OPEN,
257278
.fid = pfid,
279+
.lease_flags = lease_flags,
258280
.replay = !!(retries),
259281
};
260282

0 commit comments

Comments
 (0)