summaryrefslogtreecommitdiff
path: root/pkg/machine/qemu/machine.go
diff options
context:
space:
mode:
authorAnders F Björklund <anders.f.bjorklund@gmail.com>2021-09-05 22:16:59 +0200
committerAnders F Björklund <anders.f.bjorklund@gmail.com>2021-12-30 13:36:56 +0100
commit8e7eeaa4dd14621bda15e396fcd7b9187bc500c5 (patch)
tree48c47ce64edb0ac5288fbe2e1a74a7c2ace28fb8 /pkg/machine/qemu/machine.go
parent807f7cfed3df770abcb7609e9b281d666a110b27 (diff)
downloadpodman-8e7eeaa4dd14621bda15e396fcd7b9187bc500c5.tar.gz
podman-8e7eeaa4dd14621bda15e396fcd7b9187bc500c5.tar.bz2
podman-8e7eeaa4dd14621bda15e396fcd7b9187bc500c5.zip
Implement virtfs volumes for podman machine
Allow using the built-in 9pfs feature of qemu, mounting host directories into vm mountpoints. The volumes are generic, the mounts are specific. Wait for the machine to be "running", otherwise the SSH function might throw an error instead. Increase the default msize from 8 KiB to 128 KiB [NO NEW TESTS NEEDED] Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Diffstat (limited to 'pkg/machine/qemu/machine.go')
-rw-r--r--pkg/machine/qemu/machine.go48
1 files changed, 47 insertions, 1 deletions
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index a80a11573..7bef4ff8e 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -167,6 +167,21 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
// Add arch specific options including image location
v.CmdLine = append(v.CmdLine, v.addArchOptions()...)
+ mounts := []Mount{}
+ for i, volume := range opts.Volumes {
+ tag := fmt.Sprintf("vol%d", i)
+ paths := strings.SplitN(volume, ":", 2)
+ source := paths[0]
+ target := source
+ if len(paths) > 1 {
+ target = paths[1]
+ }
+ addVirtfsOptions := []string{"-virtfs", fmt.Sprintf("local,path=%s,mount_tag=%s,security_model=mapped-xattr", source, tag)}
+ v.CmdLine = append(v.CmdLine, addVirtfsOptions...)
+ mounts = append(mounts, Mount{Type: "9p", Tag: tag, Source: source, Target: target})
+ }
+ v.Mounts = mounts
+
// Add location of bootable image
v.CmdLine = append(v.CmdLine, "-drive", "if=virtio,file="+v.ImagePath)
// This kind of stinks but no other way around this r/n
@@ -329,7 +344,28 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
return err
}
_, err = bufio.NewReader(conn).ReadString('\n')
- return err
+ if err != nil {
+ return err
+ }
+
+ if len(v.Mounts) > 0 {
+ for !v.isRunning() || !v.isListening() {
+ time.Sleep(100 * time.Millisecond)
+ }
+ }
+ for _, mount := range v.Mounts {
+ fmt.Printf("Mounting volume... %s:%s\n", mount.Source, mount.Target)
+ // create mountpoint directory if it doesn't exist
+ err = v.SSH(name, machine.SSHOptions{Args: []string{"-q", "--", "sudo", "mkdir", "-p", mount.Target}})
+ if err != nil {
+ return err
+ }
+ err = v.SSH(name, machine.SSHOptions{Args: []string{"-q", "--", "sudo", "mount", "-t", mount.Type, "-o", "trans=virtio", mount.Tag, mount.Target, "-o", "version=9p2000.L,msize=131072"}})
+ if err != nil {
+ return err
+ }
+ }
+ return nil
}
// Stop uses the qmp monitor to call a system_powerdown
@@ -506,6 +542,16 @@ func (v *MachineVM) isRunning() bool {
return true
}
+func (v *MachineVM) isListening() bool {
+ // Check if we can dial it
+ conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", "localhost", v.Port), 10*time.Millisecond)
+ if err != nil {
+ return false
+ }
+ conn.Close()
+ return true
+}
+
// SSH opens an interactive SSH session to the vm specified.
// Added ssh function to VM interface: pkg/machine/config/go : line 58
func (v *MachineVM) SSH(name string, opts machine.SSHOptions) error {