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

enhance tar/zfile checking #253

Merged
merged 1 commit into from
Aug 24, 2023
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
3 changes: 2 additions & 1 deletion src/overlaybd/lsmt/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ void *do_parallel_load_index(void *param) {
return nullptr;
}
auto file = job->get_file();
LOG_INFO("check file if normalfile or LSMTFile");
LOG_INFO("check `-th file is normal file or LSMT file", job->i);
IMemoryIndex *pi = nullptr;
LSMT::SegmentMapping *p = nullptr;
auto type = file->ioctl(IFileRO::GetType);
Expand Down Expand Up @@ -1560,6 +1560,7 @@ void *do_parallel_load_index(void *param) {
LOG_ERROR_RETURN(0, nullptr, "failed to create memory index!");
}
job->set_index(pi);
LOG_INFO("load index from `-th file done", job->i);
}
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/overlaybd/registryfs/registryfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class RegistryFileImpl : public photon::fs::VirtualReadOnlyFile {
LOG_WARN("failed to perform HTTP GET, going to retry ", VALUE(code), VALUE(offset),
VALUE(count), VALUE(ret_len), eno);

photon::thread_usleep(1000);
photon::thread_usleep(10000);
goto again;
} else {
LOG_ERROR_RETURN(ENOENT, -1, "failed to perform HTTP GET ", VALUE(m_url),
Expand Down
24 changes: 16 additions & 8 deletions src/overlaybd/tar/tar_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,20 +301,23 @@ class TarFs : public ForwardFS_Ownership {

int is_tar_file(IFile *file) {
TarHeader th_buf;
if (file->pread(&th_buf, T_BLOCKSIZE, 0) != T_BLOCKSIZE) {
LOG_DEBUG("error read tar file header");
auto ret = file->pread(&th_buf, T_BLOCKSIZE, 0);
if (ret < 0) {
LOG_ERROR_RETURN(0, -1, "read tar file header failed");
} else if (ret != T_BLOCKSIZE) {
LOG_WARN("read tar file header error, expect `, ret `", T_BLOCKSIZE, ret);
return 0;
}
if (strncmp(th_buf.magic, TMAGIC, TMAGLEN - 1) != 0) {
LOG_DEBUG("unknown magic value in tar header");
LOG_INFO("unknown magic value in tar header");
return 0;
}
if (strncmp(th_buf.version, TVERSION, TVERSLEN) != 0) {
LOG_DEBUG("unknown version value in tar header");
LOG_INFO("unknown version value in tar header");
return 0;
}
if (!th_buf.crc_ok()) {
LOG_DEBUG("tar header checksum error");
LOG_INFO("tar header checksum error");
return 0;
}
return 1;
Expand All @@ -329,11 +332,16 @@ IFile *new_tar_file(IFile *file, bool create) {
}

IFile *open_tar_file(IFile *file) {
if (is_tar_file(file) == 1) {
auto ret = is_tar_file(file);
if (ret == 1) {
LOG_INFO("open file as tar file");
return new_tar_file(file);
} else if (ret == 0) {
LOG_INFO("open file as normal file");
return file;
} else {
LOG_ERROR_RETURN(0, nullptr, "open tar file failed");
}
LOG_DEBUG("not tar file, open as normal file");
return file; // open as normal file
}

IFileSystem *new_tar_fs_adaptor(IFileSystem *fs) {
Expand Down
3 changes: 3 additions & 0 deletions src/overlaybd/zfile/zfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,9 @@ int zfile_validation_check(IFile *src) {
}

int is_zfile(IFile *file) {
if (!file) {
LOG_ERROR_RETURN(0, -1, "file is nullptr.");
}
char buf[CompressionFile::HeaderTrailer::SPACE];
auto ret = file->pread(buf, CompressionFile::HeaderTrailer::SPACE, 0);
if (ret < (ssize_t)CompressionFile::HeaderTrailer::SPACE)
Expand Down
6 changes: 6 additions & 0 deletions src/switch_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ static IFile *try_open_zfile(IFile *file, bool verify, const char *file_path) {
LOG_ERROR_RETURN(0, nullptr, "zfile_open_ro failed, path: `: error: `(`)", file_path,
errno, strerror(errno));
}
LOG_INFO("open file as zfile");
return zf;
}
LOG_INFO("file is not zfile format");
return file;
}

Expand Down Expand Up @@ -83,6 +85,10 @@ class SwitchFile : public ISwitchFile {
}

file = try_open_zfile(new_tar_file_adaptor(file), false, m_filepath.c_str());
if (file == nullptr) {
LOG_ERROR("failed to open commit file as zfile, path: `", m_filepath);
return;
}
LOG_INFO("switch to localfile '`' success.", m_filepath);
m_local_file = file;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/overlaybd-zfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ IFileSystem *lfs = nullptr;

int verify_crc(IFile* src_file) {

if (!is_zfile(src_file)) {
if (is_zfile(src_file) != 1) {
fprintf(stderr, "format error! <source_file> should be a zfile.\n");
exit(-1);
}
Expand Down