From da60484db5960f2b94cf3302dd08fe7fb673eaf3 Mon Sep 17 00:00:00 2001 From: George Amanakis Date: Sat, 1 Aug 2020 14:17:18 -0400 Subject: [PATCH] Fix logging in l2arc_rebuild() In case the L2ARC rebuild was canceled, do not log to spa history log as the pool may be in the process of being removed and a panic may occur: BUG: kernel NULL pointer dereference, address: 0000000000000018 RIP: 0010:spa_history_log_internal+0xb1/0x120 [zfs] Call Trace: l2arc_rebuild+0x464/0x7c0 [zfs] l2arc_dev_rebuild_start+0x2d/0x130 [zfs] ? l2arc_rebuild+0x7c0/0x7c0 [zfs] thread_generic_wrapper+0x78/0xb0 [spl] kthread+0xfb/0x130 ? IS_ERR+0x10/0x10 [spl] ? kthread_park+0x90/0x90 ret_from_fork+0x35/0x40 Reviewed-by: Brian Behlendorf Signed-off-by: George Amanakis Closes #10659 --- module/zfs/arc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/module/zfs/arc.c b/module/zfs/arc.c index 9399f97218..31f046784c 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -9692,6 +9692,13 @@ out: "no valid log blocks"); bzero(l2dhdr, dev->l2ad_dev_hdr_asize); l2arc_dev_hdr_update(dev); + } else if (err == ECANCELED) { + /* + * In case the rebuild was canceled do not log to spa history + * log as the pool may be in the process of being removed. + */ + zfs_dbgmsg("L2ARC rebuild aborted, restored %llu blocks", + zfs_refcount_count(&dev->l2ad_lb_count)); } else if (err != 0) { spa_history_log_internal(spa, "L2ARC rebuild", NULL, "aborted, restored %llu blocks",