• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang mount.Interface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount.Interface的典型用法代码示例。如果您正苦于以下问题:Golang Interface类的具体用法?Golang Interface怎么用?Golang Interface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Interface类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: getMountRefCount

// Examines /proc/mounts to find the source device of the PD resource and the
// number of references to that device. Returns both the full device path under
// the /dev tree and the number of references.
func getMountRefCount(mounter mount.Interface, mountPath string) (string, int, error) {
	// TODO(jonesdl) This can be split up into two procedures, finding the device path
	// and finding the number of references. The parsing could also be separated and another
	// utility could determine if a path is an active mount point.

	mps, err := mounter.List()
	if err != nil {
		return "", -1, err
	}

	// Find the device name.
	deviceName := ""
	for i := range mps {
		if mps[i].Path == mountPath {
			deviceName = mps[i].Device
			break
		}
	}

	// Find the number of references to the device.
	refCount := 0
	for i := range mps {
		if mps[i].Device == deviceName {
			refCount++
		}
	}
	return deviceName, refCount, nil
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:31,代码来源:mount_util.go


示例2: diskSetUp

// utility to mount a disk based filesystem
func diskSetUp(manager diskManager, disk rbd, volPath string, mounter mount.Interface) error {
	globalPDPath := manager.MakeGlobalPDName(disk)
	// TODO: handle failed mounts here.
	mountpoint, err := mounter.IsMountPoint(volPath)

	if err != nil && !os.IsNotExist(err) {
		glog.Errorf("cannot validate mountpoint: %s", volPath)
		return err
	}
	if mountpoint {
		return nil
	}
	if err := manager.AttachDisk(disk); 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 disk.readOnly {
		options = append(options, "ro")
	}
	err = mounter.Mount(globalPDPath, volPath, "", options)
	if err != nil {
		glog.Errorf("failed to bind mount:%s", globalPDPath)
		return err
	}
	return nil
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:34,代码来源:disk_manager.go


示例3: diskSetUp

// utility to mount a disk based filesystem
func diskSetUp(manager diskManager, disk iscsiDisk, volPath string, mounter mount.Interface) error {
	globalPDPath := manager.MakeGlobalPDName(disk)
	// TODO: handle failed mounts here.
	mountpoint, err := mounter.IsMountPoint(volPath)

	if err != nil && !os.IsNotExist(err) {
		glog.Errorf("cannot validate mountpoint: %s", volPath)
		return err
	}
	if mountpoint {
		return nil
	}
	if err := manager.AttachDisk(disk); 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.
	flags := uintptr(0)
	if disk.readOnly {
		flags = mount.FlagReadOnly
	}
	err = mounter.Mount(globalPDPath, volPath, "", mount.FlagBind|flags, "")
	if err != nil {
		glog.Errorf("failed to bind mount:%s", globalPDPath)
		return err
	}
	return nil
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:34,代码来源:disk_manager.go


示例4: getDevicePrefixRefCount

// getDevicePrefixRefCount: given a prefix of device path, find its reference count from /proc/mounts
// returns the reference count to the device and error code
// for services like iscsi construct multiple device paths with the same prefix pattern.
// this function aggregates all references to a service based on the prefix pattern
// More specifically, this prefix semantics is to aggregate disk paths that belong to the same iSCSI target/iqn pair.
// an iSCSI target could expose multiple LUNs through the same IQN, and Linux iSCSI initiator creates disk paths that start the same prefix but end with different LUN number
// When we decide whether it is time to logout a target, we have to see if none of the LUNs are used any more.
// That's where the prefix based ref count kicks in. If we only count the disks using exact match, we could log other disks out.
func getDevicePrefixRefCount(mounter mount.Interface, deviceNamePrefix string) (int, error) {
	mps, err := mounter.List()
	if err != nil {
		return -1, err
	}

	// Find the number of references to the device.
	refCount := 0
	for i := range mps {
		if strings.HasPrefix(mps[i].Device, deviceNamePrefix) {
			refCount++
		}
	}
	return refCount, nil
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:23,代码来源:iscsi_util.go


示例5: diskTearDown

// utility to tear down a disk based filesystem
func diskTearDown(manager diskManager, disk rbd, volPath string, mounter mount.Interface) error {
	mountpoint, err := mounter.IsMountPoint(volPath)
	if err != nil {
		glog.Errorf("cannot validate mountpoint %s", volPath)
		return err
	}
	if !mountpoint {
		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 umount %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(disk, mntPath); err != nil {
			glog.Errorf("failed to detach disk from %s", mntPath)
			return err
		}
	}

	mountpoint, mntErr := mounter.IsMountPoint(volPath)
	if mntErr != nil {
		glog.Errorf("isMountpoint check failed: %v", mntErr)
		return err
	}
	if !mountpoint {
		if err := os.Remove(volPath); err != nil {
			return err
		}
	}
	return nil

}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:43,代码来源:disk_manager.go



注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount.Interface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang node.GetHostname函数代码示例发布时间:2022-05-23
下一篇:
Golang mount.FakeMounter类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap