Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /* Filesystem index definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #define FSCACHE_DEBUG_LEVEL CACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) enum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 						    const void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 						    uint16_t datalen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 						    loff_t object_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)  * The root index is owned by FS-Cache itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)  * When a netfs requests caching facilities, FS-Cache will, if one doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)  * already exist, create an entry in the root index with the key being the name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)  * of the netfs ("AFS" for example), and the auxiliary data holding the index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  * structure version supplied by the netfs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  *				     FSDEF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  *				       |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)  *				 +-----------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)  *				 |           |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)  *				NFS         AFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)  *			       [v=1]       [v=1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)  * If an entry with the appropriate name does already exist, the version is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)  * compared.  If the version is different, the entire subtree from that entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)  * will be discarded and a new entry created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)  * The new entry will be an index, and a cookie referring to it will be passed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)  * to the netfs.  This is then the root handle by which the netfs accesses the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)  * cache.  It can create whatever objects it likes in that index, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)  * further indices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static struct fscache_cookie_def fscache_fsdef_index_def = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	.name		= ".FS-Cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	.type		= FSCACHE_COOKIE_TYPE_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct fscache_cookie fscache_fsdef_index = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	.usage		= ATOMIC_INIT(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	.n_active	= ATOMIC_INIT(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	.lock		= __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	.backing_objects = HLIST_HEAD_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	.def		= &fscache_fsdef_index_def,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	.flags		= 1 << FSCACHE_COOKIE_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	.type		= FSCACHE_COOKIE_TYPE_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) EXPORT_SYMBOL(fscache_fsdef_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)  * Definition of an entry in the root index.  Each entry is an index, keyed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)  * a specific netfs and only applicable to a particular version of the index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)  * structure used by that netfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct fscache_cookie_def fscache_fsdef_netfs_def = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	.name		= "FSDEF.netfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	.type		= FSCACHE_COOKIE_TYPE_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	.check_aux	= fscache_fsdef_netfs_check_aux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)  * check that the index structure version number stored in the auxiliary data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)  * matches the one the netfs gave us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static enum fscache_checkaux fscache_fsdef_netfs_check_aux(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	void *cookie_netfs_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	const void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	uint16_t datalen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	loff_t object_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	struct fscache_netfs *netfs = cookie_netfs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	uint32_t version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	_enter("{%s},,%hu", netfs->name, datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	if (datalen != sizeof(version)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 		_leave(" = OBSOLETE [dl=%d v=%zu]", datalen, sizeof(version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 		return FSCACHE_CHECKAUX_OBSOLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 	memcpy(&version, data, sizeof(version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 	if (version != netfs->version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 		_leave(" = OBSOLETE [ver=%x net=%x]", version, netfs->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 		return FSCACHE_CHECKAUX_OBSOLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) 	_leave(" = OKAY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) 	return FSCACHE_CHECKAUX_OKAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }