Theodore Ts'o [Mon, 21 Jan 2013 22:15:25 +0000 (17:15 -0500)]
contrib: add thread locking and readdir64_r support to spd_readdir
This is part of a series of improvements from a 2008 version of
spd_readdir.c that somehow didn't make it into the version which we
checked into e2fsprogs git tree.
Theodore Ts'o [Mon, 21 Jan 2013 21:35:16 +0000 (16:35 -0500)]
contrib: add safe_getenv() support to spd_readdir
This is part of a series of improvements from a 2008 version of
spd_readdir.c that somehow didn't make it into the version which we
checked into e2fsprogs git tree.
Theodore Ts'o [Sun, 20 Jan 2013 04:21:11 +0000 (23:21 -0500)]
libext2fs: teach the ext2fs_*_block_bitmap_range2() about clusters
The ext2fs_{mark,unmark,test}_block_bitmap2() functions understand
about clusters, and will take block numbers and convert them to
clusters before checking the bitmap. The
ext2fs_*_block_bitmap_range2() functions did not do this, which made
them inconsistent. Fortunately, nothing has depended on this
incorrect behavior, and in fact most of the usage of these functions
have only recently been added, and only for optimizations that were
only enabled for non-bigalloc file systems.
So this is a change in previously exported functions, but (a) it
doesn't change the behavior at all for non-bigalloc file systems, and
(b) the change is more likely to fix bugs for bigalloc file systems.
For example, this change fixes a problem with resize2fs and bigalloc
file systems.
Theodore Ts'o [Wed, 16 Jan 2013 18:43:36 +0000 (13:43 -0500)]
resize2fs: check in test-resize script
This should be made into a more formal, automated test case, but for
now, save this as script since it's useful for validating resize2fs's
handling of very large file systems.
Phillip Susi [Tue, 15 Jan 2013 20:31:23 +0000 (15:31 -0500)]
e2image: add -a switch to include all data
Normally the raw and QCOW2 images only contain fs metadata.
Add a new switch ( -a ) to include all data. This makes it
possible to use e2image to clone a whole filesystem.
Darren Hart [Fri, 4 Jan 2013 20:00:59 +0000 (12:00 -0800)]
debugfs: add symlink command
Add support for symbolic links using a new symlink command. Modeled
after the do_mkdir() command.
Testing demonstrates both fastlinks and slowlinks work correctly.
Very long target paths fail as the command parsing appears to truncate
the input to somewhere around 256 bytes.
Signed-off-by: Darren Hart <dvhart@infradead.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: "Darrick J. Wong" <darrick.wong@oracle.com> Cc: Andreas Dilger <adilger@dilger.ca>
Darren Hart [Fri, 4 Jan 2013 20:00:58 +0000 (12:00 -0800)]
libext2fs: add the ext2fs_symlink() function
Creating symlinks is a complex affair when accounting for slowlinks.
Create a new function, ext2fs_symlink(), modeled after ext2fs_mkdir().
Like ext2fs_mkdir(), ext2fs_symlink() takes on the task of allocating a
new inode and block (for slowlinks), setting up sane default values in
the inode, copying the target path to either the inode (for fastlinks)
or to the first block (for slowlinks), and accounting for the inode and
block stats. Disallow link targets longer than blocksize as the Linux
kernel prevents this.
It does not attempt to expand the parent directory, instead returning
EXT2_ET_DIR_NO_SPACE and leaving it to the caller to expand just as
ext2fs_mkdir() does. Ideally, I think both of these functions should
make a single attempt to expand the directory.
[ Fixed a few bugs discovered when creating a test case for ext2fs_symlink() ]
Signed-off-by: Darren Hart <dvhart@infradead.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: "Darrick J. Wong" <darrick.wong@oracle.com> Cc: Andreas Dilger <adilger@dilger.ca>
Theodore Ts'o [Tue, 15 Jan 2013 00:29:54 +0000 (19:29 -0500)]
libext2fs: avoid 32-bit overflow in ext2fs_initialize with a 512M cluster size
If the user attemps to create a 512MB cluster, we need to adjust the
defaults to avoid a 32-bit overflow of s_blocks_per_group. Also check
to make sure that the caller of ext2fs_initialize() has not given a
value of s_clusters_per_group that would result in an overflow of
s_blocks_per_group.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Theodore Ts'o [Tue, 15 Jan 2013 00:03:11 +0000 (19:03 -0500)]
mke2fs: teach mke2fs to understand -b 4k and -C 256M
The -b and -C options now use parse_num_blocks2() instead of strtol,
so that users can specify -C 256M instead of the much less convenient
-C 268435456.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Theodore Ts'o [Mon, 14 Jan 2013 22:30:23 +0000 (17:30 -0500)]
mke2fs: the -g option will now specify the clusters per block group
If bigalloc is enabled, then -g will specify the clusters per block
group. (If bigalloc is not enabled, then a cluster == a block, so the
meaning of -g is not changed.)
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Zheng Liu [Sun, 13 Jan 2013 09:08:13 +0000 (17:08 +0800)]
mke2fs: require the bigalloc feature explicity if the cluster size is set
When cluster-size is specified without the bigalloc feature, mke2fs
will ignore this argument silently. But user might think bigalloc
feature has been enabled unless they use the dumpe2fs command. So now
we ask user to set bigalloc feature explicity when cluster-size is
enabled. This can make sure that users understand what they are doing
because bigalloc might impact the performance for some workloads.
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Theodore Ts'o [Sat, 12 Jan 2013 22:33:44 +0000 (17:33 -0500)]
resize2fs: add debugging code to test the old online resizing interfaces
The old online resize ioctl interfaces are still present in the
kernel, and we want to make it easy to test both the kernel code for
those older interfaces, and resize2fs's use of those interfaces in a
relatively easy manner.
To do this, resize2fs will now check the environment variable
RESIZE2FS_KERNEL_VERSION. If the version given is less than 3.3, then
do not try using the new resizing ioctl, but instead use the resizing
ioctls that were used before Linux version 3.3.
If the version given is less than 3.7, then emulate sanity checks
which get done to protect against the fact that the new resizing ioctl
prior to 3.7 did not handle meta_bg resizing. (This was previously
tested via the presence of the RESIZE2FS_NO_META_BG_RESIZE environment
variable. But the new environment variable, RESIZE2FS_KERNEL_VERISON,
is more general.)
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Eric Whitney [Fri, 4 Jan 2013 10:27:12 +0000 (10:27 +0000)]
config: silence printf format warnings
The printfs in the asm_types.c code contained within parse-types.sh
expect sizeof to return an int. Fix this for architectures where this
isn't true (x86_64, etc.) so we don't see warning messages while
running the configure script.
Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Theodore Ts'o [Wed, 9 Jan 2013 01:47:11 +0000 (20:47 -0500)]
libext2fs: ext2fs_open2() should not set ret_fs after a MMP failure
The addition of MMP code was added in the wrong place, so ret_fs could
get set (and EXT2_FLAG_NOFREE_ON_ERROR was cleared as well, which
could confuse e2fsck which depends on this flag being cleared if
ext2fs_open2() succeeded.)
e2fsck: avoid memory corruption on ext2fs_open2 failure
In try_open_fs(), if ext2fs_open2() returns an error, do not try to
access the struct ext2_filesys. The previous check 'if (ret_fs)' was
always true, but even 'if (*ret_fs)' might be incorrect in some cases,
so check 'retval==0' instead.
Previously e2fsck would corrupt memory if the log file name was longer
than 100 bytes (e.g., a long log_filename value in e2fsck.conf or a
pattern that expands out to more than 100 bytes). This was due to
incorrectly calling realloc() in append_string() on the struct string
instead of the malloc'ed char* buffer, among other problems. This
patch fixes the call to realloc() and also ensures that the buffer is
grown by sufficiently many bytes (not just by 2x).
Zheng Liu [Sun, 6 Jan 2013 12:25:17 +0000 (20:25 +0800)]
mke2fs: check extents feature when bigalloc feature is enabled
When bigalloc feature is enabled in mkfs, extents feature also needs
to be enabled. But now when bigalloc feature is enabled without
extents feature, users will not get any warning messages until they
try to mount this file system.
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
There are a number of places where we multiply a dgrp_t with
s_blocks_per_group expecting that we will get a blk64_t. This
requires a cast, or using the convenience function
ext2fs_group_first_block2().
This audit was suggested by Eric Sandeen.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Theodore Ts'o [Thu, 3 Jan 2013 13:35:25 +0000 (08:35 -0500)]
resize2fs: use [un]mark_block_range bitmap functions to reduce CPU usage
Use ext2fs_[un]mark_block_range2() functions to reduce the CPU
overhead of resizing large file systems by 45%, primarily by
reducing the time spent in fix_uninit_block_bitmaps().
Theodore Ts'o [Thu, 3 Jan 2013 14:01:22 +0000 (09:01 -0500)]
resize2fs: fix 32-bit overflow when calculating the number of free blocks
This caused the free blocks count in the superblock to be incorrect
after resizing a 64-bit file system if the number of free blocks
overflowed a 32-bit value.
Theodore Ts'o [Thu, 3 Jan 2013 04:31:04 +0000 (23:31 -0500)]
resize2fs: fix 32-bit overflow issue which can corrupt 64-bit file systems
Fix a 32-bit overflow bug caused by a missing blk64_t cast which can
cause the block bitmap to get corrupted when doing an off-line resize
of a 64-bit file system.
Theodore Ts'o [Wed, 2 Jan 2013 15:06:09 +0000 (10:06 -0500)]
Clean up texinfo files
Fix up the com_err.texinfo file so it will produce a valid printed
output, by cleaning up some errors in the texinfo file, and updating
texinfo.tex to be consistent with the version in the doc subdirectory.
Also add rules so we can generate pdf and ps files from
com_err.texinfo and libext2fs.texinfo.
Andreas Dilger [Thu, 22 Nov 2012 15:06:12 +0000 (15:06 +0000)]
filefrag: improvements to filefrag FIEMAP handling
Update the filefrag program to allow displaying the extents in
some different formats. Try and stay within 80 columns.
* add -k option to print extents in kB-sized units (like df -k)
* add -b {blocksize} to print extents in blocksize units
* add -e option to print extent format, even when FIBMAP is used
* add -X option to print extents in hexadecimal format
Internally, the FIBMAP handling code has been moved into its own
function like FIEMAP, so that the code is more modular. Extent
offsets are now handled in bytes instead of in blocks, to allow
printing extents with arbitrary block sizes. The extent header
printing also moved into its own function so that it can be shared
between the FIEMAP and FIBMAP handling routines, since it got more
complex with the different output options.
Only print error about FIBMAP being root-only a single time.
Print the filesystem type if it changes between specified files.
Add fsync() for FIBMAP if "-s" is given.
Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Andreas Dilger [Thu, 29 Nov 2012 12:47:54 +0000 (05:47 -0700)]
libquota: quiet log_err() bad format warnings
The macro for log_err() was written so that it needed to always
have an argument, but GCC was unhappy to have an argument when
none was specified in the format string. Use the CPP "##" to
eat the preceeding comma if no argument is specified.
Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Andreas Dilger [Thu, 29 Nov 2012 12:47:53 +0000 (05:47 -0700)]
build: quiet some "gcc -Wall" compiler warnings
Quiet a number of simple compiler warnings:
- pointers not initialized by ext2fs_get_mem()
- return without value in non-void function
- dereferencing type-punned pointers
- unused variables
Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Andreas Dilger [Thu, 29 Nov 2012 12:47:51 +0000 (05:47 -0700)]
tests: don't consider "make check" a compiler error
In a number of places, the output format from "make check" is
incorrectly interpreted as compiler warning output (triggered by
the presence of colons and parenthesis in the output). Convert
these lines to similar output that does not trigger false build
warnings.
In the case of the tst_uuid.c program, the "ctime()" output was
difficult to change, but in fact it is better to actually compare
the time-based UUID against wallclock time instead of just printing
the formatted time as a string, so this test is improved.
Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Sat, 29 Dec 2012 08:43:55 +0000 (03:43 -0500)]
resize2fs: create optimized flex_bg block groups
Now that we are reserving all of the bg-specific metadata before we
try to allocate the metadata for the new block groups, we don't have
to temporarily disable the flex_bg feature flag while we allocate the
new metadata blocks --- this allows the newly created block groups to
have a much more optimized layout, instead of fragmenting the inode
table and block/inode bitmaps in sepraate block groups.
Theodore Ts'o [Sat, 29 Dec 2012 08:38:34 +0000 (03:38 -0500)]
resize2fs: allow resizing flex_bg && !resize_inode file systems
With the bug fixes from the last two commits, resize2fs can now fully
support off-line resizing of file systems with flex_bg even if the
resize_inode feature is not present; so we no longer need to disallow
this combination.
Theodore Ts'o [Sat, 29 Dec 2012 08:25:10 +0000 (03:25 -0500)]
resize2fs: handle bg descriptors which overlap with other bg's metadata
With flex_bg file systems, bg-specific metadata (i.e., bitmaps and the
inode table blocks) can be located in another block group. Hence,
when we grow the number of block group descriptors, we need to check
if we need to relocate metadata blocks not just for the block group
where the bgd blocks are located, but in all block groups.
Theodore Ts'o [Sat, 29 Dec 2012 05:53:16 +0000 (00:53 -0500)]
resize2fs: reserve all metadata blocks for flex_bg file systems
For flex_bg file systems, if we need to relocate an allocation bitmap
or inode table, we need to make sure that all metadata blocks have
been reserved, lest we end up overwriting a metadata block belonging
to a different block group.
Theodore Ts'o [Sat, 29 Dec 2012 00:54:19 +0000 (19:54 -0500)]
resize2fs: reserve fs metadata blocks first in blocks_to_move()
This is the first commit to add support for off-line resizing using
flex_bg without the assist of using the resize_inode to reserve gdt
blocks. This functionality has been broken up into separate commits
which are hopefully obviously correct to make them easier to review
for correctness.
In this first step, we break up the for loop at the end of
blocks_to_move() so that we first mark all of the metadata blocks
which don't need to be moved in the reserve_blocks bitmap, and then
try to allocate the metadata blocks are new or which need to moved
second.
debian: use more specific library file names in *.files
This patch specifies libraries using a more specific glob that will pick
only the lib*.so.<version> file and will not match the lib*.so symlink
and the lib*.a archive/static library.
Signed-off-by: Filipe Brandenburger <filbranden@google.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian: look for quota.pc and libquota.a from root of install tree
The rules makefile was already using `find' in order to cope with
multi-arch directories under /usr/lib. This patch changes it to look for
those files from the root of the install tree. This allows for
installing to libdirs of /usr/lib64 or /lib or /lib64. There are no
other files with the same names in the package so it's not a problem to
find from the root of the tree.
Signed-off-by: Filipe Brandenburger <filbranden@google.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian: add make variable to pass extra parameters to configure
Setting EXTRA_CONF_FLAGS in rules.custom will pass the extra arguments
to calls of ./configure when building e2fsprogs. This can be used, for
instance, to pass a --libdir argument or similar to the configure
script.
Signed-off-by: Filipe Brandenburger <filbranden@google.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian: add make variable to prevent building e2fsck.static package
Setting BUILD_E2FSCK_STATIC=no in rules.custom will prevent the
debian/rules makefile from building a statically-linked e2fsck and
from creating a deb package for it.
Signed-off-by: Filipe Brandenburger <filbranden@google.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Theodore Ts'o [Sun, 23 Dec 2012 03:15:22 +0000 (22:15 -0500)]
libext2fs: link the test programs with static libraries
Force the use of the static libraries when linking the test program so
that "make check" works when the shared libraries have not been
installed, and so that we test against the version of the libraries in
the source tree.
Theodore Ts'o [Sat, 22 Dec 2012 23:50:33 +0000 (18:50 -0500)]
debugfs: add the ability to manipulate the extent tree directly
This commit adds the functionality which had previously only been in
the tst_extents command to debugfs. The debugfs command extent_open
will open extent tree of a particular inode, and enables a series of
commands which will allow the user to interact with the extent tree
directly. Once the extent tree is closed via extent_open(), these
additional commands will be disabled again.
This commit exports two new functions from lib/ext2fs/extent.c which
had previously been statically defined: ext2fs_extent_node_split() and
ext2fs_extent_goto2().
Theodore Ts'o [Thu, 20 Dec 2012 23:37:01 +0000 (18:37 -0500)]
e2fsck: make sure the extent tree is consistent after bogus node in the tree
Commit 789bd401c3 ("e2fsck: fix incorrect interior node logical start
values") surfaced a bug where if e2fsck finds and removed an invalid
node in the extent tree, i.e.:
Inode 12 has an invalid extent node (blk 22, lblk 0)
Clear? yes
It was possible for starting logical blocks found in the interior
nodes of the extent tree. Commit 789bd401c3 added the ability for
e2fsck to discover this problem, which resulted in the test
f_extent_bad_node to fail when the second pass of e2fsck reported the
following complaint:
Interior extent node level 0 of inode 12:
Logical start 0 does not match logical start 3 at next level. Fix? yes
This patch fixes this by adding a call to ext2fs_extent_fix_parents()
after deleting the bogus node in the extent tree.
Theodore Ts'o [Thu, 20 Dec 2012 23:27:33 +0000 (18:27 -0500)]
libext2fs: ext2fs_extents_fix_parents() should not modify the handle location
Previously, ext2fs_extent_fix_parents() would only avoid modifying the
cursor location associated with the extent handle the cursor was
pointed at a leaf node in the extent tree. This is because it saved
the starting logical block number of the current extent, but not the
"level" of the extent (where level 0 is the leaf node, level 1 is the
interior node which points at blocks containing leaf nodes, etc.)
Fix ext2fs_extent_fix_parents() so it is guaranteed to not change the
current extent in the handle even if the current extent is not at the
bottom of the tree.
Also add a fix_extent command to the tst_extents program to make it
easier to test this function.
An index node's logical start (ei_block) should
match the logical start of the first node (index
or leaf) below it. If we find a node whose start
does not match its parent, fix all of its parents
accordingly.
If it finds such a problem, we'll see:
Pass 1: Checking inodes, blocks, and sizes
Interior extent node level 0 of inode 274258:
Logical start 3666 does not match logical start 4093 at next level. Fix<y>?
Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
The current m68k code was buggy for multiple reasons; first the bfset,
et. al commands interpret the bit number as a signed number, not an
unsigned number. Secondly, there were missing memory clobbers. Since
there is no real benefit in using explicit asm's at this point (gcc is
smart enough to optimize the generic C code to use the set/clear/test
bit m68k instruction) fix this bug by removing the m68k specific asm
versions of these functions.
Tested on m68k-linux with e2fsprogs-1.42.6 and gcc-4.6.3 as before.
All tests pass and the debug output looks sane.
I compared the e2fsck binaries from the previous build with this
one. They had identical .text sizes, and almost the same number
of bit field instructions (obviously compiler-generated), so this
change should have no serious performance implications.
Signed-off-by: Mikael Pettersson <mikpe@it.uu.se> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: Andreas Schwab <schwab@linux-m68k.org>
Theodore Ts'o [Mon, 17 Dec 2012 01:14:20 +0000 (20:14 -0500)]
libext2fs: fix memory and fd leak in error path of unix_open()
Fix a potential memory leak reported by Li Xi. In addition, there
were possible error cases where the file descriptor would not be
properly closed, so fix those as well while we're at it.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reported-by: Li Xi <pkuelelixi@gmail.com>
Gregoire Pichon [Wed, 17 Oct 2012 14:57:32 +0000 (16:57 +0200)]
mke2fs: fix handling of mmp_update_interval option
Make sure the s_mmp_update_interval super block field is set
from the file system parameters block which is passed into the
ext2fs_initialize() function.
Theodore Ts'o [Sun, 16 Dec 2012 03:32:23 +0000 (22:32 -0500)]
e2fsck: fix pass5 optimization for bigalloc file systems
Commit 53e3120c18 introduced a regression which would case e2fsck to
overrun an array boundary for bigalloc file systems, and most likely
crash. Fix this by correctly using blocks instead of clusters when
incrementing the loop counter in the fast path optimization case.
Eric Sandeen [Tue, 27 Nov 2012 18:35:48 +0000 (12:35 -0600)]
tune2fs: respect quota config option
If we haven't turned --enable-quota on at config time,
I don't think tune2fs should know about the feature either.
Today we can actually tune2fs -O quota even if not
configured on, and then the rest of the tools will
refuse to touch it:
# tune2fs -O quota /dev/sda1
# tune2fs -O ^quota /dev/whatever complains
tune2fs 1.42.3 (14-May-2012)
tune2fs: Filesystem has unsupported read-only feature(s) while trying to open /dev/sda1
# fsck /dev/sda1
fsck from util-linux 2.21.2
e2fsck 1.42.3 (14-May-2012)
/dev/sda1 has unsupported feature(s): quota
e2fsck: Get a newer version of e2fsck!
Ok, so turn it off?
# tune2fs -O ^quota /dev/whatever complains
tune2fs 1.42.3 (14-May-2012)
tune2fs: Filesystem has unsupported read-only feature(s) while trying to open /dev/sda1
Nope. Debugfs? Nope.
# debugfs -w /dev/sda1
debugfs 1.42.3 (14-May-2012)
/dev/sda1: Filesystem has unsupported read-only feature(s) while opening filesystem
Theodore Ts'o [Sun, 25 Nov 2012 00:17:44 +0000 (19:17 -0500)]
e2fsck: optimize pass 5 for CPU utilization
Add a fast path optimization in e2fsck's pass 5 for the common case
where the block bitmap is correct. The optimization works by
extracting each block group's block allocation bitmap into a memory
buffer, and comparing it with the expected allocation bitmap using
memcmp(). If it matches, then we can just update the free block
counts and be on our way, and skip checking each bit individually.
Theodore Ts'o [Sat, 24 Nov 2012 20:40:17 +0000 (15:40 -0500)]
e2fsck: optimize pass1 for CPU time
Optimize e2fsck pass 1 by marking entire extents as being in use at a
time, instead of block by block. This optimization only works for
non-bigalloc file systems for now (it's tricky to handle bigalloc file
systems since this code is also responsible for dealing with blocks
that are not correctly aligned within a cluster). When the
optimization works, the CPU savings can be significant: ove a full CPU
minute for a mostly full 4T disk.
Restructure the ext2fs_get_device_size() and blkid_get_dev_size()
code to localize the variables used for different device probing
methods. This at least reduces the #ifdef mess to only one part
of the code for each method, and avoids "unused variable" compiler
warnings added when variables are declared without being #ifdef'd.
Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Wed, 10 Oct 2012 02:45:40 +0000 (22:45 -0400)]
e2fsck: only consult inode_dir_map if needed in pass4
In e2fsck_pass4(), we were consulting inode_dir_map using
ext2fs_test_inode_bitmap2() for every single inode in the file system.
However, there were many cases where we never needed the result of the
test --- most notably if the inode is not in use.
I was a bit surprised that GCC 4.7 with CFLAGS set to "-g -O2" wasn't
able to optimize this out for us, but here is the pass 4 timing for an
empty 3T file system before this patch:
Theodore Ts'o [Sat, 6 Oct 2012 01:59:40 +0000 (21:59 -0400)]
libext2fs: further optimize rb_test_bit
Profiling shows that rb_test_bit() is now calling ext2fs_rb_next() a
lot, and this function is now the hot spot when running e2freefrag.
If we cache the results of ext2fs_rb_next(), we can eliminate those
extra calls, which further speeds up both e2freefrag and e2fsck by
reducing the amount of CPU time spent in userspace.
Theodore Ts'o [Sat, 6 Oct 2012 00:57:49 +0000 (20:57 -0400)]
libext2fs: remove pointless indirection in rbtree bitmaps
The code was previously allocating a single 4 or 8 byte pointer for
the rcursor and wcursor fields in the ext2fs_rb_private structure;
this added two extra memory allocations (which could fail), and extra
indirections, for no good reason. Removing the extra indirection also
makes the code more readable, so it's all upside and no downside.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Theodore Ts'o [Fri, 5 Oct 2012 03:38:55 +0000 (23:38 -0400)]
libext2fs: optimize rb_test_bit
Optimize testing for a bit in an rbtree-based bitmap for the case
where the calling application is scanning through the bitmap
sequentially. Previously, we did this for a set of bits which were
inside an allocated extent, but we did not optimize the case where
there was a large number of bits after an allocated extents which were
not in use.
In my tests of a roughly half-filled file system, the run time of
e2freefrag was halved, and the cpu time spent in userspace was during
e2fsck's pass 5 was reduced by a factor of 30%.