From owner-freebsd-bugs@FreeBSD.ORG Thu Nov 9 22:11:29 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 99DA416A4F1 for ; Thu, 9 Nov 2006 22:11:29 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1B65E43DB0 for ; Thu, 9 Nov 2006 22:10:21 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id kA9MAK2b092749 for ; Thu, 9 Nov 2006 22:10:20 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id kA9MAKiY092748; Thu, 9 Nov 2006 22:10:20 GMT (envelope-from gnats) Resent-Date: Thu, 9 Nov 2006 22:10:20 GMT Resent-Message-Id: <200611092210.kA9MAKiY092748@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ed Schouten Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3AC0316A412 for ; 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 ; 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/105346: fcntl(): prevent useless locking with F_DUPFD X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Ed Schouten List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Nov 2006 22:11:29 -0000 >Number: 105346 >Category: kern >Synopsis: fcntl(): prevent useless locking with F_DUPFD >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Nov 09 22:10:20 GMT 2006 >Closed-Date: >Last-Modified: >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: >Unformatted: