@@ -28,6 +28,7 @@ import (
2828 "google.golang.org/grpc/codes"
2929 "google.golang.org/grpc/status"
3030 "k8s.io/klog/v2"
31+ azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
3132)
3233
3334const (
@@ -98,6 +99,11 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
9899 }
99100 }
100101
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+
101107 if createSubDir {
102108 // Mount smb base share so we can create a subdirectory
103109 if err := d .internalMount (ctx , smbVol , volCap , secrets ); err != nil {
@@ -147,6 +153,11 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
147153 return & csi.DeleteVolumeResponse {}, nil
148154 }
149155
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+
150161 var volCap * csi.VolumeCapability
151162 secrets := req .GetSecrets ()
152163 mountOptions := getMountOptions (secrets )
@@ -167,6 +178,16 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
167178
168179 if len (req .GetSecrets ()) > 0 && ! strings .EqualFold (smbVol .onDelete , retain ) {
169180 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+
170191 // mount smb base share so we can delete or archive the subdirectory
171192 if err = d .internalMount (ctx , smbVol , volCap , secrets ); err != nil {
172193 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)
211232 klog .V (2 ).Infof ("DeleteVolume(%s) does not delete subdirectory" , volumeID )
212233 }
213234
235+ d .volDeletionCache .Set (volumeID , "" )
214236 return & csi.DeleteVolumeResponse {}, nil
215237}
216238
0 commit comments