Skip to content
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
2 changes: 1 addition & 1 deletion sysfs/mdraid.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (fs FS) Mdraids() ([]Mdraid, error) {
}

if val, err := util.SysReadFile(filepath.Join(path, "sync_completed")); err == nil {
if val != "none" {
if val != "none" && val != "delayed" {
var a, b uint64

// File contains two values representing the fraction of number of completed
Expand Down
73 changes: 73 additions & 0 deletions sysfs/mdraid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package sysfs

import (
"os"
"path/filepath"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -155,3 +157,74 @@ func TestMdraidStats(t *testing.T) {
t.Fatalf("unexpected Mdraid (-want +got):\n%s", diff)
}
}

func TestMdraidsIgnoresDelayedSyncCompleted(t *testing.T) {
root := t.TempDir()

writeFile := func(rel, content string) {
t.Helper()
path := filepath.Join(root, rel)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
t.Fatal(err)
}
}

symlink := func(target, rel string) {
t.Helper()
path := filepath.Join(root, rel)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.Symlink(target, path); err != nil {
t.Fatal(err)
}
}

writeFile("block/md1/md/level", "raid1\n")
writeFile("block/md1/md/array_state", "clean\n")
writeFile("block/md1/md/metadata_version", "1.2\n")
writeFile("block/md1/md/raid_disks", "2\n")
writeFile("block/md1/md/uuid", "test-md1-uuid\n")
writeFile("block/md1/md/degraded", "0\n")
writeFile("block/md1/md/sync_action", "resync\n")
writeFile("block/md1/md/sync_completed", "delayed\n")
writeFile("block/md1/md/dev-sda/state", "in_sync\n")
writeFile("block/md1/md/dev-sdb/state", "in_sync\n")
symlink("dev-sda", "block/md1/md/rd0")
symlink("dev-sdb", "block/md1/md/rd1")

fs, err := NewFS(root)
if err != nil {
t.Fatal(err)
}

got, err := fs.Mdraids()
if err != nil {
t.Fatal(err)
}

want := []Mdraid{
{
Device: "md1",
Level: "raid1",
ArrayState: "clean",
MetadataVersion: "1.2",
Disks: func(v uint64) *uint64 { return &v }(2),
Components: []MdraidComponent{
{Device: "sda", State: "in_sync"},
{Device: "sdb", State: "in_sync"},
},
UUID: "test-md1-uuid",
DegradedDisks: 0,
SyncAction: "resync",
SyncCompleted: 0,
},
}

if diff := cmp.Diff(want, got); diff != "" {
t.Fatalf("unexpected Mdraid (-want +got):\n%s", diff)
}
}