diff options
Diffstat (limited to 'fs/cifs/cached_dir.c')
-rw-r--r-- | fs/cifs/cached_dir.c | 110 |
1 files changed, 67 insertions, 43 deletions
diff --git a/fs/cifs/cached_dir.c b/fs/cifs/cached_dir.c index 753b850b6f87..78e8deb82a0a 100644 --- a/fs/cifs/cached_dir.c +++ b/fs/cifs/cached_dir.c @@ -18,7 +18,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, const char *path, struct cifs_sb_info *cifs_sb, - struct cached_fid **cfid) + struct cached_fid **ret_cfid) { struct cifs_ses *ses; struct TCP_Server_Info *server; @@ -35,6 +35,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, u8 oplock = SMB2_OPLOCK_LEVEL_II; struct cifs_fid *pfid; struct dentry *dentry; + struct cached_fid *cfid; if (tcon == NULL || tcon->nohandlecache || is_smb1_server(tcon->ses->server)) @@ -51,12 +52,13 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, dentry = cifs_sb->root; - mutex_lock(&tcon->cfid.fid_mutex); - if (tcon->cfid.is_valid) { + cfid = tcon->cfid; + mutex_lock(&cfid->fid_mutex); + if (cfid->is_valid) { cifs_dbg(FYI, "found a cached root file handle\n"); - *cfid = &tcon->cfid; - kref_get(&tcon->cfid.refcount); - mutex_unlock(&tcon->cfid.fid_mutex); + *ret_cfid = cfid; + kref_get(&cfid->refcount); + mutex_unlock(&cfid->fid_mutex); return 0; } @@ -67,7 +69,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, * thus causing a deadlock */ - mutex_unlock(&tcon->cfid.fid_mutex); + mutex_unlock(&cfid->fid_mutex); if (smb3_encryption_required(tcon)) flags |= CIFS_TRANSFORM_REQ; @@ -75,7 +77,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, if (!server->ops->new_lease_key) return -EIO; - pfid = tcon->cfid.fid; + pfid = &cfid->fid; server->ops->new_lease_key(pfid); memset(rqst, 0, sizeof(rqst)); @@ -118,14 +120,14 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, rc = compound_send_recv(xid, ses, server, flags, 2, rqst, resp_buftype, rsp_iov); - mutex_lock(&tcon->cfid.fid_mutex); + mutex_lock(&cfid->fid_mutex); /* * Now we need to check again as the cached root might have * been successfully re-opened from a concurrent process */ - if (tcon->cfid.is_valid) { + if (cfid->is_valid) { /* work was already done */ /* stash fids for close() later */ @@ -138,9 +140,9 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, * caller expects this func to set the fid in cfid to valid * cached root, so increment the refcount. */ - kref_get(&tcon->cfid.refcount); + kref_get(&cfid->refcount); - mutex_unlock(&tcon->cfid.fid_mutex); + mutex_unlock(&cfid->fid_mutex); if (rc == 0) { /* close extra handle outside of crit sec */ @@ -170,11 +172,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, oparms.fid->mid = le64_to_cpu(o_rsp->hdr.MessageId); #endif /* CIFS_DEBUG2 */ - tcon->cfid.tcon = tcon; - tcon->cfid.is_valid = true; - tcon->cfid.dentry = dentry; + cfid->tcon = tcon; + cfid->is_valid = true; + cfid->dentry = dentry; dget(dentry); - kref_init(&tcon->cfid.refcount); + kref_init(&cfid->refcount); /* BB TBD check to see if oplock level check can be removed below */ if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) { @@ -182,8 +184,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, * See commit 2f94a3125b87. Increment the refcount when we * get a lease for root, release it if lease break occurs */ - kref_get(&tcon->cfid.refcount); - tcon->cfid.has_lease = true; + kref_get(&cfid->refcount); + cfid->has_lease = true; smb2_parse_contexts(server, o_rsp, &oparms.fid->epoch, oparms.fid->lease_key, &oplock, @@ -198,37 +200,41 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, le16_to_cpu(qi_rsp->OutputBufferOffset), sizeof(struct smb2_file_all_info), &rsp_iov[1], sizeof(struct smb2_file_all_info), - (char *)&tcon->cfid.file_all_info)) - tcon->cfid.file_all_info_is_valid = true; - tcon->cfid.time = jiffies; + (char *)&cfid->file_all_info)) + cfid->file_all_info_is_valid = true; + cfid->time = jiffies; oshr_exit: - mutex_unlock(&tcon->cfid.fid_mutex); + mutex_unlock(&cfid->fid_mutex); oshr_free: SMB2_open_free(&rqst[0]); SMB2_query_info_free(&rqst[1]); free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); if (rc == 0) - *cfid = &tcon->cfid; + *ret_cfid = cfid; return rc; } int open_cached_dir_by_dentry(struct cifs_tcon *tcon, struct dentry *dentry, - struct cached_fid **cfid) + struct cached_fid **ret_cfid) { - mutex_lock(&tcon->cfid.fid_mutex); - if (tcon->cfid.dentry == dentry) { + struct cached_fid *cfid; + + cfid = tcon->cfid; + + mutex_lock(&cfid->fid_mutex); + if (cfid->dentry == dentry) { cifs_dbg(FYI, "found a cached root file handle by dentry\n"); - *cfid = &tcon->cfid; - kref_get(&tcon->cfid.refcount); - mutex_unlock(&tcon->cfid.fid_mutex); + *ret_cfid = cfid; + kref_get(&cfid->refcount); + mutex_unlock(&cfid->fid_mutex); return 0; } - mutex_unlock(&tcon->cfid.fid_mutex); + mutex_unlock(&cfid->fid_mutex); return -ENOENT; } @@ -241,8 +247,8 @@ smb2_close_cached_fid(struct kref *ref) if (cfid->is_valid) { cifs_dbg(FYI, "clear cached root file handle\n"); - SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid, - cfid->fid->volatile_fid); + SMB2_close(0, cfid->tcon, cfid->fid.persistent_fid, + cfid->fid.volatile_fid); } /* @@ -312,7 +318,7 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb) tcon = tlink_tcon(tlink); if (IS_ERR(tcon)) continue; - cfid = &tcon->cfid; + cfid = tcon->cfid; mutex_lock(&cfid->fid_mutex); if (cfid->dentry) { dput(cfid->dentry); @@ -328,12 +334,12 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb) */ void invalidate_all_cached_dirs(struct cifs_tcon *tcon) { - mutex_lock(&tcon->cfid.fid_mutex); - tcon->cfid.is_valid = false; + mutex_lock(&tcon->cfid->fid_mutex); + tcon->cfid->is_valid = false; /* cached handle is not valid, so SMB2_CLOSE won't be sent below */ - close_cached_dir_lease_locked(&tcon->cfid); - memset(tcon->cfid.fid, 0, sizeof(struct cifs_fid)); - mutex_unlock(&tcon->cfid.fid_mutex); + close_cached_dir_lease_locked(tcon->cfid); + memset(&tcon->cfid->fid, 0, sizeof(struct cifs_fid)); + mutex_unlock(&tcon->cfid->fid_mutex); } static void @@ -347,16 +353,34 @@ smb2_cached_lease_break(struct work_struct *work) int cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16]) { - if (tcon->cfid.is_valid && + if (tcon->cfid->is_valid && !memcmp(lease_key, - tcon->cfid.fid->lease_key, + tcon->cfid->fid.lease_key, SMB2_LEASE_KEY_SIZE)) { - tcon->cfid.time = 0; - INIT_WORK(&tcon->cfid.lease_break, + tcon->cfid->time = 0; + INIT_WORK(&tcon->cfid->lease_break, smb2_cached_lease_break); queue_work(cifsiod_wq, - &tcon->cfid.lease_break); + &tcon->cfid->lease_break); return true; } return false; } + +struct cached_fid *init_cached_dir(void) +{ + struct cached_fid *cfid; + + cfid = kzalloc(sizeof(*cfid), GFP_KERNEL); + if (!cfid) + return NULL; + INIT_LIST_HEAD(&cfid->dirents.entries); + mutex_init(&cfid->dirents.de_mutex); + mutex_init(&cfid->fid_mutex); + return cfid; +} + +void free_cached_dir(struct cifs_tcon *tcon) +{ + kfree(tcon->cfid); +} |