The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2975

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Part of #2866.
From c6f95056f4e576c2e3ae0a3b87b1bd48595dcd52 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Tue, 28 Feb 2017 13:22:00 +0100
Subject: [PATCH 1/3] storage: change signature for StoragePoolUpdate()

        StoragePoolUpdate(changedConfig []string) error
becomes
        StoragePoolUpdate(writable *api.StoragePoolPut, changedConfig []string) 
error

because we need access to the writable fields.

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 lxd/storage.go             | 2 +-
 lxd/storage_btrfs.go       | 2 +-
 lxd/storage_dir.go         | 2 +-
 lxd/storage_lvm.go         | 7 ++++++-
 lxd/storage_mock.go        | 2 +-
 lxd/storage_pools_utils.go | 6 +++---
 lxd/storage_zfs.go         | 2 +-
 7 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/lxd/storage.go b/lxd/storage.go
index 0765294..3d118d3 100644
--- a/lxd/storage.go
+++ b/lxd/storage.go
@@ -202,7 +202,7 @@ type storage interface {
        StoragePoolDelete() error
        StoragePoolMount() (bool, error)
        StoragePoolUmount() (bool, error)
-       StoragePoolUpdate(changedConfig []string) error
+       StoragePoolUpdate(writable *api.StoragePoolPut, changedConfig []string) 
error
        GetStoragePoolWritable() api.StoragePoolPut
        SetStoragePoolWritable(writable *api.StoragePoolPut)
 
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 1a980da..7d62ae3 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -418,7 +418,7 @@ func (s *storageBtrfs) StoragePoolUmount() (bool, error) {
        return true, nil
 }
 
-func (s *storageBtrfs) StoragePoolUpdate(changedConfig []string) error {
+func (s *storageBtrfs) StoragePoolUpdate(writable *api.StoragePoolPut, 
changedConfig []string) error {
        return fmt.Errorf("Btrfs storage properties cannot be changed.")
 }
 
diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go
index 2691359..c9b0c1e 100644
--- a/lxd/storage_dir.go
+++ b/lxd/storage_dir.go
@@ -144,7 +144,7 @@ func (s *storageDir) GetContainerPoolInfo() (int64, string) 
{
        return s.poolID, s.pool.Name
 }
 
-func (s *storageDir) StoragePoolUpdate(changedConfig []string) error {
+func (s *storageDir) StoragePoolUpdate(writable *api.StoragePoolPut, 
changedConfig []string) error {
        return fmt.Errorf("Dir storage properties cannot be changed.")
 }
 
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index afac382..d8a1d5a 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -698,9 +698,14 @@ func (s *storageLvm) GetContainerPoolInfo() (int64, 
string) {
        return s.poolID, s.pool.Name
 }
 
-func (s *storageLvm) StoragePoolUpdate(changedConfig []string) error {
+func (s *storageLvm) StoragePoolUpdate(writable *api.StoragePoolPut, 
changedConfig []string) error {
        shared.LogInfof("Updating LVM storage pool \"%s\".", s.pool.Name)
 
+       err := s.StoragePoolCheck()
+       if err != nil {
+               return err
+       }
+
        if shared.StringInSlice("size", changedConfig) {
                return fmt.Errorf("The \"size\" property cannot be changed.")
        }
diff --git a/lxd/storage_mock.go b/lxd/storage_mock.go
index eabf196..f0ab7e6 100644
--- a/lxd/storage_mock.go
+++ b/lxd/storage_mock.go
@@ -99,7 +99,7 @@ func (s *storageMock) StoragePoolVolumeUpdate(changedConfig 
[]string) error {
        return nil
 }
 
-func (s *storageMock) StoragePoolUpdate(changedConfig []string) error {
+func (s *storageMock) StoragePoolUpdate(writable *api.StoragePoolPut, 
changedConfig []string) error {
        return nil
 }
 
diff --git a/lxd/storage_pools_utils.go b/lxd/storage_pools_utils.go
index c4f1f48..940bae8 100644
--- a/lxd/storage_pools_utils.go
+++ b/lxd/storage_pools_utils.go
@@ -42,20 +42,20 @@ func storagePoolUpdate(d *Daemon, name string, newConfig 
map[string]string) erro
                return nil
        }
 
+       newWritable.Config = newConfig
+
        // Update the storage pool
        if !userOnly {
                if shared.StringInSlice("driver", changedConfig) {
                        return fmt.Errorf("The \"driver\" property of a storage 
pool cannot be changed.")
                }
 
-               err = s.StoragePoolUpdate(changedConfig)
+               err = s.StoragePoolUpdate(&newWritable, changedConfig)
                if err != nil {
                        return err
                }
        }
 
-       newWritable.Config = newConfig
-
        // Apply the new configuration
        s.SetStoragePoolWritable(&newWritable)
 
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 0573638..6b2cb6f 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -315,7 +315,7 @@ func (s *storageZfs) GetContainerPoolInfo() (int64, string) 
{
        return s.poolID, s.pool.Name
 }
 
-func (s *storageZfs) StoragePoolUpdate(changedConfig []string) error {
+func (s *storageZfs) StoragePoolUpdate(writable *api.StoragePoolPut, 
changedConfig []string) error {
        shared.LogInfof("Updating ZFS storage pool \"%s\".", s.pool.Name)
 
        if shared.StringInSlice("size", changedConfig) {

From 6d8123efd907404a0392037c367128833315050c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Tue, 28 Feb 2017 13:40:02 +0100
Subject: [PATCH 2/3] lvm: implement volume group renaming

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 lxd/storage_lvm.go     | 33 ++++++++++++++++++++++++++++++++-
 test/suites/storage.sh |  3 +++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index d8a1d5a..dc8374a 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -173,6 +173,15 @@ func storageLVMValidateThinPoolName(d *Daemon, vgName 
string, value string) erro
        return nil
 }
 
+func lvmVGRename(oldName string, newName string) error {
+       output, err := tryExec("vgrename", oldName, newName)
+       if err != nil {
+               return fmt.Errorf("Could not rename volume group from \"%s\" to 
\"%s\": %s.", oldName, newName, string(output))
+       }
+
+       return nil
+}
+
 func xfsGenerateNewUUID(lvpath string) error {
        output, err := exec.Command(
                "xfs_admin",
@@ -244,6 +253,11 @@ func (s *storageLvm) getOnDiskPoolName() string {
        return s.pool.Name
 }
 
+func (s *storageLvm) setOnDiskPoolName(newName string) {
+       s.vgName = newName
+       s.pool.Config["source"] = newName
+}
+
 func getLvmDevPath(lvmPool string, volumeType string, lvmVolume string) string 
{
        return fmt.Sprintf("/dev/%s/%s_%s", lvmPool, volumeType, lvmVolume)
 }
@@ -743,7 +757,24 @@ func (s *storageLvm) StoragePoolUpdate(writable 
*api.StoragePoolPut, changedConf
        }
 
        if shared.StringInSlice("lvm.vg_name", changedConfig) {
-               return fmt.Errorf("The \"lvm.vg_name\" property cannot be 
changed.")
+               newName := writable.Config["lvm.vg_name"]
+               // Paranoia check
+               if newName == "" {
+                       return fmt.Errorf("Could not rename volume group: No 
new name provided.")
+               }
+               writable.Config["source"] = newName
+
+               oldPoolName := s.getOnDiskPoolName()
+               err := lvmVGRename(oldPoolName, newName)
+               if err != nil {
+                       return err
+               }
+
+               // Already set the new dataset name so that any potentially
+               // following operations use the correct on-disk name of the
+               // volume group.
+               s.setOnDiskPoolName(newName)
+               return nil
        }
 
        shared.LogInfof("Updated LVM storage pool \"%s\".", s.pool.Name)
diff --git a/test/suites/storage.sh b/test/suites/storage.sh
index 5be6a92..f18b750 100644
--- a/test/suites/storage.sh
+++ b/test/suites/storage.sh
@@ -209,6 +209,9 @@ test_storage() {
       lxc init testimage c10pool6 -s "lxdtest-$(basename "${LXD_DIR}")-pool6"
       lxc list -c b c10pool6 | grep "lxdtest-$(basename "${LXD_DIR}")-pool6"
 
+      # Test if volume group renaming works by setting lvm.vg_name.
+      lxc storage set "lxdtest-$(basename "${LXD_DIR}")-pool6" lvm.vg_name 
"lxdtest-$(basename "${LXD_DIR}")-pool6-newName" 
+
       lxc launch testimage c12pool6 -s "lxdtest-$(basename "${LXD_DIR}")-pool6"
       lxc list -c b c12pool6 | grep "lxdtest-$(basename "${LXD_DIR}")-pool6"
 

From 27291ccd01aea292ab77feb01046dab3f177ff3b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Tue, 28 Feb 2017 13:40:25 +0100
Subject: [PATCH 3/3] doc: document lvm volume group renaming extension

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 doc/api-extensions.md | 3 +++
 lxd/api_1.0.go        | 1 +
 2 files changed, 4 insertions(+)

diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index dbf18c6..175b98d 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -211,3 +211,6 @@ Implements the X-LXD-write header which can be one of 
"overwrite" or "append".
 
 ## network\_dhcp\_expiry
 Introduces "ipv4.dhcp.expiry" and "ipv6.dhcp.expiry" allowing to set the DHCP 
lease expiry time.
+
+## storage\_lvm\_vg\_rename
+Introduces the ability to rename a volume group by setting 
"storage.lvm.vg_name".
diff --git a/lxd/api_1.0.go b/lxd/api_1.0.go
index 2c4cab9..27ba1a9 100644
--- a/lxd/api_1.0.go
+++ b/lxd/api_1.0.go
@@ -93,6 +93,7 @@ func api10Get(d *Daemon, r *http.Request) Response {
                        "file_delete",
                        "file_append",
                        "network_dhcp_expiry",
+                       "storage_lvm_vg_rename",
                },
                APIStatus:  "stable",
                APIVersion: version.APIVersion,
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to