From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu, darrick.wong@oracle.com
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 33/39] libext2fs: use fallocate for creating journals and hugefiles
Date: Sat, 25 Oct 2014 13:59:56 -0700 [thread overview]
Message-ID: <20141025205956.532.51585.stgit@birch.djwong.org> (raw)
In-Reply-To: <20141025205623.532.12119.stgit@birch.djwong.org>
Use the new fallocate API for creating the journal and the mk_hugefile
feature.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
lib/ext2fs/mkjournal.c | 134 +++++++-----------------------------------------
misc/mk_hugefiles.c | 96 ++++------------------------------
2 files changed, 30 insertions(+), 200 deletions(-)
diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c
index 2cd7ca5..9378314 100644
--- a/lib/ext2fs/mkjournal.c
+++ b/lib/ext2fs/mkjournal.c
@@ -250,89 +250,6 @@ errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
}
/*
- * Helper function for creating the journal using direct I/O routines
- */
-struct mkjournal_struct {
- int num_blocks;
- int newblocks;
- blk64_t goal;
- blk64_t blk_to_zero;
- int zero_count;
- int flags;
- char *buf;
- errcode_t err;
-};
-
-static int mkjournal_proc(ext2_filsys fs,
- blk64_t *blocknr,
- e2_blkcnt_t blockcnt,
- blk64_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
- void *priv_data)
-{
- struct mkjournal_struct *es = (struct mkjournal_struct *) priv_data;
- blk64_t new_blk;
- errcode_t retval;
-
- if (*blocknr) {
- es->goal = *blocknr;
- return 0;
- }
- if (blockcnt &&
- (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1)))
- new_blk = es->goal+1;
- else {
- es->goal &= ~EXT2FS_CLUSTER_MASK(fs);
- retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk);
- if (retval) {
- es->err = retval;
- return BLOCK_ABORT;
- }
- ext2fs_block_alloc_stats2(fs, new_blk, +1);
- es->newblocks++;
- }
- if (blockcnt >= 0)
- es->num_blocks--;
-
- retval = 0;
- if (blockcnt <= 0)
- retval = io_channel_write_blk64(fs->io, new_blk, 1, es->buf);
- else if (!(es->flags & EXT2_MKJOURNAL_LAZYINIT)) {
- if (es->zero_count) {
- if ((es->blk_to_zero + es->zero_count == new_blk) &&
- (es->zero_count < 1024))
- es->zero_count++;
- else {
- retval = ext2fs_zero_blocks2(fs,
- es->blk_to_zero,
- es->zero_count,
- 0, 0);
- es->zero_count = 0;
- }
- }
- if (es->zero_count == 0) {
- es->blk_to_zero = new_blk;
- es->zero_count = 1;
- }
- }
-
- if (blockcnt == 0)
- memset(es->buf, 0, fs->blocksize);
-
- if (retval) {
- es->err = retval;
- return BLOCK_ABORT;
- }
- *blocknr = es->goal = new_blk;
-
- if (es->num_blocks == 0)
- return (BLOCK_CHANGED | BLOCK_ABORT);
- else
- return BLOCK_CHANGED;
-
-}
-
-/*
* Calculate the initial goal block to be roughly at the middle of the
* filesystem. Pick a group that has the largest number of free
* blocks.
@@ -373,7 +290,8 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
errcode_t retval;
struct ext2_inode inode;
unsigned long long inode_size;
- struct mkjournal_struct es;
+ int falloc_flags = EXT2_FALLOCATE_FORCE_INIT;
+ blk64_t zblk;
if ((retval = ext2fs_create_journal_superblock(fs, num_blocks, flags,
&buf)))
@@ -390,40 +308,16 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
goto out2;
}
- es.num_blocks = num_blocks;
- es.newblocks = 0;
- es.buf = buf;
- es.err = 0;
- es.flags = flags;
- es.zero_count = 0;
- es.goal = (goal != ~0ULL) ? goal : get_midpoint_journal_block(fs);
+ if (goal == ~0ULL)
+ goal = get_midpoint_journal_block(fs);
- if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) {
+ if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)
inode.i_flags |= EXT4_EXTENTS_FL;
- if ((retval = ext2fs_write_inode(fs, journal_ino, &inode)))
- goto out2;
- }
- retval = ext2fs_block_iterate3(fs, journal_ino, BLOCK_FLAG_APPEND,
- 0, mkjournal_proc, &es);
- if (retval)
- goto out2;
- if (es.err) {
- retval = es.err;
- goto out2;
- }
- if (es.zero_count) {
- retval = ext2fs_zero_blocks2(fs, es.blk_to_zero,
- es.zero_count, 0, 0);
- if (retval)
- goto out2;
- }
-
- if ((retval = ext2fs_read_inode(fs, journal_ino, &inode)))
- goto out2;
+ if (!(flags & EXT2_MKJOURNAL_LAZYINIT))
+ falloc_flags |= EXT2_FALLOCATE_ZERO_BLOCKS;
inode_size = (unsigned long long)fs->blocksize * num_blocks;
- ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
inode.i_mtime = inode.i_ctime = fs->now ? fs->now : time(0);
inode.i_links_count = 1;
inode.i_mode = LINUX_S_IFREG | 0600;
@@ -431,9 +325,21 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
if (retval)
goto out2;
+ retval = ext2fs_fallocate(fs, falloc_flags, journal_ino,
+ &inode, goal, 0, num_blocks);
+ if (retval)
+ goto out2;
+
if ((retval = ext2fs_write_new_inode(fs, journal_ino, &inode)))
goto out2;
- retval = 0;
+
+ retval = ext2fs_bmap2(fs, journal_ino, &inode, NULL, 0, 0, NULL, &zblk);
+ if (retval)
+ goto out2;
+
+ retval = io_channel_write_blk64(fs->io, zblk, 1, buf);
+ if (retval)
+ goto out2;
memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4);
fs->super->s_jnl_blocks[15] = inode.i_size_high;
diff --git a/misc/mk_hugefiles.c b/misc/mk_hugefiles.c
index 3e4274c..5ac1114 100644
--- a/misc/mk_hugefiles.c
+++ b/misc/mk_hugefiles.c
@@ -258,12 +258,7 @@ static errcode_t mk_hugefile(ext2_filsys fs, blk64_t num,
{
errcode_t retval;
- blk64_t lblk, bend = 0;
- __u64 size;
- blk64_t left;
- blk64_t count = 0;
struct ext2_inode inode;
- ext2_extent_handle_t handle;
retval = ext2fs_new_inode(fs, 0, LINUX_S_IFREG, NULL, ino);
if (retval)
@@ -283,85 +278,20 @@ static errcode_t mk_hugefile(ext2_filsys fs, blk64_t num,
ext2fs_inode_alloc_stats2(fs, *ino, +1, 0);
- retval = ext2fs_extent_open2(fs, *ino, &inode, &handle);
+ if (EXT2_HAS_INCOMPAT_FEATURE(fs->super,
+ EXT3_FEATURE_INCOMPAT_EXTENTS))
+ inode.i_flags |= EXT4_EXTENTS_FL;
+ retval = ext2fs_fallocate(fs,
+ EXT2_FALLOCATE_FORCE_INIT |
+ EXT2_FALLOCATE_ZERO_BLOCKS,
+ *ino, &inode, ~0ULL, 0, num);
if (retval)
return retval;
-
- lblk = 0;
- left = num ? num : 1;
- while (left) {
- blk64_t pblk, end;
- blk64_t n = left;
-
- retval = ext2fs_find_first_zero_block_bitmap2(fs->block_map,
- goal, ext2fs_blocks_count(fs->super) - 1, &end);
- if (retval)
- goto errout;
- goal = end;
-
- retval = ext2fs_find_first_set_block_bitmap2(fs->block_map, goal,
- ext2fs_blocks_count(fs->super) - 1, &bend);
- if (retval == ENOENT) {
- bend = ext2fs_blocks_count(fs->super);
- if (num == 0)
- left = 0;
- }
- if (!num || bend - goal < left)
- n = bend - goal;
- pblk = goal;
- if (num)
- left -= n;
- goal += n;
- count += n;
- ext2fs_block_alloc_stats_range(fs, pblk, n, +1);
-
- if (zero_hugefile) {
- blk64_t ret_blk;
- retval = ext2fs_zero_blocks2(fs, pblk, n,
- &ret_blk, NULL);
-
- if (retval)
- com_err(program_name, retval,
- _("while zeroing block %llu "
- "for hugefile"), ret_blk);
- }
-
- while (n) {
- blk64_t l = n;
- struct ext2fs_extent newextent;
-
- if (l > EXT_INIT_MAX_LEN)
- l = EXT_INIT_MAX_LEN;
-
- newextent.e_len = l;
- newextent.e_pblk = pblk;
- newextent.e_lblk = lblk;
- newextent.e_flags = 0;
-
- retval = ext2fs_extent_insert(handle,
- EXT2_EXTENT_INSERT_AFTER, &newextent);
- if (retval)
- return retval;
- pblk += l;
- lblk += l;
- n -= l;
- }
- }
-
- retval = ext2fs_read_inode(fs, *ino, &inode);
- if (retval)
- goto errout;
-
- retval = ext2fs_iblk_add_blocks(fs, &inode,
- count / EXT2FS_CLUSTER_RATIO(fs));
- if (retval)
- goto errout;
- size = (__u64) count * fs->blocksize;
- retval = ext2fs_inode_size_set(fs, &inode, size);
+ retval = ext2fs_inode_size_set(fs, &inode, num * fs->blocksize);
if (retval)
- goto errout;
+ return retval;
- retval = ext2fs_write_new_inode(fs, *ino, &inode);
+ retval = ext2fs_write_inode(fs, *ino, &inode);
if (retval)
goto errout;
@@ -379,13 +309,7 @@ retry:
goto retry;
}
- if (retval)
- goto errout;
-
errout:
- if (handle)
- ext2fs_extent_free(handle);
next prev parent reply other threads:[~2014-10-25 21:00 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-25 20:56 [PATCH 00/39] e2fsprogs October 2014 patchbomb, part 6.1 Darrick J. Wong
2014-10-25 20:56 ` [PATCH 01/39] misc: fix compiler warnings Darrick J. Wong
2014-11-04 16:36 ` Theodore Ts'o
2014-10-25 20:56 ` [PATCH 02/39] e2fuzz: exercise fuzzed blocks more aggressively Darrick J. Wong
2014-11-04 16:36 ` Theodore Ts'o
2014-10-25 20:56 ` [PATCH 03/39] libext2fs: directory iteration mustn't walk off the buffer end Darrick J. Wong
2014-11-04 16:37 ` Theodore Ts'o
2014-10-25 20:56 ` [PATCH 04/39] libext2fs: zero the EA block buffer before filling it Darrick J. Wong
2014-11-04 16:47 ` Theodore Ts'o
2014-10-25 20:56 ` [PATCH 05/39] libext2fs: don't memcpy identical pointers when writing a cache block Darrick J. Wong
2014-11-04 16:48 ` Theodore Ts'o
2014-10-25 20:57 ` [PATCH 06/39] misc: fix broken libmagic interaction with plausibility check Darrick J. Wong
2014-11-04 16:50 ` Theodore Ts'o
2014-10-25 20:57 ` [PATCH 07/39] tune2fs: speed up rewriting extent tree when enabling metadata_csum Darrick J. Wong
2014-11-04 16:52 ` Theodore Ts'o
2014-10-25 20:57 ` [PATCH 08/39] tune2fs: don't change metadata_csum on a mounted fs Darrick J. Wong
2014-11-04 16:52 ` Theodore Ts'o
2014-10-25 20:57 ` [PATCH 09/39] resize2fs: don't exit if shrinking sparse_super2 fs to one bg Darrick J. Wong
2014-10-25 20:57 ` [PATCH 10/39] resize2fs: quickly rewrite extent blocks when moving an inode w/ metadata_csum Darrick J. Wong
2014-10-25 20:57 ` [PATCH 11/39] resize2fs: use old_fs to detect per-bg metadata blocks to free Darrick J. Wong
2014-10-25 20:57 ` [PATCH 12/39] resize2fs: don't interpret bitmap shift while crossing flexbg as raid stride Darrick J. Wong
2014-10-25 20:57 ` [PATCH 13/39] resize2fs: set block_uninit in former last bg when expanding fs Darrick J. Wong
2014-10-27 23:29 ` [PATCH v2 13/39] resize2fs: set bg flags and unused inode count when resizing Darrick J. Wong
2014-10-25 20:57 ` [PATCH 14/39] mke2fs: don't zero inode table blocks that are already zeroed Darrick J. Wong
2014-10-25 20:57 ` [PATCH 15/39] dumpe2fs: 80 column outputs, please Darrick J. Wong
2014-10-25 20:58 ` [PATCH 16/39] dumpe2fs: output cleanup Darrick J. Wong
2014-10-25 20:58 ` [PATCH 17/39] e2fsck: fix dangling pointer when dir_info array is resized Darrick J. Wong
2014-11-05 16:12 ` Theodore Ts'o
2014-10-25 20:58 ` [PATCH 18/39] e2fsck: opportunistically recalculate unused inode count and inode_uninit after pass 5 Darrick J. Wong
2014-10-27 20:18 ` Darrick J. Wong
2014-10-25 20:58 ` [PATCH 19/39] e2fsck: opportunistically set block_uninit " Darrick J. Wong
2014-10-27 23:27 ` [PATCH 19/39] libext2fs: set BLOCK_UNINIT for non-last blockgroups if all blocks are free Darrick J. Wong
2014-10-25 20:58 ` [PATCH 20/39] libext2fs/e2fsck: provide routines to read-ahead metadata Darrick J. Wong
2014-10-25 20:58 ` [PATCH 21/39] e2fsck: read-ahead metadata during passes 1, 2, and 4 Darrick J. Wong
2014-10-25 20:58 ` [PATCH 22/39] libext2fs: ext2fs_new_block2() should call alloc_block hook Darrick J. Wong
2014-10-25 20:58 ` [PATCH 23/39] libext2fs: support BLKZEROOUT/FALLOC_FL_ZERO_RANGE in ext2fs_zero_blocks Darrick J. Wong
2014-10-25 20:58 ` [PATCH 24/39] libext2fs/e2fsck: refactor everyone who writes zero blocks to disk Darrick J. Wong
2014-10-25 20:59 ` [PATCH 25/39] libext2fs: support allocating uninit blocks in bmap2() Darrick J. Wong
2014-10-25 20:59 ` [PATCH 26/39] libext2fs: file IO routines should handle uninit blocks Darrick J. Wong
2014-10-25 20:59 ` [PATCH 27/39] resize2fs: convert fs to and from 64bit mode Darrick J. Wong
2014-10-25 20:59 ` [PATCH 28/39] tests: test resize2fs 32->64 and 64->32bit conversion code Darrick J. Wong
2014-10-25 20:59 ` [PATCH 29/39] libext2fs: find inode goal when allocating blocks Darrick J. Wong
2014-10-25 20:59 ` [PATCH 30/39] libext2fs: find/alloc a range of empty blocks Darrick J. Wong
2014-10-25 20:59 ` [PATCH 31/39] libext2fs: add new hooks to support large allocations Darrick J. Wong
2014-10-25 20:59 ` [PATCH 32/39] libext2fs: implement fallocate Darrick J. Wong
2014-10-25 20:59 ` Darrick J. Wong [this message]
2014-10-25 21:00 ` [PATCH 34/39] debugfs: " Darrick J. Wong
2014-10-25 21:00 ` [PATCH 35/39] tests: test debugfs punch command Darrick J. Wong
2014-10-25 21:00 ` [PATCH 37/39] fuse2fs: translate ACL structures Darrick J. Wong
2014-10-25 21:00 ` [PATCH 38/39] fuse2fs: handle 64-bit dates correctly Darrick J. Wong
2014-10-25 21:00 ` [PATCH 39/39] fuse2fs: implement fallocate Darrick J. Wong
2014-10-27 23:31 ` [PATCH 40/39] e2fsck: fix reporting of unknown htree block inode number Darrick J. Wong
2014-11-05 16:11 ` Theodore Ts'o
2014-10-27 23:32 ` [PATCH 41/39] mke2fs: warn if enabling metadata_csum on a pre-3.18 kernel Darrick J. Wong
2014-11-05 16:20 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141025205956.532.51585.stgit@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).