[lxc-devel] [lxd/master] Backup: Fixes backup dir creation when using custom daemon storage volumes

tomponline on Github lxc-bot at linuxcontainers.org
Thu Sep 24 15:04:37 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/20200924/d7e8b45d/attachment.bin>
-------------- next part --------------
From f0ffccd6f18e4ddd477da4d09d052d075c88d9c5 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 24 Sep 2020 16:01:47 +0100
Subject: [PATCH 1/6] lxd/sys/fs: initDirs comment

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/sys/fs.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/sys/fs.go b/lxd/sys/fs.go
index 482d0ba0dc..93991792d4 100644
--- a/lxd/sys/fs.go
+++ b/lxd/sys/fs.go
@@ -35,7 +35,7 @@ func (s *OS) LegacyGlobalDatabasePath() string {
 	return filepath.Join(s.VarDir, "raft", "db.bin")
 }
 
-// Make sure all our directories are available.
+// initDirs Make sure all our directories are available.
 func (s *OS) initDirs() error {
 	dirs := []struct {
 		path string

From 904349f08e1865c2b8534cca2062c051a23b624c Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 24 Sep 2020 16:02:01 +0100
Subject: [PATCH 2/6] lxd/sys/fs: Removes backups/instances and backups/custom
 from pre-storage mount setup

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/sys/fs.go | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lxd/sys/fs.go b/lxd/sys/fs.go
index 93991792d4..61e711ac08 100644
--- a/lxd/sys/fs.go
+++ b/lxd/sys/fs.go
@@ -43,8 +43,6 @@ func (s *OS) initDirs() error {
 	}{
 		{s.VarDir, 0711},
 		{filepath.Join(s.VarDir, "backups"), 0700},
-		{filepath.Join(s.VarDir, "backups", "custom"), 0700},
-		{filepath.Join(s.VarDir, "backups", "instances"), 0700},
 		{s.CacheDir, 0700},
 		// containers is 0711 because liblxc needs to traverse dir to get to each container.
 		{filepath.Join(s.VarDir, "containers"), 0711},

From 2700f35c735738240f71a8226e0eb853db316f65 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 24 Sep 2020 16:02:48 +0100
Subject: [PATCH 3/6] lxd/sys/fs: initDirs error quoting

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/sys/fs.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/sys/fs.go b/lxd/sys/fs.go
index 61e711ac08..a9b6326126 100644
--- a/lxd/sys/fs.go
+++ b/lxd/sys/fs.go
@@ -70,12 +70,12 @@ func (s *OS) initDirs() error {
 		err := os.Mkdir(dir.path, dir.mode)
 		if err != nil {
 			if !os.IsExist(err) {
-				return errors.Wrapf(err, "Failed to init dir %s", dir.path)
+				return errors.Wrapf(err, "Failed to init dir %q", dir.path)
 			}
 
 			err = os.Chmod(dir.path, dir.mode)
 			if err != nil && !os.IsNotExist(err) {
-				return errors.Wrapf(err, "Failed to chmod dir %s", dir.path)
+				return errors.Wrapf(err, "Failed to chmod dir %q", dir.path)
 			}
 		}
 	}

From bad724ab9e6d962c94cc6a844837c7996378364e Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 24 Sep 2020 16:03:01 +0100
Subject: [PATCH 4/6] lxd/sys/fs: Adds initStorageDirs to be called after
 storage pools and daemon volumes are mounted

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

diff --git a/lxd/sys/fs.go b/lxd/sys/fs.go
index a9b6326126..9aefba8155 100644
--- a/lxd/sys/fs.go
+++ b/lxd/sys/fs.go
@@ -82,3 +82,30 @@ func (s *OS) initDirs() error {
 
 	return nil
 }
+
+// initStorageDirs make sure all our directories are on the storage layer (after storage is mounted).
+func (s *OS) initStorageDirs() error {
+	dirs := []struct {
+		path string
+		mode os.FileMode
+	}{
+		{filepath.Join(s.VarDir, "backups", "custom"), 0700},
+		{filepath.Join(s.VarDir, "backups", "instances"), 0700},
+	}
+
+	for _, dir := range dirs {
+		err := os.Mkdir(dir.path, dir.mode)
+		if err != nil {
+			if !os.IsExist(err) {
+				return errors.Wrapf(err, "Failed to init storage dir %q", dir.path)
+			}
+
+			err = os.Chmod(dir.path, dir.mode)
+			if err != nil && !os.IsNotExist(err) {
+				return errors.Wrapf(err, "Failed to chmod storage dir %q", dir.path)
+			}
+		}
+	}
+
+	return nil
+}

From f2093e17c87f2d510697747c3d299c5aeb9d25fa Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 24 Sep 2020 16:03:33 +0100
Subject: [PATCH 5/6] lxd/sys/os: Adds InitStorage

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

diff --git a/lxd/sys/os.go b/lxd/sys/os.go
index c68ceb6aaf..61cdf47394 100644
--- a/lxd/sys/os.go
+++ b/lxd/sys/os.go
@@ -146,3 +146,8 @@ func (s *OS) Init() error {
 
 	return nil
 }
+
+// InitStorage initialises the storage layer after it has been mounted.
+func (s *OS) InitStorage() error {
+	return s.initStorageDirs()
+}

From 089b47bf24add39c582a949eb61f3fb0b405170d Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 24 Sep 2020 16:03:50 +0100
Subject: [PATCH 6/6] lxd/daemon: Call d.os.InitStorage after daemon storage
 volumes are mounted

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

diff --git a/lxd/daemon.go b/lxd/daemon.go
index 171d0df966..a422ef8b20 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -938,6 +938,12 @@ func (d *Daemon) init() error {
 		return err
 	}
 
+	// Create directories on daemon storage mounts.
+	err = d.os.InitStorage()
+	if err != nil {
+		return err
+	}
+
 	// Apply all patches that need to be run after daemon storage is initialised.
 	err = patchesApply(d, patchPostDaemonStorage)
 	if err != nil {


More information about the lxc-devel mailing list