[lxc-devel] [lxd/master] storage: generate new xfs uuid

brauner on Github lxc-bot at linuxcontainers.org
Sat Sep 2 03:58:14 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 495 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170902/700ff807/attachment.bin>
-------------- next part --------------
From 934fbdab70f42d18912d070226864f1c16f617f2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 2 Sep 2017 05:57:01 +0200
Subject: [PATCH] storage: generate new xfs uuid

Move the helper into makeFSType() itself. This way any new implementation won't
accidently forget to call it.

Closes #3752.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/storage_lvm.go       | 12 ------------
 lxd/storage_lvm_utils.go | 12 ------------
 lxd/storage_utils.go     | 12 ++++++++++++
 3 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 2b84c03a6..6da7070ec 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -891,7 +891,6 @@ func (s *storageLvm) ContainerCreateFromImage(container container, fingerprint s
 	tryUndo := true
 
 	containerName := container.Name()
-	containerLvmName := containerNameToLVName(containerName)
 
 	var err error
 	if s.useThinpool {
@@ -924,17 +923,6 @@ func (s *storageLvm) ContainerCreateFromImage(container container, fingerprint s
 		return err
 	}
 
-	poolName := s.getOnDiskPoolName()
-	containerLvDevPath := getLvmDevPath(poolName, storagePoolVolumeAPIEndpointContainers, containerLvmName)
-	// Generate a new xfs's UUID
-	lvFsType := s.getLvmFilesystem()
-	if lvFsType == "xfs" {
-		err := xfsGenerateNewUUID(containerLvDevPath)
-		if err != nil {
-			return err
-		}
-	}
-
 	ourMount, err := s.ContainerMount(container)
 	if err != nil {
 		return err
diff --git a/lxd/storage_lvm_utils.go b/lxd/storage_lvm_utils.go
index 26241f46f..cded35c24 100644
--- a/lxd/storage_lvm_utils.go
+++ b/lxd/storage_lvm_utils.go
@@ -752,18 +752,6 @@ func lvmLVRename(vgName string, oldName string, newName string) error {
 	return nil
 }
 
-func xfsGenerateNewUUID(lvpath string) error {
-	output, err := shared.RunCommand(
-		"xfs_admin",
-		"-U", "generate",
-		lvpath)
-	if err != nil {
-		return fmt.Errorf("Error generating new UUID: %v\noutput:'%s'", err, output)
-	}
-
-	return nil
-}
-
 func containerNameToLVName(containerName string) string {
 	lvName := strings.Replace(containerName, "-", "--", -1)
 	return strings.Replace(lvName, shared.SnapshotDelimiter, "-", -1)
diff --git a/lxd/storage_utils.go b/lxd/storage_utils.go
index fead8062f..a45a8f28b 100644
--- a/lxd/storage_utils.go
+++ b/lxd/storage_utils.go
@@ -181,6 +181,15 @@ func lxdUsesPool(dbObj *sql.DB, onDiskPoolName string, driver string, onDiskProp
 	return false, "", nil
 }
 
+func xfsGenerateNewUUID(path string) error {
+	_, err := shared.RunCommand("xfs_admin", "-U", "generate", path)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
 func makeFSType(path string, fsType string) (string, error) {
 	var err error
 	var msg string
@@ -188,6 +197,9 @@ func makeFSType(path string, fsType string) (string, error) {
 	switch fsType {
 	case "xfs":
 		msg, err = shared.TryRunCommand("mkfs.xfs", path)
+		if err == nil {
+			err = xfsGenerateNewUUID(path)
+		}
 	default:
 		msg, err = shared.TryRunCommand(
 			"mkfs.ext4",


More information about the lxc-devel mailing list