-
Notifications
You must be signed in to change notification settings - Fork 374
Add virtio-fs support (alternative to virtio-9p) #1016
Changes from all commits
0217077
9e87fa2
d690dff
9480978
82d1a9d
6767c1a
75f7586
0a69eb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,32 @@ default_memory = @DEFMEMSZ@ | |
# 9pfs is used instead to pass the rootfs. | ||
disable_block_device_use = @DEFDISABLEBLOCK@ | ||
|
||
# Shared file system type: | ||
# - virtio-9p (default) | ||
# - virtio-fs | ||
shared_fs = "@DEFSHAREDFS@" | ||
|
||
# Path to vhost-user-fs daemon. | ||
virtio_fs_daemon = "@DEFVIRTIOFSDAEMON@" | ||
|
||
# Default size of DAX cache in MiB | ||
virtio_fs_cache_size = @DEFVIRTIOFSCACHESIZE@ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, thank you! Will fix in the next revision. |
||
|
||
# Cache mode: | ||
# | ||
# - none | ||
# Metadata, data, and pathname lookup are not cached in guest. They are | ||
# always fetched from host and any changes are immediately pushed to host. | ||
# | ||
# - auto | ||
# Metadata and pathname lookup cache expires after a configured amount of | ||
# time (default is 1 second). Data is cached while the file is open (close | ||
# to open consistency). | ||
# | ||
# - always | ||
# Metadata, data, and pathname lookup are cached in guest and never expire. | ||
virtio_fs_cache = "@DEFVIRTIOFSCACHE@" | ||
|
||
# Block storage driver to be used for the hypervisor in case the container | ||
# rootfs is backed by a block device. This is virtio-scsi, virtio-blk | ||
# or nvdimm. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ const ( | |
|
||
//VhostUserBlk represents a block vhostuser device type | ||
VhostUserBlk = "vhost-user-blk-pci" | ||
|
||
//VhostUserFS represents a virtio-fs vhostuser device type | ||
VhostUserFS = "vhost-user-fs-pci" | ||
) | ||
|
||
const ( | ||
|
@@ -52,6 +55,14 @@ const ( | |
Nvdimm = "nvdimm" | ||
) | ||
|
||
const ( | ||
// Virtio9P means use virtio-9p for the shared file system | ||
Virtio9P = "virtio-9p" | ||
|
||
// VirtioFS means use virtio-fs for the shared file system | ||
VirtioFS = "virtio-fs" | ||
) | ||
|
||
// Defining these as a variable instead of a const, to allow | ||
// overriding this in the tests. | ||
|
||
|
@@ -174,6 +185,11 @@ type VhostUserDeviceAttrs struct { | |
|
||
// MacAddress is only meaningful for vhost user net device | ||
MacAddress string | ||
|
||
// These are only meaningful for vhost user fs devices | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, it's unclear from the context that additional fields are added by later patches: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it! |
||
Tag string | ||
CacheSize uint32 | ||
Cache string | ||
} | ||
|
||
// GetHostPathFunc is function pointer used to mock GetHostPath in tests. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (C) 2019 Red Hat, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package drivers | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
"github.com/kata-containers/runtime/virtcontainers/device/api" | ||
"github.com/kata-containers/runtime/virtcontainers/device/config" | ||
"github.com/kata-containers/runtime/virtcontainers/utils" | ||
) | ||
|
||
// VhostUserFSDevice is a virtio-fs vhost-user device | ||
type VhostUserFSDevice struct { | ||
*GenericDevice | ||
config.VhostUserDeviceAttrs | ||
} | ||
|
||
// Device interface | ||
|
||
func (device *VhostUserFSDevice) Attach(devReceiver api.DeviceReceiver) (err error) { | ||
skip, err := device.bumpAttachCount(true) | ||
if err != nil { | ||
return err | ||
} | ||
if skip { | ||
return nil | ||
} | ||
|
||
defer func() { | ||
if err != nil { | ||
device.bumpAttachCount(false) | ||
} | ||
}() | ||
|
||
// generate a unique ID to be used for hypervisor commandline fields | ||
randBytes, err := utils.GenerateRandomBytes(8) | ||
if err != nil { | ||
return err | ||
} | ||
id := hex.EncodeToString(randBytes) | ||
|
||
device.DevID = id | ||
device.Type = device.DeviceType() | ||
|
||
return devReceiver.AppendDevice(device) | ||
} | ||
|
||
func (device *VhostUserFSDevice) Detach(devReceiver api.DeviceReceiver) error { | ||
_, err := device.bumpAttachCount(false) | ||
return err | ||
} | ||
|
||
func (device *VhostUserFSDevice) DeviceType() config.DeviceType { | ||
return config.VhostUserFS | ||
} | ||
|
||
// GetDeviceInfo returns device information that the device is created based on | ||
func (device *VhostUserFSDevice) GetDeviceInfo() interface{} { | ||
device.Type = device.DeviceType() | ||
return &device.VhostUserDeviceAttrs | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we mention that a QEMU version greater than X is required to use this filesystem ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is currently not available in upstream QEMU. Launching the guest will fail with a QEMU error message because -device vhost-user-fs-pci is not supported. This can be seen in the kata-runtime log.
It is possible to probe a QEMU binary for this feature by running "qemu-system-x86_64 -device ?" to list available device models. I'm not sure if that's a good idea though since it will slow down Kata. Caching this information somewhere makes it more complex and prone to issues. I hope just relying on the QEMU error message is sufficient.