[lxc-devel] [lxd/master] Fix incorrect size of download images after fallback
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Nov 12 17:14:03 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191112/4db7a5de/attachment.bin>
-------------- next part --------------
From 1810dc02bf5e68e031200337132b07bd4852d048 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 12 Nov 2019 09:13:05 -0800
Subject: [PATCH 1/2] lxc/image: Truncate image files down to size
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>
---
lxc/image.go | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/lxc/image.go b/lxc/image.go
index 5f91615e69..47db1ae9ed 100644
--- a/lxc/image.go
+++ b/lxc/image.go
@@ -528,6 +528,19 @@ func (c *cmdImageExport) Run(cmd *cobra.Command, args []string) error {
return err
}
+ // Truncate down to size
+ if resp.RootfsSize > 0 {
+ err = destRootfs.Truncate(resp.RootfsSize)
+ if err != nil {
+ return err
+ }
+ }
+
+ err = dest.Truncate(resp.MetaSize)
+ if err != nil {
+ return err
+ }
+
// Cleanup
if resp.RootfsSize == 0 {
err := os.Remove(targetRootfs)
From 244c74b0f0eb6598f8b6a17cd29436a2f4d0e535 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 12 Nov 2019 09:13:17 -0800
Subject: [PATCH 2/2] lxd/images: Truncate image files down to size
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/daemon_images.go | 13 +++++++++++++
lxd/images.go | 13 +++++++++++++
2 files changed, 26 insertions(+)
diff --git a/lxd/daemon_images.go b/lxd/daemon_images.go
index 51e126d4d1..e80694f066 100644
--- a/lxd/daemon_images.go
+++ b/lxd/daemon_images.go
@@ -461,6 +461,19 @@ func (d *Daemon) ImageDownload(op *operations.Operation, server string, protocol
return nil, err
}
+ // Truncate down to size
+ if resp.RootfsSize > 0 {
+ err = destRootfs.Truncate(resp.RootfsSize)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ err = dest.Truncate(resp.MetaSize)
+ if err != nil {
+ return nil, err
+ }
+
// Deal with unified images
if resp.RootfsSize == 0 {
err := os.Remove(destName + ".rootfs")
diff --git a/lxd/images.go b/lxd/images.go
index 6600d8d623..1f66c38108 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -2027,6 +2027,19 @@ func imageImportFromNode(imagesDir string, client lxd.InstanceServer, fingerprin
metaFile.Close()
rootfsFile.Close()
+ // Truncate down to size
+ if getResp.RootfsSize > 0 {
+ err = rootfsFile.Truncate(getResp.RootfsSize)
+ if err != nil {
+ return err
+ }
+ }
+
+ err = metaFile.Truncate(getResp.MetaSize)
+ if err != nil {
+ return err
+ }
+
if getResp.RootfsSize == 0 {
// This is a unified image.
rootfsPath := filepath.Join(imagesDir, fingerprint)
More information about the lxc-devel
mailing list