Skip to content

Commit 9d841c9

Browse files
committed
mkcw: use xfsprogs -p to populate XFS filesystems
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
1 parent b5bcd59 commit 9d841c9

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

internal/mkcw/makefs.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ import (
1010

1111
// MakeFS formats the imageFile as a filesystem of the specified type,
1212
// populating it with the contents of the directory at sourcePath.
13-
// Recognized filesystem types are "ext2", "ext3", "ext4", and "btrfs".
13+
// Recognized filesystem types are "btrfs", "ext2", "ext3", "ext4", and "xfs".
1414
// Note that krun's init is currently hard-wired to assume "ext4".
1515
// Returns the stdout, stderr, and any error returned by the mkfs command.
1616
func MakeFS(sourcePath, imageFile, filesystem string) (string, string, error) {
1717
var stdout, stderr strings.Builder
18-
// N.B. mkfs.xfs can accept a protofile via its -p option, but the
19-
// protofile format doesn't allow us to supply timestamp information or
20-
// specify that files are hard linked
2118
switch filesystem {
2219
case "ext2", "ext3", "ext4":
2320
logrus.Debugf("mkfs -t %s --rootdir %q %q", filesystem, sourcePath, imageFile)
@@ -33,6 +30,16 @@ func MakeFS(sourcePath, imageFile, filesystem string) (string, string, error) {
3330
cmd.Stderr = &stderr
3431
err := cmd.Run()
3532
return stdout.String(), stderr.String(), err
33+
case "xfs":
34+
// N.B. -p treating directories as source for the filesystem contents only
35+
// available in xfsprogs-6.17.0 or later; before that, it only accepts prototype
36+
// files
37+
logrus.Debugf("mkfs -t %s -p %q %q", filesystem, sourcePath, imageFile)
38+
cmd := exec.Command("mkfs", "-t", filesystem, "-p", sourcePath, imageFile)
39+
cmd.Stdout = &stdout
40+
cmd.Stderr = &stderr
41+
err := cmd.Run()
42+
return stdout.String(), stderr.String(), err
3643
}
3744
return "", "", fmt.Errorf("don't know how to make a %q filesystem with contents", filesystem)
3845
}

tests/chroot.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ load helpers
176176
mkdir -p ${TEST_SCRATCH_DIR}/chroot/merged/var/lib/containers/storage
177177
chmod 755 ${TEST_SCRATCH_DIR}/chroot/merged/var/lib/containers/storage
178178
# https://github.com/podman-container-tools/buildah/issues/6967
179-
# chown -R is not safe against concurent removal, it will exit 1 when
179+
# chown -R is not safe against concurrent removal, it will exit 1 when
180180
# it happens but still walks all files so we can ignore the error here.
181181
# Bug: https://bugs.gnu.org/81444
182182
# Only once the fix landed in our test distro images coreutils version this workaround can be removed.

0 commit comments

Comments
 (0)