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 }
func (dms *DevMapperStorage) PrepareContainer(ci *Container, sharedDir string) error { if err := dm.CreateNewDevice(ci.mountID, dms.DevPrefix, dms.RootPath()); err != nil { return err } devFullName, err := dm.MountContainerToSharedDir(ci.mountID, sharedDir, dms.DevPrefix) if err != nil { glog.Error("got error when mount container to share dir ", err.Error()) return err } fstype, err := dm.ProbeFsType(devFullName) if err != nil { fstype = "ext4" } ci.rootfs = "/rootfs" ci.fstype = fstype ci.ApiContainer.Image = devFullName return nil }
func (dms *DevMapperStorage) CreateVolume(daemon *Daemon, podId, shortName string) (*hypervisor.VolumeInfo, error) { volName := fmt.Sprintf("%s-%s-%s", dms.VolPoolName, podId, shortName) dev_id, _ := daemon.GetVolumeId(podId, volName) glog.Infof("DeviceID is %d", dev_id) restore := dev_id > 0 for { if !restore { dev_id = dms.randDevId() } dev_id_str := strconv.Itoa(dev_id) err := dm.CreateVolume(dms.VolPoolName, volName, dev_id_str, DEFAULT_DM_VOL_SIZE, restore) if err != nil && !restore && strings.Contains(err.Error(), "failed: File exists") { glog.V(1).Infof("retry for dev_id #%d creating collision: %v", dev_id, err) continue } else if err != nil { glog.V(1).Infof("failed to create dev_id #%d: %v", dev_id, err) return nil, err } glog.V(3).Infof("device (%d) created (restore:%v) for %s: %s", dev_id, restore, podId, volName) daemon.db.UpdatePodVolume(podId, volName, []byte(fmt.Sprintf("%s:%s", volName, dev_id_str))) break } fstype, err := dm.ProbeFsType("/dev/mapper/" + volName) if err != nil { fstype = "ext4" } glog.V(1).Infof("volume %s created with dm as %s", shortName, volName) return &hypervisor.VolumeInfo{ Name: shortName, Filepath: path.Join("/dev/mapper/", volName), Fstype: fstype, Format: "raw", }, nil }
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 }