mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 04:04:45 +00:00
runtime-rs: fixed bug on core-sched error handling
Kernel code returns -errno, this should check negative values. Fixes: #4429 Signed-off-by: Ji-Xinyou <jerryji0414@outlook.com>
This commit is contained in:
parent
591dfa4fe6
commit
a355812e05
@ -38,7 +38,7 @@ pub const PR_SCHED_CORE_SHARE_FROM: usize = 3;
|
||||
pub fn core_sched_create(pidtype: usize) -> Result<(), Errno> {
|
||||
let errno = unsafe { nix::libc::prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, 0, pidtype, 0) };
|
||||
if errno != 0 {
|
||||
Err(nix::errno::Errno::from_i32(errno))
|
||||
Err(nix::errno::Errno::from_i32(-errno))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@ -50,7 +50,7 @@ pub fn core_sched_share_from(pid: usize, pidtype: usize) -> Result<(), Errno> {
|
||||
let errno =
|
||||
unsafe { nix::libc::prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, pid, pidtype, 0) };
|
||||
if errno != 0 {
|
||||
Err(nix::errno::Errno::from_i32(errno))
|
||||
Err(nix::errno::Errno::from_i32(-errno))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@ -87,18 +87,15 @@ mod tests {
|
||||
// therefore it does not make sense to assert a successful prctl call
|
||||
// but we can still make sure that the return value is a possible value
|
||||
let e = core_sched_create(PROCESS_GROUP);
|
||||
match e {
|
||||
Err(errno) => {
|
||||
if errno != EINVAL
|
||||
&& errno != ENODEV
|
||||
&& errno != ENOMEM
|
||||
&& errno != EPERM
|
||||
&& errno != ESRCH
|
||||
{
|
||||
panic!("impossible return value {:?}", errno);
|
||||
}
|
||||
if let Err(errno) = e {
|
||||
if errno != EINVAL
|
||||
&& errno != ENODEV
|
||||
&& errno != ENOMEM
|
||||
&& errno != EPERM
|
||||
&& errno != ESRCH
|
||||
{
|
||||
panic!("impossible return value {:?}", errno);
|
||||
}
|
||||
Ok(()) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use std::os::unix::io::RawFd;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use kata_sys_util::spec::get_bundle_path;
|
||||
use nix::errno::Errno;
|
||||
|
||||
use crate::{
|
||||
core_sched, logger,
|
||||
@ -71,14 +70,11 @@ fn get_server_fd() -> Result<RawFd> {
|
||||
}
|
||||
|
||||
// TODO: currently we log a warning on fail (i.e. kernel version < 5.14), maybe just exit
|
||||
fn try_core_sched() -> Result<(), Errno> {
|
||||
// TODO: more test on higher version of kernel
|
||||
fn try_core_sched() -> Result<()> {
|
||||
if let Ok(v) = std::env::var("SCHED_CORE") {
|
||||
info!(
|
||||
sl!(),
|
||||
"containerd wants to enable core scheduling, SCHED_CORE={}(expected 1)", v
|
||||
);
|
||||
if !v.is_empty() {
|
||||
return core_sched::core_sched_create(core_sched::PROCESS_GROUP);
|
||||
core_sched::core_sched_create(core_sched::PROCESS_GROUP)?
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user