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 * 2.6.30 API change,
65 * The const keyword was added to the 'struct dentry_operations' in
66 * the dentry structure. To handle this we define an appropriate
67 * dentry_operations_t typedef which can be used.
68 */
69 typedef const struct dentry_operations dentry_operations_t;
70
71 /*
72 * 2.6.38 API addition,
73 * Added d_clear_d_op() helper function which clears some flags and the
74 * registered dentry->d_op table. This is required because d_set_d_op()
75 * issues a warning when the dentry operations table is already set.
76 * For the .zfs control directory to work properly we must be able to
77 * override the default operations table and register custom .d_automount
78 * and .d_revalidate callbacks.
79 */
80 static inline void
d_clear_d_op(struct dentry * dentry)81 d_clear_d_op(struct dentry *dentry)
82 {
83 dentry->d_op = NULL;
84 dentry->d_flags &= ~(
85 DCACHE_OP_HASH | DCACHE_OP_COMPARE |
86 DCACHE_OP_REVALIDATE | DCACHE_OP_DELETE);
87 }
88
89 /*
90 * Walk and invalidate all dentry aliases of an inode
91 * unless it's a mountpoint
92 */
93 static inline void
zpl_d_drop_aliases(struct inode * inode)94 zpl_d_drop_aliases(struct inode *inode)
95 {
96 struct dentry *dentry;
97 spin_lock(&inode->i_lock);
98 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
99 if (!IS_ROOT(dentry) && !d_mountpoint(dentry) &&
100 (dentry->d_inode == inode)) {
101 d_drop(dentry);
102 }
103 }
104 spin_unlock(&inode->i_lock);
105 }
106 #endif /* _ZFS_DCACHE_H */
107