The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/8100
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) ===
From 6d6aa4316fab5a127073cbbdfb9a807aa7007853 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 30 Oct 2020 11:02:37 +0100 Subject: [PATCH 1/3] lxd/instance/drivers: Issue warning if virtiofsd is missing Issue a warning instead of failing, if virtiofsd is missing. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/instance/drivers/driver_qemu.go | 74 +++++++++++++++-------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go index 8b59e1ea5b..17dfa3c246 100644 --- a/lxd/instance/drivers/driver_qemu.go +++ b/lxd/instance/drivers/driver_qemu.go @@ -884,37 +884,37 @@ func (vm *qemu) Start(stateful bool) error { } } - if cmd == "" { - return fmt.Errorf("Required binary 'virtiofsd' couldn't be found") - } + 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 + } - // 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 + } - err = proc.Start() - if err != nil { - return err - } + revert.Add(func() { proc.Stop() }) - revert.Add(func() { proc.Stop() }) + pidPath := filepath.Join(vm.LogPath(), "virtiofsd.pid") - pidPath := filepath.Join(vm.LogPath(), "virtiofsd.pid") + err = proc.Save(pidPath) + if err != nil { + return err + } - 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 + } - // Wait for socket file to exist - for i := 0; i < 10; i++ { - if shared.PathExists(sockPath) { - break + time.Sleep(50 * time.Millisecond) } - - 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. @@ -1898,18 +1898,22 @@ func (vm *qemu) generateQemuConfigFile(busName string, devConfs []*deviceConfig. return "", err } - devBus, devAddr, multi = bus.allocate(busFunctionGroup9p) - err = qemuDriveConfig.Execute(sb, map[string]interface{}{ - "bus": bus.name, - "devBus": devBus, - "devAddr": devAddr, - "multifunction": multi, - "protocol": "virtio-fs", + sockPath := filepath.Join(vm.LogPath(), "virtio-fs.config.sock") - "path": filepath.Join(vm.LogPath(), "virtio-fs.config.sock"), - }) - if err != nil { - return "", err + if shared.PathExists(sockPath) { + devBus, devAddr, multi = bus.allocate(busFunctionGroup9p) + err = qemuDriveConfig.Execute(sb, map[string]interface{}{ + "bus": bus.name, + "devBus": devBus, + "devAddr": devAddr, + "multifunction": multi, + "protocol": "virtio-fs", + + "path": sockPath, + }) + if err != nil { + return "", err + } } devBus, devAddr, multi = bus.allocate(busFunctionGroupNone) From 5254f369911c7d12042e070ece5ce3c1104c13b3 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 30 Oct 2020 11:03:04 +0100 Subject: [PATCH 2/3] lxd/device: Issue warning if virtiofsd is missing Issue a warning instead of failing, if virtiofsd is missing. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/device/disk.go | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lxd/device/disk.go b/lxd/device/disk.go index b20ac4a2ed..92e9c6b598 100644 --- a/lxd/device/disk.go +++ b/lxd/device/disk.go @@ -573,37 +573,37 @@ func (d *disk) startVM() (*deviceConfig.RunConfig, error) { } } - if cmd == "" { - return nil, fmt.Errorf("Required binary 'virtiofsd' couldn't be found") - } + 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", srcPath)}, logPath, logPath) + if err != nil { + return nil, err + } - // 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", srcPath)}, logPath, logPath) - if err != nil { - return nil, err - } + err = proc.Start() + if err != nil { + return nil, errors.Wrapf(err, "Failed to start virtiofsd for device %q", d.name) + } - err = proc.Start() - if err != nil { - return nil, errors.Wrapf(err, "Failed to start virtiofsd for device %q", d.name) - } + revert.Add(func() { proc.Stop() }) - revert.Add(func() { proc.Stop() }) + pidPath := filepath.Join(d.inst.DevicesPath(), fmt.Sprintf("virtio-fs.%s.pid", d.name)) - pidPath := filepath.Join(d.inst.DevicesPath(), fmt.Sprintf("virtio-fs.%s.pid", d.name)) + err = proc.Save(pidPath) + if err != nil { + return nil, errors.Wrapf(err, "Failed to save virtiofsd state for device %q", d.name) + } - err = proc.Save(pidPath) - if err != nil { - return nil, errors.Wrapf(err, "Failed to save virtiofsd state for device %q", d.name) - } + // Wait for socket file to exist + for i := 0; i < 10; i++ { + if shared.PathExists(sockPath) { + break + } - // Wait for socket file to exist - for i := 0; i < 10; i++ { - if shared.PathExists(sockPath) { - break + time.Sleep(50 * time.Millisecond) } - - time.Sleep(50 * time.Millisecond) + } else { + logger.Warnf("Unable to use virtio-fs for device %q, using 9p as a fallback: virtiofsd missing", d.name) } } From 0281f7f66e460c5ad93c228e8fc2ec3910bf93ab Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 30 Oct 2020 12:00:37 +0100 Subject: [PATCH 3/3] lxd/instance/drivers: Fix lxd-agent systemd unit conditions This fixes the lxd-agent mount service files, so that the 9p fallback actually works. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/instance/drivers/driver_qemu.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go index 17dfa3c246..cbe3770793 100644 --- a/lxd/instance/drivers/driver_qemu.go +++ b/lxd/instance/drivers/driver_qemu.go @@ -1465,7 +1465,7 @@ Documentation=https://linuxcontainers.org/lxd ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd After=local-fs.target lxd-agent-virtiofs.service DefaultDependencies=no -ConditionPathExists=!/run/lxd_config/drive +ConditionPathIsMountPoint=!/run/lxd_config/drive [Service] Type=oneshot @@ -1491,7 +1491,7 @@ ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd After=local-fs.target Before=lxd-agent-9p.service DefaultDependencies=no -ConditionPathExists=!/run/lxd_config/drive +ConditionPathIsMountPoint=!/run/lxd_config/drive [Service] Type=oneshot
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel