Merge pull request #519 from ofek/mapper

[disk][linux] add label based on devicemapper name of disk
pull/521/head
shirou 7 years ago committed by GitHub
commit 7c23d960dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -117,6 +117,10 @@ Several methods have been added which are not present in psutil, but will provid
- VirtualizationSystem (ex: "LXC")
- VirtualizationRole (ex: "guest"/"host")
- IOCounters
- Label (linux only) The registered [device mapper name](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-block-dm)
- cpu/CPUInfo() (linux, freebsd)
- CPU (ex: 0, 1, ...)

@ -42,6 +42,7 @@ type IOCountersStat struct {
WeightedIO uint64 `json:"weightedIO"`
Name string `json:"name"`
SerialNumber string `json:"serialNumber"`
Label string `json:"label"`
}
func (d UsageStat) String() string {

@ -5,6 +5,7 @@ package disk
import (
"context"
"fmt"
"io/ioutil"
"os/exec"
"path/filepath"
"strconv"
@ -370,6 +371,8 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC
d.Name = name
d.SerialNumber = GetDiskSerialNumber(name)
d.Label = GetLabel(name)
ret[name] = d
}
return ret, nil
@ -406,6 +409,26 @@ func GetDiskSerialNumberWithContext(ctx context.Context, name string) string {
return ""
}
// GetLabel returns label of given device or empty string on error.
// Name of device is expected, eg. /dev/sda
// Supports label based on devicemapper name
// See https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-block-dm
func GetLabel(name string) string {
// Try label based on devicemapper name
dmname_filename := common.HostSys(fmt.Sprintf("block/%s/dm/name", name))
if !common.PathExists(dmname_filename) {
return ""
}
dmname, err := ioutil.ReadFile(dmname_filename)
if err != nil {
return ""
} else {
return dmname
}
}
func getFsType(stat unix.Statfs_t) string {
t := int64(stat.Type)
ret, ok := fsTypeMap[t]

Loading…
Cancel
Save