Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 May 2009 02:42:29 +0000 (UTC)
From:      Dag-Erling Smorgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r192079 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb fs/procfs fs/pseudofs
Message-ID:  <200905140242.n4E2gTCr074630@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Thu May 14 02:42:29 2009
New Revision: 192079
URL: http://svn.freebsd.org/changeset/base/192079

Log:
  MFC r188677: always call pfs_attr if defined
  MFC r190806: fix incorrect KASSERT, add more
  MFC r188677: remove incorrect locking

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/ath/ath_hal/   (props changed)
  stable/7/sys/dev/cxgb/   (props changed)
  stable/7/sys/fs/procfs/procfs.c
  stable/7/sys/fs/pseudofs/pseudofs_vnops.c

Modified: stable/7/sys/fs/procfs/procfs.c
==============================================================================
--- stable/7/sys/fs/procfs/procfs.c	Thu May 14 02:27:38 2009	(r192078)
+++ stable/7/sys/fs/procfs/procfs.c	Thu May 14 02:42:29 2009	(r192079)
@@ -99,7 +99,6 @@ procfs_docurproc(PFS_FILL_ARGS)
 int
 procfs_attr(PFS_ATTR_ARGS)
 {
-	PROC_LOCK_ASSERT(p, MA_OWNED);
 
 	/* XXX inefficient, split into separate functions */
 	if (strcmp(pn->pn_name, "ctl") == 0 ||
@@ -112,11 +111,12 @@ procfs_attr(PFS_ATTR_ARGS)
 	    strcmp(pn->pn_name, "fpregs") == 0)
 		vap->va_mode = 0600;
 
-	if ((p->p_flag & P_SUGID) && pn->pn_type != pfstype_procdir)
-		vap->va_mode = 0;
+	if (p != NULL) {
+		PROC_LOCK_ASSERT(p, MA_OWNED);
 
-	vap->va_uid = p->p_ucred->cr_uid;
-	vap->va_gid = p->p_ucred->cr_gid;
+		if ((p->p_flag & P_SUGID) && pn->pn_type != pfstype_procdir)
+			vap->va_mode = 0;
+	}
 
 	return (0);
 }

Modified: stable/7/sys/fs/pseudofs/pseudofs_vnops.c
==============================================================================
--- stable/7/sys/fs/pseudofs/pseudofs_vnops.c	Thu May 14 02:27:38 2009	(r192078)
+++ stable/7/sys/fs/pseudofs/pseudofs_vnops.c	Thu May 14 02:42:29 2009	(r192079)
@@ -52,6 +52,20 @@ __FBSDID("$FreeBSD$");
 #include <fs/pseudofs/pseudofs.h>
 #include <fs/pseudofs/pseudofs_internal.h>
 
+#define KASSERT_PN_IS_DIR(pn)						\
+	KASSERT((pn)->pn_type == pfstype_root ||			\
+	    (pn)->pn_type == pfstype_dir ||				\
+	    (pn)->pn_type == pfstype_procdir,				\
+	    ("%s(): VDIR vnode refers to non-directory pfs_node", __func__))
+
+#define KASSERT_PN_IS_FILE(pn)						\
+	KASSERT((pn)->pn_type == pfstype_file,				\
+	    ("%s(): VREG vnode refers to non-file pfs_node", __func__))
+
+#define KASSERT_PN_IS_LINK(pn)						\
+	KASSERT((pn)->pn_type == pfstype_symlink,			\
+	    ("%s(): VLNK vnode refers to non-link pfs_node", __func__))
+
 /*
  * Returns the fileno, adjusted for target pid
  */
@@ -226,14 +240,17 @@ pfs_getattr(struct vop_getattr_args *va)
 	if (proc != NULL) {
 		vap->va_uid = proc->p_ucred->cr_ruid;
 		vap->va_gid = proc->p_ucred->cr_rgid;
-		if (pn->pn_attr != NULL)
-			error = pn_attr(va->a_td, proc, pn, vap);
-		PROC_UNLOCK(proc);
 	} else {
 		vap->va_uid = 0;
 		vap->va_gid = 0;
 	}
 
+	if (pn->pn_attr != NULL)
+		error = pn_attr(va->a_td, proc, pn, vap);
+
+	if(proc != NULL)
+		PROC_UNLOCK(proc);
+
 	PFS_RETURN (error);
 }
 
@@ -254,6 +271,7 @@ pfs_ioctl(struct vop_ioctl_args *va)
 
 	if (vn->v_type != VREG)
 		PFS_RETURN (EINVAL);
+	KASSERT_PN_IS_FILE(pn);
 
 	if (pn->pn_ioctl == NULL)
 		PFS_RETURN (ENOTTY);
@@ -330,6 +348,7 @@ pfs_lookup(struct vop_cachedlookup_args 
 
 	if (vn->v_type != VDIR)
 		PFS_RETURN (ENOTDIR);
+	KASSERT_PN_IS_DIR(pd);
 
 	error = VOP_ACCESS(vn, VEXEC, cnp->cn_cred, cnp->cn_thread);
 	if (error)
@@ -484,6 +503,7 @@ pfs_read(struct vop_read_args *va)
 
 	if (vn->v_type != VREG)
 		PFS_RETURN (EINVAL);
+	KASSERT_PN_IS_FILE(pn);
 
 	if (!(pn->pn_flags & PFS_RD))
 		PFS_RETURN (EBADF);
@@ -626,6 +646,7 @@ pfs_readdir(struct vop_readdir_args *va)
 
 	if (vn->v_type != VDIR)
 		PFS_RETURN (ENOTDIR);
+	KASSERT_PN_IS_DIR(pd);
 	uio = va->a_uio;
 
 	/* only allow reading entire entries */
@@ -734,6 +755,7 @@ pfs_readlink(struct vop_readlink_args *v
 
 	if (vn->v_type != VLNK)
 		PFS_RETURN (EINVAL);
+	KASSERT_PN_IS_LINK(pn);
 
 	if (pn->pn_fill == NULL)
 		PFS_RETURN (EIO);
@@ -819,8 +841,7 @@ pfs_write(struct vop_write_args *va)
 
 	if (vn->v_type != VREG)
 		PFS_RETURN (EINVAL);
-	KASSERT(pn->pn_type != pfstype_file,
-	    ("%s(): VREG vnode refers to non-file pfs_node", __func__));
+	KASSERT_PN_IS_FILE(pn);
 
 	if (!(pn->pn_flags & PFS_WR))
 		PFS_RETURN (EBADF);
@@ -840,9 +861,7 @@ pfs_write(struct vop_write_args *va)
 	}
 
 	if (pn->pn_flags & PFS_RAWWR) {
-		pfs_lock(pn);
 		error = pn_fill(curthread, proc, pn, NULL, uio);
-		pfs_unlock(pn);
 		if (proc != NULL)
 			PRELE(proc);
 		PFS_RETURN (error);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905140242.n4E2gTCr074630>