[PATCH 06/11] cifs: have cifs_new_fileinfo take a tcon arg

Jeff Layton <[email protected]>
Newsgroups gmane.linux.file-systems.cifs,gmane.linux.file-systems
Message-ID <[email protected]>
To minimize calls to cifs_sb_tcon and to allow for a clear error path if
a tcon can't be acquired.

Signed-off-by: Jeff Layton <[email protected]>
---
 fs/cifs/dir.c  |   26 ++++++++++++++++++--------
 fs/cifs/file.c |    6 +++++-
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index e563314..05ee024 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -131,8 +131,9 @@ cifs_bp_rename_retry:
 }
 
 struct cifsFileInfo *
-cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle,
-		  struct file *file, struct vfsmount *mnt, unsigned int oflags)
+cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle, struct file *file,
+		  struct vfsmount *mnt, struct cifsTconInfo *tcon,
+		  unsigned int oflags)
 {
 	int oplock = 0;
 	struct cifsFileInfo *pCifsFile;
@@ -154,7 +155,7 @@ cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle,
 	pCifsFile->pfile = file;
 	pCifsFile->invalidHandle = false;
 	pCifsFile->closePend = false;
-	pCifsFile->tcon = cifs_sb_tcon(cifs_sb);
+	pCifsFile->tcon = tcon;
 	mutex_init(&pCifsFile->fh_mutex);
 	mutex_init(&pCifsFile->lock_mutex);
 	INIT_LIST_HEAD(&pCifsFile->llist);
@@ -193,6 +194,10 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
 	__u32 posix_flags = 0;
 	struct cifs_sb_info *cifs_sb = CIFS_SB(mnt->mnt_sb);
 	struct cifs_fattr fattr;
+	struct cifsTconInfo *tcon = cifs_sb_tcon(cifs_sb);
+
+	if (IS_ERR(tcon))
+		return PTR_ERR(tcon);
 
 	cFYI(1, ("posix open %s", full_path));
 
@@ -227,9 +232,9 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
 		posix_flags |= SMB_O_DIRECT;
 
 	mode &= ~current_umask();
-	rc = CIFSPOSIXCreate(xid, cifs_sb_tcon(cifs_sb), posix_flags, mode,
-			pnetfid, presp_data, poplock, full_path,
-			cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
+	rc = CIFSPOSIXCreate(xid, tcon, posix_flags, mode, pnetfid, presp_data,
+			     poplock, full_path, cifs_sb->local_nls,
+			     cifs_sb->mnt_cifs_flags &
 					CIFS_MOUNT_MAP_SPECIAL_CHR);
 	if (rc)
 		goto posix_open_ret;
@@ -253,7 +258,7 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
 		cifs_fattr_to_inode(*pinode, &fattr);
 	}
 
-	cifs_new_fileinfo(*pinode, *pnetfid, NULL, mnt, oflags);
+	cifs_new_fileinfo(*pinode, *pnetfid, NULL, mnt, tcon, oflags);
 
 posix_open_ret:
 	kfree(presp_data);
@@ -304,6 +309,11 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
 	cifs_sb = CIFS_SB(inode->i_sb);
 	tcon = cifs_sb_tcon(cifs_sb);
 
+	if (IS_ERR(tcon)) {
+		FreeXid(xid);
+		return PTR_ERR(tcon);
+	}
+
 	full_path = build_path_from_dentry(direntry);
 	if (full_path == NULL) {
 		rc = -ENOMEM;
@@ -467,7 +477,7 @@ cifs_create_set_dentry:
 		CIFSSMBClose(xid, tcon, fileHandle);
 	} else if (!(posix_create) && (newinode)) {
 			cifs_new_fileinfo(newinode, fileHandle, NULL,
-						nd->path.mnt, oflags);
+					  nd->path.mnt, tcon, oflags);
 	}
 cifs_create_out:
 	kfree(buf);
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 651dde4..26665b8 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -269,6 +269,10 @@ int cifs_open(struct inode *inode, struct file *file)
 
 	cifs_sb = CIFS_SB(inode->i_sb);
 	tcon = cifs_sb_tcon(cifs_sb);
+	if (IS_ERR(tcon)) {
+		FreeXid(xid);
+		return PTR_ERR(tcon);
+	}
 
 	pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
 	pCifsFile = cifs_fill_filedata(file);
@@ -391,7 +395,7 @@ int cifs_open(struct inode *inode, struct file *file)
 	}
 
 	pCifsFile = cifs_new_fileinfo(inode, netfid, file, file->f_path.mnt,
-					file->f_flags);
+				      tcon, file->f_flags);
 	file->private_data = pCifsFile;
 	if (file->private_data == NULL) {
 		rc = -ENOMEM;
-- 
1.6.6.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.