Whamcloud - gitweb
tools/e2fsprogs.git
20 months agotests: add pfsck test
Wang Shilong [Wed, 23 Sep 2020 15:58:23 +0000 (23:58 +0800)]
tests: add pfsck test

pfsck run on a clean fs should not return any errors.

Generate an image with possible features enabled,
especially EA shared blocks etc.

E2fsprogs-commit: 59ae5e5a627aaa24d663e8ce41955e1ded46633a

Change-Id: Ifa8d725993cf8bec08e847e2734bb44b0ddbfd04
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: reset @inodes_to_rebuild if restart
Wang Shilong [Thu, 24 Sep 2020 02:00:06 +0000 (10:00 +0800)]
e2fsck: reset @inodes_to_rebuild if restart

Verify multiple thread on a corrupted images hit following bug:

pass1.c:2902: e2fsck_pass1_thread_prepare:
Assertion `global_ctx->inodes_to_rebuild == NULL' failed.
Signal (6) SIGABRT si_code=SI_TKILL
./e2fsck/e2fsck[0x43829e]
/lib64/libpthread.so.0(+0x14b20)[0x7f3b45135b20]
/lib64/libc.so.6(gsignal+0x145)[0x7f3b44f2c625]
/lib64/libc.so.6(abort+0x12b)[0x7f3b44f158d9]
/lib64/libc.so.6(+0x257a9)[0x7f3b44f157a9]
/lib64/libc.so.6(+0x34a66)[0x7f3b44f24a66]
./e2fsck/e2fsck(e2fsck_pass1+0x1662)[0x423572]
./e2fsck/e2fsck(e2fsck_run+0x5a)[0x41611a]
./e2fsck/e2fsck(main+0x1608)[0x4121b8]
/lib64/libc.so.6(__libc_start_main+0xf3)[0x7f3b44f171a3]
./e2fsck/e2fsck(_start+0x2e)[0x413dde]

@inodes_to_rebuild could be not NULL after we restart pass1

E2fsprogs-commit: 3b7879e310d30d5f4c518c607aec830b63b2315b

Change-Id: I8ca6a37d41788333fe9494bd84816932f39fcb3c
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: update mmp block in one thread
Wang Shilong [Wed, 23 Sep 2020 14:36:41 +0000 (22:36 +0800)]
e2fsck: update mmp block in one thread

For multiple threads, different threads will try to
update mmp block at the same time, only allow one
thread to update it.

E2fsprogs-commit: 1806140014cbce395d0ca4a51d46fa21e2833241

Change-Id: Id78b949d338c384a64828b955ed7477aa816f8ee
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: make default smallest RA size to 1M
Wang Shilong [Tue, 15 Sep 2020 07:06:11 +0000 (15:06 +0800)]
e2fsck: make default smallest RA size to 1M

If we have a smaller inodes per group, default ra size could
be very small(etc 128KiB), this hurts performances.

Tune above 128K to 1M, i see pass1 time drop down from
677.12 seconds to 246 secons with 32 threads.

E2fsprogs-commit: 9226b3264b74044013f4933280b1989c33be42f3

Change-Id: Ia503b4f73dc8f3d5e6be705c7311bdacc5b874a9
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: avoid too much memory allocation for pfsck
Wang Shilong [Wed, 27 May 2020 07:14:23 +0000 (07:14 +0000)]
e2fsck: avoid too much memory allocation for pfsck

e2fsck init memory according to filesystem inodes/dir numbers
recorded in the superblock, this should be aware of filesystem
number of threads, otherwise, oom happen.

E2fsprogs-commit: ed2cec54da604efe1af2734182985d1730674138

Change-Id: Ia66cd782a330f3f0215c7119c25ef701edc8b143
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: cleanup e2fsck_pass1_thread_join()
Wang Shilong [Wed, 23 Sep 2020 10:05:34 +0000 (18:05 +0800)]
e2fsck: cleanup e2fsck_pass1_thread_join()

Use e2fsck_reset_context() to free memory to simpify
codes.

E2fsprogs-commit: 41f40f4215fd9a357a3d250a34745eb953982bda

Change-Id: I1fdf12eb520f738d90453bbc886dbe89bc9a2b17
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: wait fix thread finish before checking
Wang Shilong [Thu, 14 May 2020 14:16:50 +0000 (22:16 +0800)]
e2fsck: wait fix thread finish before checking

Before proceeding next inodes, waitting existed
fixing finished.

E2fsprogs-commit: ae4a78493b16d01d7dbe628ec9064216f960bd16

Change-Id: I159082381e66bd51b3558a65ef45e936aa741370
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: set E2F_FLAG_ALLOC_OK after threads
Wang Shilong [Thu, 16 Apr 2020 07:08:31 +0000 (15:08 +0800)]
e2fsck: set E2F_FLAG_ALLOC_OK after threads

Only flag ALLOC OK after all threads finished without problem.

E2fsprogs-commit: 2c1e9ced674f0d8e634c3b6299ce9bdfbe4b8739

Change-Id: I764d08bab5299ec0aec9d7d5e9b21320c085dee9
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoLU-14768 e2fsck: merge casefolded dir lists after thread finish
Wang Shilong [Thu, 12 Mar 2020 11:40:27 +0000 (19:40 +0800)]
LU-14768 e2fsck: merge casefolded dir lists after thread finish

This is missed and should be done after threads finish.

Original commit:
18538b27 ("LU-8465 e2fsck: merge encrypted dir lists after thread finish")
Upstream is now using e2fsck_struct->casefolded_dirs instead of
encrypted_dirs.

Only for the correctness of pfsck, we won't use casefolded feature on
ldiskfs.

Change-Id: I6f3a28501886c2ed4bec26dc5c5e5a1914fece04
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/44010
Reviewed-by: Wang Shilong <wshilong@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
20 months agoe2fsck: simplify e2fsck context merging codes
Wang Shilong [Fri, 13 Mar 2020 10:46:24 +0000 (18:46 +0800)]
e2fsck: simplify e2fsck context merging codes

We tried to copy thread context to global context directly
and then copy back some saved variables before merging.

Since we have finished almost all necessary variables
in the e2fsck context, we could simplify codes, and
this could help us understand what is missing rather
than hide problems.

E2fsprogs-commit: 41c991af7ed7244da0fd799f63e4e6fd0d6c5b25

Change-Id: I450e3f5fb26c5c6fe8a075373bf538965f443d02
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge extent depth count after threads finish
Wang Shilong [Fri, 20 Mar 2020 01:55:18 +0000 (09:55 +0800)]
e2fsck: merge extent depth count after threads finish

tests covered by f_extent_htree.

E2fsprogs-commit: 291bc9b7fc5280166e58b0e586d5ec93738f31a7

Change-Id: I5b4f629e1031f719a2d032a9dd5edb1cfac90975
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: reset lost_and_found after threads finish
Wang Shilong [Fri, 20 Mar 2020 01:50:56 +0000 (09:50 +0800)]
e2fsck: reset lost_and_found after threads finish

This should not be kept, the reaons is similar to what
e2fsck_pass1 has done before.

E2fsprogs-commit: 10abbf8fd534d61c40fbf9699bf605ac6456b2e2

Change-Id: I0e431be7619720e31927ab1df7034aee1e3eb747
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge options after threads finish
Wang Shilong [Thu, 19 Mar 2020 14:05:30 +0000 (22:05 +0800)]
e2fsck: merge options after threads finish

It will be possible that threads might append E2F_OPT_YES,
so we need merge options to global, test f_yesall cover this.

E2fsprogs-commit: a68a5e890793eda2e8d7b4f7d27d23a7eeb474c5

Change-Id: I0e8bbc078fc538bd7d948ced1161506710401ab3
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: fix readahead for pfsck of pass1
Wang Shilong [Wed, 11 Mar 2020 12:48:00 +0000 (20:48 +0800)]
e2fsck: fix readahead for pfsck of pass1

Several improvments for this patch:

1) move readahead_kb detection to preparing phase.
2) inode readahead should be aware of thread block group
boundary.
3) make readahead_kb aware of multiple threads.

E2fsprogs-commit: 02618b8f69c1ed453b092476cbd0d735206c939d

Change-Id: I2f9d7b8ae5039c0551bb3994f1c7814af257cee5
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoLU-14432 ext2fs: fix ext2fs_get_avg_group() warning
Andreas Dilger [Mon, 31 May 2021 21:08:13 +0000 (15:08 -0600)]
LU-14432 ext2fs: fix ext2fs_get_avg_group() warning

Move ext2fs_get_avg_group() into e2fsck/pass1.c instead of the
ext2fs.h header, since it is currently only used in that one
function.  It is too large to be a static inline function, and
it is currently causing many compile warnings because it is
not marked with "_INLINE_".

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Ie948bc10f44dccf91558099a5217ea1fb5ce7057
Reviewed-on: https://review.whamcloud.com/43881
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Wang Shilong <wshilong@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
20 months agoe2fsck: adjust number of threads
Wang Shilong [Wed, 9 Sep 2020 07:07:10 +0000 (15:07 +0800)]
e2fsck: adjust number of threads

number of threads should not exceed flex bg numbers,
and output messages if we adjust threads number.

E2fsprogs-commit: 56070582ad951aa55b6eeecd7e8e2a19d53bbff6

Change-Id: I8bc87e6ca99205d7fc9e0c9f35d0ba9c3eed38ca
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: allow admin specify number of threads
Wang Shilong [Mon, 9 Mar 2020 07:11:10 +0000 (15:11 +0800)]
e2fsck: allow admin specify number of threads

-m option is introduced to specify number of threads for pfsck.

E2fsprogs-commit: e3bb22efe1c62f8c81686e1d8d065a4943e14bd3

Change-Id: I856d06e0c62f23bdd84e7b6bf53cdc4a46dd58da
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: kickoff mutex lock for block found map
Wang Shilong [Wed, 11 Mar 2020 02:12:18 +0000 (10:12 +0800)]
e2fsck: kickoff mutex lock for block found map

Now @block_found_map is no longer shared by multiple threads,
and @block_dup_map need be checked again after threads finish.

E2fsprogs-commit: 17df3e9f85594eca5515630753542ab5a5c92ee1

Change-Id: I4fb9ae84b70b7ee7d7ce2c0f7a8876ab89c31b5c
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge EA blocks properly
Wang Shilong [Thu, 12 Mar 2020 08:05:51 +0000 (16:05 +0800)]
e2fsck: merge EA blocks properly

EA blocks might be shared, merge them carefully.

E2fsprogs-commit: b9c38a69ff1af2e0c2b9ddce96de965ce62b0de6

Change-Id: Ib01b7cf9c32f7e119bfd00972488b731b13f1ed9
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: split and merge invalid bitmaps
Wang Shilong [Sat, 14 Dec 2019 05:12:36 +0000 (13:12 +0800)]
e2fsck: split and merge invalid bitmaps

Invalid bitmaps are splitted per thread, and we
should merge them after thread finish.

E2fsprogs-commit: e3e15f5c8f72f95d65d602929f59c1c78e72c5a0

Change-Id: I004f595c107adf390f3b16b90cb4b6aa3650f9de
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: move some fixes out of parallel pthreads
Wang Shilong [Sat, 7 Mar 2020 14:00:45 +0000 (22:00 +0800)]
e2fsck: move some fixes out of parallel pthreads

We could only use @found_map_block to find free blocks
after we have collectd all used blocks, so something like
handle_fs_bad_blocks(), ext2fs_create_resize_inode(),
e2fsck_pass1_dupblocks() really should be handled after
all threads has been finished.

E2fsprogs-commit: 6b1d459bf6018eea7ff0a0ae6b555276718dcda3

Change-Id: Ibdbaed3d218623daa0baec31837037d773799262
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: serialize fix operations
Wang Shilong [Fri, 6 Mar 2020 08:46:47 +0000 (16:46 +0800)]
e2fsck: serialize fix operations

Allow different threads to fix at the same time could
be dangerous and error-prone now, and most of time
parallel scanning and checking is important.

So this patch adds a mutex to serialize
fix operations during pass1.

And the good benefit of this, we don't need block
allocations and free, superblock updates protection
any more, since only fix operations during pass1
could touch them.

E2fsprogs-commit: 5485120b668c952b6e83f24a1e1a74eaa7bf362e

Change-Id: Iedb64545240cc9325dc0c4ce737a970b27f4f3f6
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge quota context after threads finish
Wang Shilong [Fri, 6 Mar 2020 15:08:07 +0000 (23:08 +0800)]
e2fsck: merge quota context after threads finish

Every threads calculate its own quota accounting,
merge them after threads finish.

E2fsprogs-commit: a0af18577fbb960eb20695afbb4af4e23b864909

Change-Id: If9f0e17e560715ed55183f85c443f21ebbce7d40
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge context flags properly
Wang Shilong [Mon, 24 Feb 2020 05:08:58 +0000 (13:08 +0800)]
e2fsck: merge context flags properly

e2fsck might restart after pass1, so we should keep
flags if possible, this patch try to fix f_illitable_flexbg failure

E2fsprogs-commit: c36fa1b28bd4171f53ab4f89a90f6b3b8bf80fd2

Change-Id: I6dda1520a2ff6255d244461af75d7609f47ba92b
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge dirs_to_hash when threads finish
Wang Shilong [Mon, 24 Feb 2020 04:44:06 +0000 (12:44 +0800)]
e2fsck: merge dirs_to_hash when threads finish

@dirs_to_hash list need be merged after threads finish,
test covered by t_dangerous.

E2fsprogs-commit: e2db6c19943065909c11af3b03c2904c35e5e4f8

Change-Id: I99b44c40afa22ce8e4530c874b077493cf969e03
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge dx_dir_info after threads finish
Wang Shilong [Fri, 6 Dec 2019 15:37:53 +0000 (23:37 +0800)]
e2fsck: merge dx_dir_info after threads finish

Merge properly.

E2fsprogs-commit: 45519b8167a00979e86d5a5aa95d0bfb07f72520

Change-Id: Ifaed7a0022b716c42df908327c41aaaaa39aa365
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge fs flags when threads finish
Li Xi [Sun, 8 Sep 2019 08:15:35 +0000 (16:15 +0800)]
e2fsck: merge fs flags when threads finish

merge fs flags properly.

E2fsprogs-commit: d4c0519725d59c9380acc828d24bc070c5bc2c03

Change-Id: I80c773bebc0e321bf2fe3b436c3f0e601b1f1b79
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge counts after threads finish
Wang Shilong [Tue, 22 Sep 2020 13:14:39 +0000 (21:14 +0800)]
e2fsck: merge counts after threads finish

Merge counts properly.

E2fsprogs-commit: 057060ccabf9b5b47afe435d90a1f7f68c03a231

Change-Id: Ieace889f0d1a20a1990424113b0e8fc81f945266
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: add debug codes for multiple threads
Li Xi [Thu, 5 Sep 2019 11:40:36 +0000 (19:40 +0800)]
e2fsck: add debug codes for multiple threads

These debug codes are added to run the multiple pass1 check
thread one by one in order. If all the codes are correct,
fsck of multiple threads should have exactly the same outcome
with single thread.

E2fsprogs-commit: a8b483a1e7987a6dddc32bc82db06f649d245630

Change-Id: I41b0493a0cd830b76434ff0f86a87c98d8d3ad22
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge dblist after thread finishes
Li Xi [Thu, 5 Sep 2019 08:30:40 +0000 (16:30 +0800)]
e2fsck: merge dblist after thread finishes

Merge dblist properly.

E2fsprogs-commit: f3c2256490297201c63139ba0fea5c6b09bca3cf

Change-Id: Ifd907035ed9762c446c688ccc5af3f3fcaa52d24
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge icounts after thread finishes
Li Xi [Wed, 4 Sep 2019 10:47:14 +0000 (18:47 +0800)]
e2fsck: merge icounts after thread finishes

Merge inode_count and inode_link_info properly after
threads finish.

E2fsprogs-commit: bb78742b5e2e95c3e7e9a76755144fdf8ec12285

Change-Id: If40930a87595010963fd59a54709a4d2b27d223b
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge badblocks after thread finishes
Wang Shilong [Tue, 22 Sep 2020 10:00:39 +0000 (18:00 +0800)]
e2fsck: merge badblocks after thread finishes

Badblocks should be merged properly after threads finish.

E2fsprogs-commit: f39197f53ef5d90cd6952d7e75f2d2e3a02bf7ef

Change-Id: Ieb9a96a5e4438270ba6e939155e2666bb53177e4
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: rbtree bitmap for dir
Wang Shilong [Mon, 21 Sep 2020 11:02:33 +0000 (19:02 +0800)]
e2fsck: rbtree bitmap for dir

Only rbtree support merge operation now, use it for bitmaps.

E2fsprogs-commit: 9bab3284e30752bccc36be3e07b9ca4dfd218041

Change-Id: I42aeb009ece78a4baf4369aff3355fc9df51089a
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge dir_info after thread finishes
Li Xi [Mon, 2 Sep 2019 08:14:38 +0000 (16:14 +0800)]
e2fsck: merge dir_info after thread finishes

dir_info need be merged after thread finish.

E2fsprogs-commit: fdbf5e226cf931a5713414001b95e4697997a464

Change-Id: I7e33c0035ec8c6bfa7c13d759e3edb468634eae3
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: optimize the inserting of dir_info_db
Li Xi [Fri, 30 Aug 2019 09:56:10 +0000 (17:56 +0800)]
e2fsck: optimize the inserting of dir_info_db

Binary search is now used when inserting an dir info to the array.
Memmove is now used when moving array. Both of them improves
the performance of inserting.

This patch is also a prepartion for the merging of two dir db
arrays.

E2fsprogs-commit: 13d3c76475d050941d244c85cbb9256ffd980f88

Change-Id: I69041084dbd7e36eefa44744c3fb3737af8e906e
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: do not change global variables
Li Xi [Fri, 30 Aug 2019 04:20:11 +0000 (12:20 +0800)]
e2fsck: do not change global variables

Global variables used in pass1 check are changed to local variables
in this patch. This will avoid conflict between threads.

E2fsprogs-commit: 5a1b22da5ca3e90728cee1dbe6bc1920b245dded

Change-Id: Ifc682874801af15e8e13764832ca569b7da4ac57
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: merge bitmaps after thread completes
Wang Shilong [Wed, 23 Sep 2020 03:17:29 +0000 (11:17 +0800)]
e2fsck: merge bitmaps after thread completes

A new method merge_bmap has been added to bitmap operations. But
only red-black bitmap has that operation now.

E2fsprogs-commit: ecf85fb474fb7537f14bddd8f85d8372b808d5e9

Change-Id: Id5c387dd813d633adff3afb9208213086c33b6d2
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: print thread log properly
Li Xi [Mon, 26 Aug 2019 14:34:06 +0000 (22:34 +0800)]
e2fsck: print thread log properly

When multi-thread fsck is enabled, logs printed from multiple
threads could overlap with each other. The overlap sometimes
makes the logs unreadable because log_out() is used multiple times
for a single line.

This patch adds leading [Thread XXX] to each logs if multi-thread
is enabed by -m option.

This patch also adds message to show the group ranges and inode
numbers for each thread, which is useful for debuging multi-thread
check.

E2fsprogs-commit: 5b071ed80deca2cdc87585a673076529dd47ca6e

Change-Id: I4bd08bc48813a399ab3a79130ff159b12d22f3a0
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: split groups to different threads
Li Xi [Thu, 22 Aug 2019 07:35:12 +0000 (15:35 +0800)]
e2fsck: split groups to different threads

The start/end groups of a thread is calculated according to the
thread number. But still, only one thread is used to check.

E2fsprogs-commit: 562df7468d97042689896cff4b48c6cebc3b8508

Change-Id: I3175b4e6f0423ecd69ed55afea45f1c5919f5c79
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: add start/end group for thread
Li Xi [Wed, 21 Aug 2019 13:58:31 +0000 (21:58 +0800)]
e2fsck: add start/end group for thread

When multi-threads are used for check, each thread needs to jump
to different group in pass1 check. This patch adds the group
jumping support. But still, only one thread is used to check.

E2fsprogs-commit: f64ff7f53c6fb22c7e4bebe86749b1be31439424

Change-Id: I904bedcbd02bca591665943cff5f2d7a6fa50fbe
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: configure one pfsck thread
Li Xi [Thu, 15 Aug 2019 08:33:19 +0000 (16:33 +0800)]
e2fsck: configure one pfsck thread

This patch creates only one thread to do pass1 check if pthreads are
enabled. The same codes can be used to create multiple threads, but
other functions need to be modified to get ready for that.

E2fsprogs-commit: b2a9a40831dfbb6dacf8bbc819acac2c25ab6980

Change-Id: I3df998a8ecc00d2dc5e959f5a9991a6b65182572
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: create logs for mult-threads
Li Xi [Tue, 13 Aug 2019 03:55:27 +0000 (11:55 +0800)]
e2fsck: create logs for mult-threads

When multi-threads are used, different logs should be created
for different threads. Each thread has log files with suffix
of ".$THREAD_INDEX".

And this patch adds f_multithread_logfile test case.

E2fsprogs-commit: 2643de7d00dc8da9f5be79fab768fca7a27f3745

Change-Id: I86982866b9e8e2d2cc5ac2ec9ac44a3b802c21e0
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: open io-channel when copying fs
Li Xi [Sat, 10 Aug 2019 07:59:09 +0000 (15:59 +0800)]
e2fsck: open io-channel when copying fs

This patch also add writethrough flag to the thread io-channel.
When multiple threads write the same disk, we don't want the
data being saved in memory cache. This will be useful in the
future, but even without that flag, the tests can be passed too.

This patch also cleanup the io channel cache of the global
context. Otherwise, after pass1 step, the next steps would use
old data saved in the cache. And the cached data might have
already been overwritten in pass1.

E2fsprogs-commit: f15100003400e5fc01b34c25a7a4b61f5ed76148

Change-Id: I7fcf4038b6cb4eb52808b9a5bafdf909ca2c0c8e
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: copy badblocks when copying fs
Wang Shilong [Wed, 9 Sep 2020 07:07:10 +0000 (15:07 +0800)]
e2fsck: copy badblocks when copying fs

This patch copies badblocks when the copying fs.

E2fsprogs-commit: 8095b716e15bb15a47925ae02cb1c06e91fdb651

Change-Id: Ibf5718ad5851a9ccd853a2a1f928bce447aa5de9
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: copy bitmaps when copying context
Li Xi [Wed, 7 Aug 2019 08:54:41 +0000 (16:54 +0800)]
e2fsck: copy bitmaps when copying context

This patch copies bitmap when the copying context. In the
multi-thread fsck, each thread use different bitmap that copied
from the glboal bitmap. And Bitmaps from multiple threads will
be merged into a global one after the pass1 finishes.

E2fsprogs-commit: 4d47d0e84388bdf2242e09f9ba592ea778c1ba8e

Change-Id: I6a5a2b49b845215a7a735a828709396586520536
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: add assert when copying context
Li Xi [Wed, 7 Aug 2019 07:34:00 +0000 (15:34 +0800)]
e2fsck: add assert when copying context

Adding the assert would simplify the copying of context.

E2fsprogs-commit: 464abd60f5b68716d8ac5063d90562f9ecd2b004

Change-Id: I8276c2e90f40b08dea28b157e04df3c0f7099211
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: clear icache when using multi-thread fsck
Wang Shilong [Thu, 17 Sep 2020 02:58:56 +0000 (10:58 +0800)]
e2fsck: clear icache when using multi-thread fsck

icache of fs will be rebuilt when needed, so after copying
fs, icache can be inited to NULL.

E2fsprogs-commit: 5d4f09fa148e41b4e0ea01fc364de5bbedf02ecf

Change-Id: I21c58b3f126fd85008d6c732da71b298b2a8b4ff
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: copy fs when using multi-thread fsck
Li Xi [Tue, 6 Aug 2019 03:19:15 +0000 (11:19 +0800)]
e2fsck: copy fs when using multi-thread fsck

This patch only copy the fs to a new one when -m is enabled.
It doesn't actually start any thread. When pass1 test finishes,
the new fs is copied back to the original context.

This patch handles the fs fields in dblist, inode_map and block_map
properly.

E2fsprogs-commit: d88f9ae76882fc1210158ca3558c0bbad6676a79

Change-Id: Iab763de64e63366bc413d954dd7c8a8af45cb6a2
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: copy context when using multi-thread fsck
Li Xi [Mon, 5 Aug 2019 04:01:17 +0000 (12:01 +0800)]
e2fsck: copy context when using multi-thread fsck

This patch only copy the context to a new one when -m is enabled.
It doesn't actually start any thread. When pass1 test finishes,
the new context is copied back to the original context.

Since the signal handler only changes the original context, so
add global_ctx in "struct e2fsck_struct" and use that to check
whether there is any signal of canceling.

This patch handles the long jump properly so that all the existing
tests can be passed even the context has been copied. Otherwise,
test f_expisize_ea_del would fail when aborting.

E2fsprogs-commit: 05a637a9e68d3f7e15323deeab00981d4b7df7e8

Change-Id: I4994e62bdf27c385b02e55de82a9dafcc6a12139
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoe2fsck: add -m option for multithread
Li Xi [Sun, 4 Aug 2019 15:28:59 +0000 (23:28 +0800)]
e2fsck: add -m option for multithread

-m option is added but no actual functionality is added. This
patch only adds the logic that when -m is specified, one of
-p/-y/-n options should be specified. And when -m is specified,
-C shouldn't be specified and the completion progress report won't
be triggered by sending SIGUSR1/SIGUSR2 signals. This simplifies
the implementation of multi-thread fsck in the future.

Completion progress support with multi-thread fsck will be added
back after multi-thread fsck implementation is finished. Right
now, disable it to simplify the implementation of multi-thread fsck.

E2fsprogs-commit: 842ae5f528f9797e4b2c739daa76884e4349e8f3

Change-Id: I428f4f3b10974b769100bf00169bdd7d8cf86deb
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoAOSP: e2fsdroid: static import of libbase
Alessio Balsini [Wed, 18 May 2022 17:09:16 +0000 (18:09 +0100)]
AOSP: e2fsdroid: static import of libbase

Fix a wrong mixed shared/static library inclusion that has been unveiled
by a recent clang upgrade to clang-r450784e: the linker couldn't find
the requested object reference and caused the tool to crash.
libsnapshot_fuzzer_test was luckily catching this misbehaviour as it was
crashing as well when trying to format a loop device as ext4.

Bug: 230851331
Test: m && atest libsnapshot_fuzzer_test
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I20b7b1d66920eb8f767e49311f913564f14ee30e
Fix AOSP commit: 83239ca87da0bbdb088be7f0d048472e837899c2

20 months agoAOSP: Moved contents of clang_cflags into cflags
Alix [Thu, 21 Apr 2022 02:57:03 +0000 (02:57 +0000)]
AOSP: Moved contents of clang_cflags into cflags

Test: Treehugger
Bug: 226636335
Change-Id: If46f7b11aadcb29e33e36b67c56078ce5fa17b94
Fix AOSP commit: 19f3f24750096491b74d1f990adb617f3a5bba40

20 months agoAOSP: Fix e2fsdroid build with musl
Colin Cross [Tue, 17 Aug 2021 00:17:03 +0000 (17:17 -0700)]
AOSP: Fix e2fsdroid build with musl

The e2fsdroid build fails with musl because config.h is not included
before ext2fs.h, which causes HAVE_SYS_TYPES_H not to be defined
resulting in a missing definition for dev_t.

Include config.h at the top of each .c file, and remove extra
config.h include from perms.h.

Bug: 190084016
Test: m USE_HOST_MUSL=true fastboot
Change-Id: I95b3fff3f10ba85c00ec049811dd6b5d412e5dd2
From AOSP commit: 09c63d5edd35e3ca8366be0d92aad922d8895ac1

20 months agoAOSP: Add vendor available for libext2_blkid library
Tristan Muntsinger [Fri, 13 Aug 2021 00:40:56 +0000 (00:40 +0000)]
AOSP: Add vendor available for libext2_blkid library

This is to support the cuttlefish f2fs/ext4
userdata filesystem.

Bug: 142424832
Test: local build
Change-Id: I7acb772e77d9250805e5a8a7e68f136deda7c5cb
From AOSP commit: 5df70145b418f84a2d0570e106fd055dbc9d0038

20 months agolibext2fs: in ext2fs_open[2](), return an error if s_first_meta_bg is too big
Theodore Ts'o [Tue, 13 Sep 2022 11:59:52 +0000 (07:59 -0400)]
libext2fs: in ext2fs_open[2](), return an error if s_first_meta_bg is too big

These checks will be skipped for e2fsck when it uses the flag
EXT2_FLAG_IGNORE_SB_ERRORS.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agodebian: add release notes for 1.46.5-2 to the debian changelog
Theodore Ts'o [Tue, 13 Sep 2022 06:42:56 +0000 (02:42 -0400)]
debian: add release notes for 1.46.5-2 to the debian changelog

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agoUpdate release notes, etc. for the 1.46.6-rc1 release v1.46.6-rc1
Theodore Ts'o [Mon, 12 Sep 2022 12:31:53 +0000 (08:31 -0400)]
Update release notes, etc. for the 1.46.6-rc1 release

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agomisc fix the chattr's man page regarding the -x flag
Theodore Ts'o [Mon, 12 Sep 2022 12:08:27 +0000 (08:08 -0400)]
misc fix the chattr's man page regarding the -x flag

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agotune2fs: tune2fs_main() should return rc when some error, occurs
Zhiqiang Liu [Mon, 5 Sep 2022 15:40:01 +0000 (23:40 +0800)]
tune2fs: tune2fs_main() should return rc when some error, occurs

If some error occurs, tune2fs_main() will go to closefs tag for
releasing resource, and it should return correct value (rc) instead
of 0 when ext2fs_close_free(&fs) successes.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Reviewed-by: Artem Blagodarenko <artem.blagodarenko@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 months agotune2fs: fix tune2fs segfault when ext2fs_run_ext3_journal() fails
Zhiqiang Liu [Mon, 5 Sep 2022 11:16:03 +0000 (19:16 +0800)]
tune2fs: fix tune2fs segfault when ext2fs_run_ext3_journal() fails

When ext2fs_run_ext3_journal() fails, tune2fs cmd will occur one
segfault problem as follows.
(gdb) bt
#0  0x00007fdadad69917 in ext2fs_mmp_stop (fs=0x0) at mmp.c:405
#1  0x0000558fa5a9365a in main (argc=<optimized out>, argv=<optimized out>) at tune2fs.c:3440

misc/tune2fs.c:
main()
  -> ext2fs_open2(&fs)
    -> ext2fs_mmp_start
  ......
  -> retval = ext2fs_run_ext3_journal(&fs)
  -> if (retval)
    // if ext2fs_run_ext3_journal fails, close and free fs.
    -> ext2fs_close_free(&fs)
    -> rc = 1
    -> goto closefs
  ......
closefs:
  -> if (rc)
    -> ext2fs_mmp_stop(fs)     // fs has been set to NULL, boom!!
  -> (ext2fs_close_free(&fs) ? 1 : 0); // close and free fs

In main() of tune2fs cmd, if ext2fs_run_ext3_journal() fails,
we should set rc=1 and goto closefs tag, in which will release fs
resource.

Fix: a2292f8a5108 ("tune2fs: reset MMP state on error exit")
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agopo: update the binary gmo files
Theodore Ts'o [Thu, 1 Sep 2022 15:55:54 +0000 (11:55 -0400)]
po: update the binary gmo files

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agopo: add Friulian lagnuage
Theodore Ts'o [Thu, 1 Sep 2022 15:55:17 +0000 (11:55 -0400)]
po: add Friulian lagnuage

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoconfig: update config.{guess,sub}
Theodore Ts'o [Thu, 1 Sep 2022 15:41:14 +0000 (11:41 -0400)]
config: update config.{guess,sub}

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoUpdate makefile dependencies
Theodore Ts'o [Thu, 1 Sep 2022 14:59:29 +0000 (10:59 -0400)]
Update makefile dependencies

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoStart bumping version numbers in preparation for 1.46.6 release
Theodore Ts'o [Thu, 1 Sep 2022 14:56:20 +0000 (10:56 -0400)]
Start bumping version numbers in preparation for 1.46.6 release

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agopo: update zh_CN.po (from translationproject.org)
Wenbin Lv [Thu, 1 Sep 2022 14:54:11 +0000 (10:54 -0400)]
po: update zh_CN.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agopo: update ms.po (from translationproject.org)
Sharuzzaman Ahmat Raslan [Thu, 1 Sep 2022 14:54:11 +0000 (10:54 -0400)]
po: update ms.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agotests/fuzz: add missing targets to the Makefile in in tests/fuzz
Theodore Ts'o [Wed, 31 Aug 2022 19:45:27 +0000 (15:45 -0400)]
tests/fuzz: add missing targets to the Makefile in in tests/fuzz

This fixes failures when running "make install" or "make destclean"
from the top level directory.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agommp: don't use O_RDWR in ext2fs_mmp_read
Marius Vollmer [Wed, 24 Aug 2022 11:38:48 +0000 (14:38 +0300)]
mmp: don't use O_RDWR in ext2fs_mmp_read

It doesn't seem to be necessary since ext2fs_mmp_write doesn't write
via mmp_fd, and opening the block device with O_RDWR will trigger
udev.

Triggering udev is bad because it leads to an infinite loop when
running dumpe2fs in response to a udev event.

[ Rebased onto the maint branch, and added O_RDONLY flag.  From the
  open(2) man page: "The argument flags must include one of the
  following access modes: O_RDONLY, O_WRONLY, or O_RDWR." -- TYT ]

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoUpdate shared library flags used for Apple/Darwin
Theodore Ts'o [Thu, 18 Aug 2022 21:24:17 +0000 (17:24 -0400)]
Update shared library flags used for Apple/Darwin

As submitted by Carlos Cabrera:

    We need to set the `-install_name` flag so that library consumers
    can find the linked libraries when installed outside the default
    dyld search path. This is the case, for example, when installed
    using the Homebrew package manager on Apple Silicon.

    I've removed the `-flat_namespace` flag because this flag is
    effectively deprecated, and can cause issues when using `dlopen`
    [1]. We also need to change `-undefined warning` to `-undefined
    dynamic_lookup`, since the former flag is not supported without
    `-flat_namespace`. Using `-undefined dynamic_lookup` instructs the
    dynamic loader to resolve undefined symbols at run/load-time.

    These are the flags used by Libtool on the newest versions of
    macOS, and we've applied similar patches to many other packages at
    Homebrew without any issues.

    [1] https://developer.apple.com/forums/thread/689991

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoe2image: checking the retval for the last update_refcount() is unnecessary
Theodore Ts'o [Sun, 14 Aug 2022 03:46:06 +0000 (23:46 -0400)]
e2image: checking the retval for the last update_refcount() is unnecessary

Addresses-Coverity-Bug: 709478
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agolibext2fs: return an error when byte swapping a corrupted dirblock block
Theodore Ts'o [Sun, 14 Aug 2022 03:32:42 +0000 (23:32 -0400)]
libext2fs: return an error when byte swapping a corrupted dirblock block

Except for e2fsck (where we want to expose the corrupted directory
entries to e2fsck mostly so that the e2fsck output stays the same on
big-endian machines compared to little-endian machines, so we don't
break our regression tests), if the directory block is corrupted, and
ext2fs_dirent_swab_in[2](), trips across this, return an error.  This
will make sure that naive users of libextfs will not try to handle a
corrupted directory block.  This prevents potential buffer overruns in
the byte swapping code paths.

This commit does not cause any functional change on little-endian
systems.

Addresses-Coverity-Bug: 1433408
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoe2fsck: remove unneeded automatic variable program_name
Theodore Ts'o [Sun, 14 Aug 2022 02:35:03 +0000 (22:35 -0400)]
e2fsck: remove unneeded automatic variable program_name

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agolibext2fs: avoid looping forever in e2image when superblock is invalid
Theodore Ts'o [Sat, 13 Aug 2022 20:39:17 +0000 (16:39 -0400)]
libext2fs: avoid looping forever in e2image when superblock is invalid

If the number of blocks or inodes per block group is not a multiple of
8 (which are invalid values) ext2fs_image_bitmap{read,write} can loop
forever.  These file systems should be not be allowed to be opened
(without EXT2_FLAG_IGNORE_SB_ERRORS) but for the fact that a long time
ago, Android devices used a buggy (but BSD-licensed, which was what
was important to the early Android founders) program for creating file
systems which would create these invalid file systems.  E2fsck
couldn't actually correctly repair these file systems, but adding a
check to enforce this (in e2fsprogs and in the kernel) would have
broken some of these devices, so support for these bogus file system
was in a grey area for many years.

We will be tightening this up soon, but for now, we'll apply this
quick fix so attempts to use e2image won't hang forever.  (Not that
Android ever shipped e2image in those days, of course...)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoe2fsprogs: fix device name parsing to resolve names containing '='
Lukas Czerner [Fri, 12 Aug 2022 13:01:22 +0000 (15:01 +0200)]
e2fsprogs: fix device name parsing to resolve names containing '='

Currently in varisous e2fsprogs tools, most notably tune2fs and e2fsck
we will get the device name by passing the user provided string into
blkid_get_devname(). This library function however is primarily intended
for parsing "NAME=value" tokens. It will return the device matching the
specified token, NULL if nothing is found, or copy of the string if it's
not in "NAME=value" format.

However in case where we're passing in a file name that contains an
equal sign blkid_get_devname() will treat it as a token and will attempt
to find the device with the match. Likely finding nothing.

Fix it by checking existence of the file first and then attempt to call
blkid_get_devname(). In case of a collision, notify the user and
automatically prefer the one returned by blkid_get_devname(). Otherwise
return either the existing file, or NULL.

We do it this way to avoid some existing file in working directory (for
example LABEL=volume-name) masking an actual device containing the
matchin LABEL. User can specify full, or relative path (e.g.
./LABEL=volume-name) to make sure the file is used instead.

Link: https://lore.kernel.org/r/20220812130122.69468-1-lczerner@redhat.com
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reported-by: Daniel Ng <danielng@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoe2fsck: validate i_extra_size in ext4_fc_handle_inode
Theodore Ts'o [Fri, 12 Aug 2022 19:48:04 +0000 (15:48 -0400)]
e2fsck: validate i_extra_size in ext4_fc_handle_inode

Addresses-Coverity-Bug: 1500765
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agodebugfs: make blocksize be unsigned in logdump.c
Theodore Ts'o [Fri, 12 Aug 2022 19:15:14 +0000 (15:15 -0400)]
debugfs: make blocksize be unsigned in logdump.c

Blocksize can never be negative, and this makes the use of signed vs
unsigned variables for offsets be consistent.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoAvoid potential NULL dereference when argv[0]
Theodore Ts'o [Fri, 12 Aug 2022 03:45:21 +0000 (23:45 -0400)]
Avoid potential NULL dereference when argv[0]

Addresses-Coverity-Bug: 1500772
Addresses-Coverity-Bug: 1500769
Addresses-Coverity-Bug: 1500767
Addresses-Coverity-Bug: 1500758
Addresses-Coverity-Bug: 1500756
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoe2fsck: mark that we don't care about the return value of e2fsck_lookup()
Theodore Ts'o [Fri, 12 Aug 2022 03:14:33 +0000 (23:14 -0400)]
e2fsck: mark that we don't care about the return value of e2fsck_lookup()

We only print the parent directory to help provide context to the
user, but it's possible that a corrupted directory doesn't have a '..'
link.

Addresses-Coverity-Bug: 1507762
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoe2fsck: streamline problem latch handling
Theodore Ts'o [Fri, 12 Aug 2022 03:01:42 +0000 (23:01 -0400)]
e2fsck: streamline problem latch handling

No functional changes, but streamline the logic, and avoid a coverity
warning.

Addresses-Coverity-Bug: 1507763
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoe2fsck: when mutating file name make sure its length never exceeds 255
Theodore Ts'o [Fri, 12 Aug 2022 02:16:41 +0000 (22:16 -0400)]
e2fsck: when mutating file name make sure its length never exceeds 255

E2fsck will attempt to mutate filenames to ensure uniqueness if
necessary.  If there are two unique filenames that are 254 or 255
characters in length and do not contain the '~' character, the
mutate_name() function would create a filename which is 256 bytes
long, which is not a legal filename in Linux.  Adjust the mutate_name
function to avoid this possibility.

Addresses-Coverity-Bug: 1500768
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoFix Coverity unintentional integer overflow warnings
Theodore Ts'o [Fri, 12 Aug 2022 02:03:08 +0000 (22:03 -0400)]
Fix Coverity unintentional integer overflow warnings

Neither of these two warnings can actually happen (other limits will
be hit first), but widening the integer to a 64-bit unsigned integer
is an cheap and effective way to silence the Coverity warnings.

Addresses-Coverity-Bug: 1500760
Addresses-Coverity-Bug: 1507886
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 months agoresize2fs: use ext2fs_get_arrayzero() instead of ext2fs_get_array() + memset()
Theodore Ts'o [Thu, 11 Aug 2022 22:37:26 +0000 (18:37 -0400)]
resize2fs: use ext2fs_get_arrayzero() instead of ext2fs_get_array() + memset()

The use of ext2fs_get_arrayzero() to replace using ext2fs_get_array()
+ memset() does not result in any functional change, but it (a) is
slightly more efficient, and (b) makes it easier for Coverity to avoid
signalling a false positive.

Addresses-Coverity-Bug: 1500763
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agotune2fs: do not change j_tail_sequence in journal superblock
zhanchengbin [Thu, 4 Aug 2022 10:33:39 +0000 (18:33 +0800)]
tune2fs: do not change j_tail_sequence in journal superblock

The function recover_ext3_journal() in debugfs/journal.c, if the log
replay is over, the j_tail_sequence in journal superblock is not
changed to the value of the last transaction sequence.  This will
cause subsequent log commitids to count from the commitid in last
time.  After tune2fs -e, the log commitid is counted from the commitid
in last time, if the log ID of the current operation overlaps with
that of the last operation, this will cause logs that were previously
replayed by tune2fs to be replayed here.

Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: liangyun <liangyun2@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agodebugfs: allow <inode> for ncheck
Li Dongyang [Fri, 5 Aug 2022 21:52:21 +0000 (15:52 -0600)]
debugfs: allow <inode> for ncheck

If the ncheck argument is of the form "<ino>", allow it for ncheck
for consistency with other commands that accept an inode number.

Improve the error message, use "Invalid inode number" instead
of "Bad inode", which implies the inode content being bad.

Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agodebugfs: quiet debugfs 'catastrophic' message
Andreas Dilger [Fri, 5 Aug 2022 22:06:07 +0000 (16:06 -0600)]
debugfs: quiet debugfs 'catastrophic' message

When debugfs runs with "-c", it prints a scary-looking message:

    catastrophic mode - not reading inode or group bitmaps

that is often misunderstood by users to mean that there is something
wrong with the filesystem, when there is no problem at all.

Not reading the bitmaps is totally normal and expected behavior for
the "-c" option, which is used to significantly shorten the debugfs
command execution time by not reading metadata that isn't needed for
commands run against very large filesystems.

Since there is often confusion about what this message means, it
would be better to just avoid printing anything at all, since the
use of "-c" is expressly requesting this behavior, and there are
no messages printed out for other options.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Reviewed-by: Dongyang Li <dongyang@ddn.com>
Change-Id: I59b26a601780544ab995aa4ca7ab0c2123c70118
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agoresize2fs: open device read-only when -P is passed
Michael Hudson-Doyle [Thu, 26 May 2022 01:08:28 +0000 (13:08 +1200)]
resize2fs: open device read-only when -P is passed

We ran into this because we noticed that resize2fs -P $device was
triggering udev events.

I added a very simple test that just checks resize2fs -P on a file
lacking the w bit succeeds.

Signed-off-by: Michael Hudson-Doyle <michael.hudson@ubuntu.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agotests: fix ACL-printing tests
Andreas Dilger [Tue, 1 Mar 2022 04:17:06 +0000 (21:17 -0700)]
tests: fix ACL-printing tests

Fix the ACL-printing tests to be more flexible for different systems.
If the MKFS_DIR is on tmpfs, it will not list "system.posix_acl*"
xattrs, so they will not be copied.  Create this on a real filesystem
or skip the test if that doesn't work.

Filter out the security.selinux xattr if it is printed, since this
depends on the selinux configuration of the host system.  However,
this also spills xattrs for "acl_dir/file" into an external xattr
block, and causes it to fail due to different block allocations.
Increase the filesystem inode size so that the allocation is the same
regardless of whether selinux is enabled or not.

Fixes: 67e6ae0a35 ("mke2fs: fix a importing a directory with an ACL")
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Artem Blagodarenko <artem.blagodarenko@hpe.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agoe2fsck: always probe filesystem blocksize with simple io_manager
Gabriel Krisman Bertazi [Mon, 25 Apr 2022 22:01:00 +0000 (18:01 -0400)]
e2fsck: always probe filesystem blocksize with simple io_manager

Combining superblock (-b) with undo file (-z) fails iff the block size
is not specified (-B) and is different from the first blocksize probed
in try_open_fs (1k).  The reason is as follows:

try_open_fs() will probe different blocksizes if none is provided on
the command line. It is done by opening and closing the filesystem
until it finds a blocksize that makes sense. This is fine for all
io_managers, but undo_io creates the undo file with that blocksize
during ext2fs_open.  Once try_open_fs realizes it had the wrong
blocksize and retries with a different blocksize, undo_io will read
the previously created file and think it's corrupt for this
filesystem.

Ideally, undo_io would know this is a probe and would fix the undo file.
It is not simple, though, because it would require undo_io to know the
file was just created by the probe code, since an undo file survives
through different fsck sessions.  We'd have to pass this information
around somehow.  This seems like a complex change to solve a corner
case.

Instead, this patch changes the blocksize probe to always use the
unix_io_manager. This way, we safely probe for the blocksize without
side effects.  Once the blocksize is known, we can safely reopen the
filesystem under the proper io_manager.

An easily reproducer for this issue (from Ted, adapted by me) is:

 mke2fs -b 4k -q -t ext4 /tmp/foo.img 2G
 e2fsck -b 32768 -z /tmp/undo /tmp/foo.img

Reported-by: Peter Urbanec <linux-ext4.vger.kernel.org@urbanec.net>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agoQuiet unused variable warnings
Andreas Dilger [Thu, 4 Aug 2022 17:18:32 +0000 (11:18 -0600)]
Quiet unused variable warnings

Quiet various compiler warnings about unreferenced or unset variables.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agoresize2fs: trim resize to cluster boundary
Kiselev, Oleg [Sat, 14 May 2022 04:17:09 +0000 (04:17 +0000)]
resize2fs: trim resize to cluster boundary

This patch rounds down the size provided to resize2fs to the nearest
cluster boundary for bigalloc filesystems.  This is similar to the
trimming already done for page boundary alignment.  Aligning the size in
the user space provides the right value feedback from the resize2fs
command, which is a better user experience than trimming the size
in the kernel.

Signed-off-by: Oleg Kiselev <okiselev@amazon.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agoe2fsck: handle invalid percent expansions in the log filename
Theodore Ts'o [Thu, 11 Aug 2022 02:48:13 +0000 (22:48 -0400)]
e2fsck: handle invalid percent expansions in the log filename

Add a missing default: case when expanding percent expansions in the
log file specified in /etc/e2fsck.conf.

Addresses-Coverity-Bug: 1500757
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agolibext2fs: validate block # of the inode table in ext2fs_image_inode_write()
Theodore Ts'o [Thu, 11 Aug 2022 02:43:00 +0000 (22:43 -0400)]
libext2fs: validate block # of the inode table in ext2fs_image_inode_write()

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agoBuild the fuzzers from oss-fuzz
Theodore Ts'o [Sat, 6 Aug 2022 22:35:30 +0000 (18:35 -0400)]
Build the fuzzers from oss-fuzz

The fuzzers from oss-fuzz in projects/e2fsprogs/fuzz (as of commit
78ecd3f07fca with some slight modifications for better error
reporting) have been placed in the tests/fuzz directory and the
configure script now supports a new option --enable-fuzzing which will
build these fuzzers using clang's -fsanitize=fuzzer command line
option.

In general, some sanitizer such as --enable-addrsan or --enable-ubsan
(to enable ASAN or UBSAN, respectively) should be enabled alongside
--enable-fuzzing.

A typical configure command to build the fuzzers might be:

  configure CC=clang CXX=clang++ CFLAGS=-g --enable-fuzzing --enable-addrsan

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agolibext2fs: fix potential integer overflow in bitmap accessors
Theodore Ts'o [Tue, 9 Aug 2022 15:16:47 +0000 (11:16 -0400)]
libext2fs: fix potential integer overflow in bitmap accessors

bmap->cluster_bits has a maximum value of 19, but Coverity doesn't
know that.  To make it happy, and just in case there is a bug where
somehow the cluster size does get set to an invalid value and the rest
of the library doesn't check it, use 1ULL instead of 1 to avoid the
integer overflow.

Addresses-Coverity-Bug: 1500759
Addresses-Coverity-Bug: 1500764
Addresses-Coverity-Bug: 1500771
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agoe2fsck: fix potential fencepost error in e2fsck_should_rebuild_extents()
Theodore Ts'o [Tue, 9 Aug 2022 14:52:57 +0000 (10:52 -0400)]
e2fsck: fix potential fencepost error in e2fsck_should_rebuild_extents()

The ext2_extent_info.max_depth is zero-based (e.g., it is zero when
the entire extent tree fits in the inode).  Hence, if it is equal to
MAX_EXTENT_DEPTH_COUNT we should always rebuild the extent tree to
shorten it.

Also, for 1k block file systems, it's possible for the worst-case
extent tree in its most compact form to have a maximum depth of 6, not
5.  So set MAX_EXTENT_DEPTH_COUNT to 8 just to be sure we have plenty
of headroom.  (The kernel supports an extent depth up to 2**16, but
e2fsck only keeps statistics up to MAX_EXTENT_DEPTH_COUNT, and if it's
deeper than that, we know that it will be profitable to rebuild the
extent tree in any case.)

Addresses-Coverity-Bug: 1507761
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agolibext2fs: make sure the bitmap locations are valid when writing bitmaps
Theodore Ts'o [Tue, 9 Aug 2022 01:02:51 +0000 (21:02 -0400)]
libext2fs: make sure the bitmap locations are valid when writing bitmaps

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agolibext2fs: reject various bitmap and inode operations for journal_dev file systems
Theodore Ts'o [Tue, 9 Aug 2022 00:52:43 +0000 (20:52 -0400)]
libext2fs: reject various bitmap and inode operations for journal_dev file systems

The ext2fs_open() function will only allow journal_dev file systems to
be open if explicitly requested by programs using the
EXT2_FLAG_JOURNAL_DEV_OK flag.  Those programs will not try to call
functions that make no sense, such as ext2fs_read_inode(),
ext2fs_read_bitmaps(), etc.  Just to make things the library more
robust against buggy programs (or unrealistic fuzzers) add a check for
journal_dev file systems to various ext2fs library functions to return
a new error, EXT2_ET_EXTERNAL_JOURNAL_NOSUPP.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agolibext2fs: in ext2fs_open[2](), return an error if s_desc_size is too large
Theodore Ts'o [Tue, 9 Aug 2022 00:17:40 +0000 (20:17 -0400)]
libext2fs: in ext2fs_open[2](), return an error if s_desc_size is too large

Previously, ext2fs_open() and ext2fs_open2() would return an error if
s_desc_size is too small.  Add a check so it will return an error if
s_desc_size is too large, as well.

These checks will be skipped for e2fsck when it uses the flag
EXT2_FLAG_IGNORE_SB_ERRORS.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
22 months agoUpdate configure/configure.ac/aclocal.m4 to use autoconf 2.71
Theodore Ts'o [Sat, 6 Aug 2022 18:58:40 +0000 (14:58 -0400)]
Update configure/configure.ac/aclocal.m4 to use autoconf 2.71

Signed-off-by: Theodore Ts'o <tytso@mit.edu>