commit 6ab553e46cf3cb78d8a6fb1752235feadc9b3750 Author: Tong Zhang Date: Sun Nov 22 18:50:16 2020 -0500 vfs_domount_first: do not crash on mount failure vfs_write_suspend_umnt() expect a non-zero vfs_write_suspend_umnt, otherwise it will panic panic: vn_finished_write: neg cnt cpuid = 7 time = 1606004193 KDB: stack backtrace: #0 0xffffffff80c0a8f5 at kdb_backtrace+0x65 #1 0xffffffff80bbeb1b at vpanic+0x17b #2 0xffffffff80bbe993 at panic+0x43 #3 0xffffffff80c9da05 at vn_finished_write+0xc5 #4 0xffffffff80c9f726 at vfs_write_suspend_umnt+0x16 #5 0xffffffff80ecdd31 at ffs_unmount+0x71 #6 0xffffffff80c844dd at vfs_domount+0xc0d #7 0xffffffff80c83228 at vfs_donmount+0x988 #8 0xffffffff80c82871 at sys_nmount+0x71 #9 0xffffffff810904c7 at amd64_syscall+0x387 #10 0xffffffff8106785e at fast_syscall_common+0xf8 Uptime: 2h10m11s diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index afbb3e313d7..03e4394cf75 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -895,6 +895,15 @@ vfs_domount_first( (error1 = VFS_ROOT(mp, LK_EXCLUSIVE, &newdp)) != 0) { if (error1 != 0) { error = error1; + /* + * if mounted as rw - we should increase mnt_writeopcount here + * since VFS_UNMOUNT will call vfs_write_suspend_umnt() and + * it expects a non-zero vfs_write_suspend_umnt + */ + if ((mp->mnt_flag & MNT_RDONLY) == 0) { + if ((error = vn_start_write(NULL, &mp, V_WAIT)) != 0) + return (error); + } if ((error1 = VFS_UNMOUNT(mp, 0)) != 0) printf("VFS_UNMOUNT returned %d\n", error1); }