Commit 2b9b6f10 authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] kNFSd: get rid of open_private_file

This is only used by nfsd to save one kmalloc, and the code is not always
kept up-to-date with dentry_open, so just get rid of it.
Signed-off-by: default avatarNeil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 08dd6c30
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/file.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/namei.h> #include <linux/namei.h>
...@@ -347,7 +348,7 @@ static int get_name(struct dentry *dentry, char *name, ...@@ -347,7 +348,7 @@ static int get_name(struct dentry *dentry, char *name,
{ {
struct inode *dir = dentry->d_inode; struct inode *dir = dentry->d_inode;
int error; int error;
struct file file; struct file *file;
struct getdents_callback buffer; struct getdents_callback buffer;
error = -ENOTDIR; error = -ENOTDIR;
...@@ -359,11 +360,13 @@ static int get_name(struct dentry *dentry, char *name, ...@@ -359,11 +360,13 @@ static int get_name(struct dentry *dentry, char *name,
/* /*
* Open the directory ... * Open the directory ...
*/ */
error = open_private_file(&file, dentry, O_RDONLY); file = dentry_open(dget(dentry), NULL, O_RDONLY);
if (error) error = PTR_ERR(file);
if (IS_ERR(file))
goto out; goto out;
error = -EINVAL; error = -EINVAL;
if (!file.f_op->readdir) if (!file->f_op->readdir)
goto out_close; goto out_close;
buffer.name = name; buffer.name = name;
...@@ -373,7 +376,7 @@ static int get_name(struct dentry *dentry, char *name, ...@@ -373,7 +376,7 @@ static int get_name(struct dentry *dentry, char *name,
while (1) { while (1) {
int old_seq = buffer.sequence; int old_seq = buffer.sequence;
error = vfs_readdir(&file, filldir_one, &buffer); error = vfs_readdir(file, filldir_one, &buffer);
if (error < 0) if (error < 0)
break; break;
...@@ -387,7 +390,7 @@ static int get_name(struct dentry *dentry, char *name, ...@@ -387,7 +390,7 @@ static int get_name(struct dentry *dentry, char *name,
} }
out_close: out_close:
close_private_file(&file); fput(file);
out: out:
return error; return error;
} }
......
...@@ -106,52 +106,6 @@ static int old_max; ...@@ -106,52 +106,6 @@ static int old_max;
EXPORT_SYMBOL(get_empty_filp); EXPORT_SYMBOL(get_empty_filp);
/*
* Clear and initialize a (private) struct file for the given dentry,
* allocate the security structure, and call the open function (if any).
* The file should be released using close_private_file.
*/
int open_private_file(struct file *filp, struct dentry *dentry, int flags)
{
int error;
memset(filp, 0, sizeof(*filp));
eventpoll_init_file(filp);
filp->f_flags = flags;
filp->f_mode = ((flags+1) & O_ACCMODE) | FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE;
atomic_set(&filp->f_count, 1);
filp->f_dentry = dentry;
filp->f_mapping = dentry->d_inode->i_mapping;
filp->f_uid = current->fsuid;
filp->f_gid = current->fsgid;
filp->f_op = dentry->d_inode->i_fop;
INIT_LIST_HEAD(&filp->f_list);
error = security_file_alloc(filp);
if (!error)
if (filp->f_op && filp->f_op->open) {
error = filp->f_op->open(dentry->d_inode, filp);
if (error)
security_file_free(filp);
}
return error;
}
EXPORT_SYMBOL(open_private_file);
/*
* Release a private file by calling the release function (if any) and
* freeing the security structure.
*/
void close_private_file(struct file *file)
{
struct inode * inode = file->f_dentry->d_inode;
if (file->f_op && file->f_op->release)
file->f_op->release(inode, file);
security_file_free(file);
}
EXPORT_SYMBOL(close_private_file);
void fastcall fput(struct file *file) void fastcall fput(struct file *file)
{ {
if (atomic_dec_and_test(&file->f_count)) if (atomic_dec_and_test(&file->f_count))
......
...@@ -53,7 +53,7 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, ...@@ -53,7 +53,7 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
*filp = file; *filp = file;
/* Set up the missing parts of the file_lock structure */ /* Set up the missing parts of the file_lock structure */
lock->fl.fl_file = &file->f_file; lock->fl.fl_file = file->f_file;
lock->fl.fl_owner = (fl_owner_t) host; lock->fl.fl_owner = (fl_owner_t) host;
} }
......
...@@ -238,7 +238,7 @@ nlmsvc_delete_block(struct nlm_block *block, int unlock) ...@@ -238,7 +238,7 @@ nlmsvc_delete_block(struct nlm_block *block, int unlock)
/* Remove block from list */ /* Remove block from list */
nlmsvc_remove_block(block); nlmsvc_remove_block(block);
posix_unblock_lock(&file->f_file, fl); posix_unblock_lock(file->f_file, fl);
block->b_granted = 0; block->b_granted = 0;
/* If the block is in the middle of a GRANT callback, /* If the block is in the middle of a GRANT callback,
...@@ -299,8 +299,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, ...@@ -299,8 +299,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
int error; int error;
dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n", dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",
file->f_file.f_dentry->d_inode->i_sb->s_id, file->f_file->f_dentry->d_inode->i_sb->s_id,
file->f_file.f_dentry->d_inode->i_ino, file->f_file->f_dentry->d_inode->i_ino,
lock->fl.fl_type, lock->fl.fl_pid, lock->fl.fl_type, lock->fl.fl_pid,
(long long)lock->fl.fl_start, (long long)lock->fl.fl_start,
(long long)lock->fl.fl_end, (long long)lock->fl.fl_end,
...@@ -316,8 +316,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, ...@@ -316,8 +316,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
/* Lock file against concurrent access */ /* Lock file against concurrent access */
down(&file->f_sema); down(&file->f_sema);
if (!(conflock = posix_test_lock(&file->f_file, &lock->fl))) { if (!(conflock = posix_test_lock(file->f_file, &lock->fl))) {
error = posix_lock_file(&file->f_file, &lock->fl); error = posix_lock_file(file->f_file, &lock->fl);
if (block) if (block)
nlmsvc_delete_block(block, 0); nlmsvc_delete_block(block, 0);
...@@ -382,13 +382,13 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock, ...@@ -382,13 +382,13 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
struct file_lock *fl; struct file_lock *fl;
dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n", dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n",
file->f_file.f_dentry->d_inode->i_sb->s_id, file->f_file->f_dentry->d_inode->i_sb->s_id,
file->f_file.f_dentry->d_inode->i_ino, file->f_file->f_dentry->d_inode->i_ino,
lock->fl.fl_type, lock->fl.fl_type,
(long long)lock->fl.fl_start, (long long)lock->fl.fl_start,
(long long)lock->fl.fl_end); (long long)lock->fl.fl_end);
if ((fl = posix_test_lock(&file->f_file, &lock->fl)) != NULL) { if ((fl = posix_test_lock(file->f_file, &lock->fl)) != NULL) {
dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n", dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n",
fl->fl_type, (long long)fl->fl_start, fl->fl_type, (long long)fl->fl_start,
(long long)fl->fl_end); (long long)fl->fl_end);
...@@ -414,8 +414,8 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock) ...@@ -414,8 +414,8 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
int error; int error;
dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n", dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n",
file->f_file.f_dentry->d_inode->i_sb->s_id, file->f_file->f_dentry->d_inode->i_sb->s_id,
file->f_file.f_dentry->d_inode->i_ino, file->f_file->f_dentry->d_inode->i_ino,
lock->fl.fl_pid, lock->fl.fl_pid,
(long long)lock->fl.fl_start, (long long)lock->fl.fl_start,
(long long)lock->fl.fl_end); (long long)lock->fl.fl_end);
...@@ -424,7 +424,7 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock) ...@@ -424,7 +424,7 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
nlmsvc_cancel_blocked(file, lock); nlmsvc_cancel_blocked(file, lock);
lock->fl.fl_type = F_UNLCK; lock->fl.fl_type = F_UNLCK;
error = posix_lock_file(&file->f_file, &lock->fl); error = posix_lock_file(file->f_file, &lock->fl);
return (error < 0)? nlm_lck_denied_nolocks : nlm_granted; return (error < 0)? nlm_lck_denied_nolocks : nlm_granted;
} }
...@@ -442,8 +442,8 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock) ...@@ -442,8 +442,8 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
struct nlm_block *block; struct nlm_block *block;
dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n", dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n",
file->f_file.f_dentry->d_inode->i_sb->s_id, file->f_file->f_dentry->d_inode->i_sb->s_id,
file->f_file.f_dentry->d_inode->i_ino, file->f_file->f_dentry->d_inode->i_ino,
lock->fl.fl_pid, lock->fl.fl_pid,
(long long)lock->fl.fl_start, (long long)lock->fl.fl_start,
(long long)lock->fl.fl_end); (long long)lock->fl.fl_end);
...@@ -515,7 +515,7 @@ nlmsvc_grant_blocked(struct nlm_block *block) ...@@ -515,7 +515,7 @@ nlmsvc_grant_blocked(struct nlm_block *block)
} }
/* Try the lock operation again */ /* Try the lock operation again */
if ((conflock = posix_test_lock(&file->f_file, &lock->fl)) != NULL) { if ((conflock = posix_test_lock(file->f_file, &lock->fl)) != NULL) {
/* Bummer, we blocked again */ /* Bummer, we blocked again */
dprintk("lockd: lock still blocked\n"); dprintk("lockd: lock still blocked\n");
nlmsvc_insert_block(block, NLM_NEVER); nlmsvc_insert_block(block, NLM_NEVER);
...@@ -528,7 +528,7 @@ nlmsvc_grant_blocked(struct nlm_block *block) ...@@ -528,7 +528,7 @@ nlmsvc_grant_blocked(struct nlm_block *block)
* following yields an error, this is most probably due to low * following yields an error, this is most probably due to low
* memory. Retry the lock in a few seconds. * memory. Retry the lock in a few seconds.
*/ */
if ((error = posix_lock_file(&file->f_file, &lock->fl)) < 0) { if ((error = posix_lock_file(file->f_file, &lock->fl)) < 0) {
printk(KERN_WARNING "lockd: unexpected error %d in %s!\n", printk(KERN_WARNING "lockd: unexpected error %d in %s!\n",
-error, __FUNCTION__); -error, __FUNCTION__);
nlmsvc_insert_block(block, 10 * HZ); nlmsvc_insert_block(block, 10 * HZ);
......
...@@ -82,7 +82,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, ...@@ -82,7 +82,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
*filp = file; *filp = file;
/* Set up the missing parts of the file_lock structure */ /* Set up the missing parts of the file_lock structure */
lock->fl.fl_file = &file->f_file; lock->fl.fl_file = file->f_file;
lock->fl.fl_owner = (fl_owner_t) host; lock->fl.fl_owner = (fl_owner_t) host;
} }
......
...@@ -124,7 +124,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result, ...@@ -124,7 +124,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,
static inline void static inline void
nlm_delete_file(struct nlm_file *file) nlm_delete_file(struct nlm_file *file)
{ {
struct inode *inode = file->f_file.f_dentry->d_inode; struct inode *inode = file->f_file->f_dentry->d_inode;
struct nlm_file **fp, *f; struct nlm_file **fp, *f;
dprintk("lockd: closing file %s/%ld\n", dprintk("lockd: closing file %s/%ld\n",
...@@ -133,7 +133,7 @@ nlm_delete_file(struct nlm_file *file) ...@@ -133,7 +133,7 @@ nlm_delete_file(struct nlm_file *file)
while ((f = *fp) != NULL) { while ((f = *fp) != NULL) {
if (f == file) { if (f == file) {
*fp = file->f_next; *fp = file->f_next;
nlmsvc_ops->fclose(&file->f_file); nlmsvc_ops->fclose(file->f_file);
kfree(file); kfree(file);
return; return;
} }
...@@ -176,7 +176,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, int action) ...@@ -176,7 +176,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, int action)
lock.fl_type = F_UNLCK; lock.fl_type = F_UNLCK;
lock.fl_start = 0; lock.fl_start = 0;
lock.fl_end = OFFSET_MAX; lock.fl_end = OFFSET_MAX;
if (posix_lock_file(&file->f_file, &lock) < 0) { if (posix_lock_file(file->f_file, &lock) < 0) {
printk("lockd: unlock failure in %s:%d\n", printk("lockd: unlock failure in %s:%d\n",
__FILE__, __LINE__); __FILE__, __LINE__);
return 1; return 1;
...@@ -230,7 +230,7 @@ nlm_traverse_files(struct nlm_host *host, int action) ...@@ -230,7 +230,7 @@ nlm_traverse_files(struct nlm_host *host, int action)
if (!file->f_blocks && !file->f_locks if (!file->f_blocks && !file->f_locks
&& !file->f_shares && !file->f_count) { && !file->f_shares && !file->f_count) {
*fp = file->f_next; *fp = file->f_next;
nlmsvc_ops->fclose(&file->f_file); nlmsvc_ops->fclose(file->f_file);
kfree(file); kfree(file);
} else { } else {
fp = &file->f_next; fp = &file->f_next;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/file.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/svc.h> #include <linux/sunrpc/svc.h>
...@@ -22,7 +23,7 @@ ...@@ -22,7 +23,7 @@
* Note: we hold the dentry use count while the file is open. * Note: we hold the dentry use count while the file is open.
*/ */
static u32 static u32
nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file *filp) nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)
{ {
u32 nfserr; u32 nfserr;
struct svc_fh fh; struct svc_fh fh;
...@@ -35,10 +36,6 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file *filp) ...@@ -35,10 +36,6 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file *filp)
exp_readlock(); exp_readlock();
nfserr = nfsd_open(rqstp, &fh, S_IFREG, MAY_LOCK, filp); nfserr = nfsd_open(rqstp, &fh, S_IFREG, MAY_LOCK, filp);
if (!nfserr) {
dget(filp->f_dentry);
mntget(filp->f_vfsmnt);
}
fh_put(&fh); fh_put(&fh);
rqstp->rq_client = NULL; rqstp->rq_client = NULL;
exp_readunlock(); exp_readunlock();
...@@ -60,9 +57,7 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file *filp) ...@@ -60,9 +57,7 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file *filp)
static void static void
nlm_fclose(struct file *filp) nlm_fclose(struct file *filp)
{ {
nfsd_close(filp); fput(filp);
dput(filp->f_dentry);
mntput(filp->f_vfsmnt);
} }
struct nlmsvc_binding nfsd_nlm_ops = { struct nlmsvc_binding nfsd_nlm_ops = {
......
...@@ -962,12 +962,10 @@ release_stateid(struct nfs4_stateid *stp, int flags) { ...@@ -962,12 +962,10 @@ release_stateid(struct nfs4_stateid *stp, int flags) {
list_del(&stp->st_perfilestate); list_del(&stp->st_perfilestate);
if((stp->st_vfs_set) && (flags & OPEN_STATE)) { if((stp->st_vfs_set) && (flags & OPEN_STATE)) {
release_stateid_lockowner(stp); release_stateid_lockowner(stp);
nfsd_close(&stp->st_vfs_file); nfsd_close(stp->st_vfs_file);
vfsclose++; vfsclose++;
dput(stp->st_vfs_file.f_dentry);
mntput(stp->st_vfs_file.f_vfsmnt);
} else if ((stp->st_vfs_set) && (flags & LOCK_STATE)) { } else if ((stp->st_vfs_set) && (flags & LOCK_STATE)) {
struct file *filp = &stp->st_vfs_file; struct file *filp = stp->st_vfs_file;
locks_remove_posix(filp, (fl_owner_t) stp->st_stateowner); locks_remove_posix(filp, (fl_owner_t) stp->st_stateowner);
} }
...@@ -1315,8 +1313,6 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf ...@@ -1315,8 +1313,6 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
goto out_free; goto out_free;
vfsopen++; vfsopen++;
dget(stp->st_vfs_file.f_dentry);
mntget(stp->st_vfs_file.f_vfsmnt);
init_stateid(stp, fp, sop, open); init_stateid(stp, fp, sop, open);
stp->st_vfs_set = 1; stp->st_vfs_set = 1;
...@@ -1331,7 +1327,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf ...@@ -1331,7 +1327,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
share_access &= open->op_share_access; share_access &= open->op_share_access;
/* update the struct file */ /* update the struct file */
if ((status = nfs4_file_upgrade(&stp->st_vfs_file, share_access))) if ((status = nfs4_file_upgrade(stp->st_vfs_file, share_access)))
goto out; goto out;
/* remember the open */ /* remember the open */
set_bit(open->op_share_access, &stp->st_access_bmap); set_bit(open->op_share_access, &stp->st_access_bmap);
...@@ -1499,7 +1495,7 @@ static inline int ...@@ -1499,7 +1495,7 @@ static inline int
nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp) nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp)
{ {
return (stp->st_vfs_set == 0 || return (stp->st_vfs_set == 0 ||
fhp->fh_dentry->d_inode != stp->st_vfs_file.f_dentry->d_inode); fhp->fh_dentry->d_inode != stp->st_vfs_file->f_dentry->d_inode);
} }
static int static int
...@@ -1816,7 +1812,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct n ...@@ -1816,7 +1812,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct n
goto out; goto out;
} }
set_access(&share_access, stp->st_access_bmap); set_access(&share_access, stp->st_access_bmap);
nfs4_file_downgrade(&stp->st_vfs_file, nfs4_file_downgrade(stp->st_vfs_file,
share_access & ~od->od_share_access); share_access & ~od->od_share_access);
reset_union_bmap_access(od->od_share_access, &stp->st_access_bmap); reset_union_bmap_access(od->od_share_access, &stp->st_access_bmap);
...@@ -2059,7 +2055,7 @@ alloc_init_lock_stateid(struct nfs4_stateowner *sop, struct nfs4_file *fp, struc ...@@ -2059,7 +2055,7 @@ alloc_init_lock_stateid(struct nfs4_stateowner *sop, struct nfs4_file *fp, struc
stp->st_stateid.si_stateownerid = sop->so_id; stp->st_stateid.si_stateownerid = sop->so_id;
stp->st_stateid.si_fileid = fp->fi_id; stp->st_stateid.si_fileid = fp->fi_id;
stp->st_stateid.si_generation = 0; stp->st_stateid.si_generation = 0;
stp->st_vfs_file = open_stp->st_vfs_file; stp->st_vfs_file = open_stp->st_vfs_file; /* FIXME refcount?? */
stp->st_vfs_set = open_stp->st_vfs_set; stp->st_vfs_set = open_stp->st_vfs_set;
stp->st_access_bmap = open_stp->st_access_bmap; stp->st_access_bmap = open_stp->st_access_bmap;
stp->st_deny_bmap = open_stp->st_deny_bmap; stp->st_deny_bmap = open_stp->st_deny_bmap;
...@@ -2172,7 +2168,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock ...@@ -2172,7 +2168,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
goto out; goto out;
} }
/* lock->lk_stateowner and lock_stp have been created or found */ /* lock->lk_stateowner and lock_stp have been created or found */
filp = &lock_stp->st_vfs_file; filp = lock_stp->st_vfs_file;
if ((status = fh_verify(rqstp, current_fh, S_IFREG, MAY_LOCK))) { if ((status = fh_verify(rqstp, current_fh, S_IFREG, MAY_LOCK))) {
printk("NFSD: nfsd4_lock: permission denied!\n"); printk("NFSD: nfsd4_lock: permission denied!\n");
...@@ -2378,7 +2374,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock ...@@ -2378,7 +2374,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
&locku->lu_stateowner, &stp, NULL))) &locku->lu_stateowner, &stp, NULL)))
goto out; goto out;
filp = &stp->st_vfs_file; filp = stp->st_vfs_file;
BUG_ON(!filp); BUG_ON(!filp);
file_lock.fl_type = F_UNLCK; file_lock.fl_type = F_UNLCK;
file_lock.fl_owner = (fl_owner_t) locku->lu_stateowner; file_lock.fl_owner = (fl_owner_t) locku->lu_stateowner;
...@@ -2473,7 +2469,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp, struct nfsd4_release_lockowner * ...@@ -2473,7 +2469,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp, struct nfsd4_release_lockowner *
list_for_each_entry(stp, &local->so_perfilestate, list_for_each_entry(stp, &local->so_perfilestate,
st_perfilestate) { st_perfilestate) {
if(stp->st_vfs_set) { if(stp->st_vfs_set) {
if (check_for_locks(&stp->st_vfs_file, local)) if (check_for_locks(stp->st_vfs_file, local))
goto out; goto out;
} }
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/time.h> #include <linux/time.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/file.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/major.h> #include <linux/major.h>
#include <linux/ext2_fs.h> #include <linux/ext2_fs.h>
...@@ -79,6 +80,7 @@ struct raparms { ...@@ -79,6 +80,7 @@ struct raparms {
unsigned int p_count; unsigned int p_count;
ino_t p_ino; ino_t p_ino;
dev_t p_dev; dev_t p_dev;
int p_set;
struct file_ra_state p_ra; struct file_ra_state p_ra;
}; };
...@@ -635,7 +637,7 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor ...@@ -635,7 +637,7 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor
*/ */
int int
nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
int access, struct file *filp) int access, struct file **filp)
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
...@@ -671,21 +673,13 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, ...@@ -671,21 +673,13 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
goto out_nfserr; goto out_nfserr;
if (access & MAY_WRITE) { if (access & MAY_WRITE) {
err = get_write_access(inode);
if (err)
goto out_nfserr;
flags = O_WRONLY|O_LARGEFILE; flags = O_WRONLY|O_LARGEFILE;
DQUOT_INIT(inode); DQUOT_INIT(inode);
} }
*filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_mnt), flags);
err = open_private_file(filp, dentry, flags); if (IS_ERR(*filp))
if (!err) { err = PTR_ERR(*filp);
filp->f_vfsmnt = fhp->fh_export->ex_mnt;
} else if (access & MAY_WRITE)
put_write_access(inode);
out_nfserr: out_nfserr:
if (err) if (err)
err = nfserrno(err); err = nfserrno(err);
...@@ -699,12 +693,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, ...@@ -699,12 +693,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
void void
nfsd_close(struct file *filp) nfsd_close(struct file *filp)
{ {
struct dentry *dentry = filp->f_dentry; fput(filp);
struct inode *inode = dentry->d_inode;
close_private_file(filp);
if (filp->f_mode & FMODE_WRITE)
put_write_access(inode);
} }
/* /*
...@@ -748,7 +737,7 @@ nfsd_sync_dir(struct dentry *dp) ...@@ -748,7 +737,7 @@ nfsd_sync_dir(struct dentry *dp)
static spinlock_t ra_lock = SPIN_LOCK_UNLOCKED; static spinlock_t ra_lock = SPIN_LOCK_UNLOCKED;
static inline struct raparms * static inline struct raparms *
nfsd_get_raparms(dev_t dev, ino_t ino, struct address_space *mapping) nfsd_get_raparms(dev_t dev, ino_t ino)
{ {
struct raparms *ra, **rap, **frap = NULL; struct raparms *ra, **rap, **frap = NULL;
int depth = 0; int depth = 0;
...@@ -770,7 +759,7 @@ nfsd_get_raparms(dev_t dev, ino_t ino, struct address_space *mapping) ...@@ -770,7 +759,7 @@ nfsd_get_raparms(dev_t dev, ino_t ino, struct address_space *mapping)
ra = *frap; ra = *frap;
ra->p_dev = dev; ra->p_dev = dev;
ra->p_ino = ino; ra->p_ino = ino;
file_ra_state_init(&ra->p_ra, mapping); ra->p_set = 0;
found: found:
if (rap != &raparm_cache) { if (rap != &raparm_cache) {
*rap = ra->p_next; *rap = ra->p_next;
...@@ -827,14 +816,14 @@ nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, ...@@ -827,14 +816,14 @@ nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
struct raparms *ra; struct raparms *ra;
mm_segment_t oldfs; mm_segment_t oldfs;
int err; int err;
struct file file; struct file *file;
struct inode *inode; struct inode *inode;
err = nfsd_open(rqstp, fhp, S_IFREG, MAY_READ, &file); err = nfsd_open(rqstp, fhp, S_IFREG, MAY_READ, &file);
if (err) if (err)
goto out; goto out;
err = nfserr_perm; err = nfserr_perm;
inode = file.f_dentry->d_inode; inode = file->f_dentry->d_inode;
#ifdef MSNFS #ifdef MSNFS
if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) && if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) &&
(!lock_may_read(inode, offset, *count))) (!lock_may_read(inode, offset, *count)))
...@@ -842,38 +831,40 @@ nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, ...@@ -842,38 +831,40 @@ nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
#endif #endif
/* Get readahead parameters */ /* Get readahead parameters */
ra = nfsd_get_raparms(inode->i_sb->s_dev, inode->i_ino, ra = nfsd_get_raparms(inode->i_sb->s_dev, inode->i_ino);
inode->i_mapping->host->i_mapping);
if (ra) if (ra && ra->p_set)
file.f_ra = ra->p_ra; file->f_ra = ra->p_ra;
if (file.f_op->sendfile) { if (file->f_op->sendfile) {
svc_pushback_unused_pages(rqstp); svc_pushback_unused_pages(rqstp);
err = file.f_op->sendfile(&file, &offset, *count, err = file->f_op->sendfile(file, &offset, *count,
nfsd_read_actor, rqstp); nfsd_read_actor, rqstp);
} else { } else {
oldfs = get_fs(); oldfs = get_fs();
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
err = vfs_readv(&file, (struct iovec __user *)vec, vlen, &offset); err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
set_fs(oldfs); set_fs(oldfs);
} }
/* Write back readahead params */ /* Write back readahead params */
if (ra) { if (ra) {
spin_lock(&ra_lock); spin_lock(&ra_lock);
ra->p_ra = file.f_ra; ra->p_ra = file->f_ra;
ra->p_set = 1;
ra->p_count--; ra->p_count--;
spin_unlock(&ra_lock); spin_unlock(&ra_lock);
} }
if (err >= 0) { if (err >= 0) {
nfsdstats.io_read += err; nfsdstats.io_read += err;
*count = err; *count = err;
err = 0; err = 0;
dnotify_parent(file.f_dentry, DN_ACCESS); dnotify_parent(file->f_dentry, DN_ACCESS);
} else } else
err = nfserrno(err); err = nfserrno(err);
out_close: out_close:
nfsd_close(&file); nfsd_close(file);
out: out:
return err; return err;
} }
...@@ -889,7 +880,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, ...@@ -889,7 +880,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
unsigned long cnt, int *stablep) unsigned long cnt, int *stablep)
{ {
struct svc_export *exp; struct svc_export *exp;
struct file file; struct file *file;
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
mm_segment_t oldfs; mm_segment_t oldfs;
...@@ -905,11 +896,11 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, ...@@ -905,11 +896,11 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
#ifdef MSNFS #ifdef MSNFS
if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) && if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) &&
(!lock_may_write(file.f_dentry->d_inode, offset, cnt))) (!lock_may_write(file->f_dentry->d_inode, offset, cnt)))
goto out_close; goto out_close;
#endif #endif
dentry = file.f_dentry; dentry = file->f_dentry;
inode = dentry->d_inode; inode = dentry->d_inode;
exp = fhp->fh_export; exp = fhp->fh_export;
...@@ -922,7 +913,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, ...@@ -922,7 +913,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
* flushing the data to disk is handled separately below. * flushing the data to disk is handled separately below.
*/ */
if (file.f_op->fsync == 0) {/* COMMIT3 cannot work */ if (file->f_op->fsync == 0) {/* COMMIT3 cannot work */
stable = 2; stable = 2;
*stablep = 2; /* FILE_SYNC */ *stablep = 2; /* FILE_SYNC */
} }
...@@ -930,15 +921,15 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, ...@@ -930,15 +921,15 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
if (!EX_ISSYNC(exp)) if (!EX_ISSYNC(exp))
stable = 0; stable = 0;
if (stable && !EX_WGATHER(exp)) if (stable && !EX_WGATHER(exp))
file.f_flags |= O_SYNC; file->f_flags |= O_SYNC;
/* Write the data. */ /* Write the data. */
oldfs = get_fs(); set_fs(KERNEL_DS); oldfs = get_fs(); set_fs(KERNEL_DS);
err = vfs_writev(&file, (struct iovec __user *)vec, vlen, &offset); err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
set_fs(oldfs); set_fs(oldfs);
if (err >= 0) { if (err >= 0) {
nfsdstats.io_write += cnt; nfsdstats.io_write += cnt;
dnotify_parent(file.f_dentry, DN_MODIFY); dnotify_parent(file->f_dentry, DN_MODIFY);
} }
/* clear setuid/setgid flag after write */ /* clear setuid/setgid flag after write */
...@@ -978,7 +969,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, ...@@ -978,7 +969,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
if (inode->i_state & I_DIRTY) { if (inode->i_state & I_DIRTY) {
dprintk("nfsd: write sync %d\n", current->pid); dprintk("nfsd: write sync %d\n", current->pid);
nfsd_sync(&file); nfsd_sync(file);
} }
#if 0 #if 0
wake_up(&inode->i_wait); wake_up(&inode->i_wait);
...@@ -994,7 +985,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, ...@@ -994,7 +985,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
else else
err = nfserrno(err); err = nfserrno(err);
out_close: out_close:
nfsd_close(&file); nfsd_close(file);
out: out:
return err; return err;
} }
...@@ -1013,7 +1004,7 @@ int ...@@ -1013,7 +1004,7 @@ int
nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
loff_t offset, unsigned long count) loff_t offset, unsigned long count)
{ {
struct file file; struct file *file;
int err; int err;
if ((u64)count > ~(u64)offset) if ((u64)count > ~(u64)offset)
...@@ -1022,14 +1013,14 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, ...@@ -1022,14 +1013,14 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
if ((err = nfsd_open(rqstp, fhp, S_IFREG, MAY_WRITE, &file)) != 0) if ((err = nfsd_open(rqstp, fhp, S_IFREG, MAY_WRITE, &file)) != 0)
return err; return err;
if (EX_ISSYNC(fhp->fh_export)) { if (EX_ISSYNC(fhp->fh_export)) {
if (file.f_op && file.f_op->fsync) { if (file->f_op && file->f_op->fsync) {
nfsd_sync(&file); nfsd_sync(file);
} else { } else {
err = nfserr_notsupp; err = nfserr_notsupp;
} }
} }
nfsd_close(&file); nfsd_close(file);
return err; return err;
} }
#endif /* CONFIG_NFSD_V3 */ #endif /* CONFIG_NFSD_V3 */
...@@ -1652,14 +1643,14 @@ nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp, ...@@ -1652,14 +1643,14 @@ nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp,
struct readdir_cd *cdp, encode_dent_fn func) struct readdir_cd *cdp, encode_dent_fn func)
{ {
int err; int err;
struct file file; struct file *file;
loff_t offset = *offsetp; loff_t offset = *offsetp;
err = nfsd_open(rqstp, fhp, S_IFDIR, MAY_READ, &file); err = nfsd_open(rqstp, fhp, S_IFDIR, MAY_READ, &file);
if (err) if (err)
goto out; goto out;
offset = vfs_llseek(&file, offset, 0); offset = vfs_llseek(file, offset, 0);
if (offset < 0) { if (offset < 0) {
err = nfserrno((int)offset); err = nfserrno((int)offset);
goto out_close; goto out_close;
...@@ -1673,18 +1664,18 @@ nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp, ...@@ -1673,18 +1664,18 @@ nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp,
do { do {
cdp->err = nfserr_eof; /* will be cleared on successful read */ cdp->err = nfserr_eof; /* will be cleared on successful read */
err = vfs_readdir(&file, (filldir_t) func, cdp); err = vfs_readdir(file, (filldir_t) func, cdp);
} while (err >=0 && cdp->err == nfs_ok); } while (err >=0 && cdp->err == nfs_ok);
if (err) if (err)
err = nfserrno(err); err = nfserrno(err);
else else
err = cdp->err; err = cdp->err;
*offsetp = vfs_llseek(&file, 0, 1); *offsetp = vfs_llseek(file, 0, 1);
if (err == nfserr_eof || err == nfserr_toosmall) if (err == nfserr_eof || err == nfserr_toosmall)
err = nfs_ok; /* can still be found in ->err */ err = nfs_ok; /* can still be found in ->err */
out_close: out_close:
nfsd_close(&file); nfsd_close(file);
out: out:
return err; return err;
} }
......
...@@ -596,11 +596,6 @@ extern spinlock_t files_lock; ...@@ -596,11 +596,6 @@ extern spinlock_t files_lock;
#define get_file(x) atomic_inc(&(x)->f_count) #define get_file(x) atomic_inc(&(x)->f_count)
#define file_count(x) atomic_read(&(x)->f_count) #define file_count(x) atomic_read(&(x)->f_count)
/* Initialize and open a private file and allocate its security structure. */
extern int open_private_file(struct file *, struct dentry *, int);
/* Release a private file and free its security structure. */
extern void close_private_file(struct file *file);
#define MAX_NON_LFS ((1UL<<31) - 1) #define MAX_NON_LFS ((1UL<<31) - 1)
/* Page cache limit. The filesystems should put that into their s_maxbytes /* Page cache limit. The filesystems should put that into their s_maxbytes
......
...@@ -20,7 +20,7 @@ struct svc_rqst; ...@@ -20,7 +20,7 @@ struct svc_rqst;
struct nlmsvc_binding { struct nlmsvc_binding {
u32 (*fopen)(struct svc_rqst *, u32 (*fopen)(struct svc_rqst *,
struct nfs_fh *, struct nfs_fh *,
struct file *); struct file **);
void (*fclose)(struct file *); void (*fclose)(struct file *);
}; };
......
...@@ -77,7 +77,7 @@ struct nlm_rqst { ...@@ -77,7 +77,7 @@ struct nlm_rqst {
struct nlm_file { struct nlm_file {
struct nlm_file * f_next; /* linked list */ struct nlm_file * f_next; /* linked list */
struct nfs_fh f_handle; /* NFS file handle */ struct nfs_fh f_handle; /* NFS file handle */
struct file f_file; /* VFS file pointer */ struct file * f_file; /* VFS file pointer */
struct nlm_share * f_shares; /* DOS shares */ struct nlm_share * f_shares; /* DOS shares */
struct nlm_block * f_blocks; /* blocked locks */ struct nlm_block * f_blocks; /* blocked locks */
unsigned int f_locks; /* guesstimate # of locks */ unsigned int f_locks; /* guesstimate # of locks */
...@@ -180,7 +180,7 @@ void nlmsvc_invalidate_all(void); ...@@ -180,7 +180,7 @@ void nlmsvc_invalidate_all(void);
static __inline__ struct inode * static __inline__ struct inode *
nlmsvc_file_inode(struct nlm_file *file) nlmsvc_file_inode(struct nlm_file *file)
{ {
return file->f_file.f_dentry->d_inode; return file->f_file->f_dentry->d_inode;
} }
/* /*
......
...@@ -94,7 +94,7 @@ int nfsd_commit(struct svc_rqst *, struct svc_fh *, ...@@ -94,7 +94,7 @@ int nfsd_commit(struct svc_rqst *, struct svc_fh *,
loff_t, unsigned long); loff_t, unsigned long);
#endif /* CONFIG_NFSD_V3 */ #endif /* CONFIG_NFSD_V3 */
int nfsd_open(struct svc_rqst *, struct svc_fh *, int, int nfsd_open(struct svc_rqst *, struct svc_fh *, int,
int, struct file *); int, struct file **);
void nfsd_close(struct file *); void nfsd_close(struct file *);
int nfsd_read(struct svc_rqst *, struct svc_fh *, int nfsd_read(struct svc_rqst *, struct svc_fh *,
loff_t, struct kvec *,int, unsigned long *); loff_t, struct kvec *,int, unsigned long *);
......
...@@ -218,7 +218,7 @@ struct nfs4_stateid { ...@@ -218,7 +218,7 @@ struct nfs4_stateid {
struct nfs4_stateowner * st_stateowner; struct nfs4_stateowner * st_stateowner;
struct nfs4_file * st_file; struct nfs4_file * st_file;
stateid_t st_stateid; stateid_t st_stateid;
struct file st_vfs_file; struct file * st_vfs_file;
int st_vfs_set; int st_vfs_set;
unsigned long st_access_bmap; unsigned long st_access_bmap;
unsigned long st_deny_bmap; unsigned long st_deny_bmap;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment