Commit Graph

6766 Commits

Author SHA1 Message Date
Gabriel Krisman Bertazi
cc4f6884bf e2fsck.8.in: document check_encoding extended option
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:19:35 -05:00
Gabriel Krisman Bertazi
1e6a3a32be e2fsck: add option to force encoded filename verification
This is interesting for !strict filesystems as part of the encoding
update procedure. Once the filesystem is known to not have badly encoded
filenames, the update is trivial, thanks to the stability of assigned
code points in the unicode specification.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:18:53 -05:00
Gabriel Krisman Bertazi
782df52338 e2fsck: detect duplicated casefolded direntries for rehash
On pass2, support casefolded directories when looking for duplicated
entries.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:16:44 -05:00
Gabriel Krisman Bertazi
b093016890 dict: support comparison with context
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:12:02 -05:00
Gabriel Krisman Bertazi
9d2e1df4c9 e2fsck: support casefold directories when rehashing
When rehashing a +F directory, the casefold comparison needs to be
performed, in order to identify duplicated filenames.  Like the -F
version, This is done in two steps, first adapt the qsort comparison to
consider casefolded directories, and then iterate over the sorted list
fixing dups.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:11:41 -05:00
Gabriel Krisman Bertazi
06b83bbd40 e2fsck: fix entries with invalid encoded characters
On strict mode, invalid Unicode sequences are not permited.  This patch
adds a verification step to pass2 to detect and modify the entries with
the same replacement char used for non-encoding directories '.'.

After the encoding test, we still want to check the name for usual
problems, '\0', '/' in the middle of the sequence.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:09:55 -05:00
Arnaud Ferraris
d380e9d6f0 e2fsck: add new problem for encoded name check
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:09:52 -05:00
Gabriel Krisman Bertazi
a3def1e3ce ext2fs: implement faster CI comparison of strings
Instead of calling casefold two times and memcmp the result, which
require allocating a temporary buffer for the casefolded version, add a
strcasecmp-like method to perform the comparison of each code-point
during the casefold itself.

This method is exposed because it needs to be used directly by fsck.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:09:39 -05:00
Gabriel Krisman Bertazi
fc9e28605a ext2fs: add method to validate casefolded strings
This is exported to be used by fsck.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:09:36 -05:00
Gabriel Krisman Bertazi
4e735c502f tune2fs: fix casefold+encrypt error message
Refering to EXT4_INCOMPAT_CASEFOLD as encoding is not as meaningful as
saying casefold.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:09:34 -05:00
Gabriel Krisman Bertazi
1f9bb778a8 tune2fs: allow enabling casefold feature after fs creation
The main reason we didn't allow this before was because !CASEFOLDED
directories were expected to be normalized().  Since this is no longer
the case, and as long as the encrypt feature is not enabled, it should
be safe to enable this feature.

Disabling the feature is trickier, since we need to make sure there are
no existing +F directories in the filesystem.  Leave that for a future
patch.

Also, enabling strict mode requires some filesystem-wide verification,
so ignore that for now.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 22:09:31 -05:00
Harshad Shirwadkar
3e994cc5b8 tests: add fast commit recovery tests
Add j_recover_fast_commit test that ensure that e2fsck is able to
recover a disk from fast commit log.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 20:12:33 -05:00
Harshad Shirwadkar
f5de3d7c1b e2fsck: add replay for add_range, del_range, and inode tags
Add replay for inode's extent trees and inode itself.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 20:12:33 -05:00
Harshad Shirwadkar
63b7192cae e2fsck: add fc replay for link, unlink, creat tags
Add fast commit replay for directory entry updates.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 20:12:33 -05:00
Harshad Shirwadkar
3ba3ec0b33 e2fsck: add fast commit replay skeleton
This function adds the skeleton for the replay path. Following patches
in the series implement the handling for individual tags.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 20:12:33 -05:00
Harshad Shirwadkar
81a6b0109d e2fsck: add fast commit scan pass
Add fast commit scan pass. Scan pass is responsible for following
things:

* Count total number of fast commit tags that need to be replayed
  during the replay phase.

* Validate whether the fast commit area is valid for a given
  transaction ID.

* Verify the CRC of fast commit area.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 20:12:33 -05:00
Harshad Shirwadkar
c8a097c2e1 e2fsck: add fast commit setup code
Introduce "e2fsck_fc_replay_state" structure which is needed for ext4
fast commit replay.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 20:12:33 -05:00
Harshad Shirwadkar
9dc54e46db e2fsck: add function to rewrite extent tree
Fast commit replay needs to rewrite the entire extent tree for inodes
found in fast commit area. This patch makes e2fsck's rewrite extent
tree path visible.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 20:12:33 -05:00
Harshad Shirwadkar
cf2d9de7ee ext2fs: add new APIs needed for fast commits
This patch adds the following new APIs:

Count the total number of blocks occupied by inode including
intermediate extent tree nodes.
extern errcode_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
                                     struct ext2_inode *inode,
				     blk64_t *ret_count);

Convert the on-disk reputation of an extent to the in-memory
representation.
extern errcode_t ext2fs_decode_extent(struct ext2fs_extent *to, void *from,
                                     int len);

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 20:11:20 -05:00
Theodore Ts'o
865221f5aa e2fsck: declare the size of bh->b_data to be 4096 in jfs_user.h
When allocating buffer_heads in e2fsck and debugfs the actual size of
the memory which is requested is based on the file system block size.
So the actual size of b_data in struct buffer_head doesn't actually
matter, except that it can triggers a UBSAN error when running the
e2fsck regression test.  So change it to be 4096 to avoid this false
positive.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-27 16:41:05 -05:00
Theodore Ts'o
45fa214d62 Merge branch 'maint' into next 2021-01-23 01:05:43 -05:00
Theodore Ts'o
26cb9f7db6 Include PTHREAD_CFLAGS in LDFLAGS* macros
PTHREAD_CFLAGS is set by AX_PTHREADS, and these flags need to be
included when linking executables.

Fixes: bdcd5f2220 ("Add configure and build support for the pthreads library")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-23 01:02:19 -05:00
Theodore Ts'o
b3f288ed9f Fix clang warnings
Clang gets unhappy when passing an unsigned char to string functions.
For better or for worse we use __u8[] in the definition of the
superblock.  So cast them these to "char *" to prevent clang
build-time warnings.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-23 00:57:18 -05:00
Theodore Ts'o
b1b864b398 libext2fs: use compiler built-in offsetof() if available
This avoids UBSAN sanitizer warnings, since &(0->member) is
technically undefined per the C standard.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-23 00:55:25 -05:00
Theodore Ts'o
3e364978bc Only build resize2fs.static when running "make all-static"
Fixes: 93df80d240 ("Teach makefiles... the target all-static")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-23 00:46:04 -05:00
Theodore Ts'o
c3c41d4ffb libext2fs: fix UBSAN warning in ext2fs_mmp_new_seq()
Left shifting the pid by 16 bits can cause a UBSAN warning if the pid
is greater than or equal to 2**16.  It doesn't matter since we're just
using the pid to seed for a pseudo-random number generator, but
silence the warning by just swapping the high and low 16 bits of the
pid instead.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 23:27:00 -05:00
Jan Kara
33b0356c35 mke2fs.8: Improve valid block size documentation
Explain which valid block sizes mke2fs supports in more detail.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 18:26:25 -05:00
Hauke Mehrtens
4d108756a4 build: Add SYSLIBS to e4crypt linking
The $(SYSLIBS) was missing when linking the e4crypt application. This is
available in the e4crypt.profiled variant, so I assume this was just
missing in the normal variant and is not left out intentionally.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 18:11:39 -05:00
Theodore Ts'o
f8049f9fd7 tune2fs: abort clearing the dir_index when the fs needs to be fsck'ed first
We were not checking the return value of check_fsck_needed() when
checking to clear the dir_index feature.  As a result, tune2fs would
print that the file system needed to be checked first, but then go
ahead and clear the dir_index flag.

Addresses-Coverity-Bug: 1467671
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 17:08:40 -05:00
Theodore Ts'o
f84fed462a e2fsck: remove dead code when recreating the journal
params.num_journal_blocks is an unsigned value so it can never be less
than zero.

Addresses-Coverity-Bug: 1472250
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 16:51:45 -05:00
Theodore Ts'o
0304717d0c debugfs: fix the printf specifier when dumping a fast commit block
Addresses-Coverity-Bug: 1472249
Addresses-Coverity-Bug: 1472253
Addresses-Coverity-Bug: 1472254
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 16:44:39 -05:00
Theodore Ts'o
7b8cf296b0 libext2fs: fix minor Coverity nits in ext2fs_rw_bitmaps()
Addresses-Coverity-Bug: 1472252
Addresses-Coverity-Bug: 1472253
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 16:34:57 -05:00
Theodore Ts'o
32c2b19945 tune2fs: fix resource leak in handle_quota_options()
Addresses-Coverity-Bug: 1467672
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 16:07:25 -05:00
Theodore Ts'o
12c415fb0b debugfs: fix double free in realloc() error path in read_list()
Fixes-Coverity-Bug: 1464575
Fixes-Coverity-Bug: 1464571
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 16:01:14 -05:00
Theodore Ts'o
dd2ed58ab1 libext2fs: fix incorrect negative error return in unix and sparse io managers
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 16:00:01 -05:00
Theodore Ts'o
ecbe47df04 libext2fs: fix incorrect negative error return in ext2fs_rw_bitmaps()
Fixes: e2e58d3128 ("ext2fs: parallel bitmap loading")
Fixes-Coverity-Bug: 147255
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 15:20:45 -05:00
Harshad Shirwadkar
8968289b51 debugfs: add fast commit support to logdump
Add fast commit support for debugfs logdump.

This commit also adds fast_commit.h that contains the necessary
helpers needed for fast commit replay. Note that this file is also
byte by byte identical with kernel's fast_commit.h.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 11:46:29 -05:00
Harshad Shirwadkar
ef44eef00e ext4: fix tests to account for new dumpe2fs output
dumpe2fs tool now is capable of reporting number of fast commit
blocks. There were slight changes in the output of dumpe2fs outside of
fast commits. This patch fixes the regression tests to expect the new
output.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:59:38 -05:00
Harshad Shirwadkar
06def17e2f Make userspace tools number of fast commits blocks aware
This patch makes number of fast commit blocks configurable. Also, the
number of fast commit blocks can now be seen in dumpe2fs output.

$ ./misc/mke2fs -O fast_commit -t ext4 image
mke2fs 1.46-WIP (20-Mar-2020)
Discarding device blocks: done
Creating filesystem with 5120 1k blocks and 1280 inodes
Allocating group tables: done
Writing inode tables: done
Creating journal (1040 blocks): done
Writing superblocks and filesystem accounting information: done

$ ./misc/dumpe2fs image
dumpe2fs 1.46-WIP (20-Mar-2020)
...
Journal features:         (none)
Total journal size:       1040k
Total journal blocks:     1040
Max transaction length:   1024
Fast commit length:       16
Journal sequence:         0x00000001
Journal start:            0

$ ./misc/mke2fs -O fast_commit -t ext4 image -J fast_commit_size=256,size=1
mke2fs 1.46-WIP (20-Mar-2020)
Creating filesystem with 5120 1k blocks and 1280 inodes
Allocating group tables: done
Writing inode tables: done
Creating journal (1280 blocks): done
Writing superblocks and filesystem accounting information: done

$ ./misc/dumpe2fs image
dumpe2fs 1.46-WIP (20-Mar-2020)
...
Journal features:         (none)
Total journal size:       1280k
Total journal blocks:     1280
Max transaction length:   1024
Fast commit length:       256
Journal sequence:         0x00000001
Journal start:            0

This patch also adds information about fast commit feature in mke2fs
and tune2fs man pages.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:57:22 -05:00
Harshad Shirwadkar
3cc4f86744 libext2fs: provide APIs to configure fast commit blocks
This patch adds new libext2fs that allow configuring number of fast
commit blocks in journal superblock. We also add a struct
ext2fs_journal_params which contains number of fast commit blocks and
number of normal journal blocks. With this patch, the preferred way
for configuring number of blocks with and without fast commits is:

struct ext2fs_journal_params params;

ext2fs_get_journal_params(&params, ...);
params.num_journal_blocks = ...;
params.num_fc_blocks = ...;
ext2fs_create_journal_superblock2(..., &params, ...);
         OR
ext2fs_add_journal_inode3(..., &params, ...);

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:55:24 -05:00
Harshad Shirwadkar
7ed2b5d0f5 e2fsck: port fc changes from kernel's recovery.c to e2fsck
This patch makes recovery.c identical with fast commit kernel changes.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:53:46 -05:00
Harshad Shirwadkar
2fc929c65e e2fsck: add kernel endian-ness conversion macros
In order to make recovery.c identical with kernel, we need endianness
conversion macros (such as cpu_to_be32 and friends) defined in
e2fsprogs. This patch defines these macros and also fixes recovery.c
to use these. These macros are also needed for fast commit recovery
patches later in this series.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:53:46 -05:00
Harshad Shirwadkar
895e8e33be ext2fs: move calculate_summary_stats to ext2fs lib
The function calculate_summary_stats sets the global metadata of the
file system. Tune2fs had this function defined statically in
tune2fs.c. Fast commit replay needs this function to set global
metadata at the end of the replay phase. So, move this function to
libext2fs.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:53:46 -05:00
Theodore Ts'o
37d5686405 Enable threaded support for e2fsprogs' applications.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:50:40 -05:00
Wang Shilong
e2e58d3128 ext2fs: parallel bitmap loading
In our benchmarking for PiB size filesystem, pass5 takes
10446s to finish and 99.5% of time takes on reading bitmaps.

It makes sense to reading bitmaps using multiple threads,
a quickly benchmark show 10446s to 626s with 64 threads.

[ This has all of many bug fixes for rw_bitmaps.c from the original
  luster patch set collapsed into a single commit.   In addition it has
  the new ext2fs_rw_bitmaps() api proposed by Ted. ]

Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:50:40 -05:00
Theodore Ts'o
2caad64629 libext2fs: allow the unix_io manager's cache to be disabled and re-enabled
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:50:40 -05:00
Theodore Ts'o
f20627cc63 libext2fs: add threading support to the I/O manager abstraction
Add initial implementation support for the unix_io manager.
Applications which want to use threading should pass in
IO_FLAG_THREADS when opening the channel.  Channels which support
threading (which as of this commit is unix_io and test_io if the
backing io_manager supports threading) will set the
CHANNEL_FLAGS_THREADS bit in io->flags.  Library code or applications
can test if threading is enabled by checking this flag.

Applications using libext2fs can pass in EXT2_FLAG_THREADS to
ext2fs_open() or ext2fs_open2() to request threading support.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:50:40 -05:00
Theodore Ts'o
bdcd5f2220 Add configure and build support for the pthreads library
Support for pthreads can be forcibly disabled by passing
"--without-pthread" to the configure script.

The actual changes in this commit are in configure.ac and MCONFIG.in;
the other files were generated as a result of running aclocal,
autoconf, and autoheader on a Debian testing system.

Note: the autoconf-archive package must now be installed before
rerunning aclocal, to supply the AX_PTHREAD macro.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-21 10:50:40 -05:00
Theodore Ts'o
0d47f5ab05 Merge branch 'maint' into next 2021-01-19 23:58:57 -05:00
Lukas Czerner
6fa8edd0fd mke2fs: Escape double quotes when parsing mke2fs.conf
Currently, when constructing the <default> configuration pseudo-file using
the profile-to-c.awk script we will just pass the double quotes as they
appear in the mke2fs.conf.

This is problematic, because the resulting default_profile.c will either
fail to compile because of syntax error, or leave the resulting
configuration invalid.

It can be reproduced by adding the following line somewhere into
mke2fs.conf configuration and forcing mke2fs to use the <default>
configuration by specifying nonexistent mke2fs.conf

MKE2FS_CONFIG="nonexistent" ./misc/mke2fs -T ext4 /dev/device

default_mntopts = "acl,user_xattr"
^ this will fail to compile

default_mntopts = ""
^ this will result in invalid config file

Syntax error in mke2fs config file (<default>, line #4)
       Unknown code prof 17

Fix it by escaping the double quotes with a backslash in
profile-to-c.awk script.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2021-01-19 23:56:20 -05:00