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

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) ===
Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 7d6ce365f90b38507ab61f759443e6cceb459e9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Tue, 10 Dec 2019 20:50:48 -0500
Subject: [PATCH] lxd/daemon: Port daemon storage to new functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/daemon_storage.go | 153 +++++++++++++++++++++++++++++++-----------
 1 file changed, 112 insertions(+), 41 deletions(-)

diff --git a/lxd/daemon_storage.go b/lxd/daemon_storage.go
index f5efe4bf7d..29135d0e6a 100644
--- a/lxd/daemon_storage.go
+++ b/lxd/daemon_storage.go
@@ -13,6 +13,8 @@ import (
        "github.com/lxc/lxd/lxd/node"
        "github.com/lxc/lxd/lxd/rsync"
        "github.com/lxc/lxd/lxd/state"
+       storagePools "github.com/lxc/lxd/lxd/storage"
+       storageDrivers "github.com/lxc/lxd/lxd/storage/drivers"
        "github.com/lxc/lxd/shared"
 )
 
@@ -45,14 +47,26 @@ func daemonStorageMount(s *state.State) error {
                volumeName := fields[1]
 
                // Mount volume
-               volume, err := storageInit(s, "default", poolName, volumeName, 
storagePoolVolumeTypeCustom)
-               if err != nil {
-                       return errors.Wrapf(err, "Unable to load storage volume 
\"%s\"", source)
-               }
+               pool, err := storagePools.GetPoolByName(s, poolName)
+               if err != storageDrivers.ErrUnknownDriver {
+                       if err != nil {
+                               return err
+                       }
 
-               _, err = volume.StoragePoolVolumeMount()
-               if err != nil {
-                       return errors.Wrapf(err, "Failed to mount storage 
volume \"%s\"", source)
+                       _, err = pool.MountCustomVolume(volumeName, nil)
+                       if err != nil {
+                               return errors.Wrapf(err, "Failed to mount 
storage volume \"%s\"", source)
+                       }
+               } else {
+                       volume, err := storageInit(s, "default", poolName, 
volumeName, storagePoolVolumeTypeCustom)
+                       if err != nil {
+                               return errors.Wrapf(err, "Unable to load 
storage volume \"%s\"", source)
+                       }
+
+                       _, err = volume.StoragePoolVolumeMount()
+                       if err != nil {
+                               return errors.Wrapf(err, "Failed to mount 
storage volume \"%s\"", source)
+                       }
                }
 
                return nil
@@ -116,18 +130,18 @@ func daemonStorageValidate(s *state.State, target string) 
error {
        volumeName := fields[1]
 
        // Validate pool exists
-       poolID, pool, err := s.Cluster.StoragePoolGet(poolName)
+       poolID, dbPool, err := s.Cluster.StoragePoolGet(poolName)
        if err != nil {
                return errors.Wrapf(err, "Unable to load storage pool \"%s\"", 
poolName)
        }
 
        // Validate pool driver (can't be CEPH or CEPHFS)
-       if pool.Driver == "ceph" || pool.Driver == "cephfs" {
+       if dbPool.Driver == "ceph" || dbPool.Driver == "cephfs" {
                return fmt.Errorf("Server storage volumes cannot be stored on 
Ceph")
        }
 
        // Confirm volume exists
-       volume, err := storageInit(s, "default", poolName, volumeName, 
storagePoolVolumeTypeCustom)
+       _, _, err = s.Cluster.StoragePoolNodeVolumeGetType(volumeName, 
storagePoolVolumeTypeCustom, poolID)
        if err != nil {
                return errors.Wrapf(err, "Unable to load storage volume 
\"%s\"", target)
        }
@@ -141,13 +155,31 @@ func daemonStorageValidate(s *state.State, target string) 
error {
                return fmt.Errorf("Storage volumes for use by LXD itself cannot 
have snapshots")
        }
 
-       // Mount volume
-       ourMount, err := volume.StoragePoolVolumeMount()
-       if err != nil {
-               return errors.Wrapf(err, "Failed to mount storage volume 
\"%s\"", target)
-       }
-       if ourMount {
-               defer volume.StoragePoolUmount()
+       pool, err := storagePools.GetPoolByName(s, poolName)
+       if err != storageDrivers.ErrUnknownDriver {
+               if err != nil {
+                       return err
+               }
+
+               // Mount volume
+               ourMount, err := pool.MountCustomVolume(volumeName, nil)
+               if err != nil {
+                       return errors.Wrapf(err, "Failed to mount storage 
volume \"%s\"", target)
+               }
+               if ourMount {
+                       defer pool.UnmountCustomVolume(volumeName, nil)
+               }
+       } else {
+               volume, err := storageInit(s, "default", poolName, volumeName, 
storagePoolVolumeTypeCustom)
+
+               // Mount volume
+               ourMount, err := volume.StoragePoolVolumeMount()
+               if err != nil {
+                       return errors.Wrapf(err, "Failed to mount storage 
volume \"%s\"", target)
+               }
+               if ourMount {
+                       defer volume.StoragePoolUmount()
+               }
        }
 
        // Validate volume is empty (ignore lost+found)
@@ -235,15 +267,28 @@ func daemonStorageMove(s *state.State, storageType 
string, target string) error
                        return errors.Wrapf(err, "Failed to move data over to 
directory \"%s\"", destPath)
                }
 
-               // Unmount old volume
-               volume, err := storageInit(s, "default", sourcePool, 
sourceVolume, storagePoolVolumeTypeCustom)
-               if err != nil {
-                       return errors.Wrapf(err, "Unable to load storage volume 
\"%s/%s\"", sourcePool, sourceVolume)
-               }
+               pool, err := storagePools.GetPoolByName(s, sourcePool)
+               if err != storageDrivers.ErrUnknownDriver {
+                       if err != nil {
+                               return err
+                       }
 
-               _, err = volume.StoragePoolVolumeUmount()
-               if err != nil {
-                       return errors.Wrapf(err, "Failed to umount storage 
volume \"%s/%s\"", sourcePool, sourceVolume)
+                       // Unmount old volume
+                       _, err = pool.UnmountCustomVolume(sourceVolume, nil)
+                       if err != nil {
+                               return errors.Wrapf(err, "Failed to umount 
storage volume \"%s/%s\"", sourcePool, sourceVolume)
+                       }
+               } else {
+                       // Unmount old volume
+                       volume, err := storageInit(s, "default", sourcePool, 
sourceVolume, storagePoolVolumeTypeCustom)
+                       if err != nil {
+                               return errors.Wrapf(err, "Unable to load 
storage volume \"%s/%s\"", sourcePool, sourceVolume)
+                       }
+
+                       _, err = volume.StoragePoolVolumeUmount()
+                       if err != nil {
+                               return errors.Wrapf(err, "Failed to umount 
storage volume \"%s/%s\"", sourcePool, sourceVolume)
+                       }
                }
 
                return nil
@@ -258,15 +303,28 @@ func daemonStorageMove(s *state.State, storageType 
string, target string) error
        poolName := fields[0]
        volumeName := fields[1]
 
-       // Mount volume
-       volume, err := storageInit(s, "default", poolName, volumeName, 
storagePoolVolumeTypeCustom)
-       if err != nil {
-               return errors.Wrapf(err, "Unable to load storage volume 
\"%s\"", target)
-       }
+       pool, err := storagePools.GetPoolByName(s, poolName)
+       if err != storageDrivers.ErrUnknownDriver {
+               if err != nil {
+                       return err
+               }
 
-       _, err = volume.StoragePoolVolumeMount()
-       if err != nil {
-               return errors.Wrapf(err, "Failed to mount storage volume 
\"%s\"", target)
+               // Mount volume
+               _, err = pool.MountCustomVolume(volumeName, nil)
+               if err != nil {
+                       return errors.Wrapf(err, "Failed to mount storage 
volume \"%s\"", target)
+               }
+       } else {
+               // Mount volume
+               volume, err := storageInit(s, "default", poolName, volumeName, 
storagePoolVolumeTypeCustom)
+               if err != nil {
+                       return errors.Wrapf(err, "Unable to load storage volume 
\"%s\"", target)
+               }
+
+               _, err = volume.StoragePoolVolumeMount()
+               if err != nil {
+                       return errors.Wrapf(err, "Failed to mount storage 
volume \"%s\"", target)
+               }
        }
 
        // Set ownership & mode
@@ -303,15 +361,28 @@ func daemonStorageMove(s *state.State, storageType 
string, target string) error
                        return errors.Wrapf(err, "Failed to move data over to 
directory \"%s\"", destPath)
                }
 
-               // Unmount old volume
-               volume, err := storageInit(s, "default", sourcePool, 
sourceVolume, storagePoolVolumeTypeCustom)
-               if err != nil {
-                       return errors.Wrapf(err, "Unable to load storage volume 
\"%s/%s\"", sourcePool, sourceVolume)
-               }
+               pool, err := storagePools.GetPoolByName(s, sourcePool)
+               if err != storageDrivers.ErrUnknownDriver {
+                       if err != nil {
+                               return err
+                       }
 
-               _, err = volume.StoragePoolVolumeUmount()
-               if err != nil {
-                       return errors.Wrapf(err, "Failed to umount storage 
volume \"%s/%s\"", sourcePool, sourceVolume)
+                       // Unmount old volume
+                       _, err = pool.UnmountCustomVolume(sourceVolume, nil)
+                       if err != nil {
+                               return errors.Wrapf(err, "Failed to umount 
storage volume \"%s/%s\"", sourcePool, sourceVolume)
+                       }
+               } else {
+                       // Unmount old volume
+                       volume, err := storageInit(s, "default", sourcePool, 
sourceVolume, storagePoolVolumeTypeCustom)
+                       if err != nil {
+                               return errors.Wrapf(err, "Unable to load 
storage volume \"%s/%s\"", sourcePool, sourceVolume)
+                       }
+
+                       _, err = volume.StoragePoolVolumeUmount()
+                       if err != nil {
+                               return errors.Wrapf(err, "Failed to umount 
storage volume \"%s/%s\"", sourcePool, sourceVolume)
+                       }
                }
 
                return nil
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to