Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Sep 2002 13:16:31 -0700 (PDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   cvs commit: src/sys/kern kern_descrip.c
Message-ID:  <200209032016.g83KGVOH086691@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
jhb         2002/09/03 13:16:31 PDT

  Modified files:
    sys/kern             kern_descrip.c 
  Log:
  - Change falloc() to acquire an fd from the process table last so that
    it can do it w/o needing to hold the filelist_lock sx lock.
  - fdalloc() doesn't need Giant to call free() anymore.  It also doesn't
    need to drop and reacquire the filedesc lock around free() now as a
    result.
  - Try to make the code that copies fd tables when extending the fd table in
    fdalloc() a bit more readable by performing assignments in separate
    statements.  This is still a bit ugly though.
  - Use max() instead of an if statement so to figure out the starting point
    in the search-for-a-free-fd loop in fdalloc() so it reads better next to
    the min() in the previous line.
  - Don't grow nfiles in steps up to the size needed if we dup2() to some
    really large number.  Go ahead and double 'nfiles' in a loop prior
    to doing the malloc().
  - malloc() doesn't need Giant now.
  - Use malloc() and free() instead of MALLOC() and FREE() in fdalloc().
  - Check to see if the size we are going to grow to is too big, not if the
    current size of the fd table is too big in the loop in fdalloc().  This
    means if we are out of space or if dup2() requests too high of a fd,
    then we will return an error before we go off and try to allocate some
    huge table and copy the existing table into it.
  - Move all of the logic for dup'ing a file descriptor into do_dup() instead
    of putting some of it in do_dup() and duplicating other parts in four
    different places.  This makes dup(), dup2(), and fcntl(F_DUPFD) basically
    wrappers of do_dup now.  fcntl() still has an extra check since it uses
    a different error return value in one case then the other functions.
  - Add a KASSERT() for an assertion that may not always be true where the
    fdcheckstd() function assumes that falloc() returns the fd requested and
    not some other fd.  I think that the assertion is always true because we
    are always single-threaded when we get to this point, but if one was
    using rfork() and another process sharing the fd table were playing with
    the fd table, there might could be a problem.
  - To handle the problem of a file descriptor we are dup()'ing being closed
    out from under us in dup() in general, do_dup() now obtains a reference
    on the file in question before calling fdalloc().  If after the call to
    fdalloc() the file for the fd we are dup'ing is a different file, then
    we drop our reference on the original file and return EBADF.  This
    race was only handled in the dup2() case before and would just retry
    the operation.  The error return allows the user to know they are being
    stupid since they have a locking bug in their app instead of dup'ing
    some other descriptor and returning it to them.
  
  Tested on:      i386, alpha, sparc64
  
  Revision  Changes    Path
  1.158     +102 -108  src/sys/kern/kern_descrip.c

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209032016.g83KGVOH086691>