[lxc-devel] [lxd/master] storage: fix "size" property
brauner on Github
lxc-bot at linuxcontainers.org
Mon Aug 21 13:25:56 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170821/32f592e8/attachment.bin>
-------------- next part --------------
From 6c7605ef5c652abcbed349169cea0c943a30d916 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 18 Aug 2017 20:22:18 +0200
Subject: [PATCH 1/4] storage: fix "size" property
storage pools:
- the "size" property is not available for the dir storage driver
storage volumes:
- defaule "size" property can only be set for the lvm and ceph storage driver
Closes #3679.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_pools_config.go | 5 ++---
lxd/storage_volumes_config.go | 5 +----
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/lxd/storage_pools_config.go b/lxd/storage_pools_config.go
index 197497fce..8e2c75190 100644
--- a/lxd/storage_pools_config.go
+++ b/lxd/storage_pools_config.go
@@ -149,12 +149,11 @@ func storagePoolValidateConfig(name string, driver string, config map[string]str
}
func storagePoolFillDefault(name string, driver string, config map[string]string) error {
- if driver == "dir" || driver == "ceph" {
+ if driver == "dir" {
if config["size"] != "" {
return fmt.Errorf("the \"size\" property does not apply to %s storage pools", driver)
}
- }
- if driver != "dir" && driver != "ceph" {
+ } else {
if config["size"] == "" {
st := syscall.Statfs_t{}
err := syscall.Statfs(shared.VarPath(), &st)
diff --git a/lxd/storage_volumes_config.go b/lxd/storage_volumes_config.go
index c74bd0b72..d44ae1ea7 100644
--- a/lxd/storage_volumes_config.go
+++ b/lxd/storage_volumes_config.go
@@ -74,7 +74,7 @@ func storageVolumeValidateConfig(name string, config map[string]string, parentPo
}
func storageVolumeFillDefault(name string, config map[string]string, parentPool *api.StoragePool) error {
- if parentPool.Driver == "dir" || parentPool.Driver == "ceph" {
+ if parentPool.Driver == "dir" {
config["size"] = ""
} else if parentPool.Driver == "lvm" || parentPool.Driver == "ceph" {
if config["block.filesystem"] == "" {
@@ -106,10 +106,7 @@ func storageVolumeFillDefault(name string, config map[string]string, parentPool
if err != nil {
return err
}
- } else {
- config["size"] = "10GB"
}
-
}
return nil
From 7ab86a27fd2cf8ddb9193746ae4ef64209c93f40 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 18 Aug 2017 20:28:18 +0200
Subject: [PATCH 2/4] storage: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_pools_config.go | 4 ++--
lxd/storage_volumes_config.go | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lxd/storage_pools_config.go b/lxd/storage_pools_config.go
index 8e2c75190..b6fffdc25 100644
--- a/lxd/storage_pools_config.go
+++ b/lxd/storage_pools_config.go
@@ -151,14 +151,14 @@ func storagePoolValidateConfig(name string, driver string, config map[string]str
func storagePoolFillDefault(name string, driver string, config map[string]string) error {
if driver == "dir" {
if config["size"] != "" {
- return fmt.Errorf("the \"size\" property does not apply to %s storage pools", driver)
+ return fmt.Errorf("The \"size\" property does not apply to %s storage pools", driver)
}
} else {
if config["size"] == "" {
st := syscall.Statfs_t{}
err := syscall.Statfs(shared.VarPath(), &st)
if err != nil {
- return fmt.Errorf("couldn't statfs %s: %s", shared.VarPath(), err)
+ return fmt.Errorf("Couldn't statfs %s: %s", shared.VarPath(), err)
}
/* choose 15 GB < x < 100GB, where x is 20% of the disk size */
diff --git a/lxd/storage_volumes_config.go b/lxd/storage_volumes_config.go
index d44ae1ea7..37ac53877 100644
--- a/lxd/storage_volumes_config.go
+++ b/lxd/storage_volumes_config.go
@@ -93,10 +93,12 @@ func storageVolumeFillDefault(name string, config map[string]string, parentPool
config["block.mount_options"] = "discard"
}
+ // Does the pool request a default size for new storage volumes?
if config["size"] == "0" || config["size"] == "" {
config["size"] = parentPool.Config["volume.size"]
}
-
+ // Does the user explicitly request a default size for new
+ // storage volumes?
if config["size"] == "0" || config["size"] == "" {
config["size"] = "10GB"
}
From 7af4e9919bd12f236b7e6efe802b3fbe013724a3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 18 Aug 2017 20:28:33 +0200
Subject: [PATCH 3/4] storage: enable "volume.size" for {btrfs,zfs}
Closes #3679.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/storage_pools_config.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lxd/storage_pools_config.go b/lxd/storage_pools_config.go
index b6fffdc25..cc429186a 100644
--- a/lxd/storage_pools_config.go
+++ b/lxd/storage_pools_config.go
@@ -191,7 +191,7 @@ func storagePoolFillDefault(name string, driver string, config map[string]string
}
}
- if driver == "lvm" || driver == "ceph" {
+ if driver == "btrfs" || driver == "ceph" || driver == "lvm" || driver == "zfs" {
if config["volume.size"] != "" {
_, err := shared.ParseByteSizeString(config["volume.size"])
if err != nil {
From eae4a025d4677b47fce7e15ec5d51f2ede714e6f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 21 Aug 2017 15:18:29 +0200
Subject: [PATCH 4/4] patches: unset "size" for ZFS containers + images
Closes #3679.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/patches.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/lxd/patches.go b/lxd/patches.go
index b345ab6dd..11bb573e0 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -46,6 +46,7 @@ var patches = []patch{
{name: "storage_api_lvm_detect_lv_size", run: patchStorageApiDetectLVSize},
{name: "storage_api_insert_zfs_driver", run: patchStorageApiInsertZfsDriver},
{name: "storage_zfs_noauto", run: patchStorageZFSnoauto},
+ {name: "storage_zfs_volume_size", run: patchStorageZFSVolumeSize},
}
type patch struct {
@@ -2321,6 +2322,72 @@ func patchStorageZFSnoauto(name string, d *Daemon) error {
return nil
}
+func patchStorageZFSVolumeSize(name string, d *Daemon) error {
+ pools, err := db.StoragePools(d.db)
+ if err != nil && err == db.NoSuchObjectError {
+ // No pool was configured in the previous update. So we're on a
+ // pristine LXD instance.
+ return nil
+ } else if err != nil {
+ // Database is screwed.
+ logger.Errorf("Failed to query database: %s", err)
+ return err
+ }
+
+ for _, poolName := range pools {
+ poolID, pool, err := db.StoragePoolGet(d.db, poolName)
+ if err != nil {
+ logger.Errorf("Failed to query database: %s", err)
+ return err
+ }
+
+ // We only care about zfs
+ if pool.Driver != "zfs" {
+ continue
+ }
+
+ // Get all storage volumes on the storage pool.
+ volumes, err := db.StoragePoolVolumesGet(d.db, poolID, supportedVolumeTypes)
+ if err != nil {
+ if err == db.NoSuchObjectError {
+ continue
+ }
+ return err
+ }
+
+ for _, volume := range volumes {
+ if volume.Type != "container" && volume.Type != "image" {
+ continue
+ }
+
+ // ZFS storage volumes for containers and images should
+ // never have a size property set directly on the
+ // storage volume itself. For containers the size
+ // property is regulated either via a profiles root disk
+ // device size property or via the containers local
+ // root disk device size property. So unset it here
+ // unconditionally.
+ if volume.Config["size"] != "" {
+ volume.Config["size"] = ""
+ }
+
+ // It shouldn't be possible that false volume types
+ // exist in the db, so it's safe to ignore the error.
+ volumeType, _ := storagePoolVolumeTypeNameToType(volume.Type)
+ // Update the volume config.
+ err = db.StoragePoolVolumeUpdate(d.db, volume.Name,
+ volumeType, poolID, volume.Description,
+ volume.Config)
+ if err != nil {
+ return err
+ }
+ }
+
+ }
+
+ return nil
+}
+
// Patches end here
// Here are a couple of legacy patches that were originally in
More information about the lxc-devel
mailing list