github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/client/fingerprint/cgroup_linux.go (about)

     1  // +build linux
     2  
     3  package fingerprint
     4  
     5  import (
     6  	"fmt"
     7  
     8  	cstructs "github.com/hashicorp/nomad/client/structs"
     9  	"github.com/opencontainers/runc/libcontainer/cgroups"
    10  )
    11  
    12  // FindCgroupMountpointDir is used to find the cgroup mount point on a Linux
    13  // system.
    14  func FindCgroupMountpointDir() (string, error) {
    15  	mount, err := cgroups.FindCgroupMountpointDir()
    16  	if err != nil {
    17  		switch e := err.(type) {
    18  		case *cgroups.NotFoundError:
    19  			// It's okay if the mount point is not discovered
    20  			return "", nil
    21  		default:
    22  			// All other errors are passed back as is
    23  			return "", e
    24  		}
    25  	}
    26  	return mount, nil
    27  }
    28  
    29  // Fingerprint tries to find a valid cgroup moint point
    30  func (f *CGroupFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cstructs.FingerprintResponse) error {
    31  	mount, err := f.mountPointDetector.MountPoint()
    32  	if err != nil {
    33  		f.clearCGroupAttributes(resp)
    34  		return fmt.Errorf("Failed to discover cgroup mount point: %s", err)
    35  	}
    36  
    37  	// Check if a cgroup mount point was found
    38  	if mount == "" {
    39  
    40  		f.clearCGroupAttributes(resp)
    41  
    42  		if f.lastState == cgroupAvailable {
    43  			f.logger.Printf("[INFO] fingerprint.cgroups: cgroups are unavailable")
    44  		}
    45  		f.lastState = cgroupUnavailable
    46  		return nil
    47  	}
    48  
    49  	resp.AddAttribute("unique.cgroup.mountpoint", mount)
    50  	resp.Detected = true
    51  
    52  	if f.lastState == cgroupUnavailable {
    53  		f.logger.Printf("[INFO] fingerprint.cgroups: cgroups are available")
    54  	}
    55  	f.lastState = cgroupAvailable
    56  	return nil
    57  }