Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Add multidevs option to fsdev
Browse files Browse the repository at this point in the history
multidevs specifies how to deal with multiple devices being shared with a 9p
export. `multidevs=remap` fixes the following warning:

```
9p: Multiple devices detected in same VirtFS export, which might lead to file
ID collisions and severe misbehaviours on guest!
You should either use a separate export for each device shared from host or
use virtfs option 'multidevs=remap'!
```

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Jul 23, 2020
1 parent 7cc4696 commit abca6f3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
25 changes: 25 additions & 0 deletions qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,23 @@ func (object Object) QemuParams(config *Config) []string {
return qemuParams
}

// Virtio9PMultidev filesystem behaviour to deal
// with multiple devices being shared with a 9p export.
type Virtio9PMultidev string

const (
// Remap shares multiple devices with only one export.
Remap Virtio9PMultidev = "remap"

// Warn assumes that only one device is shared by the same export.
// Only a warning message is logged (once) by qemu on host side.
// This is the default behaviour.
Warn Virtio9PMultidev = "warn"

// Forbid like "warn" but also deny access to additional devices on guest.
Forbid Virtio9PMultidev = "forbid"
)

// FSDriver represents a qemu filesystem driver.
type FSDriver string

Expand Down Expand Up @@ -350,6 +367,10 @@ type FSDevice struct {

// Transport is the virtio transport for this device.
Transport VirtioTransport

// Multidev is the filesystem behaviour to deal
// with multiple devices being shared with a 9p export
Multidev Virtio9PMultidev
}

// Virtio9PTransport is a map of the virtio-9p device name that corresponds
Expand Down Expand Up @@ -393,6 +414,10 @@ func (fsdev FSDevice) QemuParams(config *Config) []string {
fsParams = append(fsParams, fmt.Sprintf(",path=%s", fsdev.Path))
fsParams = append(fsParams, fmt.Sprintf(",security_model=%s", fsdev.SecurityModel))

if fsdev.Multidev != "" {
fsParams = append(fsParams, fmt.Sprintf(",multidevs=%s", fsdev.Multidev))
}

qemuParams = append(qemuParams, "-device")
qemuParams = append(qemuParams, strings.Join(deviceParams, ""))

Expand Down
2 changes: 1 addition & 1 deletion qemu/qemu_arch_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package qemu
import "testing"

var (
deviceFSString = "-device virtio-9p-pci,disable-modern=true,fsdev=workload9p,mount_tag=rootfs,romfile=efi-virtio.rom -fsdev local,id=workload9p,path=/var/lib/docker/devicemapper/mnt/e31ebda2,security_model=none"
deviceFSString = "-device virtio-9p-pci,disable-modern=true,fsdev=workload9p,mount_tag=rootfs,romfile=efi-virtio.rom -fsdev local,id=workload9p,path=/var/lib/docker/devicemapper/mnt/e31ebda2,security_model=none,multidevs=remap"
deviceNetworkString = "-netdev tap,id=tap0,vhost=on,ifname=ceth0,downscript=no,script=no -device driver=virtio-net-pci,netdev=tap0,mac=01:02:de:ad:be:ef,disable-modern=true,romfile=efi-virtio.rom"
deviceNetworkStringMq = "-netdev tap,id=tap0,vhost=on,fds=3:4 -device driver=virtio-net-pci,netdev=tap0,mac=01:02:de:ad:be:ef,disable-modern=true,mq=on,vectors=6,romfile=efi-virtio.rom"
deviceSerialString = "-device virtio-serial-pci,disable-modern=true,id=serial0,romfile=efi-virtio.rom,max_ports=2"
Expand Down
2 changes: 1 addition & 1 deletion qemu/qemu_s390x_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import "testing"
// -pci devices don't play well with Z hence replace them with corresponding -ccw devices
// See https://wiki.qemu.org/Documentation/Platforms/S390X
var (
deviceFSString = "-device virtio-9p-ccw,fsdev=workload9p,mount_tag=rootfs,devno=" + DevNo + " -fsdev local,id=workload9p,path=/var/lib/docker/devicemapper/mnt/e31ebda2,security_model=none"
deviceFSString = "-device virtio-9p-ccw,fsdev=workload9p,mount_tag=rootfs,devno=" + DevNo + " -fsdev local,id=workload9p,path=/var/lib/docker/devicemapper/mnt/e31ebda2,security_model=none,multidevs=remap"
deviceNetworkString = "-netdev tap,id=tap0,vhost=on,ifname=ceth0,downscript=no,script=no -device driver=virtio-net-ccw,netdev=tap0,mac=01:02:de:ad:be:ef,devno=" + DevNo
deviceNetworkStringMq = "-netdev tap,id=tap0,vhost=on,fds=3:4 -device driver=virtio-net-ccw,netdev=tap0,mac=01:02:de:ad:be:ef,mq=on,devno=" + DevNo
deviceSerialString = "-device virtio-serial-ccw,id=serial0,devno=" + DevNo
Expand Down
1 change: 1 addition & 0 deletions qemu/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func TestAppendDeviceFS(t *testing.T) {
SecurityModel: None,
DisableModern: true,
ROMFile: "efi-virtio.rom",
Multidev: Remap,
}

if fsdev.Transport.isVirtioCCW(nil) {
Expand Down

0 comments on commit abca6f3

Please sign in to comment.