PERFORCE change 182719 for review
Zheng Liu
lz at FreeBSD.org
Sun Aug 22 06:06:25 UTC 2010
http://p4web.freebsd.org/@@182719?ac=10
Change 182719 by lz at gnehzuil-freebsd on 2010/08/22 06:06:22
Make ext4fs can work.
Affected files ...
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_alloc.c#5 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_balloc.c#5 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_bmap.c#5 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_dinode.h#4 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_dir.h#3 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extents.c#9 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extents.h#7 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extern.h#4 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_htree.c#2 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_htree.h#3 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_inode.c#6 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_inode_cnv.c#7 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_lookup.c#6 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_mount.h#3 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_readwrite.c#10 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_rsv_win.h#7 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_subr.c#6 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_vfsops.c#13 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_vnops.c#4 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2fs.h#11 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/fs.h#3 edit
.. //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/inode.h#8 edit
Differences ...
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_alloc.c#5 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_balloc.c#5 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_bmap.c#5 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_dinode.h#4 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_dir.h#3 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extents.c#9 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extents.h#7 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_extern.h#4 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_htree.c#2 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_htree.h#3 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_inode.c#6 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_inode_cnv.c#7 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_lookup.c#6 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_mount.h#3 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_readwrite.c#10 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_rsv_win.h#7 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_subr.c#6 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_vfsops.c#13 (text+ko) ====
@@ -98,6 +98,8 @@
int ronly);
static int compute_sb_data(struct vnode * devvp,
struct ext2fs * es, struct m_ext2fs * fs);
+static int ext4_init_fg(struct m_ext2fs *);
+static int find_most_set_bit(int64_t n);
static const char *ext2_opts[] = { "from", "export", "acls", "noexec",
"noatime", "union", "suiddir", "multilabel", "nosymfollow",
@@ -353,6 +355,7 @@
fs->e2fs_ipb = fs->e2fs_bsize / EXT2_INODE_SIZE(fs);
fs->e2fs_itpg = fs->e2fs_ipg /fs->e2fs_ipb;
fs->e2fs_descpb = fs->e2fs_bsize / sizeof (struct ext2_gd);
+ fs->e2fs_descpbbits = find_most_set_bit(fs->e2fs_descpb);
/* s_resuid / s_resgid ? */
fs->e2fs_gcount = (((int64_t)(es->e2fs_bcount_hi) << 32 | es->e2fs_bcount_lo)
- es->e2fs_first_dblock + EXT2_BLOCKS_PER_GROUP(fs) - 1) /
@@ -389,6 +392,9 @@
bp = NULL;
}
+ /* initialize flex groups */
+ ext4_init_fg(fs);
+
fs->e2fs_total_dir = 0;
for (i=0; i < fs->e2fs_gcount; i++){
fs->e2fs_total_dir += (fs->e2fs_gd[i].ext2bgd_ndirs_lo);
@@ -414,13 +420,81 @@
}
if (E2FS_REV0_INODE_SIZE + fs->e2fs_want_extra_isize >
- fs->e2fs_isize)
+ fs->e2fs_isize) {
printf("EXT2-fs: no space for extra inode.\n");
+ return (EIO);
+ }
+
return (0);
}
/*
+ * Initialize flex groups data structure.
+ */
+static int
+ext4_init_fg(struct m_ext2fs *fs)
+{
+ struct ext2fs *es = fs->e2fs;
+ int i, gpf = 0;
+ unsigned int fgcount, fg;
+ long nifree, nbfree, ndirs;
+
+ fs->e2fs_log_gpf = es->e2fs_log_gpf;
+ gpf = 1 << fs->e2fs_log_gpf;
+
+ if (gpf < 2) {
+ fs->e2fs_log_gpf = 0;
+ return (0);
+ }
+
+ fgcount = ((fs->e2fs_gcount + gpf - 1) +
+ ((es->e2fs_reserved_ngdb + 1) << fs->e2fs_descpbbits)) / gpf;
+
+ fs->e2fs_fg = malloc(fgcount * sizeof(struct ext4_flex_groups),
+ M_EXT2MNT, M_WAITOK | M_ZERO);
+
+ for (i = 0; i < fs->e2fs_gcount; i++) {
+ nifree = 0;
+ nbfree = 0;
+ ndirs = 0;
+ fg = i >> fs->e2fs_log_gpf;
+
+ /* XXX: need to support 64 bits. */
+ nifree = fs->e2fs_gd[i].ext2bgd_nifree_lo;
+ nbfree = fs->e2fs_gd[i].ext2bgd_nbfree_lo;
+ ndirs = fs->e2fs_gd[i].ext2bgd_ndirs_lo;
+
+ atomic_add_long(&fs->e2fs_fg[fg].e2fg_nifree, nifree);
+ atomic_add_long(&fs->e2fs_fg[fg].e2fg_nbfree, nbfree);
+ atomic_add_long(&fs->e2fs_fg[fg].e2fg_ndirs, ndirs);
+ }
+
+ return (0);
+}
+
+/*
+ * Find most significant set bit.
+ *
+ * TODO: Maybe it need to rewrite by assembly language for
+ * improving the performance.
+ */
+static int
+find_most_set_bit(int64_t n)
+{
+ int64_t num, i;
+ unsigned int pos, res = 0;
+
+ for (num = 1; num <= n; num++) {
+ for (i = (num >> 1), pos = 0; i != 0; pos++)
+ i >>= 1;
+ res = pos;
+ }
+
+ return res;
+}
+
+/*
* Reload all incore data for a filesystem (used after running fsck on
* the root filesystem and finding things to fix). The filesystem must
* be mounted read-only.
@@ -605,6 +679,12 @@
if ((error = compute_sb_data(devvp, ump->um_e2fs->e2fs, ump->um_e2fs)))
goto out;
+ /* Initial reservation window index and lock */
+ bzero(&ump->um_e2fs->e2fs_rsv_lock, sizeof(struct mtx));
+ mtx_init(&ump->um_e2fs->e2fs_rsv_lock,
+ "rsv tree lock", NULL, MTX_DEF);
+ RB_INIT(&ump->um_e2fs->e2fs_rsv_tree);
+
brelse(bp);
bp = NULL;
fs = ump->um_e2fs;
@@ -704,6 +784,8 @@
g_topology_unlock();
PICKUP_GIANT();
vrele(ump->um_devvp);
+ mtx_destroy(&fs->e2fs_rsv_lock);
+ free(fs->e2fs_fg, M_EXT2MNT);
free(fs->e2fs_gd, M_EXT2MNT);
free(fs->e2fs_contigdirs, M_EXT2MNT);
free(fs->e2fs, M_EXT2MNT);
@@ -881,7 +963,7 @@
struct cdev *dev;
struct thread *td;
int error;
- int i, used_blocks;
+ /*int i, used_blocks;*/
td = curthread;
error = vfs_hash_get(mp, ino, flags, td, vpp, NULL, NULL);
@@ -947,6 +1029,15 @@
ip->i_prealloc_count = 0;
ip->i_prealloc_block = 0;
+ /* initialize rsv lock and rsv data structure */
+ bzero(&ip->i_rsv_lock, sizeof(struct mtx));
+ mtx_init(&ip->i_rsv_lock, "inode rsv lock", NULL, MTX_DEF);
+ EXT2_RSV_LOCK(ip);
+ ip->i_rsv = NULL;
+ if (ip->i_rsv == NULL)
+ ext2_init_rsv(ip);
+ EXT2_RSV_UNLOCK(ip);
+
/* initialize ext lock */
bzero(&ip->i_ext_lock, sizeof(struct mtx));
mtx_init(&ip->i_ext_lock, "inode ext lock", NULL, MTX_DEF);
@@ -961,15 +1052,16 @@
* NOTE: When ext4 file system use extents, we don't zero
* block pointers.
*/
- if (!(fs->e2fs->e2fs_features_incompat & EXT4F_INCOMPAT_EXTENTS)) {
- if (S_ISDIR(ip->i_mode) || S_ISREG(ip->i_mode)) {
- used_blocks = (ip->i_size+fs->e2fs_bsize-1) / fs->e2fs_bsize;
- for(i = used_blocks; i < EXT2_NDIR_BLOCKS; i++)
- ip->i_db[i] = 0;
- }
- }
+#if 0
+ if(S_ISDIR(ip->i_mode) || S_ISREG(ip->i_mode)) {
+ used_blocks = (ip->i_size+fs->e2fs_bsize-1) / fs->e2fs_bsize;
+ for(i = used_blocks; i < EXT2_NDIR_BLOCKS; i++)
+ ip->i_db[i] = 0;
+ }
+#endif
+
- /*ext2_print_inode(ip);*/
+ ext2_print_inode(ip);
bqrelse(bp);
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2_vnops.c#4 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/ext2fs.h#11 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/fs.h#3 (text+ko) ====
==== //depot/projects/soc2010/ext4fs/src/sys/fs/ext2fs/inode.h#8 (text+ko) ====
More information about the p4-projects
mailing list