The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/1567
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 5b0f6b7628af7e29f2d758595d1532552f9adcd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Thu, 4 Feb 2016 12:23:01 +0100 Subject: [PATCH 1/3] init: Improve detection of available backends MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1565 Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxd/main.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lxd/main.go b/lxd/main.go index 8b47714..4558aa8 100644 --- a/lxd/main.go +++ b/lxd/main.go @@ -510,6 +510,15 @@ func setupLXD() error { var networkPort int // Port var trustPassword string // Trust password + backendsAvailable := []string{"dir"} + backendsSupported := []string{"dir", "zfs"} + + // Detect zfs + out, err := exec.LookPath("zfs") + if err == nil && len(out) != 0 { + backendsAvailable = append(backendsAvailable, "zfs") + } + reader := bufio.NewReader(os.Stdin) askBool := func(question string) bool { @@ -613,6 +622,14 @@ func setupLXD() error { if *argAuto { // Do a bunch of sanity checks + if !shared.StringInSlice(*argStorageBackend, backendsSupported) { + return fmt.Errorf("The requested backend '%s' isn't supported by lxd init.", *argStorageBackend,) + } + + if !shared.StringInSlice(*argStorageBackend, backendsAvailable) { + return fmt.Errorf("The requested backend '%s' isn't available on your system (missing tools).", *argStorageBackend,) + } + if *argStorageBackend == "dir" { if *argStorageCreateLoop != -1 || *argStorageCreateDevice != "" || *argStoragePool != "" { return fmt.Errorf("None of --storage-pool, --storage-create-device or --storage-create-pool may be used with the 'dir' backend.") @@ -655,7 +672,15 @@ func setupLXD() error { networkPort = *argNetworkPort trustPassword = *argTrustPassword } else { - storageBackend = askChoice("Name of the storage backend to use (dir or zfs): ", []string{"dir", "zfs"}) + storageBackend = askChoice("Name of the storage backend to use (dir or zfs): ", backendsSupported) + + if !shared.StringInSlice(storageBackend, backendsSupported) { + return fmt.Errorf("The requested backend '%s' isn't supported by lxd init.", storageBackend) + } + + if !shared.StringInSlice(storageBackend, backendsAvailable) { + return fmt.Errorf("The requested backend '%s' isn't available on your system (missing tools).", storageBackend) + } if storageBackend == "zfs" { if askBool("Create a new ZFS pool (yes/no)? ") { @@ -698,11 +723,6 @@ func setupLXD() error { } if storageBackend == "zfs" { - out, err := exec.LookPath("zfs") - if err != nil || len(out) == 0 { - return fmt.Errorf("The 'zfs' tool isn't available") - } - if storageMode == "loop" { storageDevice = shared.VarPath("zfs.img") f, err := os.Create(storageDevice) From 382bc88584de2eae4c1a8927d92facc0f4915460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Thu, 4 Feb 2016 12:23:37 +0100 Subject: [PATCH 2/3] init: Use zpool create -f to work on unformatted disks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1566 Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxd/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxd/main.go b/lxd/main.go index 4558aa8..e888010 100644 --- a/lxd/main.go +++ b/lxd/main.go @@ -745,7 +745,7 @@ func setupLXD() error { output, err := exec.Command( "zpool", "create", storagePool, storageDevice, - "-m", "none").CombinedOutput() + "-f", "-m", "none").CombinedOutput() if err != nil { return fmt.Errorf("Failed to create the ZFS pool: %s", output) } From 1df773b9a1ad41c74ad5e3d6db65bba76d325f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Thu, 4 Feb 2016 12:25:21 +0100 Subject: [PATCH 3/3] init: Attempt to modprobe the zfs module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1564 Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxd/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lxd/main.go b/lxd/main.go index e888010..808c0d8 100644 --- a/lxd/main.go +++ b/lxd/main.go @@ -723,6 +723,8 @@ func setupLXD() error { } if storageBackend == "zfs" { + _, _ = exec.Command("modprobe", "zfs").CombinedOutput() + if storageMode == "loop" { storageDevice = shared.VarPath("zfs.img") f, err := os.Create(storageDevice)
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel