Skip to content

Commit

Permalink
Merge pull request topolvm#962 from topolvm/lvmd/handle-too-small-thi…
Browse files Browse the repository at this point in the history
…n-pool

change: lvmd: make sure enough free space is available when creating LV snapshot
  • Loading branch information
pluser authored Sep 12, 2024
2 parents 84eaed5 + 2656bf2 commit f6329ce
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/lvmd/lvservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ func (s *lvService) CreateLVSnapshot(ctx context.Context, req *proto.CreateLVSna
return nil, status.Errorf(codes.OutOfRange, "requested size %v is smaller than source logical volume: %v", desiredSize, sizeOnCreation)
}

pool, err := vg.FindPool(ctx, dc.ThinPoolConfig.Name)
if err != nil {
logger.Error(err, "failed to get thinpool")
return nil, status.Error(codes.Internal, err.Error())
}
tpu, err := pool.Free(ctx)
free := calcThinPoolFreeBytes(dc.ThinPoolConfig.OverprovisionRatio, tpu.SizeBytes, tpu.VirtualBytes)
if free < desiredSize {
logger.Error(err, "not enough space left on VG", "free", free, "desiredSize", desiredSize)
return nil, status.Errorf(codes.ResourceExhausted, "no enough space left on VG: free=%d, desiredSize=%d", free, desiredSize)
}

logger.Info(
"lvservice req",
"sizeOnCreation", sizeOnCreation,
Expand Down

0 comments on commit f6329ce

Please sign in to comment.