Skip to content

Commit c7e6024

Browse files
authored
Merge pull request #159 from HileQAQ/errlog
Enhance log
2 parents 50fe7e4 + 90c7f04 commit c7e6024

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/image_file.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,24 @@ IFile *ImageFile::__open_ro_remote(const std::string &dir, const std::string &di
9999
LOG_DEBUG("open file from remotefs: `, size: `", url, size);
100100
IFile *remote_file = image_service.global_fs.remote_fs->open(url.c_str(), O_RDONLY);
101101
if (!remote_file) {
102-
if (errno == EPERM)
103-
set_auth_failed();
104-
else
105-
set_failed("failed to open remote file " + url);
106-
LOG_ERROR_RETURN(0, nullptr, "failed to open remote file `", url);
102+
std::string err_msg = "failed to open remote file " + url + ": ";
103+
if (errno == EPERM || errno == EACCES) {
104+
err_msg += "Authentication failed";
105+
} else if (errno == ENOTCONN) {
106+
err_msg += "Connection failed";
107+
} else if (errno == ETIMEDOUT) {
108+
err_msg += "Get meta timedout";
109+
} else if (errno == ENOENT) {
110+
err_msg += "No such file or directory";
111+
} else if (errno == EBUSY) {
112+
err_msg += "Too many requests";
113+
} else if (errno == EIO) {
114+
err_msg += "Unexpected response";
115+
} else {
116+
err_msg += std::string(strerror(errno));
117+
}
118+
set_failed(err_msg);
119+
LOG_ERRNO_RETURN(0, nullptr, err_msg);
107120
}
108121

109122
ISwitchFile *switch_file = new_switch_file(remote_file);

src/overlaybd/registryfs/registryfs.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,16 +432,18 @@ class RegistryFileImpl : public photon::fs::VirtualReadOnlyFile {
432432
auto code = m_fs->GET(m_url.c_str(), &headers, -1, -1, nullptr, tmo.timeout());
433433
if (code != 200 && code != 206) {
434434
if (tmo.expire() < photon::now)
435-
LOG_ERROR_RETURN(ETIMEDOUT, -1, "get meta timedout");
436-
435+
LOG_ERROR_RETURN(ETIMEDOUT, -1, "Get meta timedout");
436+
if (retry--)
437+
goto again;
437438
if (code == 401 || code == 403) {
438-
if (retry--)
439-
goto again;
440439
LOG_ERROR_RETURN(EPERM, -1, "Authorization failed");
440+
} else if (code == 404) {
441+
LOG_ERROR_RETURN(ENOENT, -1, "No such file or directory");
442+
} else if (code == 429) {
443+
LOG_ERROR_RETURN(EBUSY, -1, "Too many request");
444+
} else {
445+
LOG_ERROR_RETURN(ENOENT, -1, "failed to get meta from server");
441446
}
442-
if (retry--)
443-
goto again;
444-
LOG_ERROR_RETURN(ENOENT, -1, "failed to get meta from server");
445447
}
446448
char buffer[64];
447449
uint64_t ret = 0;

0 commit comments

Comments
 (0)