Skip to content

Commit

Permalink
fscache: Pass object size in rather than calling back for it
Browse files Browse the repository at this point in the history
Pass the object size in to fscache_acquire_cookie() and
fscache_write_page() rather than the netfs providing a callback by which it
can be received.  This makes it easier to update the size of the object
when a new page is written that extends the object.

The current object size is also passed by fscache to the check_aux
function, obviating the need to store it in the aux data.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Anna Schumaker <anna.schumaker@netapp.com>
Tested-by: Steve Dickson <steved@redhat.com>
  • Loading branch information
dhowells committed Apr 6, 2018
1 parent 402cb8d commit ee1235a
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 166 deletions.
61 changes: 31 additions & 30 deletions Documentation/filesystems/caching/netfs-api.txt
Expand Up @@ -129,12 +129,10 @@ To define an object, a structure of the following type should be filled out:
const void *parent_netfs_data,
const void *cookie_netfs_data);

void (*get_attr)(const void *cookie_netfs_data,
uint64_t *size);

enum fscache_checkaux (*check_aux)(void *cookie_netfs_data,
const void *data,
uint16_t datalen);
uint16_t datalen,
loff_t object_size);

void (*get_context)(void *cookie_netfs_data, void *context);

Expand Down Expand Up @@ -179,16 +177,7 @@ This has the following fields:
cache in the parent's list will be chosen, or failing that, the first
cache in the master list.

(4) A function to retrieve attribute data from the netfs [optional].

This function will be called with the netfs data that was passed to the
cookie acquisition function. It should return the size of the file if
this is a data file. The size may be used to govern how much cache must
be reserved for this file in the cache.

If the function is absent, a file size of 0 is assumed.

(5) A function to check the auxiliary data [optional].
(4) A function to check the auxiliary data [optional].

This function will be called to check that a match found in the cache for
this object is valid. For instance with AFS it could check the auxiliary
Expand All @@ -198,6 +187,9 @@ This has the following fields:
If this function is absent, it will be assumed that matching objects in a
cache are always valid.

The function is also passed the cache's idea of the object size and may
use this to manage coherency also.

If present, the function should return one of the following values:

(*) FSCACHE_CHECKAUX_OKAY - the entry is okay as is
Expand All @@ -207,7 +199,7 @@ This has the following fields:
This function can also be used to extract data from the auxiliary data in
the cache and copy it into the netfs's structures.

(6) A pair of functions to manage contexts for the completion callback
(5) A pair of functions to manage contexts for the completion callback
[optional].

The cache read/write functions are passed a context which is then passed
Expand All @@ -221,7 +213,7 @@ This has the following fields:
required for indices as indices may not contain data. These functions may
be called in interrupt context and so may not sleep.

(7) A function to mark a page as retaining cache metadata [optional].
(6) A function to mark a page as retaining cache metadata [optional].

This is called by the cache to indicate that it is retaining in-memory
information for this page and that the netfs should uncache the page when
Expand All @@ -233,7 +225,7 @@ This has the following fields:

This function is not required for indices as they're not permitted data.

(8) A function to unmark all the pages retaining cache metadata [mandatory].
(7) A function to unmark all the pages retaining cache metadata [mandatory].

This is called by FS-Cache to indicate that a backing store is being
unbound from a cookie and that all the marks on the pages should be
Expand Down Expand Up @@ -310,6 +302,7 @@ the path to the file:
const void *aux_data,
size_t aux_data_len,
void *netfs_data,
loff_t object_size,
bool enable);

This function creates an index entry in the index represented by parent,
Expand All @@ -326,6 +319,10 @@ The netfs may pass an arbitrary value in netfs_data and this will be presented
to it in the event of any calling back. This may also be used in tracing or
logging of messages.

The cache tracks the size of the data attached to an object and this set to be
object_size. For indices, this should be 0. This value will be passed to the
->check_aux() callback.

Note that this function never returns an error - all errors are handled
internally. It may, however, return NULL to indicate no cookie. It is quite
acceptable to pass this token back to this function as the parent to another
Expand All @@ -349,7 +346,7 @@ entry would have a dependent inode containing volume mappings within this cell:
&afs_cell_cache_index_def,
cell->name, strlen(cell->name),
NULL, 0,
cell, true);
cell, 0, true);

And then a particular volume could be added to that index by ID, creating
another index for vnodes (AFS inode equivalents):
Expand All @@ -359,7 +356,7 @@ another index for vnodes (AFS inode equivalents):
&afs_volume_cache_index_def,
&volume->vid, sizeof(volume->vid),
NULL, 0,
volume, true);
volume, 0, true);


======================
Expand All @@ -375,7 +372,7 @@ the object definition should be something other than index type.
&afs_vnode_cache_object_def,
&key, sizeof(key),
&aux, sizeof(aux),
vnode, true);
vnode, vnode->status.size, true);


=================================
Expand All @@ -393,7 +390,7 @@ it would be some other type of object such as a data file.
&afs_xattr_cache_object_def,
&xattr->name, strlen(xattr->name),
NULL, 0,
xattr, true);
xattr, strlen(xattr->val), true);

Miscellaneous objects might be used to store extended attributes or directory
entries for example.
Expand All @@ -410,8 +407,7 @@ cache to adjust its metadata for data tracking appropriately:
int fscache_attr_changed(struct fscache_cookie *cookie);

The cache will return -ENOBUFS if there is no backing cache or if there is no
space to allocate any extra metadata required in the cache. The attributes
will be accessed with the get_attr() cookie definition operation.
space to allocate any extra metadata required in the cache.

Note that attempts to read or write data pages in the cache over this size may
be rebuffed with -ENOBUFS.
Expand Down Expand Up @@ -536,12 +532,13 @@ written back to the cache:

int fscache_write_page(struct fscache_cookie *cookie,
struct page *page,
loff_t object_size,
gfp_t gfp);

The cookie argument must specify a data file cookie, the page specified should
contain the data to be written (and is also used to specify the page number),
and the gfp argument is used to control how any memory allocations made are
satisfied.
object_size is the revised size of the object and the gfp argument is used to
control how any memory allocations made are satisfied.

The page must have first been read or allocated successfully and must not have
been uncached before writing is performed.
Expand Down Expand Up @@ -735,11 +732,11 @@ still possible to uncache pages and relinquish the cookie.

The initial enablement state is set by fscache_acquire_cookie(), but the cookie
can be enabled or disabled later. To disable a cookie, call:

void fscache_disable_cookie(struct fscache_cookie *cookie,
const void *aux_data,
bool invalidate);

If the cookie is not already disabled, this locks the cookie against other
enable and disable ops, marks the cookie as being disabled, discards or
invalidates any backing objects and waits for cessation of activity on any
Expand All @@ -748,14 +745,15 @@ associated object before unlocking the cookie.
All possible failures are handled internally. The caller should consider
calling fscache_uncache_all_inode_pages() afterwards to make sure all page
markings are cleared up.

Cookies can be enabled or reenabled with:

void fscache_enable_cookie(struct fscache_cookie *cookie,
const void *aux_data,
loff_t object_size,
bool (*can_enable)(void *data),
void *data)

If the cookie is not already enabled, this locks the cookie against other
enable and disable ops, invokes can_enable() and, if the cookie is not an index
cookie, will begin the procedure of acquiring backing objects.
Expand All @@ -766,6 +764,9 @@ ruling as to whether or not enablement should actually be permitted to begin.
All possible failures are handled internally. The cookie will only be marked
as enabled if provisional backing objects are allocated.

The object's data size is updated from object_size and is passed to the
->check_aux() function.

In both cases, the cookie's auxiliary data buffer is updated from aux_data if
that is non-NULL inside the enablement lock before proceeding.

Expand Down
27 changes: 11 additions & 16 deletions fs/9p/cache.c
Expand Up @@ -75,7 +75,7 @@ void v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses)
v9ses->cachetag,
strlen(v9ses->cachetag),
NULL, 0,
v9ses, true);
v9ses, 0, true);
p9_debug(P9_DEBUG_FSC, "session %p get cookie %p\n",
v9ses, v9ses->fscache);
}
Expand All @@ -88,20 +88,11 @@ void v9fs_cache_session_put_cookie(struct v9fs_session_info *v9ses)
v9ses->fscache = NULL;
}

static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data,
uint64_t *size)
{
const struct v9fs_inode *v9inode = cookie_netfs_data;
*size = i_size_read(&v9inode->vfs_inode);

p9_debug(P9_DEBUG_FSC, "inode %p get attr %llu\n",
&v9inode->vfs_inode, *size);
}

static enum
fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
const void *buffer,
uint16_t buflen)
uint16_t buflen,
loff_t object_size)
{
const struct v9fs_inode *v9inode = cookie_netfs_data;

Expand All @@ -118,7 +109,6 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
const struct fscache_cookie_def v9fs_cache_inode_index_def = {
.name = "9p.inode",
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
.get_attr = v9fs_cache_inode_get_attr,
.check_aux = v9fs_cache_inode_check_aux,
};

Expand All @@ -141,7 +131,9 @@ void v9fs_cache_inode_get_cookie(struct inode *inode)
sizeof(v9inode->qid.path),
&v9inode->qid.version,
sizeof(v9inode->qid.version),
v9inode, true);
v9inode,
i_size_read(&v9inode->vfs_inode),
true);

p9_debug(P9_DEBUG_FSC, "inode %p get cookie %p\n",
inode, v9inode->fscache);
Expand Down Expand Up @@ -212,7 +204,9 @@ void v9fs_cache_inode_reset_cookie(struct inode *inode)
sizeof(v9inode->qid.path),
&v9inode->qid.version,
sizeof(v9inode->qid.version),
v9inode, true);
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);

Expand Down Expand Up @@ -338,7 +332,8 @@ void __v9fs_readpage_to_fscache(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);
ret = fscache_write_page(v9inode->fscache, page, GFP_KERNEL);
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);
Expand Down
24 changes: 4 additions & 20 deletions fs/afs/cache.c
Expand Up @@ -12,11 +12,10 @@
#include <linux/sched.h>
#include "internal.h"

static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
uint64_t *size);
static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
const void *buffer,
uint16_t buflen);
uint16_t buflen,
loff_t object_size);

struct fscache_netfs afs_cache_netfs = {
.name = "afs",
Expand All @@ -36,31 +35,16 @@ struct fscache_cookie_def afs_volume_cache_index_def = {
struct fscache_cookie_def afs_vnode_cache_index_def = {
.name = "AFS.vnode",
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
.get_attr = afs_vnode_cache_get_attr,
.check_aux = afs_vnode_cache_check_aux,
};

/*
* provide updated file attributes
*/
static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
uint64_t *size)
{
const struct afs_vnode *vnode = cookie_netfs_data;

_enter("{%x,%x,%llx},",
vnode->fid.vnode, vnode->fid.unique,
vnode->status.data_version);

*size = vnode->status.size;
}

/*
* check that the auxiliary data indicates that the entry is still valid
*/
static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
const void *buffer,
uint16_t buflen)
uint16_t buflen,
loff_t object_size)
{
struct afs_vnode *vnode = cookie_netfs_data;
struct afs_vnode_cache_aux aux;
Expand Down
2 changes: 1 addition & 1 deletion fs/afs/cell.c
Expand Up @@ -524,7 +524,7 @@ static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell)
&afs_cell_cache_index_def,
cell->name, strlen(cell->name),
NULL, 0,
cell, true);
cell, 0, true);
#endif
ret = afs_proc_cell_setup(net, cell);
if (ret < 0)
Expand Down
6 changes: 4 additions & 2 deletions fs/afs/file.c
Expand Up @@ -339,7 +339,8 @@ int afs_page_filler(void *data, struct page *page)
/* send the page to the cache */
#ifdef CONFIG_AFS_FSCACHE
if (PageFsCache(page) &&
fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
fscache_write_page(vnode->cache, page, vnode->status.size,
GFP_KERNEL) != 0) {
fscache_uncache_page(vnode->cache, page);
BUG_ON(PageFsCache(page));
}
Expand Down Expand Up @@ -403,7 +404,8 @@ static void afs_readpages_page_done(struct afs_call *call, struct afs_read *req)
/* send the page to the cache */
#ifdef CONFIG_AFS_FSCACHE
if (PageFsCache(page) &&
fscache_write_page(vnode->cache, page, GFP_KERNEL) != 0) {
fscache_write_page(vnode->cache, page, vnode->status.size,
GFP_KERNEL) != 0) {
fscache_uncache_page(vnode->cache, page);
BUG_ON(PageFsCache(page));
}
Expand Down
2 changes: 1 addition & 1 deletion fs/afs/inode.c
Expand Up @@ -265,7 +265,7 @@ static void afs_get_inode_cache(struct afs_vnode *vnode)
&afs_vnode_cache_index_def,
&key, sizeof(key),
&aux, sizeof(aux),
vnode, true);
vnode, vnode->status.size, true);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion fs/afs/volume.c
Expand Up @@ -227,7 +227,7 @@ void afs_activate_volume(struct afs_volume *volume)
&afs_volume_cache_index_def,
&volume->vid, sizeof(volume->vid),
NULL, 0,
volume, true);
volume, 0, true);
#endif

write_lock(&volume->cell->proc_lock);
Expand Down
5 changes: 2 additions & 3 deletions fs/cachefiles/interface.c
Expand Up @@ -441,7 +441,7 @@ static int cachefiles_attr_changed(struct fscache_object *_object)
loff_t oi_size;
int ret;

_object->cookie->def->get_attr(_object->cookie->netfs_data, &ni_size);
ni_size = _object->store_limit_l;

_enter("{OBJ%x},[%llu]",
_object->debug_id, (unsigned long long) ni_size);
Expand Down Expand Up @@ -513,8 +513,7 @@ static void cachefiles_invalidate_object(struct fscache_operation *op)
cache = container_of(object->fscache.cache,
struct cachefiles_cache, cache);

op->object->cookie->def->get_attr(op->object->cookie->netfs_data,
&ni_size);
ni_size = op->object->store_limit_l;

_enter("{OBJ%x},[%llu]",
op->object->debug_id, (unsigned long long)ni_size);
Expand Down
6 changes: 4 additions & 2 deletions fs/cachefiles/xattr.c
Expand Up @@ -182,7 +182,8 @@ int cachefiles_check_auxdata(struct cachefiles_object *object)
goto error;

xlen--;
validity = fscache_check_aux(&object->fscache, &auxbuf->data, xlen);
validity = fscache_check_aux(&object->fscache, &auxbuf->data, xlen,
i_size_read(d_backing_inode(dentry)));
if (validity != FSCACHE_CHECKAUX_OKAY)
goto error;

Expand Down Expand Up @@ -251,7 +252,8 @@ int cachefiles_check_object_xattr(struct cachefiles_object *object,
object->fscache.cookie->def->name, dlen);

result = fscache_check_aux(&object->fscache,
&auxbuf->data, dlen);
&auxbuf->data, dlen,
i_size_read(d_backing_inode(dentry)));

switch (result) {
/* entry okay as is */
Expand Down

0 comments on commit ee1235a

Please sign in to comment.