From owner-svn-src-all@FreeBSD.ORG Thu Oct 20 18:54:05 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 681A31065670; Thu, 20 Oct 2011 18:54:05 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 55A0C8FC08; Thu, 20 Oct 2011 18:54:05 +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 p9KIs5kF087172; Thu, 20 Oct 2011 18:54:05 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p9KIs5Z8087169; Thu, 20 Oct 2011 18:54:05 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201110201854.p9KIs5Z8087169@svn.freebsd.org> From: Konstantin Belousov Date: Thu, 20 Oct 2011 18:54:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226578 - in stable/9/sys: kern sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Oct 2011 18:54:05 -0000 Author: kib Date: Thu Oct 20 18:54:05 2011 New Revision: 226578 URL: http://svn.freebsd.org/changeset/base/226578 Log: MFC r226042: Supply unique (st_dev, st_ino) value pair for the fstat(2) done on the pipes. Approved by: re (bz) Modified: stable/9/sys/kern/sys_pipe.c stable/9/sys/sys/pipe.h Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/sys_pipe.c ============================================================================== --- stable/9/sys/kern/sys_pipe.c Thu Oct 20 18:47:58 2011 (r226577) +++ stable/9/sys/kern/sys_pipe.c Thu Oct 20 18:54:05 2011 (r226578) @@ -93,6 +93,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -224,6 +225,8 @@ static int pipe_zone_init(void *mem, int static void pipe_zone_fini(void *mem, int size); static uma_zone_t pipe_zone; +static struct unrhdr *pipeino_unr; +static dev_t pipedev_ino; SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_ANY, pipeinit, NULL); @@ -235,6 +238,10 @@ pipeinit(void *dummy __unused) pipe_zone_ctor, NULL, pipe_zone_init, pipe_zone_fini, UMA_ALIGN_PTR, 0); KASSERT(pipe_zone != NULL, ("pipe_zone not initialized")); + pipeino_unr = new_unrhdr(1, INT32_MAX, NULL); + KASSERT(pipeino_unr != NULL, ("pipe fake inodes not initialized")); + pipedev_ino = devfs_alloc_cdp_inode(); + KASSERT(pipedev_ino > 0, ("pipe dev inode not initialized")); } static int @@ -562,6 +569,12 @@ pipe_create(pipe, backing) /* If we're not backing this pipe, no need to do anything. */ error = 0; } + if (error == 0) { + pipe->pipe_ino = alloc_unr(pipeino_unr); + if (pipe->pipe_ino == -1) + /* pipeclose will clear allocated kva */ + error = ENOMEM; + } return (error); } @@ -1408,9 +1421,10 @@ pipe_stat(fp, ub, active_cred, td) ub->st_ctim = pipe->pipe_ctime; ub->st_uid = fp->f_cred->cr_uid; ub->st_gid = fp->f_cred->cr_gid; + ub->st_dev = pipedev_ino; + ub->st_ino = pipe->pipe_ino; /* - * Left as 0: st_dev, st_ino, st_nlink, st_rdev, st_flags, st_gen. - * XXX (st_dev, st_ino) should be unique. + * Left as 0: st_nlink, st_rdev, st_flags, st_gen. */ return (0); } @@ -1463,6 +1477,7 @@ pipeclose(cpipe) { struct pipepair *pp; struct pipe *ppipe; + ino_t ino; KASSERT(cpipe != NULL, ("pipeclose: cpipe == NULL")); @@ -1521,6 +1536,12 @@ pipeclose(cpipe) knlist_destroy(&cpipe->pipe_sel.si_note); /* + * Postpone the destroy of the fake inode number allocated for + * our end, until pipe mtx is unlocked. + */ + ino = cpipe->pipe_ino; + + /* * If both endpoints are now closed, release the memory for the * pipe pair. If not, unlock. */ @@ -1532,6 +1553,9 @@ pipeclose(cpipe) uma_zfree(pipe_zone, cpipe->pipe_pair); } else PIPE_UNLOCK(cpipe); + + if (ino > 0) + free_unr(pipeino_unr, cpipe->pipe_ino); } /*ARGSUSED*/ Modified: stable/9/sys/sys/pipe.h ============================================================================== --- stable/9/sys/sys/pipe.h Thu Oct 20 18:47:58 2011 (r226577) +++ stable/9/sys/sys/pipe.h Thu Oct 20 18:54:05 2011 (r226578) @@ -112,6 +112,7 @@ struct pipe { u_int pipe_state; /* pipe status info */ int pipe_busy; /* busy flag, mostly to handle rundown sanely */ int pipe_present; /* still present? */ + ino_t pipe_ino; /* fake inode for stat(2) */ }; /*