Skip to content

Commit

Permalink
CWA customer change #3.2: Fix lvm disk dimension Part 2: add source f…
Browse files Browse the repository at this point in the history
…ield in PartitionStat of Linux disk
  • Loading branch information
ZhenyuTan-amz committed Apr 12, 2022
1 parent d2625f0 commit a7251cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion patches/gopsutil/v3/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package disk
import (
"context"
"encoding/json"
"modernc.org/cc/v3"

"github.com/shirou/gopsutil/v3/internal/common"
)
Expand All @@ -25,6 +24,7 @@ type UsageStat struct {

type PartitionStat struct {
Device string `json:"device"`
Source string `json:"source,omitempty"`
Mountpoint string `json:"mountpoint"`
Fstype string `json:"fstype"`
Opts []string `json:"opts"`
Expand Down
1 change: 1 addition & 0 deletions patches/gopsutil/v3/disk/disk_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
if strings.HasPrefix(d.Device, "/dev/mapper/") {
devpath, err := filepath.EvalSymlinks(common.HostDev(strings.Replace(d.Device, "/dev", "", -1)))
if err == nil {
d.Source = d.Device
d.Device = devpath
}
}
Expand Down
11 changes: 11 additions & 0 deletions patches/gopsutil/v3/disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ func TestDiskPartitionStat_String(t *testing.T) {
if e != fmt.Sprintf("%v", v) {
t.Errorf("DiskUsageStat string is invalid: %v", v)
}
v = PartitionStat{
Device: "dm-1",
Source: "vg0--lv0",
Mountpoint: "/",
Fstype: "ext4",
Opts: []string{"ro"},
}
e = `{"device":"dm-1","source":"vg0--lv0","mountpoint":"/","fstype":"ext4","opts":"ro"}`
if e != fmt.Sprintf("%v", v) {
t.Errorf("DiskUsageStat string is invalid: %v", v)
}
}

func TestDiskIOCountersStat_String(t *testing.T) {
Expand Down

0 comments on commit a7251cf

Please sign in to comment.