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

fix: extfs repair and resize #10116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hack/test/patches/image-cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ name: IMAGECACHE
provisioning:
diskSelector:
match: 'system_disk'
grow: true
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