當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cgroups.PathExists函數代碼示例

本文整理匯總了Golang中github.com/opencontainers/runc/libcontainer/cgroups.PathExists函數的典型用法代碼示例。如果您正苦於以下問題:Golang PathExists函數的具體用法?Golang PathExists怎麽用?Golang PathExists使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了PathExists函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Set

func (m *Manager) Set(container *configs.Config) error {
	for name, path := range m.Paths {
		sys, err := subsystems.Get(name)
		if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) {
			continue
		}
		if err := sys.Set(path, container.Cgroups); err != nil {
			return err
		}
	}
	return nil
}
開發者ID:DaveDaCoda,項目名稱:docker,代碼行數:12,代碼來源:apply_raw.go

示例2: Set

func (m *Manager) Set(container *configs.Config) error {
	for name, path := range m.Paths {
		sys, ok := subsystems[name]
		if !ok || !cgroups.PathExists(path) {
			continue
		}
		if err := sys.Set(path, container.Cgroups); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:waterytowers,項目名稱:global-hack-day-3,代碼行數:13,代碼來源:apply_systemd.go

示例3: Exists

// Exists checks if all subsystem cgroups already exist
func (m *cgroupManagerImpl) Exists(name CgroupName) bool {
	// Get map of all cgroup paths on the system for the particular cgroup
	cgroupPaths := m.buildCgroupPaths(name)

	// If even one cgroup path doesn't exist, then the cgroup doesn't exist.
	for _, path := range cgroupPaths {
		if !libcontainercgroups.PathExists(path) {
			return false
		}
	}

	return true
}
開發者ID:Q-Lee,項目名稱:kubernetes,代碼行數:14,代碼來源:cgroup_manager_linux.go

示例4: GetStats

func (m *Manager) GetStats() (*cgroups.Stats, error) {
	m.mu.Lock()
	defer m.mu.Unlock()
	stats := cgroups.NewStats()
	for name, path := range m.Paths {
		sys, err := subsystems.Get(name)
		if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) {
			continue
		}
		if err := sys.GetStats(path, stats); err != nil {
			return nil, err
		}
	}
	return stats, nil
}
開發者ID:xee5ch,項目名稱:binctr,代碼行數:15,代碼來源:apply_raw.go

示例5: Exists

// Exists checks if all subsystem cgroups already exist
func (m *cgroupManagerImpl) Exists(name string) bool {
	// Get map of all cgroup paths on the system for the particular cgroup
	cgroupPaths := make(map[string]string, len(m.subsystems.MountPoints))
	for key, val := range m.subsystems.MountPoints {
		cgroupPaths[key] = path.Join(val, name)
	}

	// If even one cgroup doesn't exist we go on to create it
	for _, path := range cgroupPaths {
		if !libcontainercgroups.PathExists(path) {
			return false
		}
	}
	return true
}
開發者ID:ncdc,項目名稱:kubernetes,代碼行數:16,代碼來源:cgroup_manager_linux.go

示例6: Exists

// Exists checks if all subsystem cgroups already exist
func (m *cgroupManagerImpl) Exists(name string) bool {
	// Get map of all cgroup paths on the system for the particular cgroup
	cgroupPaths := make(map[string]string, len(m.subsystems.mountPoints))
	for key, val := range m.subsystems.mountPoints {
		cgroupPaths[key] = path.Join(val, name)
	}

	// If even one cgroup doesn't exist we go on to create it
	// @TODO(dubstack) We skip check for systemd until we update
	// libcontainer in vendor
	for key, path := range cgroupPaths {
		if key != "systemd" && !libcontainercgroups.PathExists(path) {
			return false
		}
	}
	return true
}
開發者ID:apcera,項目名稱:kubernetes,代碼行數:18,代碼來源:cgroup_manager_linux.go

示例7: setKernelMemory

func setKernelMemory(path string, kernelMemoryLimit int64) error {
	if path == "" {
		return fmt.Errorf("no such directory for %s", cgroupKernelMemoryLimit)
	}
	if !cgroups.PathExists(filepath.Join(path, cgroupKernelMemoryLimit)) {
		// kernel memory is not enabled on the system so we should do nothing
		return nil
	}
	if err := ioutil.WriteFile(filepath.Join(path, cgroupKernelMemoryLimit), []byte(strconv.FormatInt(kernelMemoryLimit, 10)), 0700); err != nil {
		// Check if the error number returned by the syscall is "EBUSY"
		// The EBUSY signal is returned on attempts to write to the
		// memory.kmem.limit_in_bytes file if the cgroup has children or
		// once tasks have been attached to the cgroup
		if pathErr, ok := err.(*os.PathError); ok {
			if errNo, ok := pathErr.Err.(syscall.Errno); ok {
				if errNo == syscall.EBUSY {
					return fmt.Errorf("failed to set %s, because either tasks have already joined this cgroup or it has children", cgroupKernelMemoryLimit)
				}
			}
		}
		return fmt.Errorf("failed to write %v to %v: %v", kernelMemoryLimit, cgroupKernelMemoryLimit, err)
	}
	return nil
}
開發者ID:jbeda,項目名稱:kubernetes,代碼行數:24,代碼來源:memory.go

示例8: Apply

func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
	path, err := d.path("memory")
	if err != nil && !cgroups.IsNotFound(err) {
		return err
	}
	// reset error.
	err = nil
	if path == "" {
		// Invalid input.
		return fmt.Errorf("invalid path for memory cgroups: %+v", d)
	}
	defer func() {
		if err != nil {
			os.RemoveAll(path)
		}
	}()
	if !cgroups.PathExists(path) {
		if err = os.MkdirAll(path, 0755); err != nil {
			return err
		}
	}
	if memoryAssigned(d.config) {
		// We have to set kernel memory here, as we can't change it once
		// processes have been attached to the cgroup.
		if err = s.SetKernelMemory(path, d.config); err != nil {
			return err
		}
	}
	// We need to join memory cgroup after set memory limits, because
	// kmem.limit_in_bytes can only be set when the cgroup is empty.
	if _, jerr := d.join("memory"); jerr != nil && !cgroups.IsNotFound(jerr) {
		err = jerr
		return err
	}
	return nil
}
開發者ID:CowLeo,項目名稱:kubernetes,代碼行數:36,代碼來源:memory.go


注:本文中的github.com/opencontainers/runc/libcontainer/cgroups.PathExists函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。