Skip to content

Fix units for cache size while calculating chunk size for LVM #2007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
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
4 changes: 2 additions & 2 deletions pkg/gce-pd-csi-driver/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
req.GetPublishContext()[common.ContextDataCacheMode],
volumeGroupName + "/" + mainLvName,
"--chunksize",
chunkSize, // default unit is KiB
chunkSize,
"--force",
"-y",
}
Expand Down Expand Up @@ -563,7 +563,7 @@ func isCachingSetup(mainLvName string) (error, bool) {
func fetchChunkSizeKiB(cacheSize string) (string, error) {
var chunkSize float64

cacheSizeInt, err := common.ConvertGiStringToInt64(cacheSize)
cacheSizeInt, err := strconv.ParseInt(cacheSize, 10, 64)
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment below needs to be updated too? "Chunksize should be divisible by 32Kib so we need (chunksize/32*1024)321024"?

if err != nil {
return "0", err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/gce-pd-csi-driver/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ func TestFetchChunkSizeKiB(t *testing.T) {
}{
{
name: "chunk size is in the allowed range",
cacheSize: "500Gi",
cacheSize: "500",
expChunkSize: "512KiB", //range defined in fetchChunkSizeKiB
},
{
name: "chunk size is set to the range ceil",
cacheSize: "30000000Gi",
cacheSize: "30000000",
expChunkSize: "1048576KiB", //range defined in fetchChunkSizeKiB - max 1GiB
},
{
name: "chunk size is set to the allowed range floor",
cacheSize: "10Gi",
cacheSize: "100",
expChunkSize: "160KiB", //range defined in fetchChunkSizeKiB - min 160 KiB
},
{
name: "cacheSize set to KiB also sets the chunk size to range floor",
cacheSize: "100Ki",
cacheSize: "1",
expChunkSize: "160KiB", //range defined in fetchChunkSizeKiB - min 160 KiB
},
{
Expand Down
2 changes: 1 addition & 1 deletion test/remote/client-wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
// Keys in the volume context.
contextForceAttach = "force-attach"

defaultLocalSsdCacheSize = "200Gi"
defaultLocalSsdCacheSize = "200"
defaultDataCacheMode = common.DataCacheModeWriteThrough
)

Expand Down