// checks if the required cgroups subsystems are mounted. // As of now, only 'cpu' and 'memory' are required. // cpu quota is a soft requirement. func validateSystemRequirements(mountUtil mount.Interface) (features, error) { const ( cgroupMountType = "cgroup" localErr = "system validation failed" ) var ( cpuMountPoint string f features ) mountPoints, err := mountUtil.List() if err != nil { return f, fmt.Errorf("%s - %v", localErr, err) } expectedCgroups := sets.NewString("cpu", "cpuacct", "cpuset", "memory") for _, mountPoint := range mountPoints { if mountPoint.Type == cgroupMountType { for _, opt := range mountPoint.Opts { if expectedCgroups.Has(opt) { expectedCgroups.Delete(opt) } if opt == "cpu" { cpuMountPoint = mountPoint.Path } } } } if expectedCgroups.Len() > 0 { return f, fmt.Errorf("%s - Following Cgroup subsystem not mounted: %v", localErr, expectedCgroups.List()) } // Check if cpu quota is available. // CPU cgroup is required and so it expected to be mounted at this point. periodExists, err := util.FileExists(path.Join(cpuMountPoint, "cpu.cfs_period_us")) if err != nil { glog.Errorf("failed to detect if CPU cgroup cpu.cfs_period_us is available - %v", err) } quotaExists, err := util.FileExists(path.Join(cpuMountPoint, "cpu.cfs_quota_us")) if err != nil { glog.Errorf("failed to detect if CPU cgroup cpu.cfs_quota_us is available - %v", err) } if quotaExists && periodExists { f.cpuHardcapping = true } return f, nil }
// utility to mount a disk based filesystem func diskSetUp(manager diskManager, b fcDiskMounter, volPath string, mounter mount.Interface, fsGroup *int64) error { globalPDPath := manager.MakeGlobalPDName(*b.fcDisk) // TODO: handle failed mounts here. noMnt, err := mounter.IsLikelyNotMountPoint(volPath) if err != nil && !os.IsNotExist(err) { glog.Errorf("cannot validate mountpoint: %s", volPath) return err } if !noMnt { return nil } if err := manager.AttachDisk(b); err != nil { glog.Errorf("failed to attach disk") return err } if err := os.MkdirAll(volPath, 0750); err != nil { glog.Errorf("failed to mkdir:%s", volPath) return err } // Perform a bind mount to the full path to allow duplicate mounts of the same disk. options := []string{"bind"} if b.readOnly { options = append(options, "ro") } err = mounter.Mount(globalPDPath, volPath, "", options) if err != nil { glog.Errorf("failed to bind mount:%s", globalPDPath) return err } if !b.readOnly { volume.SetVolumeOwnership(&b, fsGroup) } return nil }
// utility to tear down a disk based filesystem func diskTearDown(manager diskManager, c fcDiskUnmounter, volPath string, mounter mount.Interface) error { noMnt, err := mounter.IsLikelyNotMountPoint(volPath) if err != nil { glog.Errorf("cannot validate mountpoint %s", volPath) return err } if noMnt { return os.Remove(volPath) } refs, err := mount.GetMountRefs(mounter, volPath) if err != nil { glog.Errorf("failed to get reference count %s", volPath) return err } if err := mounter.Unmount(volPath); err != nil { glog.Errorf("failed to unmount %s", volPath) return err } // If len(refs) is 1, then all bind mounts have been removed, and the // remaining reference is the global mount. It is safe to detach. if len(refs) == 1 { mntPath := refs[0] if err := manager.DetachDisk(c, mntPath); err != nil { glog.Errorf("failed to detach disk from %s", mntPath) return err } } noMnt, mntErr := mounter.IsLikelyNotMountPoint(volPath) if mntErr != nil { glog.Errorf("isMountpoint check failed: %v", mntErr) return err } if noMnt { if err := os.Remove(volPath); err != nil { return err } } return nil }
// Unmount the global mount path, which should be the only one, and delete it. func unmountPDAndRemoveGlobalPath(globalMountPath string, mounter mount.Interface) error { err := mounter.Unmount(globalMountPath) os.Remove(globalMountPath) return err }