From nobody Wed Jan 24 05:12:14 2024 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 4TKXBk6cKsz57Sm9; Wed, 24 Jan 2024 05:12:14 +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 4TKXBk61Bpz4ZHt; Wed, 24 Jan 2024 05:12:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706073134; 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=D0qppDWaKW06TDqESf1BU5xo5kbEndJbe6WU7ltSCas=; b=N3inqXMZ48ndCkLLFT3nbKcXVxus00uL4fApFy04uKD9qer1TyctOTQRQRjJ4hubQg/Zah YltsysmQCWwFfaDTq2yk+KG/FAdgqynsYmG5y3+DGy89HUX2mEPeJa4JkqZ60OVP8npN2X 3eYwXi6Sr8z4h/FMO/G8MVK1YWI+lZxuyWOmwzFDTcPxSztnQdhAEQqzQgV7HZ49OHQmCB 8ZVu0m5xZ2W8xGoWrrgxmbqdKIuuQAD+c35vILJkTuk8TP+KVwPnKgRuLBe+CsAfGcoiV3 flNDJCzgjedBoHDg673nEwYEq+o3vXsAQ4FCtUclL+KAw9vD13+iAN9g3RxHFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706073134; 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=D0qppDWaKW06TDqESf1BU5xo5kbEndJbe6WU7ltSCas=; b=fmum5z6BO+UHwkNmaOQtVVDG0qjlV2cqmclYGoQ1oVABxd6N4cOTSwJ6ZrwBcWBclvNb/Q uWlhtiVoDrvOI7Yk5wJCpXn7YtPjV65T9CH184Y5pKSvJFkijGj6ce4WvvTpAc1+QqLTO5 vdj/vpZZ0OiZVddz+2MZK9DzaLykEQkCifojeuqlP/948AI12q/sbTewJBwuCqC03qwE8t I5PIDP4WprnuHAB0vXPMhXqKvhbhAfUoiNJ1IJ+Vq5YgUATa+MKhM0A2+yEcbzH/1I9Sfd etBIzn11FzHQ4uvzgM6htjSNmm4GJwfnJ7k8rXufqr4nwIYDPaXstk5p3AwLvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706073134; a=rsa-sha256; cv=none; b=LfuHKWPz/SMiItdV7RrnLWNEpNZ3MJg+ZYxEHKrHcJHg0/370j3FcEgdugON0vWsBsHUHm Ix8demD81TpUnYx5/ziMY/UPCYoRNYHW8nZUXeXCub1S/DQxSjHfPnTVlWFjiMoEeOXxr3 TqggtJ3u5JwkSQjjagX53DTZt+UwmusSkq4DXzzfked82jYlsDyrFvc5jZVYR52nmj9pgD CwuCfMnwILIlzKpdh7w/xnNeBnkevtwMTFmKOhTRlX115VwTiSXXq1a83mxorsM7/Cd8Hp vKC3LQq4J2X/yw9lAIyEfAAXaygLdH4p28loFv1DYGnwWZ6E6gML0bcfsytP7w== 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 4TKXBk54Znz11Sf; Wed, 24 Jan 2024 05:12:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40O5CEJS039976; Wed, 24 Jan 2024 05:12:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40O5CEo1039973; Wed, 24 Jan 2024 05:12:14 GMT (envelope-from git) Date: Wed, 24 Jan 2024 05:12:14 GMT Message-Id: <202401240512.40O5CEo1039973@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 58d317169834 - main - Add fget_remote() 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 58d3171698341c664d7c676541b86385a924ae93 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=58d3171698341c664d7c676541b86385a924ae93 commit 58d3171698341c664d7c676541b86385a924ae93 Author: Konstantin Belousov AuthorDate: 2024-01-22 22:31:55 +0000 Commit: Konstantin Belousov CommitDate: 2024-01-24 05:11:26 +0000 Add fget_remote() The function holds and returns struct file for a file descriptor index in the given process. Reviewed by: brooks, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43518 --- sys/kern/kern_descrip.c | 32 ++++++++++++++++++++++++++++++++ sys/sys/file.h | 1 + 2 files changed, 33 insertions(+) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index a0130842aacb..e8e08f57196b 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -2960,6 +2960,38 @@ fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp, } #endif +int +fget_remote(struct thread *td, struct proc *p, int fd, struct file **fpp) +{ + struct filedesc *fdp; + struct file *fp; + int error; + + if (p == td->td_proc) /* curproc */ + return (fget_unlocked(td, fd, &cap_no_rights, fpp)); + + PROC_LOCK(p); + fdp = fdhold(p); + PROC_UNLOCK(p); + if (fdp == NULL) + return (ENOENT); + FILEDESC_SLOCK(fdp); + if (refcount_load(&fdp->fd_refcnt) != 0) { + fp = fget_noref(fdp, fd); + if (fp != NULL && fhold(fp)) { + *fpp = fp; + error = 0; + } else { + error = EBADF; + } + } else { + error = ENOENT; + } + FILEDESC_SUNLOCK(fdp); + fddrop(fdp); + return (error); +} + #ifdef CAPABILITIES int fgetvp_lookup_smr(struct nameidata *ndp, struct vnode **vpp, bool *fsearch) diff --git a/sys/sys/file.h b/sys/sys/file.h index 0bdf7e9baa7b..83da5105ad2b 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -261,6 +261,7 @@ int fget_write(struct thread *td, int fd, cap_rights_t *rightsp, int fget_fcntl(struct thread *td, int fd, cap_rights_t *rightsp, int needfcntl, struct file **fpp); int _fdrop(struct file *fp, struct thread *td); +int fget_remote(struct thread *td, struct proc *p, int fd, struct file **fpp); fo_rdwr_t invfo_rdwr; fo_truncate_t invfo_truncate;