Skip to content

Commit 232febb

Browse files
WaberZhuanghsiangkao
authored andcommitted
Fix EROFS support of TurboOCI-apply
- Correct the bottom layer check; - Fix up pread() alignment issue. Signed-off-by: zhuangbowei.zbw <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent 8fbcd89 commit 232febb

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/overlaybd/tar/tarerofs.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#define __stringify_1(x...) #x
2626
#define __stringify(x...) __stringify_1(x)
2727

28+
#define LSMT_ALIGNMENT 512
29+
2830
int TarErofs::extract_all() {
2931
ssize_t read;
3032
struct stat st;
@@ -44,7 +46,7 @@ int TarErofs::extract_all() {
4446
return -1;
4547
}
4648

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

56-
if (fs_base_file->pread(&metasize, sizeof(metasize), 0) !=
57-
sizeof(metasize)) {
58+
// lsmt.pread should align to 512
59+
if (fs_base_file->pread(&buf, LSMT_ALIGNMENT, 0) != LSMT_ALIGNMENT) {
5860
LOG_ERROR("failed to read EROFS metadata size");
5961
return -1;
6062
}
63+
metasize = *(uint64_t *)buf;
6164

6265
while (metasize) {
6366
int count = std::min(sizeof(buf), metasize);
@@ -89,6 +92,9 @@ int TarErofs::extract_all() {
8992
}
9093
status = pclose(fp);
9194

95+
if (!first_layer)
96+
unlink(base_path);
97+
9298
if (read < 0 || status) {
9399
return -1;
94100
}
@@ -110,10 +116,8 @@ int TarErofs::extract_all() {
110116
read = -1;
111117
break;
112118
}
113-
metasize += read;
114119
}
115120

116-
117121
/* write mapfile */
118122
fp = fopen("upper.map", "r");
119123
if (fp == NULL) {

src/overlaybd/tar/tarerofs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
class TarErofs {
2222
public:
2323
TarErofs(photon::fs::IFile *file, photon::fs::IFile *target, uint64_t fs_blocksize = 4096,
24-
photon::fs::IFile *bf = nullptr, bool meta_only = true)
25-
: file(file), fout(target), fs_base_file(bf), meta_only(meta_only) {}
24+
photon::fs::IFile *bf = nullptr, bool meta_only = true, bool first_layer = true)
25+
: file(file), fout(target), fs_base_file(bf), meta_only(meta_only), first_layer(first_layer) {}
2626

2727
int extract_all();
2828

@@ -31,6 +31,7 @@ class TarErofs {
3131
photon::fs::IFile *fout = nullptr; // target
3232
photon::fs::IFile *fs_base_file = nullptr;
3333
bool meta_only;
34+
bool first_layer;
3435
std::set<std::string> unpackedPaths;
3536
std::list<std::pair<std::string, int>> dirs; // <path, utime>
3637
};

src/tools/turboOCI-apply.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ int main(int argc, char **argv) {
129129
if (fstype == "erofs") {
130130
photon::fs::IFile* base_file = raw ? nullptr : ((ImageFile *)imgfile)->get_base();
131131

132+
ImageConfigNS::ImageConfig cfg;
133+
if (!cfg.ParseJSON(image_config_path)) {
134+
fprintf(stderr, "failed to parse image config\n");
135+
exit(-1);
136+
}
137+
132138
auto tar =
133-
new TarErofs(src_file, imgfile, 4096, base_file, true);
139+
new TarErofs(src_file, imgfile, 4096, base_file, true, cfg.lowers().size() == 0);
134140

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

0 commit comments

Comments
 (0)