Linux Audio

Check our new training course

Loading...
Note: File does not exist in v6.13.7.
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/* Filesystem index definition
 3 *
 4 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
 5 * Written by David Howells (dhowells@redhat.com)
 6 */
 7
 8#define FSCACHE_DEBUG_LEVEL CACHE
 9#include <linux/module.h>
10#include "internal.h"
11
12static
13enum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
14						    const void *data,
15						    uint16_t datalen,
16						    loff_t object_size);
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 */
42static struct fscache_cookie_def fscache_fsdef_index_def = {
43	.name		= ".FS-Cache",
44	.type		= FSCACHE_COOKIE_TYPE_INDEX,
45};
46
47struct 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,
55};
56EXPORT_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 */
63struct 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,
67};
68
69/*
70 * check that the index structure version number stored in the auxiliary data
71 * matches the one the netfs gave us
72 */
73static enum fscache_checkaux fscache_fsdef_netfs_check_aux(
74	void *cookie_netfs_data,
75	const void *data,
76	uint16_t datalen,
77	loff_t object_size)
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}