Skip to content

Commit 49aba1f

Browse files
author
Muhamad Azmy
authored
Include more clean up to the storage type conversion (#811)
* Include more clean up to the storage type conversion * check opts only when needed * Try to create the rootfs on hdd, then ssd
1 parent 890ab1b commit 49aba1f

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

pkg/flist/flist.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ func (f *flistModule) mount(name, url, storage string, opts pkg.MountOptions) (s
183183
if err != nil {
184184
sublog.Info().Msgf("create new subvolume %s", name)
185185
// and only create a new one if it doesn't exist
186+
if opts.Limit == 0 || len(opts.Type) == 0 {
187+
// sanity check in case type is not set always use hdd
188+
return "", fmt.Errorf("invalid mount option, missing disk type and/or size")
189+
}
190+
186191
path, err = f.storage.CreateFilesystem(name, opts.Limit*mib, opts.Type)
187192
if err != nil {
188193
return "", errors.Wrap(err, "failed to create read-write subvolume for 0-fs")

pkg/provision/primitives/volume.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (p *Provisioner) volumeProvisionImpl(ctx context.Context, reservation *prov
4646
}, nil
4747
}
4848

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

5151
return VolumeResult{
5252
ID: reservation.ID,

pkg/provision/primitives/zdb.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,26 @@ func (p *Provisioner) createZdbContainer(ctx context.Context, allocation pkg.All
138138
hw := ifaceutil.HardwareAddrFromInputBytes([]byte(allocation.VolumeID))
139139

140140
slog.Debug().Str("flist", zdbFlistURL).Msg("mounting flist")
141-
rootFS, err := flist.Mount(zdbFlistURL, "", pkg.MountOptions{
142-
Limit: 10,
143-
ReadOnly: false,
144-
})
141+
var err error
142+
var rootFS string
143+
for _, typ := range []pkg.DeviceType{pkg.HDDDevice, pkg.SSDDevice} {
144+
rootFS, err = flist.Mount(zdbFlistURL, "", pkg.MountOptions{
145+
Limit: 10,
146+
ReadOnly: false,
147+
Type: typ,
148+
})
149+
150+
if err != nil {
151+
log.Error().Err(err).Msgf("failed to allocate rootfs for zdb container (type: '%s'): %s", typ, err)
152+
}
153+
154+
if err == nil {
155+
break
156+
}
157+
}
158+
145159
if err != nil {
146-
return err
160+
return fmt.Errorf("failed to allocate rootfs for zdb container: %s", err)
147161
}
148162

149163
cleanup := func() {

pkg/storage.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ func (e ErrNotEnoughSpace) Error() string {
3333
return fmt.Sprintf("Not enough space left in pools of this type %s", e.DeviceType)
3434
}
3535

36+
// ErrInvalidDeviceType raised when trying to allocate space on unsupported device type
37+
type ErrInvalidDeviceType struct {
38+
DeviceType DeviceType
39+
}
40+
41+
func (e ErrInvalidDeviceType) Error() string {
42+
return fmt.Sprintf("invalid device type '%s'. type unknown", e.DeviceType)
43+
}
44+
3645
// DeviceType is the actual type of hardware that the storage device runs on,
3746
// i.e. SSD or HDD
3847
type DeviceType string

pkg/storage/storage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ func (s *storageModule) ensureCache() error {
442442
func (s *storageModule) createSubvol(size uint64, name string, poolType pkg.DeviceType) (filesystem.Volume, error) {
443443
var err error
444444

445+
if poolType != pkg.HDDDevice && poolType != pkg.SSDDevice {
446+
return nil, pkg.ErrInvalidDeviceType{DeviceType: poolType}
447+
}
448+
445449
type Candidate struct {
446450
Pool filesystem.Pool
447451
Available uint64

pkg/storage/zdb.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ func (s *storageModule) Allocate(nsID string, diskType pkg.DeviceType, size uint
5757
Str("mode", string(mode)).
5858
Logger()
5959

60+
if diskType != pkg.HDDDevice && diskType != pkg.SSDDevice {
61+
return allocation, pkg.ErrInvalidDeviceType{DeviceType: diskType}
62+
}
63+
6064
log.Info().Msg("try to allocation space for 0-DB")
6165

6266
for _, pool := range s.volumes {

0 commit comments

Comments
 (0)