Reduce error log by downgrading unnecessary error! to warn!

This commit is contained in:
ClawSeven 2023-12-21 11:38:37 +08:00 committed by volcano
parent 367fa9c4ce
commit 6c8c8fc871
3 changed files with 29 additions and 15 deletions

@ -437,12 +437,12 @@ fn parse_host_files(file_buffer: *const host_file_buffer) -> Result<i32> {
let resolv_conf_ptr = unsafe { (*file_buffer).resolv_conf_buf };
match parse_host_file(HostFile::ResolvConf, resolv_conf_ptr) {
Err(e) => {
error!("failed to parse /etc/resolv.conf: {}", e.backtrace());
warn!("failed to parse /etc/resolv.conf: {}", e.backtrace());
}
Ok(resolv_conf_str) => {
*RESOLV_CONF_STR.write().unwrap() = Some(resolv_conf_str);
if let Err(e) = write_host_file(HostFile::ResolvConf) {
error!("failed to write /etc/resolv.conf: {}", e.backtrace());
warn!("failed to write /etc/resolv.conf: {}", e.backtrace());
}
}
}
@ -450,13 +450,13 @@ fn parse_host_files(file_buffer: *const host_file_buffer) -> Result<i32> {
let hostname_ptr = unsafe { (*file_buffer).hostname_buf };
match parse_host_file(HostFile::HostName, hostname_ptr) {
Err(e) => {
error!("failed to parse /etc/hostname: {}", e.backtrace());
warn!("failed to parse /etc/hostname: {}", e.backtrace());
}
Ok(hostname_str) => {
misc::init_nodename(&hostname_str);
*HOSTNAME_STR.write().unwrap() = Some(hostname_str);
if let Err(e) = write_host_file(HostFile::HostName) {
error!("failed to write /etc/hostname: {}", e.backtrace());
warn!("failed to write /etc/hostname: {}", e.backtrace());
}
}
}
@ -464,12 +464,12 @@ fn parse_host_files(file_buffer: *const host_file_buffer) -> Result<i32> {
let hosts_ptr = unsafe { (*file_buffer).hosts_buf };
match parse_host_file(HostFile::Hosts, hosts_ptr) {
Err(e) => {
error!("failed to parse /etc/hosts: {}", e.backtrace());
warn!("failed to parse /etc/hosts: {}", e.backtrace());
}
Ok(hosts_str) => {
*HOSTS_STR.write().unwrap() = Some(hosts_str);
if let Err(e) = write_host_file(HostFile::Hosts) {
error!("failed to write /etc/hosts: {}", e.backtrace());
warn!("failed to write /etc/hosts: {}", e.backtrace());
}
}
}

@ -689,26 +689,38 @@ fn do_syscall(user_context: &mut CpuContext) {
let retval = match ret {
Ok(retval) => retval as isize,
Err(e) => {
let should_log_err = |errno| {
// let syscall_num = SyscallNum::try_from(num).unwrap();
let should_log_err = |num, errno| {
let syscall_num = match SyscallNum::try_from(num) {
Ok(num) => num,
Err(e) => return true,
};
// If the log level requires every detail, don't ignore any error
if log::max_level() == LevelFilter::Trace {
return true;
}
// All other log levels require errors to be outputed. But
// some errnos are usually benign and may occur in a very high
// frequency. So we want to ignore them to keep noises at a
// minimum level in the log.
// frequency. So we want to lower them to warn level to keep noises
// at a minimum level in the error log.
//
// TODO: use a smarter, frequency-based strategy to decide whether
// to suppress error messages.
match errno {
EAGAIN | ETIMEDOUT => false,
EAGAIN | ETIMEDOUT | ENOENT | ENOTTY => false,
ENOSYS => match syscall_num {
SyscallNum::Getrusage => false,
SyscallNum::Madvise => false,
_ => true,
},
_ => true,
}
};
if should_log_err(e.errno()) {
if should_log_err(num, e.errno()) {
error!("Error = {}", e.backtrace());
} else {
warn!("Error = {}", e.backtrace());
}
let retval = -(e.errno() as isize);

@ -485,10 +485,12 @@ impl ProcessVM {
*brk_guard = brk;
Ok(brk)
} else {
if brk < heap_start {
error!("New brk address is too low");
if brk == 0 {
debug!("Try get current program break address")
} else if brk < heap_start {
warn!("New brk address is too low");
} else if brk > heap_end {
error!("New brk address is too high");
warn!("New brk address is too high");
}
Ok(*brk_guard)