@@ -53,7 +53,7 @@ type GCENodeServer struct {
53
53
54
54
// deviceInUseErrors keeps tracks of device names and a timestamp for when an error is
55
55
// encounted for that device
56
- deviceInUseErrors map [ string ]time. Time
56
+ deviceInUseErrors deviceErrMap
57
57
58
58
// If set, this semaphore will be used to serialize formatAndMount. It will be raised
59
59
// when the operation starts, and lowered either when finished, or when
@@ -85,8 +85,6 @@ const (
85
85
fsTypeExt3 = "ext3"
86
86
87
87
readAheadKBMountFlagRegexPattern = "^read_ahead_kb=(.+)$"
88
-
89
- deviceInUseTimeout = 30
90
88
)
91
89
92
90
var (
@@ -101,32 +99,6 @@ func getDefaultFsType() string {
101
99
}
102
100
}
103
101
104
- // checkDeviceErrorTimeout returns true an error was encounted for the specified deviceName,
105
- // where the error happened at least `deviceInUseTimeout` seconds ago.
106
- func (ns * GCENodeServer ) checkDeviceErrorTimeout (deviceName string ) bool {
107
- if ns .deviceInUseErrors == nil {
108
- ns .deviceInUseErrors = make (map [string ]time.Time )
109
- }
110
-
111
- lastErrTime , exists := ns .deviceInUseErrors [deviceName ]
112
- return exists && time .Now ().Sub (lastErrTime ).Seconds () >= deviceInUseTimeout
113
- }
114
-
115
- // markDeviceError updates the internal `deviceInUseErrors` map to denote an error was encounted
116
- // for the specified deviceName at the current time
117
- func (ns * GCENodeServer ) markDeviceError (deviceName string ) {
118
- if ns .deviceInUseErrors == nil {
119
- ns .deviceInUseErrors = make (map [string ]time.Time )
120
- }
121
-
122
- // If an earlier error has already been recorded, do not overwrite it
123
- if _ , exists := ns .deviceInUseErrors [deviceName ]; ! exists {
124
- now := time .Now ()
125
- klog .V (4 ).Infof ("Recording in-use error for device %s at time %s" , deviceName , now )
126
- ns .deviceInUseErrors [deviceName ] = now
127
- }
128
- }
129
-
130
102
func (ns * GCENodeServer ) isVolumePathMounted (path string ) bool {
131
103
notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (path )
132
104
klog .V (4 ).Infof ("Checking volume path %s is mounted %t: error %v" , path , ! notMnt , err )
@@ -489,18 +461,18 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
489
461
}
490
462
491
463
if err := ns .confirmDeviceUnused (volumeID ); err != nil {
492
- var targetErr * ignoreableError
493
- if errors .As (err , & targetErr ) {
464
+ var ignoreableErr * ignoreableError
465
+ if errors .As (err , & ignoreableErr ) {
494
466
klog .Warningf ("Unabled to check if device for %s is unused. Device has been unmounted successfully. Ignoring and continuing with unstaging. (%v)" , volumeID , err )
495
- } else if ns .checkDeviceErrorTimeout (volumeID ) {
467
+ } else if ns .deviceInUseErrors . checkDeviceErrorTimeout (volumeID ) {
496
468
klog .Warningf ("Device %s could not be released after timeout of %d seconds. NodeUnstageVolume will return success." , volumeID , deviceInUseTimeout )
497
469
} else {
498
- ns .markDeviceError (volumeID )
470
+ ns .deviceInUseErrors . markDeviceError (volumeID )
499
471
return nil , status .Errorf (codes .Internal , "NodeUnstageVolume for volume %s failed: %v" , volumeID , err )
500
472
}
501
473
}
502
474
503
- delete ( ns .deviceInUseErrors , volumeID )
475
+ ns .deviceInUseErrors . deleteDevice ( volumeID )
504
476
klog .V (4 ).Infof ("NodeUnstageVolume succeeded on %v from %s" , volumeID , stagingTargetPath )
505
477
return & csi.NodeUnstageVolumeResponse {}, nil
506
478
}
0 commit comments