Release 4.18 fs/9p/cache.c
/*
* V9FS cache definitions.
*
* Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
* Free Software Foundation
* 51 Franklin Street, Fifth Floor
* Boston, MA 02111-1301 USA
*
*/
#include <linux/jiffies.h>
#include <linux/file.h>
#include <linux/slab.h>
#include <linux/stat.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <net/9p/9p.h>
#include "v9fs.h"
#include "cache.h"
#define CACHETAG_LEN 11
struct fscache_netfs v9fs_cache_netfs = {
.name = "9p",
.version = 0,
};
/**
* v9fs_random_cachetag - Generate a random tag to be associated
* with a new cache session.
*
* The value of jiffies is used for a fairly randomly cache tag.
*/
static
int v9fs_random_cachetag(struct v9fs_session_info *v9ses)
{
v9ses->cachetag = kmalloc(CACHETAG_LEN, GFP_KERNEL);
if (!v9ses->cachetag)
return -ENOMEM;
return scnprintf(v9ses->cachetag, CACHETAG_LEN, "%lu", jiffies);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 47 | 100.00% | 1 | 100.00% |
Total | 47 | 100.00% | 1 | 100.00% |
const struct fscache_cookie_def v9fs_cache_session_index_def = {
.name = "9P.session",
.type = FSCACHE_COOKIE_TYPE_INDEX,
};
void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
{
/* If no cache session tag was specified, we generate a random one. */
if (!v9ses->cachetag) {
if (v9fs_random_cachetag(v9ses) < 0) {
v9ses->fscache = NULL;
return;
}
}
v9ses->fscache = fscache_acquire_cookie(v9fs_cache_netfs.primary_index,
&v9fs_cache_session_index_def,
v9ses->cachetag,
strlen(v9ses->cachetag),
NULL, 0,
v9ses, 0, true);
p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n",
v9ses, v9ses->fscache);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 50 | 58.14% | 1 | 20.00% |
David Howells | 34 | 39.53% | 3 | 60.00% |
Joe Perches | 2 | 2.33% | 1 | 20.00% |
Total | 86 | 100.00% | 5 | 100.00% |
void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses)
{
p9_debug(P9_DEBUG_FSC, "session %p put cookie %p\n",
v9ses, v9ses->fscache);
fscache_relinquish_cookie(v9ses->fscache, NULL, false);
v9ses->fscache = NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 35 | 87.50% | 1 | 33.33% |
David Howells | 3 | 7.50% | 1 | 33.33% |
Joe Perches | 2 | 5.00% | 1 | 33.33% |
Total | 40 | 100.00% | 3 | 100.00% |
static enum
fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
const void *buffer,
uint16_t buflen,
loff_t object_size)
{
const struct v9fs_inode *v9inode = cookie_netfs_data;
if (buflen != sizeof(v9inode->qid.version))
return FSCACHE_CHECKAUX_OBSOLETE;
if (memcmp(buffer, &v9inode->qid.version,
sizeof(v9inode->qid.version)))
return FSCACHE_CHECKAUX_OBSOLETE;
return FSCACHE_CHECKAUX_OKAY;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 61 | 81.33% | 1 | 25.00% |
Aneesh Kumar K.V | 11 | 14.67% | 2 | 50.00% |
David Howells | 3 | 4.00% | 1 | 25.00% |
Total | 75 | 100.00% | 4 | 100.00% |
const struct fscache_cookie_def v9fs_cache_inode_index_def = {
.name = "9p.inode",
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
.check_aux = v9fs_cache_inode_check_aux,
};
void v9fs_cache_inode_get_cookie(struct inode *inode)
{
struct v9fs_inode *v9inode;
struct v9fs_session_info *v9ses;
if (!S_ISREG(inode->i_mode))
return;
v9inode = V9FS_I(inode);
if (v9inode->fscache)
return;
v9ses = v9fs_inode2v9ses(inode);
v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
&v9fs_cache_inode_index_def,
&v9inode->qid.path,
sizeof(v9inode->qid.path),
&v9inode->qid.version,
sizeof(v9inode->qid.version),
v9inode,
i_size_read(&v9inode->vfs_inode),
true);
p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
inode, v9inode->fscache);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 71 | 57.72% | 1 | 16.67% |
David Howells | 42 | 34.15% | 3 | 50.00% |
Aneesh Kumar K.V | 8 | 6.50% | 1 | 16.67% |
Joe Perches | 2 | 1.63% | 1 | 16.67% |
Total | 123 | 100.00% | 6 | 100.00% |
void v9fs_cache_inode_put_cookie(struct inode *inode)
{
struct v9fs_inode *v9inode = V9FS_I(inode);
if (!v9inode->fscache)
return;
p9_debug(P9_DEBUG_FSC, "inode %p put cookie %p\n",
inode, v9inode->fscache);
fscache_relinquish_cookie(v9inode->fscache, &v9inode->qid.version,
false);
v9inode->fscache = NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 46 | 73.02% | 1 | 25.00% |
David Howells | 8 | 12.70% | 1 | 25.00% |
Aneesh Kumar K.V | 7 | 11.11% | 1 | 25.00% |
Joe Perches | 2 | 3.17% | 1 | 25.00% |
Total | 63 | 100.00% | 4 | 100.00% |
void v9fs_cache_inode_flush_cookie(struct inode *inode)
{
struct v9fs_inode *v9inode = V9FS_I(inode);
if (!v9inode->fscache)
return;
p9_debug(P9_DEBUG_FSC, "inode %p flush cookie %p\n",
inode, v9inode->fscache);
fscache_relinquish_cookie(v9inode->fscache, NULL, true);
v9inode->fscache = NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 46 | 79.31% | 1 | 25.00% |
Aneesh Kumar K.V | 7 | 12.07% | 1 | 25.00% |
David Howells | 3 | 5.17% | 1 | 25.00% |
Joe Perches | 2 | 3.45% | 1 | 25.00% |
Total | 58 | 100.00% | 4 | 100.00% |
void v9fs_cache_inode_set_cookie(struct inode *inode, struct file *filp)
{
struct v9fs_inode *v9inode = V9FS_I(inode);
if (!v9inode->fscache)
return;
mutex_lock(&v9inode->fscache_lock);
if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
v9fs_cache_inode_flush_cookie(inode);
else
v9fs_cache_inode_get_cookie(inode);
mutex_unlock(&v9inode->fscache_lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 62 | 86.11% | 1 | 33.33% |
Aneesh Kumar K.V | 8 | 11.11% | 1 | 33.33% |
Sasha Levin | 2 | 2.78% | 1 | 33.33% |
Total | 72 | 100.00% | 3 | 100.00% |
void v9fs_cache_inode_reset_cookie(struct inode *inode)
{
struct v9fs_inode *v9inode = V9FS_I(inode);
struct v9fs_session_info *v9ses;
struct fscache_cookie *old;
if (!v9inode->fscache)
return;
old = v9inode->fscache;
mutex_lock(&v9inode->fscache_lock);
fscache_relinquish_cookie(v9inode->fscache, NULL, true);
v9ses = v9fs_inode2v9ses(inode);
v9inode->fscache = fscache_acquire_cookie(v9ses->fscache,
&v9fs_cache_inode_index_def,
&v9inode->qid.path,
sizeof(v9inode->qid.path),
&v9inode->qid.version,
sizeof(v9inode->qid.version),
v9inode,
i_size_read(&v9inode->vfs_inode),
true);
p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n",
inode, old, v9inode->fscache);
mutex_unlock(&v9inode->fscache_lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 89 | 58.94% | 1 | 14.29% |
David Howells | 45 | 29.80% | 3 | 42.86% |
Aneesh Kumar K.V | 13 | 8.61% | 1 | 14.29% |
Sasha Levin | 2 | 1.32% | 1 | 14.29% |
Joe Perches | 2 | 1.32% | 1 | 14.29% |
Total | 151 | 100.00% | 7 | 100.00% |
int __v9fs_fscache_release_page(struct page *page, gfp_t gfp)
{
struct inode *inode = page->mapping->host;
struct v9fs_inode *v9inode = V9FS_I(inode);
BUG_ON(!v9inode->fscache);
return fscache_maybe_release_page(v9inode->fscache, page, gfp);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 46 | 85.19% | 1 | 25.00% |
Aneesh Kumar K.V | 5 | 9.26% | 1 | 25.00% |
David Howells | 3 | 5.56% | 2 | 50.00% |
Total | 54 | 100.00% | 4 | 100.00% |
void __v9fs_fscache_invalidate_page(struct page *page)
{
struct inode *inode = page->mapping->host;
struct v9fs_inode *v9inode = V9FS_I(inode);
BUG_ON(!v9inode->fscache);
if (PageFsCache(page)) {
fscache_wait_on_page_write(v9inode->fscache, page);
BUG_ON(!PageLocked(page));
fscache_uncache_page(v9inode->fscache, page);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 69 | 92.00% | 1 | 50.00% |
Aneesh Kumar K.V | 6 | 8.00% | 1 | 50.00% |
Total | 75 | 100.00% | 2 | 100.00% |
static void v9fs_vfs_readpage_complete(struct page *page, void *data,
int error)
{
if (!error)
SetPageUptodate(page);
unlock_page(page);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 33 | 100.00% | 1 | 100.00% |
Total | 33 | 100.00% | 1 | 100.00% |
/**
* __v9fs_readpage_from_fscache - read a page from cache
*
* Returns 0 if the pages are in cache and a BIO is submitted,
* 1 if the pages are not in cache and -error otherwise.
*/
int __v9fs_readpage_from_fscache(struct inode *inode, struct page *page)
{
int ret;
const struct v9fs_inode *v9inode = V9FS_I(inode);
p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
if (!v9inode->fscache)
return -ENOBUFS;
ret = fscache_read_or_alloc_page(v9inode->fscache,
page,
v9fs_vfs_readpage_complete,
NULL,
GFP_KERNEL);
switch (ret) {
case -ENOBUFS:
case -ENODATA:
p9_debug(P9_DEBUG_FSC, "page/inode not in cache %d\n", ret);
return 1;
case 0:
p9_debug(P9_DEBUG_FSC, "BIO submitted\n");
return ret;
default:
p9_debug(P9_DEBUG_FSC, "ret %d\n", ret);
return ret;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 107 | 89.17% | 1 | 33.33% |
Joe Perches | 8 | 6.67% | 1 | 33.33% |
Aneesh Kumar K.V | 5 | 4.17% | 1 | 33.33% |
Total | 120 | 100.00% | 3 | 100.00% |
/**
* __v9fs_readpages_from_fscache - read multiple pages from cache
*
* Returns 0 if the pages are in cache and a BIO is submitted,
* 1 if the pages are not in cache and -error otherwise.
*/
int __v9fs_readpages_from_fscache(struct inode *inode,
struct address_space *mapping,
struct list_head *pages,
unsigned *nr_pages)
{
int ret;
const struct v9fs_inode *v9inode = V9FS_I(inode);
p9_debug(P9_DEBUG_FSC, "inode %p pages %u\n", inode, *nr_pages);
if (!v9inode->fscache)
return -ENOBUFS;
ret = fscache_read_or_alloc_pages(v9inode->fscache,
mapping, pages, nr_pages,
v9fs_vfs_readpage_complete,
NULL,
mapping_gfp_mask(mapping));
switch (ret) {
case -ENOBUFS:
case -ENODATA:
p9_debug(P9_DEBUG_FSC, "pages/inodes not in cache %d\n", ret);
return 1;
case 0:
BUG_ON(!list_empty(pages));
BUG_ON(*nr_pages != 0);
p9_debug(P9_DEBUG_FSC, "BIO submitted\n");
return ret;
default:
p9_debug(P9_DEBUG_FSC, "ret %d\n", ret);
return ret;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 141 | 91.56% | 1 | 33.33% |
Joe Perches | 8 | 5.19% | 1 | 33.33% |
Aneesh Kumar K.V | 5 | 3.25% | 1 | 33.33% |
Total | 154 | 100.00% | 3 | 100.00% |
/**
* __v9fs_readpage_to_fscache - write a page to the cache
*
*/
void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
{
int ret;
const struct v9fs_inode *v9inode = V9FS_I(inode);
p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
ret = fscache_write_page(v9inode->fscache, page,
i_size_read(&v9inode->vfs_inode), GFP_KERNEL);
p9_debug(P9_DEBUG_FSC, "ret = %d\n", ret);
if (ret != 0)
v9fs_uncache_page(inode, page);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 67 | 80.72% | 1 | 25.00% |
David Howells | 8 | 9.64% | 1 | 25.00% |
Joe Perches | 4 | 4.82% | 1 | 25.00% |
Aneesh Kumar K.V | 4 | 4.82% | 1 | 25.00% |
Total | 83 | 100.00% | 4 | 100.00% |
/*
* wait for a page to complete writing to the cache
*/
void __v9fs_fscache_wait_on_page_write(struct inode *inode, struct page *page)
{
const struct v9fs_inode *v9inode = V9FS_I(inode);
p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
if (PageFsCache(page))
fscache_wait_on_page_write(v9inode->fscache, page);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Aneesh Kumar K.V | 51 | 96.23% | 2 | 66.67% |
Joe Perches | 2 | 3.77% | 1 | 33.33% |
Total | 53 | 100.00% | 3 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Kulkarni | 1058 | 76.72% | 1 | 8.33% |
David Howells | 149 | 10.80% | 5 | 41.67% |
Aneesh Kumar K.V | 131 | 9.50% | 3 | 25.00% |
Joe Perches | 34 | 2.47% | 1 | 8.33% |
Sasha Levin | 4 | 0.29% | 1 | 8.33% |
Tejun Heo | 3 | 0.22% | 1 | 8.33% |
Total | 1379 | 100.00% | 12 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.