1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Filesystem index definition
4 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #define FSCACHE_DEBUG_LEVEL CACHE
9 #include <linux/module.h>
13 enum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
19 * The root index is owned by FS-Cache itself.
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:
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.
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
42 static struct fscache_cookie_def fscache_fsdef_index_def = {
44 .type = FSCACHE_COOKIE_TYPE_INDEX,
47 struct fscache_cookie fscache_fsdef_index = {
49 .ref = REFCOUNT_INIT(1),
50 .n_active = ATOMIC_INIT(1),
51 .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),
52 .backing_objects = HLIST_HEAD_INIT,
53 .def = &fscache_fsdef_index_def,
54 .flags = 1 << FSCACHE_COOKIE_ENABLED,
55 .type = FSCACHE_COOKIE_TYPE_INDEX,
57 EXPORT_SYMBOL(fscache_fsdef_index);
60 * Definition of an entry in the root index. Each entry is an index, keyed to
61 * a specific netfs and only applicable to a particular version of the index
62 * structure used by that netfs.
64 struct fscache_cookie_def fscache_fsdef_netfs_def = {
65 .name = "FSDEF.netfs",
66 .type = FSCACHE_COOKIE_TYPE_INDEX,
67 .check_aux = fscache_fsdef_netfs_check_aux,
71 * check that the index structure version number stored in the auxiliary data
72 * matches the one the netfs gave us
74 static enum fscache_checkaux fscache_fsdef_netfs_check_aux(
75 void *cookie_netfs_data,
80 struct fscache_netfs *netfs = cookie_netfs_data;
83 _enter("{%s},,%hu", netfs->name, datalen);
85 if (datalen != sizeof(version)) {
86 _leave(" = OBSOLETE [dl=%d v=%zu]", datalen, sizeof(version));
87 return FSCACHE_CHECKAUX_OBSOLETE;
90 memcpy(&version, data, sizeof(version));
91 if (version != netfs->version) {
92 _leave(" = OBSOLETE [ver=%x net=%x]", version, netfs->version);
93 return FSCACHE_CHECKAUX_OBSOLETE;
97 return FSCACHE_CHECKAUX_OKAY;