mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-05 03:26:37 +00:00
block: Add cache-related options for block devices
Add block_device_cache_set, block_device_cache_direct and block_device_cache_noflush. They are cache-related options for block devices that are described in https://github.com/qemu/qemu/blob/master/qapi/block-core.json. block_device_cache_direct denotes whether use of O_DIRECT (bypass the host page cache) is enabled. block_device_cache_noflush denotes whether flush requests for the device are ignored. The json said they are supported since 2.9. So add block_device_cache_set to control the cache options set to block devices or not. It will help to support the old version qemu. Fixes: #956 Signed-off-by: Hui Zhu <teawater@hyper.sh>
This commit is contained in:
parent
9dee04a314
commit
f6511471d4
@ -28,6 +28,9 @@ const defaultBridgesCount uint32 = 1
|
|||||||
const defaultInterNetworkingModel = "macvtap"
|
const defaultInterNetworkingModel = "macvtap"
|
||||||
const defaultDisableBlockDeviceUse bool = false
|
const defaultDisableBlockDeviceUse bool = false
|
||||||
const defaultBlockDeviceDriver = "virtio-scsi"
|
const defaultBlockDeviceDriver = "virtio-scsi"
|
||||||
|
const defaultBlockDeviceCacheSet bool = false
|
||||||
|
const defaultBlockDeviceCacheDirect bool = false
|
||||||
|
const defaultBlockDeviceCacheNoflush bool = false
|
||||||
const defaultEnableIOThreads bool = false
|
const defaultEnableIOThreads bool = false
|
||||||
const defaultEnableMemPrealloc bool = false
|
const defaultEnableMemPrealloc bool = false
|
||||||
const defaultEnableHugePages bool = false
|
const defaultEnableHugePages bool = false
|
||||||
|
@ -79,33 +79,36 @@ type factory struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type hypervisor struct {
|
type hypervisor struct {
|
||||||
Path string `toml:"path"`
|
Path string `toml:"path"`
|
||||||
Kernel string `toml:"kernel"`
|
Kernel string `toml:"kernel"`
|
||||||
Initrd string `toml:"initrd"`
|
Initrd string `toml:"initrd"`
|
||||||
Image string `toml:"image"`
|
Image string `toml:"image"`
|
||||||
Firmware string `toml:"firmware"`
|
Firmware string `toml:"firmware"`
|
||||||
MachineAccelerators string `toml:"machine_accelerators"`
|
MachineAccelerators string `toml:"machine_accelerators"`
|
||||||
KernelParams string `toml:"kernel_params"`
|
KernelParams string `toml:"kernel_params"`
|
||||||
MachineType string `toml:"machine_type"`
|
MachineType string `toml:"machine_type"`
|
||||||
BlockDeviceDriver string `toml:"block_device_driver"`
|
BlockDeviceDriver string `toml:"block_device_driver"`
|
||||||
EntropySource string `toml:"entropy_source"`
|
EntropySource string `toml:"entropy_source"`
|
||||||
NumVCPUs int32 `toml:"default_vcpus"`
|
BlockDeviceCacheSet bool `toml:"block_device_cache_set"`
|
||||||
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
|
BlockDeviceCacheDirect bool `toml:"block_device_cache_direct"`
|
||||||
MemorySize uint32 `toml:"default_memory"`
|
BlockDeviceCacheNoflush bool `toml:"block_device_cache_noflush"`
|
||||||
MemSlots uint32 `toml:"memory_slots"`
|
NumVCPUs int32 `toml:"default_vcpus"`
|
||||||
DefaultBridges uint32 `toml:"default_bridges"`
|
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
|
||||||
Msize9p uint32 `toml:"msize_9p"`
|
MemorySize uint32 `toml:"default_memory"`
|
||||||
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
|
MemSlots uint32 `toml:"memory_slots"`
|
||||||
MemPrealloc bool `toml:"enable_mem_prealloc"`
|
DefaultBridges uint32 `toml:"default_bridges"`
|
||||||
HugePages bool `toml:"enable_hugepages"`
|
Msize9p uint32 `toml:"msize_9p"`
|
||||||
Swap bool `toml:"enable_swap"`
|
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
|
||||||
Debug bool `toml:"enable_debug"`
|
MemPrealloc bool `toml:"enable_mem_prealloc"`
|
||||||
DisableNestingChecks bool `toml:"disable_nesting_checks"`
|
HugePages bool `toml:"enable_hugepages"`
|
||||||
EnableIOThreads bool `toml:"enable_iothreads"`
|
Swap bool `toml:"enable_swap"`
|
||||||
UseVSock bool `toml:"use_vsock"`
|
Debug bool `toml:"enable_debug"`
|
||||||
HotplugVFIOOnRootBus bool `toml:"hotplug_vfio_on_root_bus"`
|
DisableNestingChecks bool `toml:"disable_nesting_checks"`
|
||||||
DisableVhostNet bool `toml:"disable_vhost_net"`
|
EnableIOThreads bool `toml:"enable_iothreads"`
|
||||||
GuestHookPath string `toml:"guest_hook_path"`
|
UseVSock bool `toml:"use_vsock"`
|
||||||
|
HotplugVFIOOnRootBus bool `toml:"hotplug_vfio_on_root_bus"`
|
||||||
|
DisableVhostNet bool `toml:"disable_vhost_net"`
|
||||||
|
GuestHookPath string `toml:"guest_hook_path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type proxy struct {
|
type proxy struct {
|
||||||
@ -416,33 +419,36 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return vc.HypervisorConfig{
|
return vc.HypervisorConfig{
|
||||||
HypervisorPath: hypervisor,
|
HypervisorPath: hypervisor,
|
||||||
KernelPath: kernel,
|
KernelPath: kernel,
|
||||||
InitrdPath: initrd,
|
InitrdPath: initrd,
|
||||||
ImagePath: image,
|
ImagePath: image,
|
||||||
FirmwarePath: firmware,
|
FirmwarePath: firmware,
|
||||||
MachineAccelerators: machineAccelerators,
|
MachineAccelerators: machineAccelerators,
|
||||||
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
|
||||||
HypervisorMachineType: machineType,
|
HypervisorMachineType: machineType,
|
||||||
NumVCPUs: h.defaultVCPUs(),
|
NumVCPUs: h.defaultVCPUs(),
|
||||||
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
|
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
|
||||||
MemorySize: h.defaultMemSz(),
|
MemorySize: h.defaultMemSz(),
|
||||||
MemSlots: h.defaultMemSlots(),
|
MemSlots: h.defaultMemSlots(),
|
||||||
EntropySource: h.GetEntropySource(),
|
EntropySource: h.GetEntropySource(),
|
||||||
DefaultBridges: h.defaultBridges(),
|
DefaultBridges: h.defaultBridges(),
|
||||||
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
|
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
|
||||||
MemPrealloc: h.MemPrealloc,
|
MemPrealloc: h.MemPrealloc,
|
||||||
HugePages: h.HugePages,
|
HugePages: h.HugePages,
|
||||||
Mlock: !h.Swap,
|
Mlock: !h.Swap,
|
||||||
Debug: h.Debug,
|
Debug: h.Debug,
|
||||||
DisableNestingChecks: h.DisableNestingChecks,
|
DisableNestingChecks: h.DisableNestingChecks,
|
||||||
BlockDeviceDriver: blockDriver,
|
BlockDeviceDriver: blockDriver,
|
||||||
EnableIOThreads: h.EnableIOThreads,
|
BlockDeviceCacheSet: h.BlockDeviceCacheSet,
|
||||||
Msize9p: h.msize9p(),
|
BlockDeviceCacheDirect: h.BlockDeviceCacheDirect,
|
||||||
UseVSock: useVSock,
|
BlockDeviceCacheNoflush: h.BlockDeviceCacheNoflush,
|
||||||
HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus,
|
EnableIOThreads: h.EnableIOThreads,
|
||||||
DisableVhostNet: h.DisableVhostNet,
|
Msize9p: h.msize9p(),
|
||||||
GuestHookPath: h.guestHookPath(),
|
UseVSock: useVSock,
|
||||||
|
HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus,
|
||||||
|
DisableVhostNet: h.DisableVhostNet,
|
||||||
|
GuestHookPath: h.guestHookPath(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,27 +544,30 @@ func initConfig() (config oci.RuntimeConfig, err error) {
|
|||||||
var defaultAgentConfig interface{}
|
var defaultAgentConfig interface{}
|
||||||
|
|
||||||
defaultHypervisorConfig := vc.HypervisorConfig{
|
defaultHypervisorConfig := vc.HypervisorConfig{
|
||||||
HypervisorPath: defaultHypervisorPath,
|
HypervisorPath: defaultHypervisorPath,
|
||||||
KernelPath: defaultKernelPath,
|
KernelPath: defaultKernelPath,
|
||||||
ImagePath: defaultImagePath,
|
ImagePath: defaultImagePath,
|
||||||
InitrdPath: defaultInitrdPath,
|
InitrdPath: defaultInitrdPath,
|
||||||
FirmwarePath: defaultFirmwarePath,
|
FirmwarePath: defaultFirmwarePath,
|
||||||
MachineAccelerators: defaultMachineAccelerators,
|
MachineAccelerators: defaultMachineAccelerators,
|
||||||
HypervisorMachineType: defaultMachineType,
|
HypervisorMachineType: defaultMachineType,
|
||||||
NumVCPUs: defaultVCPUCount,
|
NumVCPUs: defaultVCPUCount,
|
||||||
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
||||||
MemorySize: defaultMemSize,
|
MemorySize: defaultMemSize,
|
||||||
DefaultBridges: defaultBridgesCount,
|
DefaultBridges: defaultBridgesCount,
|
||||||
MemPrealloc: defaultEnableMemPrealloc,
|
MemPrealloc: defaultEnableMemPrealloc,
|
||||||
HugePages: defaultEnableHugePages,
|
HugePages: defaultEnableHugePages,
|
||||||
Mlock: !defaultEnableSwap,
|
Mlock: !defaultEnableSwap,
|
||||||
Debug: defaultEnableDebug,
|
Debug: defaultEnableDebug,
|
||||||
DisableNestingChecks: defaultDisableNestingChecks,
|
DisableNestingChecks: defaultDisableNestingChecks,
|
||||||
BlockDeviceDriver: defaultBlockDeviceDriver,
|
BlockDeviceDriver: defaultBlockDeviceDriver,
|
||||||
EnableIOThreads: defaultEnableIOThreads,
|
BlockDeviceCacheSet: defaultBlockDeviceCacheSet,
|
||||||
Msize9p: defaultMsize9p,
|
BlockDeviceCacheDirect: defaultBlockDeviceCacheDirect,
|
||||||
HotplugVFIOOnRootBus: defaultHotplugVFIOOnRootBus,
|
BlockDeviceCacheNoflush: defaultBlockDeviceCacheNoflush,
|
||||||
GuestHookPath: defaultGuestHookPath,
|
EnableIOThreads: defaultEnableIOThreads,
|
||||||
|
Msize9p: defaultMsize9p,
|
||||||
|
HotplugVFIOOnRootBus: defaultHotplugVFIOOnRootBus,
|
||||||
|
GuestHookPath: defaultGuestHookPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = config.InterNetworkModel.SetModel(defaultInterNetworkingModel)
|
err = config.InterNetworkModel.SetModel(defaultInterNetworkingModel)
|
||||||
|
@ -206,6 +206,17 @@ type HypervisorConfig struct {
|
|||||||
// it will be used for the sandbox's kernel path instead of KernelPath.
|
// it will be used for the sandbox's kernel path instead of KernelPath.
|
||||||
customAssets map[assetType]*asset
|
customAssets map[assetType]*asset
|
||||||
|
|
||||||
|
// BlockDeviceCacheSet specifies cache-related options will be set to block devices or not.
|
||||||
|
BlockDeviceCacheSet bool
|
||||||
|
|
||||||
|
// BlockDeviceCacheDirect specifies cache-related options for block devices.
|
||||||
|
// Denotes whether use of O_DIRECT (bypass the host page cache) is enabled.
|
||||||
|
BlockDeviceCacheDirect bool
|
||||||
|
|
||||||
|
// BlockDeviceCacheNoflush specifies cache-related options for block devices.
|
||||||
|
// Denotes whether flush requests for the device are ignored.
|
||||||
|
BlockDeviceCacheNoflush bool
|
||||||
|
|
||||||
// DisableBlockDeviceUse disallows a block device from being used.
|
// DisableBlockDeviceUse disallows a block device from being used.
|
||||||
DisableBlockDeviceUse bool
|
DisableBlockDeviceUse bool
|
||||||
|
|
||||||
|
@ -736,7 +736,12 @@ func (q *qemu) hotplugBlockDevice(drive *config.BlockDrive, op operation) error
|
|||||||
devID := "virtio-" + drive.ID
|
devID := "virtio-" + drive.ID
|
||||||
|
|
||||||
if op == addDevice {
|
if op == addDevice {
|
||||||
if err := q.qmpMonitorCh.qmp.ExecuteBlockdevAdd(q.qmpMonitorCh.ctx, drive.File, drive.ID); err != nil {
|
if q.config.BlockDeviceCacheSet {
|
||||||
|
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAddWithCache(q.qmpMonitorCh.ctx, drive.File, drive.ID, q.config.BlockDeviceCacheDirect, q.config.BlockDeviceCacheNoflush)
|
||||||
|
} else {
|
||||||
|
err = q.qmpMonitorCh.qmp.ExecuteBlockdevAdd(q.qmpMonitorCh.ctx, drive.File, drive.ID)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user