Commit 6caf69fe authored by Trond Myklebust's avatar Trond Myklebust

NFSv2/v3/v4: Place NFS nfs_page shared data into a single structure

   that hangs off filp->private_data. As a side effect, this also
   cleans up the NFSv4 private file state info.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@fys.uio.no>
parent af0ccd94
...@@ -110,7 +110,7 @@ nfs_free_user_pages(struct page **pages, int npages, int do_dirty) ...@@ -110,7 +110,7 @@ nfs_free_user_pages(struct page **pages, int npages, int do_dirty)
* nfs_direct_read_seg - Read in one iov segment. Generate separate * nfs_direct_read_seg - Read in one iov segment. Generate separate
* read RPCs for each "rsize" bytes. * read RPCs for each "rsize" bytes.
* @inode: target inode * @inode: target inode
* @file: target file (may be NULL) * @ctx: target file open context
* user_addr: starting address of this segment of user's buffer * user_addr: starting address of this segment of user's buffer
* count: size of this segment * count: size of this segment
* file_offset: offset in file to begin the operation * file_offset: offset in file to begin the operation
...@@ -118,7 +118,7 @@ nfs_free_user_pages(struct page **pages, int npages, int do_dirty) ...@@ -118,7 +118,7 @@ nfs_free_user_pages(struct page **pages, int npages, int do_dirty)
* nr_pages: size of pages array * nr_pages: size of pages array
*/ */
static int static int
nfs_direct_read_seg(struct inode *inode, struct file *file, nfs_direct_read_seg(struct inode *inode, struct nfs_open_context *ctx,
unsigned long user_addr, size_t count, loff_t file_offset, unsigned long user_addr, size_t count, loff_t file_offset,
struct page **pages, int nr_pages) struct page **pages, int nr_pages)
{ {
...@@ -127,9 +127,11 @@ nfs_direct_read_seg(struct inode *inode, struct file *file, ...@@ -127,9 +127,11 @@ nfs_direct_read_seg(struct inode *inode, struct file *file,
int curpage = 0; int curpage = 0;
struct nfs_read_data rdata = { struct nfs_read_data rdata = {
.inode = inode, .inode = inode,
.cred = ctx->cred,
.args = { .args = {
.fh = NFS_FH(inode), .fh = NFS_FH(inode),
.lockowner = current->files, .lockowner = ctx->lockowner,
.state = ctx->state,
}, },
.res = { .res = {
.fattr = &rdata.fattr, .fattr = &rdata.fattr,
...@@ -151,7 +153,7 @@ nfs_direct_read_seg(struct inode *inode, struct file *file, ...@@ -151,7 +153,7 @@ nfs_direct_read_seg(struct inode *inode, struct file *file,
user_addr + tot_bytes, rdata.args.pgbase, curpage); user_addr + tot_bytes, rdata.args.pgbase, curpage);
lock_kernel(); lock_kernel();
result = NFS_PROTO(inode)->read(&rdata, file); result = NFS_PROTO(inode)->read(&rdata);
unlock_kernel(); unlock_kernel();
if (result <= 0) { if (result <= 0) {
...@@ -183,7 +185,7 @@ nfs_direct_read_seg(struct inode *inode, struct file *file, ...@@ -183,7 +185,7 @@ nfs_direct_read_seg(struct inode *inode, struct file *file,
* nfs_direct_read - For each iov segment, map the user's buffer * nfs_direct_read - For each iov segment, map the user's buffer
* then generate read RPCs. * then generate read RPCs.
* @inode: target inode * @inode: target inode
* @file: target file (may be NULL) * @ctx: target file open context
* @iov: array of vectors that define I/O buffer * @iov: array of vectors that define I/O buffer
* file_offset: offset in file to begin the operation * file_offset: offset in file to begin the operation
* nr_segs: size of iovec array * nr_segs: size of iovec array
...@@ -193,7 +195,7 @@ nfs_direct_read_seg(struct inode *inode, struct file *file, ...@@ -193,7 +195,7 @@ nfs_direct_read_seg(struct inode *inode, struct file *file,
* server. * server.
*/ */
static ssize_t static ssize_t
nfs_direct_read(struct inode *inode, struct file *file, nfs_direct_read(struct inode *inode, struct nfs_open_context *ctx,
const struct iovec *iov, loff_t file_offset, const struct iovec *iov, loff_t file_offset,
unsigned long nr_segs) unsigned long nr_segs)
{ {
...@@ -216,7 +218,7 @@ nfs_direct_read(struct inode *inode, struct file *file, ...@@ -216,7 +218,7 @@ nfs_direct_read(struct inode *inode, struct file *file,
return page_count; return page_count;
} }
result = nfs_direct_read_seg(inode, file, user_addr, size, result = nfs_direct_read_seg(inode, ctx, user_addr, size,
file_offset, pages, page_count); file_offset, pages, page_count);
nfs_free_user_pages(pages, page_count, 1); nfs_free_user_pages(pages, page_count, 1);
...@@ -239,7 +241,7 @@ nfs_direct_read(struct inode *inode, struct file *file, ...@@ -239,7 +241,7 @@ nfs_direct_read(struct inode *inode, struct file *file,
* nfs_direct_write_seg - Write out one iov segment. Generate separate * nfs_direct_write_seg - Write out one iov segment. Generate separate
* write RPCs for each "wsize" bytes, then commit. * write RPCs for each "wsize" bytes, then commit.
* @inode: target inode * @inode: target inode
* @file: target file (may be NULL) * @ctx: target file open context
* user_addr: starting address of this segment of user's buffer * user_addr: starting address of this segment of user's buffer
* count: size of this segment * count: size of this segment
* file_offset: offset in file to begin the operation * file_offset: offset in file to begin the operation
...@@ -247,7 +249,7 @@ nfs_direct_read(struct inode *inode, struct file *file, ...@@ -247,7 +249,7 @@ nfs_direct_read(struct inode *inode, struct file *file,
* nr_pages: size of pages array * nr_pages: size of pages array
*/ */
static int static int
nfs_direct_write_seg(struct inode *inode, struct file *file, nfs_direct_write_seg(struct inode *inode, struct nfs_open_context *ctx,
unsigned long user_addr, size_t count, loff_t file_offset, unsigned long user_addr, size_t count, loff_t file_offset,
struct page **pages, int nr_pages) struct page **pages, int nr_pages)
{ {
...@@ -257,9 +259,11 @@ nfs_direct_write_seg(struct inode *inode, struct file *file, ...@@ -257,9 +259,11 @@ nfs_direct_write_seg(struct inode *inode, struct file *file,
struct nfs_writeverf first_verf; struct nfs_writeverf first_verf;
struct nfs_write_data wdata = { struct nfs_write_data wdata = {
.inode = inode, .inode = inode,
.cred = ctx->cred,
.args = { .args = {
.fh = NFS_FH(inode), .fh = NFS_FH(inode),
.lockowner = current->files, .lockowner = ctx->lockowner,
.state = ctx->state,
}, },
.res = { .res = {
.fattr = &wdata.fattr, .fattr = &wdata.fattr,
...@@ -290,7 +294,7 @@ nfs_direct_write_seg(struct inode *inode, struct file *file, ...@@ -290,7 +294,7 @@ nfs_direct_write_seg(struct inode *inode, struct file *file,
user_addr + tot_bytes, wdata.args.pgbase, curpage); user_addr + tot_bytes, wdata.args.pgbase, curpage);
lock_kernel(); lock_kernel();
result = NFS_PROTO(inode)->write(&wdata, file); result = NFS_PROTO(inode)->write(&wdata);
unlock_kernel(); unlock_kernel();
if (result <= 0) { if (result <= 0) {
...@@ -325,7 +329,7 @@ nfs_direct_write_seg(struct inode *inode, struct file *file, ...@@ -325,7 +329,7 @@ nfs_direct_write_seg(struct inode *inode, struct file *file,
wdata.args.offset = file_offset; wdata.args.offset = file_offset;
lock_kernel(); lock_kernel();
result = NFS_PROTO(inode)->commit(&wdata, file); result = NFS_PROTO(inode)->commit(&wdata);
unlock_kernel(); unlock_kernel();
if (result < 0 || memcmp(&first_verf.verifier, if (result < 0 || memcmp(&first_verf.verifier,
...@@ -349,7 +353,7 @@ nfs_direct_write_seg(struct inode *inode, struct file *file, ...@@ -349,7 +353,7 @@ nfs_direct_write_seg(struct inode *inode, struct file *file,
* nfs_direct_write - For each iov segment, map the user's buffer * nfs_direct_write - For each iov segment, map the user's buffer
* then generate write and commit RPCs. * then generate write and commit RPCs.
* @inode: target inode * @inode: target inode
* @file: target file (may be NULL) * @ctx: target file open context
* @iov: array of vectors that define I/O buffer * @iov: array of vectors that define I/O buffer
* file_offset: offset in file to begin the operation * file_offset: offset in file to begin the operation
* nr_segs: size of iovec array * nr_segs: size of iovec array
...@@ -358,8 +362,7 @@ nfs_direct_write_seg(struct inode *inode, struct file *file, ...@@ -358,8 +362,7 @@ nfs_direct_write_seg(struct inode *inode, struct file *file,
* that non-direct readers might access, so they will pick up these * that non-direct readers might access, so they will pick up these
* writes immediately. * writes immediately.
*/ */
static ssize_t static int nfs_direct_write(struct inode *inode, struct nfs_open_context *ctx,
nfs_direct_write(struct inode *inode, struct file *file,
const struct iovec *iov, loff_t file_offset, const struct iovec *iov, loff_t file_offset,
unsigned long nr_segs) unsigned long nr_segs)
{ {
...@@ -382,7 +385,7 @@ nfs_direct_write(struct inode *inode, struct file *file, ...@@ -382,7 +385,7 @@ nfs_direct_write(struct inode *inode, struct file *file,
return page_count; return page_count;
} }
result = nfs_direct_write_seg(inode, file, user_addr, size, result = nfs_direct_write_seg(inode, ctx, user_addr, size,
file_offset, pages, page_count); file_offset, pages, page_count);
nfs_free_user_pages(pages, page_count, 0); nfs_free_user_pages(pages, page_count, 0);
...@@ -414,6 +417,7 @@ nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, ...@@ -414,6 +417,7 @@ nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
{ {
ssize_t result = -EINVAL; ssize_t result = -EINVAL;
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct nfs_open_context *ctx;
struct dentry *dentry = file->f_dentry; struct dentry *dentry = file->f_dentry;
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
...@@ -423,19 +427,20 @@ nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, ...@@ -423,19 +427,20 @@ nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
if (!is_sync_kiocb(iocb)) if (!is_sync_kiocb(iocb))
return result; return result;
ctx = (struct nfs_open_context *)file->private_data;
switch (rw) { switch (rw) {
case READ: case READ:
dprintk("NFS: direct_IO(read) (%s) off/no(%Lu/%lu)\n", dprintk("NFS: direct_IO(read) (%s) off/no(%Lu/%lu)\n",
dentry->d_name.name, file_offset, nr_segs); dentry->d_name.name, file_offset, nr_segs);
result = nfs_direct_read(inode, file, iov, result = nfs_direct_read(inode, ctx, iov,
file_offset, nr_segs); file_offset, nr_segs);
break; break;
case WRITE: case WRITE:
dprintk("NFS: direct_IO(write) (%s) off/no(%Lu/%lu)\n", dprintk("NFS: direct_IO(write) (%s) off/no(%Lu/%lu)\n",
dentry->d_name.name, file_offset, nr_segs); dentry->d_name.name, file_offset, nr_segs);
result = nfs_direct_write(inode, file, iov, result = nfs_direct_write(inode, ctx, iov,
file_offset, nr_segs); file_offset, nr_segs);
break; break;
default: default:
...@@ -471,6 +476,8 @@ nfs_file_direct_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t ...@@ -471,6 +476,8 @@ nfs_file_direct_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t
ssize_t retval = -EINVAL; ssize_t retval = -EINVAL;
loff_t *ppos = &iocb->ki_pos; loff_t *ppos = &iocb->ki_pos;
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct nfs_open_context *ctx =
(struct nfs_open_context *) file->private_data;
struct dentry *dentry = file->f_dentry; struct dentry *dentry = file->f_dentry;
struct address_space *mapping = file->f_mapping; struct address_space *mapping = file->f_mapping;
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
...@@ -502,7 +509,7 @@ nfs_file_direct_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t ...@@ -502,7 +509,7 @@ nfs_file_direct_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t
goto out; goto out;
} }
retval = nfs_direct_read(inode, file, &iov, pos, 1); retval = nfs_direct_read(inode, ctx, &iov, pos, 1);
if (retval > 0) if (retval > 0)
*ppos = pos + retval; *ppos = pos + retval;
...@@ -542,6 +549,8 @@ nfs_file_direct_write(struct kiocb *iocb, const char __user *buf, size_t count, ...@@ -542,6 +549,8 @@ nfs_file_direct_write(struct kiocb *iocb, const char __user *buf, size_t count,
loff_t *ppos = &iocb->ki_pos; loff_t *ppos = &iocb->ki_pos;
unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur; unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct nfs_open_context *ctx =
(struct nfs_open_context *) file->private_data;
struct dentry *dentry = file->f_dentry; struct dentry *dentry = file->f_dentry;
struct address_space *mapping = file->f_mapping; struct address_space *mapping = file->f_mapping;
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
...@@ -589,7 +598,7 @@ nfs_file_direct_write(struct kiocb *iocb, const char __user *buf, size_t count, ...@@ -589,7 +598,7 @@ nfs_file_direct_write(struct kiocb *iocb, const char __user *buf, size_t count,
goto out; goto out;
} }
retval = nfs_direct_write(inode, file, &iov, pos, 1); retval = nfs_direct_write(inode, ctx, &iov, pos, 1);
if (mapping->nrpages) if (mapping->nrpages)
invalidate_inode_pages2(mapping); invalidate_inode_pages2(mapping);
if (retval > 0) if (retval > 0)
......
...@@ -113,6 +113,7 @@ nfs_file_release(struct inode *inode, struct file *filp) ...@@ -113,6 +113,7 @@ nfs_file_release(struct inode *inode, struct file *filp)
static int static int
nfs_file_flush(struct file *file) nfs_file_flush(struct file *file)
{ {
struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data;
struct inode *inode = file->f_dentry->d_inode; struct inode *inode = file->f_dentry->d_inode;
int status; int status;
...@@ -124,8 +125,8 @@ nfs_file_flush(struct file *file) ...@@ -124,8 +125,8 @@ nfs_file_flush(struct file *file)
/* Ensure that data+attribute caches are up to date after close() */ /* Ensure that data+attribute caches are up to date after close() */
status = nfs_wb_all(inode); status = nfs_wb_all(inode);
if (!status) { if (!status) {
status = file->f_error; status = ctx->error;
file->f_error = 0; ctx->error = 0;
if (!status) if (!status)
__nfs_revalidate_inode(NFS_SERVER(inode), inode); __nfs_revalidate_inode(NFS_SERVER(inode), inode);
} }
...@@ -197,6 +198,7 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma) ...@@ -197,6 +198,7 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
static int static int
nfs_fsync(struct file *file, struct dentry *dentry, int datasync) nfs_fsync(struct file *file, struct dentry *dentry, int datasync)
{ {
struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data;
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
int status; int status;
...@@ -205,8 +207,8 @@ nfs_fsync(struct file *file, struct dentry *dentry, int datasync) ...@@ -205,8 +207,8 @@ nfs_fsync(struct file *file, struct dentry *dentry, int datasync)
lock_kernel(); lock_kernel();
status = nfs_wb_all(inode); status = nfs_wb_all(inode);
if (!status) { if (!status) {
status = file->f_error; status = ctx->error;
file->f_error = 0; ctx->error = 0;
} }
unlock_kernel(); unlock_kernel();
return status; return status;
......
...@@ -121,8 +121,9 @@ nfs_delete_inode(struct inode * inode) ...@@ -121,8 +121,9 @@ nfs_delete_inode(struct inode * inode)
{ {
dprintk("NFS: delete_inode(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino); dprintk("NFS: delete_inode(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
nfs_wb_all(inode);
/* /*
* The following can never actually happen... * The following should never happen...
*/ */
if (nfs_have_writebacks(inode)) { if (nfs_have_writebacks(inode)) {
printk(KERN_ERR "nfs_delete_inode: inode %ld has pending RPC requests\n", inode->i_ino); printk(KERN_ERR "nfs_delete_inode: inode %ld has pending RPC requests\n", inode->i_ino);
...@@ -139,10 +140,10 @@ static void ...@@ -139,10 +140,10 @@ static void
nfs_clear_inode(struct inode *inode) nfs_clear_inode(struct inode *inode)
{ {
struct nfs_inode *nfsi = NFS_I(inode); struct nfs_inode *nfsi = NFS_I(inode);
struct rpc_cred *cred = nfsi->mm_cred; struct rpc_cred *cred;
if (cred) nfs_wb_all(inode);
put_rpccred(cred); BUG_ON (!list_empty(&nfsi->open_files));
cred = nfsi->cache_access.cred; cred = nfsi->cache_access.cred;
if (cred) if (cred)
put_rpccred(cred); put_rpccred(cred);
...@@ -812,53 +813,114 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) ...@@ -812,53 +813,114 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
return err; return err;
} }
struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred)
{
struct nfs_open_context *ctx;
ctx = (struct nfs_open_context *)kmalloc(sizeof(*ctx), GFP_KERNEL);
if (ctx != NULL) {
atomic_set(&ctx->count, 1);
ctx->dentry = dget(dentry);
ctx->cred = get_rpccred(cred);
ctx->state = NULL;
ctx->lockowner = current->files;
ctx->error = 0;
init_waitqueue_head(&ctx->waitq);
}
return ctx;
}
struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
{
if (ctx != NULL)
atomic_inc(&ctx->count);
return ctx;
}
void put_nfs_open_context(struct nfs_open_context *ctx)
{
if (atomic_dec_and_test(&ctx->count)) {
if (ctx->state != NULL)
nfs4_close_state(ctx->state, ctx->mode);
if (ctx->cred != NULL)
put_rpccred(ctx->cred);
dput(ctx->dentry);
kfree(ctx);
}
}
/* /*
* Ensure that mmap has a recent RPC credential for use when writing out * Ensure that mmap has a recent RPC credential for use when writing out
* shared pages * shared pages
*/ */
void void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
nfs_set_mmcred(struct inode *inode, struct rpc_cred *cred)
{ {
struct rpc_cred **p = &NFS_I(inode)->mm_cred, struct inode *inode = filp->f_dentry->d_inode;
*oldcred = *p; struct nfs_inode *nfsi = NFS_I(inode);
*p = get_rpccred(cred); filp->private_data = get_nfs_open_context(ctx);
if (oldcred) spin_lock(&inode->i_lock);
put_rpccred(oldcred); list_add(&ctx->list, &nfsi->open_files);
spin_unlock(&inode->i_lock);
}
struct nfs_open_context *nfs_find_open_context(struct inode *inode, int mode)
{
struct nfs_inode *nfsi = NFS_I(inode);
struct nfs_open_context *pos, *ctx = NULL;
spin_lock(&inode->i_lock);
list_for_each_entry(pos, &nfsi->open_files, list) {
if ((pos->mode & mode) == mode) {
ctx = get_nfs_open_context(pos);
break;
}
}
spin_unlock(&inode->i_lock);
return ctx;
}
void nfs_file_clear_open_context(struct file *filp)
{
struct inode *inode = filp->f_dentry->d_inode;
struct nfs_open_context *ctx = (struct nfs_open_context *)filp->private_data;
if (ctx) {
filp->private_data = NULL;
spin_lock(&inode->i_lock);
list_del(&ctx->list);
spin_unlock(&inode->i_lock);
put_nfs_open_context(ctx);
}
} }
/* /*
* These are probably going to contain hooks for * These allocate and release file read/write context information.
* allocating and releasing RPC credentials for
* the file. I'll have to think about Tronds patch
* a bit more..
*/ */
int nfs_open(struct inode *inode, struct file *filp) int nfs_open(struct inode *inode, struct file *filp)
{ {
struct rpc_auth *auth; struct nfs_open_context *ctx;
struct rpc_cred *cred; struct rpc_cred *cred;
auth = NFS_CLIENT(inode)->cl_auth; if ((cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0)) == NULL)
cred = rpcauth_lookupcred(auth, 0); return -ENOMEM;
filp->private_data = cred; ctx = alloc_nfs_open_context(filp->f_dentry, cred);
if ((filp->f_mode & FMODE_WRITE) != 0) { put_rpccred(cred);
nfs_set_mmcred(inode, cred); if (ctx == NULL)
return -ENOMEM;
ctx->mode = filp->f_mode;
nfs_file_set_open_context(filp, ctx);
put_nfs_open_context(ctx);
if ((filp->f_mode & FMODE_WRITE) != 0)
nfs_begin_data_update(inode); nfs_begin_data_update(inode);
}
return 0; return 0;
} }
int nfs_release(struct inode *inode, struct file *filp) int nfs_release(struct inode *inode, struct file *filp)
{ {
struct rpc_cred *cred;
lock_kernel();
if ((filp->f_mode & FMODE_WRITE) != 0) if ((filp->f_mode & FMODE_WRITE) != 0)
nfs_end_data_update(inode); nfs_end_data_update(inode);
cred = nfs_file_cred(filp); nfs_file_clear_open_context(filp);
if (cred)
put_rpccred(cred);
unlock_kernel();
return 0; return 0;
} }
...@@ -1397,6 +1459,9 @@ static void nfs4_clear_inode(struct inode *inode) ...@@ -1397,6 +1459,9 @@ static void nfs4_clear_inode(struct inode *inode)
{ {
struct nfs_inode *nfsi = NFS_I(inode); struct nfs_inode *nfsi = NFS_I(inode);
/* First call standard NFS clear_inode() code */
nfs_clear_inode(inode);
/* Now clear out any remaining state */
while (!list_empty(&nfsi->open_states)) { while (!list_empty(&nfsi->open_states)) {
struct nfs4_state *state; struct nfs4_state *state;
...@@ -1411,8 +1476,6 @@ static void nfs4_clear_inode(struct inode *inode) ...@@ -1411,8 +1476,6 @@ static void nfs4_clear_inode(struct inode *inode)
BUG_ON(atomic_read(&state->count) != 1); BUG_ON(atomic_read(&state->count) != 1);
nfs4_close_state(state, state->state); nfs4_close_state(state, state->state);
} }
/* Now call standard NFS clear_inode() code */
nfs_clear_inode(inode);
} }
...@@ -1717,7 +1780,6 @@ static struct inode *nfs_alloc_inode(struct super_block *sb) ...@@ -1717,7 +1780,6 @@ static struct inode *nfs_alloc_inode(struct super_block *sb)
if (!nfsi) if (!nfsi)
return NULL; return NULL;
nfsi->flags = 0; nfsi->flags = 0;
nfsi->mm_cred = NULL;
nfs4_zero_state(nfsi); nfs4_zero_state(nfsi);
return &nfsi->vfs_inode; return &nfsi->vfs_inode;
} }
...@@ -1737,6 +1799,7 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) ...@@ -1737,6 +1799,7 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
spin_lock_init(&nfsi->req_lock); spin_lock_init(&nfsi->req_lock);
INIT_LIST_HEAD(&nfsi->dirty); INIT_LIST_HEAD(&nfsi->dirty);
INIT_LIST_HEAD(&nfsi->commit); INIT_LIST_HEAD(&nfsi->commit);
INIT_LIST_HEAD(&nfsi->open_files);
INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC); INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
atomic_set(&nfsi->data_updates, 0); atomic_set(&nfsi->data_updates, 0);
nfsi->ndirty = 0; nfsi->ndirty = 0;
......
...@@ -68,18 +68,6 @@ nfs3_async_handle_jukebox(struct rpc_task *task) ...@@ -68,18 +68,6 @@ nfs3_async_handle_jukebox(struct rpc_task *task)
return 1; return 1;
} }
static struct rpc_cred *
nfs_cred(struct inode *inode, struct file *filp)
{
struct rpc_cred *cred = NULL;
if (filp)
cred = (struct rpc_cred *)filp->private_data;
if (!cred)
cred = NFS_I(inode)->mm_cred;
return cred;
}
/* /*
* Bare-bones access to getattr: this is for nfs_read_super. * Bare-bones access to getattr: this is for nfs_read_super.
*/ */
...@@ -233,8 +221,7 @@ nfs3_proc_readlink(struct inode *inode, struct page *page) ...@@ -233,8 +221,7 @@ nfs3_proc_readlink(struct inode *inode, struct page *page)
return status; return status;
} }
static int static int nfs3_proc_read(struct nfs_read_data *rdata)
nfs3_proc_read(struct nfs_read_data *rdata, struct file *filp)
{ {
int flags = rdata->flags; int flags = rdata->flags;
struct inode * inode = rdata->inode; struct inode * inode = rdata->inode;
...@@ -243,13 +230,13 @@ nfs3_proc_read(struct nfs_read_data *rdata, struct file *filp) ...@@ -243,13 +230,13 @@ nfs3_proc_read(struct nfs_read_data *rdata, struct file *filp)
.rpc_proc = &nfs3_procedures[NFS3PROC_READ], .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
.rpc_argp = &rdata->args, .rpc_argp = &rdata->args,
.rpc_resp = &rdata->res, .rpc_resp = &rdata->res,
.rpc_cred = rdata->cred,
}; };
int status; int status;
dprintk("NFS call read %d @ %Ld\n", rdata->args.count, dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
(long long) rdata->args.offset); (long long) rdata->args.offset);
fattr->valid = 0; fattr->valid = 0;
msg.rpc_cred = nfs_cred(inode, filp);
status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags); status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
if (status >= 0) if (status >= 0)
nfs_refresh_inode(inode, fattr); nfs_refresh_inode(inode, fattr);
...@@ -257,8 +244,7 @@ nfs3_proc_read(struct nfs_read_data *rdata, struct file *filp) ...@@ -257,8 +244,7 @@ nfs3_proc_read(struct nfs_read_data *rdata, struct file *filp)
return status; return status;
} }
static int static int nfs3_proc_write(struct nfs_write_data *wdata)
nfs3_proc_write(struct nfs_write_data *wdata, struct file *filp)
{ {
int rpcflags = wdata->flags; int rpcflags = wdata->flags;
struct inode * inode = wdata->inode; struct inode * inode = wdata->inode;
...@@ -267,13 +253,13 @@ nfs3_proc_write(struct nfs_write_data *wdata, struct file *filp) ...@@ -267,13 +253,13 @@ nfs3_proc_write(struct nfs_write_data *wdata, struct file *filp)
.rpc_proc = &nfs3_procedures[NFS3PROC_WRITE], .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
.rpc_argp = &wdata->args, .rpc_argp = &wdata->args,
.rpc_resp = &wdata->res, .rpc_resp = &wdata->res,
.rpc_cred = wdata->cred,
}; };
int status; int status;
dprintk("NFS call write %d @ %Ld\n", wdata->args.count, dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
(long long) wdata->args.offset); (long long) wdata->args.offset);
fattr->valid = 0; fattr->valid = 0;
msg.rpc_cred = nfs_cred(inode, filp);
status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags); status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
if (status >= 0) if (status >= 0)
nfs_refresh_inode(inode, fattr); nfs_refresh_inode(inode, fattr);
...@@ -281,8 +267,7 @@ nfs3_proc_write(struct nfs_write_data *wdata, struct file *filp) ...@@ -281,8 +267,7 @@ nfs3_proc_write(struct nfs_write_data *wdata, struct file *filp)
return status < 0? status : wdata->res.count; return status < 0? status : wdata->res.count;
} }
static int static int nfs3_proc_commit(struct nfs_write_data *cdata)
nfs3_proc_commit(struct nfs_write_data *cdata, struct file *filp)
{ {
struct inode * inode = cdata->inode; struct inode * inode = cdata->inode;
struct nfs_fattr * fattr = cdata->res.fattr; struct nfs_fattr * fattr = cdata->res.fattr;
...@@ -290,13 +275,13 @@ nfs3_proc_commit(struct nfs_write_data *cdata, struct file *filp) ...@@ -290,13 +275,13 @@ nfs3_proc_commit(struct nfs_write_data *cdata, struct file *filp)
.rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT], .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
.rpc_argp = &cdata->args, .rpc_argp = &cdata->args,
.rpc_resp = &cdata->res, .rpc_resp = &cdata->res,
.rpc_cred = cdata->cred,
}; };
int status; int status;
dprintk("NFS call commit %d @ %Ld\n", cdata->args.count, dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
(long long) cdata->args.offset); (long long) cdata->args.offset);
fattr->valid = 0; fattr->valid = 0;
msg.rpc_cred = nfs_cred(inode, filp);
status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
if (status >= 0) if (status >= 0)
nfs_refresh_inode(inode, fattr); nfs_refresh_inode(inode, fattr);
...@@ -840,27 +825,6 @@ nfs3_proc_commit_setup(struct nfs_write_data *data, int how) ...@@ -840,27 +825,6 @@ nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
rpc_call_setup(task, &msg, 0); rpc_call_setup(task, &msg, 0);
} }
/*
* Set up the nfspage struct with the right credentials
*/
void
nfs3_request_init(struct nfs_page *req, struct file *filp)
{
req->wb_cred = get_rpccred(nfs_cred(req->wb_inode, filp));
}
static int
nfs3_request_compatible(struct nfs_page *req, struct file *filp, struct page *page)
{
if (req->wb_file != filp)
return 0;
if (req->wb_page != page)
return 0;
if (req->wb_cred != nfs_file_cred(filp))
return 0;
return 1;
}
static int static int
nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
{ {
...@@ -900,7 +864,5 @@ struct nfs_rpc_ops nfs_v3_clientops = { ...@@ -900,7 +864,5 @@ struct nfs_rpc_ops nfs_v3_clientops = {
.commit_setup = nfs3_proc_commit_setup, .commit_setup = nfs3_proc_commit_setup,
.file_open = nfs_open, .file_open = nfs_open,
.file_release = nfs_release, .file_release = nfs_release,
.request_init = nfs3_request_init,
.request_compatible = nfs3_request_compatible,
.lock = nfs3_proc_lock, .lock = nfs3_proc_lock,
}; };
...@@ -975,7 +975,7 @@ static int nfs4_proc_readlink(struct inode *inode, struct page *page) ...@@ -975,7 +975,7 @@ static int nfs4_proc_readlink(struct inode *inode, struct page *page)
return err; return err;
} }
static int _nfs4_proc_read(struct nfs_read_data *rdata, struct file *filp) static int _nfs4_proc_read(struct nfs_read_data *rdata)
{ {
int flags = rdata->flags; int flags = rdata->flags;
struct inode *inode = rdata->inode; struct inode *inode = rdata->inode;
...@@ -985,6 +985,7 @@ static int _nfs4_proc_read(struct nfs_read_data *rdata, struct file *filp) ...@@ -985,6 +985,7 @@ static int _nfs4_proc_read(struct nfs_read_data *rdata, struct file *filp)
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
.rpc_argp = &rdata->args, .rpc_argp = &rdata->args,
.rpc_resp = &rdata->res, .rpc_resp = &rdata->res,
.rpc_cred = rdata->cred,
}; };
unsigned long timestamp = jiffies; unsigned long timestamp = jiffies;
int status; int status;
...@@ -992,19 +993,6 @@ static int _nfs4_proc_read(struct nfs_read_data *rdata, struct file *filp) ...@@ -992,19 +993,6 @@ static int _nfs4_proc_read(struct nfs_read_data *rdata, struct file *filp)
dprintk("NFS call read %d @ %Ld\n", rdata->args.count, dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
(long long) rdata->args.offset); (long long) rdata->args.offset);
/*
* Try first to use O_RDONLY, then O_RDWR stateid.
*/
if (filp) {
struct nfs4_state *state;
state = (struct nfs4_state *)filp->private_data;
rdata->args.state = state;
msg.rpc_cred = state->owner->so_cred;
} else {
rdata->args.state = NULL;
msg.rpc_cred = NFS_I(inode)->mm_cred;
}
fattr->valid = 0; fattr->valid = 0;
status = rpc_call_sync(server->client, &msg, flags); status = rpc_call_sync(server->client, &msg, flags);
if (!status) if (!status)
...@@ -1013,19 +1001,19 @@ static int _nfs4_proc_read(struct nfs_read_data *rdata, struct file *filp) ...@@ -1013,19 +1001,19 @@ static int _nfs4_proc_read(struct nfs_read_data *rdata, struct file *filp)
return status; return status;
} }
static int nfs4_proc_read(struct nfs_read_data *rdata, struct file *filp) static int nfs4_proc_read(struct nfs_read_data *rdata)
{ {
struct nfs4_exception exception = { }; struct nfs4_exception exception = { };
int err; int err;
do { do {
err = nfs4_handle_exception(NFS_SERVER(rdata->inode), err = nfs4_handle_exception(NFS_SERVER(rdata->inode),
_nfs4_proc_read(rdata, filp), _nfs4_proc_read(rdata),
&exception); &exception);
} while (exception.retry); } while (exception.retry);
return err; return err;
} }
static int _nfs4_proc_write(struct nfs_write_data *wdata, struct file *filp) static int _nfs4_proc_write(struct nfs_write_data *wdata)
{ {
int rpcflags = wdata->flags; int rpcflags = wdata->flags;
struct inode *inode = wdata->inode; struct inode *inode = wdata->inode;
...@@ -1035,44 +1023,32 @@ static int _nfs4_proc_write(struct nfs_write_data *wdata, struct file *filp) ...@@ -1035,44 +1023,32 @@ static int _nfs4_proc_write(struct nfs_write_data *wdata, struct file *filp)
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
.rpc_argp = &wdata->args, .rpc_argp = &wdata->args,
.rpc_resp = &wdata->res, .rpc_resp = &wdata->res,
.rpc_cred = wdata->cred,
}; };
int status; int status;
dprintk("NFS call write %d @ %Ld\n", wdata->args.count, dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
(long long) wdata->args.offset); (long long) wdata->args.offset);
/*
* Try first to use O_WRONLY, then O_RDWR stateid.
*/
if (filp) {
struct nfs4_state *state;
state = (struct nfs4_state *)filp->private_data;
wdata->args.state = state;
msg.rpc_cred = state->owner->so_cred;
} else {
wdata->args.state = NULL;
msg.rpc_cred = NFS_I(inode)->mm_cred;
}
fattr->valid = 0; fattr->valid = 0;
status = rpc_call_sync(server->client, &msg, rpcflags); status = rpc_call_sync(server->client, &msg, rpcflags);
dprintk("NFS reply write: %d\n", status); dprintk("NFS reply write: %d\n", status);
return status; return status;
} }
static int nfs4_proc_write(struct nfs_write_data *wdata, struct file *filp) static int nfs4_proc_write(struct nfs_write_data *wdata)
{ {
struct nfs4_exception exception = { }; struct nfs4_exception exception = { };
int err; int err;
do { do {
err = nfs4_handle_exception(NFS_SERVER(wdata->inode), err = nfs4_handle_exception(NFS_SERVER(wdata->inode),
_nfs4_proc_write(wdata, filp), _nfs4_proc_write(wdata),
&exception); &exception);
} while (exception.retry); } while (exception.retry);
return err; return err;
} }
static int _nfs4_proc_commit(struct nfs_write_data *cdata, struct file *filp) static int _nfs4_proc_commit(struct nfs_write_data *cdata)
{ {
struct inode *inode = cdata->inode; struct inode *inode = cdata->inode;
struct nfs_fattr *fattr = cdata->res.fattr; struct nfs_fattr *fattr = cdata->res.fattr;
...@@ -1081,33 +1057,26 @@ static int _nfs4_proc_commit(struct nfs_write_data *cdata, struct file *filp) ...@@ -1081,33 +1057,26 @@ static int _nfs4_proc_commit(struct nfs_write_data *cdata, struct file *filp)
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
.rpc_argp = &cdata->args, .rpc_argp = &cdata->args,
.rpc_resp = &cdata->res, .rpc_resp = &cdata->res,
.rpc_cred = cdata->cred,
}; };
int status; int status;
dprintk("NFS call commit %d @ %Ld\n", cdata->args.count, dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
(long long) cdata->args.offset); (long long) cdata->args.offset);
/*
* Try first to use O_WRONLY, then O_RDWR stateid.
*/
if (filp)
msg.rpc_cred = ((struct nfs4_state *)filp->private_data)->owner->so_cred;
else
msg.rpc_cred = NFS_I(inode)->mm_cred;
fattr->valid = 0; fattr->valid = 0;
status = rpc_call_sync(server->client, &msg, 0); status = rpc_call_sync(server->client, &msg, 0);
dprintk("NFS reply commit: %d\n", status); dprintk("NFS reply commit: %d\n", status);
return status; return status;
} }
static int nfs4_proc_commit(struct nfs_write_data *cdata, struct file *filp) static int nfs4_proc_commit(struct nfs_write_data *cdata)
{ {
struct nfs4_exception exception = { }; struct nfs4_exception exception = { };
int err; int err;
do { do {
err = nfs4_handle_exception(NFS_SERVER(cdata->inode), err = nfs4_handle_exception(NFS_SERVER(cdata->inode),
_nfs4_proc_commit(cdata, filp), _nfs4_proc_commit(cdata),
&exception); &exception);
} while (exception.retry); } while (exception.retry);
return err; return err;
...@@ -1797,8 +1766,10 @@ static int ...@@ -1797,8 +1766,10 @@ static int
nfs4_proc_file_open(struct inode *inode, struct file *filp) nfs4_proc_file_open(struct inode *inode, struct file *filp)
{ {
struct dentry *dentry = filp->f_dentry; struct dentry *dentry = filp->f_dentry;
struct nfs4_state *state; struct nfs_open_context *ctx;
struct nfs4_state *state = NULL;
struct rpc_cred *cred; struct rpc_cred *cred;
int status = -ENOMEM;
dprintk("nfs4_proc_file_open: starting on (%.*s/%.*s)\n", dprintk("nfs4_proc_file_open: starting on (%.*s/%.*s)\n",
(int)dentry->d_parent->d_name.len, (int)dentry->d_parent->d_name.len,
...@@ -1808,21 +1779,28 @@ nfs4_proc_file_open(struct inode *inode, struct file *filp) ...@@ -1808,21 +1779,28 @@ nfs4_proc_file_open(struct inode *inode, struct file *filp)
/* Find our open stateid */ /* Find our open stateid */
cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0); cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
state = nfs4_find_state(inode, cred, filp->f_mode); if (unlikely(cred == NULL))
return -ENOMEM;
ctx = alloc_nfs_open_context(dentry, cred);
put_rpccred(cred); put_rpccred(cred);
if (state == NULL) { if (unlikely(ctx == NULL))
printk(KERN_WARNING "NFS: v4 raced in function %s\n", __FUNCTION__); return -ENOMEM;
return -EIO; /* ERACE actually */ status = -EIO; /* ERACE actually */
} state = nfs4_find_state(inode, cred, filp->f_mode);
if (unlikely(state == NULL))
goto no_state;
ctx->state = state;
nfs4_close_state(state, filp->f_mode); nfs4_close_state(state, filp->f_mode);
if (filp->f_mode & FMODE_WRITE) { ctx->mode = filp->f_mode;
lock_kernel(); nfs_file_set_open_context(filp, ctx);
nfs_set_mmcred(inode, state->owner->so_cred); put_nfs_open_context(ctx);
if (filp->f_mode & FMODE_WRITE)
nfs_begin_data_update(inode); nfs_begin_data_update(inode);
unlock_kernel();
}
filp->private_data = state;
return 0; return 0;
no_state:
printk(KERN_WARNING "NFS: v4 raced in function %s\n", __FUNCTION__);
put_nfs_open_context(ctx);
return status;
} }
/* /*
...@@ -1831,37 +1809,12 @@ nfs4_proc_file_open(struct inode *inode, struct file *filp) ...@@ -1831,37 +1809,12 @@ nfs4_proc_file_open(struct inode *inode, struct file *filp)
static int static int
nfs4_proc_file_release(struct inode *inode, struct file *filp) nfs4_proc_file_release(struct inode *inode, struct file *filp)
{ {
struct nfs4_state *state = (struct nfs4_state *)filp->private_data; if (filp->f_mode & FMODE_WRITE)
if (state)
nfs4_close_state(state, filp->f_mode);
if (filp->f_mode & FMODE_WRITE) {
lock_kernel();
nfs_end_data_update(inode); nfs_end_data_update(inode);
unlock_kernel(); nfs_file_clear_open_context(filp);
}
return 0; return 0;
} }
/*
* Set up the nfspage struct with the right state info and credentials
*/
static void
nfs4_request_init(struct nfs_page *req, struct file *filp)
{
struct nfs4_state *state;
if (!filp) {
req->wb_cred = get_rpccred(NFS_I(req->wb_inode)->mm_cred);
req->wb_state = NULL;
return;
}
state = (struct nfs4_state *)filp->private_data;
req->wb_state = state;
req->wb_cred = get_rpccred(state->owner->so_cred);
req->wb_lockowner = current->files;
}
static int static int
nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server) nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server)
{ {
...@@ -1974,28 +1927,6 @@ int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_ ...@@ -1974,28 +1927,6 @@ int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_
return nfs4_map_errors(ret); return nfs4_map_errors(ret);
} }
static int
nfs4_request_compatible(struct nfs_page *req, struct file *filp, struct page *page)
{
struct nfs4_state *state = NULL;
struct rpc_cred *cred = NULL;
if (req->wb_file != filp)
return 0;
if (req->wb_page != page)
return 0;
state = (struct nfs4_state *)filp->private_data;
if (req->wb_state != state)
return 0;
if (req->wb_lockowner != current->files)
return 0;
cred = state->owner->so_cred;
if (req->wb_cred != cred)
return 0;
return 1;
}
int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port) int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port)
{ {
static nfs4_verifier sc_verifier; static nfs4_verifier sc_verifier;
...@@ -2353,13 +2284,14 @@ static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock * ...@@ -2353,13 +2284,14 @@ static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *
static int static int
nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
{ {
struct nfs_open_context *ctx;
struct nfs4_state *state; struct nfs4_state *state;
unsigned long timeout = NFS4_LOCK_MINTIMEOUT; unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
int status; int status;
/* verify open state */ /* verify open state */
state = (struct nfs4_state *)filp->private_data; ctx = (struct nfs_open_context *)filp->private_data;
BUG_ON(!state); state = ctx->state;
if (request->fl_start < 0 || request->fl_end < 0) if (request->fl_start < 0 || request->fl_end < 0)
return -EINVAL; return -EINVAL;
...@@ -2419,8 +2351,6 @@ struct nfs_rpc_ops nfs_v4_clientops = { ...@@ -2419,8 +2351,6 @@ struct nfs_rpc_ops nfs_v4_clientops = {
.commit_setup = nfs4_proc_commit_setup, .commit_setup = nfs4_proc_commit_setup,
.file_open = nfs4_proc_file_open, .file_open = nfs4_proc_file_open,
.file_release = nfs4_proc_file_release, .file_release = nfs4_proc_file_release,
.request_init = nfs4_request_init,
.request_compatible = nfs4_request_compatible,
.lock = nfs4_proc_lock, .lock = nfs4_proc_lock,
}; };
......
...@@ -728,7 +728,7 @@ static int nfs4_reclaim_locks(struct nfs4_state *state) ...@@ -728,7 +728,7 @@ static int nfs4_reclaim_locks(struct nfs4_state *state)
for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) { for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) {
if (!(fl->fl_flags & FL_POSIX)) if (!(fl->fl_flags & FL_POSIX))
continue; continue;
if ((struct nfs4_state *)fl->fl_file->private_data != state) if (((struct nfs_open_context *)fl->fl_file->private_data)->state != state)
continue; continue;
status = nfs4_lock_reclaim(state, fl); status = nfs4_lock_reclaim(state, fl);
if (status >= 0) if (status >= 0)
......
...@@ -31,7 +31,6 @@ nfs_page_alloc(void) ...@@ -31,7 +31,6 @@ nfs_page_alloc(void)
if (p) { if (p) {
memset(p, 0, sizeof(*p)); memset(p, 0, sizeof(*p));
INIT_LIST_HEAD(&p->wb_list); INIT_LIST_HEAD(&p->wb_list);
init_waitqueue_head(&p->wb_wait);
} }
return p; return p;
} }
...@@ -57,7 +56,7 @@ nfs_page_free(struct nfs_page *p) ...@@ -57,7 +56,7 @@ nfs_page_free(struct nfs_page *p)
* User should ensure it is safe to sleep in this function. * User should ensure it is safe to sleep in this function.
*/ */
struct nfs_page * struct nfs_page *
nfs_create_request(struct file *file, struct inode *inode, nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
struct page *page, struct page *page,
unsigned int offset, unsigned int count) unsigned int offset, unsigned int count)
{ {
...@@ -89,33 +88,38 @@ nfs_create_request(struct file *file, struct inode *inode, ...@@ -89,33 +88,38 @@ nfs_create_request(struct file *file, struct inode *inode,
req->wb_offset = offset; req->wb_offset = offset;
req->wb_pgbase = offset; req->wb_pgbase = offset;
req->wb_bytes = count; req->wb_bytes = count;
req->wb_inode = inode;
atomic_set(&req->wb_count, 1); atomic_set(&req->wb_count, 1);
server->rpc_ops->request_init(req, file); req->wb_context = get_nfs_open_context(ctx);
return req; return req;
} }
/**
* nfs_unlock_request - Unlock request and wake up sleepers.
* @req:
*/
void nfs_unlock_request(struct nfs_page *req)
{
if (!NFS_WBACK_BUSY(req)) {
printk(KERN_ERR "NFS: Invalid unlock attempted\n");
BUG();
}
smp_mb__before_clear_bit();
clear_bit(PG_BUSY, &req->wb_flags);
smp_mb__after_clear_bit();
wake_up_all(&req->wb_context->waitq);
nfs_release_request(req);
}
/** /**
* nfs_clear_request - Free up all resources allocated to the request * nfs_clear_request - Free up all resources allocated to the request
* @req: * @req:
* *
* Release all resources associated with a write request after it * Release page resources associated with a write request after it
* has completed. * has completed.
*/ */
void nfs_clear_request(struct nfs_page *req) void nfs_clear_request(struct nfs_page *req)
{ {
if (req->wb_state)
req->wb_state = NULL;
/* Release struct file or cached credential */
if (req->wb_file) {
fput(req->wb_file);
req->wb_file = NULL;
}
if (req->wb_cred) {
put_rpccred(req->wb_cred);
req->wb_cred = NULL;
}
if (req->wb_page) { if (req->wb_page) {
page_cache_release(req->wb_page); page_cache_release(req->wb_page);
req->wb_page = NULL; req->wb_page = NULL;
...@@ -142,6 +146,7 @@ nfs_release_request(struct nfs_page *req) ...@@ -142,6 +146,7 @@ nfs_release_request(struct nfs_page *req)
/* Release struct file or cached credential */ /* Release struct file or cached credential */
nfs_clear_request(req); nfs_clear_request(req);
put_nfs_open_context(req->wb_context);
nfs_page_free(req); nfs_page_free(req);
} }
...@@ -185,12 +190,12 @@ nfs_list_add_request(struct nfs_page *req, struct list_head *head) ...@@ -185,12 +190,12 @@ nfs_list_add_request(struct nfs_page *req, struct list_head *head)
int int
nfs_wait_on_request(struct nfs_page *req) nfs_wait_on_request(struct nfs_page *req)
{ {
struct inode *inode = req->wb_inode; struct inode *inode = req->wb_context->dentry->d_inode;
struct rpc_clnt *clnt = NFS_CLIENT(inode); struct rpc_clnt *clnt = NFS_CLIENT(inode);
if (!NFS_WBACK_BUSY(req)) if (!NFS_WBACK_BUSY(req))
return 0; return 0;
return nfs_wait_event(clnt, req->wb_wait, !NFS_WBACK_BUSY(req)); return nfs_wait_event(clnt, req->wb_context->waitq, !NFS_WBACK_BUSY(req));
} }
/** /**
...@@ -215,7 +220,11 @@ nfs_coalesce_requests(struct list_head *head, struct list_head *dst, ...@@ -215,7 +220,11 @@ nfs_coalesce_requests(struct list_head *head, struct list_head *dst,
req = nfs_list_entry(head->next); req = nfs_list_entry(head->next);
if (prev) { if (prev) {
if (req->wb_cred != prev->wb_cred) if (req->wb_context->cred != prev->wb_context->cred)
break;
if (req->wb_context->lockowner != prev->wb_context->lockowner)
break;
if (req->wb_context->state != prev->wb_context->state)
break; break;
if (req->wb_index != (prev->wb_index + 1)) if (req->wb_index != (prev->wb_index + 1))
break; break;
......
...@@ -49,18 +49,6 @@ ...@@ -49,18 +49,6 @@
extern struct rpc_procinfo nfs_procedures[]; extern struct rpc_procinfo nfs_procedures[];
static struct rpc_cred *
nfs_cred(struct inode *inode, struct file *filp)
{
struct rpc_cred *cred = NULL;
if (filp)
cred = (struct rpc_cred *)filp->private_data;
if (!cred)
cred = NFS_I(inode)->mm_cred;
return cred;
}
/* /*
* Bare-bones access to getattr: this is for nfs_read_super. * Bare-bones access to getattr: this is for nfs_read_super.
*/ */
...@@ -167,8 +155,7 @@ nfs_proc_readlink(struct inode *inode, struct page *page) ...@@ -167,8 +155,7 @@ nfs_proc_readlink(struct inode *inode, struct page *page)
return status; return status;
} }
static int static int nfs_proc_read(struct nfs_read_data *rdata)
nfs_proc_read(struct nfs_read_data *rdata, struct file *filp)
{ {
int flags = rdata->flags; int flags = rdata->flags;
struct inode * inode = rdata->inode; struct inode * inode = rdata->inode;
...@@ -177,15 +164,14 @@ nfs_proc_read(struct nfs_read_data *rdata, struct file *filp) ...@@ -177,15 +164,14 @@ nfs_proc_read(struct nfs_read_data *rdata, struct file *filp)
.rpc_proc = &nfs_procedures[NFSPROC_READ], .rpc_proc = &nfs_procedures[NFSPROC_READ],
.rpc_argp = &rdata->args, .rpc_argp = &rdata->args,
.rpc_resp = &rdata->res, .rpc_resp = &rdata->res,
.rpc_cred = rdata->cred,
}; };
int status; int status;
dprintk("NFS call read %d @ %Ld\n", rdata->args.count, dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
(long long) rdata->args.offset); (long long) rdata->args.offset);
fattr->valid = 0; fattr->valid = 0;
msg.rpc_cred = nfs_cred(inode, filp);
status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags); status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
if (status >= 0) { if (status >= 0) {
nfs_refresh_inode(inode, fattr); nfs_refresh_inode(inode, fattr);
/* Emulate the eof flag, which isn't normally needed in NFSv2 /* Emulate the eof flag, which isn't normally needed in NFSv2
...@@ -198,8 +184,7 @@ nfs_proc_read(struct nfs_read_data *rdata, struct file *filp) ...@@ -198,8 +184,7 @@ nfs_proc_read(struct nfs_read_data *rdata, struct file *filp)
return status; return status;
} }
static int static int nfs_proc_write(struct nfs_write_data *wdata)
nfs_proc_write(struct nfs_write_data *wdata, struct file *filp)
{ {
int flags = wdata->flags; int flags = wdata->flags;
struct inode * inode = wdata->inode; struct inode * inode = wdata->inode;
...@@ -208,13 +193,13 @@ nfs_proc_write(struct nfs_write_data *wdata, struct file *filp) ...@@ -208,13 +193,13 @@ nfs_proc_write(struct nfs_write_data *wdata, struct file *filp)
.rpc_proc = &nfs_procedures[NFSPROC_WRITE], .rpc_proc = &nfs_procedures[NFSPROC_WRITE],
.rpc_argp = &wdata->args, .rpc_argp = &wdata->args,
.rpc_resp = &wdata->res, .rpc_resp = &wdata->res,
.rpc_cred = wdata->cred,
}; };
int status; int status;
dprintk("NFS call write %d @ %Ld\n", wdata->args.count, dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
(long long) wdata->args.offset); (long long) wdata->args.offset);
fattr->valid = 0; fattr->valid = 0;
msg.rpc_cred = nfs_cred(inode, filp);
status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags); status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
if (status >= 0) { if (status >= 0) {
nfs_refresh_inode(inode, fattr); nfs_refresh_inode(inode, fattr);
...@@ -621,27 +606,6 @@ nfs_proc_commit_setup(struct nfs_write_data *data, int how) ...@@ -621,27 +606,6 @@ nfs_proc_commit_setup(struct nfs_write_data *data, int how)
BUG(); BUG();
} }
/*
* Set up the nfspage struct with the right credentials
*/
static void
nfs_request_init(struct nfs_page *req, struct file *filp)
{
req->wb_cred = get_rpccred(nfs_cred(req->wb_inode, filp));
}
static int
nfs_request_compatible(struct nfs_page *req, struct file *filp, struct page *page)
{
if (req->wb_file != filp)
return 0;
if (req->wb_page != page)
return 0;
if (req->wb_cred != nfs_file_cred(filp))
return 0;
return 1;
}
static int static int
nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl) nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
{ {
...@@ -682,7 +646,5 @@ struct nfs_rpc_ops nfs_v2_clientops = { ...@@ -682,7 +646,5 @@ struct nfs_rpc_ops nfs_v2_clientops = {
.commit_setup = nfs_proc_commit_setup, .commit_setup = nfs_proc_commit_setup,
.file_open = nfs_open, .file_open = nfs_open,
.file_release = nfs_release, .file_release = nfs_release,
.request_init = nfs_request_init,
.request_compatible = nfs_request_compatible,
.lock = nfs_proc_lock, .lock = nfs_proc_lock,
}; };
...@@ -91,8 +91,8 @@ int nfs_return_empty_page(struct page *page) ...@@ -91,8 +91,8 @@ int nfs_return_empty_page(struct page *page)
/* /*
* Read a page synchronously. * Read a page synchronously.
*/ */
static int static int nfs_readpage_sync(struct nfs_open_context *ctx, struct inode *inode,
nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page) struct page *page)
{ {
unsigned int rsize = NFS_SERVER(inode)->rsize; unsigned int rsize = NFS_SERVER(inode)->rsize;
unsigned int count = PAGE_CACHE_SIZE; unsigned int count = PAGE_CACHE_SIZE;
...@@ -105,10 +105,12 @@ nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page) ...@@ -105,10 +105,12 @@ nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page)
memset(rdata, 0, sizeof(*rdata)); memset(rdata, 0, sizeof(*rdata));
rdata->flags = (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0); rdata->flags = (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
rdata->cred = ctx->cred;
rdata->inode = inode; rdata->inode = inode;
INIT_LIST_HEAD(&rdata->pages); INIT_LIST_HEAD(&rdata->pages);
rdata->args.fh = NFS_FH(inode); rdata->args.fh = NFS_FH(inode);
rdata->args.lockowner = current->files; rdata->args.lockowner = ctx->lockowner;
rdata->args.state = ctx->state;
rdata->args.pages = &page; rdata->args.pages = &page;
rdata->args.pgbase = 0UL; rdata->args.pgbase = 0UL;
rdata->args.count = rsize; rdata->args.count = rsize;
...@@ -134,7 +136,7 @@ nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page) ...@@ -134,7 +136,7 @@ nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page)
rdata->args.count); rdata->args.count);
lock_kernel(); lock_kernel();
result = NFS_PROTO(inode)->read(rdata, file); result = NFS_PROTO(inode)->read(rdata);
unlock_kernel(); unlock_kernel();
/* /*
...@@ -169,8 +171,8 @@ nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page) ...@@ -169,8 +171,8 @@ nfs_readpage_sync(struct file *file, struct inode *inode, struct page *page)
return result; return result;
} }
static int static int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,
nfs_readpage_async(struct file *file, struct inode *inode, struct page *page) struct page *page)
{ {
LIST_HEAD(one_request); LIST_HEAD(one_request);
struct nfs_page *new; struct nfs_page *new;
...@@ -179,7 +181,7 @@ nfs_readpage_async(struct file *file, struct inode *inode, struct page *page) ...@@ -179,7 +181,7 @@ nfs_readpage_async(struct file *file, struct inode *inode, struct page *page)
len = nfs_page_length(inode, page); len = nfs_page_length(inode, page);
if (len == 0) if (len == 0)
return nfs_return_empty_page(page); return nfs_return_empty_page(page);
new = nfs_create_request(file, inode, page, 0, len); new = nfs_create_request(ctx, inode, page, 0, len);
if (IS_ERR(new)) { if (IS_ERR(new)) {
unlock_page(page); unlock_page(page);
return PTR_ERR(new); return PTR_ERR(new);
...@@ -202,8 +204,8 @@ static void nfs_readpage_release(struct nfs_page *req) ...@@ -202,8 +204,8 @@ static void nfs_readpage_release(struct nfs_page *req)
nfs_unlock_request(req); nfs_unlock_request(req);
dprintk("NFS: read done (%s/%Ld %d@%Ld)\n", dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",
req->wb_inode->i_sb->s_id, req->wb_context->dentry->d_inode->i_sb->s_id,
(long long)NFS_FILEID(req->wb_inode), (long long)NFS_FILEID(req->wb_context->dentry->d_inode),
req->wb_bytes, req->wb_bytes,
(long long)req_offset(req)); (long long)req_offset(req));
} }
...@@ -217,16 +219,16 @@ static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data, ...@@ -217,16 +219,16 @@ static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
struct inode *inode; struct inode *inode;
data->req = req; data->req = req;
data->inode = inode = req->wb_inode; data->inode = inode = req->wb_context->dentry->d_inode;
data->cred = req->wb_cred; data->cred = req->wb_context->cred;
data->args.fh = NFS_FH(inode); data->args.fh = NFS_FH(inode);
data->args.offset = req_offset(req) + offset; data->args.offset = req_offset(req) + offset;
data->args.pgbase = req->wb_pgbase + offset; data->args.pgbase = req->wb_pgbase + offset;
data->args.pages = data->pagevec; data->args.pages = data->pagevec;
data->args.count = count; data->args.count = count;
data->args.lockowner = req->wb_lockowner; data->args.lockowner = req->wb_context->lockowner;
data->args.state = req->wb_state; data->args.state = req->wb_context->state;
data->res.fattr = &data->fattr; data->res.fattr = &data->fattr;
data->res.count = count; data->res.count = count;
...@@ -396,7 +398,7 @@ nfs_pagein_list(struct list_head *head, int rpages) ...@@ -396,7 +398,7 @@ nfs_pagein_list(struct list_head *head, int rpages)
while (!list_empty(head)) { while (!list_empty(head)) {
pages += nfs_coalesce_requests(head, &one_request, rpages); pages += nfs_coalesce_requests(head, &one_request, rpages);
req = nfs_list_entry(one_request.next); req = nfs_list_entry(one_request.next);
error = nfs_pagein_one(&one_request, req->wb_inode); error = nfs_pagein_one(&one_request, req->wb_context->dentry->d_inode);
if (error < 0) if (error < 0)
break; break;
} }
...@@ -500,9 +502,9 @@ void nfs_readpage_result(struct rpc_task *task) ...@@ -500,9 +502,9 @@ void nfs_readpage_result(struct rpc_task *task)
* - The error flag is set for this page. This happens only when a * - The error flag is set for this page. This happens only when a
* previous async read operation failed. * previous async read operation failed.
*/ */
int int nfs_readpage(struct file *file, struct page *page)
nfs_readpage(struct file *file, struct page *page)
{ {
struct nfs_open_context *ctx;
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
int error; int error;
...@@ -519,25 +521,33 @@ nfs_readpage(struct file *file, struct page *page) ...@@ -519,25 +521,33 @@ nfs_readpage(struct file *file, struct page *page)
if (error) if (error)
goto out_error; goto out_error;
if (file == NULL) {
ctx = nfs_find_open_context(inode, FMODE_READ);
if (ctx == NULL)
return -EBADF;
} else
ctx = get_nfs_open_context((struct nfs_open_context *)
file->private_data);
if (!IS_SYNC(inode)) { if (!IS_SYNC(inode)) {
error = nfs_readpage_async(file, inode, page); error = nfs_readpage_async(ctx, inode, page);
goto out; goto out;
} }
error = nfs_readpage_sync(file, inode, page); error = nfs_readpage_sync(ctx, inode, page);
if (error < 0 && IS_SWAPFILE(inode)) if (error < 0 && IS_SWAPFILE(inode))
printk("Aiee.. nfs swap-in of page failed!\n"); printk("Aiee.. nfs swap-in of page failed!\n");
out: out:
put_nfs_open_context(ctx);
return error; return error;
out_error: out_error:
unlock_page(page); unlock_page(page);
goto out; return error;
} }
struct nfs_readdesc { struct nfs_readdesc {
struct list_head *head; struct list_head *head;
struct file *filp; struct nfs_open_context *ctx;
}; };
static int static int
...@@ -552,7 +562,7 @@ readpage_async_filler(void *data, struct page *page) ...@@ -552,7 +562,7 @@ readpage_async_filler(void *data, struct page *page)
len = nfs_page_length(inode, page); len = nfs_page_length(inode, page);
if (len == 0) if (len == 0)
return nfs_return_empty_page(page); return nfs_return_empty_page(page);
new = nfs_create_request(desc->filp, inode, page, 0, len); new = nfs_create_request(desc->ctx, inode, page, 0, len);
if (IS_ERR(new)) { if (IS_ERR(new)) {
SetPageError(page); SetPageError(page);
unlock_page(page); unlock_page(page);
...@@ -565,13 +575,11 @@ readpage_async_filler(void *data, struct page *page) ...@@ -565,13 +575,11 @@ readpage_async_filler(void *data, struct page *page)
return 0; return 0;
} }
int int nfs_readpages(struct file *filp, struct address_space *mapping,
nfs_readpages(struct file *filp, struct address_space *mapping,
struct list_head *pages, unsigned nr_pages) struct list_head *pages, unsigned nr_pages)
{ {
LIST_HEAD(head); LIST_HEAD(head);
struct nfs_readdesc desc = { struct nfs_readdesc desc = {
.filp = filp,
.head = &head, .head = &head,
}; };
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
...@@ -583,12 +591,20 @@ nfs_readpages(struct file *filp, struct address_space *mapping, ...@@ -583,12 +591,20 @@ nfs_readpages(struct file *filp, struct address_space *mapping,
(long long)NFS_FILEID(inode), (long long)NFS_FILEID(inode),
nr_pages); nr_pages);
if (filp == NULL) {
desc.ctx = nfs_find_open_context(inode, FMODE_READ);
if (desc.ctx == NULL)
return -EBADF;
} else
desc.ctx = get_nfs_open_context((struct nfs_open_context *)
filp->private_data);
ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc); ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc);
if (!list_empty(&head)) { if (!list_empty(&head)) {
int err = nfs_pagein_list(&head, server->rpages); int err = nfs_pagein_list(&head, server->rpages);
if (!ret) if (!ret)
ret = err; ret = err;
} }
put_nfs_open_context(desc.ctx);
return ret; return ret;
} }
......
This diff is collapsed.
...@@ -83,6 +83,20 @@ struct nfs_access_entry { ...@@ -83,6 +83,20 @@ struct nfs_access_entry {
int mask; int mask;
}; };
struct nfs4_state;
struct nfs_open_context {
atomic_t count;
struct dentry *dentry;
struct rpc_cred *cred;
struct nfs4_state *state;
fl_owner_t lockowner;
int mode;
int error;
struct list_head list;
wait_queue_head_t waitq;
};
/* /*
* nfs fs inode data in memory * nfs fs inode data in memory
*/ */
...@@ -156,8 +170,8 @@ struct nfs_inode { ...@@ -156,8 +170,8 @@ struct nfs_inode {
ncommit, ncommit,
npages; npages;
/* Credentials for shared mmap */ /* Open contexts for shared mmap writes */
struct rpc_cred *mm_cred; struct list_head open_files;
wait_queue_head_t nfs_i_wait; wait_queue_head_t nfs_i_wait;
...@@ -268,7 +282,6 @@ extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *, ...@@ -268,7 +282,6 @@ extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *,
extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *); extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
extern int nfs_permission(struct inode *, int, struct nameidata *); extern int nfs_permission(struct inode *, int, struct nameidata *);
extern void nfs_set_mmcred(struct inode *, struct rpc_cred *);
extern int nfs_open(struct inode *, struct file *); extern int nfs_open(struct inode *, struct file *);
extern int nfs_release(struct inode *, struct file *); extern int nfs_release(struct inode *, struct file *);
extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *); extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
...@@ -278,6 +291,12 @@ extern void nfs_end_attr_update(struct inode *); ...@@ -278,6 +291,12 @@ extern void nfs_end_attr_update(struct inode *);
extern void nfs_begin_data_update(struct inode *); extern void nfs_begin_data_update(struct inode *);
extern void nfs_end_data_update(struct inode *); extern void nfs_end_data_update(struct inode *);
extern void nfs_end_data_update_defer(struct inode *); extern void nfs_end_data_update_defer(struct inode *);
extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred);
extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
extern void put_nfs_open_context(struct nfs_open_context *ctx);
extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx);
extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, int mode);
extern void nfs_file_clear_open_context(struct file *filp);
/* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */ /* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
extern u32 root_nfs_parse_addr(char *name); /*__init*/ extern u32 root_nfs_parse_addr(char *name); /*__init*/
...@@ -289,16 +308,15 @@ extern struct inode_operations nfs_file_inode_operations; ...@@ -289,16 +308,15 @@ extern struct inode_operations nfs_file_inode_operations;
extern struct file_operations nfs_file_operations; extern struct file_operations nfs_file_operations;
extern struct address_space_operations nfs_file_aops; extern struct address_space_operations nfs_file_aops;
static __inline__ struct rpc_cred * static inline struct rpc_cred *nfs_file_cred(struct file *file)
nfs_file_cred(struct file *file)
{ {
struct rpc_cred *cred = NULL; if (file != NULL) {
if (file) struct nfs_open_context *ctx;
cred = (struct rpc_cred *)file->private_data;
#ifdef RPC_DEBUG ctx = (struct nfs_open_context*)file->private_data;
BUG_ON(cred && cred->cr_magic != RPCAUTH_CRED_MAGIC); return ctx->cred;
#endif }
return cred; return NULL;
} }
/* /*
...@@ -684,6 +702,7 @@ struct nfs4_mount_data; ...@@ -684,6 +702,7 @@ struct nfs4_mount_data;
#define destroy_nfsv4_state(server) do { } while (0) #define destroy_nfsv4_state(server) do { } while (0)
#define nfs4_put_state_owner(inode, owner) do { } while (0) #define nfs4_put_state_owner(inode, owner) do { } while (0)
#define nfs4_put_open_state(state) do { } while (0) #define nfs4_put_open_state(state) do { } while (0)
#define nfs4_close_state(a, b) do { } while (0)
#define nfs4_renewd_prepare_shutdown(server) do { } while (0) #define nfs4_renewd_prepare_shutdown(server) do { } while (0)
#endif #endif
......
...@@ -29,14 +29,9 @@ ...@@ -29,14 +29,9 @@
struct nfs_page { struct nfs_page {
struct list_head wb_list, /* Defines state of page: */ struct list_head wb_list, /* Defines state of page: */
*wb_list_head; /* read/write/commit */ *wb_list_head; /* read/write/commit */
struct file *wb_file;
fl_owner_t wb_lockowner;
struct inode *wb_inode;
struct rpc_cred *wb_cred;
struct nfs4_state *wb_state;
struct page *wb_page; /* page to read in/write out */ struct page *wb_page; /* page to read in/write out */
struct nfs_open_context *wb_context; /* File state context info */
atomic_t wb_complete; /* i/os we're waiting for */ atomic_t wb_complete; /* i/os we're waiting for */
wait_queue_head_t wb_wait; /* wait queue */
unsigned long wb_index; /* Offset >> PAGE_CACHE_SHIFT */ unsigned long wb_index; /* Offset >> PAGE_CACHE_SHIFT */
unsigned int wb_offset, /* Offset & ~PAGE_CACHE_MASK */ unsigned int wb_offset, /* Offset & ~PAGE_CACHE_MASK */
wb_pgbase, /* Start of page data */ wb_pgbase, /* Start of page data */
...@@ -50,9 +45,11 @@ struct nfs_page { ...@@ -50,9 +45,11 @@ struct nfs_page {
#define NFS_NEED_COMMIT(req) (test_bit(PG_NEED_COMMIT,&(req)->wb_flags)) #define NFS_NEED_COMMIT(req) (test_bit(PG_NEED_COMMIT,&(req)->wb_flags))
#define NFS_NEED_RESCHED(req) (test_bit(PG_NEED_RESCHED,&(req)->wb_flags)) #define NFS_NEED_RESCHED(req) (test_bit(PG_NEED_RESCHED,&(req)->wb_flags))
extern struct nfs_page *nfs_create_request(struct file *, struct inode *, extern struct nfs_page *nfs_create_request(struct nfs_open_context *ctx,
struct page *, struct inode *inode,
unsigned int, unsigned int); struct page *page,
unsigned int offset,
unsigned int count);
extern void nfs_clear_request(struct nfs_page *req); extern void nfs_clear_request(struct nfs_page *req);
extern void nfs_release_request(struct nfs_page *req); extern void nfs_release_request(struct nfs_page *req);
...@@ -64,6 +61,7 @@ extern int nfs_scan_list(struct list_head *, struct list_head *, ...@@ -64,6 +61,7 @@ extern int nfs_scan_list(struct list_head *, struct list_head *,
extern int nfs_coalesce_requests(struct list_head *, struct list_head *, extern int nfs_coalesce_requests(struct list_head *, struct list_head *,
unsigned int); unsigned int);
extern int nfs_wait_on_request(struct nfs_page *); extern int nfs_wait_on_request(struct nfs_page *);
extern void nfs_unlock_request(struct nfs_page *req);
/* /*
* Lock the page of an asynchronous request without incrementing the wb_count * Lock the page of an asynchronous request without incrementing the wb_count
...@@ -88,19 +86,6 @@ nfs_lock_request(struct nfs_page *req) ...@@ -88,19 +86,6 @@ nfs_lock_request(struct nfs_page *req)
return 1; return 1;
} }
static inline void
nfs_unlock_request(struct nfs_page *req)
{
if (!NFS_WBACK_BUSY(req)) {
printk(KERN_ERR "NFS: Invalid unlock attempted\n");
BUG();
}
smp_mb__before_clear_bit();
clear_bit(PG_BUSY, &req->wb_flags);
smp_mb__after_clear_bit();
wake_up_all(&req->wb_wait);
nfs_release_request(req);
}
/** /**
* nfs_list_remove_request - Remove a request from its wb_list * nfs_list_remove_request - Remove a request from its wb_list
......
...@@ -678,9 +678,9 @@ struct nfs_rpc_ops { ...@@ -678,9 +678,9 @@ struct nfs_rpc_ops {
struct nfs_fh *, struct nfs_fattr *); struct nfs_fh *, struct nfs_fattr *);
int (*access) (struct inode *, struct nfs_access_entry *); int (*access) (struct inode *, struct nfs_access_entry *);
int (*readlink)(struct inode *, struct page *); int (*readlink)(struct inode *, struct page *);
int (*read) (struct nfs_read_data *, struct file *); int (*read) (struct nfs_read_data *);
int (*write) (struct nfs_write_data *, struct file *); int (*write) (struct nfs_write_data *);
int (*commit) (struct nfs_write_data *, struct file *); int (*commit) (struct nfs_write_data *);
struct inode * (*create) (struct inode *, struct qstr *, struct inode * (*create) (struct inode *, struct qstr *,
struct iattr *, int); struct iattr *, int);
int (*remove) (struct inode *, struct qstr *); int (*remove) (struct inode *, struct qstr *);
...@@ -712,8 +712,6 @@ struct nfs_rpc_ops { ...@@ -712,8 +712,6 @@ struct nfs_rpc_ops {
void (*commit_setup) (struct nfs_write_data *, int how); void (*commit_setup) (struct nfs_write_data *, int how);
int (*file_open) (struct inode *, struct file *); int (*file_open) (struct inode *, struct file *);
int (*file_release) (struct inode *, struct file *); int (*file_release) (struct inode *, struct file *);
void (*request_init)(struct nfs_page *, struct file *);
int (*request_compatible)(struct nfs_page *, struct file *, struct page *);
int (*lock)(struct file *, int, struct file_lock *); int (*lock)(struct file *, int, struct file_lock *);
}; };
......
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