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
9  * or http://www.opensolaris.org/os/licensing.
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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
24  * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
25  */
26 
27 #ifndef	_SYS_ZFS_ZNODE_IMPL_H
28 #define	_SYS_ZFS_ZNODE_IMPL_H
29 
30 #ifndef _KERNEL
31 #error "no user serviceable parts within"
32 #endif
33 
34 #include <sys/isa_defs.h>
35 #include <sys/types32.h>
36 #include <sys/list.h>
37 #include <sys/dmu.h>
38 #include <sys/sa.h>
39 #include <sys/zfs_vfsops.h>
40 #include <sys/rrwlock.h>
41 #include <sys/zfs_sa.h>
42 #include <sys/zfs_stat.h>
43 #include <sys/zfs_rlock.h>
44 
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 #define	ZNODE_OS_FIELDS			\
51 	struct inode	z_inode;
52 
53 
54 /*
55  * Convert between znode pointers and inode pointers
56  */
57 #define	ZTOI(znode)	(&((znode)->z_inode))
58 #define	ITOZ(inode)	(container_of((inode), znode_t, z_inode))
59 #define	ZTOZSB(znode)	((zfsvfs_t *)(ZTOI(znode)->i_sb->s_fs_info))
60 #define	ITOZSB(inode)	((zfsvfs_t *)((inode)->i_sb->s_fs_info))
61 
62 #define	ZTOTYPE(zp)	(ZTOI(zp)->i_mode)
63 #define	ZTOGID(zp) (ZTOI(zp)->i_gid)
64 #define	ZTOUID(zp) (ZTOI(zp)->i_uid)
65 #define	ZTONLNK(zp) (ZTOI(zp)->i_nlink)
66 
67 #define	Z_ISBLK(type) S_ISBLK(type)
68 #define	Z_ISCHR(type) S_ISCHR(type)
69 #define	Z_ISLNK(type) S_ISLNK(type)
70 #define	Z_ISDEV(type)	(S_ISCHR(type) || S_ISBLK(type) || S_ISFIFO(type))
71 #define	Z_ISDIR(type)	S_ISDIR(type)
72 
73 #define	zn_has_cached_data(zp)	((zp)->z_is_mapped)
74 #define	zn_rlimit_fsize(zp, uio, td)	(0)
75 
76 #define	zhold(zp)	igrab(ZTOI((zp)))
77 #define	zrele(zp)	iput(ZTOI((zp)))
78 
79 /* Called on entry to each ZFS inode and vfs operation. */
80 #define	ZFS_ENTER_ERROR(zfsvfs, error)				\
81 do {								\
82 	ZFS_TEARDOWN_ENTER_READ(zfsvfs, FTAG);			\
83 	if (unlikely((zfsvfs)->z_unmounted)) {			\
84 		ZFS_EXIT_READ(zfsvfs, FTAG);			\
85 		return (error);					\
86 	}							\
87 } while (0)
88 #define	ZFS_ENTER(zfsvfs)	ZFS_ENTER_ERROR(zfsvfs, EIO)
89 #define	ZPL_ENTER(zfsvfs)	ZFS_ENTER_ERROR(zfsvfs, -EIO)
90 
91 /* Must be called before exiting the operation. */
92 #define	ZFS_EXIT(zfsvfs)					\
93 do {								\
94 	zfs_exit_fs(zfsvfs);					\
95 	ZFS_EXIT_READ(zfsvfs, FTAG);				\
96 } while (0)
97 
98 #define	ZPL_EXIT(zfsvfs)					\
99 do {								\
100 	rrm_exit(&(zfsvfs)->z_teardown_lock, FTAG);		\
101 } while (0)
102 
103 /* Verifies the znode is valid. */
104 #define	ZFS_VERIFY_ZP_ERROR(zp, error)				\
105 do {								\
106 	if (unlikely((zp)->z_sa_hdl == NULL)) {			\
107 		ZFS_EXIT(ZTOZSB(zp));				\
108 		return (error);					\
109 	}							\
110 } while (0)
111 #define	ZFS_VERIFY_ZP(zp)	ZFS_VERIFY_ZP_ERROR(zp, EIO)
112 #define	ZPL_VERIFY_ZP(zp)	ZFS_VERIFY_ZP_ERROR(zp, -EIO)
113 
114 /*
115  * Macros for dealing with dmu_buf_hold
116  */
117 #define	ZFS_OBJ_MTX_SZ		64
118 #define	ZFS_OBJ_MTX_MAX		(1024 * 1024)
119 #define	ZFS_OBJ_HASH(zfsvfs, obj)	((obj) & ((zfsvfs->z_hold_size) - 1))
120 
121 extern unsigned int zfs_object_mutex_size;
122 
123 /*
124  * Encode ZFS stored time values from a struct timespec / struct timespec64.
125  */
126 #define	ZFS_TIME_ENCODE(tp, stmp)		\
127 do {						\
128 	(stmp)[0] = (uint64_t)(tp)->tv_sec;	\
129 	(stmp)[1] = (uint64_t)(tp)->tv_nsec;	\
130 } while (0)
131 
132 #if defined(HAVE_INODE_TIMESPEC64_TIMES)
133 /*
134  * Decode ZFS stored time values to a struct timespec64
135  * 4.18 and newer kernels.
136  */
137 #define	ZFS_TIME_DECODE(tp, stmp)		\
138 do {						\
139 	(tp)->tv_sec = (time64_t)(stmp)[0];	\
140 	(tp)->tv_nsec = (long)(stmp)[1];	\
141 } while (0)
142 #else
143 /*
144  * Decode ZFS stored time values to a struct timespec
145  * 4.17 and older kernels.
146  */
147 #define	ZFS_TIME_DECODE(tp, stmp)		\
148 do {						\
149 	(tp)->tv_sec = (time_t)(stmp)[0];	\
150 	(tp)->tv_nsec = (long)(stmp)[1];	\
151 } while (0)
152 #endif /* HAVE_INODE_TIMESPEC64_TIMES */
153 
154 #define	ZFS_ACCESSTIME_STAMP(zfsvfs, zp)
155 
156 struct znode;
157 
158 extern int	zfs_sync(struct super_block *, int, cred_t *);
159 extern int	zfs_inode_alloc(struct super_block *, struct inode **ip);
160 extern void	zfs_inode_destroy(struct inode *);
161 extern void	zfs_inode_update(struct znode *);
162 extern void	zfs_mark_inode_dirty(struct inode *);
163 extern boolean_t zfs_relatime_need_update(const struct inode *);
164 
165 #if defined(HAVE_UIO_RW)
166 extern caddr_t zfs_map_page(page_t *, enum seg_rw);
167 extern void zfs_unmap_page(page_t *, caddr_t);
168 #endif /* HAVE_UIO_RW */
169 
170 extern zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE];
171 extern int zfsfstype;
172 
173 #ifdef	__cplusplus
174 }
175 #endif
176 
177 #endif	/* _SYS_ZFS_ZNODE_IMPL_H */
178