Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 2 | /* Filesystem index definition |
| 3 | * |
| 4 | * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #define FSCACHE_DEBUG_LEVEL CACHE |
| 9 | #include <linux/module.h> |
| 10 | #include "internal.h" |
| 11 | |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 12 | static |
| 13 | enum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data, |
| 14 | const void *data, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 15 | uint16_t datalen, |
| 16 | loff_t object_size); |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * The root index is owned by FS-Cache itself. |
| 20 | * |
| 21 | * When a netfs requests caching facilities, FS-Cache will, if one doesn't |
| 22 | * already exist, create an entry in the root index with the key being the name |
| 23 | * of the netfs ("AFS" for example), and the auxiliary data holding the index |
| 24 | * structure version supplied by the netfs: |
| 25 | * |
| 26 | * FSDEF |
| 27 | * | |
| 28 | * +-----------+ |
| 29 | * | | |
| 30 | * NFS AFS |
| 31 | * [v=1] [v=1] |
| 32 | * |
| 33 | * If an entry with the appropriate name does already exist, the version is |
| 34 | * compared. If the version is different, the entire subtree from that entry |
| 35 | * will be discarded and a new entry created. |
| 36 | * |
| 37 | * The new entry will be an index, and a cookie referring to it will be passed |
| 38 | * to the netfs. This is then the root handle by which the netfs accesses the |
| 39 | * cache. It can create whatever objects it likes in that index, including |
| 40 | * further indices. |
| 41 | */ |
| 42 | static struct fscache_cookie_def fscache_fsdef_index_def = { |
| 43 | .name = ".FS-Cache", |
| 44 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
| 45 | }; |
| 46 | |
| 47 | struct fscache_cookie fscache_fsdef_index = { |
| 48 | .usage = ATOMIC_INIT(1), |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 49 | .n_active = ATOMIC_INIT(1), |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 50 | .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock), |
| 51 | .backing_objects = HLIST_HEAD_INIT, |
| 52 | .def = &fscache_fsdef_index_def, |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 53 | .flags = 1 << FSCACHE_COOKIE_ENABLED, |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 54 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 55 | }; |
| 56 | EXPORT_SYMBOL(fscache_fsdef_index); |
| 57 | |
| 58 | /* |
| 59 | * Definition of an entry in the root index. Each entry is an index, keyed to |
| 60 | * a specific netfs and only applicable to a particular version of the index |
| 61 | * structure used by that netfs. |
| 62 | */ |
| 63 | struct fscache_cookie_def fscache_fsdef_netfs_def = { |
| 64 | .name = "FSDEF.netfs", |
| 65 | .type = FSCACHE_COOKIE_TYPE_INDEX, |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 66 | .check_aux = fscache_fsdef_netfs_check_aux, |
| 67 | }; |
| 68 | |
| 69 | /* |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 70 | * check that the index structure version number stored in the auxiliary data |
| 71 | * matches the one the netfs gave us |
| 72 | */ |
| 73 | static enum fscache_checkaux fscache_fsdef_netfs_check_aux( |
| 74 | void *cookie_netfs_data, |
| 75 | const void *data, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 76 | uint16_t datalen, |
| 77 | loff_t object_size) |
David Howells | a689164 | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 78 | { |
| 79 | struct fscache_netfs *netfs = cookie_netfs_data; |
| 80 | uint32_t version; |
| 81 | |
| 82 | _enter("{%s},,%hu", netfs->name, datalen); |
| 83 | |
| 84 | if (datalen != sizeof(version)) { |
| 85 | _leave(" = OBSOLETE [dl=%d v=%zu]", datalen, sizeof(version)); |
| 86 | return FSCACHE_CHECKAUX_OBSOLETE; |
| 87 | } |
| 88 | |
| 89 | memcpy(&version, data, sizeof(version)); |
| 90 | if (version != netfs->version) { |
| 91 | _leave(" = OBSOLETE [ver=%x net=%x]", version, netfs->version); |
| 92 | return FSCACHE_CHECKAUX_OBSOLETE; |
| 93 | } |
| 94 | |
| 95 | _leave(" = OKAY"); |
| 96 | return FSCACHE_CHECKAUX_OKAY; |
| 97 | } |