The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/8110

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From df7fface1c16a688d9c86d3ca4dfd1e2e5c803ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Mon, 2 Nov 2020 15:31:59 -0500
Subject: [PATCH] lxd/virtiofs: Fix handling of config drive
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/device/disk.go                  |  6 +-
 lxd/instance/drivers/driver_qemu.go | 97 +++++++++++++++--------------
 2 files changed, 56 insertions(+), 47 deletions(-)

diff --git a/lxd/device/disk.go b/lxd/device/disk.go
index 92e9c6b598..da3f862a68 100644
--- a/lxd/device/disk.go
+++ b/lxd/device/disk.go
@@ -595,13 +595,17 @@ func (d *disk) startVM() (*deviceConfig.RunConfig, error) 
{
                                        }
 
                                        // Wait for socket file to exist
-                                       for i := 0; i < 10; i++ {
+                                       for i := 0; i < 20; i++ {
                                                if shared.PathExists(sockPath) {
                                                        break
                                                }
 
                                                time.Sleep(50 * 
time.Millisecond)
                                        }
+
+                                       if !shared.PathExists(sockPath) {
+                                               return nil, 
fmt.Errorf("virtiofsd failed to bind socket within 2s")
+                                       }
                                } else {
                                        logger.Warnf("Unable to use virtio-fs 
for device %q, using 9p as a fallback: virtiofsd missing", d.name)
                                }
diff --git a/lxd/instance/drivers/driver_qemu.go 
b/lxd/instance/drivers/driver_qemu.go
index cbe3770793..a05c27b9cd 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -699,6 +699,7 @@ func (vm *qemu) Start(stateful bool) error {
                return err
        }
 
+       // Create all needed paths.
        err = os.MkdirAll(vm.LogPath(), 0700)
        if err != nil {
                op.Done(err)
@@ -717,6 +718,56 @@ func (vm *qemu) Start(stateful bool) error {
                return err
        }
 
+       // Setup virtiofsd for config path.
+       sockPath := filepath.Join(vm.LogPath(), "virtio-fs.config.sock")
+
+       // Remove old socket if needed.
+       os.Remove(sockPath)
+
+       cmd, err := exec.LookPath("virtiofsd")
+       if err != nil {
+               if shared.PathExists("/usr/lib/qemu/virtiofsd") {
+                       cmd = "/usr/lib/qemu/virtiofsd"
+               }
+       }
+
+       if cmd != "" {
+               // Start the virtiofsd process in non-daemon mode.
+               proc, err := subprocess.NewProcess(cmd, 
[]string{fmt.Sprintf("--socket-path=%s", sockPath), "-o", 
fmt.Sprintf("source=%s", filepath.Join(vm.Path(), "config"))}, "", "")
+               if err != nil {
+                       return err
+               }
+
+               err = proc.Start()
+               if err != nil {
+                       return err
+               }
+
+               revert.Add(func() { proc.Stop() })
+
+               pidPath := filepath.Join(vm.LogPath(), "virtiofsd.pid")
+
+               err = proc.Save(pidPath)
+               if err != nil {
+                       return err
+               }
+
+               // Wait for socket file to exist
+               for i := 0; i < 20; i++ {
+                       if shared.PathExists(sockPath) {
+                               break
+                       }
+
+                       time.Sleep(50 * time.Millisecond)
+               }
+
+               if !shared.PathExists(sockPath) {
+                       return fmt.Errorf("virtiofsd failed to bind socket 
within 1s")
+               }
+       } else {
+               logger.Warn("Unable to use virtio-fs for config drive, using 9p 
as a fallback: virtiofsd missing")
+       }
+
        // Get a UUID for Qemu.
        vmUUID := vm.localConfig["volatile.vm.uuid"]
        if vmUUID == "" {
@@ -872,51 +923,6 @@ func (vm *qemu) Start(stateful bool) error {
                forkLimitsCmd = append(forkLimitsCmd, fmt.Sprintf("fd=%d", 3+i))
        }
 
-       sockPath := filepath.Join(vm.LogPath(), "virtio-fs.config.sock")
-
-       // Remove old socket if needed.
-       os.Remove(sockPath)
-
-       cmd, err := exec.LookPath("virtiofsd")
-       if err != nil {
-               if shared.PathExists("/usr/lib/qemu/virtiofsd") {
-                       cmd = "/usr/lib/qemu/virtiofsd"
-               }
-       }
-
-       if cmd != "" {
-               // Start the virtiofsd process in non-daemon mode.
-               proc, err := subprocess.NewProcess(cmd, 
[]string{fmt.Sprintf("--socket-path=%s", sockPath), "-o", 
fmt.Sprintf("source=%s", filepath.Join(vm.Path(), "config"))}, "", "")
-               if err != nil {
-                       return err
-               }
-
-               err = proc.Start()
-               if err != nil {
-                       return err
-               }
-
-               revert.Add(func() { proc.Stop() })
-
-               pidPath := filepath.Join(vm.LogPath(), "virtiofsd.pid")
-
-               err = proc.Save(pidPath)
-               if err != nil {
-                       return err
-               }
-
-               // Wait for socket file to exist
-               for i := 0; i < 10; i++ {
-                       if shared.PathExists(sockPath) {
-                               break
-                       }
-
-                       time.Sleep(50 * time.Millisecond)
-               }
-       } else {
-               logger.Warn("Unable to use virtio-fs for config drive, using 9p 
as a fallback: virtiofsd missing")
-       }
-
        // Setup background process.
        p, err := subprocess.NewProcess(vm.state.OS.ExecPath, 
append(forkLimitsCmd, qemuCmd...), vm.EarlyLogFilePath(), vm.EarlyLogFilePath())
        if err != nil {
@@ -1899,7 +1905,6 @@ func (vm *qemu) generateQemuConfigFile(busName string, 
devConfs []*deviceConfig.
        }
 
        sockPath := filepath.Join(vm.LogPath(), "virtio-fs.config.sock")
-
        if shared.PathExists(sockPath) {
                devBus, devAddr, multi = bus.allocate(busFunctionGroup9p)
                err = qemuDriveConfig.Execute(sb, map[string]interface{}{
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to