Darrick J. Wong [Thu, 25 May 2017 01:56:36 +0000 (21:56 -0400)]
e2fsck: fix sparse bmap to extent conversion
When e2fsck is trying to convert a sparse block-mapped file to an extent
file, we incorrectly merge block mappings that are physically contiguous
but not logically contiguous because of insufficient checking with the
extent we're constructing. Therefore, compare the logical offsets for
contiguity as well.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Biggers [Thu, 25 May 2017 01:48:41 +0000 (21:48 -0400)]
libext2fs: correctly subtract xattr blocks on bigalloc filesystems
ext2fs_inode_data_blocks2() calculates an inode's data block count by
subtracting the external xattr block, if any, from the total blocks.
But on bigalloc filesystems, the xattr "block" is actually a whole
cluster, so ext2fs_inode_data_blocks2() would return a too-large value.
It seems this could have caused several different problems, but the one
I encountered was that xfstest generic/399 failed in the "bigalloc"
config because e2fsck incorrectly considered a symlink on the filesystem
to be corrupted at the end of the test. This happened because e2fsck
incorrectly calculated a nonzero data block count for a "fast" symlink
with an external xattr block and therefore treated it as a "slow"
symlink, which failed validation.
Fix this by updating ext2fs_inode_data_blocks2() to subtract the cluster
size rather than the block size.
Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Whitney [Thu, 25 May 2017 01:34:20 +0000 (21:34 -0400)]
e2fsck: fix multiply-claimed block quota accounting when deleting files
As e2fsck processes each file in pass1, the actual file system quota is
increased by the number of blocks discovered in the file. This can
include both non-multiply-claimed and multiply-claimed blocks, if the
latter exist. However, if a file containing multiply-claimed blocks
is then deleted in pass1b, those blocks are not taken into account when
decreasing the actual quota. In this case, the new quota values written
to the file system by e2fsck overstate the space actually consumed.
And, e2fsck must be run twice on the file system to fully correct
quota.
Fix this by counting multiply-claimed blocks as a debit to quota when
deleting files in pass1b.
Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Mike Frysinger [Fri, 19 May 2017 17:25:59 +0000 (13:25 -0400)]
include sys/sysmacros.h as needed
The minor/major/makedev macros are not entirely standard. glibc has had
the definitions in sys/sysmacros.h since the start, and wants to move away
from always defining them implicitly via sys/types.h (as this pollutes the
namespace in violation of POSIX). Other C libraries have already dropped
them. Since the configure script already checks for this header, use that
to pull in the header in files that use these macros.
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Biggers [Mon, 8 May 2017 22:47:57 +0000 (15:47 -0700)]
misc: fix 'zero_hugefiles = false' regression
When mk_hugefiles() was switched to use ext2fs_fallocate(), it was
accidentally changed to ignore the 'zero_hugefiles = false' setting,
which should cause hugefiles to be allocated without initializing their
contents. Fix this by only passing EXT2_FALLOCATE_ZERO_BLOCKS to
ext2fs_fallocate() when zero_hugefiles is true.
Google-Bug-Id: 38037607 Fixes: 4f868703f6f2 ("libext2fs: use fallocate for creating journals and hugefiles") Cc: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck: update quota when optimizing the extent tree
If quota is enabled, optimizing the extent tree wouldn't update the
in-memory quota statistics, so that a subsequent e2fsck run would show
that the quota usage statistics on disk were incorrect.
Joe Richey [Mon, 3 Apr 2017 16:52:50 +0000 (16:52 +0000)]
e4crypt: fix error handling for KEYCTL_GET_KEYRING_ID
Due to some interesting behaviour in keyctl (as described in the
comments), we use KEYCTL_GET_KEYRING_ID to translate the special value
of KEY_SPEC_SESSION_KEYRING to a real keyring id. However, how we
currently do this is flawed in two ways.
First, if KEYCTL_GET_KEYRING_ID fails, we don't detect it as it returns
-1 and zero is used for an error value in get_keyring_id. Second, if the
user specifies "-k @s" the translation never runs and the undesireable
behavior occurs.
These are both fixed by doing the translation outside of get_keyring_id.
Signed-off-by: Joe Richey <joerichey@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Whitney [Sun, 2 Apr 2017 16:57:05 +0000 (12:57 -0400)]
e2fsck: fix quota accounting to use cluster units
The quota accounting code in e2fsck's pass 1 and pass 3 uses block units
rather than cluster units when recording the allocated space consumed by
files and directories. In pass 1, this causes a large undercount of
actual quota results and test failures for xfstests generic/383, /384,
/385, and /386 on bigalloc file systems. In pass 3, this results in
quota accounting errors when the lost+found directory is either extended
or recreated on a bigalloc file system.
Use clusters rather than blocks when accounting for allocated space,
and correct a related header comment in the quota code.
Note that pass 1b also contains call sites for quota_data_sub() that
also need to be addressed. However, it appears that more than just
unit conversion may be needed, so that will be left to a future patch.
Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Biggers [Fri, 17 Mar 2017 22:38:36 +0000 (15:38 -0700)]
libext2fs: apply LDFLAGS when building tst_inline_data
If libext2fs was compiled with an external libblkid pointed to by
LDFLAGS, then linking the tst_inline_data program failed because the
requested linker flags were not used. Fix this by adding $(ALL_LDFLAGS)
to the build rule, as is done for the other test programs.
Fixes: 31253488385a ("libext2fs: add a unit test for inline data") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Whitney [Fri, 31 Mar 2017 23:21:59 +0000 (19:21 -0400)]
e2fsck: fix type mismatches in quota warning message
The conversion operations in the format control strings found in the
fprintf call used to print the quota warning message do not match the
types of their corresponding arguments. Although this probably hasn't
generally been a problem, it obfuscates a bigalloc quota accounting bug
where the reported actual quota goes negative.
Clean up the mismatches and some unnecessary casts. While we're at it,
fix a spelling nit in a related comment.
Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Darrick J. Wong [Thu, 2 Mar 2017 04:52:12 +0000 (20:52 -0800)]
misc: fix all the compiler warnings
Fix the various compiler warnings that have crept in, and only define
__bitwise if the system headers haven't already done so. Linux 4.10
changes the __bitwise definition so that our redefinition here is
just different enough that gcc complains.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Alexey Lyashkov [Wed, 1 Mar 2017 20:03:54 +0000 (15:03 -0500)]
libext2fs: readahead for meta_bg
There are ~37k of random IOs with meta_bg option on 300T target.
Debugfs requires 20 minutes to be started. Enabling readahead for
group blocks metadata save time dramatically. Only 12s to start.
Signed-off-by: Alexey Lyashkov <alexey.lyashkov@seagate.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Andreas Dilger [Fri, 17 Feb 2017 17:57:29 +0000 (12:57 -0500)]
e2fsck: make problem comments match error messages
Since the @x compression obscures e2fsck problem error messages
from being found by normal searching, make the comment for each
error match the actual error message so that they can be found
more easily.
Signed-off-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Fri, 17 Feb 2017 15:42:17 +0000 (10:42 -0500)]
e2fsck: don't check inode flag values for deleted inodes
Commit 47b8941774df "e2fsck: make sure system.data xattr is present"
exposed a bug in e2fsck's pass 1 handling which caused the xfstests's
generic/079 to fail if the inline_data feature was enabled. The
problem was that e2fsck was checking if an inode with inline data had
the system.xattr EA before checking to see if that inode was still in
use --- and this invariant isn't necessarily true for deleted inodes.
There were a number of other checks that were done too early that
could also potentially cause false positive complaints, although those
would normally only happen if a now-unused portion of the inode table
had gotten corrupted, or if tune2fs had disabled a particular file
system feature and there old, deleted inodes that had values
inconsistent with the new file system configuration.
Reported-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Fri, 17 Feb 2017 03:02:35 +0000 (22:02 -0500)]
e2fsck: exit with exit status 0 if no errors were fixed
Previously, e2fsck would exit with a status code of 1 even though the
only changes that it made to the file system were various
optimziations and not fixing file system corruption. Since the man
page states that an exit status of 1 means "file system errors
corrupted", fix e2fsck to return an exit status of 0.
Theodore Ts'o [Thu, 16 Feb 2017 23:54:41 +0000 (18:54 -0500)]
Refactor code to print journal superblock information
Move the code to list the journal superblock information to libe2p, so
it can be used by debugfs, and so we don't have two copies of
substantially the same code in dumpe2fs.
Fixes: 68a1de3df340 ("debugfs: pretty print encrypted filenames in the ls command") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
John Haxby [Wed, 8 Feb 2017 15:26:38 +0000 (15:26 +0000)]
mke2fs: remove the -f option from the man page
The -f option was removed in c6ed60cdeb13 (mke2fs: support creating
bigalloc file systems), let's remove it from the man page as well.
And as it was the only noted bug, take the BUGS section with it.
Signed-off-by: John Haxby <john.haxby@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Whitney [Sat, 4 Feb 2017 03:23:34 +0000 (22:23 -0500)]
tune2fs: fix quota enablement regression
Commit 5c2a665afa (Avoid dereferencing beyond allocated memory in quota
handling) induced a quota enablement regression in tune2fs. Attempts
to enable a particular quota type (tune2fs -O project <dev>, for
example) set the appropriate feature flag in the superblock but the
quota file for the type is not initialized.
The regression prevents the current version of xfstests from running
generic/383, 384, 385, and 386 (all project quota tests) with e2fsprogs
1.43.4. These tests exit with the message "Installed kernel does not
support project quotas", but the actual problem is that the project
quota file is not present.
Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Tue, 31 Jan 2017 19:05:45 +0000 (14:05 -0500)]
e2fsck: make sure system.data xattr is present
E2fsprogs used to assume that if i_size is less than 60 bytes, the
system.data xattr isn't needed (and should be removed). The kernel
disagree, and will declare the file system to be corrupted. Enforce
the tighter constraints assumed by the kernel.
During filesystem creation with -d option files copied from given
directory. If supported, FS_IOC_FIEMAP ioctl is used to get file
extents. For empty file fm_mapped_extents is 0 and no error code
is returned, because this is not fail situation.
Without this patch errno from previous operation is returned and
successful FS_IOC_FIEMAP ioctl call for empty file is interpreted
as error.
Signed-off-by: Artem Blagodarenko <artem.blagodarenko@seagate.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Eric Whitney [Mon, 30 Jan 2017 17:34:16 +0000 (12:34 -0500)]
e2fsprogs: enable project quota reporting in debugfs
Make the minor changes required so the list_quota and get_quota commands
can report project quota information. This also fixes a debugfs
segfault that currently occurs when either list_quota or get_quota is
invoked with an unknown quota_type argument.
Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Sun, 29 Jan 2017 03:34:16 +0000 (22:34 -0500)]
libext2fs: translate internal ext4 acl to Posix ACL in ext2fs_xattr_[sg]et()
ext2fs_xattr_[sg]et() will now translate the Posix ACL xattrs to and
from the internal ext4 attr format, since the callers of the libext2fs
are much more likely to want to use the public Posix ACL format.
For debugfs and those applications that want to see the on-disk
format, the new ext4fs_xattr_flags() function will allow those callers
to request the raw format.
Theodore Ts'o [Sat, 28 Jan 2017 18:09:53 +0000 (13:09 -0500)]
debugfs: improve how we display and parse extended attribute values
Use the new C string printing routine, and allow ea_get command to
display the system.data extended attribute. Also allow the user to
explicitly request that the string be printed using hex values.
Eric Sandeen [Tue, 20 Dec 2016 15:23:29 +0000 (09:23 -0600)]
libext2fs: don't ignore fsync errors
Today, if mke2fs experiences IO errors (say, on a thin device
which filled up during mkfs), mke2fs is silent and returns
success even though the filesystem was not properly created.
Catch errors from the io_channel_flush() callchain to
fix this up. Fix formatting of the printed error as
well:
...
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information:
Warning, had trouble writing out superblocks.
# echo $?
5
Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Fri, 23 Dec 2016 03:23:58 +0000 (22:23 -0500)]
lib/et/testcases: checked in imap_err.et from cyrus-imapd version 2.5.10
This version of imap_err.et has a 4-clause BSD license, which should
hopefully be more comforting to lawyers than the license with
prohibits non-commercial use --- which shouldn't be a problem since
it's in a test case that would never show up in any binary, and so
license compatibility wouldn't be an issue.
Jan Kara [Tue, 25 Oct 2016 18:08:59 +0000 (14:08 -0400)]
mke2fs: Avoid crashes / infinite loops for absurdly large devices
When a device reports absurdly high size, some arithmetics in mke2fs can
overflow (e.g. number of block descriptors) and we end in an infinite
loop. Fix that by checking and refusing insanely large devices.
Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
libsupport: fix compilation on RHEL 5.x due to missing magic define
RHEL 5.x does have magic.h, but it does not define all expected symbols. In
particular, the NO_CHECK symbols were only added in file 4.20 and RHEL 5.x
is using 4.17.
Add substitute defines to allow continued usage of magic but without the
requested exclude checks.
Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Mon, 24 Oct 2016 18:15:43 +0000 (14:15 -0400)]
mke2fs.conf: add back missing uninit_bg feature flag
Commit 0da058af9f88: "mke2fs.conf: don't enable metadata_csum by
default" removed metadata_csum without adding back the uninit_bg flag
--- which had the net result of causing file systems to take a long
time to mke2fs, since this caused all of the block group metadata to
be initialized.
Theodore Ts'o [Fri, 21 Oct 2016 14:21:54 +0000 (10:21 -0400)]
libext2fs: unix_io: reflect error from read/write calls to caller
If the read(2) or write(2) system calls fail, return the error to the
caller instead of returning "short read" or "short write", which is
just misleading.
libext2fs: force DIO alignment FreeBSD when operating on a block device
FreeBSD (and possibly BSD systems) requires that reads and writes to
block devices must be aligned, even when the O_DIRECT flag is not
specified. Previously this was hard-coded to 512 bytes, but in order
to properly handle Advanced Format HDD's, query the BSD kernel to
determine the proper alignment to use.
libext2fs: fix unaligned, multiblock writes in the unix_io handler
The read-modify-write code for the unaligned fallback code wasn't
working for multi-block writes. This was unmasked by FreeBSD 11-rc2,
since its malloc() is returning unaligned memory regions for large
memory regions.
Avoid crashing on unaligned pointers from corrupted file systems
On platforms that don't permit unaligned pointer dereferences,
corrupted file systems will as used by the regression test suite can
cause e2fsck and debugfs to crash. Avoid those crashes caused by
corrupted file systems. With this commit the full set of regression
test suites will pass on the sparc64 platform.
Fix a typo in the @ifNotGNUmake@ case of MCONFIG.in.
Also allow the FORCE_NATIVE_MAKE to force the use of the non-GNU make
optimized Makefile. The resulting makefile will work with GNU Make
4.2.1, although "make V=1" won't be honored.
Commit 35a4e1b1c5cbb introduced a regression which caused e2fsck on
32-bit systems to think all timestamps were legacy pre-1970
timestamps. Fix the bug.
debian: fix build reproducibility problems in the rules file
The configure file needs to be run using a relative pathname so that
when $(srcdir) gets introduced into binary file, the location of the
build directory doesn't find its way into the binaries.
libext2fs: allow the default journal size to go as large as a gigabyte
Recent research has shown that for a metadata-heavy workload, a 128 MB
is journal be a bottleneck on HDD's, and that the optimal journal size
is proportional to number of unique metadata blocks that can be
modified (and written into the journal) in a 30 second window. One
gigabyte should be sufficient for most workloads, which will be used
for file systems larger than 128 gigabytes.