lxd/storage_btrfs.go
func (s *storageBtrfs) StoragePoolVolumeCreate() error {
	logger.Infof("Creating BTRFS storage volume \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)

	_, err := s.StoragePoolMount()
	if err != nil {
		return err
	}

	isSnapshot := shared.IsSnapshot(s.volume.Name)

	// Create subvolume path on the storage pool.
	var customSubvolumePath string

	if isSnapshot {
		customSubvolumePath = s.getCustomSnapshotSubvolumePath(s.pool.Name)
	} else {
		customSubvolumePath = s.getCustomSubvolumePath(s.pool.Name)
	}

	if !shared.PathExists(customSubvolumePath) {
		err := os.MkdirAll(customSubvolumePath, 0700)
		if err != nil {
			return err
		}
	}

	// Create subvolume.
	var customSubvolumeName string

	if isSnapshot {
		customSubvolumeName = getStoragePoolVolumeSnapshotMountPoint(s.pool.Name, s.volume.Name)
	} else {
		customSubvolumeName = getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
	}

	err = btrfsSubVolumeCreate(customSubvolumeName)
	if err != nil {
		return err
	}

	// apply quota
	if s.volume.Config["size"] != "" {
		size, err := shared.ParseByteSizeString(s.volume.Config["size"])
		if err != nil {
			return err
		}

		err = s.StorageEntitySetQuota(storagePoolVolumeTypeCustom, size, nil)
		if err != nil {
			return err
		}
	}

	logger.Infof("Created BTRFS storage volume \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
	return nil
}
func (s *storageBtrfs) StoragePoolVolumeCreate() error {
	logger.Infof("Creating BTRFS storage volume \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)

	_, err := s.StoragePoolMount()
	if err != nil {
		return err
	}

	isSnapshot := shared.IsSnapshot(s.volume.Name)

	// Create subvolume path on the storage pool.
	var customSubvolumePath string

	if isSnapshot {
		customSubvolumePath = s.getCustomSnapshotSubvolumePath(s.pool.Name)
	} else {
		customSubvolumePath = s.getCustomSubvolumePath(s.pool.Name)
	}

	if !shared.PathExists(customSubvolumePath) {
		err := os.MkdirAll(customSubvolumePath, 0700)
		if err != nil {
			return err
		}
	}

	// Create subvolume.
	var customSubvolumeName string

	if isSnapshot {
		customSubvolumeName = getStoragePoolVolumeSnapshotMountPoint(s.pool.Name, s.volume.Name)
	} else {
		customSubvolumeName = getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
	}

	err = btrfsSubVolumeCreate(customSubvolumeName)
	if err != nil {
		return err
	}

	// apply quota
	if s.volume.Config["size"] != "" {
		size, err := shared.ParseByteSizeString(s.volume.Config["size"])
		if err != nil {
			return err
		}

		err = s.StorageEntitySetQuota(storagePoolVolumeTypeCustom, size, nil)
		if err != nil {
			return err
		}
	}

	logger.Infof("Created BTRFS storage volume \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
	return nil
}
// Functions dealing with storage volumes.