xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/unlink/unlinked_fh_accessible.ksh (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# https://opensource.org/license/CDDL-1.0.
12#
13
14#
15# Copyright 2026, tiehexue <tiehexue@hotmail.com>. All rights reserved.
16#
17
18. $STF_SUITE/include/libtest.shlib
19
20#
21# DESCRIPTION:
22# Verify that a filehandle-based reopen of an open-unlinked file
23# succeeds. This tests that zfs_vget() / zfs_fhtovp() does not
24# incorrectly reject znodes with z_unlinked when the inode/vnode
25# is still referenced.
26#
27# STRATEGY:
28# 1. Use the file_unlink_fh helper to create a file, obtain a
29#    filehandle (name_to_handle_at on Linux, getfh on FreeBSD),
30#    unlink the file, and then attempt to re-open it via
31#    open_by_handle_at (Linux) / fhopen (FreeBSD).
32# 2. Verify that the reopen succeeds.
33#
34
35verify_runnable "global"
36
37function cleanup
38{
39	cd "$cwd" || true
40	[[ -e $TESTDIR ]] && log_must rm -Rf $TESTDIR/*
41}
42
43log_assert "filehandle reopen of open-unlinked file should succeed"
44
45log_onexit cleanup
46
47cwd=$PWD
48log_must cd $TESTDIR
49
50# file_unlink_fh: creates file, gets filehandle, unlinks, reopens via
51# open_by_handle_at (Linux) or fhopen (FreeBSD). Exits 0 on success.
52log_must file_unlink_fh unlinked_fh_testfile
53
54log_pass "filehandle reopen of open-unlinked file succeeded"
55