[lxc-devel] [lxd/master] Use shared.IsSnapshot

stgraber on Github lxc-bot at linuxcontainers.org
Thu Apr 4 19:52:44 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/20190404/5635a2af/attachment-0001.bin>
-------------- next part --------------
From 0fb5e667c3f4445e2c26d69d7be5ecf150892a93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 4 Apr 2019 15:36:36 -0400
Subject: [PATCH 1/3] lxc/config: Use shared.IsSnapshot
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>
---
 lxc/config/remote.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxc/config/remote.go b/lxc/config/remote.go
index 416c047b1c..02cdaafd87 100644
--- a/lxc/config/remote.go
+++ b/lxc/config/remote.go
@@ -39,7 +39,7 @@ func (c *Config) ParseRemote(raw string) (string, string, error) {
 	_, ok := c.Remotes[result[0]]
 	if !ok {
 		// Attempt to play nice with snapshots containing ":"
-		if shared.IsSnapshot(raw) && strings.Contains(result[0], "/") {
+		if shared.IsSnapshot(raw) && shared.IsSnapshot(result[0]) {
 			return c.DefaultRemote, raw, nil
 		}
 

From 648370b25c0c81f65cd18cd98f8ccc294ca2ccfe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 4 Apr 2019 15:36:44 -0400
Subject: [PATCH 2/3] lxc: Use shared.IsSnapshot
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>
---
 lxc/storage_volume.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxc/storage_volume.go b/lxc/storage_volume.go
index 594225d34e..d609949eb5 100644
--- a/lxc/storage_volume.go
+++ b/lxc/storage_volume.go
@@ -371,7 +371,7 @@ func (c *cmdStorageVolumeCopy) Run(cmd *cobra.Command, args []string) error {
 	var srcVol *api.StorageVolume
 
 	// Check if requested storage volume exists
-	isSnapshot := strings.Contains(srcVolName, "/")
+	isSnapshot := shared.IsSnapshot(srcVolName)
 
 	if isSnapshot {
 		fields := strings.SplitN(srcVolName, "/", 2)
@@ -1102,7 +1102,7 @@ func (c *cmdStorageVolumeList) Run(cmd *cobra.Command, args []string) error {
 	for _, volume := range volumes {
 		usedby := strconv.Itoa(len(volume.UsedBy))
 		entry := []string{volume.Type, volume.Name, volume.Description, usedby}
-		if strings.Contains(volume.Name, "/") {
+		if shared.IsSnapshot(volume.Name) {
 			entry[0] = fmt.Sprintf("%s (snapshot)", volume.Type)
 		}
 		if resource.server.IsClustered() {

From dcd136f38792b687a82e46446bec7c04fcf485b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 4 Apr 2019 15:45:58 -0400
Subject: [PATCH 3/3] lxd/storage: Make use of shared.IsSnapshot
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_btrfs.go | 8 ++++----
 lxd/storage_ceph.go  | 4 ++--
 lxd/storage_dir.go   | 8 ++++----
 lxd/storage_lvm.go   | 4 ++--
 lxd/storage_zfs.go   | 8 ++++----
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index a1b3a8aed7..5e8d21045c 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -557,7 +557,7 @@ func (s *storageBtrfs) StoragePoolVolumeCreate() error {
 		return err
 	}
 
-	isSnapshot := strings.Contains(s.volume.Name, "/")
+	isSnapshot := shared.IsSnapshot(s.volume.Name)
 
 	// Create subvolume path on the storage pool.
 	var customSubvolumePath string
@@ -2931,8 +2931,8 @@ func (s *storageBtrfs) StoragePoolVolumeCopy(source *api.StorageVolumeSource) er
 	logger.Infof("Copying BTRFS storage volume \"%s\" on storage pool \"%s\" as \"%s\" to storage pool \"%s\"", source.Name, source.Pool, s.volume.Name, s.pool.Name)
 	successMsg := fmt.Sprintf("Copied BTRFS storage volume \"%s\" on storage pool \"%s\" as \"%s\" to storage pool \"%s\"", source.Name, source.Pool, s.volume.Name, s.pool.Name)
 
-	isSrcSnapshot := strings.Contains(source.Name, "/")
-	isDstSnapshot := strings.Contains(s.volume.Name, "/")
+	isSrcSnapshot := shared.IsSnapshot(source.Name)
+	isDstSnapshot := shared.IsSnapshot(s.volume.Name)
 
 	var srcMountPoint string
 	var dstMountPoint string
@@ -3119,7 +3119,7 @@ func (s *storageBtrfs) StoragePoolVolumeSnapshotRename(newName string) error {
 	logger.Infof("Renaming BTRFS storage volume on storage pool \"%s\" from \"%s\" to \"%s\"", s.pool.Name, s.volume.Name, newName)
 	var fullSnapshotName string
 
-	if strings.Contains(newName, "/") {
+	if shared.IsSnapshot(newName) {
 		// When renaming volume snapshots, newName will contain the full snapshot name
 		fullSnapshotName = newName
 	} else {
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 8e99ff126a..b7657c2921 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -728,7 +728,7 @@ func (s *storageCeph) StoragePoolVolumeRename(newName string) error {
 	logger.Debugf(`Mapped RBD storage volume for container "%s" on storage pool "%s"`,
 		newName, s.pool.Name)
 
-	isSnapshot := strings.Contains(s.volume.Name, "/")
+	isSnapshot := shared.IsSnapshot(s.volume.Name)
 
 	var oldPath string
 	var newPath string
@@ -2571,7 +2571,7 @@ func (s *storageCeph) StoragePoolVolumeCopy(source *api.StorageVolumeSource) err
 	logger.Infof("Copying RBD storage volume \"%s\" on storage pool \"%s\" as \"%s\" to storage pool \"%s\"", source.Name, source.Pool, s.volume.Name, s.pool.Name)
 	successMsg := fmt.Sprintf("Copied RBD storage volume \"%s\" on storage pool \"%s\" as \"%s\" to storage pool \"%s\"", source.Name, source.Pool, s.volume.Name, s.pool.Name)
 
-	isSnapshot := strings.Contains(s.volume.Name, "/")
+	isSnapshot := shared.IsSnapshot(s.volume.name)
 
 	var srcMountPoint string
 	var dstMountPoint string
diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go
index 2b29832f65..daea114ad7 100644
--- a/lxd/storage_dir.go
+++ b/lxd/storage_dir.go
@@ -334,7 +334,7 @@ func (s *storageDir) StoragePoolVolumeCreate() error {
 		return fmt.Errorf("no \"source\" property found for the storage pool")
 	}
 
-	isSnapshot := strings.Contains(s.volume.Name, "/")
+	isSnapshot := shared.IsSnapshot(s.volume.Name)
 
 	var storageVolumePath string
 
@@ -1311,8 +1311,8 @@ func (s *storageDir) StoragePoolVolumeCopy(source *api.StorageVolumeSource) erro
 	var srcMountPoint string
 	var dstMountPoint string
 
-	isSrcSnapshot := strings.Contains(source.Name, "/")
-	isDstSnapshot := strings.Contains(s.volume.Name, "/")
+	isSrcSnapshot := shared.IsSnapshot(source.Name)
+	isDstSnapshot := shared.IsSnapshot(s.volume.Name)
 
 	if isSrcSnapshot {
 		srcMountPoint = getStoragePoolVolumeSnapshotMountPoint(source.Pool, source.Name)
@@ -1432,7 +1432,7 @@ func (s *storageDir) StoragePoolVolumeSnapshotRename(newName string) error {
 	logger.Infof("Renaming DIR storage volume on storage pool \"%s\" from \"%s\" to \"%s\"", s.pool.Name, s.volume.Name, newName)
 	var fullSnapshotName string
 
-	if strings.Contains(newName, "/") {
+	if shared.IsSnapshot(newName) {
 		// When renaming volume snapshots, newName will contain the full snapshot name
 		fullSnapshotName = newName
 	} else {
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index b9fd4487da..91686f2005 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -2207,11 +2207,11 @@ func (s *storageLvm) StoragePoolVolumeCopy(source *api.StorageVolumeSource) erro
 	sourceName := source.Name
 	targetName := s.volume.Name
 
-	if strings.Contains(sourceName, "/") {
+	if shared.IsSnapshot(sourceName) {
 		sourceName = containerNameToLVName(sourceName)
 	}
 
-	if strings.Contains(targetName, "/") {
+	if shared.IsSnapshot(targetName) {
 		targetName = containerNameToLVName(targetName)
 	}
 
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 197e17a9dd..a0d23d86dc 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -393,7 +393,7 @@ func (s *storageZfs) StoragePoolUmount() (bool, error) {
 func (s *storageZfs) StoragePoolVolumeCreate() error {
 	logger.Infof("Creating ZFS storage volume \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
 
-	isSnapshot := strings.Contains(s.volume.Name, "/")
+	isSnapshot := shared.IsSnapshot(s.volume.Name)
 
 	var fs string
 
@@ -748,7 +748,7 @@ func (s *storageZfs) StoragePoolVolumeRename(newName string) error {
 			s.volume.Name, s.pool.Name)
 	}
 
-	isSnapshot := strings.Contains(s.volume.Name, "/")
+	isSnapshot := shared.IsSnapshot(s.volume.Name)
 
 	var oldPath string
 	var newPath string
@@ -3006,7 +3006,7 @@ func (s *storageZfs) doCrossPoolStorageVolumeCopy(source *api.StorageVolumeSourc
 }
 
 func (s *storageZfs) copyVolumeWithoutSnapshotsFull(source *api.StorageVolumeSource) error {
-	sourceIsSnapshot := strings.Contains(source.Name, "/")
+	sourceIsSnapshot := shared.IsSnapshot(source.Name)
 
 	var snapshotSuffix string
 	var sourceDataset string
@@ -3171,7 +3171,7 @@ func (s *storageZfs) StoragePoolVolumeCopy(source *api.StorageVolumeSource) erro
 
 	poolName := s.getOnDiskPoolName()
 
-	if !strings.Contains(source.Name, "/") {
+	if !shared.IsSnapshot(source.Name) {
 		snapshots, err = zfsPoolListSnapshots(poolName, fmt.Sprintf("custom/%s", source.Name))
 		if err != nil {
 			return err


More information about the lxc-devel mailing list