[lxc-devel] [lxd/master] Storage: Fixes shrinkFileSystem to detect e2fsck filesystem modifications

tomponline on Github lxc-bot at linuxcontainers.org
Thu Aug 20 09:14:42 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 376 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200820/1e1a3bc0/attachment.bin>
-------------- next part --------------
From f25e9db704187aca1019255a74e121b21b29aa73 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 20 Aug 2020 10:13:49 +0100
Subject: [PATCH] lxd/storage/drivers/utils: Fixes shrinkFileSystem to detect
 e2fsck filesystem modifications

Fixes #7788

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/utils.go | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go
index 055fd73e2d..0408e2fc64 100644
--- a/lxd/storage/drivers/utils.go
+++ b/lxd/storage/drivers/utils.go
@@ -5,6 +5,7 @@ import (
 	"io"
 	"io/ioutil"
 	"os"
+	"os/exec"
 	"path/filepath"
 	"sort"
 	"strings"
@@ -476,8 +477,23 @@ func shrinkFileSystem(fsType string, devPath string, vol Volume, byteSize int64)
 		return vol.UnmountTask(func(op *operations.Operation) error {
 			output, err := shared.RunCommand("e2fsck", "-f", "-y", devPath)
 			if err != nil {
-				// e2fsck provides some context to errors on stdout.
-				return errors.Wrapf(err, "%s", strings.TrimSpace(output))
+				exitCodeFSModified := false
+				runErr, ok := err.(shared.RunError)
+				if ok {
+					exitError, ok := runErr.Err.(*exec.ExitError)
+					if ok {
+						if exitError.ExitCode() == 1 {
+							exitCodeFSModified = true
+						}
+					}
+				}
+
+				// e2fsck can return non-zero exit code if it has modified the filesystem, but
+				// this isn't an error and we can proceed.
+				if !exitCodeFSModified {
+					// e2fsck provides some context to errors on stdout.
+					return errors.Wrapf(err, "%s", strings.TrimSpace(output))
+				}
 			}
 
 			_, err = shared.RunCommand("resize2fs", devPath, strSize)


More information about the lxc-devel mailing list