[lxc-devel] [lxd/master] lvm: Don't call lvextend on new LVM

stgraber on Github lxc-bot at linuxcontainers.org
Mon Jun 13 20:35:56 UTC 2016


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/20160613/36294d07/attachment.bin>
-------------- next part --------------
From 8266b3abcb11241a9cc369cf988227a2aab0016c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 13 Jun 2016 16:35:11 -0400
Subject: [PATCH] lvm: Don't call lvextend on new LVM
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_lvm.go | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index e66c189..80de0ec 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -778,12 +778,21 @@ func (s *storageLvm) ImageDelete(fingerprint string) error {
 
 func (s *storageLvm) createDefaultThinPool() (string, error) {
 	thinPoolName := daemonConfig["storage.lvm_thinpool_name"].Get()
+	isRecent, err := s.lvmVersionIsAtLeast("2.02.99")
+	if err != nil {
+		return "", fmt.Errorf("Error checking LVM version: %v", err)
+	}
+
+	size := "100%FREE"
+	if !isRecent {
+		size = "1G"
+	}
 
-	// Create a tiny 1G thinpool
+	// Create the thin pool
 	output, err := tryExec(
 		"lvcreate",
 		"--poolmetadatasize", "1G",
-		"-L", "1G",
+		"-L", size,
 		"--thinpool",
 		fmt.Sprintf("%s/%s", s.vgName, thinPoolName))
 
@@ -799,23 +808,25 @@ func (s *storageLvm) createDefaultThinPool() (string, error) {
 			"Could not create LVM thin pool named %s", thinPoolName)
 	}
 
-	// Grow it to the maximum VG size (two step process required by old LVM)
-	output, err = tryExec(
-		"lvextend",
-		"--alloc", "anywhere",
-		"-l", "100%FREE",
-		fmt.Sprintf("%s/%s", s.vgName, thinPoolName))
-
-	if err != nil {
-		s.log.Error(
-			"Could not grow thin pool",
-			log.Ctx{
-				"name":   thinPoolName,
-				"err":    err,
-				"output": string(output)})
+	if !isRecent {
+		// Grow it to the maximum VG size (two step process required by old LVM)
+		output, err = tryExec(
+			"lvextend",
+			"--alloc", "anywhere",
+			"-l", "100%FREE",
+			fmt.Sprintf("%s/%s", s.vgName, thinPoolName))
 
-		return "", fmt.Errorf(
-			"Could not grow LVM thin pool named %s", thinPoolName)
+		if err != nil {
+			s.log.Error(
+				"Could not grow thin pool",
+				log.Ctx{
+					"name":   thinPoolName,
+					"err":    err,
+					"output": string(output)})
+
+			return "", fmt.Errorf(
+				"Could not grow LVM thin pool named %s", thinPoolName)
+		}
 	}
 
 	return thinPoolName, nil


More information about the lxc-devel mailing list