[lxc-devel] [lxd/master] storage: rework container volume properties

brauner on Github lxc-bot at linuxcontainers.org
Tue Sep 26 19:24:52 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 667 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170926/64482dbe/attachment.bin>
-------------- next part --------------
From c10ec57e662a52a0a0b0e90c4508c272c710d2ab Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 26 Sep 2017 20:42:09 +0200
Subject: [PATCH 1/3] storage api: move check for type into api

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_volumes.go       | 9 +++++++++
 lxd/storage_volumes_utils.go | 7 -------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index ba2233d2f..4e42ba9f6 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -164,6 +164,15 @@ func storagePoolVolumesTypePost(d *Daemon, r *http.Request) Response {
 	// volume is supposed to be created.
 	poolName := mux.Vars(r)["name"]
 
+
+	// We currently only allow to create storage volumes of type
+	// storagePoolVolumeTypeCustom. So check, that nothing else was
+	// requested.
+	if req.Type != storagePoolVolumeTypeNameCustom {
+		return BadRequest(fmt.Errorf(`Currently not allowed to create `+
+			`storage volumes of type %s`, req.Type))
+	}
+
 	err = storagePoolVolumeCreateInternal(d.State(), poolName, req.Name, req.Description, req.Type, req.Config)
 	if err != nil {
 		return InternalError(err)
diff --git a/lxd/storage_volumes_utils.go b/lxd/storage_volumes_utils.go
index d4e4bc221..561922e63 100644
--- a/lxd/storage_volumes_utils.go
+++ b/lxd/storage_volumes_utils.go
@@ -302,13 +302,6 @@ func storagePoolVolumeDBCreate(s *state.State, poolName string, volumeName, volu
 		return err
 	}
 
-	// We currently only allow to create storage volumes of type
-	// storagePoolVolumeTypeCustom. So check, that nothing else was
-	// requested.
-	if volumeType != storagePoolVolumeTypeCustom {
-		return fmt.Errorf("currently not allowed to create storage volumes of type %s", volumeTypeName)
-	}
-
 	// Load storage pool the volume will be attached to.
 	poolID, poolStruct, err := db.StoragePoolGet(s.DB, poolName)
 	if err != nil {

From 01f5bc816489cccbf0ba2d45aada9b3ff47a0a1b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 26 Sep 2017 21:06:16 +0200
Subject: [PATCH 2/3] storage: rework container volume properties

For storage volumes of type storagePoolVolumeTypeContainer We only allow to
change properties directly on the storage volume if there's not corresponding
way to change it by other means. A good example is the "size" property which
can be manipulated by setting a root disk device "size" property.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_btrfs.go          | 4 ++++
 lxd/storage_ceph.go           | 4 ++++
 lxd/storage_lvm.go            | 4 ++++
 lxd/storage_volumes.go        | 1 -
 lxd/storage_volumes_config.go | 5 +++++
 lxd/storage_zfs.go            | 4 ++++
 6 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 06d0c924b..9aabdc054 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -624,6 +624,10 @@ func (s *storageBtrfs) StoragePoolVolumeUpdate(writable *api.StorageVolumePut, c
 	}
 
 	if shared.StringInSlice("size", changedConfig) {
+		if s.volume.Type != storagePoolVolumeTypeNameCustom {
+			return updateStoragePoolVolumeError([]string{"size"}, "btrfs")
+		}
+
 		if s.volume.Config["size"] != writable.Config["size"] {
 			size, err := shared.ParseByteSizeString(writable.Config["size"])
 			if err != nil {
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index f081544a9..9b2626cba 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -684,6 +684,10 @@ func (s *storageCeph) StoragePoolVolumeUpdate(writable *api.StorageVolumePut, ch
 	}
 
 	if shared.StringInSlice("size", changedConfig) {
+		if s.volume.Type != storagePoolVolumeTypeNameCustom {
+			return updateStoragePoolVolumeError([]string{"size"}, "ceph")
+		}
+
 		if s.volume.Config["size"] != writable.Config["size"] {
 			size, err := shared.ParseByteSizeString(writable.Config["size"])
 			if err != nil {
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index f355d3e30..fb307e0d2 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -804,6 +804,10 @@ func (s *storageLvm) StoragePoolVolumeUpdate(writable *api.StorageVolumePut,
 	}
 
 	if shared.StringInSlice("size", changedConfig) {
+		if s.volume.Type != storagePoolVolumeTypeNameCustom {
+			return updateStoragePoolVolumeError([]string{"size"}, "lvm")
+		}
+
 		if s.volume.Config["size"] != writable.Config["size"] {
 			size, err := shared.ParseByteSizeString(writable.Config["size"])
 			if err != nil {
diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index 4e42ba9f6..ea960dd3d 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -164,7 +164,6 @@ func storagePoolVolumesTypePost(d *Daemon, r *http.Request) Response {
 	// volume is supposed to be created.
 	poolName := mux.Vars(r)["name"]
 
-
 	// We currently only allow to create storage volumes of type
 	// storagePoolVolumeTypeCustom. So check, that nothing else was
 	// requested.
diff --git a/lxd/storage_volumes_config.go b/lxd/storage_volumes_config.go
index 3110b49aa..8e64f9454 100644
--- a/lxd/storage_volumes_config.go
+++ b/lxd/storage_volumes_config.go
@@ -13,6 +13,11 @@ func updateStoragePoolVolumeError(unchangeable []string, driverName string) erro
 		`storage volumes`, unchangeable, driverName)
 }
 
+// For storage volumes of type storagePoolVolumeTypeContainer We only allow to
+// change properties directly on the storage volume if there's not
+// corresponding way to change it by other means. A good example is the "size"
+// property which can be manipulated by setting a root disk device "size"
+// property.
 var changeableStoragePoolVolumeProperties = map[string][]string{
 	"btrfs": {"size"},
 
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index e2dd3bbf4..1c955b770 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -581,6 +581,10 @@ func (s *storageZfs) StoragePoolVolumeUpdate(writable *api.StorageVolumePut, cha
 	}
 
 	if shared.StringInSlice("size", changedConfig) {
+		if s.volume.Type != storagePoolVolumeTypeNameCustom {
+			return updateStoragePoolVolumeError([]string{"size"}, "zfs")
+		}
+
 		if s.volume.Config["size"] != writable.Config["size"] {
 			size, err := shared.ParseByteSizeString(writable.Config["size"])
 			if err != nil {

From 57ea3df9e6d299cf18bc94f558eb547df6a7c800 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 26 Sep 2017 21:09:29 +0200
Subject: [PATCH 3/3] tests: adapt tests

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 test/suites/storage.sh | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/test/suites/storage.sh b/test/suites/storage.sh
index e4561dbac..b54366b6a 100644
--- a/test/suites/storage.sh
+++ b/test/suites/storage.sh
@@ -19,11 +19,9 @@ test_storage() {
   lxc storage show "$storage_pool" | grep -q 'description: foo'
 
   lxc storage volume create "$storage_pool" "$storage_volume"
-  if [ "$lxd_backend" != "dir" ] && [ "$lxd_backend" != "ceph" ]; then
-    # Test resizing/applying quota to a storage volume.
-    lxc storage volume set "$storage_pool" "$storage_volume" size 200MB
-    lxc storage volume unset "$storage_pool" "$storage_volume" size
-  fi
+  # Test resizing/applying quota to a storage volume's of type container fails.
+  ! lxc storage volume set "$storage_pool" "$storage_volume" size 200MB
+
   # Test setting description on a storage volume
   lxc storage volume show "$storage_pool" "$storage_volume" | sed 's/^description:.*/description: bar/' | lxc storage volume edit "$storage_pool" "$storage_volume"
   lxc storage volume show "$storage_pool" "$storage_volume" | grep -q 'description: bar'


More information about the lxc-devel mailing list