Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 2 | /* AFS caching stuff |
| 3 | * |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 4 | * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 8 | #include <linux/sched.h> |
| 9 | #include "internal.h" |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 10 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 11 | static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data, |
| 12 | const void *buffer, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 13 | uint16_t buflen, |
| 14 | loff_t object_size); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 15 | |
| 16 | struct fscache_netfs afs_cache_netfs = { |
| 17 | .name = "afs", |
David Howells | 27a3ee3 | 2018-04-04 13:41:25 +0100 | [diff] [blame] | 18 | .version = 2, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 19 | }; |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 20 | |
| 21 | struct fscache_cookie_def afs_cell_cache_index_def = { |
| 22 | .name = "AFS.cell", |
| 23 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | struct fscache_cookie_def afs_volume_cache_index_def = { |
| 27 | .name = "AFS.volume", |
| 28 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | struct fscache_cookie_def afs_vnode_cache_index_def = { |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 32 | .name = "AFS.vnode", |
| 33 | .type = FSCACHE_COOKIE_TYPE_DATAFILE, |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 34 | .check_aux = afs_vnode_cache_check_aux, |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 35 | }; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 38 | * check that the auxiliary data indicates that the entry is still valid |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 39 | */ |
| 40 | static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data, |
| 41 | const void *buffer, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 42 | uint16_t buflen, |
| 43 | loff_t object_size) |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 44 | { |
| 45 | struct afs_vnode *vnode = cookie_netfs_data; |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 46 | struct afs_vnode_cache_aux aux; |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 47 | |
David Howells | 3b6492d | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 48 | _enter("{%llx,%x,%llx},%p,%u", |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 49 | vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, |
| 50 | buffer, buflen); |
| 51 | |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 52 | memcpy(&aux, buffer, sizeof(aux)); |
| 53 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 54 | /* check the size of the data is what we're expecting */ |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 55 | if (buflen != sizeof(aux)) { |
| 56 | _leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux)); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 57 | return FSCACHE_CHECKAUX_OBSOLETE; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 58 | } |
| 59 | |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 60 | if (vnode->status.data_version != aux.data_version) { |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 61 | _leave(" = OBSOLETE [vers %llx != %llx]", |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 62 | aux.data_version, vnode->status.data_version); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 63 | return FSCACHE_CHECKAUX_OBSOLETE; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | _leave(" = SUCCESS"); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 67 | return FSCACHE_CHECKAUX_OKAY; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 68 | } |