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
...@@ -33,67 +33,11 @@ ...@@ -33,67 +33,11 @@
#define CACHETAG_LEN 11 #define CACHETAG_LEN 11
struct kmem_cache *vcookie_cache;
struct fscache_netfs v9fs_cache_netfs = { struct fscache_netfs v9fs_cache_netfs = {
.name = "9p", .name = "9p",
.version = 0, .version = 0,
}; };
static void init_once(void *foo)
{
struct v9fs_cookie *vcookie = (struct v9fs_cookie *) foo;
vcookie->fscache = NULL;
vcookie->qid = NULL;
inode_init_once(&vcookie->inode);
}
/**
* v9fs_init_vcookiecache - initialize a cache for vcookies to maintain
* vcookie to inode mapping
*
* Returns 0 on success.
*/
static int v9fs_init_vcookiecache(void)
{
vcookie_cache = kmem_cache_create("vcookie_cache",
sizeof(struct v9fs_cookie),
0, (SLAB_RECLAIM_ACCOUNT|
SLAB_MEM_SPREAD),
init_once);
if (!vcookie_cache)
return -ENOMEM;
return 0;
}
/**
* v9fs_destroy_vcookiecache - destroy the cache of vcookies
*
*/
static void v9fs_destroy_vcookiecache(void)
{
kmem_cache_destroy(vcookie_cache);
}
int __v9fs_cache_register(void)
{
int ret;
ret = v9fs_init_vcookiecache();
if (ret < 0)
return ret;
return fscache_register_netfs(&v9fs_cache_netfs);
}
void __v9fs_cache_unregister(void)
{
v9fs_destroy_vcookiecache();
fscache_unregister_netfs(&v9fs_cache_netfs);
}
/** /**
* v9fs_random_cachetag - Generate a random tag to be associated * v9fs_random_cachetag - Generate a random tag to be associated
* with a new cache session. * with a new cache session.
...@@ -133,9 +77,9 @@ static uint16_t v9fs_cache_session_get_key(const void *cookie_netfs_data, ...@@ -133,9 +77,9 @@ static uint16_t v9fs_cache_session_get_key(const void *cookie_netfs_data,
} }
const struct fscache_cookie_def v9fs_cache_session_index_def = { const struct fscache_cookie_def v9fs_cache_session_index_def = {
.name = "9P.session", .name = "9P.session",
.type = FSCACHE_COOKIE_TYPE_INDEX, .type = FSCACHE_COOKIE_TYPE_INDEX,
.get_key = v9fs_cache_session_get_key, .get_key = v9fs_cache_session_get_key,
}; };
void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses) void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
...@@ -163,33 +107,33 @@ void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses) ...@@ -163,33 +107,33 @@ void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses)
static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data, static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t bufmax) void *buffer, uint16_t bufmax)
{ {
const struct v9fs_cookie *vcookie = cookie_netfs_data; const struct v9fs_inode *v9inode = cookie_netfs_data;
memcpy(buffer, &vcookie->qid->path, sizeof(vcookie->qid->path)); memcpy(buffer, &v9inode->fscache_key->path,
sizeof(v9inode->fscache_key->path));
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get key %llu", &vcookie->inode, P9_DPRINTK(P9_DEBUG_FSC, "inode %p get key %llu", &v9inode->vfs_inode,
vcookie->qid->path); v9inode->fscache_key->path);
return sizeof(vcookie->qid->path); return sizeof(v9inode->fscache_key->path);
} }
static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data, static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data,
uint64_t *size) uint64_t *size)
{ {
const struct v9fs_cookie *vcookie = cookie_netfs_data; const struct v9fs_inode *v9inode = cookie_netfs_data;
*size = i_size_read(&vcookie->inode); *size = i_size_read(&v9inode->vfs_inode);
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get attr %llu", &vcookie->inode, P9_DPRINTK(P9_DEBUG_FSC, "inode %p get attr %llu", &v9inode->vfs_inode,
*size); *size);
} }
static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data, static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data,
void *buffer, uint16_t buflen) void *buffer, uint16_t buflen)
{ {
const struct v9fs_cookie *vcookie = cookie_netfs_data; const struct v9fs_inode *v9inode = cookie_netfs_data;
memcpy(buffer, &vcookie->qid->version, sizeof(vcookie->qid->version)); memcpy(buffer, &v9inode->fscache_key->version,
sizeof(v9inode->fscache_key->version));
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get aux %u", &vcookie->inode, P9_DPRINTK(P9_DEBUG_FSC, "inode %p get aux %u", &v9inode->vfs_inode,
vcookie->qid->version); v9inode->fscache_key->version);
return sizeof(vcookie->qid->version); return sizeof(v9inode->fscache_key->version);
} }
static enum static enum
...@@ -197,13 +141,13 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data, ...@@ -197,13 +141,13 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
const void *buffer, const void *buffer,
uint16_t buflen) uint16_t buflen)
{ {
const struct v9fs_cookie *vcookie = cookie_netfs_data; const struct v9fs_inode *v9inode = cookie_netfs_data;
if (buflen != sizeof(vcookie->qid->version)) if (buflen != sizeof(v9inode->fscache_key->version))
return FSCACHE_CHECKAUX_OBSOLETE; return FSCACHE_CHECKAUX_OBSOLETE;
if (memcmp(buffer, &vcookie->qid->version, if (memcmp(buffer, &v9inode->fscache_key->version,
sizeof(vcookie->qid->version))) sizeof(v9inode->fscache_key->version)))
return FSCACHE_CHECKAUX_OBSOLETE; return FSCACHE_CHECKAUX_OBSOLETE;
return FSCACHE_CHECKAUX_OKAY; return FSCACHE_CHECKAUX_OKAY;
...@@ -211,7 +155,7 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data, ...@@ -211,7 +155,7 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
static void v9fs_cache_inode_now_uncached(void *cookie_netfs_data) static void v9fs_cache_inode_now_uncached(void *cookie_netfs_data)
{ {
struct v9fs_cookie *vcookie = cookie_netfs_data; struct v9fs_inode *v9inode = cookie_netfs_data;
struct pagevec pvec; struct pagevec pvec;
pgoff_t first; pgoff_t first;
int loop, nr_pages; int loop, nr_pages;
...@@ -220,7 +164,7 @@ static void v9fs_cache_inode_now_uncached(void *cookie_netfs_data) ...@@ -220,7 +164,7 @@ static void v9fs_cache_inode_now_uncached(void *cookie_netfs_data)
first = 0; first = 0;
for (;;) { for (;;) {
nr_pages = pagevec_lookup(&pvec, vcookie->inode.i_mapping, nr_pages = pagevec_lookup(&pvec, v9inode->vfs_inode.i_mapping,
first, first,
PAGEVEC_SIZE - pagevec_count(&pvec)); PAGEVEC_SIZE - pagevec_count(&pvec));
if (!nr_pages) if (!nr_pages)
...@@ -249,115 +193,114 @@ const struct fscache_cookie_def v9fs_cache_inode_index_def = { ...@@ -249,115 +193,114 @@ const struct fscache_cookie_def v9fs_cache_inode_index_def = {
void v9fs_cache_inode_get_cookie(struct inode *inode) void v9fs_cache_inode_get_cookie(struct inode *inode)
{ {
struct v9fs_cookie *vcookie; struct v9fs_inode *v9inode;
struct v9fs_session_info *v9ses; struct v9fs_session_info *v9ses;
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return; return;
vcookie = v9fs_inode2cookie(inode); v9inode = V9FS_I(inode);
if (vcookie->fscache) if (v9inode->fscache)
return; return;
v9ses = v9fs_inode2v9ses(inode); v9ses = v9fs_inode2v9ses(inode);
vcookie->fscache = fscache_acquire_cookie(v9ses->fscache, v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
&v9fs_cache_inode_index_def, &v9fs_cache_inode_index_def,
vcookie); v9inode);
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get cookie %p", inode, P9_DPRINTK(P9_DEBUG_FSC, "inode %p get cookie %p", inode,
vcookie->fscache); v9inode->fscache);
} }
void v9fs_cache_inode_put_cookie(struct inode *inode) void v9fs_cache_inode_put_cookie(struct inode *inode)
{ {
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
if (!vcookie->fscache) if (!v9inode->fscache)
return; return;
P9_DPRINTK(P9_DEBUG_FSC, "inode %p put cookie %p", inode, P9_DPRINTK(P9_DEBUG_FSC, "inode %p put cookie %p", inode,
vcookie->fscache); v9inode->fscache);
fscache_relinquish_cookie(vcookie->fscache, 0); fscache_relinquish_cookie(v9inode->fscache, 0);
vcookie->fscache = NULL; v9inode->fscache = NULL;
} }
void v9fs_cache_inode_flush_cookie(struct inode *inode) void v9fs_cache_inode_flush_cookie(struct inode *inode)
{ {
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
if (!vcookie->fscache) if (!v9inode->fscache)
return; return;
P9_DPRINTK(P9_DEBUG_FSC, "inode %p flush cookie %p", inode, P9_DPRINTK(P9_DEBUG_FSC, "inode %p flush cookie %p", inode,
vcookie->fscache); v9inode->fscache);
fscache_relinquish_cookie(vcookie->fscache, 1); fscache_relinquish_cookie(v9inode->fscache, 1);
vcookie->fscache = NULL; v9inode->fscache = NULL;
} }
void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp) void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp)
{ {
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
struct p9_fid *fid; struct p9_fid *fid;
if (!vcookie->fscache) if (!v9inode->fscache)
return; return;
spin_lock(&vcookie->lock); spin_lock(&v9inode->fscache_lock);
fid = filp->private_data; fid = filp->private_data;
if ((filp->f_flags & O_ACCMODE) != O_RDONLY) if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
v9fs_cache_inode_flush_cookie(inode); v9fs_cache_inode_flush_cookie(inode);
else else
v9fs_cache_inode_get_cookie(inode); v9fs_cache_inode_get_cookie(inode);
spin_unlock(&vcookie->lock); spin_unlock(&v9inode->fscache_lock);
} }
void v9fs_cache_inode_reset_cookie(struct inode *inode) void v9fs_cache_inode_reset_cookie(struct inode *inode)
{ {
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
struct v9fs_session_info *v9ses; struct v9fs_session_info *v9ses;
struct fscache_cookie *old; struct fscache_cookie *old;
if (!vcookie->fscache) if (!v9inode->fscache)
return; return;
old = vcookie->fscache; old = v9inode->fscache;
spin_lock(&vcookie->lock); spin_lock(&v9inode->fscache_lock);
fscache_relinquish_cookie(vcookie->fscache, 1); fscache_relinquish_cookie(v9inode->fscache, 1);
v9ses = v9fs_inode2v9ses(inode); v9ses = v9fs_inode2v9ses(inode);
vcookie->fscache = fscache_acquire_cookie(v9ses->fscache, v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
&v9fs_cache_inode_index_def, &v9fs_cache_inode_index_def,
vcookie); v9inode);
P9_DPRINTK(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p", P9_DPRINTK(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p",
inode, old, vcookie->fscache); inode, old, v9inode->fscache);
spin_unlock(&vcookie->lock); spin_unlock(&v9inode->fscache_lock);
} }
int __v9fs_fscache_release_page(struct page *page, gfp_t gfp) int __v9fs_fscache_release_page(struct page *page, gfp_t gfp)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
BUG_ON(!vcookie->fscache); BUG_ON(!v9inode->fscache);
return fscache_maybe_release_page(vcookie->fscache, page, gfp); return fscache_maybe_release_page(v9inode->fscache, page, gfp);
} }
void __v9fs_fscache_invalidate_page(struct page *page) void __v9fs_fscache_invalidate_page(struct page *page)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); struct v9fs_inode *v9inode = V9FS_I(inode);
BUG_ON(!vcookie->fscache); BUG_ON(!v9inode->fscache);
if (PageFsCache(page)) { if (PageFsCache(page)) {
fscache_wait_on_page_write(vcookie->fscache, page); fscache_wait_on_page_write(v9inode->fscache, page);
BUG_ON(!PageLocked(page)); BUG_ON(!PageLocked(page));
fscache_uncache_page(vcookie->fscache, page); fscache_uncache_page(v9inode->fscache, page);
} }
} }
...@@ -380,13 +323,13 @@ static void v9fs_vfs_readpage_complete(struct page *page, void *data, ...@@ -380,13 +323,13 @@ static void v9fs_vfs_readpage_complete(struct page *page, void *data,
int __v9fs_readpage_from_fscache(struct inode *inode, struct page *page) int __v9fs_readpage_from_fscache(struct inode *inode, struct page *page)
{ {
int ret; int ret;
const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); const struct v9fs_inode *v9inode = V9FS_I(inode);
P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page); P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page);
if (!vcookie->fscache) if (!v9inode->fscache)
return -ENOBUFS; return -ENOBUFS;
ret = fscache_read_or_alloc_page(vcookie->fscache, ret = fscache_read_or_alloc_page(v9inode->fscache,
page, page,
v9fs_vfs_readpage_complete, v9fs_vfs_readpage_complete,
NULL, NULL,
...@@ -418,13 +361,13 @@ int __v9fs_readpages_from_fscache(struct inode *inode, ...@@ -418,13 +361,13 @@ int __v9fs_readpages_from_fscache(struct inode *inode,
unsigned *nr_pages) unsigned *nr_pages)
{ {
int ret; int ret;
const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); const struct v9fs_inode *v9inode = V9FS_I(inode);
P9_DPRINTK(P9_DEBUG_FSC, "inode %p pages %u", inode, *nr_pages); P9_DPRINTK(P9_DEBUG_FSC, "inode %p pages %u", inode, *nr_pages);
if (!vcookie->fscache) if (!v9inode->fscache)
return -ENOBUFS; return -ENOBUFS;
ret = fscache_read_or_alloc_pages(vcookie->fscache, ret = fscache_read_or_alloc_pages(v9inode->fscache,
mapping, pages, nr_pages, mapping, pages, nr_pages,
v9fs_vfs_readpage_complete, v9fs_vfs_readpage_complete,
NULL, NULL,
...@@ -453,10 +396,10 @@ int __v9fs_readpages_from_fscache(struct inode *inode, ...@@ -453,10 +396,10 @@ int __v9fs_readpages_from_fscache(struct inode *inode,
void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page) void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
{ {
int ret; int ret;
const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); const struct v9fs_inode *v9inode = V9FS_I(inode);
P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page); P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page);
ret = fscache_write_page(vcookie->fscache, page, GFP_KERNEL); ret = fscache_write_page(v9inode->fscache, page, GFP_KERNEL);
P9_DPRINTK(P9_DEBUG_FSC, "ret = %d", ret); P9_DPRINTK(P9_DEBUG_FSC, "ret = %d", ret);
if (ret != 0) if (ret != 0)
v9fs_uncache_page(inode, page); v9fs_uncache_page(inode, page);
...@@ -467,8 +410,8 @@ void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page) ...@@ -467,8 +410,8 @@ void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
*/ */
void __v9fs_fscache_wait_on_page_write(struct inode *inode, struct page *page) void __v9fs_fscache_wait_on_page_write(struct inode *inode, struct page *page)
{ {
const struct v9fs_cookie *vcookie = v9fs_inode2cookie(inode); const struct v9fs_inode *v9inode = V9FS_I(inode);
P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page); P9_DPRINTK(P9_DEBUG_FSC, "inode %p page %p", inode, page);
if (PageFsCache(page)) if (PageFsCache(page))
fscache_wait_on_page_write(vcookie->fscache, page); fscache_wait_on_page_write(v9inode->fscache, page);
} }
...@@ -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