From 47319ef7a6319a55fae98a323c23cd6b60301032 Mon Sep 17 00:00:00 2001 From: Ameer Hamza Date: Wed, 10 Dec 2025 22:16:45 +0500 Subject: [PATCH] ZTS: Add test for snapshot automount race Add snapshot_019_pos to verify parallel snapshot automount operations don't cause AVL tree panic. Regression test for commit 4ce030e025. Reviewed-by: Tony Hutter Reviewed-by: Brian Behlendorf Signed-off-by: Ameer Hamza Closes #18035 --- tests/runfiles/common.run | 2 +- tests/runfiles/sanity.run | 2 +- tests/zfs-tests/tests/Makefile.am | 1 + .../functional/snapshot/snapshot_019_pos.ksh | 82 +++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100755 tests/zfs-tests/tests/functional/snapshot/snapshot_019_pos.ksh diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index 3b5760e3b..9b4c4154c 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -1020,7 +1020,7 @@ tests = ['clone_001_pos', 'rollback_001_pos', 'rollback_002_pos', 'snapshot_006_pos', 'snapshot_007_pos', 'snapshot_008_pos', 'snapshot_009_pos', 'snapshot_010_pos', 'snapshot_011_pos', 'snapshot_012_pos', 'snapshot_013_pos', 'snapshot_014_pos', - 'snapshot_017_pos', 'snapshot_018_pos'] + 'snapshot_017_pos', 'snapshot_018_pos', 'snapshot_019_pos'] tags = ['functional', 'snapshot'] [tests/functional/snapused] diff --git a/tests/runfiles/sanity.run b/tests/runfiles/sanity.run index 249b41502..95bdf05dc 100644 --- a/tests/runfiles/sanity.run +++ b/tests/runfiles/sanity.run @@ -580,7 +580,7 @@ tests = ['clone_001_pos', 'rollback_001_pos', 'rollback_002_pos', 'snapshot_007_pos', 'snapshot_008_pos', 'snapshot_009_pos', 'snapshot_010_pos', 'snapshot_011_pos', 'snapshot_012_pos', 'snapshot_013_pos', 'snapshot_014_pos', 'snapshot_017_pos', - 'snapshot_018_pos'] + 'snapshot_018_pos', 'snapshot_019_pos'] tags = ['functional', 'snapshot'] [tests/functional/snapused] diff --git a/tests/zfs-tests/tests/Makefile.am b/tests/zfs-tests/tests/Makefile.am index 4502f268a..a4b3e7376 100644 --- a/tests/zfs-tests/tests/Makefile.am +++ b/tests/zfs-tests/tests/Makefile.am @@ -2122,6 +2122,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \ functional/snapshot/snapshot_016_pos.ksh \ functional/snapshot/snapshot_017_pos.ksh \ functional/snapshot/snapshot_018_pos.ksh \ + functional/snapshot/snapshot_019_pos.ksh \ functional/snapused/cleanup.ksh \ functional/snapused/setup.ksh \ functional/snapused/snapused_001_pos.ksh \ diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_019_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_019_pos.ksh new file mode 100755 index 000000000..c8a1a8a7b --- /dev/null +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_019_pos.ksh @@ -0,0 +1,82 @@ +#!/bin/ksh -p +# SPDX-License-Identifier: CDDL-1.0 +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or https://opensource.org/licenses/CDDL-1.0. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2025 iXsystems, Inc. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/snapshot/snapshot.cfg + +# +# DESCRIPTION: +# Verify that parallel snapshot automount operations don't cause AVL tree +# panic due to duplicate mount attempts. +# +# STRATEGY: +# 1. Create a filesystem with snapdir=visible +# 2. Create a snapshot +# 3. Trigger parallel ls operations on the snapshot directory +# 4. Verify no kernel panic occurred and snapshot is accessible +# + +function cleanup +{ + destroy_pool $TESTPOOL +} + +verify_runnable "both" + +log_assert "Verify parallel snapshot automount doesn't cause AVL tree panic" + +log_onexit cleanup + +# Create pool and filesystem +create_pool $TESTPOOL $DISKS +log_must zfs create -o snapdir=visible -o mountpoint=$TESTDIR $TESTPOOL/$TESTFS + +# Create a snapshot +log_must zfs snapshot $SNAPFS + +# Trigger parallel automount operations to reproduce the race condition. +# Multiple concurrent ls operations will attempt to automount the same +# unmounted snapshot, which previously could cause duplicate mount helpers +# and AVL tree panic. +snapdir_path="$TESTDIR/.zfs/snapshot/$TESTSNAP" +for i in {1..100} +do + ls $snapdir_path >/dev/null 2>&1 & +done + +# Wait for all background processes to complete +wait + +# Verify the snapshot is accessible and properly mounted after parallel access +log_must ls $snapdir_path + +# Verify we can unmount the filesystem cleanly. This confirms no processes +# are stuck in a syscall and all automated snapshots were unmounted properly. +# If the AVL panic occurred, unmount would fail. +log_must zfs unmount $TESTPOOL/$TESTFS + +log_pass "Parallel snapshot automount completed without AVL tree panic"