2007-04-26 22:55:03 +00:00
|
|
|
/* AFS caching stuff
|
|
|
|
*
|
2009-04-03 15:42:41 +00:00
|
|
|
* Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
|
2007-04-26 22:55:03 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data,
|
|
|
|
void *buffer, uint16_t buflen);
|
|
|
|
static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data,
|
|
|
|
void *buffer, uint16_t buflen);
|
|
|
|
|
|
|
|
static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data,
|
|
|
|
void *buffer, uint16_t buflen);
|
|
|
|
static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
|
|
|
|
uint64_t *size);
|
|
|
|
static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data,
|
|
|
|
void *buffer, uint16_t buflen);
|
|
|
|
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",
|
2017-11-02 15:27:47 +00:00
|
|
|
.version = 1,
|
2009-04-03 15:42:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fscache_cookie_def afs_cell_cache_index_def = {
|
|
|
|
.name = "AFS.cell",
|
|
|
|
.type = FSCACHE_COOKIE_TYPE_INDEX,
|
|
|
|
.get_key = afs_cell_cache_get_key,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fscache_cookie_def afs_volume_cache_index_def = {
|
|
|
|
.name = "AFS.volume",
|
|
|
|
.type = FSCACHE_COOKIE_TYPE_INDEX,
|
|
|
|
.get_key = afs_volume_cache_get_key,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fscache_cookie_def afs_vnode_cache_index_def = {
|
|
|
|
.name = "AFS.vnode",
|
|
|
|
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
|
|
|
|
.get_key = afs_vnode_cache_get_key,
|
|
|
|
.get_attr = afs_vnode_cache_get_attr,
|
|
|
|
.get_aux = afs_vnode_cache_get_aux,
|
|
|
|
.check_aux = afs_vnode_cache_check_aux,
|
2007-04-26 22:55:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2009-04-03 15:42:41 +00:00
|
|
|
* set the key for the index entry
|
2007-04-26 22:55:03 +00:00
|
|
|
*/
|
2009-04-03 15:42:41 +00:00
|
|
|
static uint16_t afs_cell_cache_get_key(const void *cookie_netfs_data,
|
|
|
|
void *buffer, uint16_t bufmax)
|
2007-04-26 22:55:03 +00:00
|
|
|
{
|
2009-04-03 15:42:41 +00:00
|
|
|
const struct afs_cell *cell = cookie_netfs_data;
|
|
|
|
uint16_t klen;
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
_enter("%p,%p,%u", cell, buffer, bufmax);
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
klen = strlen(cell->name);
|
|
|
|
if (klen > bufmax)
|
|
|
|
return 0;
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
memcpy(buffer, cell->name, klen);
|
|
|
|
return klen;
|
2007-04-26 22:55:03 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/*****************************************************************************/
|
2007-04-26 22:55:03 +00:00
|
|
|
/*
|
2009-04-03 15:42:41 +00:00
|
|
|
* set the key for the volume index entry
|
2007-04-26 22:55:03 +00:00
|
|
|
*/
|
2009-04-03 15:42:41 +00:00
|
|
|
static uint16_t afs_volume_cache_get_key(const void *cookie_netfs_data,
|
2017-11-02 15:27:47 +00:00
|
|
|
void *buffer, uint16_t bufmax)
|
2007-04-26 22:55:03 +00:00
|
|
|
{
|
2009-04-03 15:42:41 +00:00
|
|
|
const struct afs_volume *volume = cookie_netfs_data;
|
2017-11-02 15:27:47 +00:00
|
|
|
struct {
|
|
|
|
u64 volid;
|
|
|
|
} __packed key;
|
2009-04-03 15:42:41 +00:00
|
|
|
|
|
|
|
_enter("{%u},%p,%u", volume->type, buffer, bufmax);
|
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
if (bufmax < sizeof(key))
|
2009-04-03 15:42:41 +00:00
|
|
|
return 0;
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
key.volid = volume->vid;
|
|
|
|
memcpy(buffer, &key, sizeof(key));
|
|
|
|
return sizeof(key);
|
2007-04-26 22:55:03 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/*****************************************************************************/
|
2007-04-26 22:55:03 +00:00
|
|
|
/*
|
2009-04-03 15:42:41 +00:00
|
|
|
* set the key for the index entry
|
2007-04-26 22:55:03 +00:00
|
|
|
*/
|
2009-04-03 15:42:41 +00:00
|
|
|
static uint16_t afs_vnode_cache_get_key(const void *cookie_netfs_data,
|
|
|
|
void *buffer, uint16_t bufmax)
|
2007-04-26 22:55:03 +00:00
|
|
|
{
|
2009-04-03 15:42:41 +00:00
|
|
|
const struct afs_vnode *vnode = cookie_netfs_data;
|
2017-11-02 15:27:47 +00:00
|
|
|
struct {
|
|
|
|
u32 vnode_id[3];
|
|
|
|
} __packed key;
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
_enter("{%x,%x,%llx},%p,%u",
|
|
|
|
vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
|
|
|
|
buffer, bufmax);
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
/* Allow for a 96-bit key */
|
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
key.vnode_id[0] = vnode->fid.vnode;
|
|
|
|
key.vnode_id[1] = 0;
|
|
|
|
key.vnode_id[2] = 0;
|
2009-04-03 15:42:41 +00:00
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
if (sizeof(key) > bufmax)
|
|
|
|
return 0;
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
memcpy(buffer, &key, sizeof(key));
|
|
|
|
return sizeof(key);
|
2007-04-26 22:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-04-03 15:42:41 +00:00
|
|
|
* provide updated file attributes
|
2007-04-26 22:55:03 +00:00
|
|
|
*/
|
2009-04-03 15:42:41 +00:00
|
|
|
static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
|
|
|
|
uint64_t *size)
|
2007-04-26 22:55:03 +00:00
|
|
|
{
|
2009-04-03 15:42:41 +00:00
|
|
|
const struct afs_vnode *vnode = cookie_netfs_data;
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
_enter("{%x,%x,%llx},",
|
|
|
|
vnode->fid.vnode, vnode->fid.unique,
|
|
|
|
vnode->status.data_version);
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
*size = vnode->status.size;
|
2007-04-26 22:55:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
struct afs_vnode_cache_aux {
|
|
|
|
u64 data_version;
|
|
|
|
u32 fid_unique;
|
|
|
|
} __packed;
|
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
/*
|
2011-03-31 01:57:33 +00:00
|
|
|
* provide new auxiliary cache data
|
2009-04-03 15:42:41 +00:00
|
|
|
*/
|
|
|
|
static uint16_t afs_vnode_cache_get_aux(const void *cookie_netfs_data,
|
|
|
|
void *buffer, uint16_t bufmax)
|
|
|
|
{
|
|
|
|
const struct afs_vnode *vnode = cookie_netfs_data;
|
2017-11-02 15:27:47 +00:00
|
|
|
struct afs_vnode_cache_aux aux;
|
2009-04-03 15:42:41 +00:00
|
|
|
|
|
|
|
_enter("{%x,%x,%Lx},%p,%u",
|
|
|
|
vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
|
|
|
|
buffer, bufmax);
|
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
memset(&aux, 0, sizeof(aux));
|
|
|
|
aux.data_version = vnode->status.data_version;
|
|
|
|
aux.fid_unique = vnode->fid.unique;
|
2009-04-03 15:42:41 +00:00
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
if (bufmax < sizeof(aux))
|
|
|
|
return 0;
|
2009-04-03 15:42:41 +00:00
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
memcpy(buffer, &aux, sizeof(aux));
|
|
|
|
return sizeof(aux);
|
2009-04-03 15:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-31 01:57:33 +00:00
|
|
|
* check that the auxiliary data indicates that the entry is still valid
|
2007-04-26 22:55:03 +00:00
|
|
|
*/
|
2009-04-03 15:42:41 +00:00
|
|
|
static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
|
|
|
|
const void *buffer,
|
|
|
|
uint16_t buflen)
|
2007-04-26 22:55:03 +00:00
|
|
|
{
|
2009-04-03 15:42:41 +00:00
|
|
|
struct afs_vnode *vnode = cookie_netfs_data;
|
2017-11-02 15:27:47 +00:00
|
|
|
struct afs_vnode_cache_aux aux;
|
2009-04-03 15:42:41 +00:00
|
|
|
|
|
|
|
_enter("{%x,%x,%llx},%p,%u",
|
|
|
|
vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
|
|
|
|
buffer, buflen);
|
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
memcpy(&aux, buffer, sizeof(aux));
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
/* check the size of the data is what we're expecting */
|
2017-11-02 15:27:47 +00:00
|
|
|
if (buflen != sizeof(aux)) {
|
|
|
|
_leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux));
|
2009-04-03 15:42:41 +00:00
|
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
2007-04-26 22:55:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
if (vnode->fid.unique != aux.fid_unique) {
|
2009-04-03 15:42:41 +00:00
|
|
|
_leave(" = OBSOLETE [uniq %x != %x]",
|
2017-11-02 15:27:47 +00:00
|
|
|
aux.fid_unique, vnode->fid.unique);
|
2009-04-03 15:42:41 +00:00
|
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
if (vnode->status.data_version != aux.data_version) {
|
2009-04-03 15:42:41 +00:00
|
|
|
_leave(" = OBSOLETE [vers %llx != %llx]",
|
2017-11-02 15:27:47 +00:00
|
|
|
aux.data_version, vnode->status.data_version);
|
2009-04-03 15:42:41 +00:00
|
|
|
return FSCACHE_CHECKAUX_OBSOLETE;
|
2007-04-26 22:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_leave(" = SUCCESS");
|
2009-04-03 15:42:41 +00:00
|
|
|
return FSCACHE_CHECKAUX_OKAY;
|
2007-04-26 22:55:03 +00:00
|
|
|
}
|