[lxc-devel] [lxd/master] Fix LVM errors and delays

stgraber on Github lxc-bot at linuxcontainers.org
Fri Nov 30 23:09:57 UTC 2018


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/20181130/e62d5d7f/attachment.bin>
-------------- next part --------------
From fac2f2fcd0967a9f51cbc2f96b02a25d0dbe56d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 30 Nov 2018 13:29:13 -0500
Subject: [PATCH 1/3] lxd/storage/lvm: Fix project handling
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/storage_lvm.go   | 6 +++---
 lxd/storage_utils.go | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 5377c0a49b..5fa3ada8ed 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -1623,7 +1623,6 @@ func (s *storageLvm) ContainerSnapshotStop(container container) (bool, error) {
 	snapshotMntPoint := getSnapshotMountPoint(container.Project(), s.pool.Name, containerName)
 
 	poolName := s.getOnDiskPoolName()
-	containerLvmName := containerNameToLVName(containerName)
 
 	if shared.IsMountPoint(snapshotMntPoint) {
 		err := tryUnmount(snapshotMntPoint, 0)
@@ -1632,13 +1631,14 @@ func (s *storageLvm) ContainerSnapshotStop(container container) (bool, error) {
 		}
 	}
 
-	containerLvmPath := getLvmDevPath(container.Project(), poolName, storagePoolVolumeAPIEndpointContainers, containerLvmName)
+	containerLvmPath := getLvmDevPath(container.Project(), poolName, storagePoolVolumeAPIEndpointContainers, containerNameToLVName(containerName))
 	wasWritableAtCheck, err := lvmLvIsWritable(containerLvmPath)
 	if err != nil {
 		return false, err
 	}
 
 	if wasWritableAtCheck {
+		containerLvmName := containerNameToLVName(projectPrefix(container.Project(), containerName))
 		output, err := shared.TryRunCommand("lvchange", "-pr", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointContainers, containerLvmName))
 		if err != nil {
 			logger.Errorf("Failed to make LVM snapshot read-only: %s", output)
@@ -1757,11 +1757,11 @@ func (s *storageLvm) ContainerBackupCreate(backup backup, source container) erro
 	if err != nil {
 		return err
 	}
-	defer s.umount("default", sourceLvmDatasetSnapshot, "")
 
 	// Copy the container
 	containerPath := fmt.Sprintf("%s/container", tmpPath)
 	err = rsync(tmpContainerMntPoint, containerPath, bwlimit)
+	s.umount(source.Project(), sourceLvmDatasetSnapshot, "")
 	if err != nil {
 		return err
 	}
diff --git a/lxd/storage_utils.go b/lxd/storage_utils.go
index 4bb24c03ab..d798a4d170 100644
--- a/lxd/storage_utils.go
+++ b/lxd/storage_utils.go
@@ -111,7 +111,7 @@ func tryUnmount(path string, flags int) error {
 		time.Sleep(500 * time.Millisecond)
 	}
 
-	if err != nil && err == syscall.EBUSY {
+	if err != nil {
 		return err
 	}
 

From 6c078b26da292306cc5a8f75bc23de9ebc454167 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 30 Nov 2018 17:34:25 -0500
Subject: [PATCH 2/3] lxd/storage: Fix check for custom volume restore
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/storage_volumes.go | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index 1016a397f7..9dcda8c89d 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -615,6 +615,7 @@ func storagePoolVolumeTypePost(d *Daemon, r *http.Request, volumeTypeName string
 		if err != nil {
 			return err
 		}
+
 		if len(ctsUsingVolume) > 0 {
 			return fmt.Errorf("Volume is still in use by running containers")
 		}
@@ -867,11 +868,19 @@ func storagePoolVolumeTypePut(d *Daemon, r *http.Request, volumeTypeName string)
 	}
 
 	if req.Restore != "" {
-		if len(volume.UsedBy) != 0 {
-			return PreconditionFailed(fmt.Errorf("Cannot restore attached volume"))
+		ctsUsingVolume, err := storagePoolVolumeUsedByRunningContainersWithProfilesGet(d.State(), poolName, volume.Name, storagePoolVolumeTypeNameCustom, true)
+		if err != nil {
+			return InternalError(err)
+		}
+
+		if len(ctsUsingVolume) != 0 {
+			return BadRequest(fmt.Errorf("Cannot restore custom volume used by running containers"))
 		}
 
 		err = storagePoolVolumeRestore(d.State(), poolName, volumeName, volumeType, req.Restore)
+		if err != nil {
+			return SmartError(err)
+		}
 	} else {
 		// Validate the configuration
 		err = storageVolumeValidateConfig(volumeName, req.Config, pool)
@@ -880,9 +889,9 @@ func storagePoolVolumeTypePut(d *Daemon, r *http.Request, volumeTypeName string)
 		}
 
 		err = storagePoolVolumeUpdate(d.State(), poolName, volumeName, volumeType, req.Description, req.Config)
-	}
-	if err != nil {
-		return SmartError(err)
+		if err != nil {
+			return SmartError(err)
+		}
 	}
 
 	return EmptySyncResponse

From 4787b8e6fbae77ea95d0b20ad5fb727e96feed60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 30 Nov 2018 17:39:28 -0500
Subject: [PATCH 3/3] shared: Fix import order
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>
---
 shared/util.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/shared/util.go b/shared/util.go
index 6641e16d05..e24c066a02 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -27,9 +27,10 @@ import (
 	"time"
 
 	"github.com/flosch/pongo2"
+	"github.com/pkg/errors"
+
 	"github.com/lxc/lxd/shared/cancel"
 	"github.com/lxc/lxd/shared/ioprogress"
-	"github.com/pkg/errors"
 )
 
 const SnapshotDelimiter = "/"


More information about the lxc-devel mailing list