From ed@hoeg.nl  Thu Nov  9 22:03:19 2006
Return-Path: <ed@hoeg.nl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3AC0316A412
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  9 Nov 2006 22:03:19 +0000 (UTC)
	(envelope-from ed@hoeg.nl)
Received: from palm.hoeg.nl (palm.hoeg.nl [83.98.131.212])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9FD6B43D97
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  9 Nov 2006 22:02:43 +0000 (GMT)
	(envelope-from ed@hoeg.nl)
Received: by palm.hoeg.nl (Postfix, from userid 1000)
	id 7CA461CE94; Thu,  9 Nov 2006 23:02:27 +0100 (CET)
Message-Id: <20061109220227.7CA461CE94@palm.hoeg.nl>
Date: Thu,  9 Nov 2006 23:02:27 +0100 (CET)
From: Ed Schouten <ed@fxq.nl>
Reply-To: Ed Schouten <ed@fxq.nl>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: fcntl(): prevent useless locking with F_DUPFD
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         105346
>Category:       kern
>Synopsis:       [libc] [patch] fcntl(): prevent useless locking with F_DUPFD
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 09 22:10:20 GMT 2006
>Closed-Date:    Wed Jul 30 21:22:54 UTC 2008
>Last-Modified:  Wed Jul 30 21:22:54 UTC 2008
>Originator:     Ed Schouten
>Release:        FreeBSD 6.2-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD palm.hoeg.nl 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #0: Fri Oct 6 14:06:07 CEST 2006 root@palm.hoeg.nl:/usr/obj/usr/src/sys/PALM i386
>Description:
The system calls dup() and dup2() allow you to duplicate file
descriptors. The fcntl(..., F_DUPFD, ...) function allows you to do
something similar as dup(). The only difference is the errno variable
that is returned when the given offset is too high.

The FreeBSD kernel implements all dup() related functionality through
the do_dup() function. The problem is that the kern_fcntl() function
almost performs the same tests as the do_dup() call, causing some
duplicate code and worst of all: more locking.
>How-To-Repeat:
n/a
>Fix:
The patch located at http://g-rave.nl/junk/freebsd-kern_descrip.diff
makes kern_fcntl() immediately call do_dup() when the request is
F_DUPFD, causing the FILEDESC_LOCK and PROC_LOCK to be contested only
once in do_dup().

It also changes the errno when the offset is too high to EINVAL instead
of EMFILE. The dup() and dup2() functions will set it back to EMFILE to
remain POSIX compliant.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Sat Nov 11 16:37:02 UTC 2006 
Responsible-Changed-Why:  
Over to DES. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105346 

From: Ed Schouten <ed@fxq.nl>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: kern/105346: fcntl(): prevent useless locking with F_DUPFD
Date: Wed, 4 Jul 2007 16:31:02 +0200

 --+jhVVhN62yS6hEJ8
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Hello,
 
 I've just updated the patch to apply on the latest CURRENT again. Jeff
 did some improvements to the kern_fcntl() routine to push down the usage
 of Giant even further, which caused the layout of the routine to change.
 
 The patch is now more compact and more readable.
 
 --=20
  Ed Schouten <ed@fxq.nl>
  WWW: http://g-rave.nl/
 
 --+jhVVhN62yS6hEJ8
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.7 (FreeBSD)
 
 iD8DBQFGi68m52SDGA2eCwURAg4lAJwJGSnpCBEVggMdTVDgzt8qMZikJwCfY7HU
 wIDhaeZZoU05O3lVGSGlByE=
 =6rEg
 -----END PGP SIGNATURE-----
 
 --+jhVVhN62yS6hEJ8--
State-Changed-From-To: open->closed 
State-Changed-By: ed 
State-Changed-When: Wed Jul 30 21:22:53 UTC 2008 
State-Changed-Why:  
Committed, with minor changes. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105346 
>Unformatted:
