Skip to content

Commit 2ba79d2

Browse files
author
Stuart Espey
committed
incusd/storage: fix squashfs unpacking to NFS destinations
NFS4v2 supports user.xattr, and can be used with Incus via the dir driver, but image unpacking will fail when the container image uses non-user xattrs such as security.xattr This fix will skip extraction of security.xattrs when extracting to an NFS hosted directory The fix is not specific to the dir driver, and could benefit a future NFS driver too. Signed-off-by: Stuart Espey <stuart.espey@mactrix.com>
1 parent b976224 commit 2ba79d2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

internal/linux/filesystem.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ func DetectFilesystem(path string) (string, error) {
4242
return FSTypeToName(int32(fs.Type))
4343
}
4444

45+
// returns true if the path exists and is NFS
46+
func IsNfs(path string) bool {
47+
backingFs, err := DetectFilesystem(path)
48+
if err != nil {
49+
return false
50+
}
51+
52+
return backingFs == "nfs"
53+
}
54+
4555
// FSTypeToName returns the name of the given fs type.
4656
// The fsType is from the Type field of unix.Statfs_t. We use int32 so that this function behaves the same on both
4757
// 32bit and 64bit platforms by requiring any 64bit FS types to be overflowed before being passed in. They will

shared/archive/archive.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"golang.org/x/sys/unix"
1717

18+
"github.com/lxc/incus/v6/internal/linux"
1819
"github.com/lxc/incus/v6/shared/ioprogress"
1920
"github.com/lxc/incus/v6/shared/logger"
2021
"github.com/lxc/incus/v6/shared/subprocess"
@@ -200,6 +201,12 @@ func Unpack(file string, path string, blockBackend bool, maxMemory int64, tracke
200201
}
201202
}
202203

204+
// NFS 4.2 can support xattrs, but not security.xattr
205+
if linux.IsNfs(path) {
206+
logger.Warn("Unpack: destination path is NFS, disabling non-user xatttr unpacking", logger.Ctx{"file": file, "command": command, "extension": extension, "path": path, "args": args})
207+
args = append(args, "-user-xattrs")
208+
}
209+
203210
args = append(args, file)
204211
} else {
205212
return fmt.Errorf("Unsupported image format: %s", extension)

0 commit comments

Comments
 (0)