Commit a78ce05d authored by Aneesh Kumar K.V's avatar Aneesh Kumar K.V Committed by Eric Van Hensbergen

fs/9p: Add v9fs_inode

Switch to the fscache code to v9fs_inode. We will later use
v9fs_inode in cache=loose mode to track the inode cache
validity timeout. Ie if we find an inode in cache older
that a specific jiffie range we will consider it stale
Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: default avatarVenkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>
parent a1211908
This diff is collapsed.
...@@ -25,20 +25,6 @@ ...@@ -25,20 +25,6 @@
#include <linux/fscache.h> #include <linux/fscache.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
extern struct kmem_cache *vcookie_cache;
struct v9fs_cookie {
spinlock_t lock;
struct inode inode;
struct fscache_cookie *fscache;
struct p9_qid *qid;
};
static inline struct v9fs_cookie *v9fs_inode2cookie(const struct inode *inode)
{
return container_of(inode, struct v9fs_cookie, inode);
}
extern struct fscache_netfs v9fs_cache_netfs; extern struct fscache_netfs v9fs_cache_netfs;
extern const struct fscache_cookie_def v9fs_cache_session_index_def; extern const struct fscache_cookie_def v9fs_cache_session_index_def;
extern const struct fscache_cookie_def v9fs_cache_inode_index_def; extern const struct fscache_cookie_def v9fs_cache_inode_index_def;
...@@ -66,21 +52,6 @@ extern int __v9fs_readpages_from_fscache(struct inode *inode, ...@@ -66,21 +52,6 @@ extern int __v9fs_readpages_from_fscache(struct inode *inode,
extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page); extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page);
extern void __v9fs_fscache_wait_on_page_write(struct inode *inode, extern void __v9fs_fscache_wait_on_page_write(struct inode *inode,
struct page *page); struct page *page);
/**
* v9fs_cache_register - Register v9fs file system with the cache
*/
static inline int v9fs_cache_register(void)
{
return __v9fs_cache_register();
}
/**
* v9fs_cache_unregister - Unregister v9fs from the cache
*/
static inline void v9fs_cache_unregister(void)
{
__v9fs_cache_unregister();
}
static inline int v9fs_fscache_release_page(struct page *page, static inline int v9fs_fscache_release_page(struct page *page,
gfp_t gfp) gfp_t gfp)
...@@ -117,18 +88,18 @@ static inline void v9fs_readpage_to_fscache(struct inode *inode, ...@@ -117,18 +88,18 @@ static inline void v9fs_readpage_to_fscache(struct inode *inode,
static inline void v9fs_uncache_page(struct inode *inode, struct page *page) static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
{ {
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
fscache_uncache_page(vcookie->fscache, page); fscache_uncache_page(v9inode->fscache, page);
BUG_ON(PageFsCache(page)); BUG_ON(PageFsCache(page));
} }
static inline void v9fs_vcookie_set_qid(struct inode *inode, static inline void v9fs_fscache_set_key(struct inode *inode,
struct p9_qid *qid) struct p9_qid *qid)
{ {
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
spin_lock(&vcookie->lock); spin_lock(&v9inode->fscache_lock);
vcookie->qid = qid; v9inode->fscache_key = qid;
spin_unlock(&vcookie->lock); spin_unlock(&v9inode->fscache_lock);
} }
static inline void v9fs_fscache_wait_on_page_write(struct inode *inode, static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
...@@ -139,13 +110,6 @@ static inline void v9fs_fscache_wait_on_page_write(struct inode *inode, ...@@ -139,13 +110,6 @@ static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
#else /* CONFIG_9P_FSCACHE */ #else /* CONFIG_9P_FSCACHE */
static inline int v9fs_cache_register(void)
{
return 1;
}
static inline void v9fs_cache_unregister(void) {}
static inline int v9fs_fscache_release_page(struct page *page, static inline int v9fs_fscache_release_page(struct page *page,
gfp_t gfp) { gfp_t gfp) {
return 1; return 1;
...@@ -174,10 +138,6 @@ static inline void v9fs_readpage_to_fscache(struct inode *inode, ...@@ -174,10 +138,6 @@ static inline void v9fs_readpage_to_fscache(struct inode *inode,
static inline void v9fs_uncache_page(struct inode *inode, struct page *page) static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
{} {}
static inline void v9fs_vcookie_set_qid(struct inode *inode,
struct p9_qid *qid)
{}
static inline void v9fs_fscache_wait_on_page_write(struct inode *inode, static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
struct page *page) struct page *page)
{ {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
static DEFINE_SPINLOCK(v9fs_sessionlist_lock); static DEFINE_SPINLOCK(v9fs_sessionlist_lock);
static LIST_HEAD(v9fs_sessionlist); static LIST_HEAD(v9fs_sessionlist);
struct kmem_cache *v9fs_inode_cache;
/* /*
* Option Parsing (code inspired by NFS code) * Option Parsing (code inspired by NFS code)
...@@ -481,6 +482,63 @@ static void v9fs_sysfs_cleanup(void) ...@@ -481,6 +482,63 @@ static void v9fs_sysfs_cleanup(void)
kobject_put(v9fs_kobj); kobject_put(v9fs_kobj);
} }
static void v9fs_inode_init_once(void *foo)
{
struct v9fs_inode *v9inode = (struct v9fs_inode *)foo;
#ifdef CONFIG_9P_FSCACHE
v9inode->fscache = NULL;
v9inode->fscache_key = NULL;
#endif
inode_init_once(&v9inode->vfs_inode);
}
/**
* v9fs_init_inode_cache - initialize a cache for 9P
* Returns 0 on success.
*/
static int v9fs_init_inode_cache(void)
{
v9fs_inode_cache = kmem_cache_create("v9fs_inode_cache",
sizeof(struct v9fs_inode),
0, (SLAB_RECLAIM_ACCOUNT|
SLAB_MEM_SPREAD),
v9fs_inode_init_once);
if (!v9fs_inode_cache)
return -ENOMEM;
return 0;
}
/**
* v9fs_destroy_inode_cache - destroy the cache of 9P inode
*
*/
static void v9fs_destroy_inode_cache(void)
{
kmem_cache_destroy(v9fs_inode_cache);
}
static int v9fs_cache_register(void)
{
int ret;
ret = v9fs_init_inode_cache();
if (ret < 0)
return ret;
#ifdef CONFIG_9P_FSCACHE
return fscache_register_netfs(&v9fs_cache_netfs);
#else
return ret;
#endif
}
static void v9fs_cache_unregister(void)
{
v9fs_destroy_inode_cache();
#ifdef CONFIG_9P_FSCACHE
fscache_unregister_netfs(&v9fs_cache_netfs);
#endif
}
/** /**
* init_v9fs - Initialize module * init_v9fs - Initialize module
* *
......
...@@ -116,6 +116,20 @@ struct v9fs_session_info { ...@@ -116,6 +116,20 @@ struct v9fs_session_info {
struct p9_fid *root_fid; /* Used for file system sync */ struct p9_fid *root_fid; /* Used for file system sync */
}; };
struct v9fs_inode {
#ifdef CONFIG_9P_FSCACHE
spinlock_t fscache_lock;
struct fscache_cookie *fscache;
struct p9_qid *fscache_key;
#endif
struct inode vfs_inode;
};
static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
{
return container_of(inode, struct v9fs_inode, vfs_inode);
}
struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *, struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,
char *); char *);
extern void v9fs_session_close(struct v9fs_session_info *v9ses); extern void v9fs_session_close(struct v9fs_session_info *v9ses);
...@@ -129,16 +143,15 @@ extern int v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -129,16 +143,15 @@ extern int v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry); struct inode *new_dir, struct dentry *new_dentry);
extern void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, extern void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd,
void *p); void *p);
extern struct inode *v9fs_inode(struct v9fs_session_info *v9ses, extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,
struct p9_fid *fid, struct p9_fid *fid,
struct super_block *sb); struct super_block *sb);
extern const struct inode_operations v9fs_dir_inode_operations_dotl; extern const struct inode_operations v9fs_dir_inode_operations_dotl;
extern const struct inode_operations v9fs_file_inode_operations_dotl; extern const struct inode_operations v9fs_file_inode_operations_dotl;
extern const struct inode_operations v9fs_symlink_inode_operations_dotl; extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
extern struct inode *v9fs_inode_dotl(struct v9fs_session_info *v9ses, extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses,
struct p9_fid *fid, struct p9_fid *fid,
struct super_block *sb); struct super_block *sb);
/* other default globals */ /* other default globals */
#define V9FS_PORT 564 #define V9FS_PORT 564
...@@ -163,7 +176,7 @@ static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses) ...@@ -163,7 +176,7 @@ static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
} }
/** /**
* v9fs_inode_from_fid - Helper routine to populate an inode by * v9fs_get_inode_from_fid - Helper routine to populate an inode by
* issuing a attribute request * issuing a attribute request
* @v9ses: session information * @v9ses: session information
* @fid: fid to issue attribute request for * @fid: fid to issue attribute request for
...@@ -171,11 +184,11 @@ static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses) ...@@ -171,11 +184,11 @@ static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
* *
*/ */
static inline struct inode * static inline struct inode *
v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
struct super_block *sb) struct super_block *sb)
{ {
if (v9fs_proto_dotl(v9ses)) if (v9fs_proto_dotl(v9ses))
return v9fs_inode_dotl(v9ses, fid, sb); return v9fs_inode_from_fid_dotl(v9ses, fid, sb);
else else
return v9fs_inode(v9ses, fid, sb); return v9fs_inode_from_fid(v9ses, fid, sb);
} }
...@@ -47,12 +47,10 @@ extern const struct dentry_operations v9fs_dentry_operations; ...@@ -47,12 +47,10 @@ extern const struct dentry_operations v9fs_dentry_operations;
extern const struct dentry_operations v9fs_cached_dentry_operations; extern const struct dentry_operations v9fs_cached_dentry_operations;
extern const struct file_operations v9fs_cached_file_operations; extern const struct file_operations v9fs_cached_file_operations;
extern const struct file_operations v9fs_cached_file_operations_dotl; extern const struct file_operations v9fs_cached_file_operations_dotl;
extern struct kmem_cache *v9fs_inode_cache;
#ifdef CONFIG_9P_FSCACHE
struct inode *v9fs_alloc_inode(struct super_block *sb); struct inode *v9fs_alloc_inode(struct super_block *sb);
void v9fs_destroy_inode(struct inode *inode); void v9fs_destroy_inode(struct inode *inode);
#endif
struct inode *v9fs_get_inode(struct super_block *sb, int mode); struct inode *v9fs_get_inode(struct super_block *sb, int mode);
int v9fs_init_inode(struct v9fs_session_info *v9ses, int v9fs_init_inode(struct v9fs_session_info *v9ses,
struct inode *inode, int mode); struct inode *inode, int mode);
......
...@@ -203,26 +203,23 @@ v9fs_blank_wstat(struct p9_wstat *wstat) ...@@ -203,26 +203,23 @@ v9fs_blank_wstat(struct p9_wstat *wstat)
wstat->extension = NULL; wstat->extension = NULL;
} }
#ifdef CONFIG_9P_FSCACHE
/** /**
* v9fs_alloc_inode - helper function to allocate an inode * v9fs_alloc_inode - helper function to allocate an inode
* This callback is executed before setting up the inode so that we
* can associate a vcookie with each inode.
* *
*/ */
struct inode *v9fs_alloc_inode(struct super_block *sb) struct inode *v9fs_alloc_inode(struct super_block *sb)
{ {
struct v9fs_cookie *vcookie; struct v9fs_inode *v9inode;
vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache, v9inode = (struct v9fs_inode *)kmem_cache_alloc(v9fs_inode_cache,
GFP_KERNEL); GFP_KERNEL);
if (!vcookie) if (!v9inode)
return NULL; return NULL;
#ifdef CONFIG_9P_FSCACHE
vcookie->fscache = NULL; v9inode->fscache = NULL;
vcookie->qid = NULL; v9inode->fscache_key = NULL;
spin_lock_init(&vcookie->lock); spin_lock_init(&v9inode->fscache_lock);
return &vcookie->inode; #endif
return &v9inode->vfs_inode;
} }
/** /**
...@@ -234,14 +231,13 @@ static void v9fs_i_callback(struct rcu_head *head) ...@@ -234,14 +231,13 @@ static void v9fs_i_callback(struct rcu_head *head)
{ {
struct inode *inode = container_of(head, struct inode, i_rcu); struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry); INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode)); kmem_cache_free(v9fs_inode_cache, V9FS_I(inode));
} }
void v9fs_destroy_inode(struct inode *inode) void v9fs_destroy_inode(struct inode *inode)
{ {
call_rcu(&inode->i_rcu, v9fs_i_callback); call_rcu(&inode->i_rcu, v9fs_i_callback);
} }
#endif
int v9fs_init_inode(struct v9fs_session_info *v9ses, int v9fs_init_inode(struct v9fs_session_info *v9ses,
struct inode *inode, int mode) struct inode *inode, int mode)
...@@ -459,7 +455,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb, ...@@ -459,7 +455,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
v9fs_stat2inode(st, inode, sb); v9fs_stat2inode(st, inode, sb);
#ifdef CONFIG_9P_FSCACHE #ifdef CONFIG_9P_FSCACHE
v9fs_vcookie_set_qid(ret, &st->qid); v9fs_fscache_set_key(inode, &st->qid);
v9fs_cache_inode_get_cookie(inode); v9fs_cache_inode_get_cookie(inode);
#endif #endif
unlock_new_inode(inode); unlock_new_inode(inode);
...@@ -472,8 +468,8 @@ static struct inode *v9fs_qid_iget(struct super_block *sb, ...@@ -472,8 +468,8 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
} }
struct inode * struct inode *
v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid, v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
struct super_block *sb) struct super_block *sb)
{ {
struct p9_wstat *st; struct p9_wstat *st;
struct inode *inode = NULL; struct inode *inode = NULL;
...@@ -572,7 +568,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, ...@@ -572,7 +568,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
} }
/* instantiate inode and assign the unopened fid to the dentry */ /* instantiate inode and assign the unopened fid to the dentry */
inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
...@@ -747,7 +743,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -747,7 +743,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
return ERR_PTR(result); return ERR_PTR(result);
} }
inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
result = PTR_ERR(inode); result = PTR_ERR(inode);
inode = NULL; inode = NULL;
......
...@@ -113,7 +113,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb, ...@@ -113,7 +113,7 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
v9fs_stat2inode_dotl(st, inode); v9fs_stat2inode_dotl(st, inode);
#ifdef CONFIG_9P_FSCACHE #ifdef CONFIG_9P_FSCACHE
v9fs_vcookie_set_qid(inode, &st->qid); v9fs_fscache_set_key(inode, &st->qid);
v9fs_cache_inode_get_cookie(inode); v9fs_cache_inode_get_cookie(inode);
#endif #endif
retval = v9fs_get_acl(inode, fid); retval = v9fs_get_acl(inode, fid);
...@@ -130,8 +130,8 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb, ...@@ -130,8 +130,8 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
} }
struct inode * struct inode *
v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
struct super_block *sb) struct super_block *sb)
{ {
struct p9_stat_dotl *st; struct p9_stat_dotl *st;
struct inode *inode = NULL; struct inode *inode = NULL;
...@@ -228,7 +228,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode, ...@@ -228,7 +228,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
fid = NULL; fid = NULL;
goto error; goto error;
} }
inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
...@@ -341,7 +341,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, ...@@ -341,7 +341,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
goto error; goto error;
} }
inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
...@@ -588,7 +588,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, ...@@ -588,7 +588,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
} }
/* instantiate inode and assign the unopened fid to dentry */ /* instantiate inode and assign the unopened fid to dentry */
inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
...@@ -747,7 +747,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, ...@@ -747,7 +747,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
goto error; goto error;
} }
inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
......
...@@ -292,10 +292,8 @@ static int v9fs_sync_fs(struct super_block *sb, int wait) ...@@ -292,10 +292,8 @@ static int v9fs_sync_fs(struct super_block *sb, int wait)
} }
static const struct super_operations v9fs_super_ops = { static const struct super_operations v9fs_super_ops = {
#ifdef CONFIG_9P_FSCACHE
.alloc_inode = v9fs_alloc_inode, .alloc_inode = v9fs_alloc_inode,
.destroy_inode = v9fs_destroy_inode, .destroy_inode = v9fs_destroy_inode,
#endif
.statfs = simple_statfs, .statfs = simple_statfs,
.evict_inode = v9fs_evict_inode, .evict_inode = v9fs_evict_inode,
.show_options = generic_show_options, .show_options = generic_show_options,
...@@ -303,10 +301,8 @@ static const struct super_operations v9fs_super_ops = { ...@@ -303,10 +301,8 @@ static const struct super_operations v9fs_super_ops = {
}; };
static const struct super_operations v9fs_super_ops_dotl = { static const struct super_operations v9fs_super_ops_dotl = {
#ifdef CONFIG_9P_FSCACHE
.alloc_inode = v9fs_alloc_inode, .alloc_inode = v9fs_alloc_inode,
.destroy_inode = v9fs_destroy_inode, .destroy_inode = v9fs_destroy_inode,
#endif
.sync_fs = v9fs_sync_fs, .sync_fs = v9fs_sync_fs,
.statfs = v9fs_statfs, .statfs = v9fs_statfs,
.evict_inode = v9fs_evict_inode, .evict_inode = v9fs_evict_inode,
......
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