sysinfo_solaris.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // +build solaris,cgo
  2. package sysinfo
  3. import (
  4. "bytes"
  5. "os/exec"
  6. "strconv"
  7. "strings"
  8. )
  9. /*
  10. #cgo LDFLAGS: -llgrp
  11. #include <unistd.h>
  12. #include <stdlib.h>
  13. #include <sys/lgrp_user.h>
  14. int getLgrpCount() {
  15. lgrp_cookie_t lgrpcookie = LGRP_COOKIE_NONE;
  16. uint_t nlgrps;
  17. if ((lgrpcookie = lgrp_init(LGRP_VIEW_OS)) == LGRP_COOKIE_NONE) {
  18. return -1;
  19. }
  20. nlgrps = lgrp_nlgrps(lgrpcookie);
  21. return nlgrps;
  22. }
  23. */
  24. import "C"
  25. // IsCPUSharesAvailable returns whether CPUShares setting is supported.
  26. // We need FSS to be set as default scheduling class to support CPU Shares
  27. func IsCPUSharesAvailable() bool {
  28. cmd := exec.Command("/usr/sbin/dispadmin", "-d")
  29. outBuf := new(bytes.Buffer)
  30. errBuf := new(bytes.Buffer)
  31. cmd.Stderr = errBuf
  32. cmd.Stdout = outBuf
  33. if err := cmd.Run(); err != nil {
  34. return false
  35. }
  36. return (strings.Contains(outBuf.String(), "FSS"))
  37. }
  38. // New returns a new SysInfo, using the filesystem to detect which features
  39. // the kernel supports.
  40. //NOTE Solaris: If we change the below capabilities be sure
  41. // to update verifyPlatformContainerSettings() in daemon_solaris.go
  42. func New(quiet bool) *SysInfo {
  43. sysInfo := &SysInfo{}
  44. sysInfo.cgroupMemInfo = setCgroupMem(quiet)
  45. sysInfo.cgroupCPUInfo = setCgroupCPU(quiet)
  46. sysInfo.cgroupBlkioInfo = setCgroupBlkioInfo(quiet)
  47. sysInfo.cgroupCpusetInfo = setCgroupCPUsetInfo(quiet)
  48. sysInfo.IPv4ForwardingDisabled = false
  49. sysInfo.AppArmor = false
  50. return sysInfo
  51. }
  52. // setCgroupMem reads the memory information for Solaris.
  53. func setCgroupMem(quiet bool) cgroupMemInfo {
  54. return cgroupMemInfo{
  55. MemoryLimit: true,
  56. SwapLimit: true,
  57. MemoryReservation: false,
  58. OomKillDisable: false,
  59. MemorySwappiness: false,
  60. KernelMemory: false,
  61. }
  62. }
  63. // setCgroupCPU reads the cpu information for Solaris.
  64. func setCgroupCPU(quiet bool) cgroupCPUInfo {
  65. return cgroupCPUInfo{
  66. CPUShares: true,
  67. CPUCfsPeriod: false,
  68. CPUCfsQuota: true,
  69. CPURealtimePeriod: false,
  70. CPURealtimeRuntime: false,
  71. }
  72. }
  73. // blkio switches are not supported in Solaris.
  74. func setCgroupBlkioInfo(quiet bool) cgroupBlkioInfo {
  75. return cgroupBlkioInfo{
  76. BlkioWeight: false,
  77. BlkioWeightDevice: false,
  78. }
  79. }
  80. // setCgroupCPUsetInfo reads the cpuset information for Solaris.
  81. func setCgroupCPUsetInfo(quiet bool) cgroupCpusetInfo {
  82. return cgroupCpusetInfo{
  83. Cpuset: true,
  84. Cpus: getCPUCount(),
  85. Mems: getLgrpCount(),
  86. }
  87. }
  88. func getCPUCount() string {
  89. ncpus := C.sysconf(C._SC_NPROCESSORS_ONLN)
  90. if ncpus <= 0 {
  91. return ""
  92. }
  93. return strconv.FormatInt(int64(ncpus), 16)
  94. }
  95. func getLgrpCount() string {
  96. nlgrps := C.getLgrpCount()
  97. if nlgrps <= 0 {
  98. return ""
  99. }
  100. return strconv.FormatInt(int64(nlgrps), 16)
  101. }