Date: Wed, 13 Jun 2012 19:00:30 +0000 (UTC) From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r237016 - head/sys/kern Message-ID: <201206131900.q5DJ0UiI042699@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206131900.q5DJ0UiI042699>