Skip to content

Commit

Permalink
fix: extfs repair and resize
Browse files Browse the repository at this point in the history
Fixes siderolabs#10103

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Jan 10, 2025
1 parent e6a4583 commit 52c6f25
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
17 changes: 14 additions & 3 deletions internal/pkg/mount/v2/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ import (

// repair a filesystem.
func (p *Point) repair(printerOptions PrinterOptions) error {
printerOptions.Printf("filesystem on %s needs cleaning, running repair", p.source)
var repairFunc func(partition string) error

if err := makefs.XFSRepair(p.source, p.fstype); err != nil {
return fmt.Errorf("xfs_repair: %w", err)
switch p.fstype {
case "ext4":
repairFunc = makefs.Ext4Repair
case "xfs":
repairFunc = makefs.XFSRepair
default:
return fmt.Errorf("unsupported filesystem type for repair: %s", p.fstype)
}

printerOptions.Printf("filesystem (%s) on %s needs cleaning, running repair", p.fstype, p.source)

if err := repairFunc(p.source); err != nil {
return fmt.Errorf("repair: %w", err)
}

printerOptions.Printf("filesystem successfully repaired on %s", p.source)
Expand Down
20 changes: 19 additions & 1 deletion pkg/makefs/ext4.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,25 @@ func Ext4(partname string, setters ...Option) error {

// Ext4Resize expands a ext4 filesystem to the maximum possible.
func Ext4Resize(partname string) error {
// resizing the filesystem requires a check first
if err := Ext4Repair(partname); err != nil {
return fmt.Errorf("failed to repair before growing ext4 filesystem: %w", err)
}

_, err := cmd.Run("resize2fs", partname)
if err != nil {
return fmt.Errorf("failed to grow ext4 filesystem: %w", err)
}

return err
return nil
}

// Ext4Repair repairs a ext4 filesystem.
func Ext4Repair(partname string) error {
_, err := cmd.Run("e2fsck", "-f", "-p", partname)
if err != nil {
return fmt.Errorf("failed to repair ext4 filesystem: %w", err)
}

return nil
}
14 changes: 8 additions & 6 deletions pkg/makefs/xfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ const (
// MUST be mounted, or this will fail.
func XFSGrow(partname string) error {
_, err := cmd.Run("xfs_growfs", "-d", partname)
if err != nil {
return fmt.Errorf("failed to grow XFS filesystem: %w", err)
}

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)
}

func XFSRepair(partname string) error {
_, err := cmd.Run("xfs_repair", partname)
if err != nil {
return fmt.Errorf("error repairing XFS filesystem: %w", err)
}

return err
return nil
}

// XFS creates a XFS filesystem on the specified partition.
Expand Down

0 comments on commit 52c6f25

Please sign in to comment.