]> git.proxmox.com Git - mirror_zfs.git/blame - include/os/linux/zfs/sys/zpl.h
Linux 6.7 compat: use inode atime/mtime accessors
[mirror_zfs.git] / include / os / linux / zfs / sys / zpl.h
CommitLineData
1efb473f
BB
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1d3ba0bf 9 * or https://opensource.org/licenses/CDDL-1.0.
1efb473f
BB
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
23 */
24
25#ifndef _SYS_ZPL_H
26#define _SYS_ZPL_H
27
0282c413 28#include <sys/mntent.h>
1efb473f 29#include <sys/vfs.h>
aaed7c40 30#include <linux/aio.h>
7b3e34ba 31#include <linux/dcache_compat.h>
055656d4 32#include <linux/exportfs.h>
cb2d1901 33#include <linux/falloc.h>
0282c413 34#include <linux/parser.h>
e3dc14b8 35#include <linux/task_io_accounting_ops.h>
aaed7c40
NB
36#include <linux/vfs_compat.h>
37#include <linux/writeback.h>
38#include <linux/xattr_compat.h>
1efb473f
BB
39
40/* zpl_inode.c */
ebe7e575 41extern void zpl_vap_init(vattr_t *vap, struct inode *dir,
d4dc53da 42 umode_t mode, cred_t *cr, zidmap_t *mnt_ns);
ebe7e575 43
1efb473f 44extern const struct inode_operations zpl_inode_operations;
dbf6108b
AS
45#ifdef HAVE_RENAME2_OPERATIONS_WRAPPER
46extern const struct inode_operations_wrapper zpl_dir_inode_operations;
47#else
1efb473f 48extern const struct inode_operations zpl_dir_inode_operations;
dbf6108b 49#endif
1efb473f
BB
50extern const struct inode_operations zpl_symlink_inode_operations;
51extern const struct inode_operations zpl_special_inode_operations;
86db35c4
PS
52
53/* zpl_file.c */
1efb473f 54extern const struct address_space_operations zpl_address_space_operations;
6b0a4be5
RN
55#ifdef HAVE_VFS_FILE_OPERATIONS_EXTEND
56extern const struct file_operations_extend zpl_file_operations;
57#else
1efb473f 58extern const struct file_operations zpl_file_operations;
6b0a4be5 59#endif
1efb473f
BB
60extern const struct file_operations zpl_dir_file_operations;
61
62/* zpl_super.c */
799e09f7 63extern void zpl_prune_sb(uint64_t nr_to_scan, void *arg);
ab26409d 64
1efb473f 65extern const struct super_operations zpl_super_operations;
055656d4 66extern const struct export_operations zpl_export_operations;
1efb473f
BB
67extern struct file_system_type zpl_fs_type;
68
69/* zpl_xattr.c */
70extern ssize_t zpl_xattr_list(struct dentry *dentry, char *buf, size_t size);
5c03efc3
BB
71extern int zpl_xattr_security_init(struct inode *ip, struct inode *dip,
72 const struct qstr *qstr);
b695c34e 73#if defined(CONFIG_FS_POSIX_ACL)
066e8252 74#if defined(HAVE_SET_ACL)
d4dc53da
YY
75#if defined(HAVE_SET_ACL_IDMAP_DENTRY)
76extern int zpl_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
77 struct posix_acl *acl, int type);
78#elif defined(HAVE_SET_ACL_USERNS)
ba646e3e
RE
79extern int zpl_set_acl(struct user_namespace *userns, struct inode *ip,
80 struct posix_acl *acl, int type);
9cd71c86
CK
81#elif defined(HAVE_SET_ACL_USERNS_DENTRY_ARG2)
82extern int zpl_set_acl(struct user_namespace *userns, struct dentry *dentry,
83 struct posix_acl *acl, int type);
ba646e3e 84#else
0420c126 85extern int zpl_set_acl(struct inode *ip, struct posix_acl *acl, int type);
ba646e3e 86#endif /* HAVE_SET_ACL_USERNS */
066e8252 87#endif /* HAVE_SET_ACL */
884a6935 88#if defined(HAVE_GET_ACL_RCU) || defined(HAVE_GET_INODE_ACL)
2079111f
BB
89extern struct posix_acl *zpl_get_acl(struct inode *ip, int type, bool rcu);
90#elif defined(HAVE_GET_ACL)
023699cd 91extern struct posix_acl *zpl_get_acl(struct inode *ip, int type);
2079111f 92#endif
023699cd
MM
93extern int zpl_init_acl(struct inode *ip, struct inode *dir);
94extern int zpl_chmod_acl(struct inode *ip);
b695c34e
MM
95#else
96static inline int
97zpl_init_acl(struct inode *ip, struct inode *dir)
98{
99 return (0);
100}
101
102static inline int
103zpl_chmod_acl(struct inode *ip)
104{
105 return (0);
106}
107#endif /* CONFIG_FS_POSIX_ACL */
1efb473f 108
777d4af8 109extern xattr_handler_t *zpl_xattr_handlers[];
1efb473f 110
ebe7e575
BB
111/* zpl_ctldir.c */
112extern const struct file_operations zpl_fops_root;
113extern const struct inode_operations zpl_ops_root;
114
115extern const struct file_operations zpl_fops_snapdir;
116extern const struct inode_operations zpl_ops_snapdir;
ebe7e575
BB
117
118extern const struct file_operations zpl_fops_shares;
119extern const struct inode_operations zpl_ops_shares;
120
9baaa7de 121#if defined(HAVE_VFS_ITERATE) || defined(HAVE_VFS_ITERATE_SHARED)
0f37d0c8 122
9464b959 123#define ZPL_DIR_CONTEXT_INIT(_dirent, _actor, _pos) { \
0f37d0c8
RY
124 .actor = _actor, \
125 .pos = _pos, \
126}
127
9464b959
BB
128typedef struct dir_context zpl_dir_context_t;
129
130#define zpl_dir_emit dir_emit
131#define zpl_dir_emit_dot dir_emit_dot
132#define zpl_dir_emit_dotdot dir_emit_dotdot
133#define zpl_dir_emit_dots dir_emit_dots
134
0f37d0c8
RY
135#else
136
9464b959 137typedef struct zpl_dir_context {
0f37d0c8
RY
138 void *dirent;
139 const filldir_t actor;
140 loff_t pos;
9464b959 141} zpl_dir_context_t;
0f37d0c8 142
9464b959 143#define ZPL_DIR_CONTEXT_INIT(_dirent, _actor, _pos) { \
0f37d0c8
RY
144 .dirent = _dirent, \
145 .actor = _actor, \
146 .pos = _pos, \
147}
148
149static inline bool
9464b959 150zpl_dir_emit(zpl_dir_context_t *ctx, const char *name, int namelen,
0f37d0c8
RY
151 uint64_t ino, unsigned type)
152{
02730c33 153 return (!ctx->actor(ctx->dirent, name, namelen, ctx->pos, ino, type));
0f37d0c8
RY
154}
155
156static inline bool
9464b959 157zpl_dir_emit_dot(struct file *file, zpl_dir_context_t *ctx)
0f37d0c8 158{
d1d7e268 159 return (ctx->actor(ctx->dirent, ".", 1, ctx->pos,
d9c97ec0 160 file_inode(file)->i_ino, DT_DIR) == 0);
0f37d0c8
RY
161}
162
163static inline bool
9464b959 164zpl_dir_emit_dotdot(struct file *file, zpl_dir_context_t *ctx)
0f37d0c8 165{
d1d7e268 166 return (ctx->actor(ctx->dirent, "..", 2, ctx->pos,
d9c97ec0 167 parent_ino(file_dentry(file)), DT_DIR) == 0);
0f37d0c8
RY
168}
169
170static inline bool
9464b959 171zpl_dir_emit_dots(struct file *file, zpl_dir_context_t *ctx)
0f37d0c8
RY
172{
173 if (ctx->pos == 0) {
9464b959 174 if (!zpl_dir_emit_dot(file, ctx))
d1d7e268 175 return (false);
0f37d0c8
RY
176 ctx->pos = 1;
177 }
178 if (ctx->pos == 1) {
9464b959 179 if (!zpl_dir_emit_dotdot(file, ctx))
d1d7e268 180 return (false);
0f37d0c8
RY
181 ctx->pos = 2;
182 }
d1d7e268 183 return (true);
0f37d0c8
RY
184}
185#endif /* HAVE_VFS_ITERATE */
186
5a35c68b
RN
187
188/* zpl_file_range.c */
189
190/* handlers for file_operations of the same name */
191extern ssize_t zpl_copy_file_range(struct file *src_file, loff_t src_off,
192 struct file *dst_file, loff_t dst_off, size_t len, unsigned int flags);
193extern loff_t zpl_remap_file_range(struct file *src_file, loff_t src_off,
194 struct file *dst_file, loff_t dst_off, loff_t len, unsigned int flags);
195extern int zpl_clone_file_range(struct file *src_file, loff_t src_off,
196 struct file *dst_file, loff_t dst_off, uint64_t len);
197extern int zpl_dedupe_file_range(struct file *src_file, loff_t src_off,
198 struct file *dst_file, loff_t dst_off, uint64_t len);
199
9927f219
RN
200/* compat for FICLONE/FICLONERANGE/FIDEDUPERANGE ioctls */
201typedef struct {
202 int64_t fcr_src_fd;
203 uint64_t fcr_src_offset;
204 uint64_t fcr_src_length;
205 uint64_t fcr_dest_offset;
206} zfs_ioc_compat_file_clone_range_t;
207
208typedef struct {
209 int64_t fdri_dest_fd;
210 uint64_t fdri_dest_offset;
211 uint64_t fdri_bytes_deduped;
212 int32_t fdri_status;
213 uint32_t fdri_reserved;
214} zfs_ioc_compat_dedupe_range_info_t;
215
216typedef struct {
217 uint64_t fdr_src_offset;
218 uint64_t fdr_src_length;
219 uint16_t fdr_dest_count;
220 uint16_t fdr_reserved1;
221 uint32_t fdr_reserved2;
222 zfs_ioc_compat_dedupe_range_info_t fdr_info[];
223} zfs_ioc_compat_dedupe_range_t;
224
225#define ZFS_IOC_COMPAT_FICLONE _IOW(0x94, 9, int)
226#define ZFS_IOC_COMPAT_FICLONERANGE \
227 _IOW(0x94, 13, zfs_ioc_compat_file_clone_range_t)
228#define ZFS_IOC_COMPAT_FIDEDUPERANGE \
229 _IOWR(0x94, 54, zfs_ioc_compat_dedupe_range_t)
230
231extern long zpl_ioctl_ficlone(struct file *filp, void *arg);
232extern long zpl_ioctl_ficlonerange(struct file *filp, void *arg);
233extern long zpl_ioctl_fideduperange(struct file *filp, void *arg);
234
5a35c68b 235
795699a6
BB
236#if defined(HAVE_INODE_TIMESTAMP_TRUNCATE)
237#define zpl_inode_timestamp_truncate(ts, ip) timestamp_truncate(ts, ip)
238#elif defined(HAVE_INODE_TIMESPEC64_TIMES)
239#define zpl_inode_timestamp_truncate(ts, ip) \
240 timespec64_trunc(ts, (ip)->i_sb->s_time_gran)
6413c95f 241#else
795699a6
BB
242#define zpl_inode_timestamp_truncate(ts, ip) \
243 timespec_trunc(ts, (ip)->i_sb->s_time_gran)
6413c95f
BB
244#endif
245
e2a82961
CK
246#if defined(HAVE_INODE_OWNER_OR_CAPABLE)
247#define zpl_inode_owner_or_capable(ns, ip) inode_owner_or_capable(ip)
d4dc53da 248#elif defined(HAVE_INODE_OWNER_OR_CAPABLE_USERNS)
e2a82961 249#define zpl_inode_owner_or_capable(ns, ip) inode_owner_or_capable(ns, ip)
d4dc53da
YY
250#elif defined(HAVE_INODE_OWNER_OR_CAPABLE_IDMAP)
251#define zpl_inode_owner_or_capable(idmap, ip) inode_owner_or_capable(idmap, ip)
e2a82961
CK
252#else
253#error "Unsupported kernel"
254#endif
255
d4dc53da 256#if defined(HAVE_SETATTR_PREPARE_USERNS) || defined(HAVE_SETATTR_PREPARE_IDMAP)
e2a82961
CK
257#define zpl_setattr_prepare(ns, dentry, ia) setattr_prepare(ns, dentry, ia)
258#else
259/*
260 * Use kernel-provided version, or our own from
261 * linux/vfs_compat.h
262 */
263#define zpl_setattr_prepare(ns, dentry, ia) setattr_prepare(dentry, ia)
264#endif
265
b37f2934
CK
266#ifdef HAVE_INODE_GET_CTIME
267#define zpl_inode_get_ctime(ip) inode_get_ctime(ip)
268#else
269#define zpl_inode_get_ctime(ip) (ip->i_ctime)
270#endif
271#ifdef HAVE_INODE_SET_CTIME_TO_TS
272#define zpl_inode_set_ctime_to_ts(ip, ts) inode_set_ctime_to_ts(ip, ts)
273#else
274#define zpl_inode_set_ctime_to_ts(ip, ts) (ip->i_ctime = ts)
275#endif
db4fc559
RN
276#ifdef HAVE_INODE_GET_ATIME
277#define zpl_inode_get_atime(ip) inode_get_atime(ip)
278#else
279#define zpl_inode_get_atime(ip) (ip->i_atime)
280#endif
281#ifdef HAVE_INODE_SET_ATIME_TO_TS
282#define zpl_inode_set_atime_to_ts(ip, ts) inode_set_atime_to_ts(ip, ts)
283#else
284#define zpl_inode_set_atime_to_ts(ip, ts) (ip->i_atime = ts)
285#endif
286#ifdef HAVE_INODE_GET_MTIME
287#define zpl_inode_get_mtime(ip) inode_get_mtime(ip)
288#else
289#define zpl_inode_get_mtime(ip) (ip->i_mtime)
290#endif
291#ifdef HAVE_INODE_SET_MTIME_TO_TS
292#define zpl_inode_set_mtime_to_ts(ip, ts) inode_set_mtime_to_ts(ip, ts)
293#else
294#define zpl_inode_set_mtime_to_ts(ip, ts) (ip->i_mtime = ts)
295#endif
b37f2934 296
1efb473f 297#endif /* _SYS_ZPL_H */