Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/flist/flist.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ func (f *flistModule) mount(name, url, storage string, opts pkg.MountOptions) (s
if err != nil {
sublog.Info().Msgf("create new subvolume %s", name)
// and only create a new one if it doesn't exist
if opts.Limit == 0 || len(opts.Type) == 0 {
// sanity check in case type is not set always use hdd
return "", fmt.Errorf("invalid mount option, missing disk type and/or size")
}

path, err = f.storage.CreateFilesystem(name, opts.Limit*mib, opts.Type)
if err != nil {
return "", errors.Wrap(err, "failed to create read-write subvolume for 0-fs")
Expand Down
2 changes: 1 addition & 1 deletion pkg/provision/primitives/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (p *Provisioner) volumeProvisionImpl(ctx context.Context, reservation *prov
}, nil
}

_, err = storageClient.CreateFilesystem(reservation.ID, config.Size*gigabyte, pkg.DeviceType(config.Type))
_, err = storageClient.CreateFilesystem(reservation.ID, config.Size*gigabyte, config.Type)

return VolumeResult{
ID: reservation.ID,
Expand Down
24 changes: 19 additions & 5 deletions pkg/provision/primitives/zdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,26 @@ func (p *Provisioner) createZdbContainer(ctx context.Context, allocation pkg.All
hw := ifaceutil.HardwareAddrFromInputBytes([]byte(allocation.VolumeID))

slog.Debug().Str("flist", zdbFlistURL).Msg("mounting flist")
rootFS, err := flist.Mount(zdbFlistURL, "", pkg.MountOptions{
Limit: 10,
ReadOnly: false,
})
var err error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

var rootFS string
for _, typ := range []pkg.DeviceType{pkg.HDDDevice, pkg.SSDDevice} {
rootFS, err = flist.Mount(zdbFlistURL, "", pkg.MountOptions{
Limit: 10,
ReadOnly: false,
Type: typ,
})

if err != nil {
log.Error().Err(err).Msgf("failed to allocate rootfs for zdb container (type: '%s'): %s", typ, err)
}

if err == nil {
break
}
}

if err != nil {
return err
return fmt.Errorf("failed to allocate rootfs for zdb container: %s", err)
}

cleanup := func() {
Expand Down
9 changes: 9 additions & 0 deletions pkg/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ func (e ErrNotEnoughSpace) Error() string {
return fmt.Sprintf("Not enough space left in pools of this type %s", e.DeviceType)
}

// ErrInvalidDeviceType raised when trying to allocate space on unsupported device type
type ErrInvalidDeviceType struct {
DeviceType DeviceType
}

func (e ErrInvalidDeviceType) Error() string {
return fmt.Sprintf("invalid device type '%s'. type unknown", e.DeviceType)
}

// DeviceType is the actual type of hardware that the storage device runs on,
// i.e. SSD or HDD
type DeviceType string
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ func (s *storageModule) ensureCache() error {
func (s *storageModule) createSubvol(size uint64, name string, poolType pkg.DeviceType) (filesystem.Volume, error) {
var err error

if poolType != pkg.HDDDevice && poolType != pkg.SSDDevice {
return nil, pkg.ErrInvalidDeviceType{DeviceType: poolType}
}

type Candidate struct {
Pool filesystem.Pool
Available uint64
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/zdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (s *storageModule) Allocate(nsID string, diskType pkg.DeviceType, size uint
Str("mode", string(mode)).
Logger()

if diskType != pkg.HDDDevice && diskType != pkg.SSDDevice {
return allocation, pkg.ErrInvalidDeviceType{DeviceType: diskType}
}

log.Info().Msg("try to allocation space for 0-DB")

for _, pool := range s.volumes {
Expand Down