[lxc-devel] [lxd/master] lxd/storage/drivers/driver/dir: Adds HostPath support
tomponline on Github
lxc-bot at linuxcontainers.org
Thu Jan 23 19:16:07 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 361 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200123/a4c83b9d/attachment.bin>
-------------- next part --------------
From 4b668a92723290a84256630fea0d7276ff58a179 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 23 Jan 2020 19:15:05 +0000
Subject: [PATCH] lxd/storage/drivers/driver/dir: Adds HostPath support
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/driver_dir.go | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/lxd/storage/drivers/driver_dir.go b/lxd/storage/drivers/driver_dir.go
index b894b1de99..027cee0b3f 100644
--- a/lxd/storage/drivers/driver_dir.go
+++ b/lxd/storage/drivers/driver_dir.go
@@ -50,24 +50,26 @@ func (d *dir) Create() error {
d.config["source"] = GetPoolMountPath(d.name)
}
- if !shared.PathExists(d.config["source"]) {
- return fmt.Errorf("Source path '%s' doesn't exist", d.config["source"])
+ sourcePath := shared.HostPath(d.config["source"])
+
+ if !shared.PathExists(sourcePath) {
+ return fmt.Errorf("Source path '%s' doesn't exist", sourcePath)
}
// Check that if within LXD_DIR, we're at our expected spot.
- cleanSource := filepath.Clean(d.config["source"])
+ cleanSource := filepath.Clean(sourcePath)
if strings.HasPrefix(cleanSource, shared.VarPath()) && cleanSource != GetPoolMountPath(d.name) {
- return fmt.Errorf("Source path '%s' is within the LXD directory", d.config["source"])
+ return fmt.Errorf("Source path '%s' is within the LXD directory", cleanSource)
}
// Check that the path is currently empty.
- isEmpty, err := shared.PathIsEmpty(d.config["source"])
+ isEmpty, err := shared.PathIsEmpty(sourcePath)
if err != nil {
return err
}
if !isEmpty {
- return fmt.Errorf("Source path '%s' isn't empty", d.config["source"])
+ return fmt.Errorf("Source path '%s' isn't empty", sourcePath)
}
return nil
@@ -103,19 +105,20 @@ func (d *dir) Update(changedConfig map[string]string) error {
// Mount mounts the storage pool.
func (d *dir) Mount() (bool, error) {
path := GetPoolMountPath(d.name)
+ sourcePath := shared.HostPath(d.config["source"])
// Check if we're dealing with an external mount.
- if d.config["source"] == path {
+ if sourcePath == path {
return false, nil
}
// Check if already mounted.
- if sameMount(d.config["source"], path) {
+ if sameMount(sourcePath, path) {
return false, nil
}
// Setup the bind-mount.
- err := TryMount(d.config["source"], path, "none", unix.MS_BIND, "")
+ err := TryMount(sourcePath, path, "none", unix.MS_BIND, "")
if err != nil {
return false, err
}
More information about the lxc-devel
mailing list