Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EROFS support of TurboOCI-apply #321

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/overlaybd/tar/tarerofs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)

#define LSMT_ALIGNMENT 512

int TarErofs::extract_all() {
ssize_t read;
struct stat st;
Expand All @@ -44,7 +46,7 @@ int TarErofs::extract_all() {
return -1;
}

if (fs_base_file->fstat(&st)>= 0 && st.st_blocks > 0) {
if (!first_layer) {
int fd = mkstemp(base_path);
if (fd < 0) {
LOG_ERROR("cannot generate a temporary file to dump overlaybd disk");
Expand All @@ -53,11 +55,12 @@ int TarErofs::extract_all() {
std::strcat(command_line, " --base ");
std::strcat(command_line, base_path);

if (fs_base_file->pread(&metasize, sizeof(metasize), 0) !=
sizeof(metasize)) {
// lsmt.pread should align to 512
if (fs_base_file->pread(&buf, LSMT_ALIGNMENT, 0) != LSMT_ALIGNMENT) {
LOG_ERROR("failed to read EROFS metadata size");
return -1;
}
metasize = *(uint64_t *)buf;

while (metasize) {
int count = std::min(sizeof(buf), metasize);
Expand Down Expand Up @@ -89,6 +92,9 @@ int TarErofs::extract_all() {
}
status = pclose(fp);

if (!first_layer)
unlink(base_path);

if (read < 0 || status) {
return -1;
}
Expand All @@ -110,10 +116,8 @@ int TarErofs::extract_all() {
read = -1;
break;
}
metasize += read;
}


/* write mapfile */
fp = fopen("upper.map", "r");
if (fp == NULL) {
Expand Down
5 changes: 3 additions & 2 deletions src/overlaybd/tar/tarerofs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
class TarErofs {
public:
TarErofs(photon::fs::IFile *file, photon::fs::IFile *target, uint64_t fs_blocksize = 4096,
photon::fs::IFile *bf = nullptr, bool meta_only = true)
: file(file), fout(target), fs_base_file(bf), meta_only(meta_only) {}
photon::fs::IFile *bf = nullptr, bool meta_only = true, bool first_layer = true)
: file(file), fout(target), fs_base_file(bf), meta_only(meta_only), first_layer(first_layer) {}

int extract_all();

Expand All @@ -31,6 +31,7 @@ class TarErofs {
photon::fs::IFile *fout = nullptr; // target
photon::fs::IFile *fs_base_file = nullptr;
bool meta_only;
bool first_layer;
std::set<std::string> unpackedPaths;
std::list<std::pair<std::string, int>> dirs; // <path, utime>
};
8 changes: 7 additions & 1 deletion src/tools/turboOCI-apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ int main(int argc, char **argv) {
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 TarErofs(src_file, imgfile, 4096, base_file, true);
new TarErofs(src_file, imgfile, 4096, base_file, true, cfg.lowers().size() == 0);

if (tar->extract_all() < 0) {
fprintf(stderr, "failed to extract\n");
Expand Down
Loading