[lxc-devel] [lxd/master] lxd/storage/ceph: Only freeze container if running

stgraber on Github lxc-bot at linuxcontainers.org
Tue Aug 21 17:18:15 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180821/e0f3d9a3/attachment.bin>
-------------- next part --------------
From 4c41b09fc058669674c0c481fee30fa4c6ea07c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 21 Aug 2018 13:17:51 -0400
Subject: [PATCH] lxd/storage/ceph: Only freeze container if running
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_ceph.go | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 15b6c6ce91..0345fd7176 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -1618,16 +1618,19 @@ func (s *storageCeph) ContainerGetUsage(container container) (int64, error) {
 }
 
 func (s *storageCeph) ContainerSnapshotCreate(snapshotContainer container, sourceContainer container) error {
-	// This is costly but we need to ensure that all cached data has
-	// been committed to disk. If we don't then the rbd snapshot of
-	// the underlying filesystem can be inconsistent or - worst case
-	// - empty.
-	syscall.Sync()
-	containerMntPoint := getContainerMountPoint(s.pool.Name, sourceContainer.Name())
-	msg, fsFreezeErr := shared.TryRunCommand("fsfreeze", "--freeze", containerMntPoint)
-	logger.Debugf("Trying to freeze the filesystem: %s: %s", msg, fsFreezeErr)
-	if fsFreezeErr == nil {
-		defer shared.TryRunCommand("fsfreeze", "--unfreeze", containerMntPoint)
+	if sourceContainer.IsRunning() {
+		// This is costly but we need to ensure that all cached data has
+		// been committed to disk. If we don't then the rbd snapshot of
+		// the underlying filesystem can be inconsistent or - worst case
+		// - empty.
+		syscall.Sync()
+
+		containerMntPoint := getContainerMountPoint(s.pool.Name, sourceContainer.Name())
+		msg, fsFreezeErr := shared.TryRunCommand("fsfreeze", "--freeze", containerMntPoint)
+		logger.Debugf("Trying to freeze the filesystem: %s: %s", msg, fsFreezeErr)
+		if fsFreezeErr == nil {
+			defer shared.TryRunCommand("fsfreeze", "--unfreeze", containerMntPoint)
+		}
 	}
 
 	return s.doContainerSnapshotCreate(snapshotContainer.Name(), sourceContainer.Name())


More information about the lxc-devel mailing list