402cb8dda9
Attach copies of the index key and auxiliary data to the fscache cookie so that: (1) The callbacks to the netfs for this stuff can be eliminated. This can simplify things in the cache as the information is still available, even after the cache has relinquished the cookie. (2) Simplifies the locking requirements of accessing the information as we don't have to worry about the netfs object going away on us. (3) The cache can do lazy updating of the coherency information on disk. As long as the cache is flushed before reboot/poweroff, there's no need to update the coherency info on disk every time it changes. (4) Cookies can be hashed or put in a tree as the index key is easily available. This allows: (a) Checks for duplicate cookies can be made at the top fscache layer rather than down in the bowels of the cache backend. (b) Caching can be added to a netfs object that has a cookie if the cache is brought online after the netfs object is allocated. A certain amount of space is made in the cookie for inline copies of the data, but if it won't fit there, extra memory will be allocated for it. The downside of this is that live cache operation requires more memory. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Anna Schumaker <anna.schumaker@netapp.com> Tested-by: Steve Dickson <steved@redhat.com>
89 lines
2.4 KiB
C
89 lines
2.4 KiB
C
/* AFS caching stuff
|
|
*
|
|
* Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*/
|
|
|
|
#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);
|
|
|
|
struct fscache_netfs afs_cache_netfs = {
|
|
.name = "afs",
|
|
.version = 2,
|
|
};
|
|
|
|
struct fscache_cookie_def afs_cell_cache_index_def = {
|
|
.name = "AFS.cell",
|
|
.type = FSCACHE_COOKIE_TYPE_INDEX,
|
|
};
|
|
|
|
struct fscache_cookie_def afs_volume_cache_index_def = {
|
|
.name = "AFS.volume",
|
|
.type = FSCACHE_COOKIE_TYPE_INDEX,
|
|
};
|
|
|
|
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)
|
|
{
|
|
struct afs_vnode *vnode = cookie_netfs_data;
|
|
struct afs_vnode_cache_aux aux;
|
|
|
|
_enter("{%x,%x,%llx},%p,%u",
|
|
vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
|
|
buffer, buflen);
|
|
|
|
memcpy(&aux, buffer, sizeof(aux));
|
|
|
|
/* check the size of the data is what we're expecting */
|
|
if (buflen != sizeof(aux)) {
|
|
_leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux));
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
}
|
|
|
|
if (vnode->status.data_version != aux.data_version) {
|
|
_leave(" = OBSOLETE [vers %llx != %llx]",
|
|
aux.data_version, vnode->status.data_version);
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
}
|
|
|
|
_leave(" = SUCCESS");
|
|
return FSCACHE_CHECKAUX_OKAY;
|
|
}
|