[lxc-devel] [lxd/master] Support squashfs as compression algorithm #6273
ulziibuyan on Github
lxc-bot at linuxcontainers.org
Tue Oct 22 04:00:30 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 521 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191021/ad8ba666/attachment-0001.bin>
-------------- next part --------------
From 90ddc5b036bd5ec1f0eafc8fc613a584f0ab07e0 Mon Sep 17 00:00:00 2001
From: Uzi Erdenebileg <lzijbuan at 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 <lzijbuan at 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 <lzijbuan at 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 <lzijbuan at 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"}
More information about the lxc-devel
mailing list