@@ -15,14 +15,6 @@ See the License for the specific language governing permissions and
1515limitations under the License.
1616*/
1717
18- // Code generated by protoc-gen-go. DO NOT EDIT.
19-
20- // NOTE: THIS IS NOT GENERATED. We have to add the line above to prevent golint
21- // checking this file. This is needed because some methods end with xxxId, but
22- // golint wants them to be xxxID. But we're not able to change it as the
23- // official CSI spec is that way and we have to implement the interface
24- // exactly.
25-
2618package driver
2719
2820import (
@@ -40,8 +32,6 @@ import (
4032)
4133
4234const (
43- diskDOPrefix = "scsi-0DO_Volume_"
44-
4535 // Current technical limit is 128
4636 // - 1 for root
4737 // - 1 for /var/lib/docker
@@ -72,6 +62,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
7262 return nil , status .Error (codes .InvalidArgument , "NodeStageVolume Volume Capability must be provided" )
7363 }
7464
65+ if acquired := d .volumeLocks .TryAcquire (req .VolumeId ); ! acquired {
66+ return nil , status .Errorf (codes .Aborted , "an operation with the given Volume ID %s already exists" , req .VolumeId )
67+ }
68+ defer d .volumeLocks .Release (req .VolumeId )
69+
7570 // Apparently sometimes we need to call udevadm trigger to get the volume
7671 // properly registered in /dev/disk. More information can be found here:
7772 // https://github.com/cloudscale-ch/csi-cloudscale/issues/9
@@ -80,12 +75,17 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
8075 return nil , err
8176 }
8277
78+ d .log .WithFields (logrus.Fields {
79+ "volume_id" : req .VolumeId ,
80+ "device_path" : source ,
81+ }).Info ("successfully found attached volume_id at device_path" )
82+
8383 // Debug logging to help diagnose potential race conditions with concurrent volume mounts
8484 resolvedSource , resolveErr := filepath .EvalSymlinks (source )
8585 if resolveErr != nil {
8686 d .log .WithFields (logrus.Fields {
87- "volume_id" : req .VolumeId ,
88- "source" : source ,
87+ "volume_id" : req .VolumeId ,
88+ "source" : source ,
8989 "resolve_error" : resolveErr ,
9090 }).Debug ("failed to resolve source symlink" )
9191 } else {
@@ -115,7 +115,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
115115 return & csi.NodeStageVolumeResponse {}, nil
116116 }
117117
118- target := req .StagingTargetPath
118+ stagingTargetPath := req .StagingTargetPath
119119
120120 mnt := req .VolumeCapability .GetMount ()
121121 options := mnt .MountFlags
@@ -153,19 +153,21 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
153153 ll .Info ("source device is already formatted" )
154154 }
155155
156- ll .Info ("mounting the volume for staging " )
156+ ll .Info ("checking if stagingTargetPath is already mounted " )
157157
158- mounted , err := d .mounter .IsMounted (target )
158+ mounted , err := d .mounter .IsMounted (stagingTargetPath )
159159 if err != nil {
160+ ll .WithError (err ).Error ("unable to check if already mounted" )
160161 return nil , err
161162 }
162163
163164 if ! mounted {
164- if err := d .mounter .Mount (source , target , fsType , luksContext , options ... ); err != nil {
165+ ll .Info ("not mounted yet, mounting the volume for staging" )
166+ if err := d .mounter .Mount (source , stagingTargetPath , fsType , luksContext , options ... ); err != nil {
165167 return nil , status .Error (codes .Internal , err .Error ())
166168 }
167169 } else {
168- ll .Info ("source device is already mounted to the target path" )
170+ ll .Info ("source device is already mounted to the stagingTargetPath path" )
169171 }
170172
171173 ll .Info ("formatting and mounting stage volume is finished" )
@@ -182,6 +184,11 @@ func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolu
182184 return nil , status .Error (codes .InvalidArgument , "NodeUnstageVolume Staging Target Path must be provided" )
183185 }
184186
187+ if acquired := d .volumeLocks .TryAcquire (req .VolumeId ); ! acquired {
188+ return nil , status .Errorf (codes .Aborted , "an operation with the given Volume ID %s already exists" , req .VolumeId )
189+ }
190+ defer d .volumeLocks .Release (req .VolumeId )
191+
185192 luksContext := LuksContext {VolumeLifecycle : VolumeLifecycleNodeUnstageVolume }
186193
187194 ll := d .log .WithFields (logrus.Fields {
@@ -229,6 +236,11 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
229236 return nil , status .Error (codes .InvalidArgument , "NodePublishVolume Volume Capability must be provided" )
230237 }
231238
239+ if acquired := d .volumeLocks .TryAcquire (req .VolumeId ); ! acquired {
240+ return nil , status .Errorf (codes .Aborted , "an operation with the given Volume ID %s already exists" , req .VolumeId )
241+ }
242+ defer d .volumeLocks .Release (req .VolumeId )
243+
232244 publishContext := req .GetPublishContext ()
233245 if publishContext == nil {
234246 return nil , status .Error (codes .InvalidArgument , "PublishContext must be provided" )
@@ -276,6 +288,11 @@ func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish
276288 return nil , status .Error (codes .InvalidArgument , "NodeUnpublishVolume Target Path must be provided" )
277289 }
278290
291+ if acquired := d .volumeLocks .TryAcquire (req .VolumeId ); ! acquired {
292+ return nil , status .Errorf (codes .Aborted , "an operation with the given Volume ID %s already exists" , req .VolumeId )
293+ }
294+ defer d .volumeLocks .Release (req .VolumeId )
295+
279296 luksContext := LuksContext {VolumeLifecycle : VolumeLifecycleNodeUnpublishVolume }
280297
281298 ll := d .log .WithFields (logrus.Fields {
0 commit comments