[lxc-devel] [lxd/master] lxd-agent/main/agent: Fix 9p mount when relative target path is supplied

tomponline on Github lxc-bot at linuxcontainers.org
Fri Jun 19 10:01:06 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 552 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200619/66c3a35c/attachment.bin>
-------------- next part --------------
From 5a6b4127a71e12c6b9d96276a0e207fa12f78dff Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 19 Jun 2020 10:59:51 +0100
Subject: [PATCH] lxd-agent/main/agent: Fix 9p mount when relative target path
 is supplied

Convert to absolute from /.

Skip if mount point doesn't exist and can't be created.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd-agent/main_agent.go | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lxd-agent/main_agent.go b/lxd-agent/main_agent.go
index 74e01068ef..887428f12f 100644
--- a/lxd-agent/main_agent.go
+++ b/lxd-agent/main_agent.go
@@ -8,6 +8,7 @@ import (
 	"io/ioutil"
 	"os"
 	"os/signal"
+	"strings"
 	"time"
 
 	"github.com/pkg/errors"
@@ -211,10 +212,16 @@ func (c *cmdAgent) mountHostShares() {
 	}
 
 	for _, mount := range agentMounts {
+		// Convert relative mounts to absolute from / otherwise dir creation fails or mount fails.
+		if !strings.HasPrefix(mount.Target, "/") {
+			mount.Target = fmt.Sprintf("/%s", mount.Target)
+		}
+
 		if !shared.PathExists(mount.Target) {
 			err := os.MkdirAll(mount.Target, 0755)
 			if err != nil {
 				logger.Errorf("Failed to create mount target %q", mount.Target)
+				continue // Don't try to mount if mount point can't be created.
 			}
 		}
 


More information about the lxc-devel mailing list