talos/pkg/makefs/xfs.go
Noel Georgi 3ae8bdd92e
chore: run xfs_repair on xfs filesystem returing EUCLEAN
Run `xfs_repair` on XFS filesystems that needs repairing indicated by
the `unix.EUCLEAN` error when mounting

Fixes #5319
Fixes #5437

Signed-off-by: Noel Georgi <git@frezbo.dev>
2022-06-08 23:59:15 +05:30

63 lines
1.4 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package makefs
import (
"fmt"
"github.com/talos-systems/go-cmd/pkg/cmd"
)
const (
// FilesystemTypeXFS is the filesystem type for XFS.
FilesystemTypeXFS = "xfs"
)
// XFSGrow expands a XFS filesystem to the maximum possible. The partition
// MUST be mounted, or this will fail.
func XFSGrow(partname string) error {
_, err := cmd.Run("xfs_growfs", "-d", partname)
return err
}
// XFSRepair repairs a XFS filesystem on the specified partition.
func XFSRepair(partname, fsType string) error {
if fsType != FilesystemTypeXFS {
return fmt.Errorf("unsupported filesystem type: %s", fsType)
}
_, err := cmd.Run("xfs_repair", partname)
return err
}
// XFS creates a XFS filesystem on the specified partition.
func XFS(partname string, setters ...Option) error {
if partname == "" {
return fmt.Errorf("missing path to disk")
}
opts := NewDefaultOptions(setters...)
// The ftype=1 naming option is required by overlayfs.
// The bigtime=1 metadata option enables timestamps beyond 2038.
args := []string{"-n", "ftype=1", "-m", "bigtime=1"}
if opts.Force {
args = append(args, "-f")
}
if opts.Label != "" {
args = append(args, "-L", opts.Label)
}
args = append(args, partname)
_, err := cmd.Run("mkfs.xfs", args...)
return err
}