[lxc-devel] [lxd/master] lxd/init: Detect LVM thin provisioning tools

stgraber on Github lxc-bot at linuxcontainers.org
Thu Jul 6 21:19:28 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170706/b849f07c/attachment.bin>
-------------- next part --------------
From 219050766c5d6f98cb865916a18b945fcf6a74ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 6 Jul 2017 17:17:41 -0400
Subject: [PATCH] lxd/init: Detect LVM thin provisioning tools
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3497

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/main_init.go | 43 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/lxd/main_init.go b/lxd/main_init.go
index 89b2d6bbb..bac6eb4b1 100644
--- a/lxd/main_init.go
+++ b/lxd/main_init.go
@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"net"
 	"os"
+	"os/exec"
 	"strconv"
 	"strings"
 	"syscall"
@@ -212,6 +213,9 @@ func (cmd *CmdInit) fillDataWithStorage(data *cmdInitData, storage *cmdInitStora
 
 	// Pool configuration
 	storagePoolConfig := map[string]string{}
+	if storage.Config != nil {
+		storagePoolConfig = storage.Config
+	}
 
 	if storage.Device != "" {
 		storagePoolConfig["source"] = storage.Device
@@ -672,7 +676,10 @@ func (cmd *CmdInit) askStorage(client lxd.ContainerServer, existingPools []strin
 	if !cmd.Context.AskBool("Do you want to configure a new storage pool (yes/no) [default=yes]? ", "yes") {
 		return nil, nil
 	}
-	storage := &cmdInitStorageParams{}
+	storage := &cmdInitStorageParams{
+		Config: map[string]string{},
+	}
+
 	defaultStorage := "dir"
 	if shared.StringInSlice("zfs", availableBackends) {
 		defaultStorage = "zfs"
@@ -725,7 +732,6 @@ func (cmd *CmdInit) askStorage(client lxd.ContainerServer, existingPools []strin
 						storage.Dataset = shared.VarPath("storage-pools", storage.Pool)
 					}
 				} else {
-
 					st := syscall.Statfs_t{}
 					err := syscall.Statfs(shared.VarPath(), &st)
 					if err != nil {
@@ -749,6 +755,28 @@ func (cmd *CmdInit) askStorage(client lxd.ContainerServer, existingPools []strin
 			question := fmt.Sprintf("Name of the existing %s pool or dataset: ", strings.ToUpper(storage.Backend))
 			storage.Dataset = cmd.Context.AskString(question, "", nil)
 		}
+
+		if storage.Backend == "lvm" {
+			_, err := exec.LookPath("thin_check")
+			if err != nil {
+				fmt.Printf(`
+The LVM thin provisioning tools couldn't be found. LVM can still be used
+without thin provisioning but this will disable over-provisioning,
+increase the space requirements and creation time of images, containers
+and snapshots.
+
+If you wish to use thin provisioning, abort now, install the tools from
+your Linux distribution and run "lxd init" again afterwards.
+
+`)
+				if !cmd.Context.AskBool("Do you want to continue without thin provisioning? (yes/no) [default=yes]: ", "yes") {
+					return nil, fmt.Errorf("The LVM thin provisioning tools couldn't be found on the system.")
+				}
+
+				storage.Config["lvm.use_thinpool"] = "false"
+			}
+		}
+
 		break
 	}
 	return storage, nil
@@ -877,11 +905,12 @@ type cmdInitData struct {
 // Parameters needed when creating a storage pool in interactive or auto
 // mode.
 type cmdInitStorageParams struct {
-	Backend  string // == supportedStoragePoolDrivers
-	LoopSize int64  // Size in GB
-	Device   string // Path
-	Pool     string // pool name
-	Dataset  string // existing ZFS pool name
+	Backend  string            // == supportedStoragePoolDrivers
+	LoopSize int64             // Size in GB
+	Device   string            // Path
+	Pool     string            // pool name
+	Dataset  string            // existing ZFS pool name
+	Config   map[string]string // Additional pool configuration
 }
 
 // Parameters needed when configuring the LXD server networking options in interactive


More information about the lxc-devel mailing list