runtime-rs: Add support for independent iothreads for virtio blk devices

As independent iothreads can work in both virtio-scsi and virtio-blk
devices, this commit aims to enable such feature in virtio-blk-pci
devices.

Signed-off-by: Fabiano Fidêncio <ffidencio@nvidia.com>
Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
This commit is contained in:
Alex Lyn
2026-06-08 14:25:49 +08:00
committed by Fabiano Fidêncio
parent 980ecfdd96
commit b0ebbc685d
2 changed files with 12 additions and 9 deletions

View File

@@ -15,7 +15,7 @@ use std::borrow::Cow;
use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use kata_types::config::hypervisor::VIRTIO_SCSI;
use kata_types::config::hypervisor::{VIRTIO_BLK_PCI, VIRTIO_SCSI};
use kata_types::rootless::is_rootless;
use serde::{Deserialize, Serialize};
use serde_json;
@@ -2631,8 +2631,10 @@ impl<'a> QemuCmdLine<'a> {
qemu_cmd_line.add_scsi_controller();
}
// Add independent IO threads for virtio-blk hotplug devices
qemu_cmd_line.add_indep_iothreads();
// Add independent IO threads only when hotplug uses virtio-blk-pci.
if config.blockdev_info.block_device_driver == VIRTIO_BLK_PCI {
qemu_cmd_line.add_indep_iothreads();
}
if config.device_info.reclaim_guest_freed_memory {
qemu_cmd_line.add_virtio_balloon();
@@ -2741,8 +2743,8 @@ impl<'a> QemuCmdLine<'a> {
self.devices.push(Box::new(virtio_scsi));
}
/// Add independent IO threads for virtio-blk devices.
/// These threads can be attached to virtio-blk devices during hotplug.
/// Add independent IO threads for virtio-blk-pci devices.
/// These threads can be attached to virtio-blk-pci devices during hotplug.
fn add_indep_iothreads(&mut self) {
// Only create independent IO threads if enable_iothreads is true and indep_iothreads > 0
if self.config.enable_iothreads && self.config.indep_iothreads > 0 {

View File

@@ -25,7 +25,7 @@ use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use kata_sys_util::netns::NetnsGuard;
use kata_types::build_path;
use kata_types::config::hypervisor::{RootlessUser, VIRTIO_BLK_CCW};
use kata_types::config::hypervisor::{RootlessUser, VIRTIO_BLK_CCW, VIRTIO_BLK_PCI};
use kata_types::rootless::is_rootless;
use kata_types::{
capabilities::{Capabilities, CapabilityBits},
@@ -950,15 +950,15 @@ impl QemuInner {
DeviceType::Block(mut block_device) => {
let block_driver = &self.config.blockdev_info.block_device_driver;
// Determine iothread for virtio-blk devices
// Determine iothread for hotplugged virtio-blk-pci devices.
// Only attach iothread when:
// 1. enable_iothreads is true
// 2. indep_iothreads > 0
// 3. block driver is not virtio-scsi (i.e., it's virtio-blk)
// 3. block driver is virtio-blk-pci
// 4. TODO: for more complex cases
let iothread = if self.config.enable_iothreads
&& self.config.indep_iothreads > 0
&& *block_driver != kata_types::config::hypervisor::VIRTIO_SCSI
&& block_driver == VIRTIO_BLK_PCI
{
// Use the first independent iothread (indep_iothread_0)
Some("indep_iothread_0")
@@ -1066,6 +1066,7 @@ impl QemuInner {
logical_sector_size,
physical_sector_size,
&BlockDeviceFormat::default(),
None,
)
.context("hotplug block device")?;