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 https://opensource.org/licenses/CDDL-1.0. 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/time.h> 40 #include <sys/zfs_vfsops.h> 41 #include <sys/rrwlock.h> 42 #include <sys/zfs_sa.h> 43 #include <sys/zfs_stat.h> 44 #include <sys/zfs_rlock.h> 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 #define ZNODE_OS_FIELDS \ 51 inode_timespec_t z_btime; /* creation/birth time (cached) */ \ 52 struct inode z_inode; 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, start, end) \ 74 filemap_range_has_page(ZTOI(zp)->i_mapping, start, end) 75 76 #define zn_flush_cached_data(zp, sync) write_inode_now(ZTOI(zp), sync) 77 #define zn_rlimit_fsize(size) (0) 78 #define zn_rlimit_fsize_uio(zp, uio) (0) 79 80 /* 81 * zhold() wraps igrab() on Linux, and igrab() may fail when the 82 * inode is in the process of being deleted. As zhold() must only be 83 * called when a ref already exists - so the inode cannot be 84 * mid-deletion - we VERIFY() this. 85 */ 86 #define zhold(zp) VERIFY3P(igrab(ZTOI((zp))), !=, NULL) 87 #define zrele(zp) iput(ZTOI((zp))) 88 89 /* Called on entry to each ZFS inode and vfs operation. */ 90 static inline int 91 zfs_enter(zfsvfs_t *zfsvfs, const char *tag) 92 { 93 ZFS_TEARDOWN_ENTER_READ(zfsvfs, tag); 94 if (unlikely(zfsvfs->z_unmounted)) { 95 ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag); 96 return (SET_ERROR(EIO)); 97 } 98 return (0); 99 } 100 101 /* Must be called before exiting the operation. */ 102 static inline void 103 zfs_exit(zfsvfs_t *zfsvfs, const char *tag) 104 { 105 zfs_exit_fs(zfsvfs); 106 ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag); 107 } 108 109 static inline int 110 zpl_enter(zfsvfs_t *zfsvfs, const char *tag) 111 { 112 return (-zfs_enter(zfsvfs, tag)); 113 } 114 115 static inline void 116 zpl_exit(zfsvfs_t *zfsvfs, const char *tag) 117 { 118 ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag); 119 } 120 121 /* zfs_verify_zp and zfs_enter_verify_zp are defined in zfs_znode.h */ 122 #define zpl_verify_zp(zp) (-zfs_verify_zp(zp)) 123 #define zpl_enter_verify_zp(zfsvfs, zp, tag) \ 124 (-zfs_enter_verify_zp(zfsvfs, zp, tag)) 125 126 /* 127 * Macros for dealing with dmu_buf_hold 128 */ 129 #define ZFS_OBJ_MTX_SZ 64 130 #define ZFS_OBJ_MTX_MAX (1024 * 1024) 131 #define ZFS_OBJ_HASH(zfsvfs, obj) ((obj) & ((zfsvfs->z_hold_size) - 1)) 132 133 extern unsigned int zfs_object_mutex_size; 134 135 /* 136 * Encode ZFS stored time values from a struct timespec / struct timespec64. 137 */ 138 #define ZFS_TIME_ENCODE(tp, stmp) \ 139 do { \ 140 (stmp)[0] = (uint64_t)(tp)->tv_sec; \ 141 (stmp)[1] = (uint64_t)(tp)->tv_nsec; \ 142 } while (0) 143 144 /* 145 * Decode ZFS stored time values to a struct timespec64 146 */ 147 #define ZFS_TIME_DECODE(tp, stmp) \ 148 do { \ 149 (tp)->tv_sec = (time64_t)(stmp)[0]; \ 150 (tp)->tv_nsec = (long)(stmp)[1]; \ 151 } while (0) 152 153 #define ZFS_ACCESSTIME_STAMP(zfsvfs, zp) 154 155 struct znode; 156 157 extern int zfs_sync(struct super_block *, int, cred_t *); 158 extern int zfs_inode_alloc(struct super_block *, struct inode **ip); 159 extern void zfs_inode_destroy(struct inode *); 160 extern void zfs_mark_inode_dirty(struct inode *); 161 extern boolean_t zfs_relatime_need_update(const struct inode *); 162 extern zil_replay_func_t *const zfs_replay_vector[TX_MAX_TYPE]; 163 164 #ifdef __cplusplus 165 } 166 #endif 167 168 #endif /* _SYS_ZFS_ZNODE_IMPL_H */ 169