svn commit: r189976 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb fs/cd9660 fs/udf

John Baldwin jhb at FreeBSD.org
Wed Mar 18 11:42:50 PDT 2009


Author: jhb
Date: Wed Mar 18 18:42:48 2009
New Revision: 189976
URL: http://svn.freebsd.org/changeset/base/189976

Log:
  MFC: Consolidate error handling in mount routines and make the mountpoint
  hold a reference on the cdev the fs is mounted on.

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/cd9660/cd9660_vfsops.c
  stable/7/sys/fs/udf/udf_vfsops.c

Modified: stable/7/sys/fs/cd9660/cd9660_vfsops.c
==============================================================================
--- stable/7/sys/fs/cd9660/cd9660_vfsops.c	Wed Mar 18 18:38:26 2009	(r189975)
+++ stable/7/sys/fs/cd9660/cd9660_vfsops.c	Wed Mar 18 18:42:48 2009	(r189976)
@@ -205,7 +205,7 @@ iso_mountfs(devvp, mp, td)
 	struct iso_mnt *isomp = (struct iso_mnt *)0;
 	struct buf *bp = NULL;
 	struct buf *pribp = NULL, *supbp = NULL;
-	struct cdev *dev = devvp->v_rdev;
+	struct cdev *dev;
 	int error = EINVAL;
 	int high_sierra = 0;
 	int iso_bsize;
@@ -221,6 +221,8 @@ iso_mountfs(devvp, mp, td)
 	struct bufobj *bo;
 	char *cs_local, *cs_disk;
 
+	dev = devvp->v_rdev;
+	dev_ref(dev);
 	DROP_GIANT();
 	g_topology_lock();
 	error = g_vfs_open(devvp, &cp, "cd9660", 0);
@@ -228,27 +230,21 @@ iso_mountfs(devvp, mp, td)
 	PICKUP_GIANT();
 	VOP_UNLOCK(devvp, 0, td);
 	if (error)
-		return error;
+		goto out;
 	if (devvp->v_rdev->si_iosize_max != 0)
 		mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max;
 	if (mp->mnt_iosize_max > MAXPHYS)
 		mp->mnt_iosize_max = MAXPHYS;
 
 	bo = &devvp->v_bufobj;
-	bo->bo_private = cp;
-	bo->bo_ops = g_vfs_bufops;
 
 	/* This is the "logical sector size".  The standard says this
 	 * should be 2048 or the physical sector size on the device,
 	 * whichever is greater.
 	 */
 	if ((ISO_DEFAULT_BLOCK_SIZE % cp->provider->sectorsize) != 0) {
-		DROP_GIANT();
-		g_topology_lock();
-		g_vfs_close(cp, td);
-		g_topology_unlock();
-                PICKUP_GIANT();
-		return (EINVAL);
+		error = EINVAL;
+		goto out;
 	}
 
 	iso_bsize = cp->provider->sectorsize;
@@ -487,6 +483,7 @@ out:
 		free((caddr_t)isomp, M_ISOFSMNT);
 		mp->mnt_data = (qaddr_t)0;
 	}
+	dev_rel(dev);
 	return error;
 }
 
@@ -526,6 +523,7 @@ cd9660_unmount(mp, mntflags, td)
 	g_topology_unlock();
 	PICKUP_GIANT();
 	vrele(isomp->im_devvp);
+	dev_rel(isomp->im_dev);
 	free((caddr_t)isomp, M_ISOFSMNT);
 	mp->mnt_data = (qaddr_t)0;
 	MNT_ILOCK(mp);

Modified: stable/7/sys/fs/udf/udf_vfsops.c
==============================================================================
--- stable/7/sys/fs/udf/udf_vfsops.c	Wed Mar 18 18:38:26 2009	(r189975)
+++ stable/7/sys/fs/udf/udf_vfsops.c	Wed Mar 18 18:42:48 2009	(r189976)
@@ -301,8 +301,10 @@ udf_checktag(struct desc_tag *tag, uint1
 }
 
 static int
-udf_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) {
+udf_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td)
+{
 	struct buf *bp = NULL;
+	struct cdev *dev;
 	struct anchor_vdp avdp;
 	struct udf_mnt *udfmp = NULL;
 	struct part_desc *pd;
@@ -319,6 +321,8 @@ udf_mountfs(struct vnode *devvp, struct 
 	struct g_consumer *cp;
 	struct bufobj *bo;
 
+	dev = devvp->v_rdev;
+	dev_ref(dev);
 	DROP_GIANT();
 	g_topology_lock();
 	error = g_vfs_open(devvp, &cp, "udf", 0);
@@ -326,7 +330,7 @@ udf_mountfs(struct vnode *devvp, struct 
 	PICKUP_GIANT();
 	VOP_UNLOCK(devvp, 0, td);
 	if (error)
-		return error;
+		goto bail;
 
 	bo = &devvp->v_bufobj;
 
@@ -347,7 +351,7 @@ udf_mountfs(struct vnode *devvp, struct 
 	mp->mnt_kern_flag |= MNTK_MPSAFE | MNTK_LOOKUP_SHARED;
 	MNT_IUNLOCK(mp);
 	udfmp->im_mountp = mp;
-	udfmp->im_dev = devvp->v_rdev;
+	udfmp->im_dev = dev;
 	udfmp->im_devvp = devvp;
 	udfmp->im_d2l = NULL;
 	udfmp->im_cp = cp;
@@ -364,12 +368,8 @@ udf_mountfs(struct vnode *devvp, struct 
 
 	if (((logical_secsize % cp->provider->sectorsize) != 0) ||
 	    (logical_secsize < cp->provider->sectorsize)) {
-		DROP_GIANT();
-		g_topology_lock();
-		g_vfs_close(cp, td);
-		g_topology_unlock();
-		PICKUP_GIANT();
-		return (EINVAL);
+		error = EINVAL;
+		goto bail;
 	}
 
 	bsize = cp->provider->sectorsize;
@@ -492,11 +492,14 @@ bail:
 		FREE(udfmp, M_UDFMOUNT);
 	if (bp != NULL)
 		brelse(bp);
-	DROP_GIANT();
-	g_topology_lock();
-	g_vfs_close(cp, td);
-	g_topology_unlock();
-	PICKUP_GIANT();
+	if (cp != NULL) {
+		DROP_GIANT();
+		g_topology_lock();
+		g_vfs_close(cp, td);
+		g_topology_unlock();
+		PICKUP_GIANT();
+	}
+	dev_rel(dev);
 	return error;
 };
 
@@ -529,6 +532,7 @@ udf_unmount(struct mount *mp, int mntfla
 	g_topology_unlock();
 	PICKUP_GIANT();
 	vrele(udfmp->im_devvp);
+	dev_rel(udfmp->im_dev);
 
 	if (udfmp->s_table != NULL)
 		FREE(udfmp->s_table, M_UDFMOUNT);


More information about the svn-src-stable-7 mailing list