The branch main has been updated by mjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4faa375cdd4e36d3a5b7fc46ee9dd8079a5e26f7

commit 4faa375cdd4e36d3a5b7fc46ee9dd8079a5e26f7
Author:     Mateusz Guzik <[email protected]>
AuthorDate: 2021-01-12 15:13:27 +0000
Commit:     Mateusz Guzik <[email protected]>
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,
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to