Bug 257316 - kstat.zfs sysctl tree unreachable for pools with "." in the name
Summary: kstat.zfs sysctl tree unreachable for pools with "." in the name
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: Alan Somers
URL: https://reviews.freebsd.org/D31265
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-21 17:42 UTC by Alan Somers
Modified: 2021-08-22 23:05 UTC (History)
1 user (show)

See Also:
asomers: mfc-stable13+
asomers: mfc-stable12+
asomers: mfc-stable11-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2021-07-21 17:42:39 UTC
FreeBSD exports statistics about pools and datasets via sysctl, in a tree rooted at "kstat.zfs.<pool_name>".  One problem: "." is a legal character in pool names but it's the separator for sysctl trees.  When a pool has "." in the name its stats will still be exported and they can be viewed by iterating through all of "kstat.zfs".  However, they won't be addressable by pool, and interpreting the output of "kstat.zfs" is difficult.  For example:

# I have a pool named "foo.bar"
$ zpool list
NAME       SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
foo.bar   9.50G   720K  9.50G        -         -     0%     0%  1.00x    ONLINE  -
testpool  9.50G  1.45M  9.50G        -         -     0%     0%  1.00x    ONLINE  -

# Its statistics are exported
$ sysctl kstat.zfs | grep foo.bar.dataset
kstat.zfs.foo.bar.dataset.objset-0x36.nunlinked: 0
kstat.zfs.foo.bar.dataset.objset-0x36.nunlinks: 0
kstat.zfs.foo.bar.dataset.objset-0x36.nread: 0
kstat.zfs.foo.bar.dataset.objset-0x36.reads: 0
kstat.zfs.foo.bar.dataset.objset-0x36.nwritten: 0
kstat.zfs.foo.bar.dataset.objset-0x36.writes: 0
kstat.zfs.foo.bar.dataset.objset-0x36.dataset_name: foo.bar

# But they aren't individually addressable
$ sysctl kstat.zfs.foo.bar
sysctl: unknown oid 'kstat.zfs.foo.bar'
$ sysctl kstat.zfs.foo
sysctl: unknown oid 'kstat.zfs.foo'

I think a proper solution would involve some kind of escaping of the "." character in the name.
Comment 1 commit-hook freebsd_committer freebsd_triage 2021-07-22 16:23:59 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6c9506559080da2914749bf611225d7c0a153609

commit 6c9506559080da2914749bf611225d7c0a153609
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2021-07-21 21:11:00 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-07-22 16:22:48 +0000

    Escape any '.' characters in sysctl node names

    ZFS creates some sysctl nodes that include a pool name, and '.' is an
    allowed character in pool names.  But it's the separator in the sysctl
    tree, so it can't be included in a sysctl name.  Replace it with "%25".
    Handily, "%" is illegal in ZFS pool names, so there's no ambiguity
    there.

    PR:             257316
    MFC after:      3 weeks
    Sponsored by:   Axcient
    Reviewed by:    freqlabs
    Differential Revision: https://reviews.freebsd.org/D31265

 sys/kern/kern_sysctl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)
Comment 2 commit-hook freebsd_committer freebsd_triage 2021-08-22 21:23:53 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e7d99efb3638b71756da8033ef8cef74213c42fd

commit e7d99efb3638b71756da8033ef8cef74213c42fd
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2021-07-21 21:11:00 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-08-22 21:11:00 +0000

    Escape any '.' characters in sysctl node names

    ZFS creates some sysctl nodes that include a pool name, and '.' is an
    allowed character in pool names.  But it's the separator in the sysctl
    tree, so it can't be included in a sysctl name.  Replace it with "%25".
    Handily, "%" is illegal in ZFS pool names, so there's no ambiguity
    there.

    PR:             257316
    Sponsored by:   Axcient
    Reviewed by:    freqlabs
    Differential Revision: https://reviews.freebsd.org/D31265

    (cherry picked from commit 6c9506559080da2914749bf611225d7c0a153609)

 sys/kern/kern_sysctl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2021-08-22 23:04:11 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=98c467192082b3d4a6c91eeaa80868bb5231534c

commit 98c467192082b3d4a6c91eeaa80868bb5231534c
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2021-07-21 21:11:00 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-08-22 22:43:50 +0000

    Escape any '.' characters in sysctl node names

    ZFS creates some sysctl nodes that include a pool name, and '.' is an
    allowed character in pool names.  But it's the separator in the sysctl
    tree, so it can't be included in a sysctl name.  Replace it with "%25".
    Handily, "%" is illegal in ZFS pool names, so there's no ambiguity
    there.

    PR:             257316
    Sponsored by:   Axcient
    Reviewed by:    freqlabs
    Differential Revision: https://reviews.freebsd.org/D31265

    (cherry picked from commit 6c9506559080da2914749bf611225d7c0a153609)

 sys/kern/kern_sysctl.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)
Comment 4 Alan Somers freebsd_committer freebsd_triage 2021-08-22 23:05:12 UTC
Not MFCing to stable/11 because stable/11 doesn't create the kstat.zfs.<pool> sysctls.