FreeBSD 13.1 : ZFS NFS : .zfs/snapshot : Stale file handle : with zfs destroy snapshot process in Uninterruptible sleep

From: Michel Le Cocq <lecocq_at_ipgp.fr>
Date: Wed, 07 Sep 2022 14:50:06 UTC
Hi, since upgrading to 13.1-RELEASE of FreeBSD I can't anymore access to
.zfs/snapshot folder over NFS.

When I tried to acces do .zfs/snapshot over NFS I obtain a 'Stale file
handle'.

Worse : Then if you tried to delete the snapshot that was accessed, you
'zfs destroy snapshot' process will fall in 'Uninterruptible sleep'
(usually IO). So you can't kill it ! 

I post this bug here :
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=266236

A little small procedure to reproduce this bug.

Install a fresh FreeBSD server under 13.1-p2

	root@server:~# freebsd-version 
	13.1-RELEASE-p2
	
Inside a zfs pool create a vol and share it by NFS.

	root@server:~# zfs get name,mountpoint,sharenfs tank/zfsnfstest
	NAME             PROPERTY    VALUE             SOURCE
	tank/zfsnfstest  name        tank/zfsnfstest   -
	tank/zfsnfstest  mountpoint  /tank/zfsnfstest  local
	tank/zfsnfstest  sharenfs    on                local
	
Mount localy your sharenfs vol.

	root@server:~# mount -t nfs 127.0.0.1:/tank/zfsnfstest /mnt
	
Create a snapshot.

	root@server:~# zfs snapshot tank/zfsnfstest@1
	
Check you can access localy.

	root@server:~# ls -l /tank/zfsnfstest/.zfs/snapshot/1/
	total 0
	root@server:~#
	
Try to acces from mounted NFS vol.

	root@server:~# ls -l /mnt/.zfs/snapshot/1/
	total 0
	ls: /mnt/.zfs/snapshot/1/: Stale NFS file handle
	
Here we see we don't have access from NFS.

Try to remove your previous created snapshot.

	root@server:~# zfs destroy tank/zfsnfstest@1

This process didn't end...
		
	root@server:~ # ps aux
	USER    PID  %CPU %MEM    VSZ  RSS TT  STAT STARTED      TIME COMMAND
	[...]
	root  58027   0.0  0.0  18012 7256  1  D+   12:27     0:00.01 zfs destroy tank/zfsnfstest@1
	
D mean : Uninterruptible sleep (usually IO). So you can't kill it !

	root@server:~ # kill 58027
	root@server:~ # ps aux | grep 58027
	root  58027   0.0  0.0  18012 7256  1  D+   12:27     0:00.01 zfs destroy tank/zfsnfstest@1
	root@server:~ # kill -1 58027
	root@server:~ # ps aux | grep 58027
	root  58027   0.0  0.0  18012 7256  1  D+   12:27     0:00.01 zfs destroy tank/zfsnfstest@1
	root@server:~ # kill -9 58027
	root@server:~ # ps aux | grep 58027
	root  58027   0.0  0.0  18012 7256  1  D+   12:27     0:00.01 zfs destroy tank/zfsnfstest@1
	root@server:~ #

Thanks.

--
M