Author: mjg
Date: Thu Jul 16 15:26:37 2015
New Revision: 285636
URL: https://svnweb.freebsd.org/changeset/base/285636

Log:
  fd: partially deduplicate fdescfree and fdescfree_remapped
  
  This also moves vrele of cdir/rdir/jdir vnodes earlier, which should not
  matter.

Modified:
  head/sys/kern/kern_descrip.c

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c        Thu Jul 16 15:13:17 2015        
(r285635)
+++ head/sys/kern/kern_descrip.c        Thu Jul 16 15:26:37 2015        
(r285636)
@@ -2110,18 +2110,46 @@ retry:
 /*
  * Release a filedesc structure.
  */
-void
-fdescfree(struct thread *td)
+static void
+fdescfree_fds(struct thread *td, struct filedesc *fdp, bool needclose)
 {
-       struct proc *p;
        struct filedesc0 *fdp0;
-       struct filedesc *fdp;
        struct freetable *ft, *tft;
        struct filedescent *fde;
        struct file *fp;
-       struct vnode *cdir, *jdir, *rdir;
        int i;
 
+       for (i = 0; i <= fdp->fd_lastfile; i++) {
+               fde = &fdp->fd_ofiles[i];
+               fp = fde->fde_file;
+               if (fp != NULL) {
+                       fdefree_last(fde);
+                       if (needclose)
+                               (void) closef(fp, td);
+                       else
+                               fdrop(fp, td);
+               }
+       }
+
+       if (NDSLOTS(fdp->fd_nfiles) > NDSLOTS(NDFILE))
+               free(fdp->fd_map, M_FILEDESC);
+       if (fdp->fd_nfiles > NDFILE)
+               free(fdp->fd_files, M_FILEDESC);
+
+       fdp0 = (struct filedesc0 *)fdp;
+       SLIST_FOREACH_SAFE(ft, &fdp0->fd_free, ft_next, tft)
+               free(ft->ft_table, M_FILEDESC);
+
+       fddrop(fdp);
+}
+
+void
+fdescfree(struct thread *td)
+{
+       struct proc *p;
+       struct filedesc *fdp;
+       struct vnode *cdir, *jdir, *rdir;
+
        p = td->td_proc;
        fdp = p->p_fd;
        MPASS(fdp != NULL);
@@ -2134,7 +2162,7 @@ fdescfree(struct thread *td)
        }
 #endif
 
-       if (td->td_proc->p_fdtol != NULL)
+       if (p->p_fdtol != NULL)
                fdclearlocks(td);
 
        PROC_LOCK(p);
@@ -2153,24 +2181,6 @@ fdescfree(struct thread *td)
        fdp->fd_jdir = NULL;
        FILEDESC_XUNLOCK(fdp);
 
-       for (i = 0; i <= fdp->fd_lastfile; i++) {
-               fde = &fdp->fd_ofiles[i];
-               fp = fde->fde_file;
-               if (fp != NULL) {
-                       fdefree_last(fde);
-                       (void) closef(fp, td);
-               }
-       }
-
-       if (NDSLOTS(fdp->fd_nfiles) > NDSLOTS(NDFILE))
-               free(fdp->fd_map, M_FILEDESC);
-       if (fdp->fd_nfiles > NDFILE)
-               free(fdp->fd_files, M_FILEDESC);
-
-       fdp0 = (struct filedesc0 *)fdp;
-       SLIST_FOREACH_SAFE(ft, &fdp0->fd_free, ft_next, tft)
-               free(ft->ft_table, M_FILEDESC);
-
        if (cdir != NULL)
                vrele(cdir);
        if (rdir != NULL)
@@ -2178,35 +2188,12 @@ fdescfree(struct thread *td)
        if (jdir != NULL)
                vrele(jdir);
 
-       fddrop(fdp);
+       fdescfree_fds(td, fdp, 1);
 }
 
 void
 fdescfree_remapped(struct filedesc *fdp)
 {
-       struct filedesc0 *fdp0;
-       struct filedescent *fde;
-       struct file *fp;
-       struct freetable *ft, *tft;
-       int i;
-
-       for (i = 0; i <= fdp->fd_lastfile; i++) {
-               fde = &fdp->fd_ofiles[i];
-               fp = fde->fde_file;
-               if (fp != NULL) {
-                       fdefree_last(fde);
-                       (void) closef(fp, NULL);
-               }
-       }
-
-       if (NDSLOTS(fdp->fd_nfiles) > NDSLOTS(NDFILE))
-               free(fdp->fd_map, M_FILEDESC);
-       if (fdp->fd_nfiles > NDFILE)
-               free(fdp->fd_files, M_FILEDESC);
-
-       fdp0 = (struct filedesc0 *)fdp;
-       SLIST_FOREACH_SAFE(ft, &fdp0->fd_free, ft_next, tft)
-               free(ft->ft_table, M_FILEDESC);
 
        if (fdp->fd_cdir != NULL)
                vrele(fdp->fd_cdir);
@@ -2214,7 +2201,8 @@ fdescfree_remapped(struct filedesc *fdp)
                vrele(fdp->fd_rdir);
        if (fdp->fd_jdir != NULL)
                vrele(fdp->fd_jdir);
-       fddrop(fdp);
+
+       fdescfree_fds(curthread, fdp, 0);
 }
 
 /*
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to