xref: /freebsd/sys/contrib/openzfs/include/os/linux/zfs/sys/zpl.h (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 /*
13  * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
14  * Copyright (c) 2026, TrueNAS.
15  */
16 
17 #ifndef	_SYS_ZPL_H
18 #define	_SYS_ZPL_H
19 
20 #include <sys/zfs_context.h>
21 #include <sys/spa.h>
22 #include <sys/mntent.h>
23 #include <sys/vfs.h>
24 #include <linux/aio.h>
25 #include <linux/dcache_compat.h>
26 #include <linux/exportfs.h>
27 #include <linux/falloc.h>
28 #include <linux/parser.h>
29 #include <linux/vfs_compat.h>
30 #include <linux/writeback.h>
31 #include <linux/idmap_compat.h>
32 #include <linux/xattr_compat.h>
33 
34 /* zpl_inode.c */
35 extern void zpl_vap_init(vattr_t *vap, struct inode *dir,
36     umode_t mode, cred_t *cr, zidmap_t *idmap);
37 
38 extern const struct inode_operations zpl_inode_operations;
39 extern const struct inode_operations zpl_dir_inode_operations;
40 extern const struct inode_operations zpl_symlink_inode_operations;
41 extern const struct inode_operations zpl_special_inode_operations;
42 
43 /* zpl_file.c */
44 extern const struct address_space_operations zpl_address_space_operations;
45 extern const struct file_operations zpl_file_operations;
46 extern const struct file_operations zpl_dir_file_operations;
47 
48 /* zpl_super.c */
49 extern void zpl_prune_sb(uint64_t nr_to_scan, void *arg);
50 
51 extern const struct super_operations zpl_super_operations;
52 extern const struct dentry_operations zpl_dentry_operations;
53 extern const struct export_operations zpl_export_operations;
54 extern struct file_system_type zpl_fs_type;
55 
56 /* zpl_xattr.c */
57 extern ssize_t zpl_xattr_list(struct dentry *dentry, char *buf, size_t size);
58 extern int zpl_xattr_security_init(struct inode *ip, struct inode *dip,
59     const struct qstr *qstr);
60 
61 #if defined(CONFIG_FS_POSIX_ACL)
62 extern int zpl_set_posix_acl(struct inode *ip, struct posix_acl *acl, int type);
63 extern struct posix_acl *zpl_get_posix_acl(struct inode *ip, int type);
64 extern int zpl_init_acl(struct inode *ip, struct inode *dir);
65 extern int zpl_chmod_acl(struct inode *ip);
66 #else
67 static inline int
zpl_init_acl(struct inode * ip,struct inode * dir)68 zpl_init_acl(struct inode *ip, struct inode *dir)
69 {
70 	return (0);
71 }
72 
73 static inline int
zpl_chmod_acl(struct inode * ip)74 zpl_chmod_acl(struct inode *ip)
75 {
76 	return (0);
77 }
78 #endif /* CONFIG_FS_POSIX_ACL */
79 
80 extern xattr_handler_t *zpl_xattr_handlers[];
81 
82 /* zpl_ctldir.c */
83 extern const struct file_operations zpl_fops_root;
84 extern const struct inode_operations zpl_ops_root;
85 
86 extern const struct file_operations zpl_fops_snapdir;
87 extern const struct inode_operations zpl_ops_snapdir;
88 
89 extern const struct file_operations zpl_fops_shares;
90 extern const struct inode_operations zpl_ops_shares;
91 
92 /*
93  * Snapentry. Held on the snapdir dentry, coordinates mount, unmount and
94  * access through the snapdir mountpoint.
95  */
96 typedef struct zfs_snapentry {
97 	/* The snapdir dentry itself, that owns this snapentry (via d_fsdata) */
98 	struct dentry	*se_dentry;
99 
100 	/*
101 	 * State flags, see below. Early in struct to be in first cacheline,
102 	 * for unlocked RCU-walk check in zpl_snapdir_manage().
103 	 */
104 	unsigned long	se_flags;
105 
106 	/* Time of last transit through this snapdir. */
107 	uint64_t	se_atime;
108 
109 	/* se_mtx protects se_flags, se_taskqid, se_mount_task and se_cv */
110 	kmutex_t	se_mtx;
111 
112 	/* ID of expiry timer. */
113 	taskqid_t	se_taskqid;
114 
115 	/* Mount task, see zpl_snapdir_manage(). */
116 	struct task_struct *se_mount_task;
117 
118 	/* Pool & snapshot objset that we mounted */
119 	spa_t		*se_spa;
120 	uint64_t	se_objsetid;
121 
122 	/* Signal state transition completed, SE_BUSY clear. */
123 	kcondvar_t	se_cv;
124 } zfs_snapentry_t;
125 
126 /*
127  * Snapentry flags.
128  *
129  * Bit 0 indicates that something currently adding a mount or invalidating the
130  * dentry.
131  *
132  * Bit 1 indicates an in-flight VFS op wants to traverse into the mount if
133  * it exists; see zpl_snapdir_manage().
134  */
135 enum {
136 	SE_BUSY,	/* mounting or unmounting, should wait */
137 	SE_WANT_MOUNT,	/* next VFS op should attempt automount */
138 };
139 
140 /*
141  * We use atomic bitops for se_flags because we need to test SE_BUSY without
142  * holding se_mtx in zpl_snapdir_manage(). Beyond that, they are always
143  * protected by se_mtx.
144  */
145 #define	SE_TEST(se, fl)		test_bit((fl), &(se)->se_flags)
146 #define	SE_SET(se, fl)		set_bit((fl), &(se)->se_flags)
147 #define	SE_CLEAR(se, fl)	clear_bit((fl), &(se)->se_flags)
148 
149 extern void zfsctl_snapshot_timer_clear(zfs_snapentry_t *se);
150 
151 /* zpl_file_range.c */
152 
153 /* handlers for file_operations of the same name */
154 extern ssize_t zpl_copy_file_range(struct file *src_file, loff_t src_off,
155     struct file *dst_file, loff_t dst_off, size_t len, unsigned int flags);
156 extern loff_t zpl_remap_file_range(struct file *src_file, loff_t src_off,
157     struct file *dst_file, loff_t dst_off, loff_t len, unsigned int flags);
158 extern int zpl_clone_file_range(struct file *src_file, loff_t src_off,
159     struct file *dst_file, loff_t dst_off, uint64_t len);
160 extern int zpl_dedupe_file_range(struct file *src_file, loff_t src_off,
161     struct file *dst_file, loff_t dst_off, uint64_t len);
162 
163 
164 #if defined(HAVE_INODE_TIMESTAMP_TRUNCATE)
165 #define	zpl_inode_timestamp_truncate(ts, ip)	timestamp_truncate(ts, ip)
166 #else
167 #define	zpl_inode_timestamp_truncate(ts, ip)	\
168 	timespec64_trunc(ts, (ip)->i_sb->s_time_gran)
169 #endif
170 
171 #ifdef HAVE_INODE_GET_CTIME
172 #define	zpl_inode_get_ctime(ip)	inode_get_ctime(ip)
173 #else
174 #define	zpl_inode_get_ctime(ip)	(ip->i_ctime)
175 #endif
176 #ifdef HAVE_INODE_SET_CTIME_TO_TS
177 #define	zpl_inode_set_ctime_to_ts(ip, ts)	inode_set_ctime_to_ts(ip, ts)
178 #else
179 #define	zpl_inode_set_ctime_to_ts(ip, ts)	(ip->i_ctime = ts)
180 #endif
181 #ifdef HAVE_INODE_GET_ATIME
182 #define	zpl_inode_get_atime(ip)	inode_get_atime(ip)
183 #else
184 #define	zpl_inode_get_atime(ip)	(ip->i_atime)
185 #endif
186 #ifdef HAVE_INODE_SET_ATIME_TO_TS
187 #define	zpl_inode_set_atime_to_ts(ip, ts)	inode_set_atime_to_ts(ip, ts)
188 #else
189 #define	zpl_inode_set_atime_to_ts(ip, ts)	(ip->i_atime = ts)
190 #endif
191 #ifdef HAVE_INODE_GET_MTIME
192 #define	zpl_inode_get_mtime(ip)	inode_get_mtime(ip)
193 #else
194 #define	zpl_inode_get_mtime(ip)	(ip->i_mtime)
195 #endif
196 #ifdef HAVE_INODE_SET_MTIME_TO_TS
197 #define	zpl_inode_set_mtime_to_ts(ip, ts)	inode_set_mtime_to_ts(ip, ts)
198 #else
199 #define	zpl_inode_set_mtime_to_ts(ip, ts)	(ip->i_mtime = ts)
200 #endif
201 
202 #endif	/* _SYS_ZPL_H */
203