Commit ec059472 authored by Trond Myklebust's avatar Trond Myklebust

Prepare for the introduction of NFSv4 state code.

Split out the open() method for regular files from that of
directories.
parent c0aaa961
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#define NFS_PARANOIA 1 #define NFS_PARANOIA 1
/* #define NFS_DEBUG_VERBOSE 1 */ /* #define NFS_DEBUG_VERBOSE 1 */
static int nfs_opendir(struct inode *, struct file *);
static int nfs_readdir(struct file *, void *, filldir_t); static int nfs_readdir(struct file *, void *, filldir_t);
static struct dentry *nfs_lookup(struct inode *, struct dentry *); static struct dentry *nfs_lookup(struct inode *, struct dentry *);
static int nfs_cached_lookup(struct inode *, struct dentry *, static int nfs_cached_lookup(struct inode *, struct dentry *,
...@@ -52,7 +53,7 @@ static int nfs_rename(struct inode *, struct dentry *, ...@@ -52,7 +53,7 @@ static int nfs_rename(struct inode *, struct dentry *,
struct file_operations nfs_dir_operations = { struct file_operations nfs_dir_operations = {
.read = generic_read_dir, .read = generic_read_dir,
.readdir = nfs_readdir, .readdir = nfs_readdir,
.open = nfs_open, .open = nfs_opendir,
.release = nfs_release, .release = nfs_release,
}; };
...@@ -71,6 +72,26 @@ struct inode_operations nfs_dir_inode_operations = { ...@@ -71,6 +72,26 @@ struct inode_operations nfs_dir_inode_operations = {
.setattr = nfs_setattr, .setattr = nfs_setattr,
}; };
/*
* Open file
*/
static int
nfs_opendir(struct inode *inode, struct file *filp)
{
struct nfs_server *server = NFS_SERVER(inode);
int res = 0;
lock_kernel();
/* Do cto revalidation */
if (server->flags & NFS_MOUNT_NOCTO)
res = __nfs_revalidate_inode(server, inode);
/* Call generic open code in order to cache credentials */
if (!res)
res = nfs_open(inode, filp);
unlock_kernel();
return res;
}
typedef u32 * (*decode_dirent_t)(u32 *, struct nfs_entry *, int); typedef u32 * (*decode_dirent_t)(u32 *, struct nfs_entry *, int);
typedef struct { typedef struct {
struct file *file; struct file *file;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#define NFSDBG_FACILITY NFSDBG_FILE #define NFSDBG_FACILITY NFSDBG_FILE
static int nfs_file_open(struct inode *, struct file *);
static int nfs_file_mmap(struct file *, struct vm_area_struct *); static int nfs_file_mmap(struct file *, struct vm_area_struct *);
static ssize_t nfs_file_sendfile(struct file *, loff_t *, size_t, read_actor_t, void *); static ssize_t nfs_file_sendfile(struct file *, loff_t *, size_t, read_actor_t, void *);
static ssize_t nfs_file_read(struct kiocb *, char *, size_t, loff_t); static ssize_t nfs_file_read(struct kiocb *, char *, size_t, loff_t);
...@@ -48,7 +49,7 @@ struct file_operations nfs_file_operations = { ...@@ -48,7 +49,7 @@ struct file_operations nfs_file_operations = {
.aio_read = nfs_file_read, .aio_read = nfs_file_read,
.aio_write = nfs_file_write, .aio_write = nfs_file_write,
.mmap = nfs_file_mmap, .mmap = nfs_file_mmap,
.open = nfs_open, .open = nfs_file_open,
.flush = nfs_file_flush, .flush = nfs_file_flush,
.release = nfs_release, .release = nfs_release,
.fsync = nfs_fsync, .fsync = nfs_fsync,
...@@ -67,6 +68,30 @@ struct inode_operations nfs_file_inode_operations = { ...@@ -67,6 +68,30 @@ struct inode_operations nfs_file_inode_operations = {
# define IS_SWAPFILE(inode) (0) # define IS_SWAPFILE(inode) (0)
#endif #endif
/*
* Open file
*/
static int
nfs_file_open(struct inode *inode, struct file *filp)
{
struct nfs_server *server = NFS_SERVER(inode);
int (*open)(struct inode *, struct file *);
int res = 0;
lock_kernel();
/* Do NFSv4 open() call */
if ((open = server->rpc_ops->file_open) != NULL)
res = open(inode, filp);
/* Do cto revalidation */
else if (server->flags & NFS_MOUNT_NOCTO)
res = __nfs_revalidate_inode(server, inode);
/* Call generic open code in order to cache credentials */
if (!res)
res = nfs_open(inode, filp);
unlock_kernel();
return res;
}
/* /*
* Flush all dirty pages, and check for write errors. * Flush all dirty pages, and check for write errors.
* *
......
...@@ -855,23 +855,13 @@ int nfs_open(struct inode *inode, struct file *filp) ...@@ -855,23 +855,13 @@ int nfs_open(struct inode *inode, struct file *filp)
{ {
struct rpc_auth *auth; struct rpc_auth *auth;
struct rpc_cred *cred; struct rpc_cred *cred;
int err = 0;
lock_kernel();
/* Ensure that we revalidate the data cache */
if (NFS_SERVER(inode)->flags & NFS_MOUNT_NOCTO) {
err = __nfs_revalidate_inode(NFS_SERVER(inode),inode);
if (err)
goto out;
}
auth = NFS_CLIENT(inode)->cl_auth; auth = NFS_CLIENT(inode)->cl_auth;
cred = rpcauth_lookupcred(auth, 0); cred = rpcauth_lookupcred(auth, 0);
filp->private_data = cred; filp->private_data = cred;
if (filp->f_mode & FMODE_WRITE) if (filp->f_mode & FMODE_WRITE)
nfs_set_mmcred(inode, cred); nfs_set_mmcred(inode, cred);
out: return 0;
unlock_kernel();
return err;
} }
int nfs_release(struct inode *inode, struct file *filp) int nfs_release(struct inode *inode, struct file *filp)
......
...@@ -1560,6 +1560,16 @@ nfs4_proc_renew(struct nfs_server *server) ...@@ -1560,6 +1560,16 @@ nfs4_proc_renew(struct nfs_server *server)
return rpc_execute(task); return rpc_execute(task);
} }
/*
* To be changed into a real NFSv4 file_open soon.
*/
int
nfs4_proc_file_open(struct inode *inode, struct file *filp)
{
return 0;
}
struct nfs_rpc_ops nfs_v4_clientops = { struct nfs_rpc_ops nfs_v4_clientops = {
.version = 4, /* protocol version */ .version = 4, /* protocol version */
.getroot = nfs4_proc_get_root, .getroot = nfs4_proc_get_root,
...@@ -1589,6 +1599,7 @@ struct nfs_rpc_ops nfs_v4_clientops = { ...@@ -1589,6 +1599,7 @@ struct nfs_rpc_ops nfs_v4_clientops = {
.read_setup = nfs4_proc_read_setup, .read_setup = nfs4_proc_read_setup,
.write_setup = nfs4_proc_write_setup, .write_setup = nfs4_proc_write_setup,
.commit_setup = nfs4_proc_commit_setup, .commit_setup = nfs4_proc_commit_setup,
.file_open = nfs4_proc_file_open,
}; };
/* /*
......
...@@ -597,6 +597,7 @@ struct nfs_rpc_ops { ...@@ -597,6 +597,7 @@ struct nfs_rpc_ops {
void (*read_setup) (struct nfs_read_data *, unsigned int count); void (*read_setup) (struct nfs_read_data *, unsigned int count);
void (*write_setup) (struct nfs_write_data *, unsigned int count, int how); void (*write_setup) (struct nfs_write_data *, unsigned int count, int how);
void (*commit_setup) (struct nfs_write_data *, u64 start, u32 len, int how); void (*commit_setup) (struct nfs_write_data *, u64 start, u32 len, int how);
int (*file_open) (struct inode *, struct file *);
}; };
/* /*
......
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