示例#1
0
func (v *volumeDriver) Create(
	volumeLocator *api.VolumeLocator,
	source *api.Source,
	spec *api.VolumeSpec,
) (string, error) {
	volumeID := strings.TrimSpace(string(uuid.New()))
	dirPath := filepath.Join(v.baseDirPath, volumeID)
	if err := os.MkdirAll(dirPath, 0777); err != nil {
		return "", err
	}
	volume := common.NewVolume(
		volumeID,
		api.FSType_FS_TYPE_FUSE,
		volumeLocator,
		source,
		spec,
	)
	volume.DevicePath = dirPath
	if err := v.CreateVol(volume); err != nil {
		return "", err
	}
	if err := v.UpdateVol(volume); err != nil {
		return "", err
	}
	return volume.Id, nil
}
示例#2
0
// Create a new subvolume. The volume spec is not taken into account.
func (d *driver) Create(
	locator *api.VolumeLocator,
	source *api.Source,
	spec *api.VolumeSpec,
) (string, error) {
	if spec.Format != api.FSType_FS_TYPE_BTRFS && spec.Format != api.FSType_FS_TYPE_NONE {
		return "", fmt.Errorf("Filesystem format (%v) must be %v", spec.Format.SimpleString(), api.FSType_FS_TYPE_BTRFS.SimpleString())
	}
	volume := common.NewVolume(
		uuid.New(),
		api.FSType_FS_TYPE_BTRFS,
		locator,
		source,
		spec,
	)
	if err := d.CreateVol(volume); err != nil {
		return "", err
	}
	if err := d.btrfs.Create(volume.Id, "", ""); err != nil {
		return "", err
	}
	devicePath, err := d.btrfs.Get(volume.Id, "")
	if err != nil {
		return volume.Id, err
	}
	volume.DevicePath = devicePath
	err = d.UpdateVol(volume)
	return volume.Id, err
}
示例#3
0
func (d *driver) Create(
	locator *api.VolumeLocator,
	source *api.Source,
	spec *api.VolumeSpec) (string, error) {

	volumeID := uuid.New()
	volumeID = strings.TrimSuffix(volumeID, "\n")

	// Create a directory on the NFS server with this UUID.
	volPath := path.Join(nfsMountPath, volumeID)
	err := os.MkdirAll(volPath, 0744)
	if err != nil {
		dlog.Println(err)
		return "", err
	}
	if source != nil {
		if len(source.Seed) != 0 {
			seed, err := seed.New(source.Seed, spec.VolumeLabels)
			if err != nil {
				dlog.Warnf("Failed to initailize seed from %q : %v",
					source.Seed, err)
				return "", err
			}
			err = seed.Load(path.Join(volPath, config.DataDir))
			if err != nil {
				dlog.Warnf("Failed to  seed from %q to %q: %v",
					source.Seed, nfsMountPath, err)
				return "", err
			}
		}
	}

	f, err := os.Create(path.Join(nfsMountPath, volumeID+nfsBlockFile))
	if err != nil {
		dlog.Println(err)
		return "", err
	}
	defer f.Close()

	if err := f.Truncate(int64(spec.Size)); err != nil {
		dlog.Println(err)
		return "", err
	}

	v := common.NewVolume(
		volumeID,
		api.FSType_FS_TYPE_NFS,
		locator,
		source,
		spec,
	)
	v.DevicePath = path.Join(nfsMountPath, volumeID+nfsBlockFile)

	if err := d.CreateVol(v); err != nil {
		return "", err
	}
	return v.Id, err
}
示例#4
0
// Create aws volume from spec.
func (d *Driver) Create(
	locator *api.VolumeLocator,
	source *api.Source,
	spec *api.VolumeSpec,
) (string, error) {
	var snapID *string
	// Spec size is in bytes, translate to GiB.
	sz := int64(spec.Size / (1024 * 1024 * 1024))
	iops, volType := mapCos(spec.Cos)
	if source != nil && string(source.Parent) != "" {
		id := string(source.Parent)
		snapID = &id
	}
	dryRun := false
	encrypted := false
	req := &ec2.CreateVolumeInput{
		AvailabilityZone: &d.md.zone,
		DryRun:           &dryRun,
		Encrypted:        &encrypted,
		Size:             &sz,
		Iops:             iops,
		VolumeType:       volType,
		SnapshotId:       snapID,
	}
	vol, err := d.ec2.CreateVolume(req)
	if err != nil {
		dlog.Warnf("Failed in CreateVolumeRequest :%v", err)
		return "", err
	}
	volume := common.NewVolume(
		*vol.VolumeId,
		api.FSType_FS_TYPE_NONE,
		locator,
		source,
		spec,
	)
	err = d.UpdateVol(volume)
	if err != nil {
		return "", err
	}
	err = d.waitStatus(volume.Id, ec2.VolumeStateAvailable)
	return volume.Id, err
}
示例#5
0
func (d *driver) Create(locator *api.VolumeLocator, source *api.Source, spec *api.VolumeSpec) (string, error) {
	volumeID := uuid.New()
	volumeID = strings.TrimSuffix(volumeID, "\n")
	// Create a directory on the Local machine with this UUID.
	if err := os.MkdirAll(filepath.Join(config.VolumeBase, string(volumeID)), 0744); err != nil {
		dlog.Println(err)
		return "", err
	}

	v := common.NewVolume(
		volumeID,
		api.FSType_FS_TYPE_VFS,
		locator,
		source,
		spec,
	)
	v.DevicePath = filepath.Join(config.VolumeBase, volumeID)

	if err := d.CreateVol(v); err != nil {
		return "", err
	}
	return v.Id, d.UpdateVol(v)
}
示例#6
0
func (d *driver) Create(locator *api.VolumeLocator, source *api.Source, spec *api.VolumeSpec) (string, error) {
	volumeID := uuid.New()
	volumeID = strings.TrimSuffix(volumeID, "\n")
	if spec.Size == 0 {
		return "", fmt.Errorf("Volume size cannot be zero", "buse")
	}
	if spec.Format == api.FSType_FS_TYPE_NONE {
		return "", fmt.Errorf("Missing volume format", "buse")
	}
	// Create a file on the local buse path with this UUID.
	buseFile := path.Join(BuseMountPath, volumeID)
	f, err := os.Create(buseFile)
	if err != nil {
		dlog.Println(err)
		return "", err
	}

	if err := f.Truncate(int64(spec.Size)); err != nil {
		dlog.Println(err)
		return "", err
	}

	bd := &buseDev{
		file: buseFile,
		f:    f,
	}
	nbd := Create(bd, int64(spec.Size))
	bd.nbd = nbd

	dlog.Infof("Connecting to NBD...")
	dev, err := bd.nbd.Connect()
	if err != nil {
		dlog.Println(err)
		return "", err
	}

	dlog.Infof("Formatting %s with %v", dev, spec.Format)
	cmd := "/sbin/mkfs." + spec.Format.SimpleString()
	o, err := exec.Command(cmd, dev).Output()
	if err != nil {
		dlog.Warnf("Failed to run command %v %v: %v", cmd, dev, o)
		return "", err
	}

	dlog.Infof("BUSE mapped NBD device %s (size=%v) to block file %s", dev, spec.Size, buseFile)

	v := common.NewVolume(
		volumeID,
		spec.Format,
		locator,
		source,
		spec,
	)
	v.DevicePath = dev

	d.buseDevices[dev] = bd

	err = d.CreateVol(v)
	if err != nil {
		return "", err
	}
	return v.Id, err
}
示例#7
0
func (d *driver) Create(
	locator *api.VolumeLocator,
	source *api.Source,
	spec *api.VolumeSpec) (string, error) {

	var err error

	project := d.project
	varray := d.varray
	vpool := d.vpool
	initiator := d.initiator

	if name, ok := locator.VolumeLabels["project"]; ok {
		project, err = d.client.Project().
			Name(name).
			Query()
		if err != nil {
			return "", err
		}
	}
	if project == nil {
		return "", ErrProjectRequired
	}

	if name, ok := locator.VolumeLabels["varray"]; ok {
		varray, err = d.client.VArray().
			Name(name).
			Query()
		if err != nil {
			return "", err
		}
	}
	if varray == nil {
		return "", ErrArrayRequired
	}

	if name, ok := locator.VolumeLabels["vpool"]; ok {
		vpool, err = d.client.VPool().
			Name(name).
			Query()
		if err != nil {
			return "", err
		}
	}
	if vpool == nil {
		return "", ErrPoolRequired
	}

	if !vpool.IsBlock() {
		return "", ErrInvalidPool
	}

	// make sure this pool supports the initiator protocol
	if !vpool.HasProtocol(initiator.Protocol) {
		return "", ErrInvalidPort
	}

	sz := spec.Size
	if sz < minVolumeSize {
		sz = minVolumeSize
	}

	vol, err := d.client.Volume().
		Name(locator.Name).
		Project(project.Id).
		Array(varray.Id).
		Pool(vpool.Id).
		Create(sz)
	if err != nil {
		return "", err
	}

	volumeID := strings.ToLower(vol.WWN)

	dlog.Infof("coprhd volume %s created", volumeID)

	volume := common.NewVolume(
		volumeID,
		api.FSType_FS_TYPE_EXT4,
		locator,
		source,
		spec)

	if err := d.UpdateVol(volume); err != nil {
		return "", err
	}

	if _, err := d.Attach(volumeID); err != nil {
		return "", err
	}

	dlog.Infof("coprhd preparing volume %s...", volumeID)

	if err := d.Format(volumeID); err != nil {
		return "", err
	}

	if err := d.Detach(volumeID); err != nil {
		return "", err
	}

	return volumeID, nil
}