PERFORCE change 178372 for review

Zheng Liu lz at FreeBSD.org
Mon May 17 09:20:52 UTC 2010


http://p4web.freebsd.org/@@178372?ac=10

Change 178372 by lz at gnehzuil-freebsd on 2010/05/17 09:20:22

	       Fix a bug when call ext2_mapsearch() function.
	
	        * When calling ext2_mapsearch() fucntion, Cylinder group maybe does not
	          have a free block

Affected files ...

.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#11 edit

Differences ...

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

@@ -65,7 +65,7 @@
 static void	ext2_add_rsv_win(struct m_ext2fs *, struct ext2_rsv_win *);
 static u_long   ext2_alloc_blk(struct m_ext2fs *, struct inode *, int cg,
                                 struct buf *, int32_t, struct ext2_rsv_win *);
-static int      ext2_alloc_new_rsv_win(struct inode *, struct ext2_rsv_win *, int32_t,
+static u_long   ext2_alloc_new_rsv_win(struct inode *, struct ext2_rsv_win *, int32_t,
                                 struct m_ext2fs *, int, struct buf *);
 static int      ext2_find_next_rsv_win(struct ext2_rsv_win *, struct ext2_rsv_win *,
                                 struct m_ext2fs *, int32_t, int);
@@ -179,7 +179,7 @@
         if (prev->rw_start > bpref)
                 prev = RB_PREV(ext2_rsv_win_tree, root, prev);
 
-        return next;
+        return prev;
 }
 
 /*
@@ -203,6 +203,7 @@
                 if (cur <= rsv->rw_end)
                         cur = rsv->rw_end + 1;
 
+                /* TODO: need to be improved */
                 if (dtog(fs, cur) != cg)
                         return -1;
 
@@ -232,7 +233,7 @@
 /*
  * Try to allocate a new reservation window.
  */
-static int
+static u_long
 ext2_alloc_new_rsv_win(struct inode *ip, struct ext2_rsv_win *rp, int32_t bpref,
     struct m_ext2fs *fs, int cg, struct buf *bp)
 {
@@ -255,7 +256,7 @@
                  * So try to allocate it in other group.
                  */
                 if (dtog(fs, bpref) != cg)
-                        return 0;
+                        bpref = 0;
                 if (bpref != 0) {
                         bpref = dtogd(fs, bpref);
                         if (isclr(bbp, bpref))
@@ -280,7 +281,10 @@
                         }
                 }
 
-                bpref = ext2_mapsearch(fs, bbp, bpref);
+                EXT2_LOCK(ump);
+                if (fs->e2fs_gd[cg].ext2bgd_nbfree > 0)
+                        bpref = ext2_mapsearch(fs, bbp, bpref);
+                EXT2_UNLOCK(ump);
                 if (bpref < 0)
                         return 0;
                 goto allocated1;
@@ -293,7 +297,10 @@
                                 ext2_remove_rsv_win(fs, rp);
                         mtx_unlock_spin(&fs->e2fs_rsv_lock);
 
-                        bpref = ext2_mapsearch(fs, bbp, bpref);
+                        EXT2_LOCK(ump);
+                        if (fs->e2fs_gd[cg].ext2bgd_nbfree > 0)
+                                bpref = ext2_mapsearch(fs, bbp, bpref);
+                        EXT2_UNLOCK(ump);
                         if (bpref < 0)
                                 return 0;
                         goto allocated1;
@@ -321,7 +328,10 @@
                         ext2_remove_rsv_win(fs, rp);
                         mtx_unlock_spin(&fs->e2fs_rsv_lock);
 
-                        bpref = ext2_mapsearch(fs, bbp, bpref);
+                        EXT2_LOCK(ump);
+                        if (fs->e2fs_gd[cg].ext2bgd_nbfree > 0)
+                                bpref = ext2_mapsearch(fs, bbp, bpref);
+                        EXT2_UNLOCK(ump);
                         if (bpref < 0)
                                 return 0;
                         goto allocated1;
@@ -359,7 +369,7 @@
         struct ext2mount *ump;
         u_long start;
         char *bbp;
-        u_long bno;
+        daddr_t bno = -1;
 
         ump = ip->i_ump;
         bbp = (char *)bp->b_data;
@@ -377,7 +387,10 @@
         ext2_remove_rsv_win(fs, rp);
         mtx_unlock_spin(&fs->e2fs_rsv_lock);
 
-        bno = ext2_mapsearch(fs, bbp, bpref);
+        EXT2_LOCK(ump);
+        if (fs->e2fs_gd[cg].ext2bgd_nbfree > 0)
+                bno = ext2_mapsearch(fs, bbp, bpref);
+        EXT2_UNLOCK(ump);
         if (bno < 0)
                 return 0;
         goto allocated;
@@ -411,7 +424,7 @@
          */
         if (rp->rw_end == EXT2_RWI_NOT_ALLOCATED) {
                 return ext2_alloc_new_rsv_win(ip, rp, bpref, fs, cg, bp);
-        } else if (rp->rw_start + rp->rw_alloc_hit - 1 == rp->rw_end) {
+        } else if (rp->rw_start + rp->rw_alloc_hit > rp->rw_end) {
                 return ext2_alloc_new_rsv_win(ip, rp, rp->rw_end, fs, cg, bp);
         }
 
@@ -481,7 +494,7 @@
                         /* Read block bitmap from buffer */
                         EXT2_UNLOCK(ump);
                         error = bread(ip->i_devvp,
-                            fsbtodb(fs, fs->e2fs_gd[i].ext2bgd_b_bitmap),
+                            fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_b_bitmap),
                             (int)fs->e2fs_bsize, NOCRED, &bp);
                         if (error) {
                                 brelse(bp);
@@ -489,7 +502,7 @@
                         }
 
                         EXT2_IRSV_LOCK(ip);
-                        bno = ext2_rsvalloc(fs, ip, i, bp, bpref, size);
+                        bno = ext2_rsvalloc(fs, ip, cg, bp, bpref, size);
                         EXT2_IRSV_UNLOCK(ip);
                         if (bno > 0)
                                 goto allocated;
@@ -511,16 +524,16 @@
                 return (0);
         }
 
-ioerror:
-        ext2_fserr(fs, cred->cr_uid, "file system IO error");
-        uprintf("\n%s: write failed, file system IO error\n", fs->e2fs_fsmnt);
-        return EIO;
-
 nospace:
 	EXT2_UNLOCK(ump);
 	ext2_fserr(fs, cred->cr_uid, "file system full");
 	uprintf("\n%s: write failed, file system is full\n", fs->e2fs_fsmnt);
 	return (ENOSPC);
+
+ioerror:
+        ext2_fserr(fs, cred->cr_uid, "file system IO error");
+        uprintf("\n%s: write failed, file system IO error\n", fs->e2fs_fsmnt);
+        return EIO;
 }
 
 /*


More information about the p4-projects mailing list