e2fsprogs: Parallel fsck support
Re: [RFCv1 12/72] libext2fs: dupfs: Add fs clone & merge api
In reply to Andreas DilgerQuoted 66 lines · Andreas Dilger
Quoted 51 lines · Ritesh Harjani (IBM)
From: Saranya Muruganandam <[email protected]>
This patch mainly adds "parent" & "
clone_flags" member inext2_filsysstruct for enabling multi-threading. Based on what CLONE flags will be passed from the client of libext2fs down toext2fs_clone_fs(), those structures/bitmaps will be cloned (thread-aware child copy) and rest will be shared with the parent fs.The same flags will also help to merge those cloned bitmap structures back into the parent bitmaps when
ext2fs_merge_fs()will be called with childfs struct.Signed-off-by Saranya Muruganandam <[email protected]>Signed-off-by Ritesh Harjani (IBM) <[email protected]>---
lib/ext2fs/dupfs.c| 183 ++++++++++++++++++++++++++++++++++++++++++++lib/ext2fs/ext2fs.h| 23 ++++++2 files changed, 206 insertions(+)lib/ext2fs/dupfs.c +16
-0@@ -14,8 +14,12 @@#if HAVE_UNISTD_H #include <unistd.h> #endif +#if HAVE_PTHREAD_H +#include <pthread.h> +#endif #include <time.h> #include <string.h> +#include <assert.h> #include "ext2_fs.h" #include "ext2fsP.h" @@ -120,3 +124,182 @@ errout: } +#ifdef HAVE_PTHREAD +errcode_t ext2fs_clone_fs (ext2_filsys fs,ext2_filsys *dest,unsigned int flags) +{ +errcode_t retval; +ext2_filsys childfs; + +EXT2_CHECK_MAGIC (fs,EXT2_ET_MAGIC_EXT2FS_FILSYS ); + + retval =ext2fs_get_mem (sizeof (struct struct_ext2_filsys ), &childfs); +if (retval) +return retval; +lib/ext2fs/dupfs.c errout: · line 148
Quoted 10 lines
lib/ext2fs/dupfs.c +10
-0+/* make an exact copy implying lists and memory structures are shared */ +memcpy (childfs, fs,sizeof (struct struct_ext2_filsys )); + childfs->inode_map =NULL ; + childfs->block_map =NULL ; + childfs->badblocks =NULL ; + childfs->dblist =NULL ; + +pthread_mutex_lock (&fs->refcount_mutex); + fs->refcount++; +pthread_mutex_unlock (&fs->refcount_mutex);The locking her doesn't make sense. Why is the mutex only protecting the "refcount", and not the rest of the fields in fs?
Quoted 4 lines
It would make more sense to hold the mutex over the whole copy process, from up before the
memcpy(), until down after the last structure is cloned. Otherwise, once fs has been cloned once and given to another thread it would be possible for them to change these structures.
Ok, so there are two things here. Let's first discuss it from the e2fsck perspective. ext2fs_clone_fs() is called in the thread prepare for each thread sequentially. Also what we are really trying to do here is copy the ext2_filsys source fs and then all threads will work on their cloned "childfs".
So we don't require any locking, because even when threads will start running, they will only modify their childfs.
Now.. let's see it from the libext2fs API perspective. So will there be any need for locking for any other client which might use ext2fs_clone_fs()? Because the general pthread programming would be like :
start():
for (t = 0; t < num_threads; t++) {
clone_contexts() -> ext2fs_clone_fs()
pthread_run()
<..>
}finish():
for (t = 0; t < num_threads; t++) {
pthread_join()
merge_contexts() -> ext2fs_merge_fs()
}So why we don't require any locking here, right? Unless ofcourse start() phase can also be called in parallel. But that won't be true no.
Quoted 24 lines
Quoted 24 lines
lib/ext2fs/dupfs.c +23
-0+if ((flags &EXT2FS_CLONE_INODE ) && fs->inode_map) { + retval =ext2fs_copy_bitmap (fs->inode_map, &childfs->inode_map); +if (retval) +return retval; + childfs->inode_map->fs = childfs; + } + +if ((flags &EXT2FS_CLONE_BLOCK ) && fs->block_map) { + retval =ext2fs_copy_bitmap (fs->block_map, &childfs->block_map); +if (retval) +return retval; + childfs->block_map->fs = childfs; + } + +if ((flags &EXT2FS_CLONE_BADBLOCKS ) && fs->badblocks) { + retval =ext2fs_badblocks_copy (fs->badblocks, &childfs->badblocks); +if (retval) +return retval; + } + +if ((flags &EXT2FS_CLONE_DBLIST ) && fs->dblist) { + retval =ext2fs_copy_dblist (fs->dblist, &childfs->dblist); +if (retval)
Quoted 8 lines
lib/ext2fs/dupfs.c errout: · line 178
Quoted 6 lines
lib/ext2fs/dupfs.c +6
-0+return retval; + childfs->dblist->fs = childfs; + } + +/* icache when NULL will be rebuilt if needed */ + childfs->icache =NULL ;This should be up where the other NULL values are set.
ok.
Quoted 24 lines
Quoted 24 lines
lib/ext2fs/dupfs.c +23
-0+ + childfs->clone_flags = flags; + childfs->parent = fs; + *dest = childfs; + +return 0 ; +} + +errcode_t ext2fs_merge_fs (ext2_filsys *thread_fs) +{ +ext2_filsys fs = *thread_fs; +errcode_t retval =0 ; +ext2_filsys dest = fs->parent; +ext2_filsys src = fs; +unsigned int flags = fs->clone_flags; +struct ext2_inode_cache *icache; +io_channel dest_io; +io_channel dest_image_io; +ext2fs_inode_bitmap inode_map; +ext2fs_block_bitmap block_map; +ext2_badblocks_list badblocks; +ext2_dblist dblist; +void *priv_data;
Quoted 8 lines
lib/ext2fs/dupfs.c errout: · line 207
Quoted 6 lines
lib/ext2fs/dupfs.c +6
-0+int fsflags; + +pthread_mutex_lock (&fs->refcount_mutex); + fs->refcount--; +assert (fs->refcount >=0 ); +pthread_mutex_unlock (&fs->refcount_mutex);Same here. The mutex should be held over the whole copy process.
Again same discussion as above. We don't need to have a lock here, because the ext2fs_merge_fs() will happen post pthread_join() for each thread.
-ritesh
Quoted 152 lines
Cheers, Andreas
Quoted 148 lines
lib/ext2fs/dupfs.c +97
-0+ icache = dest->icache; + dest_io = dest->io; + dest_image_io = dest->image_io; + inode_map = dest->inode_map; + block_map = dest->block_map; + badblocks = dest->badblocks; + dblist = dest->dblist; + priv_data = dest->priv_data; + fsflags = dest->flags; + +memcpy (dest, src,sizeof (struct struct_ext2_filsys )); + + dest->io = dest_io; + dest->image_io = dest_image_io; + dest->icache = icache; + dest->inode_map = inode_map; + dest->block_map = block_map; + dest->badblocks = badblocks; + dest->dblist = dblist; + dest->priv_data = priv_data; +if (dest->dblist) + dest->dblist->fs = dest; + dest->flags = src->flags | fsflags; +if (!(src->flags &EXT2_FLAG_VALID ) || !(dest->flags &EXT2_FLAG_VALID )) +ext2fs_unmark_valid (dest); + +if ((flags &EXT2FS_CLONE_INODE ) && src->inode_map) { +if (dest->inode_map ==NULL ) { + dest->inode_map = src->inode_map; + src->inode_map =NULL ; + }else { + retval =ext2fs_merge_bitmap (src->inode_map, dest->inode_map,NULL ,NULL ); +if (retval) + goto out; + } + dest->inode_map->fs = dest; + } + +if ((flags &EXT2FS_CLONE_BLOCK ) && src->block_map) { +if (dest->block_map ==NULL ) { + dest->block_map = src->block_map; + src->block_map =NULL ; + }else { + retval =ext2fs_merge_bitmap (src->block_map, dest->block_map,NULL ,NULL ); +if (retval) + goto out; + } + dest->block_map->fs = dest; + } + +if ((flags &EXT2FS_CLONE_BADBLOCKS ) && src->badblocks) { +if (dest->badblocks ==NULL ) + retval =ext2fs_badblocks_copy (src->badblocks, &dest->badblocks); +else + retval =ext2fs_badblocks_merge (src->badblocks, dest->badblocks); +if (retval) + goto out; + } + +if ((flags &EXT2FS_CLONE_DBLIST ) && src->dblist) { +if (dest->dblist ==NULL ) { + dest->dblist = src->dblist; + src->dblist =NULL ; + }else { + retval =ext2fs_merge_dblist (src->dblist, dest->dblist); +if (retval) + goto out; + } + dest->dblist->fs = dest; + } + +if (src->icache) { +ext2fs_free_inode_cache (src->icache); + src->icache =NULL ; + } + +out: +if (src->io) +io_channel_close (src->io); + +if ((flags &EXT2FS_CLONE_INODE ) && src->inode_map) +ext2fs_free_generic_bmap (src->inode_map); +if ((flags &EXT2FS_CLONE_BLOCK ) && src->block_map) +ext2fs_free_generic_bmap (src->block_map); +if ((flags &EXT2FS_CLONE_BADBLOCKS ) && src->badblocks) +ext2fs_badblocks_list_free (src->badblocks); +if ((flags &EXT2FS_CLONE_DBLIST ) && src->dblist) { +ext2fs_free_dblist (src->dblist); + src->dblist =NULL ; + } + +ext2fs_free_mem (&src); + *thread_fs =NULL ; + + return retval; +} +#endif lib/ext2fs/ext2fs.h +23
-0@@ -12,6 +12,10 @@#ifndef _EXT2FS_EXT2FS_H#define _EXT2FS_EXT2FS_H +#ifdef HAVE_PTHREAD_H +#include <pthread.h> +#endif +#ifdef __GNUC__#define EXT2FS_ATTR (x) __attribute__(x)#else @@ -331,6 +335,13 @@ struct struct_ext2_filsys {struct ext2fs_hashmap * block_sha_map;const struct ext2fs_nls_table *encoding; + +#ifdef HAVE_PTHREAD +struct struct_ext2_filsys *parent; +size_t refcount; +pthread_mutex_t refcount_mutex; +unsigned int clone_flags; +#endif };#if EXT2_FLAT_INCLUDES @@ -1057,6 +1068,18 @@ extern errcode_t ext2fs_move_blocks(ext2_filsys fs,/* check_desc.c */ extern errcode_t ext2fs_check_desc (ext2_filsys fs); +#ifdef HAVE_PTHREAD +/* flags for ext2fs_clone_fs */ +#define EXT2FS_CLONE_BLOCK 0x0001 +#define EXT2FS_CLONE_INODE 0x0002 +#define EXT2FS_CLONE_BADBLOCKS 0x0004 +#define EXT2FS_CLONE_DBLIST 0x0008 + +extern errcode_t ext2fs_clone_fs (ext2_filsys fs,ext2_filsys *dest, +unsigned int flags); +extern errcode_t ext2fs_merge_fs (ext2_filsys *fs); +#endif +/* closefs.c */ extern errcode_t ext2fs_close (ext2_filsys fs);extern errcode_t ext2fs_close2 (ext2_filsys fs,int flags);Signature · 1 line
2.37.3
Quoted 39 lines · Andreas Dilger
On Nov 7, 2022, at 06:22, Ritesh Harjani (IBM) <[email protected]> wrote:
Hello,
This is a RFC patch series which has the list of all pfsck related changes which should also address the problem statements mentioned by Ted and Harshad here [1]
Below points will provide more details on how this patch series is laid out:-
1. This series is rebased on the latest e2fsprogs master branch.
2. Patch series is broken down into logical patches for easier review. The series contains libext2fs changes first, followed by e2fsck changes which utilizes libext2fs apis to add pfsck support to pass1.
3. Changes [0005] to [0012] addresses the problem statement laid out by Ted and Harshad [1] i.e. we now have a libext2fs API for clone and merge of
ext2_filsysstruct. (ext2fs_clone_fs()&ext2fs_merge_fs())4. These two changes [0016] & [0026] uses above clone/merge api for test and for use in e2fsck.
5. For a lot of libext2fs changes (for e.g. bitmap merging logic or clone/merge apis), there are some unit tests added for it's functionality verification.
Performance results:
=====================
1. On nvme with 22M 0-byte inodes: 7sec v/s 19sec
2. On nvme with 22M 4KB-32KB inodes: 17sec v/s 30sec
3. On nvme with 11M 32KB inodes: 9sec v/s 15sec
4. On RAID HDD setups: (will get back with perf results for this. Although, I had shared some numbers earlier, but I wanted to run pfsck with different FS layout and collect the numbers once again)
Quoted 2 lines
Ritesh,
Thanks for your work to update this patch series. I've been meaning to look at it, but
Thanks Andreas, I see you have already started reviewing. This is super helpful :)
Quoted 4 lines
have been traveling the past couple of weeks.
Have you done any performance comparisons against the original pfsck patch series?
Yes, I did, for the existing tests that I just mentioned above and found the perf numbers to be
similar. I am also planning to take a RAID device setup from an internal team and collect
some performance numbers there.
Quoted 5 lines
I did make a patch against our original series to improve the workload balance between threads, so that they are assigned a roughly equal number of inodes, instead of an equal number of block groups, since my testing showed the processing time of the threads
was proportional to the inode count. This avoids uneven thread completion and reduces overall processing time.
Yes, based on my testing so far. I too agree that to improve the workload balance one should assign an equal
number of inodes to different threads.
Quoted 5 lines
That patch is available in our Gerrit, and I can push it once this series lands, or it could be merged into the original patch that adds the
e2fsck_pass1_thread_prepare()code.
Sure, I will keep a note of this patch too in my performance runs.
So, now given the number of patches are quite large, I am hoping that we could review all libext2fs changes
for getting it in shape for merge. Then while we are at e2fsck change, we can definitely look at the above patch
too.
Thanks again!!
-ritesh
Quoted 224 lines
Cheers, Andreas.
For review: Since these are large number of changes. So if the overall series looks good, then we can start reviewing changes in batches. For e.g. if we could review initial changes in libext2fs (from [001] - [0020]), that would be a good start.
Patch-0073 adds support to all tests/* with "-m 2" mode to test pfsck as well. If pthread support is present, make check then test with "-m 2" fsck mode option as well (for tests which utilizes
run_e2fsckscript).
This was mainly done for verifying that all existing tests passes with pfsck. In this only few tests are kept disabled by passing SKIP_MT=true (Note: Last min. I have decided to drop this patch from sending. Although this can still be found in the github branch [2] for any testing)On Threadsan: I had tested this patch series against threadsan as well. It does lists few race conditions when running multi-threading (these doesn't looks to be any major problem). I have fixed a few [0070] and rest might either need some minor fixing or marking it false positive.
Here is the github link with all these commits (pfsck-RFCv1 branch) [2].
[1]: https://lore.kernel.org/linux-ext4/YMN10sXgoTR%[email protected]/
[2]: https://github.com/riteshharjani/e2fsprogs/commits/pfsck-RFCv1Andreas Dilger (2):
libext2fs: Misc fixes forstruct_ext2_filsys
e2fsck: misc cleanups for pfsckLi Xi (16):
dblist: add dblist merge logic
libext2fs: Add flush cleanup API
libext2fs: merge icounts after thread finishes
e2fsck: add -m option for multithread
e2fsck: copy context when using multi-thread fsck
e2fsck: create logs for multi-threads
e2fsck: configure one pfsck thread
e2fsck: Add asserts inopen_channel_fs
e2fsck: add start/end group for thread
e2fsck: split groups to different threads
e2fsck: print thread log properly
e2fsck: do not change global variables
e2fsck: optimize the inserting ofdir_info_db
e2fsck: mergedir_infoafter thread finishes
e2fsck: merge icounts after thread finishes
e2fsck: add debug codes for multiple threadsRitesh Harjani (IBM) (15):
e2fsck: Fix unbalanced mutex unlock forBOUNCE_MTX
gen_bitmaps: Fix ext2fs_compare_generic_bmap/bitmap logic
blkmap64_ba: Add common helper for bits size calculation
badblocks: Remove unusedbadblocks_flags
tst_badblocks: Add unit test to verify badblocks list merge api
tst_bitmaps_standalone: Add copy and merge bitmaps test
tst_bitmaps_pthread: Add merge bitmaps test using pthreads
tst_libext2fs_pthread: Add libext2fs merge/clone unit tests
e2fsck: Adde2fsck_pass1_thread_joinreturn value
e2fsck: Use merge/clone apis of libext2fs
e2fsck: Fixio->alignassert check
e2fsck: Fix double free ofinodes_to_process
e2fsck: Fix and simplifyupdate_mmpin case of pfsck
e2fsck: Make threads calllog_outafterpthread_jointests/f_multithread: Fixf_multithreadrelated testsSaranya Muruganandam (3):
libext2fs: dupfs: Add fs clone & merge api
e2fsck: propagate number of threads
e2fsck: Annotating fields ine2fsck_structSebastien Buisson (1):
sec: support encrypted files handling in pfsck modeWang Shilong (35):
badblocks: Add badblocks merge logic
libext2fs: Add rbtree bitmap merge logic
libext2fs: Add bitmaps merge ops
libext2fs: merge quota context after threads finish
libext2fs: Add support forext2fs_test_block_bitmap_range2_valid()
libext2fs: Add support to get average group count
libext2fs: avoid too much memory allocation in casefs_num_threads
e2fsck: Adde2fsck_pass1_merge_bitmap()api
e2fsck: rbtree bitmap for dir
e2fsck: merge counts after threads finish
e2fsck: mergedx_dir_infoafter threads finish
e2fsck: mergedirs_to_hashwhen threads finish
e2fsck: merge context flags properly
e2fsck: merge quota context after threads finish
e2fsck: serialize fix operations
e2fsck: move some fixes out of parallel pthreads
e2fsck: split and merge invalid bitmaps
e2fsck: merge EA blocks properly
e2fsck: kickoff mutex lock for block found map
e2fsck: allow admin specify number of threads
e2fsck: adjust number of threads
e2fsck: fix readahead for pfsck of pass1
e2fsck: merge options after threads finish
e2fsck: resetlost_and_foundafter threads finish
e2fsck: merge extent depth count after threads finish
e2fsck: simplify e2fsck context merging codes
e2fsck: setE2F_FLAG_ALLOC_OKafter threads
e2fsck: wait fix thread finish before checking
e2fsck: cleanupe2fsck_pass1_thread_join()
e2fsck: make default smallest RA size to 1M
e2fsck: update mmp block in one thread
e2fsck: reset @inodes_to_rebuild if restart
tests: add pfsck test
e2fsck: fix memory leaks with pfsck enabled
e2fsck: merge casefolded dir lists after thread finishe2fsck/dirinfo.c | 238 ++- e2fsck/dx_dirinfo.c | 64 + e2fsck/e2fsck.8.in | 8 +- e2fsck/e2fsck.c | 11 + e2fsck/e2fsck.h | 103 +- e2fsck/encrypted_files.c | 139 ++ e2fsck/logfile.c | 13 +- e2fsck/pass1.c | 1894 +++++++++++++++++++---- e2fsck/problem.c | 11 + e2fsck/problem.h | 3 + e2fsck/readahead.c | 4 + e2fsck/unix.c | 58 +- e2fsck/util.c | 193 ++- lib/ext2fs/Makefile.in | 53 +- lib/ext2fs/badblocks.c | 81 +- lib/ext2fs/bitmaps.c | 10 + lib/ext2fs/bitops.h | 2 + lib/ext2fs/blkmap64_ba.c | 20 +- lib/ext2fs/blkmap64_rb.c | 65 + lib/ext2fs/bmap64.h | 4 + lib/ext2fs/dblist.c | 38 + lib/ext2fs/dupfs.c | 183 +++ lib/ext2fs/ext2_err.et.in | 3 + lib/ext2fs/ext2_io.h | 2 + lib/ext2fs/ext2fs.h | 66 +- lib/ext2fs/ext2fsP.h | 1 - lib/ext2fs/gen_bitmap.c | 9 +- lib/ext2fs/gen_bitmap64.c | 72 +- lib/ext2fs/icount.c | 107 ++ lib/ext2fs/tst_badblocks.c | 61 +- lib/ext2fs/tst_bitmaps_pthread.c | 247 +++ lib/ext2fs/tst_bitmaps_standalone.c | 170 ++ lib/ext2fs/tst_libext2fs_pthread.c | 315 ++++ lib/ext2fs/undo_io.c | 19 + lib/ext2fs/unix_io.c | 25 +- lib/support/mkquota.c | 39 + lib/support/quotaio.h | 3 + tests/f_itable_collision/expect.1 | 3 - tests/f_multithread/expect.1 | 25 + tests/f_multithread/expect.2 | 7 + tests/f_multithread/image.gz | 1 + tests/f_multithread/name | 1 + tests/f_multithread/script | 4 + tests/f_multithread_completion/expect.1 | 2 + tests/f_multithread_completion/expect.2 | 23 + tests/f_multithread_completion/image.gz | 1 + tests/f_multithread_completion/name | 1 + tests/f_multithread_completion/script | 4 + tests/f_multithread_logfile/expect.1 | 25 + tests/f_multithread_logfile/image.gz | 1 + tests/f_multithread_logfile/name | 1 + tests/f_multithread_logfile/script | 32 + tests/f_multithread_no/expect.1 | 26 + tests/f_multithread_no/expect.2 | 23 + tests/f_multithread_no/image.gz | 1 + tests/f_multithread_no/name | 1 + tests/f_multithread_no/script | 4 + tests/f_multithread_ok/expect.1 | 15 + tests/f_multithread_ok/image.gz | Bin 0 -> 796311 bytes tests/f_multithread_ok/name | 1 + tests/f_multithread_ok/script | 4 + tests/f_multithread_preen/expect.1 | 11 + tests/f_multithread_preen/expect.2 | 23 + tests/f_multithread_preen/image.gz | 1 + tests/f_multithread_preen/name | 1 + tests/f_multithread_preen/script | 4 + tests/f_multithread_yes/expect.1 | 2 + tests/f_multithread_yes/expect.2 | 23 + tests/f_multithread_yes/image.gz | 1 + tests/f_multithread_yes/name | 1 + tests/f_multithread_yes/script | 4 + tests/test_one.in | 8 + 72 files changed, 4186 insertions(+), 433 deletions(-)create mode 100644
lib/ext2fs/tst_bitmaps_pthread.ccreate mode 100644lib/ext2fs/tst_bitmaps_standalone.ccreate mode 100644lib/ext2fs/tst_libext2fs_pthread.ccreate mode 100644 tests/f_multithread/expect.1 create mode 100644 tests/f_multithread/expect.2 create mode 120000 tests/f_multithread/image.gz create mode 100644 tests/f_multithread/name create mode 100644 tests/f_multithread/script create mode 100644 tests/f_multithread_completion/expect.1 create mode 100644 tests/f_multithread_completion/expect.2 create mode 120000 tests/f_multithread_completion/image.gz create mode 100644 tests/f_multithread_completion/name create mode 100644 tests/f_multithread_completion/script create mode 100644 tests/f_multithread_logfile/expect.1 create mode 120000 tests/f_multithread_logfile/image.gz create mode 100644 tests/f_multithread_logfile/name create mode 100644 tests/f_multithread_logfile/script create mode 100644 tests/f_multithread_no/expect.1 create mode 100644 tests/f_multithread_no/expect.2 create mode 120000 tests/f_multithread_no/image.gz create mode 100644 tests/f_multithread_no/name create mode 100644 tests/f_multithread_no/script create mode 100644 tests/f_multithread_ok/expect.1 create mode 100644 tests/f_multithread_ok/image.gz create mode 100644 tests/f_multithread_ok/name create mode 100644 tests/f_multithread_ok/script create mode 100644 tests/f_multithread_preen/expect.1 create mode 100644 tests/f_multithread_preen/expect.2 create mode 120000 tests/f_multithread_preen/image.gz create mode 100644 tests/f_multithread_preen/name create mode 100644 tests/f_multithread_preen/script create mode 100644 tests/f_multithread_yes/expect.1 create mode 100644 tests/f_multithread_yes/expect.2 create mode 120000 tests/f_multithread_yes/image.gz create mode 100644 tests/f_multithread_yes/name create mode 100644 tests/f_multithread_yes/script--
2.37.3
Re: [RFCv1 02/72] gen_bitmaps: Fix ext2fs_compare_generic_bmap/bitmap logic
In reply to Ritesh Harjani (IBM)lib/ext2fs/gen_bitmap.c errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
Quoted 17 lines · Ritesh Harjani (IBM)
Currently this function was not correctly comparing against the right length of the bitmap. Also when we compare bitarray v/s rbtree bitmap the value returned by
ext2fs_test_generic_bmap()could be different in these two implementations. Hence only check against boolean value.Signed-off-by Ritesh Harjani (IBM) <[email protected]>---
lib/ext2fs/gen_bitmap.c| 9 ++++++---lib/ext2fs/gen_bitmap64.c| 10 +++++++---2 files changed, 13 insertions(+), 6 deletions(-)lib/ext2fs/gen_bitmap.c +0
-0@@ -385,10 +385,13 @@ errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
if ((bm1->start != bm2->start) ||
(bm1->end != bm2->end) ||
(memcmp(bm1->bitmap, bm2->bitmap,lib/ext2fs/gen_bitmap.c errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq, · line 388
Quoted 4 lines
lib/ext2fs/gen_bitmap.c +0
-1(size_t) (bm1->end - bm1->start)/8)))return neq; -for (i = bm1->end - ((bm1->end - bm1->start) %8 ); i <= bm1->end; i++)
On first review it appears that this is only comparing at most the last 7 bits before "end", which appears to be wrong. However, if you include the context earlier in the function (which I've added above), it is using memcmp() to compare the majority of the bitmaps in byte-wise order, so this is only needs to compare the remaining bits, and doing the full bitwise scan is much less efficient.
I was going to say that the "start" value needs to be added to the bitmap offset for the comparison, but I don't think that is correct either. Looking at the code (and thinking about it some more), it doesn't make sense to allocate space for bits before "start", so this must be a virtual offset, and the *actual* bits are always starting at "bitmap", so the above code is correct, AFAICS.
In summary, I don't think this patch will introduce a visible defect, but it makes the comparisons orders of magnitude less efficient when comparing each bit individually instead of using memcmp() that is likely hardware accelerated.
It may well be that the calling convention of this code is such that it is always called with end=byte-aligned value so this code is never used, but that doesn't mean it shouldn't be coded properly, in case that isn't true in the future.
lib/ext2fs/gen_bitmap.c errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq, · line 391
Quoted 6 lines
lib/ext2fs/gen_bitmap.c +4
-2-if (ext2fs_fast_test_block_bitmap (gen_bm1, i) != -ext2fs_fast_test_block_bitmap (gen_bm2, i)) +for (i = bm1->start; i <= bm1->end; i++) { +int ret1, ret2; + ret1 = !!ext2fs_fast_test_block_bitmap (gen_bm1, i); + ret2 = !!ext2fs_fast_test_block_bitmap (gen_bm2, i);
Strictly speaking, the !! here is not needed, and ! is enough for comparing the inequality of the two values. However, this is only used for 0-7 bits and isn't performance critical since the memcmp() does the heavy lifting.
lib/ext2fs/gen_bitmap64.c errcode_t ext2fs_compare_generic_bmap(errcode_t neq, · line 629
Quoted 12 lines
lib/ext2fs/gen_bitmap.c +2
-0+if (ret1 != ret2)return neq; + }return 0 ; }lib/ext2fs/gen_bitmap64.c +0
-0@@ -629,10 +629,14 @@ errcode_t ext2fs_compare_generic_bmap(errcode_t neq, (bm1->end != bm2->end))
Conversely, *this* version of the function is *not* doing the memcmp() of the bulk of the bitmap contents, so it would appear to have a bug that the patch fixes, but in a very slow manner. It would be better to use memcmp().
lib/ext2fs/gen_bitmap64.c errcode_t ext2fs_compare_generic_bmap(errcode_t neq, · line 635
Quoted 9 lines
lib/ext2fs/gen_bitmap64.c +4
-3return neq; -for (i = bm1->end - ((bm1->end - bm1->start) %8 ); i <= bm1->end; i++) -if (ext2fs_test_generic_bmap (gen_bm1, i) != -ext2fs_test_generic_bmap (gen_bm2, i)) +for (i = bm1->start; i < bm1->end; i++) { +int ret1, ret2; + ret1 = !!ext2fs_test_generic_bmap (gen_bm1, i); + ret2 = !!ext2fs_test_generic_bmap (gen_bm2, i);
Cheers, Andreas
Re: [RFCv1 13/72] tst_badblocks: Add unit test to verify badblocks list merge api
In reply to Ritesh Harjani (IBM)Quoted 5 lines · Ritesh Harjani (IBM)
Add unit test to verify badblocks list merge api i.e.
ext2fs_badblocks_merge()Signed-off-by Ritesh Harjani (IBM) <[email protected]>
Quoted 103 lines
---
lib/ext2fs/tst_badblocks.c| 61 ++++++++++++++++++++++++++++++++++++--1 file changed, 59 insertions(+), 2 deletions(-)lib/ext2fs/tst_badblocks.c +59
-3@@ -119,6 +119,40 @@ static void print_list(badblocks_list bb, int verify) } } +static void do_list_merge_verify (badblocks_list bb,badblocks_list bbm,int verify) +{ +errcode_t retval; +badblocks_iterate iter; +blk_t blk; +int i, ok; + + retval =ext2fs_badblocks_merge (bb, bbm); +if (retval) { +com_err ("do_list_merge_verify" , retval,"while doing list merge" ); +return ; + } + +if (!verify) +return ; + + retval =ext2fs_badblocks_list_iterate_begin (bb, &iter); +if (retval) { +com_err ("do_list_merge_verify" , retval,"while setting up iterator" ); +return ; + } + +while (ext2fs_badblocks_list_iterate (iter, &blk)) { + retval =ext2fs_badblocks_list_test (bbm, blk); +if (retval ==0 ) { +printf (" --- NOT OK\n" ); + test_fail++; +return ; + } + } +ext2fs_badblocks_list_iterate_end (iter); +printf (" --- OK\n" ); +} +static void validate_test_seq (badblocks_list bb,blk_t *vec) {int i, match, ok;@@ -275,13 +309,13 @@ out:int main (int argc,char **argv) { -badblocks_list bb1, bb2, bb3, bb4, bb5; +badblocks_list bb1, bb2, bb3, bb4, bb5, bbm;int equal;errcode_t retval;add_error_table (&et_ext2_error_table); - bb1 = bb2 = bb3 = bb4 = bb5 =0 ; + bb1 = bb2 = bb3 = bb4 = bb5 = bbm =0 ;printf ("test1: " ); retval =create_test_list (test1, &bb1);@@ -346,6 +380,27 @@ int main(int argc, char **argv)printf ("\n" ); } +printf ("Create merge bb list\n" ); + retval =ext2fs_badblocks_list_create (&bbm,5 ); +if (retval) { +com_err ("ext2fs_badblocks_list_create" , retval,"while creating list" ); + test_fail++; + } + +printf ("Merge & Verify all bb{1..5} into bbm\n" ); +if (bb1 && bb2 && bb3 && bb4 && bb5 && bbm) { +printf ("Merge bb1 into bbm" ); +do_list_merge_verify (bb1, bbm,1 ); +printf ("Merge bb2 into bbm" ); +do_list_merge_verify (bb2, bbm,1 ); +printf ("Merge bb3 into bbm" ); +do_list_merge_verify (bb3, bbm,1 ); +printf ("Merge bb4 into bbm" ); +do_list_merge_verify (bb4, bbm,1 ); +printf ("Merge bb5 into bbm" ); +do_list_merge_verify (bb5, bbm,1 ); + } +file_test (bb4);file_test_invalid (bb4);@@ -363,6 +418,8 @@ int main(int argc, char **argv)ext2fs_badblocks_list_free (bb4);if (bb5)ext2fs_badblocks_list_free (bb5); +if (bbm) +ext2fs_badblocks_list_free (bbm);return test_fail; --
Quoted 2 lines
2.37.3
Cheers, Andreas
Re: [RFCv1 14/72] tst_bitmaps_standalone: Add copy and merge bitmaps test
In reply to Ritesh Harjani (IBM)Quoted 4 lines · Ritesh Harjani (IBM)
This adds a basic copy and merge api test for rbtree bitmap type.
Signed-off-by Ritesh Harjani (IBM) <[email protected]>
Thanks for adding this test. It looks like it is only testing the default rbtree bitmap type. It would be good to also add a test for regular bitmaps.
Quoted 276 lines
---
lib/ext2fs/Makefile.in| 25 +++-lib/ext2fs/tst_bitmaps_standalone.c| 170 ++++++++++++++++++++++++++++2 files changed, 189 insertions(+), 6 deletions(-)create mode 100644
lib/ext2fs/tst_bitmaps_standalone.clib/ext2fs/Makefile.in +8
-2@@ -227,6 +227,7 @@ SRCS= ext2_err.c \ $(srcdir)/write_bb_file.c \ $(srcdir)/rbtree.c \ $(srcdir)/tst_libext2fs.c \ + $(srcdir)/tst_bitmaps_standalone.c \ $(DEBUG_SRCS) HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \@@ -328,9 +329,9 @@ tst_getsectsize: tst_getsectsize.o getsectsize.o $(STATIC_LIBEXT2FS) \ $(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \ $(SYSLIBS) -tst_types.o: $(srcdir)/tst_types.c ext2_types.h +tst_types.o: $(srcdir)/tst_types.c ext2_types.h -tst_types: tst_types.o ext2_types.h +tst_types: tst_types.o ext2_types.h $(E) " LD $@" $(Q) $(CC) -o tst_types tst_types.o $(ALL_LDFLAGS) $(SYSLIBS)@@ -362,6 +363,11 @@ tst_sha512: $(srcdir)/sha512.c $(srcdir)/ext2_fs.h $(Q) $(CC) $(ALL_LDFLAGS) $(ALL_CFLAGS) -o tst_sha512 \ $(srcdir)/sha512.c -DUNITTEST $(SYSLIBS) +tst_bitmaps_standalone: tst_bitmaps_standalone.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) + $(E) " LD $@" + $(Q) $(CC) -o tst_bitmaps_standalone tst_bitmaps_standalone.o $(ALL_LDFLAGS) \ + $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS) +
ext2_tdbtool: tdbtool.o$(E) " LD $@" $(Q) $(CC) -o ext2_tdbtool tdbtool.o tdb.o $(ALL_LDFLAGS) $(SYSLIBS)lib/ext2fs/Makefile.in +2
-1@@ -533,7 +539,7 @@ mkjournal: mkjournal.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) fullcheck check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \ tst_super_size tst_types tst_inode_size tst_csum tst_crc32c tst_bitmaps \ tst_inline tst_inline_data tst_libext2fs tst_sha256 tst_sha512 \ - tst_digest_encode tst_getsize tst_getsectsize + tst_digest_encode tst_getsize tst_getsectsize tst_bitmaps_standalone $(TESTENV) ./tst_bitops $(TESTENV) ./tst_badblocks $(TESTENV) ./tst_iscan@@ -556,6 +562,7 @@ fullcheck check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \ $(TESTENV) ./tst_bitmaps -l -f $(srcdir)/tst_bitmaps_cmds > tst_bitmaps_out diff $(srcdir)/tst_bitmaps_exp tst_bitmaps_out $(TESTENV) ./tst_digest_encode + $(TESTENV) ./tst_bitmaps_standaloneinstalldirs::
$(E) " MKDIR_P $(libdir) $(includedir)/ext2fs"lib/ext2fs/Makefile.in +0
-0@@ -581,7 +588,7 @@ install:: all $(HFILES) $(HFILES_IN) installdirs ext2fs.pcuninstall::
$(RM) -f $(DESTDIR)$(libdir)/libext2fs.a \ $(DESTDIR)$(pkgconfigdir)/ext2fs.pclib/ext2fs/Makefile.in +1
-1- $(RM) -rf $(DESTDIR)$(includedir)/ext2fs + $(RM) -rf $(DESTDIR)$(includedir)/ext2fsclean::
$(RM) -f \#* *.s *.o *.a *~ *.bak core profiled/* \lib/ext2fs/Makefile.in +8
-2@@ -590,7 +597,7 @@ clean:: tst_bitops tst_types tst_icount tst_super_size tst_csum \ tst_bitmaps tst_bitmaps_out tst_extents tst_inline \ tst_inline_data tst_inode_size tst_bitmaps_cmd.c \ - tst_digest_encode tst_sha256 tst_sha512 \ + tst_digest_encode tst_sha256 tst_sha512 tst_bitmaps_standalone \ ext2_tdbtool mkjournal debug_cmds.c tst_cmds.c extent_cmds.c \ ../libext2fs.a ../libext2fs_p.a ../libext2fs_chk.a \ crc32c_table.h gen_crc32ctable tst_crc32c tst_libext2fs \@@ -646,7 +653,7 @@ windows_io.o: $(srcdir)/windows_io.c $(top_builddir)/lib/config.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/ext2fsP.h # +++ Dependency line eater +++ -# +# # Makefile dependencies follow. This must be the last section in # the Makefile.in file #@@ -1156,6 +1163,12 @@ tst_iscan.o: $(srcdir)/tst_iscan.c $(top_builddir)/lib/config.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h +tst_bitmaps_standalone.o: $(srcdir)/tst_bitmaps_standalone.c $(top_builddir)/lib/config.h \ + $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ + $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h undo_io.o: $(srcdir)/undo_io.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \lib/ext2fs/tst_bitmaps_standalone.c new file +170
-1@@ -0,0 +1,170 @@ +#include "config.h" +#include <stdio.h> +#include <string.h> +#include <assert.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#include <fcntl.h> +#include <time.h> +#include <sys/stat.h> +#include <sys/types.h> +#if HAVE_ERRNO_H +#include <errno.h> +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "bmap64.h" + +ext2_filsys test_fs; +ext2fs_block_bitmap block_map_1; +ext2fs_block_bitmap block_map_2; +ext2fs_block_bitmap block_map; + +static int test_fail =0 ; + +void dump_bitmap (ext2fs_generic_bitmap bmap,unsigned int start,unsigned num) +{ +unsigned char *buf; +errcode_t retval; +int i, len = (num - start +7 ) /8 ; + + buf =malloc (len); +if (!buf) { +com_err ("dump_bitmap" ,0 ,"couldn't allocate buffer" ); +return ; + } +memset (buf,0 , len); + retval =ext2fs_get_generic_bmap_range (bmap, (__u64 ) start, num, buf); +if (retval) { +com_err ("dump_bitmap" , retval, +"while calling ext2fs_generic_bmap_range" ); +free (buf); +return ; + } +for (i=len-1 ; i >=0 ; i--) +printf ("%02x " , buf[i]); +printf ("\n" ); +printf ("bits set: %u\n" ,ext2fs_bitcount (buf, len)); +free (buf); +} + +static void test_copy_run () +{ +int blocks[] = {1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,21 ,23 ,26 ,29 ,33 ,37 ,38 }; +errcode_t ret; +char *buf_map =NULL ; +char *buf_copy_map =NULL ; + +assert (ext2fs_allocate_block_bitmap (test_fs,"block bitmap" , &block_map_1) ==0 ); + +for (int i =0 ; i <sizeof (blocks)/sizeof (blocks[0 ]); i++) { +ext2fs_mark_block_bitmap2 (block_map_1, blocks[i]); + } + +assert (ext2fs_copy_bitmap (block_map_1, &block_map) ==0 ); + +if (ext2fs_compare_block_bitmap (block_map_1, block_map) !=0 ) { +printf ("block bitmap copy test failed\n" ); + test_fail++; + +dump_bitmap (block_map_1, test_fs->super->s_first_data_block, + test_fs->super->s_blocks_count); + +dump_bitmap (block_map, test_fs->super->s_first_data_block, + test_fs->super->s_blocks_count); + } + +ext2fs_free_block_bitmap (block_map_1); +ext2fs_free_block_bitmap (block_map); +} + +void test_merge_run () +{ +int blocks_odd[] = {1 ,3 ,5 ,7 ,9 ,21 ,23 ,29 ,33 ,37 }; +int blocks_even[] = {2 ,4 ,6 ,8 ,10 ,26 ,38 }; +ext2fs_generic_bitmap_64 tmp_map; + +assert (ext2fs_allocate_block_bitmap (test_fs,"block bitmap 1" , &block_map_1) ==0 ); +assert (ext2fs_allocate_block_bitmap (test_fs,"block bitmap 2" , &block_map_2) ==0 ); +assert (ext2fs_allocate_block_bitmap (test_fs,"block bitmap 2" , &block_map) ==0 ); + +for (int i =0 ; i <sizeof (blocks_odd) /sizeof (blocks_odd[0 ]); i++) { +ext2fs_mark_block_bitmap2 (block_map_1, blocks_odd[i]); +ext2fs_mark_block_bitmap2 (block_map, blocks_odd[i]); + } + +for (int i =0 ; i <sizeof (blocks_even) /sizeof (blocks_even[0 ]); i++) { +ext2fs_mark_block_bitmap2 (block_map_2, blocks_even[i]); +ext2fs_mark_block_bitmap2 (block_map, blocks_even[i]); + } + +assert (ext2fs_merge_bitmap (block_map_2, block_map_1,NULL ,NULL ) ==0 ); +if (ext2fs_compare_block_bitmap (block_map_1, block_map) !=0 ) { +printf ("block bitmap merge test failed\n" ); + test_fail++; + +dump_bitmap (block_map_1, test_fs->super->s_first_data_block, + test_fs->super->s_blocks_count); + +dump_bitmap (block_map, test_fs->super->s_first_data_block, + test_fs->super->s_blocks_count); + } + +ext2fs_free_block_bitmap (block_map_1); +ext2fs_free_block_bitmap (block_map_2); +ext2fs_free_block_bitmap (block_map); +} + +static void setup_filesystem (const char *name,unsigned int blocks, +unsigned int inodes,unsigned int type, +unsigned int flags) +{ +struct ext2_super_block param; +errcode_t ret; + +memset (¶m,0 ,sizeof (param)); +ext2fs_blocks_count_set (¶m, blocks); + param.s_inodes_count = inodes; + + ret =ext2fs_initialize (name, flags, ¶m, test_io_manager, + &test_fs); +if (ret) { +com_err (name, ret,"while initializing filesystem" ); +return ; + } + + test_fs->default_bitmap_type = type; + +ext2fs_free_block_bitmap (test_fs->block_map); +ext2fs_free_block_bitmap (test_fs->inode_map); + +return ; +errout: +ext2fs_close_free (&test_fs); +} + +int main (int argc,char **argv) +{ +unsigned int blocks =127 ; +unsigned int inodes =0 ; +unsigned int type =EXT2FS_BMAP64_RBTREE ; +unsigned int flags =EXT2_FLAG_64BITS ; +char *buf =NULL ; + +setup_filesystem (argv[0 ], blocks, inodes, type, flags); + +/* test for EXT2FS_BMAP64_RBTREE */ +test_copy_run (); +test_merge_run (); + +/* TODO: test for EXT2FS_BMAP64_BITARRAY */ + +if (test_fail) +printf ("%s: Test copy & merge bitmaps -- NOT OK\n" , argv[0 ]); +else +printf ("%s: Test copy & merge bitmaps -- OK\n" , argv[0 ]); + +return test_fail; +} --
Quoted 2 lines
2.37.3
Cheers, Andreas
Re: [RFCv1 14/72] tst_bitmaps_standalone: Add copy and merge bitmaps test
Quoted 8 lines · Andreas Dilger
Quoted 4 lines · Ritesh Harjani (IBM)
This adds a basic copy and merge api test for rbtree bitmap type.
Signed-off-by Ritesh Harjani (IBM) <[email protected]>Thanks for adding this test. It looks like it is only testing the default rbtree bitmap type. It would be good to also add a test for regular bitmaps.
sure, the test will also requires merge logic for regular bitmap. I had added some basic support earlier (non-aligned was remaining to be added). In the next iteration, I will keep a note about this.
Quoted 2 lines
Reviewed-by Andreas Dilger <[email protected]>
Thanks for the review!
Quoted 287 lines
Quoted 277 lines
---
lib/ext2fs/Makefile.in| 25 +++-lib/ext2fs/tst_bitmaps_standalone.c| 170 ++++++++++++++++++++++++++++2 files changed, 189 insertions(+), 6 deletions(-)create mode 100644
lib/ext2fs/tst_bitmaps_standalone.clib/ext2fs/Makefile.in +8
-2@@ -227,6 +227,7 @@ SRCS= ext2_err.c \ $(srcdir)/write_bb_file.c \ $(srcdir)/rbtree.c \ $(srcdir)/tst_libext2fs.c \ + $(srcdir)/tst_bitmaps_standalone.c \ $(DEBUG_SRCS) HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \@@ -328,9 +329,9 @@ tst_getsectsize: tst_getsectsize.o getsectsize.o $(STATIC_LIBEXT2FS) \ $(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \ $(SYSLIBS) -tst_types.o: $(srcdir)/tst_types.c ext2_types.h +tst_types.o: $(srcdir)/tst_types.c ext2_types.h -tst_types: tst_types.o ext2_types.h +tst_types: tst_types.o ext2_types.h $(E) " LD $@" $(Q) $(CC) -o tst_types tst_types.o $(ALL_LDFLAGS) $(SYSLIBS)@@ -362,6 +363,11 @@ tst_sha512: $(srcdir)/sha512.c $(srcdir)/ext2_fs.h $(Q) $(CC) $(ALL_LDFLAGS) $(ALL_CFLAGS) -o tst_sha512 \ $(srcdir)/sha512.c -DUNITTEST $(SYSLIBS) +tst_bitmaps_standalone: tst_bitmaps_standalone.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) + $(E) " LD $@" + $(Q) $(CC) -o tst_bitmaps_standalone tst_bitmaps_standalone.o $(ALL_LDFLAGS) \ + $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS) +
ext2_tdbtool: tdbtool.o$(E) " LD $@" $(Q) $(CC) -o ext2_tdbtool tdbtool.o tdb.o $(ALL_LDFLAGS) $(SYSLIBS)lib/ext2fs/Makefile.in +2
-1@@ -533,7 +539,7 @@ mkjournal: mkjournal.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR) fullcheck check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \ tst_super_size tst_types tst_inode_size tst_csum tst_crc32c tst_bitmaps \ tst_inline tst_inline_data tst_libext2fs tst_sha256 tst_sha512 \ - tst_digest_encode tst_getsize tst_getsectsize + tst_digest_encode tst_getsize tst_getsectsize tst_bitmaps_standalone $(TESTENV) ./tst_bitops $(TESTENV) ./tst_badblocks $(TESTENV) ./tst_iscan@@ -556,6 +562,7 @@ fullcheck check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \ $(TESTENV) ./tst_bitmaps -l -f $(srcdir)/tst_bitmaps_cmds > tst_bitmaps_out diff $(srcdir)/tst_bitmaps_exp tst_bitmaps_out $(TESTENV) ./tst_digest_encode + $(TESTENV) ./tst_bitmaps_standaloneinstalldirs::
$(E) " MKDIR_P $(libdir) $(includedir)/ext2fs"lib/ext2fs/Makefile.in +0
-0@@ -581,7 +588,7 @@ install:: all $(HFILES) $(HFILES_IN) installdirs ext2fs.pcuninstall::
$(RM) -f $(DESTDIR)$(libdir)/libext2fs.a \ $(DESTDIR)$(pkgconfigdir)/ext2fs.pclib/ext2fs/Makefile.in +1
-1- $(RM) -rf $(DESTDIR)$(includedir)/ext2fs + $(RM) -rf $(DESTDIR)$(includedir)/ext2fsclean::
$(RM) -f \#* *.s *.o *.a *~ *.bak core profiled/* \lib/ext2fs/Makefile.in +8
-2@@ -590,7 +597,7 @@ clean:: tst_bitops tst_types tst_icount tst_super_size tst_csum \ tst_bitmaps tst_bitmaps_out tst_extents tst_inline \ tst_inline_data tst_inode_size tst_bitmaps_cmd.c \ - tst_digest_encode tst_sha256 tst_sha512 \ + tst_digest_encode tst_sha256 tst_sha512 tst_bitmaps_standalone \ ext2_tdbtool mkjournal debug_cmds.c tst_cmds.c extent_cmds.c \ ../libext2fs.a ../libext2fs_p.a ../libext2fs_chk.a \ crc32c_table.h gen_crc32ctable tst_crc32c tst_libext2fs \@@ -646,7 +653,7 @@ windows_io.o: $(srcdir)/windows_io.c $(top_builddir)/lib/config.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/bitops.h $(srcdir)/ext2fsP.h # +++ Dependency line eater +++ -# +# # Makefile dependencies follow. This must be the last section in # the Makefile.in file #@@ -1156,6 +1163,12 @@ tst_iscan.o: $(srcdir)/tst_iscan.c $(top_builddir)/lib/config.h \ $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h +tst_bitmaps_standalone.o: $(srcdir)/tst_bitmaps_standalone.c $(top_builddir)/lib/config.h \ + $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ + $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h undo_io.o: $(srcdir)/undo_io.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \lib/ext2fs/tst_bitmaps_standalone.c new file +170
-1@@ -0,0 +1,170 @@ +#include "config.h" +#include <stdio.h> +#include <string.h> +#include <assert.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#include <fcntl.h> +#include <time.h> +#include <sys/stat.h> +#include <sys/types.h> +#if HAVE_ERRNO_H +#include <errno.h> +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "bmap64.h" + +ext2_filsys test_fs; +ext2fs_block_bitmap block_map_1; +ext2fs_block_bitmap block_map_2; +ext2fs_block_bitmap block_map; + +static int test_fail =0 ; + +void dump_bitmap (ext2fs_generic_bitmap bmap,unsigned int start,unsigned num) +{ +unsigned char *buf; +errcode_t retval; +int i, len = (num - start +7 ) /8 ; + + buf =malloc (len); +if (!buf) { +com_err ("dump_bitmap" ,0 ,"couldn't allocate buffer" ); +return ; + } +memset (buf,0 , len); + retval =ext2fs_get_generic_bmap_range (bmap, (__u64 ) start, num, buf); +if (retval) { +com_err ("dump_bitmap" , retval, +"while calling ext2fs_generic_bmap_range" ); +free (buf); +return ; + } +for (i=len-1 ; i >=0 ; i--) +printf ("%02x " , buf[i]); +printf ("\n" ); +printf ("bits set: %u\n" ,ext2fs_bitcount (buf, len)); +free (buf); +} + +static void test_copy_run () +{ +int blocks[] = {1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,21 ,23 ,26 ,29 ,33 ,37 ,38 }; +errcode_t ret; +char *buf_map =NULL ; +char *buf_copy_map =NULL ; + +assert (ext2fs_allocate_block_bitmap (test_fs,"block bitmap" , &block_map_1) ==0 ); + +for (int i =0 ; i <sizeof (blocks)/sizeof (blocks[0 ]); i++) { +ext2fs_mark_block_bitmap2 (block_map_1, blocks[i]); + } + +assert (ext2fs_copy_bitmap (block_map_1, &block_map) ==0 ); + +if (ext2fs_compare_block_bitmap (block_map_1, block_map) !=0 ) { +printf ("block bitmap copy test failed\n" ); + test_fail++; + +dump_bitmap (block_map_1, test_fs->super->s_first_data_block, + test_fs->super->s_blocks_count); + +dump_bitmap (block_map, test_fs->super->s_first_data_block, + test_fs->super->s_blocks_count); + } + +ext2fs_free_block_bitmap (block_map_1); +ext2fs_free_block_bitmap (block_map); +} + +void test_merge_run () +{ +int blocks_odd[] = {1 ,3 ,5 ,7 ,9 ,21 ,23 ,29 ,33 ,37 }; +int blocks_even[] = {2 ,4 ,6 ,8 ,10 ,26 ,38 }; +ext2fs_generic_bitmap_64 tmp_map; + +assert (ext2fs_allocate_block_bitmap (test_fs,"block bitmap 1" , &block_map_1) ==0 ); +assert (ext2fs_allocate_block_bitmap (test_fs,"block bitmap 2" , &block_map_2) ==0 ); +assert (ext2fs_allocate_block_bitmap (test_fs,"block bitmap 2" , &block_map) ==0 ); + +for (int i =0 ; i <sizeof (blocks_odd) /sizeof (blocks_odd[0 ]); i++) { +ext2fs_mark_block_bitmap2 (block_map_1, blocks_odd[i]); +ext2fs_mark_block_bitmap2 (block_map, blocks_odd[i]); + } + +for (int i =0 ; i <sizeof (blocks_even) /sizeof (blocks_even[0 ]); i++) { +ext2fs_mark_block_bitmap2 (block_map_2, blocks_even[i]); +ext2fs_mark_block_bitmap2 (block_map, blocks_even[i]); + } + +assert (ext2fs_merge_bitmap (block_map_2, block_map_1,NULL ,NULL ) ==0 ); +if (ext2fs_compare_block_bitmap (block_map_1, block_map) !=0 ) { +printf ("block bitmap merge test failed\n" ); + test_fail++; + +dump_bitmap (block_map_1, test_fs->super->s_first_data_block, + test_fs->super->s_blocks_count); + +dump_bitmap (block_map, test_fs->super->s_first_data_block, + test_fs->super->s_blocks_count); + } + +ext2fs_free_block_bitmap (block_map_1); +ext2fs_free_block_bitmap (block_map_2); +ext2fs_free_block_bitmap (block_map); +} + +static void setup_filesystem (const char *name,unsigned int blocks, +unsigned int inodes,unsigned int type, +unsigned int flags) +{ +struct ext2_super_block param; +errcode_t ret; + +memset (¶m,0 ,sizeof (param)); +ext2fs_blocks_count_set (¶m, blocks); + param.s_inodes_count = inodes; + + ret =ext2fs_initialize (name, flags, ¶m, test_io_manager, + &test_fs); +if (ret) { +com_err (name, ret,"while initializing filesystem" ); +return ; + } + + test_fs->default_bitmap_type = type; + +ext2fs_free_block_bitmap (test_fs->block_map); +ext2fs_free_block_bitmap (test_fs->inode_map); + +return ; +errout: +ext2fs_close_free (&test_fs); +} + +int main (int argc,char **argv) +{ +unsigned int blocks =127 ; +unsigned int inodes =0 ; +unsigned int type =EXT2FS_BMAP64_RBTREE ; +unsigned int flags =EXT2_FLAG_64BITS ; +char *buf =NULL ; + +setup_filesystem (argv[0 ], blocks, inodes, type, flags); + +/* test for EXT2FS_BMAP64_RBTREE */ +test_copy_run (); +test_merge_run (); + +/* TODO: test for EXT2FS_BMAP64_BITARRAY */ + +if (test_fail) +printf ("%s: Test copy & merge bitmaps -- NOT OK\n" , argv[0 ]); +else +printf ("%s: Test copy & merge bitmaps -- OK\n" , argv[0 ]); + +return test_fail; +} --Quoted 2 lines
2.37.3
Cheers, Andreas
Re: [RFCv1 15/72] tst_bitmaps_pthread: Add merge bitmaps test using pthreads
In reply to Ritesh Harjani (IBM)Quoted 5 lines · Ritesh Harjani (IBM)
This patch adds a test to verify the core bitmaps merge APIs for rbtree bitmap type.
Signed-off-by Ritesh Harjani (IBM) <[email protected]>
Quoted 5 lines
+/*
+ * Note we useEXT2FS_BMAP64_BITARRAYalways forused_bitmap, this is because
+ *EXT2FS_BMAP64_RBTREEdoes not support parallel scan due to rcursor
+ * optimization.
+ */
Is this going to be a problem in the future? I think for pass1/pass5 there are no rbtree bitmaps that are *source* bitmaps for multi-threaded operation, but I suspect that once we try to parallelize pass2 this could break.
Is there any check in the code that prevents multi-thread access to an rbtree bitmap? Making a copy for each thread, or ideally copying the rcursor for each thread, to allow at least multi-threaded reads. I don't think there is a high need for multi-threaded write
Cheers, Andreas
Re: [RFCv1 16/72] tst_libext2fs_pthread: Add libext2fs merge/clone unit tests
In reply to Ritesh Harjani (IBM)Quoted 9 lines · Ritesh Harjani (IBM)
This adds a unit tests for libext2fs merge/clone apis and uses pthreads to test the functionality correctly.
TODO:
We can also addEXT2FS_CLONE_BADBLOCKSandEXT2FS_CLONE_DBLISTtest as well into it.Signed-off-by Ritesh Harjani (IBM) <[email protected]>
Quoted 391 lines
---
lib/ext2fs/Makefile.in| 17 +-lib/ext2fs/tst_libext2fs_pthread.c| 315 +++++++++++++++++++++++++++++2 files changed, 330 insertions(+), 2 deletions(-)create mode 100644
lib/ext2fs/tst_libext2fs_pthread.clib/ext2fs/Makefile.in +6
-0@@ -229,6 +229,7 @@ SRCS= ext2_err.c \ $(srcdir)/tst_libext2fs.c \ $(srcdir)/tst_bitmaps_standalone.c \ $(srcdir)/tst_bitmaps_pthread.c \ + $(srcdir)/tst_libext2fs_pthread.c \ $(DEBUG_SRCS) HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \@@ -374,6 +375,11 @@ tst_bitmaps_pthread: tst_bitmaps_pthread.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCO $(Q) $(CC) -o tst_bitmaps_pthread tst_bitmaps_pthread.o $(ALL_LDFLAGS) \ $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS) +tst_libext2fs_pthread: tst_libext2fs_pthread.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR) + $(E) " LD $@" + $(Q) $(CC) -o tst_libext2fs_pthread tst_libext2fs_pthread.o $(ALL_LDFLAGS) \ + $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS) +
ext2_tdbtool: tdbtool.o$(E) " LD $@" $(Q) $(CC) -o ext2_tdbtool tdbtool.o tdb.o $(ALL_LDFLAGS) $(SYSLIBS)lib/ext2fs/Makefile.in +2
-1@@ -546,7 +552,7 @@ fullcheck check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \ tst_super_size tst_types tst_inode_size tst_csum tst_crc32c tst_bitmaps \ tst_inline tst_inline_data tst_libext2fs tst_sha256 tst_sha512 \ tst_digest_encode tst_getsize tst_getsectsize tst_bitmaps_standalone \ - tst_bitmaps_pthread + tst_bitmaps_pthread tst_libext2fs_pthread $(TESTENV) ./tst_bitops $(TESTENV) ./tst_badblocks $(TESTENV) ./tst_iscan@@ -571,6 +577,7 @@ fullcheck check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \ $(TESTENV) ./tst_digest_encode $(TESTENV) ./tst_bitmaps_standalone $(TESTENV) ./tst_bitmaps_pthread + $(TESTENV) ./tst_libext2fs_pthreadinstalldirs::
$(E) " MKDIR_P $(libdir) $(includedir)/ext2fs"lib/ext2fs/Makefile.in +7
-1@@ -606,7 +613,7 @@ clean:: tst_bitmaps tst_bitmaps_out tst_extents tst_inline \ tst_inline_data tst_inode_size tst_bitmaps_cmd.c \ tst_digest_encode tst_sha256 tst_sha512 tst_bitmaps_standalone \ - tst_bitmaps_pthread \ + tst_bitmaps_pthread tst_libext2fs_pthread \ ext2_tdbtool mkjournal debug_cmds.c tst_cmds.c extent_cmds.c \ ../libext2fs.a ../libext2fs_p.a ../libext2fs_chk.a \ crc32c_table.h gen_crc32ctable tst_crc32c tst_libext2fs \@@ -1184,6 +1191,12 @@ tst_bitmaps_pthread.o: $(srcdir)/tst_bitmaps_pthread.c $(top_builddir)/lib/confi $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h +tst_libext2fs_pthread.o: $(srcdir)/tst_libext2fs_pthread.c $(top_builddir)/lib/config.h \ + $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ + $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \ + $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \ + $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h undo_io.o: $(srcdir)/undo_io.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \lib/ext2fs/tst_libext2fs_pthread.c new file +315
-1@@ -0,0 +1,315 @@ +#include "config.h" +#include <stdio.h> +#include <string.h> +#include <assert.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#include <fcntl.h> +#include <time.h> +#include <sys/stat.h> +#include <sys/types.h> +#if HAVE_ERRNO_H +#include <errno.h> +#endif +#if HAVE_PTHREAD +#include <pthread.h> +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +#ifdef HAVE_PTHREAD +int test_fail =0 ; +ext2_filsys testfs; +ext2fs_inode_bitmap inode_used_map; +ext2fs_block_bitmap block_used_map; +ext2_filsys childfs[2 ]; +pthread_t pthread_infos[2 ]; + +#define nr_bits 16384 +int nr_threads =2 ; + +int should_mark_bit () +{ +return rand () %2 ==0 ; +} + +void setupfs () +{ +errcode_t retval; +struct ext2_super_block param; + +initialize_ext2_error_table (); + +memset (¶m,0 ,sizeof (param)); +ext2fs_blocks_count_set (¶m, nr_bits); + retval =ext2fs_initialize ("test fs" ,EXT2_FLAG_64BITS , ¶m, + test_io_manager, &testfs); +if (retval) { +com_err ("setup" , retval,"while initializing filesystem" ); +exit (1 ); + } + + retval =ext2fs_allocate_tables (testfs); +if (retval) { +com_err ("setup" , retval,"while allocating tables for testfs" ); +exit (1 ); + } +} + +void setup_used_bitmaps () +{ +int saved_type = testfs->default_bitmap_type; +ext2_inode_scan scan; +struct ext2_inode inode; +ext2_ino_t ino; +errcode_t retval; +int i; + + testfs->default_bitmap_type =EXT2FS_BMAP64_BITARRAY ; + +/* allocate block and inode used bitmaps */ + retval =ext2fs_allocate_block_bitmap (testfs,"block used map" , &block_used_map); +if (retval) + goto out; + + retval =ext2fs_allocate_inode_bitmap (testfs,"inode used map" , &inode_used_map); +if (retval) + goto out; + +/* setup block and inode used bitmaps */ +for (i =1 ; i < nr_bits; i++) { +/* +* we check for testfs->block_map as well since there could be some +* blocks already set as part of the FS metadata. +*/ +if (should_mark_bit () ||ext2fs_test_block_bitmap2 (testfs->block_map, i)) { +ext2fs_mark_block_bitmap2 (block_used_map, i); + } + } + + retval =ext2fs_open_inode_scan (testfs,8 , &scan); +if (retval) { +com_err ("setup_inode_map" , retval,"while open inode scan" ); +exit (1 ); + } + + retval =ext2fs_get_next_inode (scan, &ino, &inode); +if (retval) { +com_err ("setup_inode_map" , retval,"while getting next inode" ); +exit (1 ); + } + +while (ino) { +if (should_mark_bit ()) +ext2fs_mark_inode_bitmap2 (inode_used_map, ino); + + retval =ext2fs_get_next_inode (scan, &ino, &inode); +if (retval) { +com_err ("setup_inode_map" , retval,"while getting next inode" ); +exit (1 ); + } + } +ext2fs_close_inode_scan (scan); + + testfs->default_bitmap_type = saved_type; +return ; +out: +com_err ("setup_used_bitmaps" , retval,"while setting up bitmaps\n" ); +exit (1 ); +} + +void setup_childfs () +{ +errcode_t retval; +int i; + +for (i =0 ; i < nr_threads; i++) { + retval =ext2fs_clone_fs (testfs, &childfs[i],EXT2FS_CLONE_INODE |EXT2FS_CLONE_BLOCK ); +if (retval) { +com_err ("setup_childfs" , retval,"while clone testfs for childfs" ); +exit (1 ); + } + + retval = childfs[i]->io->manager->open (childfs[i]->device_name, +IO_FLAG_THREADS |IO_FLAG_NOCACHE , &childfs[i]->io); +if (retval) { +com_err ("setup_pthread" , retval,"while opening childfs" ); +exit (1 ); + } +assert (childfs[i]->parent == testfs); + } +} + +static errcode_t scan_callback(ext2_filsys fs, + ext2_inode_scan scan EXT2FS_ATTR((unused)), + dgrp_t group, void *priv_data) +{ + pthread_t id = *((pthread_t *)priv_data); + +printf ("%s: Called for group %d via thread %d\n" , __func__, group, +pthread_equal (pthread_infos[1 ], id)); +if (pthread_equal (pthread_infos[0 ], id)) { +if (group >= fs->group_desc_count /2 -1 ) +return 1 ; + } +return 0 ; +} + +static void *run_pthread (void *arg) +{ +errcode_t retval =0 ; +int i =0 , start, end; +ext2fs_block_bitmap test_block_bitmap; +ext2fs_inode_bitmap test_inode_bitmap; +ext2_inode_scan scan; +struct ext2_inode inode; +ext2_ino_t ino; +pthread_t id =pthread_self (); + +if (pthread_equal (pthread_infos[0 ], id)) { + start =1 ; + end = nr_bits/2 ; + test_block_bitmap = childfs[0 ]->block_map; + test_inode_bitmap = childfs[0 ]->inode_map; + + retval =ext2fs_open_inode_scan (childfs[0 ],8 , &scan); +if (retval) { +com_err ("setup_inode_map" , retval,"while open inode scan" ); +exit (1 ); + } + + }else { + start = nr_bits /2 +1 ;; + end = nr_bits -1 ; + test_block_bitmap = childfs[1 ]->block_map; + test_inode_bitmap = childfs[1 ]->inode_map; + + retval =ext2fs_open_inode_scan (childfs[1 ],8 , &scan); +if (retval) { +com_err ("setup_inode_map" , retval,"while open inode scan" ); +exit (1 ); + } +ext2fs_inode_scan_goto_blockgroup (scan, testfs->group_desc_count/2 ); + } + +ext2fs_set_inode_callback (scan, scan_callback, &id); + +/* blocks scan */ +for (i = start; i <= end; i++) { +if (ext2fs_test_block_bitmap2 (block_used_map, i)) { +ext2fs_mark_block_bitmap2 (test_block_bitmap, i); + } + } + +/* inodes scan */ + retval =ext2fs_get_next_inode (scan, &ino, &inode); +if (retval) { +com_err ("setup_inode_map" , retval,"while getting next inode" ); +exit (1 ); + } + +while (ino) { +if (ext2fs_test_inode_bitmap2 (inode_used_map, ino)) { +ext2fs_mark_inode_bitmap2 (test_inode_bitmap, ino); + } + + retval =ext2fs_get_next_inode (scan, &ino, &inode); +if (retval) +break ; + } +ext2fs_close_inode_scan (scan); +return NULL ; +} + +void run_pthreads () +{ +errcode_t retval; +int i; + +for (i =0 ; i < nr_threads; i++) { +printf ("Starting thread (%d)\n" , i); + retval =pthread_create (&pthread_infos[i],NULL , &run_pthread,NULL ); +if (retval) { +com_err ("run_pthreads" , retval,"while pthread_create" ); +exit (1 ); + } + } + +for (i =0 ; i < nr_threads; i++) { +void *status; +int ret; + retval =pthread_join (pthread_infos[i], &status); +if (retval) { +com_err ("run_pthreads" , retval,"while joining pthreads" ); +exit (1 ); + + } + ret = status ==NULL ?0 : *(int *)status; +if (ret) { +com_err ("run_pthreads" , ret,"pthread returned error" ); + test_fail++; + } + +printf ("Closing thread (%d), ret(%d)\n" , i, ret); + } + +assert (ext2fs_merge_fs (&childfs[0 ]) ==0 ); +assert (ext2fs_merge_fs (&childfs[1 ]) ==0 ); +} + +void test_bitmaps () +{ +errcode_t retval; + retval =ext2fs_compare_block_bitmap (testfs->block_map, block_used_map); +if (retval) { +printf ("Block bitmap compare -- NOT OK!! (%ld)\n" , retval); + test_fail++; + } + +printf ("Block compare bitmap -- OK!!\n" ); + retval =ext2fs_compare_inode_bitmap (testfs->inode_map, inode_used_map); +if (retval) { +printf ("Inode bitmap compare -- NOT OK!! (%ld)\n" , retval); + test_fail++; + } +printf ("Inode compare bitmap -- OK!!\n" ); +} + +void free_used_bitmaps () +{ +ext2fs_free_block_bitmap (block_used_map); +ext2fs_free_inode_bitmap (inode_used_map); +} + +#endif + +int main (int argc,char *argv[]) +{ +int i; + +#ifndef HAVE_PTHREAD +printf ("No PTHREAD support, exiting...\n" ); +return 0 ; +#else + +srand (time (0 )); + +setupfs (); +setup_used_bitmaps (); + +setup_childfs (); +run_pthreads (); +test_bitmaps (i); + +if (test_fail) +printf ("%s: Test libext2fs clone/merge with pthreads NOT OK!!\n" , argv[0 ]); +else +printf ("%s: Test libext2fs clone/merge with pthreads OK!!\n" , argv[0 ]); +free_used_bitmaps (); +ext2fs_free (testfs); + +return test_fail; +#endif +} --
Quoted 2 lines
2.37.3
Cheers, Andreas
Re: [RFCv1 17/72] libext2fs: Add support for ext2fs_test_block_bitmap_range2_valid()
In reply to Ritesh Harjani (IBM)Quoted 7 lines · Ritesh Harjani (IBM)
From: Wang Shilong <[email protected]>
This adds the support in libext2fs to query whether the block range is valid or not (within range) given the block bitmap.
Also to avoid duplicate warning messages in case of invalid blocks.
Quoted 6 lines
This will be later used in pass1 of e2fsck
is_blocks_used()function to check whether the given block range is valid or not to avoid duplicate warning resulting fromext2fs_test_block_bitmap_range2()Signed-off-by Wang Shilong <[email protected]>Signed-off-by Ritesh Harjani (IBM) <[email protected]>
I don't think this patch is correct?
Quoted 14 lines
---
lib/ext2fs/gen_bitmap64.c +5
-0@@ -731,6 +731,39 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap gen_bmap,return bmap->bitmap_ops->test_clear_bmap_extent (bmap, block, num); } +int ext2fs_test_block_bitmap_range2_valid (ext2fs_block_bitmap bitmap, +blk64_t block,unsigned int num) +{ +ext2fs_generic_bitmap_64 bmap = (ext2fs_generic_bitmap_64 )bitmap; +__u64 end = block + num;
lib/ext2fs/gen_bitmap64.c int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap gen_bmap, · line 748
Quoted 10 lines
lib/ext2fs/gen_bitmap64.c +10
-0+ +if (!bmap) +return 0 ; + +if (EXT2FS_IS_32_BITMAP (bmap)) { +if ((block & ~0xffffffffULL ) || + ((block+num-1 ) & ~0xffffffffULL )) { +return 0 ; + } + }
This is bailing out early if the requested bit is > 2^32, but that is before cluster conversion below. However, I think the bitmap is actually stored in clusters, so the 2^32 check seems premature?
Quoted 6 lines
lib/ext2fs/gen_bitmap64.c +6
-0+ +if (!EXT2FS_IS_64_BITMAP (bmap)) +return 0 ; + +/* convert to clusters if necessary */ + block >>= bmap->cluster_bits;
lib/ext2fs/gen_bitmap64.c int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap gen_bmap, · line 764
Quoted 10 lines
lib/ext2fs/gen_bitmap64.c +10
-0+ end += (1 << bmap->cluster_bits) -1 ; + end >>= bmap->cluster_bits; + num = end - block; + +if ((block < bmap->start) || (block > bmap->end) || + (block+num-1 > bmap->end)) +return 0 ; + +return 1 ; +}
Cheers, Andreas
Re: [RFCv1 19/72] libext2fs: Misc fixes for struct_ext2_filsys
In reply to Ritesh Harjani (IBM)Quoted 5 lines · Ritesh Harjani (IBM)
From: Andreas Dilger <[email protected]>
Move
ext2_filsysfs_num_threadsto fit into the__u16"pad" field to avoid consuming one of the few remaining__u32reserved fields.
This should be merged into the previous patch.
Quoted 26 lines
Signed-off-by Andreas Dilger <[email protected]>Signed-off-by Ritesh Harjani (IBM) <[email protected]>---
lib/ext2fs/ext2fs.h| 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)lib/ext2fs/ext2fs.h +2
-4@@ -278,12 +278,11 @@ struct struct_ext2_filsys {time_t now;int cluster_ratio_bits;__u16 default_bitmap_type; -__u16 pad; -__u32 fs_num_threads; +__u16 fs_num_threads;/* * Reserved for future expansion */ -__u32 reserved[4 ]; +__u32 reserved[5 ];/* * Reserved for the use of the calling application. --
Quoted 2 lines
2.37.3
Cheers, Andreas
Re: [RFCv1 18/72] libext2fs: Add support to get average group count
In reply to Ritesh Harjani (IBM)Quoted 25 lines · Ritesh Harjani (IBM)
From: Wang Shilong <[email protected]>
number of threads in pfsck should not exceed flex bg numbers. This patch adds the support in libext2fs to calculate
ext2fs_get_avg_group()which returns an average group count which each thread has to scan.
fs->fs_num_threadswill be set by the client, in this case e2fsck. No. of threads will be passed along with -m option while running e2fsck. That will also setfs->fs_num_threads, which will help in controlling the amount of memory consumed to maintain in memory data structures (per thread) in case of multiple parallel threads (pfsck) to avoid oom.Signed-off-by Wang Shilong <[email protected]>Signed-off-by Ritesh Harjani (IBM) <[email protected]>---
lib/ext2fs/ext2fs.h| 32 +++++++++++++++++++++++++++++++-1 file changed, 31 insertions(+), 1 deletion(-)lib/ext2fs/ext2fs.h +0
-0
lib/ext2fs/ext2fs.h struct struct_ext2_filsys { · line 282
Quoted 4 lines
lib/ext2fs/ext2fs.h +1
-0@@ -279,10 +279,11 @@ struct struct_ext2_filsys {int cluster_ratio_bits;__u16 default_bitmap_type;__u16 pad; +__u32 fs_num_threads;
From later cleanup patch, fs_num_threads should just use "__u16 pad" field.
Otherwise, looks OK.
Quoted 45 lines
lib/ext2fs/ext2fs.h +30
-2/* * Reserved for future expansion */ -__u32 reserved[5 ]; +__u32 reserved[4 ];/* * Reserved for the use of the calling application. @@ -2231,6 +2232,35 @@ ext2fs_orphan_block_tail(ext2_filsys fs, char *buf) sizeof(struct ext4_orphan_block_tail)); } +static dgrp_t ext2fs_get_avg_group (ext2_filsys fs) +{ +#ifdef HAVE_PTHREAD +dgrp_t average_group; +unsigned flexbg_size; + +if (fs->fs_num_threads <=1 ) +return fs->group_desc_count; + + average_group = fs->group_desc_count / fs->fs_num_threads; +if (average_group <=1 ) +return 1 ; + +if (ext2fs_has_feature_flex_bg (fs->super)) { +int times =1 ; + + flexbg_size =1 << fs->super->s_log_groups_per_flex; +if (average_group % flexbg_size) { + times = average_group / flexbg_size; + average_group = times * flexbg_size; + } + } + +return average_group; +#else +return fs->group_desc_count; +#endif +} +#undef _INLINE_#endif --
Quoted 2 lines
2.37.3
Cheers, Andreas
Re: [RFCv1 21/72] e2fsck: add -m option for multithread
In reply to Ritesh Harjani (IBM)Quoted 10 lines · Ritesh Harjani (IBM)
From: Li Xi <[email protected]>
-m option is added but no actual functionality is added. This patch only adds the logic that when -m is specified, one of
(quoted diff) +0
-2-p/-y/-n options should be specified. And when -m is specified, -C shouldn't be specified and the completion progress report won'tbe triggered by sending SIGUSR1/SIGUSR2 signals. This simplifies the implementation of multi-thread fsck in the future.
Quoted 7 lines
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.
Signed-off-by Li Xi <[email protected]>Signed-off-by Wang Shilong <[email protected]>Signed-off-by Ritesh Harjani (IBM) <[email protected]>
Minor nit below, but looks OK otherwise:
e2fsck/unix.c static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) · line 859
Quoted 11 lines
e2fsck/unix.c +2
-1@@ -854,7 +855,8 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) phys_mem_kb =get_memory_size () /1024 ; ctx->readahead_kb = ~0ULL ; -while ((c =getopt (argc, argv,"panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDkz:" )) !=EOF ) + +while ((c =getopt (argc, argv,"pamnyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDkz:" )) !=EOF )
I find it easier to find/add options when these are sorted in alphabetical order, but that is not solely the fault of this patch. At least 'm' is added in order relative to most other lower-case options.
Cheers, Andreas
Theodore Ts'o
AppliedRe: [RFCv1 01/72] e2fsck: Fix unbalanced mutex unlock for BOUNCE_MTX
In reply to Ritesh Harjani (IBM)Quoted 6 lines · Ritesh Harjani (IBM)
f_crashdisktest failed with UNIX_IO_FORCE_BOUNCE=yes due to unbalanced mutex unlock in below path.This patch fixes it.
Signed-off-by Ritesh Harjani (IBM) <[email protected]>
Applied, thanks.
- Ted
Re: [RFCv1 02/72] gen_bitmaps: Fix ext2fs_compare_generic_bmap/bitmap logic
In reply to Andreas DilgerQuoted 10 lines · Andreas Dilger
Quoted 9 lines · Ritesh Harjani (IBM)
Currently this function was not correctly comparing against the right length of the bitmap. Also when we compare bitarray v/s rbtree bitmap the value returned by
ext2fs_test_generic_bmap()could be different in these two implementations. Hence only check against boolean value.Signed-off-by Ritesh Harjani (IBM) <[email protected]>---
lib/ext2fs/gen_bitmap.c| 9 ++++++---
The gen_bitmap.c file supports only the original 32-bit bitmaps, so there is not rbtree bitmap. That's why using memcmp is safe, and as near as I can tell, no changes are needed for the lib/ext2fs/gen_bitmap.c
Quoted 10 lines
lib/ext2fs/gen_bitmap64.c errcode_t ext2fs_compare_generic_bmap(errcode_t neq, · line 629
Quoted 6 lines
lib/ext2fs/gen_bitmap64.c +0
-0@@ -629,10 +629,14 @@ errcode_t ext2fs_compare_generic_bmap(errcode_t neq, (bm1->end != bm2->end))Conversely, *this* version of the function is *not* doing the
memcmp()of the bulk of the bitmap contents, so it would appear to have a bug that the patch fixes, but in a very slow manner. It would be better to usememcmp().
This is where we have a problem, and the reason why we can't use memcmp is because in the case where the bitmap is really encoded using an rbtree, a memcmp isn't applicable.
We *could* extract the bitmap into a bitarray, but that would require allocating memory, and in the case of a very large file system/bitmap, especially when running on a 32-bit NAS box, we might not be able to *afford* to allocate that much memory (or it might not even be addressable :-).
So yes, we need a fix here, and yes, comparing bit by bit is very slow. Fortunately, from what I can tell, no one is actually calling this function, which is why no once noticed that the 64-bit compare bitmap fucntion was totally hosed.
So applying Ritesh's fix here makes sense, since it at least fixes the obvious problems. In the long term, we should probably add proper unit regression tests so can test whether or not this function is actually working correctly, and if we *want* a faster version of it, we could do something faster in the case where both bitmaps are the same type (e.g., both bitarrays or both rbtrees), and if they could do something where we look for "runs" where all of the bits are all set or not set, and then compare that against the other bitmap, etc. But given that we don't have anyusers of this function any more (we used to, but it disappeared when we optimzied e2fsck's pass5 implementation), that's probably not an urgent fix.
- Ted