Esempio n. 1
0
File: disk.go Progetto: hyperhq/runv
func NewDiskContext(ctx *VmContext, vol *api.VolumeDescription) *DiskContext {
	dc := &DiskContext{
		DiskDescriptor: &DiskDescriptor{
			Name:         vol.Name,
			Filename:     vol.Source,
			Format:       vol.Format,
			Fstype:       vol.Fstype,
			DockerVolume: vol.DockerVolume,
		},
		sandbox:   ctx,
		observers: make(map[string]*sync.WaitGroup),
		lock:      &sync.RWMutex{},
	}
	if vol.IsDir() {
		dc.ready = true
	} else if vol.Format == "rbd" {
		dc.Options = map[string]string{
			"user":        vol.Options.User,
			"keyring":     vol.Options.Keyring,
			"monitors":    strings.Join(vol.Options.Monitors, ";"),
			"bytespersec": strconv.Itoa(int(vol.Options.BytesPerSec)),
			"iops":        strconv.Itoa(int(vol.Options.Iops)),
		}
	}
	return dc
}
Esempio n. 2
0
func (ctx *VmContext) AddVolume(vol *api.VolumeDescription, result chan api.Result) {
	ctx.lock.Lock()
	defer ctx.lock.Unlock()

	if _, ok := ctx.volumes[vol.Name]; ok {
		estr := fmt.Sprintf("duplicate volume %s", vol.Name)
		ctx.Log(WARNING, estr)
		result <- api.NewResultBase(vol.Name, true, estr)
		return
	}

	dc := NewDiskContext(ctx, vol)

	if vol.IsDir() {
		ctx.Log(INFO, "return volume add success for dir %s", vol.Name)
		result <- api.NewResultBase(vol.Name, true, "")
	} else {
		ctx.Log(DEBUG, "insert disk for volume %s", vol.Name)
		dc.insert(result)
	}

	ctx.volumes[vol.Name] = dc
}