Skip to content

Commit

Permalink
Merge pull request topolvm#961 from topolvm/lvmd/use-0-as-free-bytes-…
Browse files Browse the repository at this point in the history
…of-thin-pool-if-usage-exceeds-total-capacity

fix: lvmd: use 0 as free bytes of thin pool if usage exceeds total capacity
  • Loading branch information
peng225 authored Sep 10, 2024
2 parents 736f451 + 4c669b9 commit 84eaed5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions internal/lvmd/lvservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"math"

"github.com/topolvm/topolvm/internal/lvmd/command"
"github.com/topolvm/topolvm/pkg/lvmd/proto"
Expand Down Expand Up @@ -79,7 +78,8 @@ func (s *lvService) CreateLV(ctx context.Context, req *proto.CreateLVRequest) (*
logger.Error(err, "failed to get free bytes")
return nil, status.Error(codes.Internal, err.Error())
}
free = uint64(math.Floor(dc.ThinPoolConfig.OverprovisionRatio*float64(tpu.SizeBytes))) - tpu.VirtualBytes
free = calcThinPoolFreeBytes(
dc.ThinPoolConfig.OverprovisionRatio, tpu.SizeBytes, tpu.VirtualBytes)
default:
// technically this block will not be hit however make sure we return error
// in such cases where deviceclass target is neither thick or thinpool
Expand Down Expand Up @@ -364,7 +364,8 @@ func (s *lvService) ResizeLV(ctx context.Context, req *proto.ResizeLVRequest) (*
logger.Error(err, "failed to get free bytes")
return nil, status.Error(codes.Internal, err.Error())
}
free = uint64(math.Floor(dc.ThinPoolConfig.OverprovisionRatio*float64(tpu.SizeBytes))) - tpu.VirtualBytes
free = calcThinPoolFreeBytes(
dc.ThinPoolConfig.OverprovisionRatio, tpu.SizeBytes, tpu.VirtualBytes)
default:
// technically this block will not be hit however make sure we return error
// in such cases where deviceclass target is neither thick or thinpool
Expand Down
11 changes: 11 additions & 0 deletions internal/lvmd/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lvmd

import "math"

func calcThinPoolFreeBytes(overProvisionRatio float64, tpuSizeBytes, tpuVirtualBytes uint64) uint64 {
virtualPoolSize := uint64(math.Floor(overProvisionRatio * float64(tpuSizeBytes)))
if virtualPoolSize <= tpuVirtualBytes {
return 0
}
return virtualPoolSize - tpuVirtualBytes
}
7 changes: 4 additions & 3 deletions internal/lvmd/vgservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"math"
"sync"

"github.com/topolvm/topolvm/internal/lvmd/command"
Expand Down Expand Up @@ -124,7 +123,8 @@ func (s *vgService) GetFreeBytes(ctx context.Context, req *proto.GetFreeBytesReq
}

// freebytes available in thinpool considering the overprovisionratio
vgFree = uint64(math.Floor(dc.ThinPoolConfig.OverprovisionRatio*float64(tpu.SizeBytes))) - tpu.VirtualBytes
vgFree = calcThinPoolFreeBytes(
dc.ThinPoolConfig.OverprovisionRatio, tpu.SizeBytes, tpu.VirtualBytes)

default:
return nil, status.Error(codes.Internal, fmt.Sprintf("unsupported device class target: %s", dc.Type))
Expand Down Expand Up @@ -187,7 +187,8 @@ func (s *vgService) send(server proto.VGService_WatchServer) error {
tpi.MetadataPercent = tpu.MetadataPercent

// used for annotating the node for capacity aware scheduling
opb := uint64(math.Floor(dc.ThinPoolConfig.OverprovisionRatio*float64(tpu.SizeBytes))) - tpu.VirtualBytes
opb := calcThinPoolFreeBytes(
dc.ThinPoolConfig.OverprovisionRatio, tpu.SizeBytes, tpu.VirtualBytes)
tpi.OverprovisionBytes = opb
if dc.Default {
res.FreeBytes = opb
Expand Down

0 comments on commit 84eaed5

Please sign in to comment.