From nobody Thu Aug 11 14:36:27 2022 X-Original-To: dev-commits-src-branches@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 4M3Trq74zZz4Y3FF; Thu, 11 Aug 2022 14:36:27 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M3Trq6bDPz3Q4D; Thu, 11 Aug 2022 14:36:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660228587; 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=+xJyyHQdXiDouUkP3yYyEho9OtDG1QUCUz3oBh7QE0Q=; b=qoVFVRscq1BtZqR2X7qv//ovXrapEepO1Nbs+NEwP8xjjK85FXbYRdaap8rVfk+dRgLgsX NeJV1tLgadjWxHsJB7+pGo4zAW0Cu49f5PcAjUGSMawrQwuidtqsJ/s7oaypa1VqqcStiB GAgDKNLzkGCkDxSYkZsZn9x0lNe1GwaMgktndTB3WEBwPeTkGmQyEeDnCU7KCv25MegNTz WvGxwbkILa52sG/cpjXQJncaNdv6t8/TbcTie6YYKsGjI3hrKQK66ZYvMksPMjhKTLnyDo 1swwun49VP1g1u+QrPHTIbYFaMXXlfuyt4ixcr0BAAeUcCCascSZxYkAGYv0gA== 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 4M3Trq5gfyztvb; Thu, 11 Aug 2022 14:36:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27BEaRAD005316; Thu, 11 Aug 2022 14:36:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27BEaRfP005315; Thu, 11 Aug 2022 14:36:27 GMT (envelope-from git) Date: Thu, 11 Aug 2022 14:36:27 GMT Message-Id: <202208111436.27BEaRfP005315@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 17e0a1c6e9e4 - stable/13 - file: Move code to share fdtol structs into kern_descrip.c List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 17e0a1c6e9e47b7fc1ab4f6144d7dcf792c3eaec Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660228587; 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=+xJyyHQdXiDouUkP3yYyEho9OtDG1QUCUz3oBh7QE0Q=; b=KPNM1BT/AYOYSNiw+ca0jyyteQz8SNdv7N98XjuAheXCZaKcK4LBUy5f0ti3PpYZohFjev xZ3lBAupg7aTNrkUklsjDwXbbq4km0FD9CsyKcPBhqLyYPYEQecSNLZAyoRhDFGjT4UpJs FMQLg1EPyLXen4KSrAw6owVHSDr1wAQXRZPFkEw2kILBGFGeKVTqTN1fQlkspMXh3s1oKh 5+aL0+vZZ5QNU+tceSBVqP7zooPwZJpGwL9zRZNkAWw2Vd0wtBElC0H7bGqekhQHuPmUhC UojZ1riy0GuKg6h0e4XzBm0QjLO42XTiFrAMwSvddZ/skAAJDUrIRv/y6nPBCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660228587; a=rsa-sha256; cv=none; b=NDlioA38+Ey//RJhotv240SWptccxbl2NyPO5aBNFlVQQAaNHouiZq47KCctVRU7ifK7ss NDIYSDhPsRYP1x0Z70Ohmsh8K0G9EtmniS9BpIEeksdYj9RiUH4vROmwqatf8Ss21TeFs2 Od4n+HYownoPd+8vgP0DLZTEKz5lMLGNW0/bZ9tpQtxvm9MDiM3NGblgZEEz3SZEyJJW75 +4hEYkqzFpC2WGcObSJSF3B94QFiJd9W1cElpAHZLAWNCc36mIm4OEbmmmZNRHza5n6MPK J3r5IhF77lceE3LzhXnNsI0M77x251yLnyMkDQ4z8MdOlD6eZmAbRHdd2nK3xg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=17e0a1c6e9e47b7fc1ab4f6144d7dcf792c3eaec commit 17e0a1c6e9e47b7fc1ab4f6144d7dcf792c3eaec Author: Mark Johnston AuthorDate: 2022-08-04 13:39:25 +0000 Commit: Mark Johnston CommitDate: 2022-08-11 14:36:11 +0000 file: Move code to share fdtol structs into kern_descrip.c This ensures the filedesc-to-leader code is consistently encapsulated in kern_descrip.c. No functional change intended. Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit d07675a9352efce5e997e987080b3f98bbfdac96) --- sys/kern/kern_descrip.c | 12 +++++++++++- sys/kern/kern_fork.c | 5 +---- sys/sys/filedesc.h | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 9d73417b7a3d..ff999cc82f97 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -4239,7 +4239,8 @@ mountcheckdirs(struct vnode *olddp, struct vnode *newdp) } struct filedesc_to_leader * -filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, struct proc *leader) +filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, + struct proc *leader) { struct filedesc_to_leader *fdtol; @@ -4263,6 +4264,15 @@ filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, s return (fdtol); } +struct filedesc_to_leader * +filedesc_to_leader_share(struct filedesc_to_leader *fdtol, struct filedesc *fdp) +{ + FILEDESC_XLOCK(fdp); + fdtol->fdl_refcount++; + FILEDESC_XUNLOCK(fdp); + return (fdtol); +} + static int sysctl_kern_proc_nfds(SYSCTL_HANDLER_ARGS) { diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 32866aa26fba..90fc027b2979 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -451,10 +451,7 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread * * Shared file descriptor table, and shared * process leaders. */ - fdtol = p1->p_fdtol; - FILEDESC_XLOCK(p1->p_fd); - fdtol->fdl_refcount++; - FILEDESC_XUNLOCK(p1->p_fd); + fdtol = filedesc_to_leader_share(p1->p_fdtol, p1->p_fd); } else { /* * Shared file descriptor table, and different diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 9ae7b543e4a1..345576438c67 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -263,6 +263,9 @@ struct filedesc *fdshare(struct filedesc *fdp); struct filedesc_to_leader * filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, struct proc *leader); +struct filedesc_to_leader * + filedesc_to_leader_share(struct filedesc_to_leader *fdtol, + struct filedesc *fdp); int getvnode(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp); int getvnode_path(struct thread *td, int fd, cap_rights_t *rightsp,