@@ -60,6 +60,8 @@ func (hp *hostPath) NodePublishVolume(ctx context.Context, req *csi.NodePublishV
60
60
hp .mutex .Lock ()
61
61
defer hp .mutex .Unlock ()
62
62
63
+ mounter := mount .New ("" )
64
+
63
65
// if ephemeral is specified, create volume here to avoid errors
64
66
if ephemeralVolume {
65
67
volID := req .GetVolumeId ()
@@ -102,8 +104,6 @@ func (hp *hostPath) NodePublishVolume(ctx context.Context, req *csi.NodePublishV
102
104
return nil , fmt .Errorf ("failed to get the loop device: %w" , err )
103
105
}
104
106
105
- mounter := mount .New ("" )
106
-
107
107
// Check if the target path exists. Create if not present.
108
108
_ , err = os .Lstat (targetPath )
109
109
if os .IsNotExist (err ) {
@@ -130,15 +130,15 @@ func (hp *hostPath) NodePublishVolume(ctx context.Context, req *csi.NodePublishV
130
130
}
131
131
132
132
options := []string {"bind" }
133
- if err := mount . New ( "" ) .Mount (loopDevice , targetPath , "" , options ); err != nil {
133
+ if err := mounter .Mount (loopDevice , targetPath , "" , options ); err != nil {
134
134
return nil , fmt .Errorf ("failed to mount block device: %s at %s: %w" , loopDevice , targetPath , err )
135
135
}
136
136
} else if req .GetVolumeCapability ().GetMount () != nil {
137
137
if vol .VolAccessType != state .MountAccess {
138
138
return nil , status .Error (codes .InvalidArgument , "cannot publish a non-mount volume as mount volume" )
139
139
}
140
140
141
- notMnt , err := mount .IsNotMountPoint (mount . New ( "" ) , targetPath )
141
+ notMnt , err := mount .IsNotMountPoint (mounter , targetPath )
142
142
if err != nil {
143
143
if os .IsNotExist (err ) {
144
144
if err = os .Mkdir (targetPath , 0750 ); err != nil {
@@ -173,7 +173,6 @@ func (hp *hostPath) NodePublishVolume(ctx context.Context, req *csi.NodePublishV
173
173
if readOnly {
174
174
options = append (options , "ro" )
175
175
}
176
- mounter := mount .New ("" )
177
176
path := hp .getVolumePath (volumeId )
178
177
179
178
if err := mounter .Mount (path , targetPath , "" , options ); err != nil {
0 commit comments