@@ -44,7 +44,7 @@ func fetchRAIDedLocalSsdPath() (string, error) {
44
44
}
45
45
info , err := common .RunCommand ("grep" , []string {raidedLocalSsdName }, "mdadm" , args ... )
46
46
if err != nil || len (info ) == 0 {
47
- return "" , fmt .Errorf ("Error getting RAIDed device path for Data Cache %v, output:%v " , err , string (info ))
47
+ return "" , fmt .Errorf ("Error getting RAIDed device path for Data Cache %v, output:%s " , err , string (info ))
48
48
}
49
49
infoString := strings .TrimSpace (string (info ))
50
50
infoSlice := strings .Fields (infoString )
@@ -55,6 +55,9 @@ func fetchRAIDedLocalSsdPath() (string, error) {
55
55
}
56
56
57
57
func setupCaching (devicePath string , req * csi.NodeStageVolumeRequest , nodeId string ) (string , error ) {
58
+ var args []string
59
+ var err error
60
+ var info []byte
58
61
59
62
// The device path may have changed after rebooting, so we need to fetch the path again
60
63
raidedLocalSsdPath , err := fetchRAIDedLocalSsdPath ()
@@ -77,32 +80,13 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
77
80
return mainDevicePath , err
78
81
}
79
82
}
80
-
81
- // Check if the Physical Volume(PV) is part of some other volume group
82
- args := []string {
83
- "--select" ,
84
- "pv_name=" + devicePath ,
85
- "-o" ,
86
- "vg_name" ,
87
- }
88
- info , err := common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "pvs" , args ... )
89
- if err != nil {
90
- klog .Errorf ("errored while checking physical volume details %v: %s" , err , info )
91
- // On error info contains the error message which we cannot use for further steps
92
- info = nil
93
- }
94
-
95
- infoString := strings .TrimSpace (strings .ReplaceAll (string (info ), "\n " , " " ))
96
- infoString = strings .ReplaceAll (infoString , "." , "" )
97
- infoString = strings .ReplaceAll (infoString , "\" " , "" )
98
- infoSlice := strings .Split (strings .TrimSpace (infoString ), " " )
99
- vgNameForPv := strings .TrimSpace (infoSlice [(len (infoSlice ) - 1 )])
83
+ vgNameForPv := fetchVgNameForPv (devicePath )
100
84
klog .V (4 ).Infof ("Physical volume is part of Volume group: %v" , vgNameForPv )
101
85
if vgNameForPv == volumeGroupName {
102
86
klog .V (4 ).Infof ("Physical Volume(PV) already exists in the Volume Group %v" , volumeGroupName )
103
87
} else if vgNameForPv != "VG" && vgNameForPv != "" {
104
88
105
- info , err = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgchange" , []string {"-an" , vgNameForPv }... )
89
+ info , err : = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgchange" , []string {"-an" , vgNameForPv }... )
106
90
if err != nil {
107
91
klog .Errorf ("Errored while deactivating VG %v: err: %v: %s" , vgNameForPv , err , info )
108
92
}
@@ -113,7 +97,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
113
97
114
98
if isCached {
115
99
// Uncache LV
116
- args = []string {
100
+ args : = []string {
117
101
"--uncache" ,
118
102
vgNameForPv + "/" + mainLvName ,
119
103
"--force" ,
@@ -181,10 +165,10 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
181
165
return mainDevicePath , err
182
166
}
183
167
// Check if LV exists
184
- info , err = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "lvs" , args ... )
168
+ info , err : = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "lvs" , args ... )
185
169
lvExists := strings .Contains (string (info ), cacheLvName )
186
170
if ! lvExists {
187
- args = []string {
171
+ args : = []string {
188
172
"--yes" ,
189
173
"-n" ,
190
174
cacheLvName ,
@@ -194,7 +178,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
194
178
volumeGroupName ,
195
179
raidedLocalSsdPath ,
196
180
}
197
- info , err = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "lvcreate" , args ... )
181
+ info , err : = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "lvcreate" , args ... )
198
182
if err != nil {
199
183
if strings .Contains (err .Error (), "insufficient free space" ) {
200
184
return mainDevicePath , status .Error (codes .InvalidArgument , fmt .Sprintf ("Error setting up cache: %v" , err .Error ()))
@@ -204,7 +188,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
204
188
}
205
189
206
190
// Once caching is setup, link the PD to cache
207
- args = []string {
191
+ args : = []string {
208
192
"--type" ,
209
193
"cache" ,
210
194
"--cachevol" ,
@@ -329,7 +313,7 @@ func FetchRaidedLssds() ([]string, error) {
329
313
330
314
info , err := common .RunCommand ("grep" , []string {"/dev" }, "mdadm" , args ... )
331
315
if err != nil {
332
- return nil , fmt .Errorf ("error fetching RAIDed LSSDs: %v ; err:%v" , info , err )
316
+ return nil , fmt .Errorf ("error fetching RAIDed LSSDs: %s ; err:%v" , info , err )
333
317
}
334
318
335
319
if len (info ) != 0 {
@@ -352,7 +336,7 @@ func FetchAllLssds() ([]string, error) {
352
336
353
337
info , err := common .RunCommand ("" /* pipedCmd */ , nil /* pipeCmdArg */ , "lsblk" , []string {"-o" , "NAME,MODEL" , "-p" , "-d" , "-n" }... )
354
338
if err != nil {
355
- return nil , fmt .Errorf ("errored while fetching NVME disks info: %v ; err:%v" , info , err )
339
+ return nil , fmt .Errorf ("errored while fetching NVME disks info: %s ; err:%v" , info , err )
356
340
}
357
341
infoList := strings .Split (strings .TrimSpace (string (info )), "\n " )
358
342
re , err := regexp .Compile ("nvme_card([0-9]+)?$" )
@@ -378,7 +362,7 @@ func FetchAllLssds() ([]string, error) {
378
362
func FetchLSSDsWihtEmptyMountPoint () ([]string , error ) {
379
363
info , err := common .RunCommand ("grep" , []string {"-E" , `^\S+\s*$` } /* pipeCmdArg */ , "lsblk" , []string {"-o" , "NAME,MOUNTPOINT" , "-pdn" }... )
380
364
if err != nil {
381
- return nil , fmt .Errorf ("Error while fetching disks with no mount point: %v ; err:%v" , info , err )
365
+ return nil , fmt .Errorf ("Error while fetching disks with no mount point: %s ; err:%v" , info , err )
382
366
}
383
367
infoList := strings .Split (string (info ), "\n " )
384
368
diskList := []string {}
@@ -396,7 +380,7 @@ func checkVgExists(volumeGroupName string) bool {
396
380
return false
397
381
}
398
382
// Check if the required volume group already exists
399
- klog .Infof ("check vg exists output: %v , volumeGroupName: %v" , string ( info ) , volumeGroupName )
383
+ klog .Infof ("check vg exists output: %s , volumeGroupName: %v" , info , volumeGroupName )
400
384
return strings .Contains (string (info ), volumeGroupName )
401
385
}
402
386
@@ -487,13 +471,22 @@ func reduceVolumeGroup(volumeGroupName string, force bool) {
487
471
return
488
472
}
489
473
args := []string {
474
+ "--updatemetadata" ,
475
+ volumeGroupName ,
476
+ }
477
+ info , err := common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgck" , args ... )
478
+ if err != nil {
479
+ klog .Errorf ("Errored while update volume group metadata %v: %s" , err , info )
480
+ }
481
+
482
+ args = []string {
490
483
"--removemissing" ,
491
484
volumeGroupName ,
492
485
}
493
486
if force {
494
487
args = append (args , "--force" )
495
488
}
496
- info , err : = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgreduce" , args ... )
489
+ info , err = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgreduce" , args ... )
497
490
if err != nil {
498
491
klog .Errorf ("Errored while cleaning up volume group %v: %s" , err , info )
499
492
}
@@ -512,7 +505,7 @@ func RaidLocalSsds(availableLssds []string) error {
512
505
args = append (args , availableLssds ... )
513
506
info , err := common .RunCommand ("" /* pipedCmd */ , nil /* pipeCmdArg */ , "mdadm" , args ... )
514
507
if err != nil {
515
- return fmt .Errorf ("errored while RAIDing LSSDs info: %v ; err:%v" , info , err )
508
+ return fmt .Errorf ("errored while RAIDing LSSDs info: %s ; err:%v" , info , err )
516
509
}
517
510
// Validate if Raided successfully
518
511
isAlreadyRaided , err := IsRaided ()
@@ -674,3 +667,28 @@ func addRaidedLSSDToVg(vgName, lssdPath string) error {
674
667
}
675
668
return nil
676
669
}
670
+
671
+ func fetchVgNameForPv (pvName string ) string {
672
+ // Check if the Physical Volume(PV) is part of some other volume group
673
+ args := []string {
674
+ "--select" ,
675
+ "pv_name=" + pvName ,
676
+ "-o" ,
677
+ "vg_name" ,
678
+ "--noheadings" ,
679
+ "2>/dev/null" , //NOT RECOMMENDED
680
+ }
681
+ info , err := common .RunCommand ("grep" , []string {pvName }, "pvs" , args ... )
682
+ if err != nil {
683
+ klog .Errorf ("errored while checking physical volume details %v: %s" , err , info )
684
+ // On error info contains the error message which we cannot use for further steps
685
+ info = nil
686
+ }
687
+ infoString := strings .TrimSpace (strings .ReplaceAll (string (info ), "\n " , " " ))
688
+ infoSlice := strings .Fields (infoString )
689
+ if len (infoSlice ) == 0 {
690
+ return ""
691
+ }
692
+ klog .V (4 ).Infof ("Physical volume is part of Volume group: %v" , infoSlice [0 ])
693
+ return infoSlice [0 ]
694
+ }
0 commit comments