From 0365064a9726f6bb6e148611a6e42fa80302d083 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 8 Mar 2013 10:48:18 -0800 Subject: [PATCH] Handle closing an unopened ZVOL Thank to commit a4430fce691d492aec382de0dfa937c05ee16500 we're now correctly returning EROFS when opening a zvol on a read-only pool. Unfortunately, it looks like this causes us to trigger some unexpected behavior by __blkdev_get(). In the failure case it's possible __blkdev_get() will call __blkdev_put() for a bdev which was never successfully opened. This results in us trying to close the device again and hitting the NULL dereference. Signed-off-by: Brian Behlendorf Closes #1343 --- module/zfs/zvol.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index 8c43e198a..4febbb6bf 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -1055,11 +1055,11 @@ zvol_release(struct gendisk *disk, fmode_t mode) drop_mutex = 1; } - ASSERT3P(zv, !=, NULL); - ASSERT3U(zv->zv_open_count, >, 0); - zv->zv_open_count--; - if (zv->zv_open_count == 0) - zvol_last_close(zv); + if (zv->zv_open_count > 0) { + zv->zv_open_count--; + if (zv->zv_open_count == 0) + zvol_last_close(zv); + } if (drop_mutex) mutex_exit(&zvol_state_lock);