[lxc-devel] [lxd/master] Tweaks to 9p VM mounts
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Mar 4 23:05:00 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200304/3375b824/attachment.bin>
-------------- next part --------------
From 193d15431bc0d65e6a87ddcbfdcfba6184699cc3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 5 Mar 2020 00:00:37 +0100
Subject: [PATCH 1/2] lxd/vm: Tweak to mount field names
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Rename to better line up with usual kernel names for those arguments.
Also set JSON field names so the JSON file looks more like a normal LXD one.
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd-agent/main_agent.go | 8 ++++----
lxd/instance/drivers/driver_qemu.go | 8 ++++----
lxd/instance/instancetype/instance_vmagentmount.go | 8 ++++----
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/lxd-agent/main_agent.go b/lxd-agent/main_agent.go
index 3d959c7f33..6eeaf20485 100644
--- a/lxd-agent/main_agent.go
+++ b/lxd-agent/main_agent.go
@@ -201,18 +201,18 @@ func (c *cmdAgent) mountHostShares() {
}
for _, mount := range agentMounts {
- args := []string{"-t", mount.FSType, mount.Source, mount.TargetPath}
+ args := []string{"-t", mount.FSType, mount.Source, mount.Target}
- for _, opt := range mount.Opts {
+ for _, opt := range mount.Options {
args = append(args, "-o", opt)
}
_, err = shared.RunCommand("mount", args...)
if err != nil {
- logger.Errorf("Failed mount %q (Type: %q, Opts: %v) to %q: %v", mount.Source, mount.FSType, mount.Opts, mount.TargetPath, err)
+ logger.Errorf("Failed mount %q (Type: %q, Options: %v) to %q: %v", mount.Source, mount.FSType, mount.Options, mount.Target, err)
continue
}
- logger.Infof("Mounted %q (Type: %q, Opts: %v) to %q", mount.Source, mount.FSType, mount.Opts, mount.TargetPath)
+ logger.Infof("Mounted %q (Type: %q, Options: %v) to %q", mount.Source, mount.FSType, mount.Options, mount.Target)
}
}
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index d0aedaa732..8863e3fb78 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -1745,15 +1745,15 @@ func (vm *qemu) addDriveDirConfig(sb *strings.Builder, fdFiles *[]string, agentM
mountTag := fmt.Sprintf("lxd_%s", driveConf.DevName)
agentMount := instancetype.VMAgentMount{
- Source: mountTag,
- TargetPath: driveConf.TargetPath,
- FSType: driveConf.FSType,
+ Source: mountTag,
+ Target: driveConf.TargetPath,
+ FSType: driveConf.FSType,
}
// Indicate to agent to mount this readonly. Note: This is purely to indicate to VM guest that this is
// readonly, it should *not* be used as a security measure, as the VM guest could remount it R/W.
if shared.StringInSlice("ro", driveConf.Opts) {
- agentMount.Opts = append(agentMount.Opts, "ro")
+ agentMount.Options = append(agentMount.Options, "ro")
}
// Record the 9p mount for the agent.
diff --git a/lxd/instance/instancetype/instance_vmagentmount.go b/lxd/instance/instancetype/instance_vmagentmount.go
index a8383aa9c0..113da022ff 100644
--- a/lxd/instance/instancetype/instance_vmagentmount.go
+++ b/lxd/instance/instancetype/instance_vmagentmount.go
@@ -2,8 +2,8 @@ package instancetype
// VMAgentMount defines mounts to perform inside VM via agent.
type VMAgentMount struct {
- Source string
- TargetPath string
- FSType string
- Opts []string
+ Source string `json:"source"`
+ Target string `json:"target"`
+ FSType string `json:"fstype"`
+ Options []string `json:"options"`
}
From 2cd935c70e5c0165c89e823e2cc6d883e1f802e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 5 Mar 2020 00:04:26 +0100
Subject: [PATCH 2/2] lxd-agent: Create mount path if missing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.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 6eeaf20485..085ea639eb 100644
--- a/lxd-agent/main_agent.go
+++ b/lxd-agent/main_agent.go
@@ -201,6 +201,13 @@ func (c *cmdAgent) mountHostShares() {
}
for _, mount := range agentMounts {
+ if !shared.PathExists(mount.Target) {
+ err := os.MkdirAll(mount.Target, 0755)
+ if err != nil {
+ logger.Errorf("Failed to create mount target %q", mount.Target)
+ }
+ }
+
args := []string{"-t", mount.FSType, mount.Source, mount.Target}
for _, opt := range mount.Options {
More information about the lxc-devel
mailing list