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

runtime-rs: Introduce kata-sys-util library crate #3306

Merged
merged 8 commits into from Feb 21, 2022

Conversation

jiangliu
Copy link
Contributor

@jiangliu jiangliu commented Dec 19, 2021

With the runtime-rs related work, there will be code shared by multiple Kata Containers components, or even some crates may be published and consumed by other projects. So introduce kata-types and kata-sys-util to crates to host shared data structures and common code to access system services.

@jiangliu jiangliu requested a review from a team as a code owner December 19, 2021 15:35
@fidencio fidencio changed the title Introduce kata-types and kata-sys-util crates runtime-rs: Introduce kata-types and kata-sys-util crates Dec 20, 2021
@liubin
Copy link
Member

liubin commented Dec 20, 2021

@jiangliu please rebase to include #3315 to pass the CI.

@dgibson dgibson linked an issue Dec 21, 2021 that may be closed by this pull request
src/libs/types-rs/src/container.rs Outdated Show resolved Hide resolved
src/libs/types-rs/src/container.rs Outdated Show resolved Hide resolved
src/libs/types-rs/src/k8s.rs Outdated Show resolved Hide resolved
src/libs/types-rs/src/k8s.rs Outdated Show resolved Hide resolved
src/libs/types-rs/src/lib.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/numa.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/numa.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/numa.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/numa.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/numa.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/Cargo.toml Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/cgroup.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/cgroup.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/cgroup.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/cgroup.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/mount.rs Outdated Show resolved Hide resolved
src/libs/sys-util-rs/README.md Outdated Show resolved Hide resolved
src/libs/sys-util-rs/src/cgroup.rs Outdated Show resolved Hide resolved
@jiangliu jiangliu force-pushed the sys-util branch 7 times, most recently from ad0cff6 to 61b5f83 Compare December 25, 2021 12:59
@jiangliu jiangliu force-pushed the sys-util branch 2 times, most recently from f1aca2e to c540afc Compare January 6, 2022 02:10
@jiangliu jiangliu closed this Jan 6, 2022
@jiangliu jiangliu reopened this Jan 6, 2022
@jiangliu jiangliu force-pushed the sys-util branch 13 times, most recently from 98f12a9 to d16bcf8 Compare January 6, 2022 10:06
@fidencio
Copy link
Member

A head's up that may affect your PR.

In the Architecture Committee meeting from January 25th, 2022, the Architecture Committee has agreed on using the "Dismiss stale pull request approvals when new commits are pushed" configuration from GitHub. It basically means that if your PR has been rebased or updated, the approvals given will be erased.

In order to minimize traumas due to the new approach, please, consider adding a note on the changes done before the rebase / force-push, and also pinging the reviewers for a subsequent round of reviews.

Thanks for your understanding!

Related issue: kata-containers/community#249

Copy link
Contributor

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jiangliu. The only blocking comment I have is the missing wait() call in handle_exit_status().

src/libs/kata-sys-util/src/fs.rs Outdated Show resolved Hide resolved
src/libs/kata-sys-util/src/hooks.rs Show resolved Hide resolved
}
executor.execute_and_wait(&mut popen)?;
info!(sl!(), "hook {} finished", hook.path);
self.states.insert(hook.into(), HookState::Done);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea: How about logging how long the hook took to run (since random hooks could have a huge impact on performance)?

src/libs/kata-sys-util/src/hooks.rs Outdated Show resolved Hide resolved
src/libs/kata-sys-util/src/hooks.rs Outdated Show resolved Hide resolved
src/libs/kata-sys-util/src/mount.rs Outdated Show resolved Hide resolved
@jodh-intel
Copy link
Contributor

Hi @jiangliu - any update on this?

@jiangliu
Copy link
Contributor Author

Hi @jiangliu - any update on this?

Back to work now, will update it soon:)

@jiangliu
Copy link
Contributor Author

Hi @jiangliu - any update on this?

@jodh-intel @dgibson @lifupan @liubin Sorry for delay, I have updated the PR according to review comments:)

Copy link
Member

@bergwolf bergwolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! @dgibson @jodh-intel Do you have more comments on the PR?

@lifupan
Copy link
Member

lifupan commented Feb 18, 2022

Hi @jodh-intel @dgibson @fidencio , do you guys have any comments?

Copy link
Contributor

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jiangliu - A few comments, mostly just nits. I'm assuming some of the code here will change when #3462 lands?

src/libs/kata-sys-util/src/fs.rs Show resolved Hide resolved
src/libs/kata-sys-util/src/hooks.rs Outdated Show resolved Hide resolved
info!(sl!(), "hook {} exec stdout: {}", self.hook.path, out);
}
}
self.timeout = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment

// Give a grace period for `execute_and_wait()`.

};
let key1 = HookKey::from(&hook);

let hook = oci::Hook {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests would be clearer and more consistent if you used the table based approach.

src/libs/kata-sys-util/src/mount.rs Show resolved Hide resolved
pub fn create_mount_destination<S: AsRef<Path>, D: AsRef<Path>, R: AsRef<Path>>(
src: S,
dst: D,
_root: R,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to be enabled when #3462 lands?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are several TODOs in mount.rs, which will be handled after merging #3462.

/// To ensure security, the `create_mount_destination()` function takes an extra parameter `root`,
/// which is used to ensure that `dst` is within the specified directory. And a safe version of
/// `PathBuf` is returned to avoid TOCTTOU type of flaws.
pub fn create_mount_destination<S: AsRef<Path>, D: AsRef<Path>, R: AsRef<Path>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For safety, shouldn't this function require that all specified paths are absolute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's designed to support the container rootfs mount scenario and simplify the caller:)

src/libs/kata-sys-util/src/mount.rs Show resolved Hide resolved
src/libs/kata-sys-util/src/mount.rs Outdated Show resolved Hide resolved
src/libs/kata-sys-util/src/mount.rs Outdated Show resolved Hide resolved
@jiangliu
Copy link
Contributor Author

Thanks @jiangliu - A few comments, mostly just nits. I'm assuming some of the code here will change when #3462 lands?

Yes, we found the secure issue when developing this PR, and then developed #3462. So let's get it done step by step:)

The kata-sys-util crate is a collection of modules that provides helpers
and utilities used by multiple Kata Containers components.

Fixes: kata-containers#3305

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Add some wrappers for mount and fs syscall.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Bin Liu <bin@hyper.sh>
Signed-off-by: Fupan Li <lifupan@gmail.com>
Signed-off-by: Huamin Tang <huamin.thm@alibaba-inc.com>
Signed-off-by: Lei Wang <wllenyj@linux.alibaba.com>
Signed-off-by: Quanwei Zhou <quanweiZhou@linux.alibaba.com>
Add utilities to manipulate cgroup, currently only v1 is supported.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: He Rongguang <herongguang@linux.alibaba.com>
Signed-off-by: Jiahuan Chao <jhchao@linux.alibaba.com>
Signed-off-by: Qingyuan Hou <qingyuan.hou@linux.alibaba.com>
Signed-off-by: Quanwei Zhou <quanweiZhou@linux.alibaba.com>
Signed-off-by: Tim Zhang <tim@hyper.sh>
Add utilities to parse NUMA information.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Qingyuan Hou <qingyuan.hou@linux.alibaba.com>
Signed-off-by: Simon Guo <wei.guo.simon@linux.alibaba.com>
Implement reflink_copy() to copy file by reflink, and fallback to normal
file copy.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
Introduce get_devid() to get major/minor number of a block device.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
Add function to detect and update K8s emptyDir volume.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Qingyuan Hou <qingyuan.hou@linux.alibaba.com>
Provide functions to execute OCI hooks.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Bin Liu <bin@hyper.sh>
Signed-off-by: Huamin Tang <huamin.thm@alibaba-inc.com>
Signed-off-by: Lei Wang <wllenyj@linux.alibaba.com>
Signed-off-by: Quanwei Zhou <quanweiZhou@linux.alibaba.com>
Copy link
Contributor

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jiangliu.

lgtm

@bergwolf
Copy link
Member

@dgibson has been inactive on the PR for more than a month since his comments were last addressed. I'm going to dismiss his review and merge the PR. @dgibson when you come back, please open new issues on any changes that you would like to see happening in this area. Thanks!

@lifupan lifupan merged commit 076e658 into kata-containers:runtime-rs Feb 21, 2022
runtime-rs automation moved this from WiP to Done Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Introduce rust crates to host common code
9 participants