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 void afs_vnode_cache_get_attr(const void *cookie_netfs_data, |
| 16 | uint64_t *size); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 17 | static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data, |
| 18 | const void *buffer, |
| 19 | uint16_t buflen); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 20 | |
| 21 | struct fscache_netfs afs_cache_netfs = { |
| 22 | .name = "afs", |
David Howells | 27a3ee3 | 2018-04-04 13:41:25 +0100 | [diff] [blame] | 23 | .version = 2, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 24 | }; |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 25 | |
| 26 | struct fscache_cookie_def afs_cell_cache_index_def = { |
| 27 | .name = "AFS.cell", |
| 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_volume_cache_index_def = { |
| 32 | .name = "AFS.volume", |
| 33 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | struct fscache_cookie_def afs_vnode_cache_index_def = { |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame^] | 37 | .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 Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 41 | }; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 42 | |
| 43 | /* |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 44 | * provide updated file attributes |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 45 | */ |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 46 | static void afs_vnode_cache_get_attr(const void *cookie_netfs_data, |
| 47 | uint64_t *size) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 48 | { |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 49 | const struct afs_vnode *vnode = cookie_netfs_data; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 50 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 51 | _enter("{%x,%x,%llx},", |
| 52 | vnode->fid.vnode, vnode->fid.unique, |
| 53 | vnode->status.data_version); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 54 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 55 | *size = vnode->status.size; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 56 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 57 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 58 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 59 | * check that the auxiliary data indicates that the entry is still valid |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 60 | */ |
| 61 | static 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 Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 66 | struct afs_vnode_cache_aux aux; |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 67 | |
| 68 | _enter("{%x,%x,%llx},%p,%u", |
| 69 | vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version, |
| 70 | buffer, buflen); |
| 71 | |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 72 | memcpy(&aux, buffer, sizeof(aux)); |
| 73 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 74 | /* check the size of the data is what we're expecting */ |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 75 | if (buflen != sizeof(aux)) { |
| 76 | _leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux)); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 77 | return FSCACHE_CHECKAUX_OBSOLETE; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 78 | } |
| 79 | |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 80 | if (vnode->status.data_version != aux.data_version) { |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 81 | _leave(" = OBSOLETE [vers %llx != %llx]", |
David Howells | ad6a942 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 82 | aux.data_version, vnode->status.data_version); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 83 | return FSCACHE_CHECKAUX_OBSOLETE; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | _leave(" = SUCCESS"); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 87 | return FSCACHE_CHECKAUX_OKAY; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 88 | } |