Skip to content

Commit

Permalink
fix: define softraid partition
Browse files Browse the repository at this point in the history
MDRaid uses `p` betwewn device name and partition number.

Signed-off-by: Serge Logvinov <[email protected]>
Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
sergelogvinov authored and frezbo committed Nov 23, 2023
1 parent a75c4cc commit d9313ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions blockdevice/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func PartNo(partname string) (string, error) {
case strings.HasPrefix(p, "loop"):
idx := strings.LastIndex(partname, "p")

return partname[idx+1:], nil
case strings.HasPrefix(p, "md"):
idx := strings.LastIndex(partname, "p")

return partname[idx+1:], nil
case strings.HasPrefix(p, "sd"):
fallthrough
Expand Down Expand Up @@ -57,6 +61,8 @@ func DevnameFromPartname(partname string) (string, error) {
fallthrough
case strings.HasPrefix(p, "loop"):
return strings.TrimSuffix(p, "p"+partno), nil
case strings.HasPrefix(p, "md"):
return strings.TrimSuffix(p, "p"+partno), nil
case strings.HasPrefix(p, "sd"):
fallthrough
case strings.HasPrefix(p, "hd"):
Expand All @@ -81,6 +87,8 @@ func PartName(d string, n int) string {
fallthrough
case strings.HasPrefix(p, "loop"):
partname = fmt.Sprintf("%sp%d", p, n)
case strings.HasPrefix(p, "md"):
partname = fmt.Sprintf("%sp%d", p, n)
default:
partname = fmt.Sprintf("%s%d", p, n)
}
Expand Down
15 changes: 15 additions & 0 deletions blockdevice/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ func Test_PartNo(t *testing.T) {
},
want: "3",
},
{
name: "md0p2",
args: args{
devname: "md0p2",
},
want: "2",
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -206,6 +213,14 @@ func Test_DevnameFromPartname(t *testing.T) {
},
want: "mmcblk0",
},
{
name: "md0p1",
args: args{
devname: "md0p1",
partno: "1",
},
want: "md0",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit d9313ea

Please sign in to comment.