[lxc-devel] [lxd/master] zfs: Support querying version through modinfo

stgraber on Github lxc-bot at linuxcontainers.org
Wed Jul 25 23:30:46 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180725/1429d9ad/attachment.bin>
-------------- next part --------------
From 945e29b0a58d3933e4c42a170fe45aeb03136037 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 25 Jul 2018 19:30:18 -0400
Subject: [PATCH] zfs: Support querying version through modinfo
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage_zfs.go       |  2 +-
 lxd/storage_zfs_utils.go | 21 +++++++++++++++++----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 4434255c3..0d0edbd46 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -52,7 +52,7 @@ func (s *storageZfs) StorageCoreInit() error {
 	util.LoadModule("zfs")
 
 	if !zfsIsEnabled() {
-		return fmt.Errorf("the \"zfs\" tool is not enabled")
+		return fmt.Errorf("The \"zfs\" tool is not enabled")
 	}
 
 	s.sTypeVersion, err = zfsModuleVersionGet()
diff --git a/lxd/storage_zfs_utils.go b/lxd/storage_zfs_utils.go
index 20ee1aa00..48995cdf8 100644
--- a/lxd/storage_zfs_utils.go
+++ b/lxd/storage_zfs_utils.go
@@ -28,12 +28,25 @@ func zfsIsEnabled() bool {
 
 // zfsModuleVersionGet returhs the ZFS module version
 func zfsModuleVersionGet() (string, error) {
-	zfsVersion, err := ioutil.ReadFile("/sys/module/zfs/version")
-	if err != nil {
-		return "", fmt.Errorf("could not determine ZFS module version")
+	var zfsVersion string
+
+	if shared.PathExists("/sys/module/zfs/version") {
+		out, err := ioutil.ReadFile("/sys/module/zfs/version")
+		if err != nil {
+			return "", fmt.Errorf("Could not determine ZFS module version")
+		}
+
+		zfsVersion = string(out)
+	} else {
+		out, err := shared.RunCommand("modinfo", "-F", "version", "zfs")
+		if err != nil {
+			return "", fmt.Errorf("Could not determine ZFS module version")
+		}
+
+		zfsVersion = out
 	}
 
-	return strings.TrimSpace(string(zfsVersion)), nil
+	return strings.TrimSpace(zfsVersion), nil
 }
 
 // zfsPoolVolumeCreate creates a ZFS dataset with a set of given properties.


More information about the lxc-devel mailing list