Skip to content

Commit 8dd86a1

Browse files
ahrensbehlendorf
authored andcommitted
Illumos 5812 - assertion failed in zrl_tryenter(): zr_owner==NULL
5812 assertion failed in zrl_tryenter(): zr_owner==NULL Reviewed by: George Wilson <george@delphix.com> Reviewed by: Alex Reece <alex@delphix.com> Reviewed by: Will Andrews <will@freebsd.org> Approved by: Gordon Ross <gwr@nexenta.com> References: https://www.illumos.org/issues/5812 illumos/illumos-gate@8df1730 Ported-by: DHE <git@dehacked.net> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #3357
1 parent 6186e29 commit 8dd86a1

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

module/zfs/zrlock.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
/*
2222
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23+
* Copyright (c) 2014 by Delphix. All rights reserved.
2324
*/
2425

2526
/*
@@ -43,7 +44,7 @@
4344
* A ZRL can be locked only while there are zero references, so ZRL_LOCKED is
4445
* treated as zero references.
4546
*/
46-
#define ZRL_LOCKED ((uint32_t)-1)
47+
#define ZRL_LOCKED -1
4748
#define ZRL_DESTROYED -2
4849

4950
void
@@ -61,7 +62,7 @@ zrl_init(zrlock_t *zrl)
6162
void
6263
zrl_destroy(zrlock_t *zrl)
6364
{
64-
ASSERT(zrl->zr_refcount == 0);
65+
ASSERT0(zrl->zr_refcount);
6566

6667
mutex_destroy(&zrl->zr_mtx);
6768
zrl->zr_refcount = ZRL_DESTROYED;
@@ -81,7 +82,7 @@ zrl_add(zrlock_t *zrl)
8182
uint32_t cas = atomic_cas_32(
8283
(uint32_t *)&zrl->zr_refcount, n, n + 1);
8384
if (cas == n) {
84-
ASSERT((int32_t)n >= 0);
85+
ASSERT3S((int32_t)n, >=, 0);
8586
#ifdef ZFS_DEBUG
8687
if (zrl->zr_owner == curthread) {
8788
DTRACE_PROBE2(zrlock__reentry,
@@ -99,7 +100,7 @@ zrl_add(zrlock_t *zrl)
99100
while (zrl->zr_refcount == ZRL_LOCKED) {
100101
cv_wait(&zrl->zr_cv, &zrl->zr_mtx);
101102
}
102-
ASSERT(zrl->zr_refcount >= 0);
103+
ASSERT3S(zrl->zr_refcount, >=, 0);
103104
zrl->zr_refcount++;
104105
#ifdef ZFS_DEBUG
105106
zrl->zr_owner = curthread;
@@ -113,14 +114,14 @@ zrl_remove(zrlock_t *zrl)
113114
{
114115
uint32_t n;
115116

116-
n = atomic_dec_32_nv((uint32_t *)&zrl->zr_refcount);
117-
ASSERT((int32_t)n >= 0);
118117
#ifdef ZFS_DEBUG
119118
if (zrl->zr_owner == curthread) {
120119
zrl->zr_owner = NULL;
121120
zrl->zr_caller = NULL;
122121
}
123122
#endif
123+
n = atomic_dec_32_nv((uint32_t *)&zrl->zr_refcount);
124+
ASSERT3S((int32_t)n, >=, 0);
124125
}
125126

126127
int
@@ -133,26 +134,26 @@ zrl_tryenter(zrlock_t *zrl)
133134
(uint32_t *)&zrl->zr_refcount, 0, ZRL_LOCKED);
134135
if (cas == 0) {
135136
#ifdef ZFS_DEBUG
136-
ASSERT(zrl->zr_owner == NULL);
137+
ASSERT3P(zrl->zr_owner, ==, NULL);
137138
zrl->zr_owner = curthread;
138139
#endif
139140
return (1);
140141
}
141142
}
142143

143-
ASSERT((int32_t)n > ZRL_DESTROYED);
144+
ASSERT3S((int32_t)n, >, ZRL_DESTROYED);
144145

145146
return (0);
146147
}
147148

148149
void
149150
zrl_exit(zrlock_t *zrl)
150151
{
151-
ASSERT(zrl->zr_refcount == ZRL_LOCKED);
152+
ASSERT3S(zrl->zr_refcount, ==, ZRL_LOCKED);
152153

153154
mutex_enter(&zrl->zr_mtx);
154155
#ifdef ZFS_DEBUG
155-
ASSERT(zrl->zr_owner == curthread);
156+
ASSERT3P(zrl->zr_owner, ==, curthread);
156157
zrl->zr_owner = NULL;
157158
membar_producer(); /* make sure the owner store happens first */
158159
#endif
@@ -166,7 +167,7 @@ zrl_refcount(zrlock_t *zrl)
166167
{
167168
int n;
168169

169-
ASSERT(zrl->zr_refcount > ZRL_DESTROYED);
170+
ASSERT3S(zrl->zr_refcount, >, ZRL_DESTROYED);
170171

171172
n = (int)zrl->zr_refcount;
172173
return (n <= 0 ? 0 : n);
@@ -175,15 +176,15 @@ zrl_refcount(zrlock_t *zrl)
175176
int
176177
zrl_is_zero(zrlock_t *zrl)
177178
{
178-
ASSERT(zrl->zr_refcount > ZRL_DESTROYED);
179+
ASSERT3S(zrl->zr_refcount, >, ZRL_DESTROYED);
179180

180181
return (zrl->zr_refcount <= 0);
181182
}
182183

183184
int
184185
zrl_is_locked(zrlock_t *zrl)
185186
{
186-
ASSERT(zrl->zr_refcount > ZRL_DESTROYED);
187+
ASSERT3S(zrl->zr_refcount, >, ZRL_DESTROYED);
187188

188189
return (zrl->zr_refcount == ZRL_LOCKED);
189190
}

0 commit comments

Comments
 (0)