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

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) ===

From 84742591f0e2e4901d3133f611f74ecf0ea5181a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Thu, 7 Nov 2019 15:58:30 -0500
Subject: [PATCH 1/4] lxd/storage/cephfs: Store version globally
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/storage/drivers/driver_cephfs.go | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lxd/storage/drivers/driver_cephfs.go 
b/lxd/storage/drivers/driver_cephfs.go
index cebc07efe9..ec6c10b029 100644
--- a/lxd/storage/drivers/driver_cephfs.go
+++ b/lxd/storage/drivers/driver_cephfs.go
@@ -19,26 +19,26 @@ import (
        "github.com/lxc/lxd/shared/units"
 )
 
+var cephfsVersion string
+
 type cephfs struct {
        common
-
-       version string
 }
 
 func (d *cephfs) Info() Info {
        // Detect and record the version.
-       if d.version == "" {
+       if cephfsVersion == "" {
                msg, err := shared.RunCommand("rbd", "--version")
                if err != nil {
-                       d.version = "unknown"
+                       cephfsVersion = "unknown"
                } else {
-                       d.version = strings.TrimSpace(msg)
+                       cephfsVersion = strings.TrimSpace(msg)
                }
        }
 
        return Info{
                Name:               "cephfs",
-               Version:            d.version,
+               Version:            cephfsVersion,
                Usable:             true,
                Remote:             true,
                OptimizedImages:    false,

From 6f21bb5c4f766d9eb059bc9fd337ae4128af8323 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Thu, 7 Nov 2019 16:22:25 -0500
Subject: [PATCH 2/4] lxd/storage/drivers: Drop Usable field
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/storage/drivers/driver_cephfs.go | 1 -
 lxd/storage/drivers/driver_dir.go    | 1 -
 lxd/storage/drivers/load.go          | 1 -
 3 files changed, 3 deletions(-)

diff --git a/lxd/storage/drivers/driver_cephfs.go 
b/lxd/storage/drivers/driver_cephfs.go
index ec6c10b029..6c2985bcba 100644
--- a/lxd/storage/drivers/driver_cephfs.go
+++ b/lxd/storage/drivers/driver_cephfs.go
@@ -39,7 +39,6 @@ func (d *cephfs) Info() Info {
        return Info{
                Name:               "cephfs",
                Version:            cephfsVersion,
-               Usable:             true,
                Remote:             true,
                OptimizedImages:    false,
                PreservesInodes:    false,
diff --git a/lxd/storage/drivers/driver_dir.go 
b/lxd/storage/drivers/driver_dir.go
index d9395933bc..beee02806a 100644
--- a/lxd/storage/drivers/driver_dir.go
+++ b/lxd/storage/drivers/driver_dir.go
@@ -32,7 +32,6 @@ func (d *dir) Info() Info {
                Version:            "1",
                OptimizedImages:    false,
                PreservesInodes:    false,
-               Usable:             true,
                Remote:             false,
                VolumeTypes:        []VolumeType{VolumeTypeCustom, 
VolumeTypeImage, VolumeTypeContainer},
                BlockBacking:       false,
diff --git a/lxd/storage/drivers/load.go b/lxd/storage/drivers/load.go
index 5d42eeb5eb..8191664658 100644
--- a/lxd/storage/drivers/load.go
+++ b/lxd/storage/drivers/load.go
@@ -28,7 +28,6 @@ func Load(state *state.State, driverName string, name string, 
config map[string]
 type Info struct {
        Name               string
        Version            string
-       Usable             bool
        Remote             bool
        OptimizedImages    bool
        PreservesInodes    bool

From de19b81a3a53379e5d2bcb4a255c1bbd2e8506cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Thu, 7 Nov 2019 16:26:16 -0500
Subject: [PATCH 3/4] lxd/storage/drivers: Implement load function
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/storage/drivers/driver_common.go | 8 +++++++-
 lxd/storage/drivers/interface.go     | 3 ++-
 lxd/storage/drivers/load.go          | 5 ++++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lxd/storage/drivers/driver_common.go 
b/lxd/storage/drivers/driver_common.go
index 6712aec86e..c83225cefb 100644
--- a/lxd/storage/drivers/driver_common.go
+++ b/lxd/storage/drivers/driver_common.go
@@ -18,13 +18,19 @@ type common struct {
        logger         logger.Logger
 }
 
-func (d *common) init(state *state.State, name string, config 
map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, 
volName string) (int64, error), commonRulesFunc func() map[string]func(string) 
error) {
+func (d *common) init(state *state.State, name string, config 
map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, 
volName string) (int64, error), commonRulesFunc func() map[string]func(string) 
error) error {
        d.name = name
        d.config = config
        d.getVolID = volIDFunc
        d.getCommonRules = commonRulesFunc
        d.state = state
        d.logger = logger
+
+       return d.load()
+}
+
+func (d *common) load() error {
+       return nil
 }
 
 // validateVolume validates a volume config against common rules and optional 
driver specific rules.
diff --git a/lxd/storage/drivers/interface.go b/lxd/storage/drivers/interface.go
index ed5a066a74..b0903f5ab5 100644
--- a/lxd/storage/drivers/interface.go
+++ b/lxd/storage/drivers/interface.go
@@ -14,7 +14,8 @@ import (
 type driver interface {
        Driver
 
-       init(state *state.State, name string, config map[string]string, logger 
logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, 
error), commonRulesFunc func() map[string]func(string) error)
+       init(state *state.State, name string, config map[string]string, logger 
logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, 
error), commonRulesFunc func() map[string]func(string) error) error
+       load() error
 }
 
 // Driver represents a low-level storage driver.
diff --git a/lxd/storage/drivers/load.go b/lxd/storage/drivers/load.go
index 8191664658..bced6925e7 100644
--- a/lxd/storage/drivers/load.go
+++ b/lxd/storage/drivers/load.go
@@ -19,7 +19,10 @@ func Load(state *state.State, driverName string, name 
string, config map[string]
        }
 
        d := driverFunc()
-       d.init(state, name, config, logger, volIDFunc, commonRulesFunc)
+       err := d.init(state, name, config, logger, volIDFunc, commonRulesFunc)
+       if err != nil {
+               return nil, err
+       }
 
        return d, nil
 }

From ba43166f03c7bcd74a5340397b88e387977b5279 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Thu, 7 Nov 2019 16:29:27 -0500
Subject: [PATCH 4/4] lxd/storage/cephfs: Implement load
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/storage/drivers/driver_cephfs.go | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/lxd/storage/drivers/driver_cephfs.go 
b/lxd/storage/drivers/driver_cephfs.go
index 6c2985bcba..dfbbf98e1c 100644
--- a/lxd/storage/drivers/driver_cephfs.go
+++ b/lxd/storage/drivers/driver_cephfs.go
@@ -6,6 +6,7 @@ import (
        "io"
        "io/ioutil"
        "os"
+       "os/exec"
        "path/filepath"
        "strconv"
        "strings"
@@ -20,22 +21,40 @@ import (
 )
 
 var cephfsVersion string
+var cephfsLoaded bool
 
 type cephfs struct {
        common
 }
 
-func (d *cephfs) Info() Info {
+func (d *cephfs) load() error {
+       if cephfsLoaded {
+               return nil
+       }
+
+       // Validate the required binaries.
+       for _, tool := range []string{"ceph", "rdb"} {
+               _, err := exec.LookPath(tool)
+               if err != nil {
+                       return fmt.Errorf("Required tool '%s' is missing", tool)
+               }
+       }
+
        // Detect and record the version.
        if cephfsVersion == "" {
-               msg, err := shared.RunCommand("rbd", "--version")
+               out, err := shared.RunCommand("rbd", "--version")
                if err != nil {
-                       cephfsVersion = "unknown"
+                       return err
                } else {
-                       cephfsVersion = strings.TrimSpace(msg)
+                       cephfsVersion = strings.TrimSpace(out)
                }
        }
 
+       cephfsLoaded = true
+       return nil
+}
+
+func (d *cephfs) Info() Info {
        return Info{
                Name:               "cephfs",
                Version:            cephfsVersion,
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to