@@ -15,24 +15,28 @@ import (
15
15
)
16
16
17
17
const (
18
- cacheSuffix = "csi-fast"
19
- mainLvSuffix = "csi-main"
20
- raidedLocalSsdName = "csi-driver-data-cache"
21
- raidMode = "0"
22
- raidedLssdPrefix = "/dev/md/"
23
- maxAllowedChunks int64 = 1000000 // This is the max allowed chunks for LVM
24
- GiB int64 = 1024 * 1024 * 1024
25
- KiB int64 = 1024
18
+ cacheSuffix = "csi-fast"
19
+ mainLvSuffix = "csi-main"
20
+ raidedLocalSsdName = "csi-driver-data-cache"
21
+ raidMode = "0"
22
+ raidedLssdPrefix = "/dev/md/"
23
+ maxAllowedChunks int64 = 1000000 // This is the max allowed chunks for LVM
24
+ GiB float64 = 1024 * 1024 * 1024
25
+ KiB float64 = 1024
26
26
)
27
27
28
- var raidedLocalSsdPath = raidedLssdPrefix + raidedLocalSsdName
28
+ var (
29
+ maxChunkSize float64 = 1 * GiB // Max allowed chunk size as per LVM documentation
30
+ minChunkSize float64 = 160 * KiB // This is randomly selected, we need a multiple of 32KiB, the default size would be too small for caching https://man7.org/linux/man-pages/man8/lvcreate.8.html (--chunksize)
31
+ raidedLocalSsdPath = raidedLssdPrefix + raidedLocalSsdName
32
+ )
29
33
30
34
func setupCaching (devicePath string , req * csi.NodeStageVolumeRequest , nodeId string ) (string , error ) {
31
35
volumeId := req .GetVolumeId ()
32
36
volumeGroupName := getVolumeGroupName (nodeId )
33
37
mainDevicePath := "/dev/" + volumeGroupName + "/" + getLvName (mainLvSuffix , volumeId )
34
38
mainLvName := getLvName (mainLvSuffix , volumeId )
35
- klog .V (2 ).Infof ("Volume group available on node %v " , volumeGroupName )
39
+ klog .V (4 ).Infof ("Volume group available on node %v " , volumeGroupName )
36
40
37
41
info , err := common .RunCommand ("grep" , raidedLocalSsdName , "ls" , raidedLssdPrefix )
38
42
if err != nil {
@@ -72,7 +76,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
72
76
infoSlice := strings .Split (strings .TrimSpace (infoString ), " " )
73
77
vgNameForPv := strings .TrimSpace (infoSlice [(len (infoSlice ) - 1 )])
74
78
if vgNameForPv == volumeGroupName {
75
- klog .V (2 ).Infof ("Physical Volume(PV) already exists in the Volume Group %v" , volumeGroupName )
79
+ klog .V (4 ).Infof ("Physical Volume(PV) already exists in the Volume Group %v" , volumeGroupName )
76
80
} else if vgNameForPv != "VG" && vgNameForPv != "" {
77
81
info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , "vgchange" , []string {"-an" , vgNameForPv }... )
78
82
if err != nil {
@@ -143,10 +147,10 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
143
147
cacheLvName := getLvName (cacheSuffix , volumeId )
144
148
if isCached {
145
149
// Validate that cache is setup for required size
146
- klog .V (2 ).Infof ("Assuming valid data cache size and mode, resizing cache is not supported" )
150
+ klog .V (4 ).Infof ("Assuming valid data cache size and mode, resizing cache is not supported" )
147
151
} else {
148
152
cacheSize := req .GetPublishContext ()[common .ContexLocalSsdCacheSize ]
149
- chunkSize , err := fetchChunkSize (cacheSize )
153
+ chunkSize , err := fetchChunkSizeKiB (cacheSize )
150
154
if err != nil {
151
155
klog .Errorf ("Errored to fetch cache size, verify the data-cache-size is valid: got %v, error: %q" , cacheSize , err )
152
156
return mainDevicePath , err
@@ -183,7 +187,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
183
187
req .GetPublishContext ()[common .ContextDataCacheMode ],
184
188
volumeGroupName + "/" + mainLvName ,
185
189
"--chunksize" ,
186
- chunkSize ,
190
+ chunkSize , // default unit is KiB
187
191
"--force" ,
188
192
"-y" ,
189
193
}
@@ -283,7 +287,7 @@ func createVg(volumeGroupName string, devicePath string, raidedLocalSsds string)
283
287
if err != nil {
284
288
return fmt .Errorf ("Volume group creation failed %w: %s" , err , info )
285
289
}
286
- klog .Infof ("Volume group creation succeeded for %v" , volumeGroupName )
290
+ klog .V ( 4 ). Infof ("Volume group creation succeeded for %v" , volumeGroupName )
287
291
288
292
args = []string {}
289
293
info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , "vgscan" , args ... )
@@ -310,9 +314,9 @@ func reduceVolumeGroup(volumeGroupName string, force bool) {
310
314
func RaidLocalSsds () error {
311
315
isAlreadyRaided , err := isRaided ()
312
316
if err != nil {
313
- klog .V (2 ).Infof ("Errored while scanning for available LocalSSDs err:%v; continuing Raiding " , err )
317
+ klog .V (4 ).Infof ("Errored while scanning for available LocalSSDs err:%v; continuing raiding " , err )
314
318
} else if isAlreadyRaided {
315
- klog .V (2 ).Infof ("Local SSDs are already RAIDed, no further action needed here" )
319
+ klog .V (4 ).Infof ("Local SSDs are already RAIDed, no further action needed here" )
316
320
return nil
317
321
}
318
322
diskList := []string {}
@@ -356,7 +360,7 @@ func RaidLocalSsds() error {
356
360
// Validate if Raided successfully
357
361
isAlreadyRaided , err = isRaided ()
358
362
if err != nil {
359
- klog .V (2 ).Infof ("Errored while scanning for available raided LocalSSDs err:%v=" , err )
363
+ klog .V (4 ).Infof ("Errored while scanning for available raided LocalSSDs err:%v=" , err )
360
364
}
361
365
if ! isAlreadyRaided {
362
366
return fmt .Errorf ("failed raiding, raided device not found on scanning" )
@@ -397,17 +401,17 @@ func isCachingSetup(mainLvName string) (error, bool) {
397
401
return nil , false
398
402
}
399
403
400
- func fetchChunkSize (cacheSize string ) (string , error ) {
404
+ func fetchChunkSizeKiB (cacheSize string ) (string , error ) {
401
405
var chunkSize float64
402
- var maxChunkSize int64 = 1 * GiB // Max allowed chunk size as per LVM documentation
403
- var minChunkSize int64 = 320 * KiB // This is randomly selected, we need a multiple of 32KiB, the default size would be too small for caching https://man7.org/linux/man-pages/man8/lvcreate.8.html (--chunksize)
406
+
404
407
cacheSizeInt , err := common .ConvertGiStringToInt64 (cacheSize )
405
408
if err != nil {
406
409
return "0" , err
407
410
}
408
411
// Chunksize should be divisible by 32Kib so we need (chunksize/32*1024)*32*1024
409
- chunkSize = float64 (cacheSizeInt ) / float64 (maxAllowedChunks )
410
- chunkSize = math .Ceil (chunkSize / float64 (32 * KiB )) * float64 (32 * KiB )
411
- chunkSize = math .Min (math .Max (chunkSize , float64 (minChunkSize )), float64 (maxChunkSize ))
412
- return strconv .FormatInt (int64 (chunkSize ), 10 ), nil
412
+ chunkSize = (float64 (cacheSizeInt ) * GiB ) / float64 (maxAllowedChunks )
413
+ chunkSize = math .Round (chunkSize / (32 * KiB )) * (32 * KiB )
414
+ chunkSize = math .Min (math .Max (chunkSize , minChunkSize ), maxChunkSize ) / KiB
415
+ // default chunk size unit KiB
416
+ return strconv .FormatInt (int64 (chunkSize ), 10 ) + "KiB" , nil
413
417
}
0 commit comments