Esempio n. 1
0
func ProbeExistingVolume(v *pod.UserVolume, sharedDir string) (*hypervisor.VolumeInfo, error) {
	if v == nil || v.Source == "" { //do not create volume in this function, it depends on storage driver.
		return nil, fmt.Errorf("can not generate volume info from %v", v)
	}

	var err error = nil
	vol := &hypervisor.VolumeInfo{
		Name: v.Name,
	}

	if v.Driver == "vfs" {
		vol.Fstype = "dir"
		vol.Filepath, err = storage.MountVFSVolume(v.Source, sharedDir)
		if err != nil {
			return nil, err
		}
		glog.V(1).Infof("dir %s is bound to %s", v.Source, vol.Filepath)
	} else {
		vol.Fstype, err = dm.ProbeFsType(v.Source)
		if err != nil {
			vol.Fstype = DEFAULT_VOL_FS //FIXME: for qcow2, the ProbeFsType doesn't work, should be fix later
		}
		vol.Format = v.Driver
		vol.Filepath = v.Source
	}

	return vol, nil
}
Esempio n. 2
0
func ProbeExistingVolume(v *apitypes.UserVolume, sharedDir string) (*runv.VolumeDescription, error) {
	if v == nil || v.Source == "" { //do not create volume in this function, it depends on storage driver.
		return nil, fmt.Errorf("can not generate volume info from %v", v)
	}

	var err error = nil
	vol := &runv.VolumeDescription{
		Name:   v.Name,
		Source: v.Source,
		Format: v.Format,
		Fstype: v.Fstype,
	}

	if v.Option != nil {
		vol.Options = &runv.VolumeOption{
			User:     v.Option.User,
			Monitors: v.Option.Monitors,
			Keyring:  v.Option.Keyring,
		}
	}

	if v.Format == "vfs" {
		vol.Fstype = "dir"
		vol.Source, err = storage.MountVFSVolume(v.Source, sharedDir)
		if err != nil {
			return nil, err
		}
		hlog.Log(DEBUG, "dir %s is bound to %s", v.Source, vol.Source)
	} else if v.Format == "raw" && v.Fstype == "" {
		vol.Fstype, err = dm.ProbeFsType(v.Source)
		if err != nil {
			vol.Fstype = storage.DEFAULT_VOL_FS
			err = nil
		}
	}

	return vol, nil
}