github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/pkg/sysinfo/sysinfo.go (about)

     1  package sysinfo
     2  
     3  import "github.com/docker/docker/pkg/parsers"
     4  
     5  // SysInfo stores information about which features a kernel supports.
     6  // TODO Windows: Factor out platform specific capabilities.
     7  type SysInfo struct {
     8  	// Whether the kernel supports AppArmor or not
     9  	AppArmor bool
    10  
    11  	cgroupMemInfo
    12  	cgroupCPUInfo
    13  	cgroupBlkioInfo
    14  	cgroupCpusetInfo
    15  
    16  	// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
    17  	IPv4ForwardingDisabled bool
    18  
    19  	// Whether bridge-nf-call-iptables is supported or not
    20  	BridgeNfCallIptablesDisabled bool
    21  
    22  	// Whether bridge-nf-call-ip6tables is supported or not
    23  	BridgeNfCallIP6tablesDisabled bool
    24  
    25  	// Whether the cgroup has the mountpoint of "devices" or not
    26  	CgroupDevicesEnabled bool
    27  }
    28  
    29  type cgroupMemInfo struct {
    30  	// Whether memory limit is supported or not
    31  	MemoryLimit bool
    32  
    33  	// Whether swap limit is supported or not
    34  	SwapLimit bool
    35  
    36  	// Whether soft limit is supported or not
    37  	MemoryReservation bool
    38  
    39  	// Whether OOM killer disable is supported or not
    40  	OomKillDisable bool
    41  
    42  	// Whether memory swappiness is supported or not
    43  	MemorySwappiness bool
    44  
    45  	// Whether kernel memory limit is supported or not
    46  	KernelMemory bool
    47  }
    48  
    49  type cgroupCPUInfo struct {
    50  	// Whether CPU shares is supported or not
    51  	CPUShares bool
    52  
    53  	// Whether CPU CFS(Completely Fair Scheduler) period is supported or not
    54  	CPUCfsPeriod bool
    55  
    56  	// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not
    57  	CPUCfsQuota bool
    58  }
    59  
    60  type cgroupBlkioInfo struct {
    61  	// Whether Block IO weight is supported or not
    62  	BlkioWeight bool
    63  
    64  	// Whether Block IO weight_device is supported or not
    65  	BlkioWeightDevice bool
    66  
    67  	// Whether Block IO read limit in bytes per second is supported or not
    68  	BlkioReadBpsDevice bool
    69  
    70  	// Whether Block IO write limit in bytes per second is supported or not
    71  	BlkioWriteBpsDevice bool
    72  }
    73  
    74  type cgroupCpusetInfo struct {
    75  	// Whether Cpuset is supported or not
    76  	Cpuset bool
    77  
    78  	// Available Cpuset's cpus
    79  	Cpus string
    80  
    81  	// Available Cpuset's memory nodes
    82  	Mems string
    83  }
    84  
    85  // IsCpusetCpusAvailable returns `true` if the provided string set is contained
    86  // in cgroup's cpuset.cpus set, `false` otherwise.
    87  // If error is not nil a parsing error occurred.
    88  func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) {
    89  	return isCpusetListAvailable(provided, c.Cpus)
    90  }
    91  
    92  // IsCpusetMemsAvailable returns `true` if the provided string set is contained
    93  // in cgroup's cpuset.mems set, `false` otherwise.
    94  // If error is not nil a parsing error occurred.
    95  func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) {
    96  	return isCpusetListAvailable(provided, c.Mems)
    97  }
    98  
    99  func isCpusetListAvailable(provided, available string) (bool, error) {
   100  	parsedProvided, err := parsers.ParseUintList(provided)
   101  	if err != nil {
   102  		return false, err
   103  	}
   104  	parsedAvailable, err := parsers.ParseUintList(available)
   105  	if err != nil {
   106  		return false, err
   107  	}
   108  	for k := range parsedProvided {
   109  		if !parsedAvailable[k] {
   110  			return false, nil
   111  		}
   112  	}
   113  	return true, nil
   114  }