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