The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6895

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 8daad23611b3d975dcaea437e220d845a3102eba Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Tue, 18 Feb 2020 15:28:34 +0000
Subject: [PATCH 1/2] lxd/storage/backend/lxd: Adds logging for
 CreateInstanceFromBackup post hook

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/backend_lxd.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 3ec19c2bd9..0e17f60b55 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -528,6 +528,9 @@ func (b *lxdBackend) CreateInstanceFromBackup(srcBackup 
backup.Info, srcData io.
        // containing the instance's root disk device's config so that the 
driver's post hook function can access
        // that config to perform any post instance creation setup.
        postHook = func(inst instance.Instance) error {
+               logger.Debug("CreateInstanceFromBackup post hook started")
+               defer logger.Debug("CreateInstanceFromBackup post hook 
finished")
+
                // Get the root disk device config.
                rootDiskConf, err := b.instanceRootVolumeConfig(inst)
                if err != nil {

From a1cfabade4c26cd16d98440aee28067ecfe61b55 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Tue, 18 Feb 2020 15:57:38 +0000
Subject: [PATCH 2/2] lxd/storage/backend/lxd: Refuse to create storage pool if
 dir exists on disk

If the directory `/var/lib/lxd/storage-pools/<pool>` exists on disk, but pool 
doesn't exist in DB, if you try and create a storage pool of the same name and 
it fails (likely because the existing dir is non-empty) then the entire storage 
pool directory will be removed.

Changes check to refuse to create storage pool if directory already exists on 
disk.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/backend_lxd.go | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 0e17f60b55..b42036f22d 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -65,16 +65,21 @@ func (b *lxdBackend) MigrationTypes(contentType 
drivers.ContentType, refresh boo
 func (b *lxdBackend) create(localOnly bool, op *operations.Operation) error {
        logger := logging.AddContext(b.logger, log.Ctx{"config": b.db.Config, 
"description": b.db.Description, "localOnly": localOnly})
        logger.Debug("create started")
-       defer logger.Debug("created finished")
+       defer logger.Debug("create finished")
 
        revert := revert.New()
        defer revert.Fail()
 
-       // Create the storage path.
        path := drivers.GetPoolMountPath(b.name)
+
+       if shared.IsDir(path) {
+               return fmt.Errorf("Storage pool directory %q already exists", 
path)
+       }
+
+       // Create the storage path.
        err := os.MkdirAll(path, 0711)
-       if err != nil && !os.IsExist(err) {
-               return errors.Wrapf(err, "Failed to create directory '%s'", 
path)
+       if err != nil {
+               return errors.Wrapf(err, "Failed to create storage pool 
directory %q", path)
        }
 
        revert.Add(func() { os.RemoveAll(path) })
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to