Re: function prototype of fdrop() and fdrop_locked() in kern_descrip.c

From: David Malone (dwmalone_at_maths.tcd.ie)
Date: 02/27/05

  • Next message: ALeine: "Re: sandisk cruzer mini quirks [failure] on RELENG_4"
    Date: Sun, 27 Feb 2005 11:05:19 +0000
    To: Yan Yu <yanyu@CS.UCLA.EDU>
    
    

    On Sat, Feb 26, 2005 at 11:22:03PM -0800, Yan Yu wrote:
    > I am wondering about what is the motivation of fdrop is defined as
    > A) as opposed to B).. or it is an arbitrary design choice?

    > it seems to me fdrop is called usually when an fd is freed(or is there
    > other reason that fdrop get called?),

    fdrop is called to drop the reference count in a file structure.
    That file structure may or may not correspond to a file that has
    an entry in the file discriptor table. For example, suppose you
    have two processes sharing a file discriptor table (as happens with
    certain threading schemes) and the following happens:

            thread 1 thread 2
            calls read on fd 1
            *sleeps in read*
                                    closes fd 1
            read completes

    At the time read completes, there is no entry in any file discriptor
    table for fd 1, but read is still using the file structure, so it must
    remain valid even though the file has been closed.

    Similar things can happen while descriptors are being passed over
    Unix domain sockets.

    So, fdrop is to do with the lifetime of the file structure not the
    lifetime of the file discriptor entry. If you want to track file
    discriptor entries, you'll have to track where fd_ofiles is
    manuipulated - these should be fairly obvious as they all involve
    grabbing the FILEDESC_LOCK.

            David.
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: ALeine: "Re: sandisk cruzer mini quirks [failure] on RELENG_4"