Exemplo 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
}
Exemplo n.º 2
0
Arquivo: pod.go Projeto: m1911/hyper
func (p *Pod) PrepareVolume(daemon *Daemon, sd Storage) (err error) {
	err = nil
	p.volumes = []*hypervisor.VolumeInfo{}

	var (
		sharedDir = path.Join(hypervisor.BaseDir, p.vm.Id, hypervisor.ShareDirTag)
	)

	for _, v := range p.spec.Volumes {
		var vol *hypervisor.VolumeInfo
		if v.Source == "" {
			vol, err = sd.CreateVolume(daemon, p.id, v.Name)
			if err != nil {
				return
			}

			v.Source = vol.Filepath
			if sd.Type() != "devicemapper" {
				v.Driver = "vfs"

				vol.Filepath, err = storage.MountVFSVolume(v.Source, sharedDir)
				if err != nil {
					return
				}
				glog.V(1).Infof("dir %s is bound to %s", v.Source, vol.Filepath)

			} else { // type other than doesn't need to be mounted
				v.Driver = "raw"
			}
		} else {
			vol, err = ProbeExistingVolume(&v, sharedDir)
			if err != nil {
				return
			}
		}

		p.volumes = append(p.volumes, vol)
	}

	return nil
}