// Check the tenant mount and dfs export to verify that they're pointing to the
// same device.
506468
func (f *Facade) verifyTenantMounts(ctx datastore.Context, svc *service.Service) error {
	logger := plog.WithFields(log.Fields{
		"service": svc.Name,
		"id":      svc.ID,
	})

	// If the pool doesn't have dfs access, we can go ahead and start the service regardless
	// of what condition the mount points are in.
	pool, err := f.GetResourcePool(ctx, svc.PoolID)
	if err != nil {
		logger.WithField("poolid", svc.PoolID).WithError(err).Error("Error looking up pool")
		return err
	}
	if !pool.HasDfsAccess() {
		return nil
	}

	tenantID, err := f.GetTenantID(ctx, svc.ID)
	if err != nil {
		return err
	}

	logger = logger.WithField("tenantid", tenantID)
	if err := f.dfs.VerifyTenantMounts(tenantID); err != nil {
		return err
	}

	return nil
}
958367
func (dfs *DistributedFilesystem) restoreSnapshot(tenant, label string, r io.Reader) error {
	tenantLogger := plog.WithField("tenant", tenant)

	vol, err := dfs.disk.Create(tenant)
	if err == volume.ErrVolumeExists {
		if vol, err = dfs.disk.Get(tenant); err != nil {
			tenantLogger.WithError(err).Error("Could not get volume for tenant")
			return err
		}
	} else if err != nil {
		tenantLogger.WithError(err).Error("Could not create volume for tenant")
		return err
	} else {
		defer func() {
			if err != nil {
				dfs.disk.Remove(tenant)
			}
		}()
	}

	err = vol.Import(label, r)
	if err == volume.ErrSnapshotExists {
		err = nil // volume.ErrSnapshotExists is an error we can ignore
	} else if err != nil {
		tenantLogger.WithError(err).WithField("label", label).
			Error("Could not import snapshot for tenant")
		return err
	}

	return nil
}
784867
func checkCrossDeviceMounts(endpoints EndpointList) (err error) {
	var absPaths []string
	for _, endpoint := range endpoints {
		if endpoint.IsLocal {
			var absPath string
			absPath, err = filepath.Abs(endpoint.Path)
			if err != nil {
				return err
			}
			absPaths = append(absPaths, absPath)
		}
	}
	return mountinfo.CheckCrossDevice(absPaths)
}
279468
func mounted(mountpoint string) (bool, error) {
	entries, err := parseMountTable()
	if err != nil {
		return false, err
	}

	// Search the table for the mountpoint
	for _, e := range entries {
		if e.MountPoint == mountpoint {
			return true, nil
		}
	}
	return false, nil
}
1048774
func isremount(device string, flags uintptr) bool {
	switch {
	// We treat device "" and "none" as a remount request to provide compatibility with
	// requests that don't explicitly set MS_REMOUNT such as those manipulating bind mounts.
	case flags&unix.MS_REMOUNT != 0, device == "", device == "none":
		return true
	default:
		return false
	}
}
739272
func CheckMissingMountedSecrets(g osgraph.Graph, podSpecNode *kubegraph.PodSpecNode) []*kubegraph.SecretNode {
	missingSecrets := []*kubegraph.SecretNode{}

	for _, uncastMountedSecretNode := range g.SuccessorNodesByNodeAndEdgeKind(podSpecNode, kubegraph.SecretNodeKind, kubeedges.MountedSecretEdgeKind) {
		mountedSecretNode := uncastMountedSecretNode.(*kubegraph.SecretNode)
		if !mountedSecretNode.Found() {
			missingSecrets = append(missingSecrets, mountedSecretNode)
		}
	}

	return missingSecrets
}
971570
func isExistingDirectory(point *copyEndpoint) (bool, error) {
	destStat, err := point.driver.Stat(point.path)
	switch {
	case os.IsNotExist(err):
		return false, nil
	case err != nil:
		return false, err
	}
	return destStat.IsDir(), nil
}
315596
func verifyDstPathSafe(dst string) error {
	if _, err := os.Stat(dst); !os.IsNotExist(err) {
		return errors.Wrapf(err, "destination path %s already exists", dst)
	}
	if _, err := os.Stat(path.Dir(dst)); os.IsNotExist(err) {
		return errors.Wrapf(err, "parent directory of destination path %s does not exist", dst)
	}
	return nil
}
300118
func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
	mounter := attacher.host.GetMounter(cinderVolumePluginName)
	notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
	if err != nil {
		if os.IsNotExist(err) {
			if err := os.MkdirAll(deviceMountPath, 0750); err != nil {
				return err
			}
			notMnt = true
		} else {
			return err
		}
	}

	_, volumeFSType, readOnly, err := getVolumeInfo(spec)
	if err != nil {
		return err
	}

	options := []string{}
	if readOnly {
		options = append(options, "ro")
	}
	if notMnt {
		diskMounter := volumeutil.NewSafeFormatAndMountFromHost(cinderVolumePluginName, attacher.host)
		mountOptions := volumeutil.MountOptionFromSpec(spec, options...)
		err = diskMounter.FormatAndMount(devicePath, deviceMountPath, volumeFSType, mountOptions)
		if err != nil {
			os.Remove(deviceMountPath)
			return err
		}
	}
	return nil
}
1301317
func (dfs *DistributedFilesystem) findImage(image, tenantID string) (string, error) {
	// Is the image in the index?
	rImage, err := dfs.index.FindImage(image)
	if err != nil {
		if err == index.ErrImageNotFound {
			return "", nil
		}
		glog.Errorf("Could not look up image %s from the registry: %s", image, err)
		return "", err
	}
	// Is this image latest under the same tenant?
	if rImage.Library == tenantID && rImage.Tag == docker.Latest {
		return rImage.String(), nil
	}
	return "", nil
}
893309
func (mount *MountInfo) IsMounted() bool {
	ret := C.ceph_is_mounted(mount.mount)
	return ret == 1
}
567261
func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
	stat, err := os.Lstat(file)
	if err != nil {
		return true, err
	}
	// If current file is a symlink, then it is a mountpoint.
	if stat.Mode()&os.ModeSymlink != 0 {
		target, err := os.Readlink(file)
		if err != nil {
			return true, fmt.Errorf("readlink error: %v", err)
		}
		exists, err := mounter.ExistsPath(target)
		if err != nil {
			return true, err
		}
		return !exists, nil
	}

	return true, nil
}
1219906
func MountContainerToSharedDir(containerId, sharedDir, devPrefix string) (string, error) {
	devFullName := fmt.Sprintf("%s/vbox/images/%s.vdi", utils.HYPER_ROOT, containerId)
	return devFullName, nil
}
1150604
func IsMountFS(mntType string, mapRoot string) (bool, bool, error) {
	mountInfos, err := GetMountInfo()
	if err != nil {
		return false, false, err
	}

	mounted, mntTypeInstance := isMountFS(mountInfos, mntType, mapRoot)
	return mounted, mntTypeInstance, nil
}
17555
func (container *Container) HasMountFor(path string) bool {
	_, exists := container.MountPoints[path]
	if exists {
		return true
	}

	// Also search among the tmpfs mounts
	for dest := range container.HostConfig.Tmpfs {
		if dest == path {
			return true
		}
	}

	return false
}
791263
func (p *cadvisorStatsProvider) ImageFsDevice() (string, error) {
	imageFsInfo, err := p.cadvisor.ImagesFsInfo()
	if err != nil {
		return "", err
	}
	return imageFsInfo.Device, nil
}
723707
func (c *containerAdapter) checkMounts() error {
	spec := c.container.spec()
	for _, mount := range spec.Mounts {
		switch mount.Type {
		case api.MountTypeBind:
			if _, err := os.Stat(mount.Source); os.IsNotExist(err) {
				return fmt.Errorf("invalid bind mount source, source path not found: %s", mount.Source)
			}
		}
	}

	return nil
}