[lxc-devel] [lxd/master] CEPH storage volume copy fixes
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Mar 26 21:40:03 UTC 2019
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/20190326/11b7605a/attachment.bin>
-------------- next part --------------
From e0e4fdc4b7d1b1c37de16e3fe02584867c02ded6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 26 Mar 2019 14:15:28 -0400
Subject: [PATCH 1/3] lxd/storage/ceph: Only freeze if needed
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 0e379a6bdb..1f9572268b 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -2762,17 +2762,20 @@ func (s *storageCeph) GetState() *state.State {
func (s *storageCeph) StoragePoolVolumeSnapshotCreate(target *api.StorageVolumeSnapshotsPost) error {
logger.Debugf("Creating RBD storage volume snapshot \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
-
- // 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()
sourcePath := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
- msg, fsFreezeErr := shared.TryRunCommand("fsfreeze", "--freeze", sourcePath)
- logger.Debugf("Trying to freeze the filesystem: %s: %s", msg, fsFreezeErr)
- if fsFreezeErr == nil {
- defer shared.TryRunCommand("fsfreeze", "--unfreeze", sourcePath)
+
+ if shared.IsMountPoint(sourcePath) {
+ // 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()
+
+ msg, fsFreezeErr := shared.TryRunCommand("fsfreeze", "--freeze", sourcePath)
+ logger.Debugf("Trying to freeze the filesystem: %s: %s", msg, fsFreezeErr)
+ if fsFreezeErr == nil {
+ defer shared.TryRunCommand("fsfreeze", "--unfreeze", sourcePath)
+ }
}
sourceOnlyName, snapshotOnlyName, _ := containerGetParentAndSnapshotName(target.Name)
From b3e9a6fa91f80a0ed7aa0e92eab4b401aa3c1ce2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 26 Mar 2019 17:38:32 -0400
Subject: [PATCH 2/3] lxd/storage/ceph: Fix copying existing volume snap
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 | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 1f9572268b..fcbea03319 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -2635,38 +2635,44 @@ func (s *storageCeph) StoragePoolVolumeCopy(source *api.StorageVolumeSource) err
return err
}
} else {
- // create sparse copy
- snapshotName := uuid.NewRandom().String()
-
- // create snapshot of original volume
- err := cephRBDSnapshotCreate(s.ClusterName, s.OSDPoolName, source.Name, storagePoolVolumeTypeNameCustom, snapshotName, s.UserName)
- if err != nil {
- logger.Errorf("Failed to create snapshot of RBD storage volume \"%s\" on storage pool \"%s\": %s", source.Name, source.Pool, err)
- return err
+ sourceOnlyName, snapshotOnlyName, isSnapshot := containerGetParentAndSnapshotName(source.Name)
+ if isSnapshot {
+ snapshotOnlyName = fmt.Sprintf("snapshot_%s", snapshotOnlyName)
+ } else {
+ // create sparse copy
+ snapshotOnlyName = uuid.NewRandom().String()
+
+ // create snapshot of original volume
+ err := cephRBDSnapshotCreate(s.ClusterName, s.OSDPoolName, sourceOnlyName, storagePoolVolumeTypeNameCustom, snapshotOnlyName, s.UserName)
+ if err != nil {
+ logger.Errorf("Failed to create snapshot of RBD storage volume \"%s\" on storage pool \"%s\": %s", sourceOnlyName, source.Pool, err)
+ return err
+ }
}
// protect volume so we can create clones of it
- err = cephRBDSnapshotProtect(s.ClusterName, s.OSDPoolName, source.Name, storagePoolVolumeTypeNameCustom, snapshotName, s.UserName)
+ err := cephRBDSnapshotProtect(s.ClusterName, s.OSDPoolName, sourceOnlyName, storagePoolVolumeTypeNameCustom, snapshotOnlyName, s.UserName)
if err != nil {
- logger.Errorf("Failed to protect snapshot for RBD storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
+ logger.Errorf("Failed to protect snapshot for RBD storage volume \"%s\" on storage pool \"%s\": %s", sourceOnlyName, s.pool.Name, err)
return err
}
// create new clone
- err = cephRBDCloneCreate(s.ClusterName, s.OSDPoolName, source.Name, storagePoolVolumeTypeNameCustom, snapshotName, s.OSDPoolName, s.volume.Name, storagePoolVolumeTypeNameCustom, s.UserName)
+ err = cephRBDCloneCreate(s.ClusterName, s.OSDPoolName, sourceOnlyName, storagePoolVolumeTypeNameCustom, snapshotOnlyName, s.OSDPoolName, s.volume.Name, storagePoolVolumeTypeNameCustom, s.UserName)
if err != nil {
logger.Errorf("Failed to clone RBD storage volume \"%s\" on storage pool \"%s\": %s", source.Name, source.Pool, err)
return err
}
}
+ // Map the rbd
RBDDevPath, err := cephRBDVolumeMap(s.ClusterName, s.OSDPoolName, s.volume.Name, storagePoolVolumeTypeNameCustom, s.UserName)
if err != nil {
logger.Errorf("Failed to map RBD storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
return err
}
- // Generate a new xfs's UUID
+ // Generate a new UUID
RBDFilesystem := s.getRBDFilesystem()
msg, err := fsGenerateNewUUID(RBDFilesystem, RBDDevPath)
if err != nil {
From e13536b05107fc354006f4bc2608d77c3c62586b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 26 Mar 2019 17:39:15 -0400
Subject: [PATCH 3/3] lxd/storage/ceph: Always unmap after use
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 | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index fcbea03319..71f834e249 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -2680,8 +2680,14 @@ func (s *storageCeph) StoragePoolVolumeCopy(source *api.StorageVolumeSource) err
return err
}
- var volumeMntPoint string
+ // Unmap the rbd
+ err = cephRBDVolumeUnmap(s.ClusterName, s.OSDPoolName, s.volume.Name, storagePoolVolumeTypeNameCustom, s.UserName, true)
+ if err != nil {
+ logger.Errorf("Failed to unmap RBD storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
+ return err
+ }
+ var volumeMntPoint string
if isSnapshot {
volumeMntPoint = getStoragePoolVolumeSnapshotMountPoint(s.pool.Name, s.volume.Name)
} else {
More information about the lxc-devel
mailing list