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: device manager for runtime-rs #5441

Merged
merged 10 commits into from
May 23, 2023

Conversation

Tim-0731-Hzt
Copy link
Member

support device manager for runtime-rs

Fixes:#5375
Signed-off-by: Zhongtao Hu zhongtaohu.tim@linux.alibaba.com

@katacontainersbot katacontainersbot added the size/huge Largest and most complex task (probably needs breaking into small pieces) label Oct 17, 2022
@Tim-0731-Hzt Tim-0731-Hzt force-pushed the device_manager_dev branch 4 times, most recently from 3072b84 to cfd3d10 Compare October 17, 2022 09:24
Copy link
Contributor

@quanweiZhou quanweiZhou left a comment

Choose a reason for hiding this comment

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

Few comments, and some advise:

  1. Give a picture of the design.
  2. Push code after make check and fix the clippy, I found some advise can check by make check.

src/agent/src/device.rs Show resolved Hide resolved
src/agent/src/device.rs Outdated Show resolved Hide resolved
src/agent/src/device.rs Outdated Show resolved Hide resolved
src/agent/src/device.rs Outdated Show resolved Hide resolved
src/agent/src/mount.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device/block.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device/block.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device_manager.rs Outdated Show resolved Hide resolved
src/agent/src/mount.rs Outdated Show resolved Hide resolved
@Tim-0731-Hzt Tim-0731-Hzt force-pushed the device_manager_dev branch 2 times, most recently from 0fffa47 to 6f504b9 Compare October 17, 2022 11:23
src/agent/src/device.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device/block.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device/block.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device/generic.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device/generic.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device_manager.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device_manager.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device_manager.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/utils.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/utils.rs Outdated Show resolved Hide resolved
pub struct GenericDevice {
id: String,
device_info: GenericConfig,
ref_count: u64,
Copy link
Member

Choose a reason for hiding this comment

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

What's the defferent between ref_count and attach_count.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think just use one of them would be enough to handle the device attach number.

@Tim-0731-Hzt
Copy link
Member Author

/test

tzY15368 added a commit to tzY15368/kata-containers that referenced this pull request Oct 25, 2022
Implements get-volume-stats trait for sandbox and add RPC calls to
agent. Also added type conversions in trans.rs

Fixes kata-containers#5441

Signed-off-by: Tingzhou Yuan <tzyuan15@bu.edu>
tzY15368 added a commit to tzY15368/kata-containers that referenced this pull request Oct 25, 2022
Implements resize-volume trait for sandbox and add RPC calls to agent.
Also added type conversions in trans.rs and replaced `ResizeRequest`
in shim-mgmt handler with the agent version to reduce redundancy.
The actual handler for the resize request is also added, and will be
implemented in the next commit.

Fixes kata-containers#5441

Signed-off-by: Tingzhou Yuan <tzyuan15@bu.edu>
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 @Tim-0731-Hzt - a few comments...

src/runtime-rs/crates/hypervisor/src/device_manager.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device_manager.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device_manager.rs Outdated Show resolved Hide resolved
src/runtime-rs/crates/hypervisor/src/device_manager.rs Outdated Show resolved Hide resolved
Comment on lines 47 to 56
let mut i = 0usize;
while i < suff_len && index >= 0 {
let letter: u8 = b'a' + (index % base) as u8;
disk_letters[i] = letter;
index = (index / base) - 1;
i += 1;
}
if index >= 0 {
return Err(anyhow!("Index not supported"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This chunk looks like it could be a separate function. That would allow it to be unit-tested with various values.

Comment on lines 48 to 59
&mut GenericConfig {
host_path: m.source.clone(),
container_path: m.destination.clone(),
dev_type: "b".to_string(),
major: stat::major(fstat.st_rdev) as i64,
minor: stat::minor(fstat.st_rdev) as i64,
file_mode: 0,
uid: 0,
gid: 0,
id: "".to_string(),
bdf: None,
driver_options: options,
io_limits: None,
..Default::default()
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these specified values are already included in ..Default::default() so I think this (and other instances) could be simplified?

Copy link
Member Author

Choose a reason for hiding this comment

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

Some variables in the struct is not specified here, this pr just support the basic functionality, so we still need them.

Comment on lines +426 to +469
devpath: &str,
) -> Result<()> {
let devname = devpath
.strip_prefix("/dev/")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is devpath guaranteed to be the fully expanded (canonical) value for the path? If not, what if something like /dev/foo/bar/../../../sbin/init was specified?

Copy link
Member Author

@Tim-0731-Hzt Tim-0731-Hzt Oct 31, 2022

Choose a reason for hiding this comment

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

Yes, it is passed as the source in the storage, and the source path is set on the runtime side, we get this by get_virt_drive_name function. So it can't be like /dev/foo/bar/../../../sbin/init.

@@ -401,6 +401,48 @@ async fn get_vfio_device_name(sandbox: &Arc<Mutex<Sandbox>>, grp: IommuGroup) ->
Ok(format!("{}/{}", SYSTEM_DEV_PATH, &uev.devname))
}

#[derive(Debug)]
struct MmioBlockMatcher {
suffix: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

  • ooi, why can't we match on the entire udev path?
  • Could you add some unit tests using fake Uevent events? That would help understanding and also clarify the point above.

Copy link
Member Author

@Tim-0731-Hzt Tim-0731-Hzt Oct 31, 2022

Choose a reason for hiding this comment

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

Normally, there are two path for a device, it could be sys/block/vda, and sys/devices/ ......./virtio0/block/vda, the first one will point to the second one, so match the suffix would be enough.

@Tim-0731-Hzt
Copy link
Member Author

/test

1 similar comment
@Tim-0731-Hzt
Copy link
Member Author

/test

@katacontainersbot katacontainersbot added size/huge Largest and most complex task (probably needs breaking into small pieces) and removed size/tiny Smallest and simplest task labels May 22, 2023
@studychao
Copy link
Member

/test

@Tim-0731-Hzt
Copy link
Member Author

/test-s390x

@snir911
Copy link
Member

snir911 commented May 22, 2023

/retest-s390x

ananos added a commit to nubificus/kata-containers that referenced this pull request May 22, 2023
This is an initial, WiP port of FC on the rust runtime of kata containers.

It is built on top of the `device_manager_dev` branch
[kata-containers#5441], since block device
support for the container rootfs is a prerequisite for FC sandboxes (FC
does not support virtio-fs).

Current issues:
- network namespaces are being deleted (probably some threading mixup), hence,
  although there's a network device present, there's no network support (the
  namespace in the host is deleted, so no tap0_kata, tc etc.)
- we do not kill the FC process leaving instances running even after container
  shutdown. This leaves running firecracker instances, keeps the devmapper snapshot
  active etc.
- no jailer support yet

Assumes FC binaries are in `$INSTALL_PREFIX/bin`

Signed-off-by: George Pyrros <gpyrros@nubificus.co.uk>
Signed-off-by: Anastassios Nanos <ananos@nubificus.co.uk>
Support device manager for runtime-rs, add block device handler for
device manager

Fixes:kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
add the trait implementation for vfio device,

Fixes:kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
add the trait implementation for vhost-user device

Fixes:kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
As dragonball support hotplug virtio-mmio device, we should handle it in agent

Fixes:kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
support devmapper for block rootfs

Fixes: kata-containers#5375

Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
support block volume in runtime-rs

Fixes: kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
support linux device in runtime-rs

Fixes:kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
Support remove device after container stop

Fixes:kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
use device type to store the config information for different kind of
devices

Fixes:kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
add virtio-blk-mmio option for dragonball

Fixes:kata-containers#5375
Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
@Tim-0731-Hzt
Copy link
Member Author

/test

@katacontainersbot katacontainersbot added size/tiny Smallest and simplest task and removed size/huge Largest and most complex task (probably needs breaking into small pieces) labels May 22, 2023
@Tim-0731-Hzt
Copy link
Member Author

/test-fc

@studychao
Copy link
Member

/test

ananos added a commit to nubificus/kata-containers that referenced this pull request May 23, 2023
This is an initial, WiP port of FC on the rust runtime of kata containers.

It is built on top of the `device_manager_dev` branch
[kata-containers#5441], since block device
support for the container rootfs is a prerequisite for FC sandboxes (FC
does not support virtio-fs).

Current issues:
- network namespaces are being deleted (probably some threading mixup), hence,
  although there's a network device present, there's no network support (the
  namespace in the host is deleted, so no tap0_kata, tc etc.)
- no jailer support yet

Assumes FC binaries are in `$INSTALL_PREFIX/bin`

Signed-off-by: George Pyrros <gpyrros@nubificus.co.uk>
Signed-off-by: Anastassios Nanos <ananos@nubificus.co.uk>
@lifupan lifupan merged commit 1703365 into kata-containers:main May 23, 2023
ananos added a commit to nubificus/kata-containers that referenced this pull request May 23, 2023
This is an initial, WiP port of FC on the rust runtime of kata containers.

It is built on top of the `device_manager_dev` branch
[kata-containers#5441], since block device
support for the container rootfs is a prerequisite for FC sandboxes (FC
does not support virtio-fs).

Current issues:
- network namespaces are being deleted (probably some threading mixup), hence,
  although there's a network device present, there's no network support (the
  namespace in the host is deleted, so no tap0_kata, tc etc.)
- no jailer support yet

Assumes FC binaries are in `$INSTALL_PREFIX/bin`

Signed-off-by: George Pyrros <gpyrros@nubificus.co.uk>
Signed-off-by: Anastassios Nanos <ananos@nubificus.co.uk>
ananos added a commit to nubificus/kata-containers that referenced this pull request May 23, 2023
This is an initial, WiP port of FC on the rust runtime of kata containers.

It is built on top of the `device_manager_dev` branch
[kata-containers#5441], since block device
support for the container rootfs is a prerequisite for FC sandboxes (FC
does not support virtio-fs).

Current issues:
- We should enter the network namespace in the forked process. For
  now, we use the pre_exec method to run a closure just before the
  exec of the external hypervisor. This way, the hypervisor belongs
  to the new namespace, whereas the runtime does not. There's an issue
  with nerdctl (not present in k8s deployments) where the netns file
  is left dangling in the host. Useful read: https://serverfault.com/a/961592
- no jailer support yet

Assumes FC binaries are in `$INSTALL_PREFIX/bin`

Signed-off-by: George Pyrros <gpyrros@nubificus.co.uk>
Signed-off-by: Anastassios Nanos <ananos@nubificus.co.uk>
@Tim-0731-Hzt Tim-0731-Hzt deleted the device_manager_dev branch June 2, 2023 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
runtime-rs size/tiny Smallest and simplest task
Projects
None yet
Development

Successfully merging this pull request may close these issues.