Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osutil/mkfs: disable orphan_file feature for ext4 #13373

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions osutil/mkfs/mkfs.go
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/snapcore/snapd/gadget/quantity"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/release"
"github.com/snapcore/snapd/strutil/shlex"
)

Expand Down Expand Up @@ -74,6 +75,15 @@ func mkfsExt4(img, label, contentsRootDir string, deviceSize, sectorSize quantit
// https://github.com/snapcore/snapd/pull/6997#discussion_r293967140
mkfsArgs := []string{"mkfs.ext4"}

// By default mkfs.ext4 on Lunar will use the orphan_file feature.
// This feature is not supported on older series and is disabled on newer ones.
// So we need to explicitly disable it when building on Lunar so the filesystem
// can be correctly handled (ex. resized) on older series.
// See https://bugs.launchpad.net/ubuntu-image/+bug/2028564
if runningOnLunar() {
mkfsArgs = append(mkfsArgs, "-O", "^orphan_file")
}

const size32MiB = 32 * quantity.SizeMiB
if deviceSize != 0 && deviceSize <= size32MiB {
// With the default block size of 4096 bytes, the minimal journal size
Expand Down Expand Up @@ -218,3 +228,8 @@ func mkfsVfat(img, label, contentsRootDir string, deviceSize, sectorSize quantit
}
return nil
}

// Check if we are running on Lunar
func runningOnLunar() bool {
return release.ReleaseInfo.VersionID == "23.04"
}
18 changes: 18 additions & 0 deletions osutil/mkfs/mkfs_test.go
Expand Up @@ -29,6 +29,7 @@ import (
. "gopkg.in/check.v1"

"github.com/snapcore/snapd/osutil/mkfs"
"github.com/snapcore/snapd/release"
"github.com/snapcore/snapd/testutil"
)

Expand Down Expand Up @@ -103,6 +104,23 @@ func (m *mkfsSuite) TestMkfsExt4Happy(c *C) {
},
})

cmd.ForgetCalls()
upils marked this conversation as resolved.
Show resolved Hide resolved

// when running on Lunar, remove orphan_file feature
restore := release.MockReleaseInfo(&release.OS{VersionID: "23.04"})
defer restore()

err = mkfs.Make("ext4", "foo.img", "my-label", 0, 0)
c.Assert(err, IsNil)
c.Check(cmd.Calls(), DeepEquals, [][]string{
{
"fakeroot",
"mkfs.ext4",
"-O", "^orphan_file",
"-L", "my-label",
"foo.img",
},
})
}

func (m *mkfsSuite) TestMkfsExt4WithSize(c *C) {
Expand Down