blob: b1c31ec4523a897b0142ba8699ff48ac10f2d801 [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 enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
16 const void *buffer,
David Howellsee1235a2018-04-04 13:41:28 +010017 uint16_t buflen,
18 loff_t object_size);
David Howells9b3f26c2009-04-03 16:42:41 +010019
20struct fscache_netfs afs_cache_netfs = {
21 .name = "afs",
David Howells27a3ee32018-04-04 13:41:25 +010022 .version = 2,
David Howells08e0e7c2007-04-26 15:55:03 -070023};
David Howells9b3f26c2009-04-03 16:42:41 +010024
25struct fscache_cookie_def afs_cell_cache_index_def = {
26 .name = "AFS.cell",
27 .type = FSCACHE_COOKIE_TYPE_INDEX,
David Howells9b3f26c2009-04-03 16:42:41 +010028};
29
30struct fscache_cookie_def afs_volume_cache_index_def = {
31 .name = "AFS.volume",
32 .type = FSCACHE_COOKIE_TYPE_INDEX,
David Howells9b3f26c2009-04-03 16:42:41 +010033};
34
35struct fscache_cookie_def afs_vnode_cache_index_def = {
David Howells402cb8d2018-04-04 13:41:28 +010036 .name = "AFS.vnode",
37 .type = FSCACHE_COOKIE_TYPE_DATAFILE,
David Howells402cb8d2018-04-04 13:41:28 +010038 .check_aux = afs_vnode_cache_check_aux,
David Howells9b3f26c2009-04-03 16:42:41 +010039};
David Howells08e0e7c2007-04-26 15:55:03 -070040
41/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -030042 * check that the auxiliary data indicates that the entry is still valid
David Howells9b3f26c2009-04-03 16:42:41 +010043 */
44static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
45 const void *buffer,
David Howellsee1235a2018-04-04 13:41:28 +010046 uint16_t buflen,
47 loff_t object_size)
David Howells9b3f26c2009-04-03 16:42:41 +010048{
49 struct afs_vnode *vnode = cookie_netfs_data;
David Howellsad6a9422017-11-02 15:27:47 +000050 struct afs_vnode_cache_aux aux;
David Howells9b3f26c2009-04-03 16:42:41 +010051
52 _enter("{%x,%x,%llx},%p,%u",
53 vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
54 buffer, buflen);
55
David Howellsad6a9422017-11-02 15:27:47 +000056 memcpy(&aux, buffer, sizeof(aux));
57
David Howells9b3f26c2009-04-03 16:42:41 +010058 /* check the size of the data is what we're expecting */
David Howellsad6a9422017-11-02 15:27:47 +000059 if (buflen != sizeof(aux)) {
60 _leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux));
David Howells9b3f26c2009-04-03 16:42:41 +010061 return FSCACHE_CHECKAUX_OBSOLETE;
David Howells08e0e7c2007-04-26 15:55:03 -070062 }
63
David Howellsad6a9422017-11-02 15:27:47 +000064 if (vnode->status.data_version != aux.data_version) {
David Howells9b3f26c2009-04-03 16:42:41 +010065 _leave(" = OBSOLETE [vers %llx != %llx]",
David Howellsad6a9422017-11-02 15:27:47 +000066 aux.data_version, vnode->status.data_version);
David Howells9b3f26c2009-04-03 16:42:41 +010067 return FSCACHE_CHECKAUX_OBSOLETE;
David Howells08e0e7c2007-04-26 15:55:03 -070068 }
69
70 _leave(" = SUCCESS");
David Howells9b3f26c2009-04-03 16:42:41 +010071 return FSCACHE_CHECKAUX_OKAY;
David Howells08e0e7c2007-04-26 15:55:03 -070072}