Skip to content

Commit

Permalink
Fix zfs_znode_sa_init() panic by updating ZFS_OBJ_MUTEX()
Browse files Browse the repository at this point in the history
The time at which a zp's z_zfsvfs is assigned was changed in
upstream here:

illumos/illumos-gate@b5fca8f

Although we had already merged in most of that change, we had
neglected to update the definition of ZFS_OBJ_MUTEX() to the new
two-argument version. Yet, when actually invoking the macro, we
were supplying two arguments.

In an attempt to reconcile the discrepancy, the panic was
introduced by

8881f60

which erroneously reverted the new code where the two-argument
version was used, rather than updating ZFS_OBJ_MUTEX() to the new
two-argument version.

This results in panic because ZFS_OBJ_MUTEX() happens to be used
before zp->z_zfsvfs has been assigned, while the one-argument
version of ZFS_OBJ_MUTEX() expects to be able to retrieve the
zfsvfs from the zp.
  • Loading branch information
ilovezfs committed Jul 24, 2014
1 parent 10bade5 commit b223a57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions include/sys/zfs_znode.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,8 @@ typedef struct znode {
* Macros for dealing with dmu_buf_hold
*/
#define ZFS_OBJ_HASH(obj_num) ((obj_num) & (ZFS_OBJ_MTX_SZ - 1))

#define ZFS_OBJ_MUTEX(zp) \
(&zp->z_zfsvfs->z_hold_mtx[ZFS_OBJ_HASH(zp->z_id)])
#define ZFS_OBJ_MUTEX(zfsvfs, obj_num) \
(&(zfsvfs)->z_hold_mtx[ZFS_OBJ_HASH(obj_num)])
#define ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num) \
mutex_enter(&zfsvfs->z_hold_mtx[ZFS_OBJ_HASH(obj_num)])
#define ZFS_OBJ_HELD(zfsvfs, obj_num) \
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/zfs_znode.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ zfs_znode_sa_init(zfsvfs_t *zfsvfs, znode_t *zp,
sa_handle_t *sa_hdl)
{
ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs) || (zfsvfs == zp->z_zfsvfs));
ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp)));
ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zfsvfs, zp->z_id)));

mutex_enter(&zp->z_lock);

Expand Down Expand Up @@ -655,7 +655,7 @@ zfs_znode_sa_init(zfsvfs_t *zfsvfs, znode_t *zp,
void
zfs_znode_dmu_fini(znode_t *zp)
{
ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp)) ||
ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp->z_zfsvfs, zp->z_id)) ||
zp->z_unlinked ||
RW_WRITE_HELD(&zp->z_zfsvfs->z_teardown_inactive_lock));

Expand Down

0 comments on commit b223a57

Please sign in to comment.