本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount.Interface.List方法的典型用法代碼示例。如果您正苦於以下問題:Golang Interface.List方法的具體用法?Golang Interface.List怎麽用?Golang Interface.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount.Interface
的用法示例。
在下文中一共展示了Interface.List方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例2: 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
}