@@ -28,6 +28,7 @@ import (
28
28
"google.golang.org/grpc/codes"
29
29
"google.golang.org/grpc/status"
30
30
"k8s.io/klog/v2"
31
+ azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
31
32
)
32
33
33
34
const (
@@ -98,6 +99,11 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
98
99
}
99
100
}
100
101
102
+ if acquired := d .volumeLocks .TryAcquire (name ); ! acquired {
103
+ return nil , status .Errorf (codes .Aborted , volumeOperationAlreadyExistsFmt , name )
104
+ }
105
+ defer d .volumeLocks .Release (name )
106
+
101
107
if createSubDir {
102
108
// Mount smb base share so we can create a subdirectory
103
109
if err := d .internalMount (ctx , smbVol , volCap , secrets ); err != nil {
@@ -147,6 +153,11 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
147
153
return & csi.DeleteVolumeResponse {}, nil
148
154
}
149
155
156
+ if acquired := d .volumeLocks .TryAcquire (volumeID ); ! acquired {
157
+ return nil , status .Errorf (codes .Aborted , volumeOperationAlreadyExistsFmt , volumeID )
158
+ }
159
+ defer d .volumeLocks .Release (volumeID )
160
+
150
161
var volCap * csi.VolumeCapability
151
162
secrets := req .GetSecrets ()
152
163
mountOptions := getMountOptions (secrets )
@@ -167,6 +178,16 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
167
178
168
179
if len (req .GetSecrets ()) > 0 && ! strings .EqualFold (smbVol .onDelete , retain ) {
169
180
klog .V (2 ).Infof ("begin to delete or archive subdirectory since secret is provided" )
181
+ // check whether volumeID is in the cache
182
+ cache , err := d .volDeletionCache .Get (volumeID , azcache .CacheReadTypeDefault )
183
+ if err != nil {
184
+ return nil , status .Errorf (codes .Internal , err .Error ())
185
+ }
186
+ if cache != nil {
187
+ klog .V (2 ).Infof ("DeleteVolume: volume %s is already deleted" , volumeID )
188
+ return & csi.DeleteVolumeResponse {}, nil
189
+ }
190
+
170
191
// mount smb base share so we can delete or archive the subdirectory
171
192
if err = d .internalMount (ctx , smbVol , volCap , secrets ); err != nil {
172
193
return nil , status .Errorf (codes .Internal , "failed to mount smb server: %v" , err .Error ())
@@ -211,6 +232,7 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
211
232
klog .V (2 ).Infof ("DeleteVolume(%s) does not delete subdirectory" , volumeID )
212
233
}
213
234
235
+ d .volDeletionCache .Set (volumeID , "" )
214
236
return & csi.DeleteVolumeResponse {}, nil
215
237
}
216
238
0 commit comments