xref: /freebsd/sys/contrib/openzfs/include/os/linux/kernel/linux/dcache_compat.h (revision efa8679e7f69c9cc225613827d9f75644cca5b3b)
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 #ifdef HAVE_DENTRY_D_U_ALIASES
36 #define	d_alias			d_u.d_alias
37 #endif
38 
39 #ifdef HAVE_MM_PAGE_FLAGS_STRUCT
40 /*
41  * Starting from Linux 6.18, the 'flags' field in 'struct page' is defined
42  * to a struct ('memdesc_flags_t' typedef) instead of an unsigned long for
43  * improved typesafety.
44  */
45 #define	page_flags flags.f
46 #else
47 #define	page_flags flags
48 #endif
49 
50 /*
51  * Starting from Linux 5.13, flush_dcache_page() becomes an inline function
52  * and under some configurations, may indirectly referencing GPL-only
53  * symbols, e.g., cpu_feature_keys on powerpc and PageHuge on riscv.
54  * Override this function when it is detected being GPL-only.
55  */
56 #if defined __powerpc__ && defined HAVE_FLUSH_DCACHE_PAGE_GPL_ONLY
57 #include <linux/simd_powerpc.h>
58 #define	flush_dcache_page(page)	do {					\
59 		if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE) &&	\
60 		    test_bit(PG_dcache_clean, &(page)->page_flags))	\
61 			clear_bit(PG_dcache_clean, &(page)->page_flags);\
62 	} while (0)
63 #endif
64 /*
65  * For riscv implementation, the use of PageHuge can be safely removed.
66  * Because it handles pages allocated by HugeTLB, while flush_dcache_page
67  * in zfs module is only called on kernel pages.
68  */
69 #if defined __riscv && defined HAVE_FLUSH_DCACHE_PAGE_GPL_ONLY
70 #define	flush_dcache_page(page)	do {					\
71 		if (test_bit(PG_dcache_clean, &(page)->page_flags))	\
72 			clear_bit(PG_dcache_clean, &(page)->page_flags);\
73 	} while (0)
74 #endif
75 
76 /*
77  * Walk and invalidate all dentry aliases of an inode
78  * unless it's a mountpoint
79  */
80 static inline void
zpl_d_drop_aliases(struct inode * inode)81 zpl_d_drop_aliases(struct inode *inode)
82 {
83 	struct dentry *dentry;
84 	spin_lock(&inode->i_lock);
85 	hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
86 		if (!IS_ROOT(dentry) && !d_mountpoint(dentry) &&
87 		    (dentry->d_inode == inode)) {
88 			d_drop(dentry);
89 		}
90 	}
91 	spin_unlock(&inode->i_lock);
92 }
93 #endif /* _ZFS_DCACHE_H */
94