func (daemon *Daemon) CreateVolume(podId, volName, dev_id string, restore bool) error { err := dm.CreateVolume(daemon.Storage.DmPoolData.PoolName, volName, dev_id, 2*1024*1024*1024, restore) if err != nil { return err } daemon.SetVolumeId(podId, volName, dev_id) 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.SetVolumeId(podId, 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 }