From nobody Mon Jun 16 21:37:28 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bLjyd6RnDz5yRqf; Mon, 16 Jun 2025 21:37:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bLjyc6HHzz3Jq0; Mon, 16 Jun 2025 21:37:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750109848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=njcCunHFIa7Dey7jVbx3spb4Q48qVRbj8lDFyKTYr/U=; b=JpbUyreC0eDoGtAMAc5oKA5qUqKfkQHQKpy6EJq7cuhRlmyHDfSMM8eLzlFbL3M/IF4AI9 Dne63BYv+Fc7QBc/71Zn9xlpfon6o0NmBRU3MUKMkIHzmucjrpeGqrintBOmDUw2jrgwTH 6PnqbR9denARO9AYjKjxWfG/PSvEUEwtETdvk1ECpcSmZgW3fAOzbOm+0VtME/mMBFN5G0 37HKoPBH3bMW81T2Ro5Uqr/M2US1gxHXx/+S/80d7E60HquraegP+5/7jvZue5NNfFDFLb KCmr/AXzU23xrTIlrwLPEvoVLRFB3/JEGgxBxjN1LTuRjfkSqyASVD48y8cveA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750109848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=njcCunHFIa7Dey7jVbx3spb4Q48qVRbj8lDFyKTYr/U=; b=wsq28lXOn+WUsnvsjOiIjhLEDEvhKS8q2GslAsp9dWC4tWTPx7mgl9L1nGHC9nq1a6EJ5U DpKR7DPnnm6SS0ZTW2HxHqxOFl2MORDRDGzyxwBe0ln56qNrP6mBlyqv1NJC2giKGOfJlA M8/G7tz6LTbG8CZeb8zw5+Z/zymiMQFpkoFvOt85QxP5Aglhthbru43ub05LLSmxvHItYp h4M4eppiyIv/W1poXT6pUM02iX8Q8si8B1sNusU+0RzRGLmZ36RCR6sGOvikKRJSyevXix PZXEU2i3sNf+PB2SK1LIzvrlynnBijN3Awx6bYfnNTw+7DdzfR+y30iS1Sa5dA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750109848; a=rsa-sha256; cv=none; b=SBU9X+7CUSSPg37LAgyUTdxhYUwgsUFah7DaqXEKTQmeD4mRc2WD/h7+kpzTihNUZ+PLP6 uiWNWJtu0EdCEQdVntNLnFYHPdfYhOf/hmsCTqlYHGSi9vwCj2TgMexPBj9v5rkMtyAUdW rsLZOu2ZiQoyWJtY3UA3U+IEcJTHrGk8SwW6zOSsos5AxnnpDb1opbTmNV55z5W6gGecwp r55efW82Y/GBY90Mcd4+R5sMR/ePZv/vs55s2oINPaGx67BLFNgPWVrc0h6ZEIhdh7L8Lu KcChRSDt8VWq3jqyFlOgHsJidpGrvPaBGZFSMt7OmhvS88zE7LAS84lUPe5jRg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bLjyc4N9Vzsm; Mon, 16 Jun 2025 21:37:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55GLbSa6073163; Mon, 16 Jun 2025 21:37:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55GLbSbJ073160; Mon, 16 Jun 2025 21:37:28 GMT (envelope-from git) Date: Mon, 16 Jun 2025 21:37:28 GMT Message-Id: <202506162137.55GLbSbJ073160@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: 66cc116bb2c1 - main - libprocstat: Drop zfs_defs.c hack, including its _KERNEL define List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 66cc116bb2c17c3373762c2c53928a2be775b17d Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=66cc116bb2c17c3373762c2c53928a2be775b17d commit 66cc116bb2c17c3373762c2c53928a2be775b17d Author: Jessica Clarke AuthorDate: 2025-06-16 21:34:34 +0000 Commit: Jessica Clarke CommitDate: 2025-06-16 21:34:34 +0000 libprocstat: Drop zfs_defs.c hack, including its _KERNEL define Now that we have a _WANT_ZNODE we can use that instead of defining _KERNEL, and we're able to move the code back into zfs.c using a real znode_t pointer. Whilst here, tidy the includes. Reviewed by: imp, kib, markj Differential Revision: https://reviews.freebsd.org/D50721 --- lib/libprocstat/Makefile | 23 ++++++----- lib/libprocstat/zfs.c | 49 +++++++++++----------- lib/libprocstat/zfs/Makefile | 30 -------------- lib/libprocstat/zfs/Makefile.depend | 11 ----- lib/libprocstat/zfs_defs.c | 81 ------------------------------------- lib/libprocstat/zfs_defs.h | 36 ----------------- 6 files changed, 38 insertions(+), 192 deletions(-) diff --git a/lib/libprocstat/Makefile b/lib/libprocstat/Makefile index 229adc6015f7..e20518910ba3 100644 --- a/lib/libprocstat/Makefile +++ b/lib/libprocstat/Makefile @@ -52,18 +52,23 @@ MLINKS+=libprocstat.3 procstat_close.3 \ libprocstat.3 procstat_open_kvm.3 \ libprocstat.3 procstat_open_sysctl.3 -# XXX This is a hack. .if ${MK_CDDL} != "no" CFLAGS+= -DLIBPROCSTAT_ZFS SRCS+= zfs.c -OBJS+= zfs/zfs_defs.o -SUBDIR= zfs -zfs/zfs_defs.o: .PHONY - @cd ${.CURDIR}/zfs && ${MAKE} zfs_defs.o -zfs/zfs_defs.pico: .PHONY - @cd ${.CURDIR}/zfs && ${MAKE} zfs_defs.pico -zfs/zfs_defs.pieo: .PHONY - @cd ${.CURDIR}/zfs && ${MAKE} zfs_defs.pieo +ZFSTOP= ${SRCTOP}/sys/contrib/openzfs +CFLAGS.zfs.c+= -DIN_BASE +CFLAGS.zfs.c+= -DHAVE_ISSETUGID +CFLAGS.zfs.c+= -DZFS_DEBUG +CFLAGS.zfs.c+= -I${ZFSTOP}/include +CFLAGS.zfs.c+= -I${ZFSTOP}/lib/libspl/include +CFLAGS.zfs.c+= -I${ZFSTOP}/lib/libspl/include/os/freebsd +CFLAGS.zfs.c+= -I${ZFSTOP}/include/os/freebsd/zfs +CFLAGS.zfs.c+= -I${ZFSTOP}/module/icp/include +CFLAGS.zfs.c+= -I${SRCTOP}/sys +CFLAGS.zfs.c+= -I${SRCTOP}/sys/modules/zfs +CFLAGS.zfs.c+= -include ${ZFSTOP}/include/os/freebsd/spl/sys/ccompile.h +CFLAGS.zfs.c+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h +CFLAGS.zfs.c+= -Wno-cast-qual .endif .include diff --git a/lib/libprocstat/zfs.c b/lib/libprocstat/zfs.c index 010337c1919a..6dc23d7573fd 100644 --- a/lib/libprocstat/zfs.c +++ b/lib/libprocstat/zfs.c @@ -26,10 +26,6 @@ * SUCH DAMAGE. */ -#include /* __RENAME */ - -#include - #include #define _WANT_MOUNT #include @@ -38,26 +34,28 @@ #include #include #include +#define _WANT_ZNODE +#include +#include #include #include #include +#include #include #include #define ZFS #include "libprocstat.h" #include "common_kvm.h" -#include "zfs_defs.h" int zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct mount mount, *mountptr; - void *znodeptr; - char *dataptr; + znode_t *kznodeptr, *znode; size_t len; int size; @@ -66,27 +64,30 @@ zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) warnx("error getting sysctl"); return (1); } - dataptr = malloc(size); - if (dataptr == NULL) { + znode = malloc(size); + if (znode == NULL) { warnx("error allocating memory for znode storage"); return (1); } - if ((size_t)size < offsetof_z_id + sizeof(uint64_t) || - (size_t)size < offsetof_z_mode + sizeof(mode_t) || - (size_t)size < offsetof_z_size + sizeof(uint64_t)) { + if ((size_t)size != sizeof(znode_t)) + warnx("znode_t size mismatch, data could be wrong"); + + if ((size_t)size < offsetof(znode_t, z_id) + sizeof(znode->z_id) || + (size_t)size < offsetof(znode_t, z_mode) + sizeof(znode->z_mode) || + (size_t)size < offsetof(znode_t, z_size) + sizeof(znode->z_size)) { warnx("znode_t size is too small"); goto bad; } - if ((size_t)size != sizeof_znode_t) - warnx("znode_t size mismatch, data could be wrong"); - - /* Since we have problems including vnode.h, we'll use the wrappers. */ - znodeptr = getvnodedata(vp); - if (!kvm_read_all(kd, (unsigned long)znodeptr, dataptr, - (size_t)size)) { - warnx("can't read znode at %p", (void *)znodeptr); + /* + * OpenZFS's libspl provides a dummy sys/vnode.h that shadows ours so + * struct vnode is an incomplete type. Use the wrapper until that is + * resolved. + */ + kznodeptr = getvnodedata(vp); + if (!kvm_read_all(kd, (unsigned long)kznodeptr, znode, (size_t)size)) { + warnx("can't read znode at %p", (void *)kznodeptr); goto bad; } @@ -102,12 +103,10 @@ zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) * under .zfs/. */ vn->vn_fsid = mount.mnt_stat.f_fsid.val[0]; - vn->vn_fileid = *(uint64_t *)(void *)(dataptr + offsetof_z_id); - vn->vn_mode = *(mode_t *)(void *)(dataptr + offsetof_z_mode); - vn->vn_size = *(uint64_t *)(void *)(dataptr + offsetof_z_size); - free(dataptr); + vn->vn_fileid = znode->z_id; + vn->vn_mode = znode->z_mode; + vn->vn_size = znode->z_size; return (0); bad: - free(dataptr); return (1); } diff --git a/lib/libprocstat/zfs/Makefile b/lib/libprocstat/zfs/Makefile deleted file mode 100644 index 5e1ebd44d1d3..000000000000 --- a/lib/libprocstat/zfs/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -.PATH: ${.CURDIR:H} - -SRCS= zfs_defs.c -OBJS= zfs_defs.o -WARNS?= 1 - -FORTIFY_SOURCE= 0 - -# We fake a kernel compilation environment in order to get the definition for -# 'zpool_t'. -CFLAGS+= -DIN_BASE -D__KERNEL__ -D_KERNEL -UKLD_TIED -DKLD_MODULE -CFLAGS+= -DHAVE_ISSETUGID -D_SYS_VMEM_H_ - -CFLAGS+= -fno-builtin -nostdlib - -CFLAGS+= -I${.CURDIR} -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/zfs -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd -CFLAGS+= -I${SRCTOP}/sys/contrib/ck/include -CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/module/icp/include -CFLAGS+= -I${SRCTOP}/sys -I. -I.. - -CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h - -all: ${OBJS} -CLEANFILES= ${OBJS} - -.include diff --git a/lib/libprocstat/zfs/Makefile.depend b/lib/libprocstat/zfs/Makefile.depend deleted file mode 100644 index 993ab0638f4a..000000000000 --- a/lib/libprocstat/zfs/Makefile.depend +++ /dev/null @@ -1,11 +0,0 @@ -# Autogenerated - do NOT edit! - -DIRDEPS = \ - include \ - - -.include - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif diff --git a/lib/libprocstat/zfs_defs.c b/lib/libprocstat/zfs_defs.c deleted file mode 100644 index 7f935c827118..000000000000 --- a/lib/libprocstat/zfs_defs.c +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2020 Andriy Gapon - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -/* - * Prevent some headers from getting included and fake some types - * in order to allow this file to compile without bringing in - * too many kernel build dependencies. - */ -#define _OPENSOLARIS_SYS_PATHNAME_H_ -#define _OPENSOLARIS_SYS_POLICY_H_ -#define _VNODE_PAGER_ - - -enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD, - VMARKER }; - -/* - * Vnode attributes. A field value of VNOVAL represents a field whose value - * is unavailable (getattr) or which is not to be changed (setattr). - */ -struct vattr { - enum vtype va_type; /* vnode type (for create) */ - u_short va_mode; /* files access mode and type */ - u_short va_padding0; - uid_t va_uid; /* owner user id */ - gid_t va_gid; /* owner group id */ - nlink_t va_nlink; /* number of references to file */ - dev_t va_fsid; /* filesystem id */ - ino_t va_fileid; /* file id */ - u_quad_t va_size; /* file size in bytes */ - long va_blocksize; /* blocksize preferred for i/o */ - struct timespec va_atime; /* time of last access */ - struct timespec va_mtime; /* time of last modification */ - struct timespec va_ctime; /* time file changed */ - struct timespec va_birthtime; /* time file created */ - u_long va_gen; /* generation number of file */ - u_long va_flags; /* flags defined for file */ - dev_t va_rdev; /* device the special file represents */ - u_quad_t va_bytes; /* bytes of disk space held by file */ - u_quad_t va_filerev; /* file modification number */ - u_int va_vaflags; /* operations flags, see below */ - long va_spare; /* remain quad aligned */ -}; - -#define _WANT_MOUNT -#include -#include - -size_t sizeof_znode_t = sizeof(znode_t); -size_t offsetof_z_id = offsetof(znode_t, z_id); -size_t offsetof_z_size = offsetof(znode_t, z_size); -size_t offsetof_z_mode = offsetof(znode_t, z_mode); - -/* Keep pcpu.h satisfied. */ -uintptr_t *__start_set_pcpu; -uintptr_t *__stop_set_pcpu; diff --git a/lib/libprocstat/zfs_defs.h b/lib/libprocstat/zfs_defs.h deleted file mode 100644 index de17efba5630..000000000000 --- a/lib/libprocstat/zfs_defs.h +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2020 Andriy Gapon - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _LIBPROCSTAT_ZFS_DEFS_H -#define _LIBPROCSTAT_ZFS_DEFS_H - -extern size_t sizeof_znode_t; -extern size_t offsetof_z_id; -extern size_t offsetof_z_size; -extern size_t offsetof_z_mode; - -#endif /* _LIBPROCSTAT_ZFS_DEFS_H */