The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6332

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
I'm creating a draft PR to let you know that I'm working on this. The **squashfs-tools-ng** has trouble compressing/decompressing tarballs created by LXD. So, I'm trying to resolve it before I can continue with this one.
From 90ddc5b036bd5ec1f0eafc8fc613a584f0ab07e0 Mon Sep 17 00:00:00 2001
From: Uzi Erdenebileg <lzijb...@gmail.com>
Date: Mon, 21 Oct 2019 04:20:26 +0000
Subject: [PATCH 1/2] lxd/cluster: Validate squashfs compression executable

Signed-off-by: Uzi Erdenebileg <lzijb...@gmail.com>
---
 lxd/cluster/config.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lxd/cluster/config.go b/lxd/cluster/config.go
index dacd9fb186..67427d5578 100644
--- a/lxd/cluster/config.go
+++ b/lxd/cluster/config.go
@@ -321,6 +321,11 @@ func validateCompression(value string) error {
                return nil
        }
 
+       // Going to look for tar2sqfs executable if ...
+       if value == "squashfs" {
+               value = "tar2sqfs"
+       }
+
        _, err := exec.LookPath(value)
        return err
 }

From 336763487001128895cec1245647eb51335d7316 Mon Sep 17 00:00:00 2001
From: Uzi Erdenebileg <lzijb...@gmail.com>
Date: Mon, 21 Oct 2019 04:30:07 +0000
Subject: [PATCH 2/2] lxd: Support squashfs compressed backup exports

Signed-off-by: Uzi Erdenebileg <lzijb...@gmail.com>
---
 lxd/backup.go | 37 +++++++++++++++++++++++--------------
 lxd/images.go | 15 +++++++++++++++
 2 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/lxd/backup.go b/lxd/backup.go
index 3be5273cd7..58d73cfc78 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -239,6 +239,7 @@ func backupCreateTarball(s *state.State, path string, b 
backup.Backup, c Instanc
        }
 
        var compress string
+       var compressedName string
 
        if b.CompressionAlgorithm() != "" {
                compress = b.CompressionAlgorithm()
@@ -256,29 +257,37 @@ func backupCreateTarball(s *state.State, path string, b 
backup.Backup, c Instanc
                }
                defer infile.Close()
 
-               compressed, err := os.Create(backupPath + ".compressed")
-               if err != nil {
-                       return err
-               }
-               compressedName := compressed.Name()
+               compressedName = backupPath + ".compressed"
 
-               defer compressed.Close()
-               defer os.Remove(compressedName)
+               if compress == "squashfs" {
+                       err = compressPath(compress, infile, compressedName)
+                       if err != nil {
+                               return err
+                       }
+               } else {
+                       compressed, err := os.Create(compressedName)
+                       if err != nil {
+                               return err
+                       }
+                       defer compressed.Close()
 
-               err = compressFile(compress, infile, compressed)
-               if err != nil {
-                       return err
-               }
+                       err = compressFile(compress, infile, compressed)
+                       if err != nil {
+                               return err
+                       }
 
-               err = os.Remove(backupPath)
-               if err != nil {
-                       return err
+                       err = os.Remove(backupPath)
+                       if err != nil {
+                               return err
+                       }
                }
 
                err = os.Rename(compressedName, backupPath)
                if err != nil {
                        return err
                }
+
+               os.Remove(compressedName)
        }
 
        // Set permissions
diff --git a/lxd/images.go b/lxd/images.go
index 67b95e67b4..118bdd5999 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -137,6 +137,21 @@ func unpackImage(imagefname string, destpath string, sType 
storageType, runningI
        return nil
 }
 
+func compressPath(compress string, infile io.Reader, fname string) error {
+       var cmdName string
+       var args []string
+
+       if compress == "squashfs" {
+               cmdName = "tar2sqfs"
+               args = []string{"--compressor", "xz", fname}
+       }
+       
+       cmd := exec.Command(cmdName, args...)
+       cmd.Stdin = infile
+
+       return cmd.Run()
+}
+
 func compressFile(compress string, infile io.Reader, outfile io.Writer) error {
        reproducible := []string{"gzip"}
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to