From owner-svn-src-head@FreeBSD.ORG Wed Jun 13 19:00:30 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A4CBF1065672; Wed, 13 Jun 2012 19:00:30 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 8ED088FC1C; Wed, 13 Jun 2012 19:00:30 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5DJ0Uqn042701; Wed, 13 Jun 2012 19:00:30 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5DJ0UiI042699; Wed, 13 Jun 2012 19:00:30 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201206131900.q5DJ0UiI042699@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Wed, 13 Jun 2012 19:00:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237016 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2012 19:00:30 -0000 Author: pjd Date: Wed Jun 13 19:00:29 2012 New Revision: 237016 URL: http://svn.freebsd.org/changeset/base/237016 Log: There is only one caller of the dupfdopen() function, so we can simplify it a bit: - We can assert that only ENODEV and ENXIO errors are passed instead of handling other errors. - The caller always call finstall() for indx descriptor, so we can assume it is set. Actually the filedesc lock is dropped between finstall() and dupfdopen(), so there is a window there for another thread to close the indx descriptor, but it will be closed in next commit. Reviewed by: mjg MFC after: 1 month Modified: head/sys/kern/kern_descrip.c Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Wed Jun 13 18:57:27 2012 (r237015) +++ head/sys/kern/kern_descrip.c Wed Jun 13 19:00:29 2012 (r237016) @@ -2593,6 +2593,9 @@ dupfdopen(struct thread *td, struct file struct file *wfp; struct file *fp; + KASSERT(error == ENODEV || error == ENXIO, + ("unexpected error %d in %s", error, __func__)); + /* * If the to-be-dup'd fd number is greater than the allowed number * of file descriptors, or the fd to be dup'd has already been @@ -2612,9 +2615,8 @@ dupfdopen(struct thread *td, struct file * * For ENXIO steal away the file structure from (dfd) and store it in * (indx). (dfd) is effectively closed by this operation. - * - * Any other error code is just returned. */ + fp = fdp->fd_ofiles[indx]; switch (error) { case ENODEV: /* @@ -2625,48 +2627,28 @@ dupfdopen(struct thread *td, struct file FILEDESC_XUNLOCK(fdp); return (EACCES); } - fp = fdp->fd_ofiles[indx]; fdp->fd_ofiles[indx] = wfp; fdp->fd_ofileflags[indx] = fdp->fd_ofileflags[dfd]; - if (fp == NULL) - fdused(fdp, indx); fhold(wfp); - FILEDESC_XUNLOCK(fdp); - if (fp != NULL) - /* - * We now own the reference to fp that the ofiles[] - * array used to own. Release it. - */ - fdrop(fp, td); - return (0); - + break; case ENXIO: /* * Steal away the file pointer from dfd and stuff it into indx. */ - fp = fdp->fd_ofiles[indx]; - fdp->fd_ofiles[indx] = fdp->fd_ofiles[dfd]; + fdp->fd_ofiles[indx] = wfp; fdp->fd_ofiles[dfd] = NULL; fdp->fd_ofileflags[indx] = fdp->fd_ofileflags[dfd]; fdp->fd_ofileflags[dfd] = 0; fdunused(fdp, dfd); - if (fp == NULL) - fdused(fdp, indx); - FILEDESC_XUNLOCK(fdp); - - /* - * We now own the reference to fp that the ofiles[] array - * used to own. Release it. - */ - if (fp != NULL) - fdrop(fp, td); - return (0); - - default: - FILEDESC_XUNLOCK(fdp); - return (error); + break; } - /* NOTREACHED */ + FILEDESC_XUNLOCK(fdp); + /* + * We now own the reference to fp that the ofiles[] array used to own. + * Release it. + */ + fdrop(fp, td); + return (0); } /*