Whamcloud - gitweb
e2fsck: merge dblist after thread finishes
authorLi Xi <lixi@ddn.com>
Thu, 5 Sep 2019 08:30:40 +0000 (16:30 +0800)
committerLi Dongyang <dongyangli@ddn.com>
Fri, 28 Apr 2023 00:43:50 +0000 (10:43 +1000)
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>
e2fsck/pass1.c
lib/ext2fs/dblist.c
lib/ext2fs/ext2fs.h

index 76b4275..cc58e45 100644 (file)
@@ -2314,12 +2314,14 @@ static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src)
        ext2fs_inode_bitmap inode_map;
        ext2fs_block_bitmap block_map;
        ext2_badblocks_list badblocks;
+       ext2_dblist dblist;
 
        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;
 
        memcpy(dest, src, sizeof(struct struct_ext2_filsys));
        dest->io = dest_io;
@@ -2328,6 +2330,7 @@ static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src)
        dest->inode_map = inode_map;
        dest->block_map = block_map;
        dest->badblocks = badblocks;
+       dest->dblist = dblist;
        if (dest->dblist)
                dest->dblist->fs = dest;
 
@@ -2346,6 +2349,19 @@ static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src)
        if (retval)
                goto out;
 
+       if (src->dblist) {
+               if (dest->dblist) {
+                       retval = ext2fs_merge_dblist(src->dblist,
+                                                    dest->dblist);
+                       if (retval)
+                               goto out;
+               } else {
+                       dest->dblist = src->dblist;
+                       dest->dblist->fs = dest;
+                       src->dblist = NULL;
+               }
+       }
+
        if (src->badblocks) {
                if (dest->badblocks == NULL)
                        retval = ext2fs_badblocks_copy(src->badblocks,
@@ -2362,6 +2378,9 @@ out:
                ext2fs_free_generic_bmap(src->block_map);
        if (src->badblocks)
                ext2fs_badblocks_list_free(src->badblocks);
+       if (src->dblist)
+               ext2fs_free_dblist(src->dblist);
+
        return retval;
 }
 
index bbdb221..1fdd8f4 100644 (file)
@@ -120,6 +120,42 @@ errcode_t ext2fs_copy_dblist(ext2_dblist src, ext2_dblist *dest)
 }
 
 /*
+ * Merge a directory block list @src to @dest
+ */
+errcode_t ext2fs_merge_dblist(ext2_dblist src, ext2_dblist dest)
+{
+       unsigned long long src_count = src->count;
+       unsigned long long dest_count = dest->count;
+       unsigned long long size = src_count + dest_count;
+       size_t size_entry = sizeof(struct ext2_db_entry2);
+       struct ext2_db_entry2 *array, *array2;
+       errcode_t retval;
+
+       if (src_count == 0)
+               return 0;
+
+       if (src->sorted || (dest->sorted && dest_count != 0))
+               return EINVAL;
+
+       retval = ext2fs_get_array(size, size_entry, &array);
+       if (retval)
+               return retval;
+
+       array2 = array;
+       memcpy(array, src->list, src_count * size_entry);
+       array += src_count;
+       memcpy(array, dest->list, dest_count * size_entry);
+       ext2fs_free_mem(&dest->list);
+
+       dest->list = array2;
+       dest->count = src_count + dest_count;
+       dest->size = size;
+       dest->sorted = 0;
+
+       return 0;
+}
+
+/*
  * Close a directory block list
  *
  * (moved to closefs.c)
index 83b4de6..fdc8f5b 100644 (file)
@@ -1147,6 +1147,7 @@ extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
                                      blk_t blk, int blockcnt);
 extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
                                       blk64_t blk, e2_blkcnt_t blockcnt);
+extern errcode_t ext2fs_merge_dblist(ext2_dblist src, ext2_dblist dest);
 extern void ext2fs_dblist_sort(ext2_dblist dblist,
                               EXT2_QSORT_TYPE (*sortfunc)(const void *,
                                                           const void *));