[lxc-devel] [lxd/master] lxd/storage: Only use raw images

monstermunchkin on Github lxc-bot at linuxcontainers.org
Wed Nov 13 16:02:13 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 355 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191113/012b5112/attachment.bin>
-------------- next part --------------
From a1dd99065ba27aa0aa098b1cbf5a402220948768 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 13 Nov 2019 13:04:49 +0100
Subject: [PATCH] lxd/storage: Only use raw images

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/storage/drivers/driver_dir.go |  4 ++--
 lxd/storage/utils.go              | 12 ++----------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/lxd/storage/drivers/driver_dir.go b/lxd/storage/drivers/driver_dir.go
index a2c2d3d335..e0b06388e6 100644
--- a/lxd/storage/drivers/driver_dir.go
+++ b/lxd/storage/drivers/driver_dir.go
@@ -169,7 +169,7 @@ func (d *dir) HasVolume(volType VolumeType, volName string) bool {
 
 // GetVolumeDiskPath returns the location and file format of a disk volume.
 func (d *dir) GetVolumeDiskPath(volType VolumeType, volName string) (string, string, error) {
-	return filepath.Join(GetVolumeMountPath(d.name, volType, volName), "root.img"), "qcow2", nil
+	return filepath.Join(GetVolumeMountPath(d.name, volType, volName), "root.img"), "raw", nil
 }
 
 // CreateVolume creates an empty volume and can optionally fill it by executing the supplied
@@ -258,7 +258,7 @@ func (d *dir) CreateVolume(vol Volume, filler func(mountPath, rootBlockPath stri
 			// If rootBlockPath doesn't exist, then there has been no filler function
 			// supplied to create it from another source. So instead create an empty
 			// volume (use for PXE booting a VM).
-			_, err = shared.RunCommand("qemu-img", "create", "-f", "qcow2", rootBlockPath, fmt.Sprintf("%d", blockSizeBytes))
+			_, err = shared.RunCommand("qemu-img", "create", "-f", "raw", rootBlockPath, fmt.Sprintf("%d", blockSizeBytes))
 			if err != nil {
 				return fmt.Errorf("Failed creating disk image %s as size %s: %v", rootBlockPath, blockSize, err)
 			}
diff --git a/lxd/storage/utils.go b/lxd/storage/utils.go
index f301a96a08..25e8e273fd 100644
--- a/lxd/storage/utils.go
+++ b/lxd/storage/utils.go
@@ -742,16 +742,8 @@ func ImageUnpack(imageFile, destPath, destBlockFile string, blockBackend, runnin
 			return err
 		}
 
-		// If dest block file doesn't exist, then the expectation is that we will just copy
-		// the qcow2 image to the specified location unmodified.
-		if os.IsNotExist(err) {
-			_, err = shared.RunCommand("cp", imageRootfsFile, destBlockFile)
-			if err != nil {
-				return fmt.Errorf("Failed copying image to %s: %v", destBlockFile, err)
-			}
-		} else if !fileInfo.IsDir() {
-			// If the dest block file exists and not a directory, then convert the
-			// qcow2 format to a raw block device.
+		if os.IsNotExist(err) || !fileInfo.IsDir() {
+			// Convert the qcow2 format to a raw block device.
 			_, err = shared.RunCommand("qemu-img", "convert", "-O", "raw", imageRootfsFile, destBlockFile)
 			if err != nil {
 				return fmt.Errorf("Failed converting image to raw at %s: %v", destBlockFile, err)


More information about the lxc-devel mailing list