Skip to content

Commit

Permalink
Allow clients to know if inodes are supported on a filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
derekwaynecarr committed Jul 26, 2016
1 parent 04f73fe commit cccf9d5
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 60 deletions.
75 changes: 34 additions & 41 deletions container/raw/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,44 @@ func (self *rawContainerHandler) GetSpec() (info.ContainerSpec, error) {
return spec, nil
}

func fsToFsStats(fs *fs.Fs) info.FsStats {
inodesFree := uint64(0)
hasInodes := fs.InodesFree != nil
if hasInodes {
inodesFree = *fs.InodesFree
}
return info.FsStats{
Device: fs.Device,
Type: fs.Type.String(),
Limit: fs.Capacity,
Usage: fs.Capacity - fs.Free,
HasInodes: hasInodes,
InodesFree: inodesFree,
Available: fs.Available,
ReadsCompleted: fs.DiskStats.ReadsCompleted,
ReadsMerged: fs.DiskStats.ReadsMerged,
SectorsRead: fs.DiskStats.SectorsRead,
ReadTime: fs.DiskStats.ReadTime,
WritesCompleted: fs.DiskStats.WritesCompleted,
WritesMerged: fs.DiskStats.WritesMerged,
SectorsWritten: fs.DiskStats.SectorsWritten,
WriteTime: fs.DiskStats.WriteTime,
IoInProgress: fs.DiskStats.IoInProgress,
IoTime: fs.DiskStats.IoTime,
WeightedIoTime: fs.DiskStats.WeightedIoTime,
}
}

func (self *rawContainerHandler) getFsStats(stats *info.ContainerStats) error {
// Get Filesystem information only for the root cgroup.
if isRootCgroup(self.name) {
filesystems, err := self.fsInfo.GetGlobalFsInfo()
if err != nil {
return err
}
for _, fs := range filesystems {
stats.Filesystem = append(stats.Filesystem,
info.FsStats{
Device: fs.Device,
Type: fs.Type.String(),
Limit: fs.Capacity,
Usage: fs.Capacity - fs.Free,
Available: fs.Available,
InodesFree: fs.InodesFree,
ReadsCompleted: fs.DiskStats.ReadsCompleted,
ReadsMerged: fs.DiskStats.ReadsMerged,
SectorsRead: fs.DiskStats.SectorsRead,
ReadTime: fs.DiskStats.ReadTime,
WritesCompleted: fs.DiskStats.WritesCompleted,
WritesMerged: fs.DiskStats.WritesMerged,
SectorsWritten: fs.DiskStats.SectorsWritten,
WriteTime: fs.DiskStats.WriteTime,
IoInProgress: fs.DiskStats.IoInProgress,
IoTime: fs.DiskStats.IoTime,
WeightedIoTime: fs.DiskStats.WeightedIoTime,
})
for i := range filesystems {
fs := filesystems[i]
stats.Filesystem = append(stats.Filesystem, fsToFsStats(&fs))
}
} else if len(self.externalMounts) > 0 {
var mountSet map[string]struct{}
Expand All @@ -204,26 +214,9 @@ func (self *rawContainerHandler) getFsStats(stats *info.ContainerStats) error {
if err != nil {
return err
}
for _, fs := range filesystems {
stats.Filesystem = append(stats.Filesystem,
info.FsStats{
Device: fs.Device,
Type: fs.Type.String(),
Limit: fs.Capacity,
Usage: fs.Capacity - fs.Free,
InodesFree: fs.InodesFree,
ReadsCompleted: fs.DiskStats.ReadsCompleted,
ReadsMerged: fs.DiskStats.ReadsMerged,
SectorsRead: fs.DiskStats.SectorsRead,
ReadTime: fs.DiskStats.ReadTime,
WritesCompleted: fs.DiskStats.WritesCompleted,
WritesMerged: fs.DiskStats.WritesMerged,
SectorsWritten: fs.DiskStats.SectorsWritten,
WriteTime: fs.DiskStats.WriteTime,
IoInProgress: fs.DiskStats.IoInProgress,
IoTime: fs.DiskStats.IoTime,
WeightedIoTime: fs.DiskStats.WeightedIoTime,
})
for i := range filesystems {
fs := filesystems[i]
stats.Filesystem = append(stats.Filesystem, fsToFsStats(&fs))
}
}
return nil
Expand Down
5 changes: 4 additions & 1 deletion fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ func (self *RealFsInfo) GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, er
fs.Capacity, fs.Free, fs.Available, err = getZfstats(device)
fs.Type = ZFS
default:
fs.Capacity, fs.Free, fs.Available, fs.Inodes, fs.InodesFree, err = getVfsStats(partition.mountpoint)
var inodes, inodesFree uint64
fs.Capacity, fs.Free, fs.Available, inodes, inodesFree, err = getVfsStats(partition.mountpoint)
fs.Inodes = &inodes
fs.InodesFree = &inodesFree
fs.Type = VFS
}
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions fs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type Fs struct {
Capacity uint64
Free uint64
Available uint64
Inodes uint64
InodesFree uint64
Inodes *uint64
InodesFree *uint64
DiskStats DiskStats
}

Expand Down
3 changes: 3 additions & 0 deletions info/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ type FsStats struct {
// Number of bytes available for non-root user.
Available uint64 `json:"available"`

// HasInodes when true, indicates that Inodes info will be available.
HasInodes bool `json:"has_inodes"`

// Number of available Inodes
InodesFree uint64 `json:"inodes_free"`

Expand Down
3 changes: 3 additions & 0 deletions info/v1/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type FsInfo struct {

// Total number of inodes available on the filesystem.
Inodes uint64 `json:"inodes"`

// HasInodes when true, indicates that Inodes info will be available.
HasInodes bool `json:"has_inodes"`
}

type Node struct {
Expand Down
4 changes: 2 additions & 2 deletions info/v2/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ type FsInfo struct {
// Labels associated with this filesystem.
Labels []string `json:"labels"`

// Number of available Inodes.
InodesFree uint64 `json:"inodes_free"`
// Number of available Inodes (if known)
InodesFree *uint64 `json:"inodes_free,omitempty"`
}

type RequestOptions struct {
Expand Down
22 changes: 13 additions & 9 deletions info/v2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ func machineFsStatsFromV1(fsStats []v1.FsStats) []MachineFsStats {
writeDuration := time.Millisecond * time.Duration(stat.WriteTime)
ioDuration := time.Millisecond * time.Duration(stat.IoTime)
weightedDuration := time.Millisecond * time.Duration(stat.WeightedIoTime)
result = append(result, MachineFsStats{
Device: stat.Device,
Type: stat.Type,
Capacity: &stat.Limit,
Usage: &stat.Usage,
Available: &stat.Available,
InodesFree: &stat.InodesFree,
machineFsStat := MachineFsStats{
Device: stat.Device,
Type: stat.Type,
Capacity: &stat.Limit,
Usage: &stat.Usage,
Available: &stat.Available,
DiskStats: DiskStats{
ReadsCompleted: &stat.ReadsCompleted,
ReadsMerged: &stat.ReadsMerged,
Expand All @@ -50,15 +49,20 @@ func machineFsStatsFromV1(fsStats []v1.FsStats) []MachineFsStats {
IoDuration: &ioDuration,
WeightedIoDuration: &weightedDuration,
},
})
}
if stat.HasInodes {
machineFsStat.InodesFree = &stat.InodesFree
}
result = append(result, machineFsStat)
}
return result
}

func MachineStatsFromV1(cont *v1.ContainerInfo) []MachineStats {
var stats []MachineStats
var last *v1.ContainerStats
for _, val := range cont.Stats {
for i := range cont.Stats {
val := cont.Stats[i]
stat := MachineStats{
Timestamp: val.Timestamp,
}
Expand Down
9 changes: 7 additions & 2 deletions machine/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ func Info(sysFs sysfs.SysFs, fsInfo fs.FsInfo, inHostNamespace bool) (*info.Mach
InstanceID: instanceID,
}

for _, fs := range filesystems {
machineInfo.Filesystems = append(machineInfo.Filesystems, info.FsInfo{Device: fs.Device, Type: fs.Type.String(), Capacity: fs.Capacity, Inodes: fs.Inodes})
for i := range filesystems {
fs := filesystems[i]
inodes := uint64(0)
if fs.Inodes != nil {
inodes = *fs.Inodes
}
machineInfo.Filesystems = append(machineInfo.Filesystems, info.FsInfo{Device: fs.Device, Type: fs.Type.String(), Capacity: fs.Capacity, Inodes: inodes, HasInodes: fs.Inodes != nil})
}

return machineInfo, nil
Expand Down
11 changes: 8 additions & 3 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ import (
"github.com/google/cadvisor/utils/sysfs"
"github.com/google/cadvisor/version"

"net/http"

"github.com/golang/glog"
"github.com/opencontainers/runc/libcontainer/cgroups"
"net/http"
)

var globalHousekeepingInterval = flag.Duration("global_housekeeping_interval", 1*time.Minute, "Interval between global housekeepings")
Expand Down Expand Up @@ -671,7 +672,8 @@ func (self *manager) GetFsInfo(label string) ([]v2.FsInfo, error) {
}
}
fsInfo := []v2.FsInfo{}
for _, fs := range stats[0].Filesystem {
for i := range stats[0].Filesystem {
fs := stats[0].Filesystem[i]
if len(label) != 0 && fs.Device != dev {
continue
}
Expand All @@ -683,14 +685,17 @@ func (self *manager) GetFsInfo(label string) ([]v2.FsInfo, error) {
if err != nil {
return nil, err
}

fi := v2.FsInfo{
Device: fs.Device,
Mountpoint: mountpoint,
Capacity: fs.Limit,
Usage: fs.Usage,
Available: fs.Available,
Labels: labels,
InodesFree: fs.InodesFree,
}
if fs.HasInodes {
fi.InodesFree = &fs.InodesFree
}
fsInfo = append(fsInfo, fi)
}
Expand Down

0 comments on commit cccf9d5

Please sign in to comment.