lkml.org 
[lkml]   [2005]   [Mar]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH][3/7] cifs: file.c cleanups in incremental bits - cifs_init_private helper function

This patch (attached) adds a new helper function to fs/cifs/file.c called
cifs_init_private and changes cifs_open() to use it. Also adds a "out"
label to cifs_open to facilitate early escape in case of errors.
This shortens the function, tries to make the flow easier to follow as
well as reducing the nesting.

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>


--
Jesper Juhl

diff -up linux-2.6.11-mm3/fs/cifs/file.c.with_patch_3 linux-2.6.11-mm3/fs/cifs/file.c
--- linux-2.6.11-mm3/fs/cifs/file.c.with_patch_3 2005-03-15 22:55:45.000000000 +0100
+++ linux-2.6.11-mm3/fs/cifs/file.c 2005-03-16 00:29:23.000000000 +0100
@@ -35,6 +35,22 @@
#include "cifs_debug.h"
#include "cifs_fs_sb.h"

+static inline struct cifsFileInfo *cifs_init_private(
+ struct cifsFileInfo *private_data, struct inode *inode,
+ struct file *file, __u16 netfid)
+{
+ memset(private_data, 0, sizeof(struct cifsFileInfo));
+ private_data->netfid = netfid;
+ private_data->pid = current->tgid;
+ init_MUTEX(&private_data->fh_sem);
+ private_data->pfile = file; /* needed for writepage */
+ private_data->pInode = inode;
+ private_data->invalidHandle = FALSE;
+ private_data->closePend = FALSE;
+
+ return private_data;
+}
+
int cifs_open(struct inode *inode, struct file *file)
{
int rc = -EACCES;
@@ -49,6 +65,7 @@ int cifs_open(struct inode *inode, struc
int disposition;
__u16 netfid;
FILE_ALL_INFO *buf = NULL;
+ void *tmppriv = NULL;

xid = GetXid();

@@ -56,14 +73,20 @@ int cifs_open(struct inode *inode, struc
pTcon = cifs_sb->tcon;

if (file->f_flags & O_CREAT) {
- /* search inode for this file and fill in file->private_data = */
+ /* search inode for this file and fill in
+ file->private_data = */
pCifsInode = CIFS_I(file->f_dentry->d_inode);
read_lock(&GlobalSMBSeslock);
- list_for_each(tmp, &pCifsInode->openFileList) {
- pCifsFile = list_entry(tmp, struct cifsFileInfo, flist);
- if ((pCifsFile->pfile == NULL) && (pCifsFile->pid == current->tgid)) {
- /* mode set in cifs_create */
- pCifsFile->pfile = file; /* needed for writepage */
+ list_for_each(tmp, &pCifsInode->openFileList) {
+ pCifsFile = list_entry(tmp, struct cifsFileInfo,
+ flist);
+ if ((pCifsFile->pfile == NULL) &&
+ (pCifsFile->pid == current->tgid)) {
+ /* mode set in cifs_create */
+
+ /* needed for writepage */
+ pCifsFile->pfile = file;
+
file->private_data = pCifsFile;
break;
}
@@ -75,7 +98,8 @@ int cifs_open(struct inode *inode, struc
return rc;
} else {
if (file->f_flags & O_EXCL)
- cERROR(1, ("could not find file instance for new file %p ", file));
+ cERROR(1, ("could not find file instance for "
+ "new file %p ", file));
}
}

@@ -139,40 +163,38 @@ int cifs_open(struct inode *inode, struc

/* BB pass O_SYNC flag through on file attributes .. BB */

- /* Also refresh inode by passing in file_info buf returned by SMBOpen
- and calling get_inode_info with returned buf (at least
- helps non-Unix server case */
+ /* Also refresh inode by passing in file_info buf returned by SMBOpen
+ and calling get_inode_info with returned buf (at least helps
+ non-Unix server case) */

/* BB we can not do this if this is the second open of a file
- and the first handle has writebehind data, we might be
- able to simply do a filemap_fdatawrite/filemap_fdatawait first */
+ and the first handle has writebehind data, we might be
+ able to simply do a filemap_fdatawrite/filemap_fdatawait first */
buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
- if (buf == NULL) {
- kfree(full_path);
- FreeXid(xid);
- return -ENOMEM;
+ if (!buf) {
+ rc = -ENOMEM;
+ goto out;
+ }
+ tmppriv = kmalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
+ if (!tmppriv) {
+ rc = -ENOMEM;
+ goto out;
}
rc = CIFSSMBOpen(xid, pTcon, full_path, disposition, desiredAccess,
- CREATE_NOT_DIR, &netfid, &oplock, buf, cifs_sb->local_nls);
+ CREATE_NOT_DIR, &netfid, &oplock, buf,
+ cifs_sb->local_nls);
if (rc) {
cFYI(1, ("cifs_open returned 0x%x ", rc));
- cFYI(1, ("oplock: %d ", oplock));
- } else {
- file->private_data =
- kmalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
- if (file->private_data) {
- memset(file->private_data, 0, sizeof(struct cifsFileInfo));
- pCifsFile = (struct cifsFileInfo *)file->private_data;
- pCifsFile->netfid = netfid;
- pCifsFile->pid = current->tgid;
- init_MUTEX(&pCifsFile->fh_sem);
- pCifsFile->pfile = file; /* needed for writepage */
- pCifsFile->pInode = inode;
- pCifsFile->invalidHandle = FALSE;
- pCifsFile->closePend = FALSE;
- write_lock(&file->f_owner.lock);
- write_lock(&GlobalSMBSeslock);
- list_add(&pCifsFile->tlist, &pTcon->openFileList);
+ cFYI(1, ("oplock: %d ", oplock));
+ kfree(tmppriv);
+ goto out;
+ }
+ file->private_data = tmppriv;
+ pCifsFile = cifs_init_private(file->private_data, inode, file, netfid);
+ write_lock(&file->f_owner.lock);
+ write_lock(&GlobalSMBSeslock);
+ list_add(&pCifsFile->tlist, &pTcon->openFileList);
+
pCifsInode = CIFS_I(file->f_dentry->d_inode);
if (pCifsInode) {
/* want handles we can use to read with first */
@@ -228,25 +250,24 @@ int cifs_open(struct inode *inode, struc
write_unlock(&GlobalSMBSeslock);
write_unlock(&file->f_owner.lock);
}
- if (oplock & CIFS_CREATE_ACTION) {
- /* time to set mode which we can not set earlier due
- to problems creating new read-only files */
- if (cifs_sb->tcon->ses->capabilities & CAP_UNIX) {
- CIFSSMBUnixSetPerms(xid, pTcon, full_path, inode->i_mode,
- (__u64)-1,
- (__u64)-1,
- 0 /* dev */,
- cifs_sb->local_nls);
- } else {
- /* BB implement via Windows security descriptors eg */
- /* CIFSSMBWinSetPerms(xid, pTcon, full_path, mode, -1, -1, local_nls); */
- /* in the meantime could set r/o dos attribute when perms are eg: */
- /* mode & 0222 == 0 */
- }
- }
+ if (oplock & CIFS_CREATE_ACTION) {
+ /* time to set mode which we can not set earlier due to
+ problems creating new read-only files */
+ if (cifs_sb->tcon->ses->capabilities & CAP_UNIX) {
+ CIFSSMBUnixSetPerms(xid, pTcon, full_path,
+ inode->i_mode,
+ (__u64)-1, (__u64)-1, 0 /* dev */,
+ cifs_sb->local_nls);
+ } else {
+ /* BB implement via Windows security descriptors eg
+ CIFSSMBWinSetPerms(xid, pTcon, full_path, mode,
+ -1, -1, local_nls);
+ in the meantime could set r/o dos attribute when
+ perms are eg: mode & 0222 == 0 */
}
}

+out:
kfree(buf);
kfree(full_path);
FreeXid(xid);
\
 
 \ /
  Last update: 2005-03-22 14:11    [W:0.036 / U:0.956 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site