blob: a16f1e024cf305ccb82c31396bd64822c1859ea2 [file] [log] [blame]
David Howells08e0e7c2007-04-26 15:55:03 -07001/* AFS caching stuff
2 *
David Howells9b3f26c2009-04-03 16:42:41 +01003 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
David Howells08e0e7c2007-04-26 15:55:03 -07004 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
David Howells9b3f26c2009-04-03 16:42:41 +010012#include <linux/sched.h>
13#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070014
David Howells9b3f26c2009-04-03 16:42:41 +010015static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
16 uint64_t *size);
David Howells9b3f26c2009-04-03 16:42:41 +010017static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
18 const void *buffer,
19 uint16_t buflen);
David Howells9b3f26c2009-04-03 16:42:41 +010020
21struct fscache_netfs afs_cache_netfs = {
22 .name = "afs",
David Howells27a3ee32018-04-04 13:41:25 +010023 .version = 2,
David Howells08e0e7c2007-04-26 15:55:03 -070024};
David Howells9b3f26c2009-04-03 16:42:41 +010025
26struct fscache_cookie_def afs_cell_cache_index_def = {
27 .name = "AFS.cell",
28 .type = FSCACHE_COOKIE_TYPE_INDEX,
David Howells9b3f26c2009-04-03 16:42:41 +010029};
30
31struct fscache_cookie_def afs_volume_cache_index_def = {
32 .name = "AFS.volume",
33 .type = FSCACHE_COOKIE_TYPE_INDEX,
David Howells9b3f26c2009-04-03 16:42:41 +010034};
35
36struct fscache_cookie_def afs_vnode_cache_index_def = {
David Howells402cb8d2018-04-04 13:41:28 +010037 .name = "AFS.vnode",
38 .type = FSCACHE_COOKIE_TYPE_DATAFILE,
39 .get_attr = afs_vnode_cache_get_attr,
40 .check_aux = afs_vnode_cache_check_aux,
David Howells9b3f26c2009-04-03 16:42:41 +010041};
David Howells08e0e7c2007-04-26 15:55:03 -070042
43/*
David Howells9b3f26c2009-04-03 16:42:41 +010044 * provide updated file attributes
David Howells08e0e7c2007-04-26 15:55:03 -070045 */
David Howells9b3f26c2009-04-03 16:42:41 +010046static void afs_vnode_cache_get_attr(const void *cookie_netfs_data,
47 uint64_t *size)
David Howells08e0e7c2007-04-26 15:55:03 -070048{
David Howells9b3f26c2009-04-03 16:42:41 +010049 const struct afs_vnode *vnode = cookie_netfs_data;
David Howells08e0e7c2007-04-26 15:55:03 -070050
David Howells9b3f26c2009-04-03 16:42:41 +010051 _enter("{%x,%x,%llx},",
52 vnode->fid.vnode, vnode->fid.unique,
53 vnode->status.data_version);
David Howells08e0e7c2007-04-26 15:55:03 -070054
David Howells9b3f26c2009-04-03 16:42:41 +010055 *size = vnode->status.size;
David Howells08e0e7c2007-04-26 15:55:03 -070056}
David Howells08e0e7c2007-04-26 15:55:03 -070057
David Howells9b3f26c2009-04-03 16:42:41 +010058/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -030059 * check that the auxiliary data indicates that the entry is still valid
David Howells9b3f26c2009-04-03 16:42:41 +010060 */
61static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
62 const void *buffer,
63 uint16_t buflen)
64{
65 struct afs_vnode *vnode = cookie_netfs_data;
David Howellsad6a9422017-11-02 15:27:47 +000066 struct afs_vnode_cache_aux aux;
David Howells9b3f26c2009-04-03 16:42:41 +010067
68 _enter("{%x,%x,%llx},%p,%u",
69 vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
70 buffer, buflen);
71
David Howellsad6a9422017-11-02 15:27:47 +000072 memcpy(&aux, buffer, sizeof(aux));
73
David Howells9b3f26c2009-04-03 16:42:41 +010074 /* check the size of the data is what we're expecting */
David Howellsad6a9422017-11-02 15:27:47 +000075 if (buflen != sizeof(aux)) {
76 _leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux));
David Howells9b3f26c2009-04-03 16:42:41 +010077 return FSCACHE_CHECKAUX_OBSOLETE;
David Howells08e0e7c2007-04-26 15:55:03 -070078 }
79
David Howellsad6a9422017-11-02 15:27:47 +000080 if (vnode->status.data_version != aux.data_version) {
David Howells9b3f26c2009-04-03 16:42:41 +010081 _leave(" = OBSOLETE [vers %llx != %llx]",
David Howellsad6a9422017-11-02 15:27:47 +000082 aux.data_version, vnode->status.data_version);
David Howells9b3f26c2009-04-03 16:42:41 +010083 return FSCACHE_CHECKAUX_OBSOLETE;
David Howells08e0e7c2007-04-26 15:55:03 -070084 }
85
86 _leave(" = SUCCESS");
David Howells9b3f26c2009-04-03 16:42:41 +010087 return FSCACHE_CHECKAUX_OKAY;
David Howells08e0e7c2007-04-26 15:55:03 -070088}