From 957b4e9fbd2b8d29dc635ff49f3b29f29299c6a5 Mon Sep 17 00:00:00 2001 From: Mariusz Zaborski Date: Fri, 6 Nov 2020 02:02:19 +0100 Subject: [PATCH] FreeBSD: Prevent a NULL reference in zvol_cdev_open Check if the ZVOL has been written before calling zil_async_to_sync. The ZIL will be opened on the first write, not earlier. Reviewed-by: Ryan Moeller Reviewed-by: Brian Behlendorf Signed-off-by: Mariusz Zaborski Closes #11152 --- module/os/freebsd/zfs/zvol_os.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/os/freebsd/zfs/zvol_os.c b/module/os/freebsd/zfs/zvol_os.c index 0db21b5757..14c43bbffb 100644 --- a/module/os/freebsd/zfs/zvol_os.c +++ b/module/os/freebsd/zfs/zvol_os.c @@ -891,7 +891,8 @@ zvol_cdev_open(struct cdev *dev, int flags, int fmt, struct thread *td) if (flags & (FSYNC | FDSYNC)) { zsd = &zv->zv_zso->zso_dev; zsd->zsd_sync_cnt++; - if (zsd->zsd_sync_cnt == 1) + if (zsd->zsd_sync_cnt == 1 && + (zv->zv_flags & ZVOL_WRITTEN_TO) != 0) zil_async_to_sync(zv->zv_zilog, ZVOL_OBJ); }