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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 /* 26 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 27 * Copyright (c) 2013 by Delphix. All rights reserved. 28 */ 29 30 #ifndef _SYS_ZFS_CONTEXT_H 31 #define _SYS_ZFS_CONTEXT_H 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #include <sys/param.h> 38 #include <sys/stdint.h> 39 #include <sys/note.h> 40 #include <sys/kernel.h> 41 #include <sys/debug.h> 42 #include <sys/systm.h> 43 #include <sys/proc.h> 44 #include <sys/sysmacros.h> 45 #include <sys/bitmap.h> 46 #include <sys/cmn_err.h> 47 #include <sys/kmem.h> 48 #include <sys/taskq.h> 49 #ifndef __NetBSD__ 50 #include <sys/taskqueue.h> 51 #endif 52 #include <sys/systm.h> 53 #include <sys/conf.h> 54 #include <sys/mutex.h> 55 #include <sys/rwlock.h> 56 #include <sys/kcondvar.h> 57 #include <sys/random.h> 58 #include <sys/byteorder.h> 59 #include <sys/systm.h> 60 #include <sys/list.h> 61 #include <sys/zfs_debug.h> 62 #include <sys/sysevent.h> 63 #include <sys/uio.h> 64 #include <sys/dirent.h> 65 #include <sys/time.h> 66 #include <sys/uio.h> 67 #include <sys/fcntl.h> 68 #ifndef __NetBSD__ 69 #include <sys/limits.h> 70 #else 71 #include <sys/syslimits.h> 72 #endif 73 #include <sys/string.h> 74 #ifndef __NetBSD__ 75 #include <sys/bio.h> 76 #endif 77 #include <sys/buf.h> 78 #include <sys/cred.h> 79 #include <sys/sdt.h> 80 #include <sys/file.h> 81 #include <sys/vfs.h> 82 #include <sys/sysctl.h> 83 #ifndef __NetBSD__ 84 #include <sys/sbuf.h> 85 #include <sys/priv.h> 86 #include <sys/kdb.h> 87 #include <sys/ktr.h> 88 #include <sys/stack.h> 89 #endif 90 #include <sys/lockf.h> 91 #include <sys/pathname.h> 92 #include <sys/policy.h> 93 #include <sys/refstr.h> 94 #include <sys/zone.h> 95 #ifndef __NetBSD__ 96 #include <sys/eventhandler.h> 97 #endif 98 #include <sys/extattr.h> 99 #include <sys/misc.h> 100 #ifndef __NetBSD__ 101 #include <sys/sig.h> 102 #include <sys/osd.h> 103 #endif 104 #include <sys/sysevent/dev.h> 105 #include <sys/sysevent/eventdefs.h> 106 #include <sys/u8_textprep.h> 107 #include <sys/fm/util.h> 108 #include <sys/sunddi.h> 109 #if defined(illumos) || defined(__NetBSD__) 110 #include <sys/cyclic.h> 111 #endif 112 #ifndef __NetBSD__ 113 #include <sys/callo.h> 114 #include <sys/disp.h> 115 #include <machine/stdarg.h> 116 117 #include <vm/vm.h> 118 #include <vm/vm_page.h> 119 #include <vm/vm_object.h> 120 #include <vm/vm_kern.h> 121 #include <vm/vm_map.h> 122 /* There is clash. vm_map.h defines the two below and vdev_cache.c use them. */ 123 #ifdef min_offset 124 #undef min_offset 125 #endif 126 #ifdef max_offset 127 #undef max_offset 128 #endif 129 #include <vm/vm_extern.h> 130 #include <vm/vnode_pager.h> 131 #else /* !__NetBSD__ */ 132 #include <sys/callout.h> 133 #include <sys/kernel.h> 134 #include <sys/stdarg.h> 135 136 #include <miscfs/specfs/specdev.h> 137 #endif /* !__NetBSD__ */ 138 139 #ifndef __NetBSD__ 140 141 #define CPU_SEQID (curcpu) 142 143 #define tsd_create(keyp, destructor) do { \ 144 *(keyp) = osd_thread_register((destructor)); \ 145 KASSERT(*(keyp) > 0, ("cannot register OSD")); \ 146 } while (0) 147 #define tsd_destroy(keyp) osd_thread_deregister(*(keyp)) 148 #define tsd_get(key) osd_thread_get(curthread, (key)) 149 #define tsd_set(key, value) osd_thread_set(curthread, (key), (value)) 150 151 #else /* !__NetBSD__ */ 152 153 #define ASSERT_VOP_LOCKED(vp, name) KASSERT(VOP_ISLOCKED(vp) != 0) 154 #define ASSERT_VOP_ELOCKED(vp, name) KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE) 155 #define callout_drain(x) callout_halt(x, NULL) 156 #define CPU_SEQID (curcpu()->ci_data.cpu_index) 157 #define FIGNORECASE 0 158 #define fm_panic panic 159 #define getf fd_getfile 160 #define getminor(a) minor(a) 161 #define GID_NOBODY (39) 162 #define issig(x) (sigispending(curlwp, 0)) 163 #define kmem_debugging() 0 164 #define releasef fd_putfile 165 #define strfree(str) kmem_free((str), strlen(str)+1) 166 #define td_ru l_ru 167 #define UID_NOBODY (32767) 168 #define vnode_pager_setsize(vp, size) zfs_netbsd_setsize(vp, size) 169 #define zone_get_hostid(a) ((unsigned)hostid) 170 171 extern struct utsname utsname; 172 173 void zfs_netbsd_setsize(vnode_t *, off_t); 174 175 static inline int 176 sprintf(char * __restrict buf, const char * __restrict fmt, ...) 177 { 178 va_list ap; 179 int rv; 180 181 va_start(ap, fmt); 182 rv = vsnprintf(buf, 1024, fmt, ap); 183 va_end(ap); 184 return rv; 185 } 186 187 static inline void 188 tsd_create(uint_t *keyp, void (*func)(void *)) 189 { 190 int error __unused; 191 192 error = lwp_specific_key_create(keyp, func); 193 KASSERT(error == 0); 194 } 195 196 static inline void 197 tsd_destroy(uint_t *keyp) 198 { 199 200 lwp_specific_key_delete(*keyp); 201 } 202 203 static inline void * 204 tsd_get(uint_t key) 205 { 206 207 return lwp_getspecific(key); 208 } 209 210 static inline int 211 tsd_set(uint_t key, void *value) 212 { 213 214 lwp_setspecific(key, value); 215 return 0; 216 } 217 218 static inline int 219 vsprintf(char * __restrict buf, const char * __restrict fmt, va_list ap) 220 { 221 222 return vsnprintf(buf, 1024, fmt, ap); 223 } 224 225 #define SYSCTL_DECL(...) 226 #define SYSCTL_NODE(...) 227 #define SYSCTL_INT(...) 228 #define SYSCTL_UINT(...) 229 #define SYSCTL_LONG(...) 230 #define SYSCTL_ULONG(...) 231 #define SYSCTL_QUAD(...) 232 #define SYSCTL_UQUAD(...) 233 #ifdef TUNABLE_INT 234 #undef TUNABLE_INT 235 #undef TUNABLE_ULONG 236 #undef TUNABLE_INT_FETCH 237 #endif 238 #define TUNABLE_INT(...) 239 #define TUNABLE_ULONG(...) 240 #define TUNABLE_INT_FETCH(...) 0 241 242 #endif /* !__NetBSD__ */ 243 244 #ifdef __cplusplus 245 } 246 #endif 247 248 extern int zfs_debug_level; 249 #ifndef __NetBSD__ 250 251 extern struct mtx zfs_debug_mtx; 252 #define ZFS_LOG(lvl, ...) do { \ 253 if (((lvl) & 0xff) <= zfs_debug_level) { \ 254 mtx_lock(&zfs_debug_mtx); \ 255 printf("%s:%u[%d]: ", __func__, __LINE__, (lvl)); \ 256 printf(__VA_ARGS__); \ 257 printf("\n"); \ 258 if ((lvl) & 0x100) \ 259 kdb_backtrace(); \ 260 mtx_unlock(&zfs_debug_mtx); \ 261 } \ 262 } while (0) 263 264 #define sys_shutdown rebooting 265 266 #else /* !__NetBSD__ */ 267 268 extern kmutex_t zfs_debug_mtx; 269 #define ZFS_LOG(lvl, ...) do { \ 270 if (((lvl) & 0xff) <= zfs_debug_level) { \ 271 mutex_enter(&zfs_debug_mtx); \ 272 printf("%s:%u[%d]: ", __func__, __LINE__, (lvl)); \ 273 printf(__VA_ARGS__); \ 274 printf("\n"); \ 275 if ((lvl) & 0x100) \ 276 /* XXXNETBSD backtrace */; \ 277 mutex_exit(&zfs_debug_mtx); \ 278 } \ 279 } while (0) 280 281 #define sys_shutdown 0 282 283 #endif /* !__NetBSD__ */ 284 285 #endif /* _SYS_ZFS_CONTEXT_H */ 286