From nobody Fri Jun 17 01:35:54 2022 X-Original-To: bugs@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 A892785FFEA for ; Fri, 17 Jun 2022 01:35:54 +0000 (UTC) (envelope-from bugzilla-noreply@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LPM7Z2w0Vz4fgw for ; Fri, 17 Jun 2022 01:35:54 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 401EA1636C for ; Fri, 17 Jun 2022 01:35:54 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 25H1ZsBJ008970 for ; Fri, 17 Jun 2022 01:35:54 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 25H1Zs9s008969 for bugs@FreeBSD.org; Fri, 17 Jun 2022 01:35:54 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 264723] the KERN_LOCKF sysctl returns kl_file_fsid that doesn't match st_dev from stat() Date: Fri, 17 Jun 2022 01:35:54 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: damjan.jov@gmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655429754; 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=HAHyiqhOOQ1zOAtF5zSidJTJg/02n+sl8JoixINHxmU=; b=yciFh/o/7poc9d0nz1Yk79PHsjZ0pwsTAW9RlQK20ym0M0NB1IHuVIj6lpcRStNFuU3QII AnFDQg3w6BlDZxHiyPfrPKCJODZoWkpkFxpUoj5cLBeVeUtNTPiyxZC6o+Whv9lv7G9F9q HDQWOuEmkjh37clw0SuTmSntLf16Skx5QZwJGjcaYCB52tbJrnCM6M+ywaf0J8Xxb4q6a6 eUtcsoNabB+Egh0HXzMquFSj6RIZcEDZJvArbKV86TbxzEXf7A+Kd/HDuy+z4DcR6/Dg5b TyG9tUHNYp/q1jtrk8BC0/wpZ+oh+9GOsjOcEIBEUYMpV8BfIsU7P5f22oUOiw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655429754; a=rsa-sha256; cv=none; b=aRXy70BsFUnXxuYmoQ2Nb9gGgZqjlqxKcsexEry+t9CpmS+Ar2JMVL8JhdcxA/yc2FWKyI JIHvqgSNpmsNBz6Z2DPFEg5DuMH/FiruMABEz0WQaesRjSYnFN3Z83JwH9rLiqO6g8iHdq MEXZelqTzxCJqJ+gKmdG13F47brzZlhQkAYEZCnJqUhaJNVdEVWfvhCbWBnCyxEDOzhKzO 7DCeXw2jPwfJnzWKxqLjzm2s625/VumVTM7lSdKwQPZpAfFNecRb2ZY/uXzszSo7YqoQA2 NImdF1rclCBMNpuJYtyV1DGP+2fsBr/gCdxUMqEwT9k1tf0Qc6cwWPtlHu8dIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D264723 Bug ID: 264723 Summary: the KERN_LOCKF sysctl returns kl_file_fsid that doesn't match st_dev from stat() Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: damjan.jov@gmail.com The new KERN_LOCKF sysctl (great work btw) returns struct kinfo_lockf, whose kl_file_fsid matches neither the st_dev from stat(), nor the kf_file_fsid f= rom kinfo_getfiles() (even though stat() and kinfo_getfiles() match each other). For example compare the FSID in "procstat advlock" for a locked file, with = the st_dev in "stat -s" output on it. vop_stdstat() derives st_dev like this: ---snip--- if (vap->va_fsid !=3D VNOVAL) sb->st_dev =3D vap->va_fsid; else sb->st_dev =3D vp->v_mount->mnt_stat.f_fsid.val[0]; ---snip--- vn_fill_kinfo_vnode() derives kf_file_fsid the same way: ---snip--- if (va.va_fsid !=3D VNOVAL) kif->kf_un.kf_file.kf_file_fsid =3D va.va_fsid; else kif->kf_un.kf_file.kf_file_fsid =3D vp->v_mount->mnt_stat.f_fsid.val[0]; ---snip--- But vfs_report_lockf() uses the entire mnt_stat.f_fsid, not just array elem= ent 0, and never uses va.va_fsid: ---snip--- fsidx =3D mp->mnt_stat.f_fsid; ... memcpy(&klf->kl.kl_file_fsid, &fsidx, sizeof(fsidx)); ---snip--- vfs_report_lockf() does call VOP_STAT(), which is (usually?) the vop_stdsta= t() function above, so it should be able to just copy its correctly populated st_dev to kl_file_fsid. When I do that, as in the following patch, it seems= to work, the FSID in "procstat advlock" matches the st_dev in "stat -s": ---snip--- diff --git a/sys/kern/kern_lockf.c b/sys/kern/kern_lockf.c index cad208197e7..98e29b2c929 100644 --- a/sys/kern/kern_lockf.c +++ b/sys/kern/kern_lockf.c @@ -2479,7 +2479,6 @@ vfs_report_lockf(struct mount *mp, struct sbuf *sb) struct ucred *ucred; char *fullpath, *freepath; struct stat stt; - fsid_t fsidx; STAILQ_HEAD(, kinfo_lockf_linked) locks; int error, gerror; @@ -2522,7 +2521,6 @@ vfs_report_lockf(struct mount *mp, struct sbuf *sb) gerror =3D 0; ucred =3D curthread->td_ucred; - fsidx =3D mp->mnt_stat.f_fsid; while ((klf =3D STAILQ_FIRST(&locks)) !=3D NULL) { STAILQ_REMOVE_HEAD(&locks, link); vp =3D klf->vp; @@ -2532,8 +2530,7 @@ vfs_report_lockf(struct mount *mp, struct sbuf *sb) error =3D VOP_STAT(vp, &stt, ucred, NOCRED); VOP_UNLOCK(vp); if (error =3D=3D 0) { - memcpy(&klf->kl.kl_file_fsid, &fsidx, - sizeof(fsidx)); + klf->kl.kl_file_fsid =3D stt.st_dev; klf->kl.kl_file_rdev =3D stt.st_rdev; klf->kl.kl_file_fileid =3D stt.st_ino; freepath =3D NULL; ---snip--- --=20 You are receiving this mail because: You are the assignee for the bug.=