Bug 274878

Summary: ZFS: sysctl "kstat.zfs.POOLNAME.dataset.objset-0xXXXX.dataset_name" not updated when renaming zvols
Product: Base System Reporter: Alan Somers <asomers>
Component: kernAssignee: Alan Somers <asomers>
Status: Closed FIXED    
Severity: Affects Only Me Flags: asomers: mfc-stable14+
asomers: mfc-stable13+
asomers: mfc-stable12-
Priority: ---    
Version: 13.2-RELEASE   
Hardware: Any   
OS: Any   
URL: https://github.com/openzfs/zfs/issues/15482

Description Alan Somers freebsd_committer freebsd_triage 2023-11-02 17:10:55 UTC
The kstat.zfs.<POOLNAME>.dataset.objset-0x<OBJID> sysctl nodes publish statistics about ZFS datasets, such as throughput.  The "dataset_name" node is supposed to contain the name of the ZFS dataset.  But on both FreeBSD 13.1 and 13.2 I am seeing some dataset_name nodes that are corrupted.  They contain the name of one dataset suffixed by part of the name of another.  For example, sysctl shows a node named:

kstat.zfs.MYPOOL.dataset.objset-0x1982c.dataset_name: MYPOOL/MYDS/transfer/273/0

But no such dataset is present.  Instead, that name seems to be synthesized by a combination of the following dataset names:

NAME                   OBJSETID
MYPOOL/MYDS/273/0      104492
MYPOOL/MYDS/transfer   17007

One possible cause, which I haven't verified, would be ZFS renames.  It may be that "zfs rename MYPOOL/MYDS/transfer/273/0 MYPOOL/MYDS/273/0" doesn't update the value of that sysctl node.

This bug is most apparent when using sysutils/ztop.
Comment 1 Alan Somers freebsd_committer freebsd_triage 2023-11-02 21:14:53 UTC
I've reproduced the issue in a VM.  As I suspected, it's caused by renames.  But _only_ for zvols.  Renaming file systems does not trigger the bug.

Steps to Reproduce
==================

$ zpool create testpool vtbd1
$ zfs create -V1m testpool/testvol
$ sysctl -n kstat.zfs.testpool.dataset.objset-$(printf 0x%x $(zfs get -Hpo value objsetid testpool/testvol)).dataset_name
testpool/testvol
$ sudo zfs rename testpool/testvol testpool/yyy
$ sysctl -n kstat.zfs.testpool.dataset.objset-$(printf 0x%x $(zfs get -Hpo value objsetid testpool/yyy)).dataset_name
testpool/testvol
Comment 2 Alan Somers freebsd_committer freebsd_triage 2023-11-02 21:49:13 UTC
The bug affects Linux as well as FreeBSD, so I opened a ticket on github.
Comment 3 Alan Somers freebsd_committer freebsd_triage 2023-12-01 16:36:46 UTC
I opened a PR with OpenZFS.  They accepted it and by now the change has been merged into FreeBSD main, stable/14, and stable/13.