From owner-dev-commits-src-main@freebsd.org Wed Jan 13 03:31:42 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 74DB34EEE66; Wed, 13 Jan 2021 03:31:42 +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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DFtK91cXYz3Mkc; Wed, 13 Jan 2021 03:31:40 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 F0F3F10C1C; Wed, 13 Jan 2021 03:31:38 +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 10D3VclD029035; Wed, 13 Jan 2021 03:31:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10D3VcoJ029034; Wed, 13 Jan 2021 03:31:38 GMT (envelope-from git) Date: Wed, 13 Jan 2021 03:31:38 GMT Message-Id: <202101130331.10D3VcoJ029034@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: 4faa375cdd4e - main - fd: provide a dedicated closef variant for unix socket code MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4faa375cdd4e36d3a5b7fc46ee9dd8079a5e26f7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jan 2021 03:31:42 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=4faa375cdd4e36d3a5b7fc46ee9dd8079a5e26f7 commit 4faa375cdd4e36d3a5b7fc46ee9dd8079a5e26f7 Author: Mateusz Guzik AuthorDate: 2021-01-12 15:13:27 +0000 Commit: Mateusz Guzik CommitDate: 2021-01-13 02:27:03 +0000 fd: provide a dedicated closef variant for unix socket code This avoids testing for td != NULL. --- sys/kern/kern_descrip.c | 14 +++++++++++++- sys/kern/uipc_usrreq.c | 4 ++-- sys/sys/filedesc.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index ad1916e87b68..237d15fb5387 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -2737,6 +2737,8 @@ closef(struct file *fp, struct thread *td) struct filedesc_to_leader *fdtol; struct filedesc *fdp; + MPASS(td != NULL); + /* * POSIX record locking dictates that any close releases ALL * locks owned by this process. This is handled by setting @@ -2749,7 +2751,7 @@ closef(struct file *fp, struct thread *td) * context that might have locks, or the locks will be * leaked. */ - if (fp->f_type == DTYPE_VNODE && td != NULL) { + if (fp->f_type == DTYPE_VNODE) { vp = fp->f_vnode; if ((td->td_proc->p_leader->p_flag & P_ADVLOCK) != 0) { lf.l_whence = SEEK_SET; @@ -2797,6 +2799,16 @@ closef(struct file *fp, struct thread *td) return (fdrop_close(fp, td)); } +/* + * Hack for file descriptor passing code. + */ +void +closef_nothread(struct file *fp) +{ + + fdrop(fp, NULL); +} + /* * Initialize the file pointer with the specified properties. * diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 44e48bc864a3..0809f5180cc1 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -2486,7 +2486,7 @@ unp_discard(struct file *fp) atomic_add_int(&unp_defers_count, 1); taskqueue_enqueue(taskqueue_thread, &unp_defer_task); } else - (void) closef(fp, (struct thread *)NULL); + closef_nothread(fp); } static void @@ -2508,7 +2508,7 @@ unp_process_defers(void *arg __unused, int pending) count = 0; while ((dr = SLIST_FIRST(&drl)) != NULL) { SLIST_REMOVE_HEAD(&drl, ud_link); - closef(dr->ud_fp, NULL); + closef_nothread(dr->ud_fp); free(dr, M_TEMP); count++; } diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index ae2232814136..132aa6c1de03 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -224,6 +224,7 @@ void filecaps_move(struct filecaps *src, struct filecaps *dst); void filecaps_free(struct filecaps *fcaps); int closef(struct file *fp, struct thread *td); +void closef_nothread(struct file *fp); int dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode, int openerror, int *indxp); int falloc_caps(struct thread *td, struct file **resultfp, int *resultfd,