stgraber on Github
2018-11-29 01:30:41 UTC
From 203647a744f05e86cda8486f8bcd704db9c83795 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <***@ubuntu.com>
Date: Wed, 28 Nov 2018 20:30:10 -0500
Subject: [PATCH] lxd/storage/zfs: Detect tool version on Ubuntu
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <***@ubuntu.com>
---
lxd/storage_zfs.go | 7 +++++--
lxd/storage_zfs_utils.go | 14 +++++++++++++-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 4fe785f984..b1e587e288 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -64,9 +64,12 @@ func (s *storageZfs) StorageCoreInit() error {
return fmt.Errorf("The \"zfs\" tool is not enabled")
}
- s.sTypeVersion, err = zfsModuleVersionGet()
+ s.sTypeVersion, err = zfsToolVersionGet()
if err != nil {
- return err
+ s.sTypeVersion, err = zfsModuleVersionGet()
+ if err != nil {
+ return err
+ }
}
zfsVersion = s.sTypeVersion
diff --git a/lxd/storage_zfs_utils.go b/lxd/storage_zfs_utils.go
index ab1871772a..f6583a8b46 100644
--- a/lxd/storage_zfs_utils.go
+++ b/lxd/storage_zfs_utils.go
@@ -26,7 +26,19 @@ func zfsIsEnabled() bool {
return true
}
-// zfsModuleVersionGet returhs the ZFS module version
+// zfsToolVersionGet returns the ZFS tools version
+func zfsToolVersionGet() (string, error) {
+ // This function is only really ever relevant on Ubuntu as the only
+ // distro that ships out of sync tools and kernel modules
+ out, err := shared.RunCommand("dpkg-query", "--showformat=${Version}", "--show", "zfsutils-linux")
+ if err != nil {
+ return "", err
+ }
+
+ return strings.TrimSpace(string(out)), nil
+}
+
+// zfsModuleVersionGet returns the ZFS module version
func zfsModuleVersionGet() (string, error) {
var zfsVersion string
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <***@ubuntu.com>
Date: Wed, 28 Nov 2018 20:30:10 -0500
Subject: [PATCH] lxd/storage/zfs: Detect tool version on Ubuntu
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <***@ubuntu.com>
---
lxd/storage_zfs.go | 7 +++++--
lxd/storage_zfs_utils.go | 14 +++++++++++++-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 4fe785f984..b1e587e288 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -64,9 +64,12 @@ func (s *storageZfs) StorageCoreInit() error {
return fmt.Errorf("The \"zfs\" tool is not enabled")
}
- s.sTypeVersion, err = zfsModuleVersionGet()
+ s.sTypeVersion, err = zfsToolVersionGet()
if err != nil {
- return err
+ s.sTypeVersion, err = zfsModuleVersionGet()
+ if err != nil {
+ return err
+ }
}
zfsVersion = s.sTypeVersion
diff --git a/lxd/storage_zfs_utils.go b/lxd/storage_zfs_utils.go
index ab1871772a..f6583a8b46 100644
--- a/lxd/storage_zfs_utils.go
+++ b/lxd/storage_zfs_utils.go
@@ -26,7 +26,19 @@ func zfsIsEnabled() bool {
return true
}
-// zfsModuleVersionGet returhs the ZFS module version
+// zfsToolVersionGet returns the ZFS tools version
+func zfsToolVersionGet() (string, error) {
+ // This function is only really ever relevant on Ubuntu as the only
+ // distro that ships out of sync tools and kernel modules
+ out, err := shared.RunCommand("dpkg-query", "--showformat=${Version}", "--show", "zfsutils-linux")
+ if err != nil {
+ return "", err
+ }
+
+ return strings.TrimSpace(string(out)), nil
+}
+
+// zfsModuleVersionGet returns the ZFS module version
func zfsModuleVersionGet() (string, error) {
var zfsVersion string