Commit ad6a942a authored by David Howells's avatar David Howells

afs: Update the cache index structure

Update the cache index structure in the following ways:

 (1) Don't use the volume name followed by the volume type as levels in the
     cache index.  Volumes can be renamed.  Use the volume ID instead.

 (2) Don't store the VLDB data for a volume in the tree.  If the volume
     database should be cached locally, then it should be done in a separate
     tree.

 (3) Expand the volume ID stored in the cache to 64 bits.

 (4) Expand the file/vnode ID stored in the cache to 96 bits.

 (5) Increment the cache structure version number to 1.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 91a90380
...@@ -14,19 +14,6 @@ ...@@ -14,19 +14,6 @@
static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data, static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t buflen); void *buffer, uint16_t buflen);
static uint16_t afs_cell_cache_get_aux(const void *cookie_netfs_data,
void *buffer, uint16_t buflen);
static enum fscache_checkaux afs_cell_cache_check_aux(void *cookie_netfs_data,
const void *buffer,
uint16_t buflen);
static uint16_t afs_vlocation_cache_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t buflen);
static uint16_t afs_vlocation_cache_get_aux(const void *cookie_netfs_data,
void *buffer, uint16_t buflen);
static enum fscache_checkaux afs_vlocation_cache_check_aux(
void *cookie_netfs_data, const void *buffer, uint16_t buflen);
static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data, static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t buflen); void *buffer, uint16_t buflen);
...@@ -42,23 +29,13 @@ static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data, ...@@ -42,23 +29,13 @@ static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
struct fscache_netfs afs_cache_netfs = { struct fscache_netfs afs_cache_netfs = {
.name = "afs", .name = "afs",
.version = 0, .version = 1,
}; };
struct fscache_cookie_def afs_cell_cache_index_def = { struct fscache_cookie_def afs_cell_cache_index_def = {
.name = "AFS.cell", .name = "AFS.cell",
.type = FSCACHE_COOKIE_TYPE_INDEX, .type = FSCACHE_COOKIE_TYPE_INDEX,
.get_key = afs_cell_cache_get_key, .get_key = afs_cell_cache_get_key,
.get_aux = afs_cell_cache_get_aux,
.check_aux = afs_cell_cache_check_aux,
};
struct fscache_cookie_def afs_vlocation_cache_index_def = {
.name = "AFS.vldb",
.type = FSCACHE_COOKIE_TYPE_INDEX,
.get_key = afs_vlocation_cache_get_key,
.get_aux = afs_vlocation_cache_get_aux,
.check_aux = afs_vlocation_cache_check_aux,
}; };
struct fscache_cookie_def afs_volume_cache_index_def = { struct fscache_cookie_def afs_volume_cache_index_def = {
...@@ -95,129 +72,6 @@ static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data, ...@@ -95,129 +72,6 @@ static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data,
return klen; return klen;
} }
/*
* provide new auxiliary cache data
*/
static uint16_t afs_cell_cache_get_aux(const void *cookie_netfs_data,
void *buffer, uint16_t bufmax)
{
const struct afs_cell *cell = cookie_netfs_data;
uint16_t dlen;
_enter("%p,%p,%u", cell, buffer, bufmax);
dlen = cell->vl_naddrs * sizeof(cell->vl_addrs[0]);
dlen = min(dlen, bufmax);
dlen &= ~(sizeof(cell->vl_addrs[0]) - 1);
memcpy(buffer, cell->vl_addrs, dlen);
return dlen;
}
/*
* check that the auxiliary data indicates that the entry is still valid
*/
static enum fscache_checkaux afs_cell_cache_check_aux(void *cookie_netfs_data,
const void *buffer,
uint16_t buflen)
{
_leave(" = OKAY");
return FSCACHE_CHECKAUX_OKAY;
}
/*****************************************************************************/
/*
* set the key for the index entry
*/
static uint16_t afs_vlocation_cache_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t bufmax)
{
const struct afs_vlocation *vlocation = cookie_netfs_data;
uint16_t klen;
_enter("{%s},%p,%u", vlocation->vldb.name, buffer, bufmax);
klen = strnlen(vlocation->vldb.name, sizeof(vlocation->vldb.name));
if (klen > bufmax)
return 0;
memcpy(buffer, vlocation->vldb.name, klen);
_leave(" = %u", klen);
return klen;
}
/*
* provide new auxiliary cache data
*/
static uint16_t afs_vlocation_cache_get_aux(const void *cookie_netfs_data,
void *buffer, uint16_t bufmax)
{
const struct afs_vlocation *vlocation = cookie_netfs_data;
uint16_t dlen;
_enter("{%s},%p,%u", vlocation->vldb.name, buffer, bufmax);
dlen = sizeof(struct afs_cache_vlocation);
dlen -= offsetof(struct afs_cache_vlocation, nservers);
if (dlen > bufmax)
return 0;
memcpy(buffer, (uint8_t *)&vlocation->vldb.nservers, dlen);
_leave(" = %u", dlen);
return dlen;
}
/*
* check that the auxiliary data indicates that the entry is still valid
*/
static
enum fscache_checkaux afs_vlocation_cache_check_aux(void *cookie_netfs_data,
const void *buffer,
uint16_t buflen)
{
const struct afs_cache_vlocation *cvldb;
struct afs_vlocation *vlocation = cookie_netfs_data;
uint16_t dlen;
_enter("{%s},%p,%u", vlocation->vldb.name, buffer, buflen);
/* check the size of the data is what we're expecting */
dlen = sizeof(struct afs_cache_vlocation);
dlen -= offsetof(struct afs_cache_vlocation, nservers);
if (dlen != buflen)
return FSCACHE_CHECKAUX_OBSOLETE;
cvldb = container_of(buffer, struct afs_cache_vlocation, nservers);
/* if what's on disk is more valid than what's in memory, then use the
* VL record from the cache */
if (!vlocation->valid || vlocation->vldb.rtime == cvldb->rtime) {
memcpy((uint8_t *)&vlocation->vldb.nservers, buffer, dlen);
vlocation->valid = 1;
_leave(" = SUCCESS [c->m]");
return FSCACHE_CHECKAUX_OKAY;
}
/* need to update the cache if the cached info differs */
if (memcmp(&vlocation->vldb, buffer, dlen) != 0) {
/* delete if the volume IDs for this name differ */
if (memcmp(&vlocation->vldb.vid, &cvldb->vid,
sizeof(cvldb->vid)) != 0
) {
_leave(" = OBSOLETE");
return FSCACHE_CHECKAUX_OBSOLETE;
}
_leave(" = UPDATE");
return FSCACHE_CHECKAUX_NEEDS_UPDATE;
}
_leave(" = OKAY");
return FSCACHE_CHECKAUX_OKAY;
}
/*****************************************************************************/ /*****************************************************************************/
/* /*
* set the key for the volume index entry * set the key for the volume index entry
...@@ -226,19 +80,18 @@ static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data, ...@@ -226,19 +80,18 @@ static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t bufmax) void *buffer, uint16_t bufmax)
{ {
const struct afs_volume *volume = cookie_netfs_data; const struct afs_volume *volume = cookie_netfs_data;
uint16_t klen; struct {
u64 volid;
} __packed key;
_enter("{%u},%p,%u", volume->type, buffer, bufmax); _enter("{%u},%p,%u", volume->type, buffer, bufmax);
klen = sizeof(volume->type); if (bufmax < sizeof(key))
if (klen > bufmax)
return 0; return 0;
memcpy(buffer, &volume->type, sizeof(volume->type)); key.volid = volume->vid;
memcpy(buffer, &key, sizeof(key));
_leave(" = %u", klen); return sizeof(key);
return klen;
} }
/*****************************************************************************/ /*****************************************************************************/
...@@ -249,20 +102,25 @@ static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data, ...@@ -249,20 +102,25 @@ static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data,
void *buffer, uint16_t bufmax) void *buffer, uint16_t bufmax)
{ {
const struct afs_vnode *vnode = cookie_netfs_data; const struct afs_vnode *vnode = cookie_netfs_data;
uint16_t klen; struct {
u32 vnode_id[3];
} __packed key;
_enter("{%x,%x,%llx},%p,%u", _enter("{%x,%x,%llx},%p,%u",
vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
buffer, bufmax); buffer, bufmax);
klen = sizeof(vnode->fid.vnode); /* Allow for a 96-bit key */
if (klen > bufmax) memset(&key, 0, sizeof(key));
return 0; key.vnode_id[0] = vnode->fid.vnode;
key.vnode_id[1] = 0;
key.vnode_id[2] = 0;
memcpy(buffer, &vnode->fid.vnode, sizeof(vnode->fid.vnode)); if (sizeof(key) > bufmax)
return 0;
_leave(" = %u", klen); memcpy(buffer, &key, sizeof(key));
return klen; return sizeof(key);
} }
/* /*
...@@ -280,6 +138,11 @@ static void afs_vnode_cache_get_attr(const void *cookie_netfs_data, ...@@ -280,6 +138,11 @@ static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
*size = vnode->status.size; *size = vnode->status.size;
} }
struct afs_vnode_cache_aux {
u64 data_version;
u32 fid_unique;
} __packed;
/* /*
* provide new auxiliary cache data * provide new auxiliary cache data
*/ */
...@@ -287,23 +150,21 @@ static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data, ...@@ -287,23 +150,21 @@ static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data,
void *buffer, uint16_t bufmax) void *buffer, uint16_t bufmax)
{ {
const struct afs_vnode *vnode = cookie_netfs_data; const struct afs_vnode *vnode = cookie_netfs_data;
uint16_t dlen; struct afs_vnode_cache_aux aux;
_enter("{%x,%x,%Lx},%p,%u", _enter("{%x,%x,%Lx},%p,%u",
vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
buffer, bufmax); buffer, bufmax);
dlen = sizeof(vnode->fid.unique) + sizeof(vnode->status.data_version); memset(&aux, 0, sizeof(aux));
if (dlen > bufmax) aux.data_version = vnode->status.data_version;
return 0; aux.fid_unique = vnode->fid.unique;
memcpy(buffer, &vnode->fid.unique, sizeof(vnode->fid.unique)); if (bufmax < sizeof(aux))
buffer += sizeof(vnode->fid.unique); return 0;
memcpy(buffer, &vnode->status.data_version,
sizeof(vnode->status.data_version));
_leave(" = %u", dlen); memcpy(buffer, &aux, sizeof(aux));
return dlen; return sizeof(aux);
} }
/* /*
...@@ -314,43 +175,29 @@ static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data, ...@@ -314,43 +175,29 @@ static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
uint16_t buflen) uint16_t buflen)
{ {
struct afs_vnode *vnode = cookie_netfs_data; struct afs_vnode *vnode = cookie_netfs_data;
uint16_t dlen; struct afs_vnode_cache_aux aux;
_enter("{%x,%x,%llx},%p,%u", _enter("{%x,%x,%llx},%p,%u",
vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
buffer, buflen); buffer, buflen);
memcpy(&aux, buffer, sizeof(aux));
/* check the size of the data is what we're expecting */ /* check the size of the data is what we're expecting */
dlen = sizeof(vnode->fid.unique) + sizeof(vnode->status.data_version); if (buflen != sizeof(aux)) {
if (dlen != buflen) { _leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux));
_leave(" = OBSOLETE [len %hx != %hx]", dlen, buflen);
return FSCACHE_CHECKAUX_OBSOLETE; return FSCACHE_CHECKAUX_OBSOLETE;
} }
if (memcmp(buffer, if (vnode->fid.unique != aux.fid_unique) {
&vnode->fid.unique,
sizeof(vnode->fid.unique)
) != 0) {
unsigned unique;
memcpy(&unique, buffer, sizeof(unique));
_leave(" = OBSOLETE [uniq %x != %x]", _leave(" = OBSOLETE [uniq %x != %x]",
unique, vnode->fid.unique); aux.fid_unique, vnode->fid.unique);
return FSCACHE_CHECKAUX_OBSOLETE; return FSCACHE_CHECKAUX_OBSOLETE;
} }
if (memcmp(buffer + sizeof(vnode->fid.unique), if (vnode->status.data_version != aux.data_version) {
&vnode->status.data_version,
sizeof(vnode->status.data_version)
) != 0) {
afs_dataversion_t version;
memcpy(&version, buffer + sizeof(vnode->fid.unique),
sizeof(version));
_leave(" = OBSOLETE [vers %llx != %llx]", _leave(" = OBSOLETE [vers %llx != %llx]",
version, vnode->status.data_version); aux.data_version, vnode->status.data_version);
return FSCACHE_CHECKAUX_OBSOLETE; return FSCACHE_CHECKAUX_OBSOLETE;
} }
......
...@@ -190,14 +190,6 @@ static inline struct afs_super_info *AFS_FS_S(struct super_block *sb) ...@@ -190,14 +190,6 @@ static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
extern struct file_system_type afs_fs_type; extern struct file_system_type afs_fs_type;
/*
* entry in the cached cell catalogue
*/
struct afs_cache_cell {
char name[AFS_MAXCELLNAME]; /* cell name (padded with NULs) */
struct in_addr vl_servers[15]; /* cached cell VL servers */
};
/* /*
* AFS network namespace record. * AFS network namespace record.
*/ */
...@@ -296,14 +288,6 @@ struct afs_cache_vlocation { ...@@ -296,14 +288,6 @@ struct afs_cache_vlocation {
time_t rtime; /* last retrieval time */ time_t rtime; /* last retrieval time */
}; };
/*
* volume -> vnode hash table entry
*/
struct afs_cache_vhash {
afs_voltype_t vtype; /* which volume variation */
uint8_t hash_bucket; /* which hash bucket this represents */
} __attribute__((packed));
/* /*
* AFS volume location record * AFS volume location record
*/ */
...@@ -314,9 +298,6 @@ struct afs_vlocation { ...@@ -314,9 +298,6 @@ struct afs_vlocation {
struct list_head grave; /* link in master graveyard list */ struct list_head grave; /* link in master graveyard list */
struct list_head update; /* link in master update list */ struct list_head update; /* link in master update list */
struct afs_cell *cell; /* cell to which volume belongs */ struct afs_cell *cell; /* cell to which volume belongs */
#ifdef CONFIG_AFS_FSCACHE
struct fscache_cookie *cache; /* caching cookie */
#endif
struct afs_cache_vlocation vldb; /* volume information DB record */ struct afs_cache_vlocation vldb; /* volume information DB record */
struct afs_volume *vols[3]; /* volume access record pointer (index by type) */ struct afs_volume *vols[3]; /* volume access record pointer (index by type) */
wait_queue_head_t waitq; /* status change waitqueue */ wait_queue_head_t waitq; /* status change waitqueue */
...@@ -477,12 +458,10 @@ struct afs_interface { ...@@ -477,12 +458,10 @@ struct afs_interface {
#ifdef CONFIG_AFS_FSCACHE #ifdef CONFIG_AFS_FSCACHE
extern struct fscache_netfs afs_cache_netfs; extern struct fscache_netfs afs_cache_netfs;
extern struct fscache_cookie_def afs_cell_cache_index_def; extern struct fscache_cookie_def afs_cell_cache_index_def;
extern struct fscache_cookie_def afs_vlocation_cache_index_def;
extern struct fscache_cookie_def afs_volume_cache_index_def; extern struct fscache_cookie_def afs_volume_cache_index_def;
extern struct fscache_cookie_def afs_vnode_cache_index_def; extern struct fscache_cookie_def afs_vnode_cache_index_def;
#else #else
#define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL) #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
#define afs_vlocation_cache_index_def (*(struct fscache_cookie_def *) NULL)
#define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL) #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
#define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL) #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
#endif #endif
......
...@@ -273,10 +273,6 @@ static void afs_vlocation_apply_update(struct afs_vlocation *vl, ...@@ -273,10 +273,6 @@ static void afs_vlocation_apply_update(struct afs_vlocation *vl,
vl->vldb.name, vldb->name); vl->vldb.name, vldb->name);
vl->vldb = *vldb; vl->vldb = *vldb;
#ifdef CONFIG_AFS_FSCACHE
fscache_update_cookie(vl->cache);
#endif
} }
/* /*
...@@ -295,28 +291,13 @@ static int afs_vlocation_fill_in_record(struct afs_vlocation *vl, ...@@ -295,28 +291,13 @@ static int afs_vlocation_fill_in_record(struct afs_vlocation *vl,
memset(&vldb, 0, sizeof(vldb)); memset(&vldb, 0, sizeof(vldb));
/* see if we have an in-cache copy (will set vl->valid if there is) */ /* Try to look up an unknown volume in the cell VL databases by name */
#ifdef CONFIG_AFS_FSCACHE
vl->cache = fscache_acquire_cookie(vl->cell->cache,
&afs_vlocation_cache_index_def, vl,
true);
#endif
if (vl->valid) {
/* try to update a known volume in the cell VL databases by
* ID as the name may have changed */
_debug("found in cache");
ret = afs_vlocation_update_record(vl, key, &vldb);
} else {
/* try to look up an unknown volume in the cell VL databases by
* name */
ret = afs_vlocation_access_vl_by_name(vl, key, &vldb); ret = afs_vlocation_access_vl_by_name(vl, key, &vldb);
if (ret < 0) { if (ret < 0) {
printk("kAFS: failed to locate '%s' in cell '%s'\n", printk("kAFS: failed to locate '%s' in cell '%s'\n",
vl->vldb.name, vl->cell->name); vl->vldb.name, vl->cell->name);
return ret; return ret;
} }
}
afs_vlocation_apply_update(vl, &vldb); afs_vlocation_apply_update(vl, &vldb);
_leave(" = 0"); _leave(" = 0");
...@@ -414,11 +395,6 @@ struct afs_vlocation *afs_vlocation_lookup(struct afs_net *net, ...@@ -414,11 +395,6 @@ struct afs_vlocation *afs_vlocation_lookup(struct afs_net *net,
spin_unlock(&vl->lock); spin_unlock(&vl->lock);
wake_up(&vl->waitq); wake_up(&vl->waitq);
/* update volume entry in local cache */
#ifdef CONFIG_AFS_FSCACHE
fscache_update_cookie(vl->cache);
#endif
/* schedule for regular updates */ /* schedule for regular updates */
afs_vlocation_queue_for_updates(net, vl); afs_vlocation_queue_for_updates(net, vl);
goto success; goto success;
...@@ -522,9 +498,6 @@ static void afs_vlocation_destroy(struct afs_net *net, struct afs_vlocation *vl) ...@@ -522,9 +498,6 @@ static void afs_vlocation_destroy(struct afs_net *net, struct afs_vlocation *vl)
{ {
_enter("%p", vl); _enter("%p", vl);
#ifdef CONFIG_AFS_FSCACHE
fscache_relinquish_cookie(vl->cache, 0);
#endif
afs_put_cell(net, vl->cell); afs_put_cell(net, vl->cell);
kfree(vl); kfree(vl);
} }
......
...@@ -125,7 +125,7 @@ struct afs_volume *afs_volume_lookup(struct afs_mount_params *params) ...@@ -125,7 +125,7 @@ struct afs_volume *afs_volume_lookup(struct afs_mount_params *params)
/* attach the cache and volume location */ /* attach the cache and volume location */
#ifdef CONFIG_AFS_FSCACHE #ifdef CONFIG_AFS_FSCACHE
volume->cache = fscache_acquire_cookie(vlocation->cache, volume->cache = fscache_acquire_cookie(volume->cell->cache,
&afs_volume_cache_index_def, &afs_volume_cache_index_def,
volume, true); volume, true);
#endif #endif
......
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