[lxc-devel] [lxd/master] Properly handle RunCommand errors
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Sep 17 08:03:49 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/20190917/2c3d0a98/attachment.bin>
-------------- next part --------------
From b82739c0d0766ebd37cfeffe5ce423a498dc3e06 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Sep 2019 09:47:47 +0200
Subject: [PATCH 1/6] lxd/storage/lvm: Properly return error messages
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/storage_lvm.go | 24 +++++++--------
lxd/storage_lvm_utils.go | 66 +++++++++++++++++++---------------------
2 files changed, 44 insertions(+), 46 deletions(-)
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 14963e48c9..2ccefa5834 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -49,7 +49,7 @@ func (s *storageLvm) StorageCoreInit() error {
output, err := shared.RunCommand("lvm", "version")
if err != nil {
- return fmt.Errorf("Error getting LVM version: %v\noutput:'%s'", err, output)
+ return fmt.Errorf("Error getting LVM version: %v", err)
}
lines := strings.Split(output, "\n")
@@ -261,9 +261,9 @@ func (s *storageLvm) StoragePoolCreate() error {
logger.Errorf("No name for physical volume detected")
}
- output, err := shared.TryRunCommand("pvcreate", pvName)
+ _, err := shared.TryRunCommand("pvcreate", pvName)
if err != nil {
- return fmt.Errorf("Failed to create the physical volume for the lvm storage pool: %s", output)
+ return fmt.Errorf("Failed to create the physical volume for the lvm storage pool: %v", err)
}
defer func() {
if tryUndo {
@@ -313,9 +313,9 @@ func (s *storageLvm) StoragePoolCreate() error {
return fmt.Errorf(msg)
}
} else {
- output, err := shared.TryRunCommand("vgcreate", poolName, pvName)
+ _, err := shared.TryRunCommand("vgcreate", poolName, pvName)
if err != nil {
- return fmt.Errorf("failed to create the volume group for the lvm storage pool: %s", output)
+ return fmt.Errorf("failed to create the volume group for the lvm storage pool: %v", err)
}
}
@@ -378,9 +378,9 @@ func (s *storageLvm) StoragePoolDelete() error {
// Remove the volume group.
if count == 0 && poolExists {
- output, err := shared.TryRunCommand("vgremove", "-f", poolName)
+ _, err := shared.TryRunCommand("vgremove", "-f", poolName)
if err != nil {
- logger.Errorf("Failed to destroy the volume group for the lvm storage pool: %s", output)
+ logger.Errorf("Failed to destroy the volume group for the lvm storage pool: %v", err)
return err
}
}
@@ -824,7 +824,7 @@ func (s *storageLvm) StoragePoolVolumeUpdate(writable *api.StorageVolumePut,
bwlimit := s.pool.Config["rsync.bwlimit"]
output, err := rsyncLocalCopy(sourceVolumeMntPoint, targetVolumeMntPoint, bwlimit, true)
if err != nil {
- return fmt.Errorf("failed to rsync container: %s: %s", string(output), err)
+ return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
}
}
@@ -1574,9 +1574,9 @@ func (s *storageLvm) ContainerSnapshotStart(container Instance) (bool, error) {
}
if !wasWritableAtCheck {
- output, err := shared.TryRunCommand("lvchange", "-prw", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointContainers, project.Prefix(container.Project(), containerLvmName)))
+ _, err := shared.TryRunCommand("lvchange", "-prw", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointContainers, project.Prefix(container.Project(), containerLvmName)))
if err != nil {
- logger.Errorf("Failed to make LVM snapshot \"%s\" read-write: %s", containerName, output)
+ logger.Errorf("Failed to make LVM snapshot \"%s\" read-write: %v", containerName, err)
return false, err
}
}
@@ -1633,9 +1633,9 @@ func (s *storageLvm) ContainerSnapshotStop(container Instance) (bool, error) {
if wasWritableAtCheck {
containerLvmName := containerNameToLVName(project.Prefix(container.Project(), containerName))
- output, err := shared.TryRunCommand("lvchange", "-pr", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointContainers, containerLvmName))
+ _, err := shared.TryRunCommand("lvchange", "-pr", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointContainers, containerLvmName))
if err != nil {
- logger.Errorf("Failed to make LVM snapshot read-only: %s", output)
+ logger.Errorf("Failed to make LVM snapshot read-only: %v", err)
return false, err
}
}
diff --git a/lxd/storage_lvm_utils.go b/lxd/storage_lvm_utils.go
index 6875df8335..65824f20d4 100644
--- a/lxd/storage_lvm_utils.go
+++ b/lxd/storage_lvm_utils.go
@@ -178,11 +178,11 @@ func (s *storageLvm) renameLVByPath(project, oldName string, newName string, vol
func removeLV(project, vgName string, volumeType string, lvName string) error {
lvmVolumePath := getLvmDevPath(project, vgName, volumeType, lvName)
- output, err := shared.TryRunCommand("lvremove", "-f", lvmVolumePath)
+ _, err := shared.TryRunCommand("lvremove", "-f", lvmVolumePath)
if err != nil {
- logger.Errorf("Could not remove LV \"%s\": %s", lvName, output)
- return fmt.Errorf("Could not remove LV named %s", lvName)
+ logger.Errorf("Could not remove LV \"%s\": %v", lvName, err)
+ return fmt.Errorf("Could not remove LV named %s: %v", lvName, err)
}
return nil
@@ -202,7 +202,6 @@ func (s *storageLvm) createSnapshotLV(project, vgName string, origLvName string,
}
lvmPoolVolumeName := getPrefixedLvName(project, volumeType, lvName)
- var output string
args := []string{"-n", lvmPoolVolumeName, "-s", sourceLvmVolumePath}
if isRecent {
args = append(args, "-kn")
@@ -236,10 +235,10 @@ func (s *storageLvm) createSnapshotLV(project, vgName string, origLvName string,
args = append(args, "-prw")
}
- output, err = shared.TryRunCommand("lvcreate", args...)
+ _, err = shared.TryRunCommand("lvcreate", args...)
if err != nil {
- logger.Errorf("Could not create LV snapshot: %s to %s: %s", origLvName, lvName, output)
- return "", fmt.Errorf("Could not create snapshot LV named %s", lvName)
+ logger.Errorf("Could not create LV snapshot: %s to %s: %v", origLvName, lvName, err)
+ return "", fmt.Errorf("Could not create snapshot LV named %s: %v", lvName, err)
}
targetLvmVolumePath := getLvmDevPath(project, vgName, volumeType, lvName)
@@ -429,15 +428,15 @@ func (s *storageLvm) copyContainerLv(target Instance, source Instance, readonly
bwlimit := s.pool.Config["rsync.bwlimit"]
output, err := rsyncLocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
if err != nil {
- return fmt.Errorf("failed to rsync container: %s: %s", string(output), err)
+ return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
}
if readonly {
targetLvmName := containerNameToLVName(targetName)
poolName := s.getOnDiskPoolName()
- output, err := shared.TryRunCommand("lvchange", "-pr", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointContainers, targetLvmName))
+ _, err := shared.TryRunCommand("lvchange", "-pr", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointContainers, targetLvmName))
if err != nil {
- logger.Errorf("Failed to make LVM snapshot \"%s\" read-write: %s", targetName, output)
+ logger.Errorf("Failed to make LVM snapshot \"%s\" read-write: %v", targetName, err)
return err
}
}
@@ -596,18 +595,18 @@ func lvmLvIsWritable(lvName string) (bool, error) {
}
func storageVGActivate(lvmVolumePath string) error {
- output, err := shared.TryRunCommand("vgchange", "-ay", lvmVolumePath)
+ _, err := shared.TryRunCommand("vgchange", "-ay", lvmVolumePath)
if err != nil {
- return fmt.Errorf("could not activate volume group \"%s\": %s: %s", lvmVolumePath, output, err)
+ return fmt.Errorf("could not activate volume group \"%s\": %v", lvmVolumePath, err)
}
return nil
}
func storageLVActivate(lvmVolumePath string) error {
- output, err := shared.TryRunCommand("lvchange", "-ay", lvmVolumePath)
+ _, err := shared.TryRunCommand("lvchange", "-ay", lvmVolumePath)
if err != nil {
- return fmt.Errorf("could not activate logival volume \"%s\": %s: %s", lvmVolumePath, output, err)
+ return fmt.Errorf("could not activate logival volume \"%s\": %v", lvmVolumePath, err)
}
return nil
@@ -784,18 +783,18 @@ func storageLVMValidateThinPoolName(s *state.State, vgName string, value string)
}
func lvmVGRename(oldName string, newName string) error {
- output, err := shared.TryRunCommand("vgrename", oldName, newName)
+ _, err := shared.TryRunCommand("vgrename", oldName, newName)
if err != nil {
- return fmt.Errorf("could not rename volume group from \"%s\" to \"%s\": %s", oldName, newName, output)
+ return fmt.Errorf("could not rename volume group from \"%s\" to \"%s\": %v", oldName, newName, err)
}
return nil
}
func lvmLVRename(vgName string, oldName string, newName string) error {
- output, err := shared.TryRunCommand("lvrename", vgName, oldName, newName)
+ _, err := shared.TryRunCommand("lvrename", vgName, oldName, newName)
if err != nil {
- return fmt.Errorf("could not rename volume group from \"%s\" to \"%s\": %s", oldName, newName, output)
+ return fmt.Errorf("could not rename volume group from \"%s\" to \"%s\": %v", oldName, newName, err)
}
return nil
@@ -844,21 +843,21 @@ func lvmCreateLv(projectName, vgName string, thinPoolName string, lvName string,
lvmPoolVolumeName := getPrefixedLvName(projectName, volumeType, lvName)
if makeThinLv {
targetVg := fmt.Sprintf("%s/%s", vgName, thinPoolName)
- output, err = shared.TryRunCommand("lvcreate", "-Wy", "--yes", "--thin", "-n", lvmPoolVolumeName, "--virtualsize", lvSizeString, targetVg)
+ _, err = shared.TryRunCommand("lvcreate", "-Wy", "--yes", "--thin", "-n", lvmPoolVolumeName, "--virtualsize", lvSizeString, targetVg)
} else {
- output, err = shared.TryRunCommand("lvcreate", "-Wy", "--yes", "-n", lvmPoolVolumeName, "--size", lvSizeString, vgName)
+ _, err = shared.TryRunCommand("lvcreate", "-Wy", "--yes", "-n", lvmPoolVolumeName, "--size", lvSizeString, vgName)
}
if err != nil {
- logger.Errorf("Could not create LV \"%s\": %s", lvmPoolVolumeName, output)
- return fmt.Errorf("Could not create thin LV named %s", lvmPoolVolumeName)
+ logger.Errorf("Could not create LV \"%s\": %v", lvmPoolVolumeName, err)
+ return fmt.Errorf("Could not create thin LV named %s: %v", lvmPoolVolumeName, err)
}
fsPath := getLvmDevPath(projectName, vgName, volumeType, lvName)
output, err = driver.MakeFSType(fsPath, lvFsType, nil)
if err != nil {
- logger.Errorf("Filesystem creation failed: %s", output)
- return fmt.Errorf("Error making filesystem on image LV: %v", err)
+ logger.Errorf("Filesystem creation failed: %s: %v", output, err)
+ return fmt.Errorf("Error making filesystem on image LV: %s: %v", output, err)
}
return nil
@@ -896,16 +895,15 @@ func createDefaultThinPool(sTypeVersion string, vgName string, thinPoolName stri
// Create the thin pool
lvmThinPool := fmt.Sprintf("%s/%s", vgName, thinPoolName)
- var output string
if isRecent {
- output, err = shared.TryRunCommand(
+ _, err = shared.TryRunCommand(
"lvcreate",
"-Wy", "--yes",
"--poolmetadatasize", "1G",
"-l", "100%FREE",
"--thinpool", lvmThinPool)
} else {
- output, err = shared.TryRunCommand(
+ _, err = shared.TryRunCommand(
"lvcreate",
"-Wy", "--yes",
"--poolmetadatasize", "1G",
@@ -914,17 +912,17 @@ func createDefaultThinPool(sTypeVersion string, vgName string, thinPoolName stri
}
if err != nil {
- logger.Errorf("Could not create thin pool \"%s\": %s", thinPoolName, string(output))
- return fmt.Errorf("Could not create LVM thin pool named %s", thinPoolName)
+ logger.Errorf("Could not create thin pool \"%s\": %v", thinPoolName, err)
+ return fmt.Errorf("Could not create LVM thin pool named %s: %v", thinPoolName, err)
}
if !isRecent {
// Grow it to the maximum VG size (two step process required by old LVM)
- output, err = shared.TryRunCommand("lvextend", "--alloc", "anywhere", "-l", "100%FREE", lvmThinPool)
+ _, err = shared.TryRunCommand("lvextend", "--alloc", "anywhere", "-l", "100%FREE", lvmThinPool)
if err != nil {
- logger.Errorf("Could not grow thin pool: \"%s\": %s", thinPoolName, string(output))
- return fmt.Errorf("Could not grow LVM thin pool named %s", thinPoolName)
+ logger.Errorf("Could not grow thin pool: \"%s\": %v", thinPoolName, err)
+ return fmt.Errorf("Could not grow LVM thin pool named %s: %v", thinPoolName, err)
}
}
@@ -1049,9 +1047,9 @@ func (s *storageLvm) copyVolumeLv(sourcePool string, source string, target strin
targetLvmName := containerNameToLVName(target)
poolName := s.getOnDiskPoolName()
- output, err := shared.TryRunCommand("lvchange", "-pr", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointCustom, targetLvmName))
+ _, err := shared.TryRunCommand("lvchange", "-pr", fmt.Sprintf("%s/%s_%s", poolName, storagePoolVolumeAPIEndpointCustom, targetLvmName))
if err != nil {
- logger.Errorf("Failed to make LVM snapshot \"%s\" read-only: %s", s.volume.Name, output)
+ logger.Errorf("Failed to make LVM snapshot \"%s\" read-only: %v", s.volume.Name, err)
return err
}
}
From 65c1a89c3f7ebe96a3519ed4016ddca5583f8f3c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Sep 2019 09:48:32 +0200
Subject: [PATCH 2/6] lxd/networks: Properly return error messages
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/networks.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lxd/networks.go b/lxd/networks.go
index 1e7607231d..04d5414ab3 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -1896,9 +1896,9 @@ func (n *network) Start() error {
}
// Start dnsmasq (occasionally races, try a few times)
- output, err := shared.TryRunCommand(dnsmasqCmd[0], dnsmasqCmd[1:]...)
+ _, err = shared.TryRunCommand(dnsmasqCmd[0], dnsmasqCmd[1:]...)
if err != nil {
- return fmt.Errorf("Failed to run: %s: %s", strings.Join(dnsmasqCmd, " "), strings.TrimSpace(output))
+ return fmt.Errorf("Failed to run: %s: %v", strings.Join(dnsmasqCmd, " "), err)
}
// Update the static leases
From b110447b28d7a03061c9cfeb585a523ca87d6669 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Sep 2019 09:53:34 +0200
Subject: [PATCH 3/6] lxd/storage/btrfs: Properly return error messages
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/storage_btrfs.go | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index a47205b80a..32f6ed28d0 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -2117,13 +2117,13 @@ func btrfsSubVolumeCreate(subvol string) error {
}
}
- output, err := shared.RunCommand(
+ _, err := shared.RunCommand(
"btrfs",
"subvolume",
"create",
subvol)
if err != nil {
- logger.Errorf("Failed to create BTRFS subvolume \"%s\": %s", subvol, output)
+ logger.Errorf("Failed to create BTRFS subvolume \"%s\": %v", subvol, err)
return err
}
@@ -2710,9 +2710,9 @@ func (s *storageBtrfs) StorageEntitySetQuota(volumeType int, size int64, data in
// Enable quotas
poolMntPoint := driver.GetStoragePoolMountPoint(s.pool.Name)
- output, err = shared.RunCommand("btrfs", "quota", "enable", poolMntPoint)
+ _, err = shared.RunCommand("btrfs", "quota", "enable", poolMntPoint)
if err != nil {
- return fmt.Errorf("Failed to enable quotas on BTRFS pool: %s", output)
+ return fmt.Errorf("Failed to enable quotas on BTRFS pool: %v", err)
}
// Retry
@@ -2721,9 +2721,9 @@ func (s *storageBtrfs) StorageEntitySetQuota(volumeType int, size int64, data in
if err == btrfsErrNoQGroup {
// Find the volume ID
- output, err = shared.RunCommand("btrfs", "subvolume", "show", subvol)
+ _, err = shared.RunCommand("btrfs", "subvolume", "show", subvol)
if err != nil {
- return fmt.Errorf("Failed to get subvol information: %s", output)
+ return fmt.Errorf("Failed to get subvol information: %v", err)
}
id := ""
@@ -2740,9 +2740,9 @@ func (s *storageBtrfs) StorageEntitySetQuota(volumeType int, size int64, data in
}
// Create qgroup
- output, err = shared.RunCommand("btrfs", "qgroup", "create", fmt.Sprintf("0/%s", id), subvol)
+ _, err = shared.RunCommand("btrfs", "qgroup", "create", fmt.Sprintf("0/%s", id), subvol)
if err != nil {
- return fmt.Errorf("Failed to create missing qgroup: %s", output)
+ return fmt.Errorf("Failed to create missing qgroup: %v", err)
}
// Retry
@@ -2757,7 +2757,7 @@ func (s *storageBtrfs) StorageEntitySetQuota(volumeType int, size int64, data in
// Attempt to make the subvolume writable
shared.RunCommand("btrfs", "property", "set", subvol, "ro", "false")
if size > 0 {
- output, err := shared.RunCommand(
+ _, err := shared.RunCommand(
"btrfs",
"qgroup",
"limit",
@@ -2765,10 +2765,10 @@ func (s *storageBtrfs) StorageEntitySetQuota(volumeType int, size int64, data in
subvol)
if err != nil {
- return fmt.Errorf("Failed to set btrfs quota: %s", output)
+ return fmt.Errorf("Failed to set btrfs quota: %v", err)
}
} else if qgroup != "" {
- output, err := shared.RunCommand(
+ _, err := shared.RunCommand(
"btrfs",
"qgroup",
"destroy",
@@ -2776,7 +2776,7 @@ func (s *storageBtrfs) StorageEntitySetQuota(volumeType int, size int64, data in
subvol)
if err != nil {
- return fmt.Errorf("Failed to set btrfs quota: %s", output)
+ return fmt.Errorf("Failed to set btrfs quota: %v", err)
}
}
From f50161eaf2f3c9d07cff596d7eb8fbe69c9c60af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Sep 2019 09:53:47 +0200
Subject: [PATCH 4/6] lxd/patches: Properly return error messages
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/patches.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/patches.go b/lxd/patches.go
index d4b759b2b7..e5253902b4 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -505,9 +505,9 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
return err
}
- output, err := rsyncLocalCopy(oldContainerMntPoint, newContainerMntPoint, "", true)
+ _, err = rsyncLocalCopy(oldContainerMntPoint, newContainerMntPoint, "", true)
if err != nil {
- logger.Errorf("Failed to rsync: %s: %s", output, err)
+ logger.Errorf("Failed to rsync: %v", err)
return err
}
@@ -3469,9 +3469,9 @@ func patchUpdateFromV15(tx *sql.Tx) error {
logger.Debug("About to rename cName in lv upgrade", log.Ctx{"lvLinkPath": lvLinkPath, "cName": cName, "newLVName": newLVName})
- output, err := shared.RunCommand("lvrename", vgName, cName, newLVName)
+ _, err := shared.RunCommand("lvrename", vgName, cName, newLVName)
if err != nil {
- return fmt.Errorf("Could not rename LV '%s' to '%s': %v\noutput:%s", cName, newLVName, err, output)
+ return fmt.Errorf("Could not rename LV '%s' to '%s': %v", cName, newLVName, err)
}
if err := os.Remove(lvLinkPath); err != nil {
From 2b1c1b0893eee2e21c8f129a99e3a004275f8a54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Sep 2019 09:57:50 +0200
Subject: [PATCH 5/6] lxd/device/disk: Properly return error messages
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/device/disk.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lxd/device/disk.go b/lxd/device/disk.go
index a695d0a0c4..6866f3f032 100644
--- a/lxd/device/disk.go
+++ b/lxd/device/disk.go
@@ -899,7 +899,7 @@ func (d *disk) getParentBlocks(path string) ([]string, error) {
output, err := shared.RunCommand("zpool", "status", "-P", "-L", poolName)
if err != nil {
- return nil, fmt.Errorf("Failed to query zfs filesystem information for %s: %s", dev[1], output)
+ return nil, fmt.Errorf("Failed to query zfs filesystem information for %s: %v", dev[1], err)
}
header := true
@@ -953,7 +953,7 @@ func (d *disk) getParentBlocks(path string) ([]string, error) {
// Accessible btrfs filesystems
output, err := shared.RunCommand("btrfs", "filesystem", "show", dev[1])
if err != nil {
- return nil, fmt.Errorf("Failed to query btrfs filesystem information for %s: %s", dev[1], output)
+ return nil, fmt.Errorf("Failed to query btrfs filesystem information for %s: %v", dev[1], err)
}
for _, line := range strings.Split(output, "\n") {
From 4b010313d41341ca3f1c8c6519c17de59a4d67d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 17 Sep 2019 10:01:25 +0200
Subject: [PATCH 6/6] lxd/storage: Consistent error messages
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/storage_dir.go | 10 +++++-----
lxd/storage_lvm.go | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go
index 92db99569b..ff5973a8f7 100644
--- a/lxd/storage_dir.go
+++ b/lxd/storage_dir.go
@@ -414,7 +414,7 @@ func (s *storageDir) StoragePoolVolumeUpdate(writable *api.StorageVolumePut, cha
bwlimit := s.pool.Config["rsync.bwlimit"]
output, err := rsyncLocalCopy(sourcePath, targetPath, bwlimit, true)
if err != nil {
- return fmt.Errorf("failed to rsync container: %s: %s", string(output), err)
+ return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
}
logger.Infof(`Restored DIR storage volume "%s" from snapshot "%s"`,
@@ -670,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)
if err != nil {
- return fmt.Errorf("failed to rsync container: %s: %s", string(output), err)
+ return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
}
err = target.TemplateApply("copy")
@@ -699,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)
if err != nil {
- return fmt.Errorf("failed to rsync container: %s: %s", string(output), err)
+ return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
}
return nil
@@ -894,7 +894,7 @@ func (s *storageDir) ContainerRestore(container Instance, sourceContainer Instan
bwlimit := s.pool.Config["rsync.bwlimit"]
output, err := rsyncLocalCopy(sourcePath, targetPath, bwlimit, true)
if err != nil {
- return fmt.Errorf("failed to rsync container: %s: %s", string(output), err)
+ return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
}
logger.Debugf("Restored DIR storage volume for container \"%s\" from %s to %s", s.volume.Name, sourceContainer.Name(), container.Name())
@@ -938,7 +938,7 @@ func (s *storageDir) ContainerSnapshotCreate(snapshotContainer Instance, sourceC
output, err := rsyncLocalCopy(oldPath, newPath, bwlimit, true)
if err != nil {
s.ContainerDelete(snapshotContainer)
- return fmt.Errorf("failed to rsync: %s: %s", string(output), err)
+ return fmt.Errorf("Failed to rsync: %s: %s", string(output), err)
}
return nil
}
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index 2ccefa5834..b3ef0b20eb 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -1492,7 +1492,7 @@ func (s *storageLvm) ContainerRestore(target Instance, source Instance) error {
bwlimit := s.pool.Config["rsync.bwlimit"]
output, err := rsyncLocalCopy(sourceContainerMntPoint, targetContainerMntPoint, bwlimit, true)
if err != nil {
- return fmt.Errorf("failed to rsync container: %s: %s", string(output), err)
+ return fmt.Errorf("Failed to rsync container: %s: %s", string(output), err)
}
}
More information about the lxc-devel
mailing list