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
= {
48 .usage
= ATOMIC_INIT(1),
49 .n_active
= ATOMIC_INIT(1),
50 .lock
= __SPIN_LOCK_UNLOCKED(fscache_fsdef_index
.lock
),
51 .backing_objects
= HLIST_HEAD_INIT
,
52 .def
= &fscache_fsdef_index_def
,
53 .flags
= 1 << FSCACHE_COOKIE_ENABLED
,
54 .type
= FSCACHE_COOKIE_TYPE_INDEX
,
56 EXPORT_SYMBOL(fscache_fsdef_index
);
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.
63 struct fscache_cookie_def fscache_fsdef_netfs_def
= {
64 .name
= "FSDEF.netfs",
65 .type
= FSCACHE_COOKIE_TYPE_INDEX
,
66 .check_aux
= fscache_fsdef_netfs_check_aux
,
70 * check that the index structure version number stored in the auxiliary data
71 * matches the one the netfs gave us
73 static enum fscache_checkaux
fscache_fsdef_netfs_check_aux(
74 void *cookie_netfs_data
,
79 struct fscache_netfs
*netfs
= cookie_netfs_data
;
82 _enter("{%s},,%hu", netfs
->name
, datalen
);
84 if (datalen
!= sizeof(version
)) {
85 _leave(" = OBSOLETE [dl=%d v=%zu]", datalen
, sizeof(version
));
86 return FSCACHE_CHECKAUX_OBSOLETE
;
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
;
96 return FSCACHE_CHECKAUX_OKAY
;