PERFORCE change 169580 for review

Aditya Sarawgi truncs at FreeBSD.org
Sun Oct 18 19:48:17 UTC 2009


http://p4web.freebsd.org/chv.cgi?CH=169580

Change 169580 by truncs at aditya on 2009/10/18 19:47:55

	Apply locking primitives to allocation functions.

Affected files ...

.. //depot/projects/soc2009/soc_ext2fs/src/sys/fs/ext2fs/ext2_alloc.c#11 edit

Differences ...

==== //depot/projects/soc2009/soc_ext2fs/src/sys/fs/ext2fs/ext2_alloc.c#11 (text+ko) ====

@@ -100,10 +100,13 @@
 	int32_t *bnp;
 {
 	struct m_ext2fs *fs;
+	struct ext2mount *ump;
 	int32_t bno;
 	int cg;	
 	*bnp = 0;
 	fs = ip->i_e2fs;
+	ump = ip->i_ump;
+	mtx_assert(EXT2_MTX(ump), MA_OWNED);
 #ifdef DIAGNOSTIC
 	if ((u_int)size > fs->e2fs_bsize || blkoff(fs, size) != 0) {
 		vn_printf(ip->i_devvp, "bsize = %lu, size = %d, fs = %s\n",
@@ -177,6 +180,7 @@
 	struct inode *ip;
 	struct vnode *vp;
 	struct buf *sbp, *ebp;
+	struct ext2mount *ump;
 	struct cluster_save *buflist;
 	struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp;
 	int32_t *bap, *sbap, *ebap;
@@ -186,6 +190,7 @@
 	vp = ap->a_vp;
 	ip = VTOI(vp);
 	fs = ip->i_e2fs;
+	ump = ip->i_ump;
 #ifdef UNKLAR
 	if (fs->fs_contigsumsize <= 0)
 		return (ENOSPC);
@@ -228,6 +233,7 @@
 	/*
 	 * Find the preferred location for the cluster.
 	 */
+	EXT2_LOCK(ump); 
 	pref = ext2_blkpref(ip, start_lbn, soff, sbap);
 	/*
 	 * If the block range spans two block maps, get the second map.
@@ -240,16 +246,20 @@
 			panic("ext2_reallocblk: start == end");
 #endif
 		ssize = len - (idp->in_off + 1);
-		if (bread(vp, idp->in_lbn, (int)fs->e2fs_bsize, NOCRED, &ebp))
+		if (bread(vp, idp->in_lbn, (int)fs->e2fs_bsize, NOCRED, &ebp)){
+			EXT2_UNLOCK(ump);	
 			goto fail;
+		}
 		ebap = (int32_t *)ebp->b_data;
 	}
 	/*
 	 * Search the block map looking for an allocation of the desired size.
 	 */
 	if ((newblk = (int32_t)ext2_hashalloc(ip, dtog(fs, pref), (long)pref,
-	    len, (u_long (*)())ext2_clusteralloc)) == 0)
+	    len, (u_long (*)())ext2_clusteralloc)) == 0){
+		EXT2_UNLOCK(ump);
 		goto fail;
+	}	
 	/*
 	 * We have found a new contiguous block.
 	 *
@@ -330,12 +340,16 @@
 	struct inode *pip;
 	struct m_ext2fs *fs;
 	struct inode *ip;
+	struct ext2mount *ump;
 	ino_t ino, ipref;
 	int i, error, cg;
 	
 	*vpp = NULL;
 	pip = VTOI(pvp);
 	fs = pip->i_e2fs;
+	ump = pip->i_ump;
+
+	EXT2_LOCK(ump);
 	if (fs->e2fs->e2fs_ficount == 0)
 		goto noinodes;
 	/*
@@ -390,6 +404,7 @@
 */
 	return (0);
 noinodes:
+	EXT2_UNLOCK(ump);
 	ext2_fserr(fs, cred->cr_uid, "out of inodes");
 	uprintf("\n%s: create/symlink failed, no inodes free\n", fs->e2fs_fsmnt);
 	return (ENOSPC);
@@ -419,6 +434,7 @@
 	int mincg, minndir;
 	int maxcontigdirs;
 
+	mtx_assert(EXT2_MTX(pip->i_ump), MA_OWNED);
 	fs = pip->i_e2fs;
 
  	avgifree = fs->e2fs->e2fs_ficount / fs->e2fs_gcount;
@@ -529,6 +545,7 @@
 	int32_t blocknr;
 {
 	int	tmp;
+	mtx_assert(EXT2_MTX(pip->i_ump), MA_OWNED);
 
 	/* if the next block is actually what we thought it is,
 	   then set the goal to what we thought it should be
@@ -569,6 +586,7 @@
         ino_t result;
         int i, icg = cg;
 
+	mtx_assert(EXT2_MTX(ip->i_ump), MA_OWNED);
         fs = ip->i_e2fs;
         /*
          * 1: preferred cylinder group
@@ -615,18 +633,22 @@
 {
 	struct m_ext2fs *fs;
 	struct buf *bp;
+	struct ext2mount *ump;
 	int error, bno, start, end, loc;
 	char *bbp;
 	/* XXX ondisk32 */
 	
 	fs = ip->i_e2fs;
+	ump = ip->i_ump;
 	if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0)
 		return (0);
+	EXT2_UNLOCK(ump);				
 	error = bread(ip->i_devvp, fsbtodb(fs,
 		fs->e2fs_gd[cg].ext2bgd_b_bitmap),
 		(int)fs->e2fs_bsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
+		EXT2_LOCK(ump);
 		return (0);
 	}
 	bbp = (char *)bp->b_data;
@@ -669,6 +691,8 @@
 
 	bno = ext2_mapsearch(fs, bbp, bpref);
 	if (bno < 0){
+		brelse(bp);
+		EXT2_LOCK(ump);
 		return (0);
 	}
 gotit:
@@ -680,9 +704,11 @@
 	}
 #endif
 	setbit(bbp, (daddr_t)bno);
+	EXT2_LOCK(ump);
 	fs->e2fs->e2fs_fbcount--;
 	fs->e2fs_gd[cg].ext2bgd_nbfree--;
 	fs->e2fs_fmod = 1;
+	EXT2_UNLOCK(ump);
 	bdwrite(bp);
 	return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno);
 }
@@ -698,21 +724,23 @@
 {
 	struct m_ext2fs *fs;
 	struct buf *bp;
+	struct ext2mount *ump;
 	int error, start, len, loc, map, i;
 	char *ibp;
 	ipref--; /* to avoid a lot of (ipref -1) */
 	if (ipref == -1)
 		ipref = 0;
 	fs = ip->i_e2fs;
+	ump = ip_i_ump;
 	if (fs->e2fs_gd[cg].ext2bgd_nifree == 0)
 		return (0);
-	lock_super(DEVVP(ip)); 
+	EXT2_UNLOCK(ump);	
 	error = bread(ip->i_devvp, fsbtodb(fs,
 		fs->e2fs_gd[cg].ext2bgd_i_bitmap),
 		(int)fs->e2fs_bsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
-		unlock_super(DEVVP(ip));  
+		EXT2_LOCK(ump);
 		return (0);
 	}
 	ibp = (char *)bp->b_data;
@@ -748,6 +776,7 @@
 	/* NOTREACHED */
 gotit:
 	setbit(ibp, ipref);
+	EXT2_LOCK(ump);
 	fs->e2fs_gd[cg].ext2bgd_nifree--;
 	fs->e2fs->e2fs_ficount--;
 	fs->e2fs_fmod = 1;
@@ -755,6 +784,7 @@
 		fs->e2fs_gd[cg].ext2bgd_ndirs++;
 		fs->e2fs_total_dir++;
 	}
+	EXT2_UNLOCK(ump);
 	bdwrite(bp);
 	unlock_super(DEVVP(ip));
 	return (cg * fs->e2fs->e2fs_ipg + ipref +1);
@@ -772,10 +802,12 @@
 {
 	struct m_ext2fs *fs;
 	struct buf *bp;
+	struct ext2mount *ump;
 	int cg, error;
 	char *bbp;
 
 	fs = ip->i_e2fs;
+	ump = ip->i_ump;
 	cg = dtog(fs, bno);
 	if ((u_int)bno >= fs->e2fs->e2fs_bcount) {
                 printf("bad block %lld, ino %llu\n", (long long)bno,
@@ -798,9 +830,11 @@
                 panic("blkfree: freeing free block");
         }
         clrbit(bbp, bno);
+	EXT2_LOCK(ump);
         fs->e2fs->e2fs_fbcount++;
         fs->e2fs_gd[cg].ext2bgd_nbfree++;
         fs->e2fs_fmod = 1;
+	EXT2_UNLOCK(ump);
         bdwrite(bp);
 }
 
@@ -817,12 +851,14 @@
 	struct m_ext2fs *fs;
 	struct inode *pip;
 	struct buf *bp;
+	struct ext2mount *ump;
 	int error, cg;
 	char * ibp;
 /*	mode_t save_i_mode; */
 
 	pip = VTOI(pvp);
 	fs = pip->i_e2fs;
+	ump = pip->i_ump;
 	if ((u_int)ino > fs->e2fs_ipg * fs->e2fs_gcount)
 		panic("ext2_vfree: range: devvp = %p, ino = %d, fs = %s",
 		    pip->i_devvp, ino, fs->e2fs_fsmnt);
@@ -844,6 +880,7 @@
 			panic("ifree: freeing free inode");
 	}
 	clrbit(ibp, ino);
+	EXT2_LOCK(ump);
 	fs->e2fs->e2fs_ficount++;
 	fs->e2fs_gd[cg].ext2bgd_nifree++;
 	if ((mode & IFMT) == IFDIR) {
@@ -851,6 +888,7 @@
 		fs->e2fs_total_dir--;
 	}
 	fs->e2fs_fmod = 1;
+	EXT2_UNLOCK(ump);
 	bdwrite(bp);
 	return (0);
 }


More information about the p4-projects mailing list