blob: 037af93e3aba784310286f4091219c4d49161b8a [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells08e0e7c2007-04-26 15:55:03 -07002/* AFS caching stuff
3 *
David Howells9b3f26c2009-04-03 16:42:41 +01004 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
David Howells08e0e7c2007-04-26 15:55:03 -07005 * Written by David Howells (dhowells@redhat.com)
David Howells08e0e7c2007-04-26 15:55:03 -07006 */
7
David Howells9b3f26c2009-04-03 16:42:41 +01008#include <linux/sched.h>
9#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070010
David Howells9b3f26c2009-04-03 16:42:41 +010011static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
12 const void *buffer,
David Howellsee1235a2018-04-04 13:41:28 +010013 uint16_t buflen,
14 loff_t object_size);
David Howells9b3f26c2009-04-03 16:42:41 +010015
16struct fscache_netfs afs_cache_netfs = {
17 .name = "afs",
David Howells27a3ee32018-04-04 13:41:25 +010018 .version = 2,
David Howells08e0e7c2007-04-26 15:55:03 -070019};
David Howells9b3f26c2009-04-03 16:42:41 +010020
21struct fscache_cookie_def afs_cell_cache_index_def = {
22 .name = "AFS.cell",
23 .type = FSCACHE_COOKIE_TYPE_INDEX,
David Howells9b3f26c2009-04-03 16:42:41 +010024};
25
26struct fscache_cookie_def afs_volume_cache_index_def = {
27 .name = "AFS.volume",
28 .type = FSCACHE_COOKIE_TYPE_INDEX,
David Howells9b3f26c2009-04-03 16:42:41 +010029};
30
31struct fscache_cookie_def afs_vnode_cache_index_def = {
David Howells402cb8d2018-04-04 13:41:28 +010032 .name = "AFS.vnode",
33 .type = FSCACHE_COOKIE_TYPE_DATAFILE,
David Howells402cb8d2018-04-04 13:41:28 +010034 .check_aux = afs_vnode_cache_check_aux,
David Howells9b3f26c2009-04-03 16:42:41 +010035};
David Howells08e0e7c2007-04-26 15:55:03 -070036
37/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -030038 * check that the auxiliary data indicates that the entry is still valid
David Howells9b3f26c2009-04-03 16:42:41 +010039 */
40static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
41 const void *buffer,
David Howellsee1235a2018-04-04 13:41:28 +010042 uint16_t buflen,
43 loff_t object_size)
David Howells9b3f26c2009-04-03 16:42:41 +010044{
45 struct afs_vnode *vnode = cookie_netfs_data;
David Howellsad6a9422017-11-02 15:27:47 +000046 struct afs_vnode_cache_aux aux;
David Howells9b3f26c2009-04-03 16:42:41 +010047
David Howells3b6492d2018-10-20 00:57:57 +010048 _enter("{%llx,%x,%llx},%p,%u",
David Howells9b3f26c2009-04-03 16:42:41 +010049 vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
50 buffer, buflen);
51
David Howellsad6a9422017-11-02 15:27:47 +000052 memcpy(&aux, buffer, sizeof(aux));
53
David Howells9b3f26c2009-04-03 16:42:41 +010054 /* check the size of the data is what we're expecting */
David Howellsad6a9422017-11-02 15:27:47 +000055 if (buflen != sizeof(aux)) {
56 _leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux));
David Howells9b3f26c2009-04-03 16:42:41 +010057 return FSCACHE_CHECKAUX_OBSOLETE;
David Howells08e0e7c2007-04-26 15:55:03 -070058 }
59
David Howellsad6a9422017-11-02 15:27:47 +000060 if (vnode->status.data_version != aux.data_version) {
David Howells9b3f26c2009-04-03 16:42:41 +010061 _leave(" = OBSOLETE [vers %llx != %llx]",
David Howellsad6a9422017-11-02 15:27:47 +000062 aux.data_version, vnode->status.data_version);
David Howells9b3f26c2009-04-03 16:42:41 +010063 return FSCACHE_CHECKAUX_OBSOLETE;
David Howells08e0e7c2007-04-26 15:55:03 -070064 }
65
66 _leave(" = SUCCESS");
David Howells9b3f26c2009-04-03 16:42:41 +010067 return FSCACHE_CHECKAUX_OKAY;
David Howells08e0e7c2007-04-26 15:55:03 -070068}