Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce the number of unnecessary clones and arguments by changing the order in which NotifyListeners are generated. #170

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub struct Start {

impl Start {
pub fn new(container_id: String) -> Self {
return Self { container_id };
Self { container_id }
}

pub fn exec(&self, root_path: PathBuf) -> Result<()> {
let container_root = root_path.join(&self.container_id);
if !container_root.exists() {
Expand Down
12 changes: 5 additions & 7 deletions src/container/builder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ impl ContainerBuilderImpl {

// create the parent and child process structure so the parent and child process can sync with each other
let (mut parent, parent_channel) = parent::ParentProcess::new(self.rootless.clone())?;
let mut child = child::ChildProcess::new(parent_channel)?;
// need to create the notify socket before we pivot root, since the unix
// domain socket used here is outside of the rootfs of container
let notify: NotifyListener = NotifyListener::new(&self.notify_path)?;
let mut child = child::ChildProcess::new(parent_channel, notify)?;

let cb = Box::new(|| {
if let Err(error) = container_init(
Expand All @@ -76,7 +79,6 @@ impl ContainerBuilderImpl {
self.syscall.clone(),
self.rootfs.clone(),
self.console_socket.clone(),
self.notify_path.clone(),
&mut child,
) {
log::debug!("failed to run container_init: {:?}", error);
Expand Down Expand Up @@ -121,14 +123,10 @@ fn container_init(
command: LinuxSyscall,
rootfs: PathBuf,
console_socket: Option<FileDescriptor>,
notify_name: PathBuf,
child: &mut child::ChildProcess,
) -> Result<()> {
let linux = &spec.linux;
let namespaces: Namespaces = linux.namespaces.clone().into();
// need to create the notify socket before we pivot root, since the unix
// domain socket used here is outside of the rootfs of container
let mut notify_socket: NotifyListener = NotifyListener::new(&notify_name)?;
let proc = &spec.process;

// if Out-of-memory score adjustment is set in specification. set the score
Expand Down Expand Up @@ -204,7 +202,7 @@ fn container_init(
child.notify_parent()?;

// listing on the notify socket for container start command
notify_socket.wait_for_container_start()?;
child.wait_for_container_start()?;

let args: &Vec<String> = &spec.process.args;
let envs: &Vec<String> = &spec.process.env;
Expand Down
10 changes: 9 additions & 1 deletion src/process/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use mio::unix::pipe::Receiver;
use mio::unix::pipe::Sender;
use mio::{Interest, Poll, Token};

use crate::notify_socket::NotifyListener;

use super::parent::ParentChannel;

// Token is used to identify which socket generated an event
Expand All @@ -15,6 +17,7 @@ pub struct ChildProcess {
parent_channel: ParentChannel,
receiver: Option<Receiver>,
poll: Option<Poll>,
notify: NotifyListener,
}

// Note : The original youki process first forks into 'parent' (P) and 'child' (C1) process
Expand All @@ -23,11 +26,12 @@ pub struct ChildProcess {
// a process point of view, init process is child of child process, which is child of original youki process.
impl ChildProcess {
/// create a new Child process structure
pub fn new(parent_channel: ParentChannel) -> Result<Self> {
pub fn new(parent_channel: ParentChannel, notify: NotifyListener) -> Result<Self> {
Ok(Self {
parent_channel,
receiver: None,
poll: None,
notify,
})
}

Expand Down Expand Up @@ -62,4 +66,8 @@ impl ChildProcess {
self.parent_channel.wait_for_mapping_ack()?;
Ok(())
}

pub fn wait_for_container_start(&mut self) -> Result<()> {
self.notify.wait_for_container_start()
}
}