1 /* Filesystem index definition
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #define FSCACHE_DEBUG_LEVEL CACHE
13 #include <linux/module.h>
17 enum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
23 * The root index is owned by FS-Cache itself.
25 * When a netfs requests caching facilities, FS-Cache will, if one doesn't
26 * already exist, create an entry in the root index with the key being the name
27 * of the netfs ("AFS" for example), and the auxiliary data holding the index
28 * structure version supplied by the netfs:
37 * If an entry with the appropriate name does already exist, the version is
38 * compared. If the version is different, the entire subtree from that entry
39 * will be discarded and a new entry created.
41 * The new entry will be an index, and a cookie referring to it will be passed
42 * to the netfs. This is then the root handle by which the netfs accesses the
43 * cache. It can create whatever objects it likes in that index, including
46 static struct fscache_cookie_def fscache_fsdef_index_def = {
48 .type = FSCACHE_COOKIE_TYPE_INDEX,
51 struct fscache_cookie fscache_fsdef_index = {
52 .usage = ATOMIC_INIT(1),
53 .n_active = ATOMIC_INIT(1),
54 .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),
55 .backing_objects = HLIST_HEAD_INIT,
56 .def = &fscache_fsdef_index_def,
57 .flags = 1 << FSCACHE_COOKIE_ENABLED,
58 .type = FSCACHE_COOKIE_TYPE_INDEX,
60 EXPORT_SYMBOL(fscache_fsdef_index);
63 * Definition of an entry in the root index. Each entry is an index, keyed to
64 * a specific netfs and only applicable to a particular version of the index
65 * structure used by that netfs.
67 struct fscache_cookie_def fscache_fsdef_netfs_def = {
68 .name = "FSDEF.netfs",
69 .type = FSCACHE_COOKIE_TYPE_INDEX,
70 .check_aux = fscache_fsdef_netfs_check_aux,
74 * check that the index structure version number stored in the auxiliary data
75 * matches the one the netfs gave us
77 static enum fscache_checkaux fscache_fsdef_netfs_check_aux(
78 void *cookie_netfs_data,
83 struct fscache_netfs *netfs = cookie_netfs_data;
86 _enter("{%s},,%hu", netfs->name, datalen);
88 if (datalen != sizeof(version)) {
89 _leave(" = OBSOLETE [dl=%d v=%zu]", datalen, sizeof(version));
90 return FSCACHE_CHECKAUX_OBSOLETE;
93 memcpy(&version, data, sizeof(version));
94 if (version != netfs->version) {
95 _leave(" = OBSOLETE [ver=%x net=%x]", version, netfs->version);
96 return FSCACHE_CHECKAUX_OBSOLETE;
100 return FSCACHE_CHECKAUX_OKAY;