svn commit: r255188 - stable/9/sys/fs/ext2fs

Pedro F. Giffuni pfg at FreeBSD.org
Tue Sep 3 18:46:13 UTC 2013


Author: pfg
Date: Tue Sep  3 18:46:11 2013
New Revision: 255188
URL: http://svnweb.freebsd.org/changeset/base/255188

Log:
  Add read-only support for extents in ext2fs.
  
  Basic support for extents was implemented by Zheng Liu as part
  of his Google Summer of Code in 2010. This support is read-only
  at this time.
  
  In addition to extents we also support the huge_file extension
  for read-only purposes. This works nicely with the additional
  support for birthtime/nanosec timestamps and dir_index that
  have been added lately.
  
  The implementation may not work for all ext4 filesystems as
  it doesn't support some features that are being enabled by
  default on recent linux like flex_bg. Nevertheless, the feature
  should be very useful for migration or simple access in
  filesystems that have been converted from ext2/3 or don't use
  incompatible features.
  
  Special thanks to Zheng Liu for his dedication and continued
  work to support ext2 in FreeBSD.
  
  Submitted by:	Zheng Liu (lz@)
  Reviewed by:	Mike Ma, Christoph Mallon (previous version)
  Sponsored by:	Google Inc.

Modified:
  stable/9/sys/fs/ext2fs/ext2_alloc.c
  stable/9/sys/fs/ext2fs/ext2_balloc.c
  stable/9/sys/fs/ext2fs/ext2_bmap.c
  stable/9/sys/fs/ext2fs/ext2_extern.h
  stable/9/sys/fs/ext2fs/ext2_inode.c
  stable/9/sys/fs/ext2fs/ext2_subr.c
  stable/9/sys/fs/ext2fs/ext2_vnops.c
  stable/9/sys/fs/ext2fs/inode.h
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/fs/   (props changed)

Modified: stable/9/sys/fs/ext2fs/ext2_alloc.c
==============================================================================
--- stable/9/sys/fs/ext2fs/ext2_alloc.c	Tue Sep  3 18:31:23 2013	(r255187)
+++ stable/9/sys/fs/ext2fs/ext2_alloc.c	Tue Sep  3 18:46:11 2013	(r255188)
@@ -80,8 +80,8 @@ static daddr_t  ext2_mapsearch(struct m_
  *        available block is located.
  */
 int
-ext2_alloc(struct inode *ip, int32_t lbn, int32_t bpref, int size,
-    struct ucred *cred, int32_t *bnp)
+ext2_alloc(struct inode *ip, daddr_t lbn, e4fs_daddr_t bpref, int size,
+    struct ucred *cred, e4fs_daddr_t *bnp)
 {
 	struct m_ext2fs *fs;
 	struct ext2mount *ump;
@@ -166,7 +166,8 @@ ext2_reallocblks(struct vop_reallocblks_
 	struct cluster_save *buflist;
 	struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp;
 	e2fs_lbn_t start_lbn, end_lbn;
-	int32_t soff, newblk, blkno;
+	int soff;
+	e2fs_daddr_t newblk, blkno;
 	int i, len, start_lvl, end_lvl, pref, ssize;
 
 	if (doreallocblks == 0)
@@ -250,7 +251,7 @@ ext2_reallocblks(struct vop_reallocblks_
 	/*
 	 * Search the block map looking for an allocation of the desired size.
 	 */
-	if ((newblk = (int32_t)ext2_hashalloc(ip, dtog(fs, pref), pref,
+	if ((newblk = (e2fs_daddr_t)ext2_hashalloc(ip, dtog(fs, pref), pref,
 	    len, ext2_clusteralloc)) == 0){
 		EXT2_UNLOCK(ump);
 		goto fail;
@@ -550,9 +551,9 @@ ext2_dirpref(struct inode *pip)
  * of the above. Then, blocknr tells us the number of the block
  * that will hold the pointer
  */
-int32_t
-ext2_blkpref(struct inode *ip, e2fs_lbn_t lbn, int indx, int32_t *bap,
-    int32_t blocknr)
+e4fs_daddr_t
+ext2_blkpref(struct inode *ip, e2fs_lbn_t lbn, int indx, e2fs_daddr_t *bap,
+    e2fs_daddr_t blocknr)
 {
 	int	tmp;
 	mtx_assert(EXT2_MTX(ip->i_ump), MA_OWNED);
@@ -575,7 +576,7 @@ ext2_blkpref(struct inode *ip, e2fs_lbn_
 	   follow the rule that a block should be allocated near its inode
 	*/
 	return blocknr ? blocknr :
-			(int32_t)(ip->i_block_group * 
+			(e2fs_daddr_t)(ip->i_block_group * 
 			EXT2_BLOCKS_PER_GROUP(ip->i_e2fs)) + 
 			ip->i_e2fs->e2fs->e2fs_first_dblock;
 }
@@ -963,7 +964,7 @@ gotit:
  *
  */
 void
-ext2_blkfree(struct inode *ip, int32_t bno, long size)
+ext2_blkfree(struct inode *ip, e4fs_daddr_t bno, long size)
 {
 	struct m_ext2fs *fs;
 	struct buf *bp;

Modified: stable/9/sys/fs/ext2fs/ext2_balloc.c
==============================================================================
--- stable/9/sys/fs/ext2fs/ext2_balloc.c	Tue Sep  3 18:31:23 2013	(r255187)
+++ stable/9/sys/fs/ext2fs/ext2_balloc.c	Tue Sep  3 18:46:11 2013	(r255188)
@@ -65,8 +65,8 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t
 	struct buf *bp, *nbp;
 	struct vnode *vp = ITOV(ip);
 	struct indir indirs[NIADDR + 2];
-	uint32_t nb, newb;
-	int32_t *bap, pref;
+	e4fs_daddr_t nb, newb;
+	e2fs_daddr_t *bap, pref;
 	int osize, nsize, num, i, error;
 
 	*bpp = NULL;
@@ -195,7 +195,7 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t
 			brelse(bp);
 			return (error);
 		}
-		bap = (int32_t *)bp->b_data;
+		bap = (e2fs_daddr_t *)bp->b_data;
 		nb = bap[indirs[i].in_off];
 		if (i == num)
 			break;

Modified: stable/9/sys/fs/ext2fs/ext2_bmap.c
==============================================================================
--- stable/9/sys/fs/ext2fs/ext2_bmap.c	Tue Sep  3 18:31:23 2013	(r255187)
+++ stable/9/sys/fs/ext2fs/ext2_bmap.c	Tue Sep  3 18:46:11 2013	(r255188)
@@ -62,7 +62,7 @@ static int ext4_bmapext(struct vnode *, 
 int
 ext2_bmap(struct vop_bmap_args *ap)
 {
-	int64_t blkno;
+	daddr_t blkno;
 	int error;
 
 	/*
@@ -139,7 +139,7 @@ ext4_bmapext(struct vnode *vp, int32_t b
  */
 
 int
-ext2_bmaparray(struct vnode *vp, int32_t bn, int64_t *bnp, int *runp, int *runb)
+ext2_bmaparray(struct vnode *vp, daddr_t bn, daddr_t *bnp, int *runp, int *runb)
 {
 	struct inode *ip;
 	struct buf *bp;
@@ -182,7 +182,7 @@ ext2_bmaparray(struct vnode *vp, int32_t
 		if (*bnp == 0) {
 			*bnp = -1;
 		} else if (runp) {
-			int32_t bnb = bn;
+			daddr_t bnb = bn;
 			for (++bn; bn < NDADDR && *runp < maxrun &&
 			    is_sequential(ump, ip->i_db[bn - 1], ip->i_db[bn]);
 			    ++bn, ++*runp);
@@ -190,7 +190,7 @@ ext2_bmaparray(struct vnode *vp, int32_t
 			if (runb && (bn > 0)) {
 				for (--bn; (bn >= 0) && (*runb < maxrun) &&
 					is_sequential(ump, ip->i_db[bn],
-						ip->i_db[bn+1]);
+						ip->i_db[bn + 1]);
 						--bn, ++*runb);
 			}
 		}
@@ -239,19 +239,20 @@ ext2_bmaparray(struct vnode *vp, int32_t
 			}
 		}
 
-		daddr = ((int32_t *)bp->b_data)[ap->in_off];
+		daddr = ((e2fs_daddr_t *)bp->b_data)[ap->in_off];
 		if (num == 1 && daddr && runp) {
 			for (bn = ap->in_off + 1;
 			    bn < MNINDIR(ump) && *runp < maxrun &&
 			    is_sequential(ump,
-			    ((int32_t *)bp->b_data)[bn - 1],
-			    ((int32_t *)bp->b_data)[bn]);
+			    ((e2fs_daddr_t *)bp->b_data)[bn - 1],
+			    ((e2fs_daddr_t *)bp->b_data)[bn]);
 			    ++bn, ++*runp);
 			bn = ap->in_off;
 			if (runb && bn) {
 				for (--bn; bn >= 0 && *runb < maxrun &&
-			    		is_sequential(ump, ((int32_t *)bp->b_data)[bn],
-					    ((int32_t *)bp->b_data)[bn+1]);
+			    		is_sequential(ump,
+					((e2fs_daddr_t *)bp->b_data)[bn],
+					((e2fs_daddr_t *)bp->b_data)[bn + 1]);
 			    		--bn, ++*runb);
 			}
 		}
@@ -287,7 +288,7 @@ ext2_bmaparray(struct vnode *vp, int32_t
  * once with the offset into the page itself.
  */
 int
-ext2_getlbns(struct vnode *vp, int32_t bn, struct indir *ap, int *nump)
+ext2_getlbns(struct vnode *vp, daddr_t bn, struct indir *ap, int *nump)
 {
 	long blockcnt;
 	e2fs_lbn_t metalbn, realbn;

Modified: stable/9/sys/fs/ext2fs/ext2_extern.h
==============================================================================
--- stable/9/sys/fs/ext2fs/ext2_extern.h	Tue Sep  3 18:31:23 2013	(r255187)
+++ stable/9/sys/fs/ext2fs/ext2_extern.h	Tue Sep  3 18:46:11 2013	(r255188)
@@ -49,24 +49,24 @@ struct vfsconf;
 struct vnode;
 
 int	ext2_add_entry(struct vnode *, struct ext2fs_direct_2 *);
-int	ext2_alloc(struct inode *,
-	    int32_t, int32_t, int, struct ucred *, int32_t *);
+int	ext2_alloc(struct inode *, daddr_t, e4fs_daddr_t, int,
+	    struct ucred *, e4fs_daddr_t *);
 int	ext2_balloc(struct inode *,
 	    e2fs_lbn_t, int, struct ucred *, struct buf **, int);
 int	ext2_blkatoff(struct vnode *, off_t, char **, struct buf **);
-void	ext2_blkfree(struct inode *, int32_t, long);
-int32_t	ext2_blkpref(struct inode *, e2fs_lbn_t, int, int32_t *, int32_t);
+void	ext2_blkfree(struct inode *,  e4fs_daddr_t, long);
+e4fs_daddr_t	ext2_blkpref(struct inode *, e2fs_lbn_t, int, e2fs_daddr_t *,
+	    e2fs_daddr_t);
 int	ext2_bmap(struct vop_bmap_args *);
-int	ext2_bmaparray(struct vnode *, int32_t, int64_t *, int *, int *);
+int	ext2_bmaparray(struct vnode *, daddr_t, daddr_t *, int *, int *);
 void	ext2_clusteracct(struct m_ext2fs *, char *, int, daddr_t, int);
 void	ext2_dirbad(struct inode *ip, doff_t offset, char *how);
 void	ext2_ei2i(struct ext2fs_dinode *, struct inode *);
-int	ext2_getlbns(struct vnode *, int32_t, struct indir *, int *);
+int	ext2_getlbns(struct vnode *, daddr_t, struct indir *, int *);
 void	ext2_i2ei(struct inode *, struct ext2fs_dinode *);
 void	ext2_itimes(struct vnode *vp);
 int	ext2_reallocblks(struct vop_reallocblks_args *);
 int	ext2_reclaim(struct vop_reclaim_args *);
-void	ext2_setblock(struct m_ext2fs *, u_char *, int32_t);
 int	ext2_truncate(struct vnode *, off_t, int, struct ucred *, struct thread *);
 int	ext2_update(struct vnode *, int);
 int	ext2_valloc(struct vnode *, int, struct ucred *, struct vnode **);

Modified: stable/9/sys/fs/ext2fs/ext2_inode.c
==============================================================================
--- stable/9/sys/fs/ext2fs/ext2_inode.c	Tue Sep  3 18:31:23 2013	(r255187)
+++ stable/9/sys/fs/ext2fs/ext2_inode.c	Tue Sep  3 18:46:11 2013	(r255188)
@@ -53,8 +53,8 @@
 #include <fs/ext2fs/fs.h>
 #include <fs/ext2fs/ext2_extern.h>
 
-static int ext2_indirtrunc(struct inode *, int32_t, int32_t, int32_t, int,
-	    long *);
+static int ext2_indirtrunc(struct inode *, daddr_t, daddr_t,
+	    daddr_t, int, e4fs_daddr_t *);
 
 /*
  * Update the access, modified, and inode change times as specified by the
@@ -118,7 +118,7 @@ ext2_truncate(struct vnode *vp, off_t le
 	struct m_ext2fs *fs;
 	struct buf *bp;
 	int offset, size, level;
-	long count, nblocks, blocksreleased = 0;
+	e4fs_daddr_t count, nblocks, blocksreleased = 0;
 	int error, i, allerror;
 	off_t osize;
 
@@ -355,16 +355,16 @@ done:
  */
 
 static int
-ext2_indirtrunc(struct inode *ip, int32_t lbn, int32_t dbn, int32_t lastbn,
-    int level, long *countp)
+ext2_indirtrunc(struct inode *ip, daddr_t lbn, daddr_t dbn,
+    daddr_t lastbn, int level, e4fs_daddr_t *countp)
 {
 	struct buf *bp;
 	struct m_ext2fs *fs = ip->i_e2fs;
 	struct vnode *vp;
-	int32_t *bap, *copy, nb, nlbn, last;
-	long blkcount, factor;
-	int i, nblocks, blocksreleased = 0;
-	int error = 0, allerror = 0;
+	e2fs_daddr_t *bap, *copy;
+	int i, nblocks, error = 0, allerror = 0;
+	e2fs_lbn_t nb, nlbn, last;
+	e4fs_daddr_t blkcount, factor, blocksreleased = 0;
 
 	/*
 	 * Calculate index in current block of last
@@ -404,11 +404,11 @@ ext2_indirtrunc(struct inode *ip, int32_
 		return (error);
 	}
 
-	bap = (int32_t *)bp->b_data;
+	bap = (e2fs_daddr_t *)bp->b_data;
 	copy = malloc(fs->e2fs_bsize, M_TEMP, M_WAITOK);
 	bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->e2fs_bsize);
 	bzero((caddr_t)&bap[last + 1],
-	  (u_int)(NINDIR(fs) - (last + 1)) * sizeof(int32_t));
+	  (NINDIR(fs) - (last + 1)) * sizeof(e2fs_daddr_t));
 	if (last == -1)
 		bp->b_flags |= B_INVAL;
 	if (DOINGASYNC(vp)) {

Modified: stable/9/sys/fs/ext2fs/ext2_subr.c
==============================================================================
--- stable/9/sys/fs/ext2fs/ext2_subr.c	Tue Sep  3 18:31:23 2013	(r255187)
+++ stable/9/sys/fs/ext2fs/ext2_subr.c	Tue Sep  3 18:46:11 2013	(r255188)
@@ -135,7 +135,7 @@ void
 ext2_checkoverlap(struct buf *bp, struct inode *ip)
 {
 	struct buf *ebp, *ep;
-	int32_t start, last;
+	e4fs_daddr_t start, last;
 	struct vnode *vp;
 
 	ebp = &buf[nbuf];
@@ -150,10 +150,10 @@ ext2_checkoverlap(struct buf *bp, struct
 		    ep->b_blkno + btodb(ep->b_bcount) <= start)
 			continue;
 		vprint("Disk overlap", vp);
-		(void)printf("\tstart %d, end %d overlap start %lld, end %ld\n",
-			start, last, (long long)ep->b_blkno,
-			(long)(ep->b_blkno + btodb(ep->b_bcount) - 1));
-		panic("Disk buffer overlap");
+		printf("\tstart %jd, end %jd overlap start %jd, end %jd\n",
+		    (intmax_t)start, (intmax_t)last, (intmax_t)ep->b_blkno,
+		    (intmax_t)(ep->b_blkno + btodb(ep->b_bcount) - 1));
+		panic("ext2_checkoverlap: Disk buffer overlap");
 	}
 }
 #endif /* KDB */

Modified: stable/9/sys/fs/ext2fs/ext2_vnops.c
==============================================================================
--- stable/9/sys/fs/ext2fs/ext2_vnops.c	Tue Sep  3 18:31:23 2013	(r255187)
+++ stable/9/sys/fs/ext2fs/ext2_vnops.c	Tue Sep  3 18:46:11 2013	(r255188)
@@ -1335,7 +1335,7 @@ ext2_strategy(struct vop_strategy_args *
 	struct vnode *vp = ap->a_vp;
 	struct inode *ip;
 	struct bufobj *bo;
-	int64_t blkno;
+	daddr_t blkno;
 	int error;
 
 	ip = VTOI(vp);

Modified: stable/9/sys/fs/ext2fs/inode.h
==============================================================================
--- stable/9/sys/fs/ext2fs/inode.h	Tue Sep  3 18:31:23 2013	(r255187)
+++ stable/9/sys/fs/ext2fs/inode.h	Tue Sep  3 18:46:11 2013	(r255188)
@@ -54,9 +54,11 @@
 #define	NIADDR	3			/* Indirect addresses in inode. */
 
 /*
- * The size of physical and logical block numbers and time fields in UFS.
+ * The size of physical and logical block numbers in EXT2FS.
  */
-typedef int32_t	e2fs_lbn_t;
+typedef	uint32_t e2fs_daddr_t;
+typedef	int64_t	e2fs_lbn_t;
+typedef	int64_t e4fs_daddr_t;
  
 /*
  * The inode is used to describe each active (or recently active) file in the


More information about the svn-src-stable mailing list