@@ -18,9 +18,10 @@ const (
18
18
raidedLocalSsdName = "csi-driver-data-cache"
19
19
raidMode = "0"
20
20
raidedLssdPrefix = "/dev/md/"
21
- raidedLocalSsdPath = raidedLssdPrefix + raidedLocalSsdName
22
21
)
23
22
23
+ var raidedLocalSsdPath = raidedLssdPrefix + raidedLocalSsdName
24
+
24
25
func setupCaching (devicePath string , req * csi.NodeStageVolumeRequest , nodeId string ) (string , error ) {
25
26
volumeId := req .GetVolumeId ()
26
27
volumeGroupName := getVolumeGroupName (nodeId )
@@ -29,9 +30,17 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
29
30
klog .V (2 ).Infof ("============================== Start LVM PoC NodeStageVolume Steps ==============================" )
30
31
klog .V (2 ).Infof ("============================== volumeGroupName is %v ==============================" , volumeGroupName )
31
32
33
+ info , err := common .RunCommand ("grep" , raidedLocalSsdName , "ls" , raidedLssdPrefix )
34
+ if err != nil {
35
+ klog .Errorf ("================== failed while listing raided devices, err: %v, output:%v ===============" , err , info )
36
+ }
37
+ infoString := strings .TrimSpace (string (info ))
38
+ klog .V (2 ).Infof ("=================== Got Raided LSSD name %v ===================" , infoString )
39
+ raidedLocalSsdPath = raidedLssdPrefix + infoString
40
+
32
41
klog .V (2 ).Infof ("============================== vgscan before vgcreate ==============================" )
33
42
args := []string {}
34
- info , err : = common .RunCommand ("vgscan" , args ... )
43
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , "vgscan" , args ... )
35
44
if err != nil {
36
45
klog .Errorf ("vgscan error %v: %s" , err , info )
37
46
}
@@ -56,14 +65,14 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
56
65
"-o" ,
57
66
"vg_name" ,
58
67
}
59
- info , err = common .RunCommand ("pvs" , args ... )
68
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " pvs" , args ... )
60
69
if err != nil {
61
70
klog .Errorf ("errored while checking physical volume details %v: %s" , err , info )
62
71
// On error info contains the error message which we cannot use for further steps
63
72
info = nil
64
73
}
65
74
66
- infoString : = strings .TrimSpace (strings .ReplaceAll (string (info ), "\n " , " " ))
75
+ infoString = strings .TrimSpace (strings .ReplaceAll (string (info ), "\n " , " " ))
67
76
infoString = strings .ReplaceAll (infoString , "." , "" )
68
77
infoString = strings .ReplaceAll (infoString , "\" " , "" )
69
78
infoSlice := strings .Split (strings .TrimSpace (infoString ), " " )
@@ -74,38 +83,40 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
74
83
} else if vgNameForPv != "VG" && vgNameForPv != "" {
75
84
76
85
klog .V (2 ).Infof ("============================== Deactivate VG %s ==============================" , vgNameForPv )
77
- info , err = common .RunCommand ("vgchange" , []string {"-an" , vgNameForPv }... )
86
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " vgchange" , []string {"-an" , vgNameForPv }... )
78
87
if err != nil {
79
88
klog .Errorf ("Errored while deactivating VG %v: err: %v: %s" , vgNameForPv , err , info )
80
89
}
81
90
82
91
reduceVolumeGroup (vgNameForPv , false )
83
- _ , isCached := isCachingSetup (raidedLocalSsdPath , mainLvName )
92
+ _ , isCached := isCachingSetup (mainLvName )
84
93
// We will continue to uncache even if it errors to check caching as it is not a terminal issue.
85
94
86
- if ! isCached {
95
+ if isCached {
87
96
klog .Infof ("============================== Uncaching the LV %v==============================" , mainLvName )
88
97
// Uncache LV
89
98
args = []string {
90
99
"--uncache" ,
91
100
vgNameForPv + "/" + mainLvName ,
101
+ "--force" ,
102
+ "-y" , // force remove cache without flushing data
92
103
}
93
- info , err = common .RunCommand ("lvconvert" , args ... )
104
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " lvconvert" , args ... )
94
105
if err != nil {
95
106
klog .Errorf ("errored while uncaching main LV. %v: %s" , err , info )
96
107
}
97
108
98
109
reduceVolumeGroup (vgNameForPv , false )
99
110
}
100
111
klog .V (2 ).Infof ("============================== Merge VG %v to Node VG %v ==============================" , vgNameForPv , volumeGroupName )
101
- info , err = common .RunCommand ("vgmerge" , []string {volumeGroupName , vgNameForPv }... )
112
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " vgmerge" , []string {volumeGroupName , vgNameForPv }... )
102
113
if err != nil {
103
114
klog .Errorf ("Errored while merging Volume group %s into %s %v: %s" , vgNameForPv , volumeGroupName , err , info )
104
115
}
105
116
106
117
} else {
107
118
klog .V (2 ).Infof ("============================== Extend Node VG %v for PV %v ==============================" , volumeGroupName , devicePath )
108
- info , err := common .RunCommand ("vgextend" , []string {volumeGroupName , devicePath }... )
119
+ info , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " vgextend" , []string {volumeGroupName , devicePath }... )
109
120
if err != nil {
110
121
klog .Errorf ("Errored while extending VGs %v: %s" , err , info )
111
122
}
@@ -118,7 +129,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
118
129
"-o" ,
119
130
"lv_name" ,
120
131
}
121
- lvList , err := common .RunCommand ("lvs" , args ... )
132
+ lvList , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " lvs" , args ... )
122
133
if err != nil {
123
134
return mainDevicePath , fmt .Errorf ("lv list error %w: %s" , err , info )
124
135
}
@@ -135,13 +146,13 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
135
146
volumeGroupName ,
136
147
devicePath ,
137
148
}
138
- info , err = common .RunCommand ("lvcreate" , args ... )
149
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " lvcreate" , args ... )
139
150
if err != nil {
140
151
return mainDevicePath , fmt .Errorf ("lvcreate error %w: %s" , err , info )
141
152
}
142
153
143
154
}
144
- err , isCached := isCachingSetup (raidedLocalSsdPath , mainLvName )
155
+ err , isCached := isCachingSetup (mainLvName )
145
156
if err != nil {
146
157
klog .Errorf ("faild to check if caching ius setup for LV. Continuing to setup caching." )
147
158
}
@@ -163,7 +174,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
163
174
volumeGroupName ,
164
175
raidedLocalSsdPath ,
165
176
}
166
- info , err = common .RunCommand ("lvcreate" , args ... )
177
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " lvcreate" , args ... )
167
178
if err != nil {
168
179
klog .V (2 ).Infof ("============================== lvcreate error %v: %s ==============================" , err , info )
169
180
return mainDevicePath , fmt .Errorf ("lvcreate error %w: %s" , err , info )
@@ -186,7 +197,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
186
197
"--force" ,
187
198
"-y" ,
188
199
}
189
- info , err = common .RunCommand ("lvconvert" , args ... )
200
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " lvconvert" , args ... )
190
201
if err != nil {
191
202
klog .V (2 ).Infof ("============================== lvconvert error %v: %s ==============================" , err , info )
192
203
return mainDevicePath , fmt .Errorf ("lvconvert error %w: %s" , err , info )
@@ -195,7 +206,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
195
206
196
207
// activate all the LVs in the Volume group
197
208
klog .V (2 ).Infof ("============================== Activate Volume group %s ==============================" , volumeGroupName )
198
- info , err = common .RunCommand ("vgchange" , []string {"-ay" , volumeGroupName }... )
209
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " vgchange" , []string {"-ay" , volumeGroupName }... )
199
210
if err != nil {
200
211
klog .Errorf ("Failed to activate VG %v %v:%s" , volumeGroupName , err , info )
201
212
}
@@ -212,15 +223,15 @@ func cleanupCache(volumeId string, nodeId string) error {
212
223
"-an" ,
213
224
"/dev/" + volumeGroupName + "/" + mainLvName ,
214
225
}
215
- info , err := common .RunCommand ("lvchange" , args ... )
226
+ info , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " lvchange" , args ... )
216
227
if err != nil {
217
228
klog .Errorf ("Errored while deactivating the disk %v: %s" , err , info )
218
229
}
219
230
args = []string {
220
231
"--uncache" ,
221
232
volumeGroupName + "/" + mainLvName ,
222
233
}
223
- info , err = common .RunCommand ("lvconvert" , args ... )
234
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " lvconvert" , args ... )
224
235
if err != nil {
225
236
return fmt .Errorf ("errored while uncaching the disk %w: %s" , err , info )
226
237
}
@@ -247,15 +258,15 @@ func createVg(volumeGroupName string, devicePath string, raidedLocalSsds string)
247
258
volumeGroupName ,
248
259
raidedLocalSsds ,
249
260
}
250
- info , err := common .RunCommand ("vgcreate" , args ... )
261
+ info , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " vgcreate" , args ... )
251
262
if err != nil {
252
263
klog .Errorf ("vgcreate error %v: %s" , err , info )
253
264
return fmt .Errorf ("vgcreate error %w: %s" , err , info )
254
265
}
255
266
256
267
klog .V (2 ).Infof ("============================== vgscan after vgcreate ==============================" )
257
268
args = []string {}
258
- info , err = common .RunCommand ("vgscan" , args ... )
269
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " vgscan" , args ... )
259
270
if err != nil {
260
271
klog .Errorf ("vgscan error %v: %s" , err , info )
261
272
} else {
@@ -273,7 +284,7 @@ func reduceVolumeGroup(volumeGroupName string, force bool) {
273
284
if force {
274
285
args = append (args , "--force" )
275
286
}
276
- info , err := common .RunCommand ("vgreduce" , args ... )
287
+ info , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipedCmdArg */ , " vgreduce" , args ... )
277
288
if err != nil {
278
289
klog .Errorf ("Errored while cleaning up volume group %v: %s" , err , info )
279
290
}
@@ -287,24 +298,19 @@ func RaidLocalSsds() error {
287
298
klog .V (2 ).Infof ("============================== Local SSDs are already RAIDed ==============================" )
288
299
return nil
289
300
}
290
- info , err := common .RunCommand ("nvme" , []string {"list" , "-o" , "json" }... )
301
+ info , err := common .RunCommand ("grep" /* pipedCmd */ , "DevicePath" /* pipeCmdArg */ , " nvme" , []string {"list" , "-o" , "json" }... )
291
302
if err != nil {
292
303
return fmt .Errorf ("errored while scanning available NVME disks info: %v; err:%v" , info , err )
293
304
}
294
- infoString := strings .TrimSpace (strings .ReplaceAll (string (info ), "\n " , " " ))
295
- klog .V (2 ).Infof ("============================== NVME list %v ==============================" , infoString )
296
- infoString = strings .ReplaceAll (infoString , "\" " , "" )
297
- infoString = strings .ReplaceAll (infoString , " :" , ":" )
298
- infoString = strings .ReplaceAll (infoString , ": " , ":" )
299
- infoString = strings .ReplaceAll (infoString , "," , " " )
300
- infoSlice := strings .Split (infoString , " " )
305
+ infoString := strings .ReplaceAll (string (info ), "\" " , "" )
306
+ infoString = strings .TrimSpace (strings .ReplaceAll (infoString , "," , " " ))
307
+ infoSlice := strings .Split (infoString , "\n " )
308
+ klog .V (2 ).Infof ("============================== NVME list %v ==============================" , infoSlice )
301
309
diskList := []string {}
302
310
for _ , diskInfo := range infoSlice {
303
311
diskName := strings .TrimSpace (diskInfo )
304
- if strings .Contains (diskName , "DevicePath" ) {
305
- diskName := strings .TrimSpace (strings .Split (diskName , ":" )[1 ])
306
- diskList = append (diskList , diskName )
307
- }
312
+ diskName = strings .TrimSpace (strings .Split (diskName , ":" )[1 ])
313
+ diskList = append (diskList , diskName )
308
314
}
309
315
nvmeDiskCount := len (diskList )
310
316
nvmeDiskList := strings .Join (diskList , " " )
@@ -323,7 +329,7 @@ func RaidLocalSsds() error {
323
329
strconv .Itoa (nvmeDiskCount ),
324
330
}
325
331
args = append (args , diskList ... )
326
- info , err = common .RunCommand ("mdadm" , args ... )
332
+ info , err = common .RunCommand ("" /* pipedCmd */ , "" /* pipeCmdArg */ , " mdadm" , args ... )
327
333
if err != nil {
328
334
return fmt .Errorf ("errored while RAIDing LSSDs info: %v; err:%v" , info , err )
329
335
}
@@ -343,7 +349,7 @@ func isRaided() (bool, error) {
343
349
"--detail" ,
344
350
"--scan" ,
345
351
}
346
- info , err := common .RunCommand ("mdadm" , args ... )
352
+ info , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipeCmdArg */ , " mdadm" , args ... )
347
353
if err != nil {
348
354
return false , fmt .Errorf ("errored while scanning for raided LSSD %v: %s" , err , info )
349
355
}
@@ -354,17 +360,18 @@ func isRaided() (bool, error) {
354
360
return false , nil
355
361
}
356
362
357
- func isCachingSetup (cachePoolName , mainLvName string ) (error , bool ) {
363
+ func isCachingSetup (mainLvName string ) (error , bool ) {
358
364
// Verify caching is setup for PD
365
+ klog .V (2 ).Infof ("============================== Verifying if caching is setup for %v ==============================" , mainLvName )
359
366
args := []string {
360
367
"--select" ,
361
368
"lv_name=" + mainLvName ,
362
369
"-o" ,
363
370
"pool_lv" ,
364
371
}
365
- poolName , err := common .RunCommand ("lvs" , args ... )
372
+ poolName , err := common .RunCommand ("" /* pipedCmd */ , "" /* pipeCmdArg */ , " lvs" , args ... )
366
373
if err != nil {
367
- return fmt .Errorf ("lvcreate error %w" , err ), false
374
+ return fmt .Errorf ("lvs error %w" , err ), false
368
375
}
369
376
if strings .Contains (string (poolName ), "csi-fast" ) {
370
377
return nil , true
0 commit comments