@@ -13,23 +13,22 @@ import (
1313)
1414
1515type BlockDeviceInfo struct {
16- Name string `json:"name"`
17- KernelName string `json:"kernel_name"`
18- ParentKernelName string `json:"parent_kernel_name"`
19- Type string `json:"type"`
20- Major int `json:"major"`
21- Minor int `json:"minor"`
22- Size uint64 `json:"size"`
23- FilesystemType string `json:"filesystem_type"`
24- Mountpoint string `json:"mountpoint"`
25- Serial string `json:"serial"`
26- ReadOnly bool `json:"read_only"`
27- Removable bool `json:"removable"`
28- PartitionTableType string `json:"partition_table_type"`
16+ Name string `json:"name"`
17+ KernelName string `json:"kernel_name"`
18+ ParentKernelName string `json:"parent_kernel_name"`
19+ Type string `json:"type"`
20+ Major int `json:"major"`
21+ Minor int `json:"minor"`
22+ Size uint64 `json:"size"`
23+ FilesystemType string `json:"filesystem_type"`
24+ Mountpoint string `json:"mountpoint"`
25+ Serial string `json:"serial"`
26+ ReadOnly bool `json:"read_only"`
27+ Removable bool `json:"removable"`
2928}
3029
31- const lsblkColumns = "NAME,KNAME,PKNAME,TYPE,MAJ:MIN,SIZE,FSTYPE,MOUNTPOINT,SERIAL,RO,RM,PTTYPE "
32- const lsblkFormat = `NAME=%q KNAME=%q PKNAME=%q TYPE=%q MAJ:MIN="%d:%d" SIZE="%d" FSTYPE=%q MOUNTPOINT=%q SERIAL=%q RO="%d" RM="%d0" PTTYPE=%q `
30+ const lsblkColumns = "NAME,KNAME,PKNAME,TYPE,MAJ:MIN,SIZE,FSTYPE,MOUNTPOINT,SERIAL,RO,RM"
31+ const lsblkFormat = `NAME=%q KNAME=%q PKNAME=%q TYPE=%q MAJ:MIN="%d:%d" SIZE="%d" FSTYPE=%q MOUNTPOINT=%q SERIAL=%q RO="%d" RM="%d0"`
3332const HostBlockDevicesPath = `host-collectors/system/block_devices.json`
3433
3534type CollectHostBlockDevices struct {
@@ -46,11 +45,6 @@ func (c *CollectHostBlockDevices) IsExcluded() (bool, error) {
4645}
4746
4847func (c * CollectHostBlockDevices ) Collect (progressChan chan <- interface {}) (map [string ][]byte , error ) {
49- // TODO: Consider using lsblk --json --output <columns> instead.
50- // This simplifies the parsing logic and also represents a parent/child relationship
51- // between devices when there are partitions.
52- // NOTE: Remember to validate the output of lsblk json
53- // NOTE: Check what version of lsblk --json was introduced.
5448 cmd := exec .Command ("lsblk" , "--noheadings" , "--bytes" , "--pairs" , "-o" , lsblkColumns )
5549 stdout , err := cmd .Output ()
5650 if err != nil {
@@ -101,7 +95,6 @@ func parseLsblkOutput(output []byte) ([]BlockDeviceInfo, error) {
10195 & bdi .Serial ,
10296 & ro ,
10397 & rm ,
104- & bdi .PartitionTableType ,
10598 )
10699 bdi .ReadOnly = ro == 1
107100 bdi .Removable = rm == 1
0 commit comments