Add linux unused code tracking
[zfs.git] / lib / libzpool / include / sys / zfs_context.h
index 9a6d712..5dd64b7 100644 (file)
@@ -19,8 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 #ifndef _SYS_ZFS_CONTEXT_H
@@ -50,8 +49,7 @@ extern "C" {
 #include <errno.h>
 #include <string.h>
 #include <strings.h>
-#include <synch.h>
-#include <thread.h>
+#include <pthread.h>
 #include <assert.h>
 #include <alloca.h>
 #include <umem.h>
@@ -59,7 +57,6 @@ extern "C" {
 #include <atomic.h>
 #include <dirent.h>
 #include <time.h>
-#include <libsysevent.h>
 #include <sys/note.h>
 #include <sys/types.h>
 #include <sys/cred.h>
@@ -73,11 +70,16 @@ extern "C" {
 #include <sys/sdt.h>
 #include <sys/kstat.h>
 #include <sys/u8_textprep.h>
-#include <sys/sysevent/eventdefs.h>
-#include <sys/sysevent/dev.h>
+#include <sys/fm/fs/zfs.h>
 #include <sys/sunddi.h>
 
 /*
+ * Stack
+ */
+
+#define  noinline      __attribute__((noinline))
+
+/*
  * Debugging
  */
 
@@ -91,6 +93,8 @@ extern "C" {
 #define        CE_PANIC        3       /* panic                */
 #define        CE_IGNORE       4       /* print nothing        */
 
+extern int aok;
+
 /*
  * ZFS debugging
  */
@@ -106,62 +110,6 @@ extern void vpanic(const char *, __va_list);
 
 #define        fm_panic        panic
 
-extern int aok;
-
-/* This definition is copied from assert.h. */
-#if defined(__STDC__)
-#if __STDC_VERSION__ - 0 >= 199901L
-#define        zverify(EX) (void)((EX) || (aok) || \
-       (__assert_c99(#EX, __FILE__, __LINE__, __func__), 0))
-#else
-#define        zverify(EX) (void)((EX) || (aok) || \
-       (__assert(#EX, __FILE__, __LINE__), 0))
-#endif /* __STDC_VERSION__ - 0 >= 199901L */
-#else
-#define        zverify(EX) (void)((EX) || (aok) || \
-       (_assert("EX", __FILE__, __LINE__), 0))
-#endif /* __STDC__ */
-
-
-#define        VERIFY  zverify
-#define        ASSERT  zverify
-#undef assert
-#define        assert  zverify
-
-extern void __assert(const char *, const char *, int);
-
-#ifdef lint
-#define        VERIFY3_IMPL(x, y, z, t)        if (x == z) ((void)0)
-#else
-/* BEGIN CSTYLED */
-#define        VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
-       const TYPE __left = (TYPE)(LEFT); \
-       const TYPE __right = (TYPE)(RIGHT); \
-       if (!(__left OP __right) && (!aok)) { \
-               char *__buf = alloca(256); \
-               (void) snprintf(__buf, 256, "%s %s %s (0x%llx %s 0x%llx)", \
-                       #LEFT, #OP, #RIGHT, \
-                       (u_longlong_t)__left, #OP, (u_longlong_t)__right); \
-               __assert(__buf, __FILE__, __LINE__); \
-       } \
-_NOTE(CONSTCOND) } while (0)
-/* END CSTYLED */
-#endif /* lint */
-
-#define        VERIFY3S(x, y, z)       VERIFY3_IMPL(x, y, z, int64_t)
-#define        VERIFY3U(x, y, z)       VERIFY3_IMPL(x, y, z, uint64_t)
-#define        VERIFY3P(x, y, z)       VERIFY3_IMPL(x, y, z, uintptr_t)
-
-#ifdef NDEBUG
-#define        ASSERT3S(x, y, z)       ((void)0)
-#define        ASSERT3U(x, y, z)       ((void)0)
-#define        ASSERT3P(x, y, z)       ((void)0)
-#else
-#define        ASSERT3S(x, y, z)       VERIFY3S(x, y, z)
-#define        ASSERT3U(x, y, z)       VERIFY3U(x, y, z)
-#define        ASSERT3P(x, y, z)       VERIFY3P(x, y, z)
-#endif
-
 /*
  * DTrace SDT probes have different signatures in userland than they do in
  * kernel.  If they're being used in kernel code, re-define them out of
@@ -196,27 +144,55 @@ _NOTE(CONSTCOND) } while (0)
 /*
  * Threads
  */
-#define        curthread       ((void *)(uintptr_t)thr_self())
-
-typedef struct kthread kthread_t;
-
-#define        thread_create(stk, stksize, func, arg, len, pp, state, pri)     \
-       zk_thread_create(func, arg)
-#define        thread_exit() thr_exit(NULL)
-#define        thread_join(t)  panic("libzpool cannot join threads")
+#define        TS_MAGIC                0x72f158ab4261e538ull
+#define        TS_RUN                  0x00000002
+#ifdef __linux__
+#define        STACK_SIZE              8192    /* Linux x86 and amd64 */
+#else
+#define        STACK_SIZE              24576   /* Solaris */
+#endif
 
-#define        newproc(f, a, cid, pri, ctp, pid)       (ENOSYS)
+#ifdef NPTL_GUARD_WITHIN_STACK
+#define        EXTRA_GUARD_BYTES       PAGESIZE
+#else
+#define        EXTRA_GUARD_BYTES       0
+#endif
 
 /* in libzpool, p0 exists only to have its address taken */
-struct proc {
+typedef struct proc {
        uintptr_t       this_is_never_used_dont_dereference_it;
-};
+} proc_t;
 
 extern struct proc p0;
 
-#define        PS_NONE         -1
+typedef void (*thread_func_t)(void *);
+typedef void (*thread_func_arg_t)(void *);
+typedef pthread_t kt_did_t;
+
+typedef struct kthread {
+       kt_did_t        t_tid;
+       thread_func_t   t_func;
+       void *          t_arg;
+} kthread_t;
+
+#define        tsd_get(key)                    pthread_getspecific(key)
+#define        tsd_set(key, val)               pthread_setspecific(key, val)
+#define        curthread                       zk_thread_current()
+#define        thread_exit                     zk_thread_exit
+#define        thread_create(stk, stksize, func, arg, len, pp, state, pri)     \
+       zk_thread_create(stk, stksize, (thread_func_t)func, arg,        \
+                        len, NULL, state, pri)
+#define        thread_join(t)                  zk_thread_join(t)
+#define        newproc(f,a,cid,pri,ctp,pid)    (ENOSYS)
+
+extern kthread_t *zk_thread_current(void);
+extern void zk_thread_exit(void);
+extern kthread_t *zk_thread_create(caddr_t stk, size_t  stksize,
+       thread_func_t func, void *arg, size_t len,
+       proc_t *pp, int state, pri_t pri);
+extern void zk_thread_join(kt_did_t tid);
 
-extern kthread_t *zk_thread_create(void (*func)(), void *arg);
+#define        PS_NONE         -1
 
 #define        issig(why)      (FALSE)
 #define        ISSIG(thr, why) (FALSE)
@@ -224,53 +200,52 @@ extern kthread_t *zk_thread_create(void (*func)(), void *arg);
 /*
  * Mutexes
  */
+#define        MTX_MAGIC       0x9522f51362a6e326ull
+#define        MTX_INIT        ((void *)NULL)
+#define        MTX_DEST        ((void *)-1UL)
+
 typedef struct kmutex {
        void            *m_owner;
-       boolean_t       initialized;
-       mutex_t         m_lock;
+       uint64_t        m_magic;
+       pthread_mutex_t m_lock;
 } kmutex_t;
 
-#define        MUTEX_DEFAULT   USYNC_THREAD
-#undef MUTEX_HELD
-#define        MUTEX_HELD(m) _mutex_held(&(m)->m_lock)
-
-/*
- * Argh -- we have to get cheesy here because the kernel and userland
- * have different signatures for the same routine.
- */
-extern int _mutex_init(mutex_t *mp, int type, void *arg);
-extern int _mutex_destroy(mutex_t *mp);
-
-#define        mutex_init(mp, b, c, d)         zmutex_init((kmutex_t *)(mp))
-#define        mutex_destroy(mp)               zmutex_destroy((kmutex_t *)(mp))
+#define        MUTEX_DEFAULT   0
+#define MUTEX_HELD(m)  ((m)->m_owner == curthread)
+#define        MUTEX_NOT_HELD(m) (!MUTEX_HELD(m))
 
-extern void zmutex_init(kmutex_t *mp);
-extern void zmutex_destroy(kmutex_t *mp);
+extern void mutex_init(kmutex_t *mp, char *name, int type, void *cookie);
+extern void mutex_destroy(kmutex_t *mp);
 extern void mutex_enter(kmutex_t *mp);
 extern void mutex_exit(kmutex_t *mp);
 extern int mutex_tryenter(kmutex_t *mp);
 extern void *mutex_owner(kmutex_t *mp);
+extern int mutex_held(kmutex_t *mp);
 
 /*
  * RW locks
  */
+#define        RW_MAGIC        0x4d31fb123648e78aull
+#define        RW_INIT         ((void *)NULL)
+#define        RW_DEST         ((void *)-1UL)
+
 typedef struct krwlock {
-       void            *rw_owner;
-       boolean_t       initialized;
-       rwlock_t        rw_lock;
+       void                    *rw_owner;
+       void                    *rw_wr_owner;
+       uint64_t                rw_magic;
+       pthread_rwlock_t        rw_lock;
+       uint_t                  rw_readers;
 } krwlock_t;
 
 typedef int krw_t;
 
 #define        RW_READER       0
 #define        RW_WRITER       1
-#define        RW_DEFAULT      USYNC_THREAD
-
-#undef RW_READ_HELD
-#define        RW_READ_HELD(x)         _rw_read_held(&(x)->rw_lock)
+#define RW_DEFAULT     RW_READER
 
-#undef RW_WRITE_HELD
-#define        RW_WRITE_HELD(x)        _rw_write_held(&(x)->rw_lock)
+#define        RW_READ_HELD(x)         ((x)->rw_readers > 0)
+#define        RW_WRITE_HELD(x)        ((x)->rw_wr_owner == curthread)
+#define        RW_LOCK_HELD(x)         (RW_READ_HELD(x) || RW_WRITE_HELD(x))
 
 extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg);
 extern void rw_destroy(krwlock_t *rwlp);
@@ -288,9 +263,14 @@ extern gid_t *crgetgroups(cred_t *cr);
 /*
  * Condition variables
  */
-typedef cond_t kcondvar_t;
+#define CV_MAGIC       0xd31ea9a83b1b30c4ull
 
-#define        CV_DEFAULT      USYNC_THREAD
+typedef struct kcondvar {
+       uint64_t                cv_magic;
+       pthread_cond_t          cv;
+} kcondvar_t;
+
+#define        CV_DEFAULT      0
 
 extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
 extern void cv_destroy(kcondvar_t *cv);
@@ -313,20 +293,35 @@ extern void kstat_delete(kstat_t *);
 #define        KM_SLEEP                UMEM_NOFAIL
 #define        KM_PUSHPAGE             KM_SLEEP
 #define        KM_NOSLEEP              UMEM_DEFAULT
+#define        KM_NODEBUG              0x0
 #define        KMC_NODEBUG             UMC_NODEBUG
 #define        kmem_alloc(_s, _f)      umem_alloc(_s, _f)
 #define        kmem_zalloc(_s, _f)     umem_zalloc(_s, _f)
 #define        kmem_free(_b, _s)       umem_free(_b, _s)
+#define        vmem_alloc(_s, _f)      kmem_alloc(_s, _f)
+#define        vmem_zalloc(_s, _f)     kmem_zalloc(_s, _f)
+#define        vmem_free(_b, _s)       kmem_free(_b, _s)
 #define        kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \
        umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i)
 #define        kmem_cache_destroy(_c)  umem_cache_destroy(_c)
 #define        kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f)
 #define        kmem_cache_free(_c, _b) umem_cache_free(_c, _b)
 #define        kmem_debugging()        0
-#define        kmem_cache_reap_now(c)
+#define        kmem_cache_reap_now(_c)         /* nothing */
+#define        kmem_cache_set_move(_c, _cb)    /* nothing */
+#define        POINTER_INVALIDATE(_pp)         /* nothing */
+#define        POINTER_IS_VALID(_p)    0
 
 typedef umem_cache_t kmem_cache_t;
 
+typedef enum kmem_cbrc {
+       KMEM_CBRC_YES,
+       KMEM_CBRC_NO,
+       KMEM_CBRC_LATER,
+       KMEM_CBRC_DONT_NEED,
+       KMEM_CBRC_DONT_KNOW
+} kmem_cbrc_t;
+
 /*
  * Task queues
  */
@@ -355,7 +350,7 @@ extern taskq_t      *taskq_create(const char *, int, pri_t, int, int, uint_t);
 extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
 extern void    taskq_destroy(taskq_t *);
 extern void    taskq_wait(taskq_t *);
-extern int     taskq_member(taskq_t *, void *);
+extern int     taskq_member(taskq_t *, kthread_t *);
 extern void    system_taskq_init(void);
 extern void    system_taskq_fini(void);
 
@@ -389,6 +384,8 @@ typedef struct xoptattr {
        uint8_t         xoa_av_modified;
        uint8_t         xoa_av_scanstamp[AV_SCANSTAMP_SZ];
        uint8_t         xoa_reparse;
+       uint8_t         xoa_offline;
+       uint8_t         xoa_sparse;
 } xoptattr_t;
 
 typedef struct vattr {
@@ -482,7 +479,7 @@ extern void delay(clock_t ticks);
 #define        minclsyspri     60
 #define        maxclsyspri     99
 
-#define        CPU_SEQID       (thr_self() & (max_ncpus - 1))
+#define        CPU_SEQID       (pthread_self() & (max_ncpus - 1))
 
 #define        kcred           NULL
 #define        CRED()          NULL
@@ -526,6 +523,7 @@ typedef struct callb_cpr {
 #define        zone_dataset_visible(x, y)      (1)
 #define        INGLOBALZONE(z)                 (1)
 
+extern char *kmem_vasprintf(const char *fmt, va_list adx);
 extern char *kmem_asprintf(const char *fmt, ...);
 #define        strfree(str) kmem_free((str), strlen(str)+1)