Skip to content

Commit

Permalink
Support Tar metaidx for EROFS
Browse files Browse the repository at this point in the history
So that `turboOCI-apply --import` can be used.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
  • Loading branch information
hsiangkao committed Jul 15, 2024
1 parent a2e8f00 commit 4863191
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/overlaybd/tar/erofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ include(FetchContent)

FetchContent_Declare(
erofs-utils
GIT_REPOSITORY https://gitee.com/anolis/erofs-utils.git
GIT_TAG 6ae5eb64136aeea90bda46d286af4628ea35d974
GIT_REPOSITORY git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git
GIT_TAG 617d708925b3c5d1dd132853e47d9d9f51443e6f
)

FetchContent_MakeAvailable(erofs-utils)
Expand Down Expand Up @@ -38,4 +38,4 @@ target_include_directories(erofs_lib PRIVATE
)

target_compile_options(erofs_lib PRIVATE "-include${EROFS_CONFIG_FILE}")
target_link_libraries(erofs_lib PRIVATE ${EROFS_LIB_STATIC})
target_link_libraries(erofs_lib PRIVATE ${EROFS_LIB_STATIC})
22 changes: 14 additions & 8 deletions src/overlaybd/tar/erofs/liberofs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "erofs/tar.h"
#include "erofs/io.h"
#include "erofs/cache.h"
#include "erofs/blobchunk.h"
#include "erofs/block_list.h"
#include "erofs/inode.h"
#include "erofs/config.h"
Expand Down Expand Up @@ -423,11 +424,6 @@ int erofs_mkfs(struct erofs_mkfs_cfg *cfg)
return -EINVAL;
}

if (!erofstar->rvsp_mode) {
LOG_ERROR("[erofs] Must be in RVSP mode.");
return -EINVAL;
}

if (!cfg->incremental) {
sbi->bmgr = erofs_buffer_init(sbi, 0);
if (!sbi->bmgr) {
Expand Down Expand Up @@ -475,6 +471,14 @@ int erofs_mkfs(struct erofs_mkfs_cfg *cfg)
goto exit;
}

if (!erofstar->rvsp_mode) {
err = erofs_mkfs_dump_blobs(sbi);
if (err) {
LOG_ERROR("[erofs] Fail to dump blob", err);
goto exit;
}
}

err = erofs_bflush(sbi->bmgr, NULL);
if (err) {
LOG_ERROR("[erofs] Bflush failed.");
Expand Down Expand Up @@ -521,7 +525,6 @@ static int erofs_init_tar(struct erofs_tarfile *erofstar,
{
erofstar->global.xattrs = LIST_HEAD_INIT(erofstar->global.xattrs);
erofstar->aufs = true;
erofstar->rvsp_mode = true;
erofstar->dev = rebuild_src_count + 1;

erofstar->ios.feof = false;
Expand Down Expand Up @@ -630,6 +633,9 @@ int LibErofs::extract_tar(photon::fs::IFile *source, bool meta_only, bool first_
goto exit;
}

erofstar.rvsp_mode = true;
if (ddtaridx)
erofstar.ddtaridx_mode = true;
cfg.sbi = &sbi;
cfg.erofstar = &erofstar;
cfg.incremental = !first_layer;
Expand All @@ -656,8 +662,8 @@ int LibErofs::extract_tar(photon::fs::IFile *source, bool meta_only, bool first_
return err;
}

LibErofs::LibErofs(photon::fs::IFile *target, uint64_t blksize)
: target(target), blksize(blksize)
LibErofs::LibErofs(photon::fs::IFile *target, uint64_t blksize, bool import_tar_headers)
: target(target), blksize(blksize), ddtaridx(import_tar_headers)
{
}

Expand Down
5 changes: 3 additions & 2 deletions src/overlaybd/tar/erofs/liberofs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include <photon/fs/fiemap.h>
#include <photon/common/string_view.h>

class LibErofs{
class LibErofs {
public:
LibErofs(photon::fs::IFile *target, uint64_t blksize);
LibErofs(photon::fs::IFile *target, uint64_t blksize, bool import_tar_headers = false);
~LibErofs();
int extract_tar(photon::fs::IFile *source, bool meta_only, bool first_layer);
private:
photon::fs::IFile * target= nullptr; /* output file */
uint64_t blksize;
bool ddtaridx;
};
#endif
4 changes: 1 addition & 3 deletions src/tools/turboOCI-apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,13 @@ int main(int argc, char **argv) {

// for now, buffer_file can't be used with turboOCI
if (fstype == "erofs") {
photon::fs::IFile* base_file = raw ? nullptr : ((ImageFile *)imgfile)->get_base();

ImageConfigNS::ImageConfig cfg;
if (!cfg.ParseJSON(image_config_path)) {
fprintf(stderr, "failed to parse image config\n");
exit(-1);
}

auto tar = new LibErofs(imgfile, 4096);
auto tar = new LibErofs(imgfile, 4096, import_tar_headers);
if (tar->extract_tar(src_file, true, cfg.lowers().size() == 0) < 0) {
fprintf(stderr, "failed to extract\n");
exit(-1);
Expand Down

0 comments on commit 4863191

Please sign in to comment.