Skip to content

Commit

Permalink
handle filesystem virtiofs devices
Browse files Browse the repository at this point in the history
Signed-off-by: Vladik Romanovsky <[email protected]>
  • Loading branch information
vladikr committed Sep 18, 2020
1 parent 34a6a33 commit 835249b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ func getRequiredCapabilities(vmi *v1.VirtualMachineInstance) []k8sv1.Capability
res = append(res, CAP_SYS_NICE)

// add CAP_SYS_ADMIN capability to allow virtiofs
if utils.IsVMIVirtiofsEnabled(vmi) {
if util.IsVMIVirtiofsEnabled(vmi) {
res = append(res, CAP_SYS_ADMIN)
}
return res
Expand Down
64 changes: 49 additions & 15 deletions pkg/virt-launcher/virtwrap/api/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* Copyright 2017, 2018 Red Hat, Inc.
*
*/
*/

package api

Expand Down Expand Up @@ -822,25 +822,25 @@ func Convert_v1_VirtualMachine_To_api_Domain(vmi *v1.VirtualMachineInstance, dom
return err
}

var isMemfdRequired = false
var isMemfdRequired = false
if vmi.Spec.Domain.Memory != nil && vmi.Spec.Domain.Memory.Hugepages != nil {
domain.Spec.MemoryBacking = &MemoryBacking{
HugePages: &HugePages{},
}
if val := vmi.Annotations[v1.MemfdMemoryBackend]; val != "false" {
isMemfdRequired = true
}
}
// virtiofs require shared access
if utils.IsVMIVirtiofsEnabled {
if domain.Spec.MemoryBacking == nil {
domain.Spec.MemoryBacking = &MemoryBacking{}
}
domain.Spec.MemoryBacking.Access = &MemoryBackingAccess{
Mode: "shared",
}
isMemfdRequired = true
}
isMemfdRequired = true
}
}
// virtiofs require shared access
if util.IsVMIVirtiofsEnabled(vmi) {
if domain.Spec.MemoryBacking == nil {
domain.Spec.MemoryBacking = &MemoryBacking{}
}
domain.Spec.MemoryBacking.Access = &MemoryBackingAccess{
Mode: "shared",
}
isMemfdRequired = true
}

if isMemfdRequired {
// Set memfd as memory backend to solve SELinux restrictions
Expand Down Expand Up @@ -977,6 +977,40 @@ func Convert_v1_VirtualMachine_To_api_Domain(vmi *v1.VirtualMachineInstance, dom

domain.Spec.Devices.Disks = append(domain.Spec.Devices.Disks, newDisk)
}
// Handle virtioFS
for _, fs := range vmi.Spec.Domain.Devices.Filesystems {
newFS := FilesystemDevice{}

newFS.Type = "mount"
newFS.AccessMode = "passthrough"
newFS.Driver = &FilesystemDriver{
Type: "virtiofs",
Queue: "1024",
}
newFS.Binary = &FilesystemBinary{
Path: "/usr/libexec/virtiofsd",
Xattr: "on",
Cache: &FilesystemBinaryCache{
Mode: "always",
},
Lock: &FilesystemBinaryLock{
Posix: "on",
Flock: "on",
},
}
newFS.Target = &FilesystemTarget{
Dir: fs.Name,
}

volume := volumes[fs.Name]
if volume == nil {
return fmt.Errorf("No matching volume with name %s found", fs.Name)
}
volDir, _ := filepath.Split(GetFilesystemVolumePath(volume.Name))
newFS.Source = &FilesystemSource{}
newFS.Source.Dir = volDir
domain.Spec.Devices.Filesystems = append(domain.Spec.Devices.Filesystems, newFS)
}

if vmi.Spec.Domain.Devices.Watchdog != nil {
newWatchdog := &Watchdog{}
Expand Down
10 changes: 10 additions & 0 deletions staging/src/kubevirt.io/client-go/api/v1/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ type Devices struct {
//Whether to attach a GPU device to the vmi.
// +optional
GPUs []GPU `json:"gpus,omitempty"`
// Filesystem describes virtiofs filesystem which is connected to the vmi.
// +optional
Filesystems []Filesystem `json:"filesystem,omitempty"`
}

//
Expand All @@ -387,6 +390,13 @@ type Input struct {
Name string `json:"name"`
}

//
// +k8s:openapi-gen=true
type Filesystem struct {
// Name is the device name
Name string `json:"name"`
}

//
// +k8s:openapi-gen=true
type GPU struct {
Expand Down

0 comments on commit 835249b

Please sign in to comment.