Skip to content

Commit

Permalink
Merge pull request #257 from yuchen0cc/main
Browse files Browse the repository at this point in the history
refactor some logs
  • Loading branch information
liulanzheng authored Aug 25, 2023
2 parents b2c803d + 0d835b1 commit 0b3d978
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 43 deletions.
3 changes: 1 addition & 2 deletions src/bk_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ bool BkDownload::download_done() {

int ret = lfs->rename(old_name.c_str(), new_name.c_str());
if (ret != 0) {
LOG_ERROR("rename(`,`), `:`", old_name, new_name, errno, strerror(errno));
return false;
LOG_ERRNO_RETURN(0, false, "rename(`,`) failed", old_name, new_name);
}
LOG_INFO("download verify done. rename(`,`) success", old_name, new_name);
return true;
Expand Down
12 changes: 5 additions & 7 deletions src/image_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ IFile *ImageFile::__open_ro_file(const std::string &path) {
auto file = open_localfile_adaptor(path.c_str(), flags, 0644, ioengine);
if (!file) {
set_failed("failed to open local file " + path);
LOG_ERROR_RETURN(0, nullptr, "open(`),`:`", path, errno, strerror(errno));
LOG_ERRNO_RETURN(0, nullptr, "open(`) failed", path);
}

if (flags & O_DIRECT) {
Expand All @@ -67,8 +67,7 @@ IFile *ImageFile::__open_ro_file(const std::string &path) {
if (!aligned_file) {
set_failed("failed to open aligned_file_adaptor " + path);
delete file;
LOG_ERROR_RETURN(0, nullptr, "new_aligned_file_adaptor(`) failed, `:`", path, errno,
strerror(errno));
LOG_ERRNO_RETURN(0, nullptr, "new_aligned_file_adaptor(`) failed", path);
}
file = aligned_file;
}
Expand All @@ -77,8 +76,7 @@ IFile *ImageFile::__open_ro_file(const std::string &path) {
if (!switch_file) {
set_failed("failed to open switch file `" + path);
delete file;
LOG_ERROR_RETURN(0, nullptr, "new_switch_file(`) failed, `,:`", path, errno,
strerror(errno));
LOG_ERRNO_RETURN(0, nullptr, "new_switch_file(`) failed", path);
}
file = switch_file;

Expand All @@ -89,7 +87,7 @@ IFile *ImageFile::__open_ro_target_file(const std::string &path) {
auto file = open_localfile_adaptor(path.c_str(), O_RDONLY, 0644, 0);
if (!file) {
set_failed("failed to open local data file " + path);
LOG_ERROR_RETURN(0, nullptr, "open(`),`:`", path, errno, strerror(errno));
LOG_ERRNO_RETURN(0, nullptr, "open(`) failed", path);
}
return file;
}
Expand Down Expand Up @@ -281,7 +279,7 @@ int ImageFile::open_lower_layer(IFile *&file, ImageConfigNS::LayerConfig &layer,
auto gz_index = open_localfile_adaptor(layer.gzipIndex().c_str(), O_RDONLY, 0644, 0);
if (!gz_index) {
set_failed("failed to open gzip index " + layer.gzipIndex());
LOG_ERROR_RETURN(0, -1, "open(`),`:`", layer.gzipIndex(), errno, strerror(errno));
LOG_ERRNO_RETURN(0, -1, "open(`) failed", layer.gzipIndex());
}
target_file = new_gzfile(target_file, gz_index, true);
if (image_service.global_conf.gzipCacheConfig().enable() && layer.targetDigest() != "") {
Expand Down
6 changes: 2 additions & 4 deletions src/overlaybd/extfs/extfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ ext2_filsys do_ext2fs_open(io_manager extfs_manager) {
);
if (ret) {
errno = -parse_extfs_error(nullptr, 0, ret);
LOG_ERROR("failed ext2fs_open, errno `:`", errno, strerror(errno));
return nullptr;
LOG_ERRNO_RETURN(0, nullptr, "failed ext2fs_open");
}
ret = ext2fs_read_bitmaps(fs);
if (ret) {
errno = -parse_extfs_error(fs, 0, ret);
LOG_ERROR("failed ext2fs_read_bitmaps, errno `:`", errno, strerror(errno));
ext2fs_close(fs);
return nullptr;
LOG_ERRNO_RETURN(0, nullptr, "failed ext2fs_read_bitmaps");
}
LOG_INFO("ext2fs opened");
return fs;
Expand Down
32 changes: 10 additions & 22 deletions src/overlaybd/tar/libtar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ int UnTar::set_file_perms(const char *filename) {
/* change owner/group */
if (geteuid() == 0) {
if (fs->lchown(filename, uid, gid) == -1) {
LOG_ERROR("lchown failed, filename `, `", filename, strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "lchown failed, filename `, uid `, gid `", filename, uid, gid);
}
}

/* change access/modification time */
if (fs->lutimes(filename, tv) == -1) {
LOG_ERROR("lutimes failed, filename `, `", filename, strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "lutimes failed, filename `", filename);
}

/* change permissions */
Expand All @@ -69,8 +67,7 @@ int UnTar::set_file_perms(const char *filename) {
return 0;
}
if (fs->chmod(filename, mode) == -1) {
LOG_ERROR("chmod failed `", strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "chmod failed, filename `, mode `", filename, mode);
}

return 0;
Expand All @@ -95,8 +92,7 @@ int UnTar::extract_all() {

while ((i = read_header()) == 0) {
if (extract_file() != 0) {
LOG_ERROR("extract failed, filename `, `", get_pathname(), strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "extract failed, filename `", get_pathname());
}
if (TH_ISDIR(header)) {
dirs.emplace_back(std::make_pair(std::string(get_pathname()), header.get_mtime()));
Expand All @@ -111,8 +107,7 @@ int UnTar::extract_all() {
tv[0].tv_sec = tv[1].tv_sec = dir.second;
tv[0].tv_usec = tv[1].tv_usec = 0;
if (fs->lutimes(path.c_str(), tv) == -1) {
LOG_ERROR("utime failed, filename `, `", dir.first.c_str(), strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "utime failed, filename `", dir.first.c_str());
}
}

Expand Down Expand Up @@ -151,15 +146,11 @@ int UnTar::extract_file() {
} else {
if (!S_ISDIR(s.st_mode)) {
if (fs->unlink(npath.c_str()) == -1 && errno != ENOENT) {
LOG_ERROR("remove exist file ` failed, `", npath.c_str(), strerror(errno));
errno = EEXIST;
return -1;
LOG_ERRNO_RETURN(EEXIST, -1, "remove exist file ` failed", npath.c_str());
}
} else if (!TH_ISDIR(header)) {
if (remove_all(npath) == -1) {
LOG_ERROR("remove exist dir ` failed, `", npath.c_str(), strerror(errno));
errno = EEXIST;
return -1;
LOG_ERRNO_RETURN(EEXIST, -1, "remove exist dir ` failed", npath.c_str());
}
}
}
Expand Down Expand Up @@ -290,8 +281,7 @@ int UnTar::extract_hardlink(const char *filename) {
char *linktgt = get_linkname();
LOG_DEBUG(" ==> extracting: ` (link to `)", filename, linktgt);
if (fs->link(linktgt, filename) == -1) {
LOG_ERROR("link failed, `", strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "link failed, filename `, linktgt `", filename, linktgt);
}
return 0;
}
Expand All @@ -300,8 +290,7 @@ int UnTar::extract_symlink(const char *filename) {
char *linktgt = get_linkname();
LOG_DEBUG(" ==> extracting: ` (symlink to `)", filename, linktgt);
if (fs->symlink(linktgt, filename) == -1) {
LOG_ERROR("symlink failed, `", strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "symlink failed, filename `, linktgt `", filename, linktgt);
}
return 0;
}
Expand All @@ -327,8 +316,7 @@ int UnTar::extract_block_char_fifo(const char *filename) {

LOG_DEBUG(" ==> extracting: ` (block/char/fifo `,`)", filename, devmaj, devmin);
if (fs->mknod(filename, mode, makedev(devmaj, devmin)) == -1) {
LOG_ERROR("block/char/fifo failed, `", strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "block/char/fifo failed, filename `", filename);
}

return 0;
Expand Down
3 changes: 3 additions & 0 deletions src/overlaybd/tar/tar_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ IFile *new_tar_file(IFile *file, bool create) {
}

IFile *open_tar_file(IFile *file) {
if (!file) {
LOG_ERROR_RETURN(0, nullptr, "file is nullptr");
}
auto ret = is_tar_file(file);
if (ret == 1) {
LOG_INFO("open file as tar file");
Expand Down
6 changes: 2 additions & 4 deletions src/overlaybd/tar/whiteout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ int UnTar::remove_all(const std::string &path, bool rmdir) {
return 0;
}
} else {
LOG_ERROR("get path ` stat failed, errno `:`", path, errno, strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "get path ` stat failed", path);
}

auto dirs = fs->opendir(path.c_str());
if (dirs == nullptr) {
LOG_ERROR("open dir ` failed, errno `:`", path, errno, strerror(errno));
return -1;
LOG_ERRNO_RETURN(0, -1, "open dir ` failed", path);
}
dirent *dirInfo;
while ((dirInfo = dirs->get()) != nullptr) {
Expand Down
7 changes: 3 additions & 4 deletions src/switch_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ static IFile *try_open_zfile(IFile *file, bool verify, const char *file_path) {
if (is_zfile == 1) {
auto zf = ZFile::zfile_open_ro(file, verify, true);
if (!zf) {
LOG_ERROR_RETURN(0, nullptr, "zfile_open_ro failed, path: `: error: `(`)", file_path,
errno, strerror(errno));
LOG_ERRNO_RETURN(0, nullptr, "zfile_open_ro failed, path: `", file_path);
}
LOG_INFO("open file as zfile");
LOG_INFO("open file as zfile format, path: `", file_path);
return zf;
}
LOG_INFO("file is not zfile format");
LOG_INFO("file is not zfile format, path: `", file_path);
return file;
}

Expand Down

0 comments on commit 0b3d978

Please sign in to comment.