Merge tag 'for-4.17-part2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave...
[linux-2.6-block.git] / fs / fscache / fsdef.c
CommitLineData
a6891645
DH
1/* Filesystem index definition
2 *
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
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
12#define FSCACHE_DEBUG_LEVEL CACHE
13#include <linux/module.h>
14#include "internal.h"
15
a6891645
DH
16static
17enum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
18 const void *data,
ee1235a9
DH
19 uint16_t datalen,
20 loff_t object_size);
a6891645
DH
21
22/*
23 * The root index is owned by FS-Cache itself.
24 *
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:
29 *
30 * FSDEF
31 * |
32 * +-----------+
33 * | |
34 * NFS AFS
35 * [v=1] [v=1]
36 *
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.
40 *
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
44 * further indices.
45 */
46static struct fscache_cookie_def fscache_fsdef_index_def = {
47 .name = ".FS-Cache",
48 .type = FSCACHE_COOKIE_TYPE_INDEX,
49};
50
51struct fscache_cookie fscache_fsdef_index = {
52 .usage = ATOMIC_INIT(1),
1362729b 53 .n_active = ATOMIC_INIT(1),
a6891645
DH
54 .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),
55 .backing_objects = HLIST_HEAD_INIT,
56 .def = &fscache_fsdef_index_def,
94d30ae9 57 .flags = 1 << FSCACHE_COOKIE_ENABLED,
402cb8dd 58 .type = FSCACHE_COOKIE_TYPE_INDEX,
a6891645
DH
59};
60EXPORT_SYMBOL(fscache_fsdef_index);
61
62/*
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.
66 */
67struct fscache_cookie_def fscache_fsdef_netfs_def = {
68 .name = "FSDEF.netfs",
69 .type = FSCACHE_COOKIE_TYPE_INDEX,
a6891645
DH
70 .check_aux = fscache_fsdef_netfs_check_aux,
71};
72
a6891645
DH
73/*
74 * check that the index structure version number stored in the auxiliary data
75 * matches the one the netfs gave us
76 */
77static enum fscache_checkaux fscache_fsdef_netfs_check_aux(
78 void *cookie_netfs_data,
79 const void *data,
ee1235a9
DH
80 uint16_t datalen,
81 loff_t object_size)
a6891645
DH
82{
83 struct fscache_netfs *netfs = cookie_netfs_data;
84 uint32_t version;
85
86 _enter("{%s},,%hu", netfs->name, datalen);
87
88 if (datalen != sizeof(version)) {
89 _leave(" = OBSOLETE [dl=%d v=%zu]", datalen, sizeof(version));
90 return FSCACHE_CHECKAUX_OBSOLETE;
91 }
92
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;
97 }
98
99 _leave(" = OKAY");
100 return FSCACHE_CHECKAUX_OKAY;
101}