Update GIT documentation to describe the new DAC setup
[zfs.git] / patches / no-debug-userspace.patch
1 Disable debug code on userspace
2
3 Index: zfs+chaos4/lib/libzfscommon/include/sys/arc.h
4 ===================================================================
5 --- zfs+chaos4.orig/lib/libzfscommon/include/sys/arc.h
6 +++ zfs+chaos4/lib/libzfscommon/include/sys/arc.h
7 @@ -82,7 +82,7 @@ int arc_released(arc_buf_t *buf);
8  int arc_has_callback(arc_buf_t *buf);
9  void arc_buf_freeze(arc_buf_t *buf);
10  void arc_buf_thaw(arc_buf_t *buf);
11 -#ifdef ZFS_DEBUG
12 +#if defined(ZFS_DEBUG) || (!defined(_KERNEL) && !defined(NDEBUG))
13  int arc_referenced(arc_buf_t *buf);
14  #endif
15  
16 Index: zfs+chaos4/lib/libzfscommon/include/sys/refcount.h
17 ===================================================================
18 --- zfs+chaos4.orig/lib/libzfscommon/include/sys/refcount.h
19 +++ zfs+chaos4/lib/libzfscommon/include/sys/refcount.h
20 @@ -43,7 +43,7 @@ extern "C" {
21   */
22  #define        FTAG ((char *)__func__)
23  
24 -#if defined(DEBUG) || !defined(_KERNEL)
25 +#if defined(DEBUG)
26  typedef struct reference {
27         list_node_t ref_link;
28         void *ref_holder;
29 Index: zfs+chaos4/lib/libzfscommon/include/sys/zfs_context_user.h
30 ===================================================================
31 --- zfs+chaos4.orig/lib/libzfscommon/include/sys/zfs_context_user.h
32 +++ zfs+chaos4/lib/libzfscommon/include/sys/zfs_context_user.h
33 @@ -96,6 +96,8 @@ extern "C" {
34  
35  #ifdef ZFS_DEBUG
36  extern void dprintf_setup(int *argc, char **argv);
37 +#else
38 +#define dprintf_setup(ac,av) ((void) 0)
39  #endif /* ZFS_DEBUG */
40  
41  extern void cmn_err(int, const char *, ...);
42 @@ -105,21 +107,26 @@ extern void vpanic(const char *, __va_li
43  
44  #define        fm_panic        panic
45  
46 +#ifndef zp_verify
47  /* This definition is copied from assert.h. */
48  #if defined(__STDC__)
49  #if __STDC_VERSION__ - 0 >= 199901L
50 -#define        verify(EX) (void)((EX) || \
51 +#define        zp_verify(EX) (void)((EX) || \
52         (__assert_c99(#EX, __FILE__, __LINE__, __func__), 0))
53  #else
54 -#define        verify(EX) (void)((EX) || (__assert(#EX, __FILE__, __LINE__), 0))
55 +#define        zp_verify(EX) (void)((EX) || (__assert(#EX, __FILE__, __LINE__), 0))
56  #endif /* __STDC_VERSION__ - 0 >= 199901L */
57  #else
58 -#define        verify(EX) (void)((EX) || (_assert("EX", __FILE__, __LINE__), 0))
59 +#define        zp_verify(EX) (void)((EX) || (_assert("EX", __FILE__, __LINE__), 0))
60  #endif /* __STDC__ */
61 +#endif
62  
63 -
64 -#define        VERIFY  verify
65 +#ifndef VERIFY
66 +#define        VERIFY  zp_verify
67 +#endif
68 +#ifndef ASSERT
69  #define        ASSERT  assert
70 +#endif
71  
72  extern void __assert(const char *, const char *, int);
73  
74 @@ -332,6 +339,7 @@ extern int  taskq_member(taskq_t *, void 
75  typedef struct vnode {
76         uint64_t        v_size;
77         int             v_fd;
78 +       mode_t          v_mode;
79         char            *v_path;
80  } vnode_t;
81  
82 Index: zfs+chaos4/lib/libzfscommon/include/sys/zfs_debug.h
83 ===================================================================
84 --- zfs+chaos4.orig/lib/libzfscommon/include/sys/zfs_debug.h
85 +++ zfs+chaos4/lib/libzfscommon/include/sys/zfs_debug.h
86 @@ -44,7 +44,7 @@ extern "C" {
87   * ZFS debugging
88   */
89  
90 -#if defined(DEBUG) || !defined(_KERNEL)
91 +#if defined(DEBUG)
92  #define        ZFS_DEBUG
93  #endif
94  
95 Index: zfs+chaos4/lib/libzpool/arc.c
96 ===================================================================
97 --- zfs+chaos4.orig/lib/libzpool/arc.c
98 +++ zfs+chaos4/lib/libzpool/arc.c
99 @@ -1802,7 +1802,7 @@ arc_reclaim_needed(void)
100                 return (1);
101  #endif
102  
103 -#else
104 +#elif defined(ZFS_DEBUG)
105         if (spa_get_random(100) == 0)
106                 return (1);
107  #endif
108 @@ -2881,7 +2881,7 @@ arc_has_callback(arc_buf_t *buf)
109         return (buf->b_efunc != NULL);
110  }
111  
112 -#ifdef ZFS_DEBUG
113 +#if defined(ZFS_DEBUG) || (!defined(_KERNEL) && !defined(NDEBUG))
114  int
115  arc_referenced(arc_buf_t *buf)
116  {
117 Index: zfs+chaos4/lib/libzpool/kernel.c
118 ===================================================================
119 --- zfs+chaos4.orig/lib/libzpool/kernel.c
120 +++ zfs+chaos4/lib/libzpool/kernel.c
121 @@ -384,6 +384,7 @@ vn_open(char *path, int x1, int flags, i
122  
123         vp->v_fd = fd;
124         vp->v_size = st.st_size;
125 +       vp->v_mode = st.st_mode;
126         vp->v_path = spa_strdup(path);
127  
128         return (0);
129 @@ -422,10 +423,17 @@ vn_rdwr(int uio, vnode_t *vp, void *addr
130                  * To simulate partial disk writes, we split writes into two
131                  * system calls so that the process can be killed in between.
132                  */
133 -               split = (len > 0 ? rand() % len : 0);
134 -               iolen = pwrite64(vp->v_fd, addr, split, offset);
135 -               iolen += pwrite64(vp->v_fd, (char *)addr + split,
136 -                   len - split, offset + split);
137 +#ifdef ZFS_DEBUG
138 +               if (!S_ISBLK(vp->v_mode) && !S_ISCHR(vp->v_mode)) {
139 +                       split = (len > 0 ? rand() % len : 0);
140 +                       iolen = pwrite64(vp->v_fd, addr, split, offset);
141 +                       iolen += pwrite64(vp->v_fd, (char *)addr + split,
142 +                           len - split, offset + split);
143 +               } else
144 +                       iolen = pwrite64(vp->v_fd, addr, len, offset);
145 +#else
146 +               iolen = pwrite64(vp->v_fd, addr, len, offset);
147 +#endif
148         }
149  
150         if (iolen < 0)
151 Index: zfs+chaos4/lib/libzpool/refcount.c
152 ===================================================================
153 --- zfs+chaos4.orig/lib/libzpool/refcount.c
154 +++ zfs+chaos4/lib/libzpool/refcount.c
155 @@ -28,7 +28,7 @@
156  #include <sys/zfs_context.h>
157  #include <sys/refcount.h>
158  
159 -#if defined(DEBUG) || !defined(_KERNEL)
160 +#if defined(DEBUG)
161  
162  #ifdef _KERNEL
163  int reference_tracking_enable = FALSE; /* runs out of memory too easily */
164 Index: zfs+chaos4/lib/libzpool/spa_misc.c
165 ===================================================================
166 --- zfs+chaos4.orig/lib/libzpool/spa_misc.c
167 +++ zfs+chaos4/lib/libzpool/spa_misc.c
168 @@ -178,11 +178,15 @@ kmem_cache_t *spa_buffer_pool;
169  int spa_mode;
170  
171  #ifdef ZFS_DEBUG
172 +#ifdef _KERNEL
173  /* Everything except dprintf is on by default in debug builds */
174  int zfs_flags = ~ZFS_DEBUG_DPRINTF;
175  #else
176 +int zfs_flags = ~0;
177 +#endif /* _KERNEL */
178 +#else
179  int zfs_flags = 0;
180 -#endif
181 +#endif /* ZFS_DEBUG */
182  
183  /*
184   * zfs_recover can be set to nonzero to attempt to recover from