Skip to content

Commit 0d835b1

Browse files
committed
refactor some logs
Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>
1 parent b2c803d commit 0d835b1

File tree

7 files changed

+26
-43
lines changed

7 files changed

+26
-43
lines changed

src/bk_download.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ bool BkDownload::download_done() {
128128

129129
int ret = lfs->rename(old_name.c_str(), new_name.c_str());
130130
if (ret != 0) {
131-
LOG_ERROR("rename(`,`), `:`", old_name, new_name, errno, strerror(errno));
132-
return false;
131+
LOG_ERRNO_RETURN(0, false, "rename(`,`) failed", old_name, new_name);
133132
}
134133
LOG_INFO("download verify done. rename(`,`) success", old_name, new_name);
135134
return true;

src/image_file.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ IFile *ImageFile::__open_ro_file(const std::string &path) {
5858
auto file = open_localfile_adaptor(path.c_str(), flags, 0644, ioengine);
5959
if (!file) {
6060
set_failed("failed to open local file " + path);
61-
LOG_ERROR_RETURN(0, nullptr, "open(`),`:`", path, errno, strerror(errno));
61+
LOG_ERRNO_RETURN(0, nullptr, "open(`) failed", path);
6262
}
6363

6464
if (flags & O_DIRECT) {
@@ -67,8 +67,7 @@ IFile *ImageFile::__open_ro_file(const std::string &path) {
6767
if (!aligned_file) {
6868
set_failed("failed to open aligned_file_adaptor " + path);
6969
delete file;
70-
LOG_ERROR_RETURN(0, nullptr, "new_aligned_file_adaptor(`) failed, `:`", path, errno,
71-
strerror(errno));
70+
LOG_ERRNO_RETURN(0, nullptr, "new_aligned_file_adaptor(`) failed", path);
7271
}
7372
file = aligned_file;
7473
}
@@ -77,8 +76,7 @@ IFile *ImageFile::__open_ro_file(const std::string &path) {
7776
if (!switch_file) {
7877
set_failed("failed to open switch file `" + path);
7978
delete file;
80-
LOG_ERROR_RETURN(0, nullptr, "new_switch_file(`) failed, `,:`", path, errno,
81-
strerror(errno));
79+
LOG_ERRNO_RETURN(0, nullptr, "new_switch_file(`) failed", path);
8280
}
8381
file = switch_file;
8482

@@ -89,7 +87,7 @@ IFile *ImageFile::__open_ro_target_file(const std::string &path) {
8987
auto file = open_localfile_adaptor(path.c_str(), O_RDONLY, 0644, 0);
9088
if (!file) {
9189
set_failed("failed to open local data file " + path);
92-
LOG_ERROR_RETURN(0, nullptr, "open(`),`:`", path, errno, strerror(errno));
90+
LOG_ERRNO_RETURN(0, nullptr, "open(`) failed", path);
9391
}
9492
return file;
9593
}
@@ -281,7 +279,7 @@ int ImageFile::open_lower_layer(IFile *&file, ImageConfigNS::LayerConfig &layer,
281279
auto gz_index = open_localfile_adaptor(layer.gzipIndex().c_str(), O_RDONLY, 0644, 0);
282280
if (!gz_index) {
283281
set_failed("failed to open gzip index " + layer.gzipIndex());
284-
LOG_ERROR_RETURN(0, -1, "open(`),`:`", layer.gzipIndex(), errno, strerror(errno));
282+
LOG_ERRNO_RETURN(0, -1, "open(`) failed", layer.gzipIndex());
285283
}
286284
target_file = new_gzfile(target_file, gz_index, true);
287285
if (image_service.global_conf.gzipCacheConfig().enable() && layer.targetDigest() != "") {

src/overlaybd/extfs/extfs.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ ext2_filsys do_ext2fs_open(io_manager extfs_manager) {
5757
);
5858
if (ret) {
5959
errno = -parse_extfs_error(nullptr, 0, ret);
60-
LOG_ERROR("failed ext2fs_open, errno `:`", errno, strerror(errno));
61-
return nullptr;
60+
LOG_ERRNO_RETURN(0, nullptr, "failed ext2fs_open");
6261
}
6362
ret = ext2fs_read_bitmaps(fs);
6463
if (ret) {
6564
errno = -parse_extfs_error(fs, 0, ret);
66-
LOG_ERROR("failed ext2fs_read_bitmaps, errno `:`", errno, strerror(errno));
6765
ext2fs_close(fs);
68-
return nullptr;
66+
LOG_ERRNO_RETURN(0, nullptr, "failed ext2fs_read_bitmaps");
6967
}
7068
LOG_INFO("ext2fs opened");
7169
return fs;

src/overlaybd/tar/libtar.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ int UnTar::set_file_perms(const char *filename) {
4444
/* change owner/group */
4545
if (geteuid() == 0) {
4646
if (fs->lchown(filename, uid, gid) == -1) {
47-
LOG_ERROR("lchown failed, filename `, `", filename, strerror(errno));
48-
return -1;
47+
LOG_ERRNO_RETURN(0, -1, "lchown failed, filename `, uid `, gid `", filename, uid, gid);
4948
}
5049
}
5150

5251
/* change access/modification time */
5352
if (fs->lutimes(filename, tv) == -1) {
54-
LOG_ERROR("lutimes failed, filename `, `", filename, strerror(errno));
55-
return -1;
53+
LOG_ERRNO_RETURN(0, -1, "lutimes failed, filename `", filename);
5654
}
5755

5856
/* change permissions */
@@ -69,8 +67,7 @@ int UnTar::set_file_perms(const char *filename) {
6967
return 0;
7068
}
7169
if (fs->chmod(filename, mode) == -1) {
72-
LOG_ERROR("chmod failed `", strerror(errno));
73-
return -1;
70+
LOG_ERRNO_RETURN(0, -1, "chmod failed, filename `, mode `", filename, mode);
7471
}
7572

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

9693
while ((i = read_header()) == 0) {
9794
if (extract_file() != 0) {
98-
LOG_ERROR("extract failed, filename `, `", get_pathname(), strerror(errno));
99-
return -1;
95+
LOG_ERRNO_RETURN(0, -1, "extract failed, filename `", get_pathname());
10096
}
10197
if (TH_ISDIR(header)) {
10298
dirs.emplace_back(std::make_pair(std::string(get_pathname()), header.get_mtime()));
@@ -111,8 +107,7 @@ int UnTar::extract_all() {
111107
tv[0].tv_sec = tv[1].tv_sec = dir.second;
112108
tv[0].tv_usec = tv[1].tv_usec = 0;
113109
if (fs->lutimes(path.c_str(), tv) == -1) {
114-
LOG_ERROR("utime failed, filename `, `", dir.first.c_str(), strerror(errno));
115-
return -1;
110+
LOG_ERRNO_RETURN(0, -1, "utime failed, filename `", dir.first.c_str());
116111
}
117112
}
118113

@@ -151,15 +146,11 @@ int UnTar::extract_file() {
151146
} else {
152147
if (!S_ISDIR(s.st_mode)) {
153148
if (fs->unlink(npath.c_str()) == -1 && errno != ENOENT) {
154-
LOG_ERROR("remove exist file ` failed, `", npath.c_str(), strerror(errno));
155-
errno = EEXIST;
156-
return -1;
149+
LOG_ERRNO_RETURN(EEXIST, -1, "remove exist file ` failed", npath.c_str());
157150
}
158151
} else if (!TH_ISDIR(header)) {
159152
if (remove_all(npath) == -1) {
160-
LOG_ERROR("remove exist dir ` failed, `", npath.c_str(), strerror(errno));
161-
errno = EEXIST;
162-
return -1;
153+
LOG_ERRNO_RETURN(EEXIST, -1, "remove exist dir ` failed", npath.c_str());
163154
}
164155
}
165156
}
@@ -290,8 +281,7 @@ int UnTar::extract_hardlink(const char *filename) {
290281
char *linktgt = get_linkname();
291282
LOG_DEBUG(" ==> extracting: ` (link to `)", filename, linktgt);
292283
if (fs->link(linktgt, filename) == -1) {
293-
LOG_ERROR("link failed, `", strerror(errno));
294-
return -1;
284+
LOG_ERRNO_RETURN(0, -1, "link failed, filename `, linktgt `", filename, linktgt);
295285
}
296286
return 0;
297287
}
@@ -300,8 +290,7 @@ int UnTar::extract_symlink(const char *filename) {
300290
char *linktgt = get_linkname();
301291
LOG_DEBUG(" ==> extracting: ` (symlink to `)", filename, linktgt);
302292
if (fs->symlink(linktgt, filename) == -1) {
303-
LOG_ERROR("symlink failed, `", strerror(errno));
304-
return -1;
293+
LOG_ERRNO_RETURN(0, -1, "symlink failed, filename `, linktgt `", filename, linktgt);
305294
}
306295
return 0;
307296
}
@@ -327,8 +316,7 @@ int UnTar::extract_block_char_fifo(const char *filename) {
327316

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

334322
return 0;

src/overlaybd/tar/tar_file.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ IFile *new_tar_file(IFile *file, bool create) {
332332
}
333333

334334
IFile *open_tar_file(IFile *file) {
335+
if (!file) {
336+
LOG_ERROR_RETURN(0, nullptr, "file is nullptr");
337+
}
335338
auto ret = is_tar_file(file);
336339
if (ret == 1) {
337340
LOG_INFO("open file as tar file");

src/overlaybd/tar/whiteout.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ int UnTar::remove_all(const std::string &path, bool rmdir) {
5959
return 0;
6060
}
6161
} else {
62-
LOG_ERROR("get path ` stat failed, errno `:`", path, errno, strerror(errno));
63-
return -1;
62+
LOG_ERRNO_RETURN(0, -1, "get path ` stat failed", path);
6463
}
6564

6665
auto dirs = fs->opendir(path.c_str());
6766
if (dirs == nullptr) {
68-
LOG_ERROR("open dir ` failed, errno `:`", path, errno, strerror(errno));
69-
return -1;
67+
LOG_ERRNO_RETURN(0, -1, "open dir ` failed", path);
7068
}
7169
dirent *dirInfo;
7270
while ((dirInfo = dirs->get()) != nullptr) {

src/switch_file.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ static IFile *try_open_zfile(IFile *file, bool verify, const char *file_path) {
4646
if (is_zfile == 1) {
4747
auto zf = ZFile::zfile_open_ro(file, verify, true);
4848
if (!zf) {
49-
LOG_ERROR_RETURN(0, nullptr, "zfile_open_ro failed, path: `: error: `(`)", file_path,
50-
errno, strerror(errno));
49+
LOG_ERRNO_RETURN(0, nullptr, "zfile_open_ro failed, path: `", file_path);
5150
}
52-
LOG_INFO("open file as zfile");
51+
LOG_INFO("open file as zfile format, path: `", file_path);
5352
return zf;
5453
}
55-
LOG_INFO("file is not zfile format");
54+
LOG_INFO("file is not zfile format, path: `", file_path);
5655
return file;
5756
}
5857

0 commit comments

Comments
 (0)