[lxc-devel] [lxd/master] Rsync package

tomponline on Github lxc-bot at linuxcontainers.org
Wed Oct 9 11:23:47 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/20191009/51b6c4b0/attachment-0001.bin>
-------------- next part --------------
From a9919a5edba5de5602d43f7efef7858db84d5680 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 9 Oct 2019 12:22:51 +0100
Subject: [PATCH 1/2] lxd/rsync: Moves rsync functions to own package

Updates static analysis tests.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/{ => rsync}/rsync.go       | 24 ++++++++++++------------
 test/suites/static_analysis.sh |  1 +
 2 files changed, 13 insertions(+), 12 deletions(-)
 rename lxd/{ => rsync}/rsync.go (86%)

diff --git a/lxd/rsync.go b/lxd/rsync/rsync.go
similarity index 86%
rename from lxd/rsync.go
rename to lxd/rsync/rsync.go
index 5bfa3c1423..4b01b1307d 100644
--- a/lxd/rsync.go
+++ b/lxd/rsync/rsync.go
@@ -1,4 +1,4 @@
-package main
+package rsync
 
 import (
 	"fmt"
@@ -17,17 +17,17 @@ import (
 	"github.com/lxc/lxd/shared/logger"
 )
 
-// rsyncCopy copies a directory using rsync (with the --devices option).
-func rsyncLocalCopy(source string, dest string, bwlimit string, xattrs bool) (string, error) {
+// LocalCopy copies a directory using rsync (with the --devices option).
+func LocalCopy(source string, dest string, bwlimit string, xattrs bool) (string, error) {
 	err := os.MkdirAll(dest, 0755)
 	if err != nil {
 		return "", err
 	}
 
 	rsyncVerbosity := "-q"
-	if debug {
+	/*if debug {
 		rsyncVerbosity = "-vi"
-	}
+	}*/
 
 	if bwlimit == "" {
 		bwlimit = "0"
@@ -73,7 +73,7 @@ func rsyncLocalCopy(source string, dest string, bwlimit string, xattrs bool) (st
 	return msg, nil
 }
 
-func rsyncSendSetup(name string, path string, bwlimit string, execPath string, features []string) (*exec.Cmd, net.Conn, io.ReadCloser, error) {
+func sendSetup(name string, path string, bwlimit string, execPath string, features []string) (*exec.Cmd, net.Conn, io.ReadCloser, error) {
 	/*
 	 * The way rsync works, it invokes a subprocess that does the actual
 	 * talking (given to it by a -E argument). Since there isn't an easy
@@ -177,10 +177,10 @@ func rsyncSendSetup(name string, path string, bwlimit string, execPath string, f
 	return cmd, *conn, stderr, nil
 }
 
-// RsyncSend sets up the sending half of an rsync, to recursively send the
+// Send sets up the sending half of an rsync, to recursively send the
 // directory pointed to by path over the websocket.
-func RsyncSend(name string, path string, conn *websocket.Conn, readWrapper func(io.ReadCloser) io.ReadCloser, features []string, bwlimit string, execPath string) error {
-	cmd, dataSocket, stderr, err := rsyncSendSetup(name, path, bwlimit, execPath, features)
+func Send(name string, path string, conn *websocket.Conn, readWrapper func(io.ReadCloser) io.ReadCloser, features []string, bwlimit string, execPath string) error {
+	cmd, dataSocket, stderr, err := sendSetup(name, path, bwlimit, execPath, features)
 	if err != nil {
 		return err
 	}
@@ -222,10 +222,10 @@ func RsyncSend(name string, path string, conn *websocket.Conn, readWrapper func(
 	return err
 }
 
-// RsyncRecv sets up the receiving half of the websocket to rsync (the other
-// half set up by RsyncSend), putting the contents in the directory specified
+// Recv sets up the receiving half of the websocket to rsync (the other
+// half set up by rsync.Send), putting the contents in the directory specified
 // by path.
-func RsyncRecv(path string, conn *websocket.Conn, writeWrapper func(io.WriteCloser) io.WriteCloser, features []string) error {
+func Recv(path string, conn *websocket.Conn, writeWrapper func(io.WriteCloser) io.WriteCloser, features []string) error {
 	args := []string{
 		"--server",
 		"-vlogDtpre.iLsfx",
diff --git a/test/suites/static_analysis.sh b/test/suites/static_analysis.sh
index 44786668d3..102c22e47b 100644
--- a/test/suites/static_analysis.sh
+++ b/test/suites/static_analysis.sh
@@ -97,6 +97,7 @@ test_static_analysis() {
       golint -set_exit_status lxd/ucred/...
       golint -set_exit_status lxd/seccomp/...
       golint -set_exit_status lxd/apparmor/...
+      golint -set_exit_status lxd/rsync/...
 
       golint -set_exit_status shared/api/
       golint -set_exit_status shared/cancel/

From a9fd094aec1c24a641533eca40f649e25141c84d Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 9 Oct 2019 12:23:15 +0100
Subject: [PATCH 2/2] lxd: Updates usage of moved rsync functions

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/daemon_storage.go     |  3 ++-
 lxd/migrate_container.go  |  9 +++++----
 lxd/patches.go            | 15 ++++++++-------
 lxd/storage_btrfs.go      | 13 +++++++------
 lxd/storage_ceph.go       |  5 +++--
 lxd/storage_ceph_utils.go |  7 ++++---
 lxd/storage_cephfs.go     |  5 +++--
 lxd/storage_dir.go        | 19 ++++++++++---------
 lxd/storage_lvm.go        |  7 ++++---
 lxd/storage_lvm_utils.go  |  5 +++--
 lxd/storage_migration.go  | 25 +++++++++++++------------
 lxd/storage_zfs.go        | 15 ++++++++-------
 12 files changed, 70 insertions(+), 58 deletions(-)

diff --git a/lxd/daemon_storage.go b/lxd/daemon_storage.go
index fc88e3b196..f5efe4bf7d 100644
--- a/lxd/daemon_storage.go
+++ b/lxd/daemon_storage.go
@@ -11,6 +11,7 @@ import (
 
 	"github.com/lxc/lxd/lxd/db"
 	"github.com/lxc/lxd/lxd/node"
+	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/lxd/state"
 	"github.com/lxc/lxd/shared"
 )
@@ -188,7 +189,7 @@ func daemonStorageMove(s *state.State, storageType string, target string) error
 
 	moveContent := func(source string, target string) error {
 		// Copy the content
-		_, err := rsyncLocalCopy(source, target, "", false)
+		_, err := rsync.LocalCopy(source, target, "", false)
 		if err != nil {
 			return err
 		}
diff --git a/lxd/migrate_container.go b/lxd/migrate_container.go
index 7bd62ac3a9..1a0c094556 100644
--- a/lxd/migrate_container.go
+++ b/lxd/migrate_container.go
@@ -19,6 +19,7 @@ import (
 	"github.com/lxc/lxd/lxd/instance/instancetype"
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
+	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/lxd/util"
 	"github.com/lxc/lxd/shared"
 	"github.com/lxc/lxd/shared/api"
@@ -266,7 +267,7 @@ func (s *migrationSourceWs) preDumpLoop(args *preDumpLoopArgs) (bool, error) {
 	// Send the pre-dump.
 	ctName, _, _ := shared.ContainerGetParentAndSnapshotName(s.instance.Name())
 	state := s.instance.DaemonState()
-	err = RsyncSend(ctName, shared.AddSlash(args.checkpointDir), s.criuConn, nil, args.rsyncFeatures, args.bwlimit, state.OS.ExecPath)
+	err = rsync.Send(ctName, shared.AddSlash(args.checkpointDir), s.criuConn, nil, args.rsyncFeatures, args.bwlimit, state.OS.ExecPath)
 	if err != nil {
 		return final, err
 	}
@@ -680,7 +681,7 @@ func (s *migrationSourceWs) Do(migrateOp *operations.Operation) error {
 		 */
 		ctName, _, _ := shared.ContainerGetParentAndSnapshotName(s.instance.Name())
 		state := s.instance.DaemonState()
-		err = RsyncSend(ctName, shared.AddSlash(checkpointDir), s.criuConn, nil, rsyncFeatures, bwlimit, state.OS.ExecPath)
+		err = rsync.Send(ctName, shared.AddSlash(checkpointDir), s.criuConn, nil, rsyncFeatures, bwlimit, state.OS.ExecPath)
 		if err != nil {
 			return abort(err)
 		}
@@ -1060,7 +1061,7 @@ func (c *migrationSink) Do(migrateOp *operations.Operation) error {
 				for !sync.GetFinalPreDump() {
 					logger.Debugf("About to receive rsync")
 					// Transfer a CRIU pre-dump
-					err = RsyncRecv(shared.AddSlash(imagesDir), criuConn, nil, rsyncFeatures)
+					err = rsync.Recv(shared.AddSlash(imagesDir), criuConn, nil, rsyncFeatures)
 					if err != nil {
 						restore <- err
 						return
@@ -1088,7 +1089,7 @@ func (c *migrationSink) Do(migrateOp *operations.Operation) error {
 			}
 
 			// Final CRIU dump
-			err = RsyncRecv(shared.AddSlash(imagesDir), criuConn, nil, rsyncFeatures)
+			err = rsync.Recv(shared.AddSlash(imagesDir), criuConn, nil, rsyncFeatures)
 			if err != nil {
 				restore <- err
 				return
diff --git a/lxd/patches.go b/lxd/patches.go
index c461998611..1193bbd927 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -17,6 +17,7 @@ import (
 	"github.com/lxc/lxd/lxd/db"
 	"github.com/lxc/lxd/lxd/db/query"
 	deviceConfig "github.com/lxc/lxd/lxd/device/config"
+	"github.com/lxc/lxd/lxd/rsync"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/shared"
 	log "github.com/lxc/lxd/shared/log15"
@@ -506,7 +507,7 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
 					return err
 				}
 
-				_, err = rsyncLocalCopy(oldContainerMntPoint, newContainerMntPoint, "", true)
+				_, err = rsync.LocalCopy(oldContainerMntPoint, newContainerMntPoint, "", true)
 				if err != nil {
 					logger.Errorf("Failed to rsync: %v", err)
 					return err
@@ -593,7 +594,7 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
 						return err
 					}
 
-					output, err := rsyncLocalCopy(oldSnapshotMntPoint, newSnapshotMntPoint, "", true)
+					output, err := rsync.LocalCopy(oldSnapshotMntPoint, newSnapshotMntPoint, "", true)
 					if err != nil {
 						logger.Errorf("Failed to rsync: %s: %s", output, err)
 						return err
@@ -797,7 +798,7 @@ func upgradeFromStorageTypeDir(name string, d *Daemon, defaultPoolName string, d
 			// First try to rename.
 			err := os.Rename(oldContainerMntPoint, newContainerMntPoint)
 			if err != nil {
-				output, err := rsyncLocalCopy(oldContainerMntPoint, newContainerMntPoint, "", true)
+				output, err := rsync.LocalCopy(oldContainerMntPoint, newContainerMntPoint, "", true)
 				if err != nil {
 					logger.Errorf("Failed to rsync: %s: %s", output, err)
 					return err
@@ -844,7 +845,7 @@ func upgradeFromStorageTypeDir(name string, d *Daemon, defaultPoolName string, d
 		if shared.PathExists(oldSnapshotMntPoint) && !shared.PathExists(newSnapshotMntPoint) {
 			err := os.Rename(oldSnapshotMntPoint, newSnapshotMntPoint)
 			if err != nil {
-				output, err := rsyncLocalCopy(oldSnapshotMntPoint, newSnapshotMntPoint, "", true)
+				output, err := rsync.LocalCopy(oldSnapshotMntPoint, newSnapshotMntPoint, "", true)
 				if err != nil {
 					logger.Errorf("Failed to rsync: %s: %s", output, err)
 					return err
@@ -1176,7 +1177,7 @@ func upgradeFromStorageTypeLvm(name string, d *Daemon, defaultPoolName string, d
 				}
 
 				// Use rsync to fill the empty volume.
-				output, err := rsyncLocalCopy(oldContainerMntPoint, newContainerMntPoint, "", true)
+				output, err := rsync.LocalCopy(oldContainerMntPoint, newContainerMntPoint, "", true)
 				if err != nil {
 					ctStorage.ContainerDelete(ctStruct)
 					return fmt.Errorf("rsync failed: %s", string(output))
@@ -1330,7 +1331,7 @@ func upgradeFromStorageTypeLvm(name string, d *Daemon, defaultPoolName string, d
 					}
 
 					// Use rsync to fill the empty volume.
-					output, err := rsyncLocalCopy(oldSnapshotMntPoint, newSnapshotMntPoint, "", true)
+					output, err := rsync.LocalCopy(oldSnapshotMntPoint, newSnapshotMntPoint, "", true)
 					if err != nil {
 						csStorage.ContainerDelete(csStruct)
 						return fmt.Errorf("rsync failed: %s", string(output))
@@ -3434,7 +3435,7 @@ func patchUpdateFromV11(_ *sql.Tx) error {
 			// containers/<container>/snapshots/<snap0>
 			// to
 			// snapshots/<container>/<snap0>
-			output, err := rsyncLocalCopy(oldPath, newPath, "", true)
+			output, err := rsync.LocalCopy(oldPath, newPath, "", true)
 			if err != nil {
 				logger.Error(
 					"Failed rsync snapshot",
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 73926948fc..cca520afb5 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -19,6 +19,7 @@ import (
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
 	"github.com/lxc/lxd/lxd/project"
+	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/lxd/state"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/lxd/util"
@@ -1098,7 +1099,7 @@ func (s *storageBtrfs) doCrossPoolContainerCopy(target Instance, source Instance
 	if !containerOnly {
 		for _, snap := range snapshots {
 			srcSnapshotMntPoint := driver.GetSnapshotMountPoint(target.Project(), sourcePool, snap.Name())
-			_, err = rsyncLocalCopy(srcSnapshotMntPoint, destContainerMntPoint, bwlimit, true)
+			_, err = rsync.LocalCopy(srcSnapshotMntPoint, destContainerMntPoint, bwlimit, true)
 			if err != nil {
 				logger.Errorf("Failed to rsync into BTRFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
 				return err
@@ -1114,7 +1115,7 @@ func (s *storageBtrfs) doCrossPoolContainerCopy(target Instance, source Instance
 	}
 
 	srcContainerMntPoint := driver.GetContainerMountPoint(source.Project(), sourcePool, source.Name())
-	_, err = rsyncLocalCopy(srcContainerMntPoint, destContainerMntPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcContainerMntPoint, destContainerMntPoint, bwlimit, true)
 	if err != nil {
 		logger.Errorf("Failed to rsync into BTRFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
 		return err
@@ -1330,7 +1331,7 @@ func (s *storageBtrfs) ContainerRestore(container Instance, sourceContainer Inst
 			// Use rsync to fill the empty volume.  Sync by using
 			// the subvolume name.
 			bwlimit := s.pool.Config["rsync.bwlimit"]
-			output, err := rsyncLocalCopy(sourceContainerSubvolumeName, targetContainerSubvolumeName, bwlimit, true)
+			output, err := rsync.LocalCopy(sourceContainerSubvolumeName, targetContainerSubvolumeName, bwlimit, true)
 			if err != nil {
 				s.ContainerDelete(container)
 				logger.Errorf("ContainerRestore: rsync failed: %s", string(output))
@@ -1692,7 +1693,7 @@ func (s *storageBtrfs) doContainerBackupCreateOptimized(tmpPath string, backup b
 func (s *storageBtrfs) doContainerBackupCreateVanilla(tmpPath string, backup backup, source Instance) error {
 	// Prepare for rsync
 	rsync := func(oldPath string, newPath string, bwlimit string) error {
-		output, err := rsyncLocalCopy(oldPath, newPath, bwlimit, true)
+		output, err := rsync.LocalCopy(oldPath, newPath, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("Failed to rsync: %s: %s", string(output), err)
 		}
@@ -2923,7 +2924,7 @@ func (s *storageBtrfs) doCrossPoolVolumeCopy(sourcePool string, sourceName strin
 		for _, snap := range snapshots {
 			srcSnapshotMntPoint := driver.GetStoragePoolVolumeSnapshotMountPoint(sourcePool, snap)
 
-			_, err = rsyncLocalCopy(srcSnapshotMntPoint, destVolumeMntPoint, bwlimit, true)
+			_, err = rsync.LocalCopy(srcSnapshotMntPoint, destVolumeMntPoint, bwlimit, true)
 			if err != nil {
 				logger.Errorf("Failed to rsync into BTRFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
 				return err
@@ -2949,7 +2950,7 @@ func (s *storageBtrfs) doCrossPoolVolumeCopy(sourcePool string, sourceName strin
 		srcVolumeMntPoint = driver.GetStoragePoolVolumeMountPoint(sourcePool, sourceName)
 	}
 
-	_, err = rsyncLocalCopy(srcVolumeMntPoint, destVolumeMntPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcVolumeMntPoint, destVolumeMntPoint, bwlimit, true)
 	if err != nil {
 		logger.Errorf("Failed to rsync into BTRFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
 		return err
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 708b73d3c6..34ca18ef9d 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -18,6 +18,7 @@ import (
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
 	"github.com/lxc/lxd/lxd/project"
+	"github.com/lxc/lxd/lxd/rsync"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/shared"
 	"github.com/lxc/lxd/shared/api"
@@ -1048,7 +1049,7 @@ func (s *storageCeph) doCrossPoolContainerCopy(target Instance, source Instance,
 	if !containerOnly {
 		for _, snap := range snapshots {
 			srcSnapshotMntPoint := driver.GetSnapshotMountPoint(snap.Project(), sourcePool, snap.Name())
-			_, err = rsyncLocalCopy(srcSnapshotMntPoint, destContainerMntPoint, bwlimit, true)
+			_, err = rsync.LocalCopy(srcSnapshotMntPoint, destContainerMntPoint, bwlimit, true)
 			if err != nil {
 				return err
 			}
@@ -1076,7 +1077,7 @@ func (s *storageCeph) doCrossPoolContainerCopy(target Instance, source Instance,
 	}
 
 	srcContainerMntPoint := driver.GetContainerMountPoint(source.Project(), sourcePool, source.Name())
-	_, err = rsyncLocalCopy(srcContainerMntPoint, destContainerMntPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcContainerMntPoint, destContainerMntPoint, bwlimit, true)
 	if err != nil {
 		if !refresh {
 			s.StoragePoolVolumeDelete()
diff --git a/lxd/storage_ceph_utils.go b/lxd/storage_ceph_utils.go
index a23ed4352a..0175357363 100644
--- a/lxd/storage_ceph_utils.go
+++ b/lxd/storage_ceph_utils.go
@@ -16,6 +16,7 @@ import (
 
 	"github.com/lxc/lxd/lxd/db"
 	"github.com/lxc/lxd/lxd/project"
+	"github.com/lxc/lxd/lxd/rsync"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/shared"
 	"github.com/lxc/lxd/shared/api"
@@ -1592,7 +1593,7 @@ func (s *storageCeph) cephRBDVolumeBackupCreate(tmpPath string, backup backup, s
 
 	// Prepare for rsync
 	rsync := func(oldPath string, newPath string, bwlimit string) error {
-		output, err := rsyncLocalCopy(oldPath, newPath, bwlimit, true)
+		output, err := rsync.LocalCopy(oldPath, newPath, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("Failed to rsync: %s: %s", string(output), err)
 		}
@@ -1934,7 +1935,7 @@ func (s *storageCeph) doCrossPoolVolumeCopy(source *api.StorageVolumeSource) err
 			_, snapOnlyName, _ := shared.ContainerGetParentAndSnapshotName(snap)
 			srcSnapshotMntPoint := driver.GetStoragePoolVolumeSnapshotMountPoint(source.Pool, snap)
 
-			_, err = rsyncLocalCopy(srcSnapshotMntPoint, dstVolumeMntPoint, bwlimit, true)
+			_, err = rsync.LocalCopy(srcSnapshotMntPoint, dstVolumeMntPoint, bwlimit, true)
 			if err != nil {
 				return err
 			}
@@ -1954,7 +1955,7 @@ func (s *storageCeph) doCrossPoolVolumeCopy(source *api.StorageVolumeSource) err
 		srcVolumeMntPoint = driver.GetStoragePoolVolumeMountPoint(source.Pool, source.Name)
 	}
 
-	_, err = rsyncLocalCopy(srcVolumeMntPoint, dstVolumeMntPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcVolumeMntPoint, dstVolumeMntPoint, bwlimit, true)
 	if err != nil {
 		os.RemoveAll(dstVolumeMntPoint)
 		logger.Errorf("Failed to rsync into RBD storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
diff --git a/lxd/storage_cephfs.go b/lxd/storage_cephfs.go
index ed3f219ece..89d0a8cc06 100644
--- a/lxd/storage_cephfs.go
+++ b/lxd/storage_cephfs.go
@@ -15,6 +15,7 @@ import (
 
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
+	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/lxd/state"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/shared"
@@ -534,7 +535,7 @@ func (s *storageCephFs) StoragePoolVolumeUpdate(writable *api.StorageVolumePut,
 
 		// Restore using rsync
 		bwlimit := s.pool.Config["rsync.bwlimit"]
-		output, err := rsyncLocalCopy(sourcePath, targetPath, bwlimit, false)
+		output, err := rsync.LocalCopy(sourcePath, targetPath, bwlimit, false)
 		if err != nil {
 			return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
 		}
@@ -984,7 +985,7 @@ func (s *storageCephFs) copyVolume(sourcePool string, source string, target stri
 
 	// Sync data on target
 	bwlimit := s.pool.Config["rsync.bwlimit"]
-	_, err := rsyncLocalCopy(srcMountPoint, dstMountPoint, bwlimit, false)
+	_, err := rsync.LocalCopy(srcMountPoint, dstMountPoint, bwlimit, false)
 	if err != nil {
 		logger.Errorf("Failed to rsync into CEPHFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
 		return err
diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go
index c24eecaae4..4bcb01f837 100644
--- a/lxd/storage_dir.go
+++ b/lxd/storage_dir.go
@@ -15,6 +15,7 @@ import (
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
 	"github.com/lxc/lxd/lxd/project"
+	"github.com/lxc/lxd/lxd/rsync"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/lxd/storage/quota"
 	"github.com/lxc/lxd/shared"
@@ -413,7 +414,7 @@ func (s *storageDir) StoragePoolVolumeUpdate(writable *api.StorageVolumePut, cha
 
 		// Restore using rsync
 		bwlimit := s.pool.Config["rsync.bwlimit"]
-		output, err := rsyncLocalCopy(sourcePath, targetPath, bwlimit, true)
+		output, err := rsync.LocalCopy(sourcePath, targetPath, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
 		}
@@ -669,7 +670,7 @@ func (s *storageDir) copyContainer(target Instance, source Instance) error {
 	}
 
 	bwlimit := s.pool.Config["rsync.bwlimit"]
-	output, err := rsyncLocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
+	output, err := rsync.LocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
 	if err != nil {
 		return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
 	}
@@ -698,7 +699,7 @@ func (s *storageDir) copySnapshot(target Instance, targetPool string, source Ins
 	}
 
 	bwlimit := s.pool.Config["rsync.bwlimit"]
-	output, err := rsyncLocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
+	output, err := rsync.LocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
 	if err != nil {
 		return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
 	}
@@ -893,7 +894,7 @@ func (s *storageDir) ContainerRestore(container Instance, sourceContainer Instan
 
 	// Restore using rsync
 	bwlimit := s.pool.Config["rsync.bwlimit"]
-	output, err := rsyncLocalCopy(sourcePath, targetPath, bwlimit, true)
+	output, err := rsync.LocalCopy(sourcePath, targetPath, bwlimit, true)
 	if err != nil {
 		return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
 	}
@@ -936,7 +937,7 @@ func (s *storageDir) ContainerSnapshotCreate(snapshotContainer Instance, sourceC
 	}
 
 	rsync := func(snapshotContainer Instance, oldPath string, newPath string, bwlimit string) error {
-		output, err := rsyncLocalCopy(oldPath, newPath, bwlimit, true)
+		output, err := rsync.LocalCopy(oldPath, newPath, bwlimit, true)
 		if err != nil {
 			s.ContainerDelete(snapshotContainer)
 			return fmt.Errorf("Failed to rsync: %s: %s", string(output), err)
@@ -1141,7 +1142,7 @@ func (s *storageDir) ContainerBackupCreate(backup backup, source Instance) error
 
 	// Prepare for rsync
 	rsync := func(oldPath string, newPath string, bwlimit string) error {
-		output, err := rsyncLocalCopy(oldPath, newPath, bwlimit, true)
+		output, err := rsync.LocalCopy(oldPath, newPath, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("Failed to rsync: %s: %s", string(output), err)
 		}
@@ -1473,7 +1474,7 @@ func (s *storageDir) StoragePoolVolumeSnapshotCreate(target *api.StorageVolumeSn
 
 	sourcePath := driver.GetStoragePoolVolumeMountPoint(s.pool.Name, sourceName)
 	bwlimit := s.pool.Config["rsync.bwlimit"]
-	msg, err := rsyncLocalCopy(sourcePath, targetPath, bwlimit, true)
+	msg, err := rsync.LocalCopy(sourcePath, targetPath, bwlimit, true)
 	if err != nil {
 		return fmt.Errorf("Failed to rsync: %s: %s", string(msg), err)
 	}
@@ -1563,7 +1564,7 @@ func (s *storageDir) copyVolume(sourcePool string, source string, target string)
 
 	bwlimit := s.pool.Config["rsync.bwlimit"]
 
-	_, err = rsyncLocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
 	if err != nil {
 		os.RemoveAll(dstMountPoint)
 		logger.Errorf("Failed to rsync into DIR storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
@@ -1584,7 +1585,7 @@ func (s *storageDir) copyVolumeSnapshot(sourcePool string, source string, target
 
 	bwlimit := s.pool.Config["rsync.bwlimit"]
 
-	_, err = rsyncLocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
 	if err != nil {
 		os.RemoveAll(dstMountPoint)
 		logger.Errorf("Failed to rsync into DIR storage volume \"%s\" on storage pool \"%s\": %s", target, s.pool.Name, err)
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index d41704a8bf..8c9162735e 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -16,6 +16,7 @@ import (
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
 	"github.com/lxc/lxd/lxd/project"
+	"github.com/lxc/lxd/lxd/rsync"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/shared"
 	"github.com/lxc/lxd/shared/api"
@@ -823,7 +824,7 @@ func (s *storageLvm) StoragePoolVolumeUpdate(writable *api.StorageVolumePut,
 			targetVolumeMntPoint := driver.GetStoragePoolVolumeMountPoint(poolName, s.volume.Name)
 
 			bwlimit := s.pool.Config["rsync.bwlimit"]
-			output, err := rsyncLocalCopy(sourceVolumeMntPoint, targetVolumeMntPoint, bwlimit, true)
+			output, err := rsync.LocalCopy(sourceVolumeMntPoint, targetVolumeMntPoint, bwlimit, true)
 			if err != nil {
 				return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
 			}
@@ -1491,7 +1492,7 @@ func (s *storageLvm) ContainerRestore(target Instance, source Instance) error {
 		defer target.Unfreeze()
 
 		bwlimit := s.pool.Config["rsync.bwlimit"]
-		output, err := rsyncLocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
+		output, err := rsync.LocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
 		}
@@ -1683,7 +1684,7 @@ func (s *storageLvm) ContainerBackupCreate(backup backup, source Instance) error
 
 	// Prepare for rsync
 	rsync := func(oldPath string, newPath string, bwlimit string) error {
-		output, err := rsyncLocalCopy(oldPath, newPath, bwlimit, true)
+		output, err := rsync.LocalCopy(oldPath, newPath, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("Failed to rsync: %s: %s", string(output), err)
 		}
diff --git a/lxd/storage_lvm_utils.go b/lxd/storage_lvm_utils.go
index a504886614..f782366ad2 100644
--- a/lxd/storage_lvm_utils.go
+++ b/lxd/storage_lvm_utils.go
@@ -13,6 +13,7 @@ import (
 	"github.com/lxc/lxd/lxd/db"
 	"github.com/lxc/lxd/lxd/instance/instancetype"
 	"github.com/lxc/lxd/lxd/project"
+	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/lxd/state"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/shared"
@@ -426,7 +427,7 @@ func (s *storageLvm) copyContainerLv(target Instance, source Instance, readonly
 	}
 
 	bwlimit := s.pool.Config["rsync.bwlimit"]
-	output, err := rsyncLocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
+	output, err := rsync.LocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
 	if err != nil {
 		return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
 	}
@@ -1034,7 +1035,7 @@ func (s *storageLvm) copyVolumeLv(sourcePool string, source string, target strin
 	}
 
 	bwlimit := s.pool.Config["rsync.bwlimit"]
-	_, err = rsyncLocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
 	if err != nil {
 		os.RemoveAll(dstMountPoint)
 		logger.Errorf("Failed to rsync into LVM storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
diff --git a/lxd/storage_migration.go b/lxd/storage_migration.go
index 6025602700..7bb005266d 100644
--- a/lxd/storage_migration.go
+++ b/lxd/storage_migration.go
@@ -12,6 +12,7 @@ import (
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
 	"github.com/lxc/lxd/lxd/project"
+	"github.com/lxc/lxd/lxd/rsync"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/shared"
 	"github.com/lxc/lxd/shared/api"
@@ -72,7 +73,7 @@ func (s rsyncStorageSourceDriver) SendStorageVolume(conn *websocket.Conn, op *op
 			path = shared.AddSlash(path)
 			logger.Debugf("Starting to send storage volume snapshot %s on storage pool %s from %s", snap, pool.Name, path)
 
-			err = RsyncSend(volume.Name, path, conn, wrapper, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
+			err = rsync.Send(volume.Name, path, conn, wrapper, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
 			if err != nil {
 				return err
 			}
@@ -83,7 +84,7 @@ func (s rsyncStorageSourceDriver) SendStorageVolume(conn *websocket.Conn, op *op
 	path := driver.GetStoragePoolVolumeMountPoint(pool.Name, volume.Name)
 	path = shared.AddSlash(path)
 	logger.Debugf("Starting to send storage volume %s on storage pool %s from %s", volume.Name, pool.Name, path)
-	err = RsyncSend(volume.Name, path, conn, wrapper, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
+	err = rsync.Send(volume.Name, path, conn, wrapper, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
 	if err != nil {
 		return err
 	}
@@ -107,7 +108,7 @@ func (s rsyncStorageSourceDriver) SendWhileRunning(conn *websocket.Conn, op *ope
 			path := send.Path()
 			wrapper := StorageProgressReader(op, "fs_progress", send.Name())
 			state := s.container.DaemonState()
-			err = RsyncSend(project.Prefix(s.container.Project(), ctName), shared.AddSlash(path), conn, wrapper, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
+			err = rsync.Send(project.Prefix(s.container.Project(), ctName), shared.AddSlash(path), conn, wrapper, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
 			if err != nil {
 				return err
 			}
@@ -127,14 +128,14 @@ func (s rsyncStorageSourceDriver) SendWhileRunning(conn *websocket.Conn, op *ope
 		}
 	}
 
-	return RsyncSend(project.Prefix(s.container.Project(), ctName), shared.AddSlash(s.container.Path()), conn, wrapper, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
+	return rsync.Send(project.Prefix(s.container.Project(), ctName), shared.AddSlash(s.container.Path()), conn, wrapper, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
 }
 
 func (s rsyncStorageSourceDriver) SendAfterCheckpoint(conn *websocket.Conn, bwlimit string) error {
 	ctName, _, _ := shared.ContainerGetParentAndSnapshotName(s.container.Name())
 	// resync anything that changed between our first send and the checkpoint
 	state := s.container.DaemonState()
-	return RsyncSend(project.Prefix(s.container.Project(), ctName), shared.AddSlash(s.container.Path()), conn, nil, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
+	return rsync.Send(project.Prefix(s.container.Project(), ctName), shared.AddSlash(s.container.Path()), conn, nil, s.rsyncFeatures, bwlimit, state.OS.ExecPath)
 }
 
 func (s rsyncStorageSourceDriver) Cleanup() {
@@ -263,7 +264,7 @@ func rsyncStorageMigrationSink(conn *websocket.Conn, op *operations.Operation, a
 			path = shared.AddSlash(path)
 			logger.Debugf("Starting to receive storage volume snapshot %s on storage pool %s into %s", target.Name, pool.Name, path)
 
-			err = RsyncRecv(path, conn, wrapper, args.RsyncFeatures)
+			err = rsync.Recv(path, conn, wrapper, args.RsyncFeatures)
 			if err != nil {
 				return err
 			}
@@ -279,7 +280,7 @@ func rsyncStorageMigrationSink(conn *websocket.Conn, op *operations.Operation, a
 	path := driver.GetStoragePoolVolumeMountPoint(pool.Name, volume.Name)
 	path = shared.AddSlash(path)
 	logger.Debugf("Starting to receive storage volume %s on storage pool %s into %s", volume.Name, pool.Name, path)
-	return RsyncRecv(path, conn, wrapper, args.RsyncFeatures)
+	return rsync.Recv(path, conn, wrapper, args.RsyncFeatures)
 }
 
 func rsyncMigrationSink(conn *websocket.Conn, op *operations.Operation, args MigrationSinkArgs) error {
@@ -356,7 +357,7 @@ func rsyncMigrationSink(conn *websocket.Conn, op *operations.Operation, args Mig
 				}
 
 				wrapper := StorageProgressWriter(op, "fs_progress", s.Name())
-				if err := RsyncRecv(shared.AddSlash(s.Path()), conn, wrapper, args.RsyncFeatures); err != nil {
+				if err := rsync.Recv(shared.AddSlash(s.Path()), conn, wrapper, args.RsyncFeatures); err != nil {
 					return err
 				}
 
@@ -371,7 +372,7 @@ func rsyncMigrationSink(conn *websocket.Conn, op *operations.Operation, args Mig
 		}
 
 		wrapper := StorageProgressWriter(op, "fs_progress", args.Instance.Name())
-		err = RsyncRecv(shared.AddSlash(args.Instance.Path()), conn, wrapper, args.RsyncFeatures)
+		err = rsync.Recv(shared.AddSlash(args.Instance.Path()), conn, wrapper, args.RsyncFeatures)
 		if err != nil {
 			return err
 		}
@@ -409,7 +410,7 @@ func rsyncMigrationSink(conn *websocket.Conn, op *operations.Operation, args Mig
 				}
 
 				wrapper := StorageProgressWriter(op, "fs_progress", snap.GetName())
-				err := RsyncRecv(shared.AddSlash(args.Instance.Path()), conn, wrapper, args.RsyncFeatures)
+				err := rsync.Recv(shared.AddSlash(args.Instance.Path()), conn, wrapper, args.RsyncFeatures)
 				if err != nil {
 					return err
 				}
@@ -434,7 +435,7 @@ func rsyncMigrationSink(conn *websocket.Conn, op *operations.Operation, args Mig
 		}
 
 		wrapper := StorageProgressWriter(op, "fs_progress", args.Instance.Name())
-		err = RsyncRecv(shared.AddSlash(args.Instance.Path()), conn, wrapper, args.RsyncFeatures)
+		err = rsync.Recv(shared.AddSlash(args.Instance.Path()), conn, wrapper, args.RsyncFeatures)
 		if err != nil {
 			return err
 		}
@@ -443,7 +444,7 @@ func rsyncMigrationSink(conn *websocket.Conn, op *operations.Operation, args Mig
 	if args.Live {
 		/* now receive the final sync */
 		wrapper := StorageProgressWriter(op, "fs_progress", args.Instance.Name())
-		err := RsyncRecv(shared.AddSlash(args.Instance.Path()), conn, wrapper, args.RsyncFeatures)
+		err := rsync.Recv(shared.AddSlash(args.Instance.Path()), conn, wrapper, args.RsyncFeatures)
 		if err != nil {
 			return err
 		}
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index b0bf9c9df9..743591695a 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -17,6 +17,7 @@ import (
 	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
 	"github.com/lxc/lxd/lxd/project"
+	"github.com/lxc/lxd/lxd/rsync"
 	driver "github.com/lxc/lxd/lxd/storage"
 	"github.com/lxc/lxd/lxd/util"
 	"github.com/lxc/lxd/shared"
@@ -1012,7 +1013,7 @@ func (s *storageZfs) copyWithoutSnapshotsSparse(target Instance, source Instance
 		}()
 
 		bwlimit := s.pool.Config["rsync.bwlimit"]
-		output, err := rsyncLocalCopy(sourceContainerPath, targetContainerPath, bwlimit, true)
+		output, err := rsync.LocalCopy(sourceContainerPath, targetContainerPath, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("rsync failed: %s", string(output))
 		}
@@ -1229,7 +1230,7 @@ func (s *storageZfs) doCrossPoolContainerCopy(target Instance, source Instance,
 	if !containerOnly {
 		for _, snap := range snapshots {
 			srcSnapshotMntPoint := driver.GetSnapshotMountPoint(target.Project(), sourcePool, snap.Name())
-			_, err = rsyncLocalCopy(srcSnapshotMntPoint, destContainerMntPoint, bwlimit, true)
+			_, err = rsync.LocalCopy(srcSnapshotMntPoint, destContainerMntPoint, bwlimit, true)
 			if err != nil {
 				logger.Errorf("Failed to rsync into ZFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
 				return err
@@ -1245,7 +1246,7 @@ func (s *storageZfs) doCrossPoolContainerCopy(target Instance, source Instance,
 	}
 
 	srcContainerMntPoint := driver.GetContainerMountPoint(source.Project(), sourcePool, source.Name())
-	_, err = rsyncLocalCopy(srcContainerMntPoint, destContainerMntPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcContainerMntPoint, destContainerMntPoint, bwlimit, true)
 	if err != nil {
 		logger.Errorf("Failed to rsync into ZFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
 		return err
@@ -1991,7 +1992,7 @@ func (s *storageZfs) doContainerBackupCreateOptimized(tmpPath string, backup bac
 func (s *storageZfs) doContainerBackupCreateVanilla(tmpPath string, backup backup, source Instance) error {
 	// Prepare for rsync
 	rsync := func(oldPath string, newPath string, bwlimit string) error {
-		output, err := rsyncLocalCopy(oldPath, newPath, bwlimit, true)
+		output, err := rsync.LocalCopy(oldPath, newPath, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("Failed to rsync: %s: %s", string(output), err)
 		}
@@ -2856,7 +2857,7 @@ func (s *storageZfs) doCrossPoolStorageVolumeCopy(source *api.StorageVolumeSourc
 		for _, snap := range snapshots {
 			srcMountPoint := driver.GetStoragePoolVolumeSnapshotMountPoint(source.Pool, snap)
 
-			_, err = rsyncLocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
+			_, err = rsync.LocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
 			if err != nil {
 				logger.Errorf("Failed to rsync into ZFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
 				return err
@@ -2876,7 +2877,7 @@ func (s *storageZfs) doCrossPoolStorageVolumeCopy(source *api.StorageVolumeSourc
 		srcMountPoint = driver.GetStoragePoolVolumeMountPoint(source.Pool, source.Name)
 	}
 
-	_, err = rsyncLocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
+	_, err = rsync.LocalCopy(srcMountPoint, dstMountPoint, bwlimit, true)
 	if err != nil {
 		os.RemoveAll(dstMountPoint)
 		logger.Errorf("Failed to rsync into ZFS storage volume \"%s\" on storage pool \"%s\": %s", s.volume.Name, s.pool.Name, err)
@@ -3029,7 +3030,7 @@ func (s *storageZfs) copyVolumeWithoutSnapshotsSparse(source *api.StorageVolumeS
 	} else {
 		bwlimit := s.pool.Config["rsync.bwlimit"]
 
-		output, err := rsyncLocalCopy(sourceVolumePath, targetVolumePath, bwlimit, true)
+		output, err := rsync.LocalCopy(sourceVolumePath, targetVolumePath, bwlimit, true)
 		if err != nil {
 			return fmt.Errorf("rsync failed: %s", string(output))
 		}


More information about the lxc-devel mailing list