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) /* FS-Cache netfs (client) registration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * Copyright (C) 2008 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 COOKIE
^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 <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)  * register a network filesystem for caching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) int __fscache_register_netfs(struct fscache_netfs *netfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	struct fscache_cookie *candidate, *cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	_enter("{%s}", netfs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	/* allocate a cookie for the primary index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	candidate = fscache_alloc_cookie(&fscache_fsdef_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 					 &fscache_fsdef_netfs_def,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 					 netfs->name, strlen(netfs->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 					 &netfs->version, sizeof(netfs->version),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 					 netfs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	if (!candidate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		_leave(" = -ENOMEM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	candidate->flags = 1 << FSCACHE_COOKIE_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	/* check the netfs type is not already present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	cookie = fscache_hash_cookie(candidate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	if (!cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 		goto already_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	if (cookie != candidate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		trace_fscache_cookie(candidate, fscache_cookie_discard, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		fscache_free_cookie(candidate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	atomic_inc(&cookie->parent->n_children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	netfs->primary_index = cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	pr_notice("Netfs '%s' registered for caching\n", netfs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	trace_fscache_netfs(netfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	_leave(" = 0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) already_registered:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	fscache_cookie_put(candidate, fscache_cookie_put_dup_netfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	_leave(" = -EEXIST");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) EXPORT_SYMBOL(__fscache_register_netfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)  * unregister a network filesystem from the cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)  * - all cookies must have been released first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void __fscache_unregister_netfs(struct fscache_netfs *netfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	_enter("{%s.%u}", netfs->name, netfs->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	fscache_relinquish_cookie(netfs->primary_index, NULL, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	pr_notice("Netfs '%s' unregistered from caching\n", netfs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) EXPORT_SYMBOL(__fscache_unregister_netfs);