xref: /freebsd/sys/contrib/openzfs/include/os/linux/kernel/linux/dcache_compat.h (revision 70999532eea52da609e90c003b583ee0bfa5246b)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (C) 2011 Lawrence Livermore National Security, LLC.
25  */
26 
27 #ifndef _ZFS_DCACHE_H
28 #define	_ZFS_DCACHE_H
29 
30 #include <linux/dcache.h>
31 
32 #define	dname(dentry)	((char *)((dentry)->d_name.name))
33 #define	dlen(dentry)	((int)((dentry)->d_name.len))
34 
35 #define	d_alias			d_u.d_alias
36 
37 /*
38  * Starting from Linux 5.13, flush_dcache_page() becomes an inline function
39  * and under some configurations, may indirectly referencing GPL-only
40  * symbols, e.g., cpu_feature_keys on powerpc and PageHuge on riscv.
41  * Override this function when it is detected being GPL-only.
42  */
43 #if defined __powerpc__ && defined HAVE_FLUSH_DCACHE_PAGE_GPL_ONLY
44 #include <linux/simd_powerpc.h>
45 #define	flush_dcache_page(page)	do {					\
46 		if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE) &&	\
47 		    test_bit(PG_dcache_clean, &(page)->flags))		\
48 			clear_bit(PG_dcache_clean, &(page)->flags);	\
49 	} while (0)
50 #endif
51 /*
52  * For riscv implementation, the use of PageHuge can be safely removed.
53  * Because it handles pages allocated by HugeTLB, while flush_dcache_page
54  * in zfs module is only called on kernel pages.
55  */
56 #if defined __riscv && defined HAVE_FLUSH_DCACHE_PAGE_GPL_ONLY
57 #define	flush_dcache_page(page)	do {					\
58 		if (test_bit(PG_dcache_clean, &(page)->flags))		\
59 			clear_bit(PG_dcache_clean, &(page)->flags);	\
60 	} while (0)
61 #endif
62 
63 /*
64  * Walk and invalidate all dentry aliases of an inode
65  * unless it's a mountpoint
66  */
67 static inline void
zpl_d_drop_aliases(struct inode * inode)68 zpl_d_drop_aliases(struct inode *inode)
69 {
70 	struct dentry *dentry;
71 	spin_lock(&inode->i_lock);
72 	hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
73 		if (!IS_ROOT(dentry) && !d_mountpoint(dentry) &&
74 		    (dentry->d_inode == inode)) {
75 			d_drop(dentry);
76 		}
77 	}
78 	spin_unlock(&inode->i_lock);
79 }
80 #endif /* _ZFS_DCACHE_H */
81