-
Notifications
You must be signed in to change notification settings - Fork 182
/
nodeserver.go
589 lines (504 loc) · 20.1 KB
/
nodeserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package azuredisk
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"time"
volumehelper "sigs.k8s.io/azuredisk-csi-driver/pkg/util"
"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util/hostutil"
mount "k8s.io/mount-utils"
)
const (
defaultLinuxFsType = "ext4"
defaultWindowsFsType = "ntfs"
defaultAzureVolumeLimit = 16
volumeOperationAlreadyExistsFmt = "An operation with the given Volume ID %s already exists"
)
func getDefaultFsType() string {
if runtime.GOOS == "windows" {
return defaultWindowsFsType
}
return defaultLinuxFsType
}
// NodeStageVolume mount disk device to a staging path
func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
diskURI := req.GetVolumeId()
if len(diskURI) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
}
target := req.GetStagingTargetPath()
if len(target) == 0 {
return nil, status.Error(codes.InvalidArgument, "Staging target not provided")
}
volumeCapability := req.GetVolumeCapability()
if volumeCapability == nil {
return nil, status.Error(codes.InvalidArgument, "Volume capability not provided")
}
if !isValidVolumeCapabilities([]*csi.VolumeCapability{volumeCapability}) {
return nil, status.Error(codes.InvalidArgument, "Volume capability not supported")
}
if acquired := d.volumeLocks.TryAcquire(diskURI); !acquired {
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, diskURI)
}
defer d.volumeLocks.Release(diskURI)
// If the access type is block, do nothing for stage
switch req.GetVolumeCapability().GetAccessType().(type) {
case *csi.VolumeCapability_Block:
return &csi.NodeStageVolumeResponse{}, nil
}
lun, ok := req.PublishContext[LUN]
if !ok {
return nil, status.Error(codes.InvalidArgument, "lun not provided")
}
mnt, err := d.ensureMountPoint(target)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not mount target %q: %v", target, err)
}
if mnt {
klog.V(2).Infof("NodeStageVolume: already mounted on target %s", target)
return &csi.NodeStageVolumeResponse{}, nil
}
// Get fsType and mountOptions that the volume will be formatted and mounted with
fstype := getDefaultFsType()
options := []string{}
if mnt := volumeCapability.GetMount(); mnt != nil {
if mnt.FsType != "" {
fstype = mnt.FsType
}
options = append(options, mnt.MountFlags...)
}
volContextFSType := getFStype(req.GetVolumeContext())
if volContextFSType != "" {
// respect "fstype" setting in storage class parameters
fstype = volContextFSType
}
source, err := d.getDevicePathWithLUN(lun)
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to find disk on lun %s. %v", lun, err)
}
// If partition is specified, should mount it only instead of the entire disk.
if partition, ok := req.GetVolumeContext()[volumeAttributePartition]; ok {
source = source + "-part" + partition
}
// FormatAndMount will format only if needed
klog.V(2).Infof("NodeStageVolume: formatting %s and mounting at %s with mount options(%s)", source, target, options)
err = d.formatAndMount(source, target, fstype, options)
if err != nil {
msg := fmt.Sprintf("could not format %q(lun: %q), and mount it at %q", source, lun, target)
return nil, status.Error(codes.Internal, msg)
}
klog.V(2).Infof("NodeStageVolume: format %s and mounting at %s successfully.", source, target)
// if resize is required, resize filesystem
if required, ok := req.GetVolumeContext()[resizeRequired]; ok && required == "true" {
klog.V(2).Infof("NodeStageVolume: fs resize initiating on target(%s) volumeid(%s)", target, diskURI)
if err != nil {
return nil, status.Errorf(codes.Internal, "NodeStageVolume: Could not get volume path for %s: %v", target, err)
}
resizer := mount.NewResizeFs(d.mounter.Exec)
if _, err := resizer.Resize(source, target); err != nil {
return nil, status.Errorf(codes.Internal, "NodeStageVolume: Could not resize volume %q (%q): %v", diskURI, source, err)
}
klog.V(2).Infof("NodeStageVolume: fs resize successful on target(%s) volumeid(%s).", target, diskURI)
}
return &csi.NodeStageVolumeResponse{}, nil
}
// NodeUnstageVolume unmount disk device from a staging path
func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
}
stagingTargetPath := req.GetStagingTargetPath()
if len(stagingTargetPath) == 0 {
return nil, status.Error(codes.InvalidArgument, "Staging target not provided")
}
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
}
defer d.volumeLocks.Release(volumeID)
klog.V(2).Infof("NodeUnstageVolume: unmounting %s", stagingTargetPath)
err := CleanupMountPoint(stagingTargetPath, d.mounter, false)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount staging target %q: %v", stagingTargetPath, err)
}
klog.V(2).Infof("NodeUnstageVolume: unmount %s successfully", stagingTargetPath)
return &csi.NodeUnstageVolumeResponse{}, nil
}
// NodePublishVolume mount the volume from staging to target path
func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
volumeID := req.GetVolumeId()
if req.GetVolumeCapability() == nil {
return nil, status.Error(codes.InvalidArgument, "Volume capability missing in request")
}
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
source := req.GetStagingTargetPath()
if len(source) == 0 {
return nil, status.Error(codes.InvalidArgument, "Staging target not provided")
}
target := req.GetTargetPath()
if len(target) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path not provided")
}
err := preparePublishPath(target, d.mounter)
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("Target path could not be prepared: %v", err))
}
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
}
defer d.volumeLocks.Release(volumeID)
mountOptions := []string{"bind"}
if req.GetReadonly() {
mountOptions = append(mountOptions, "ro")
}
switch req.GetVolumeCapability().GetAccessType().(type) {
case *csi.VolumeCapability_Block:
lun, ok := req.PublishContext[LUN]
if !ok {
return nil, status.Error(codes.InvalidArgument, "lun not provided")
}
var err error
source, err = d.getDevicePathWithLUN(lun)
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to find device path with lun %s. %v", lun, err)
}
klog.V(2).Infof("NodePublishVolume [block]: found device path %s with lun %s", source, lun)
err = d.ensureBlockTargetFile(target)
if err != nil {
return nil, err
}
case *csi.VolumeCapability_Mount:
mnt, err := d.ensureMountPoint(target)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not mount target %q: %v", target, err)
}
if mnt {
klog.V(2).Infof("NodePublishVolume: already mounted on target %s", target)
return &csi.NodePublishVolumeResponse{}, nil
}
}
klog.V(2).Infof("NodePublishVolume: mounting %s at %s", source, target)
if err := d.mounter.Mount(source, target, "", mountOptions); err != nil {
return nil, status.Errorf(codes.Internal, "Could not mount %q at %q: %v", source, target, err)
}
klog.V(2).Infof("NodePublishVolume: mount %s at %s successfully", source, target)
return &csi.NodePublishVolumeResponse{}, nil
}
// NodeUnpublishVolume unmount the volume from the target path
func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
targetPath := req.GetTargetPath()
volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
if len(targetPath) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
}
klog.V(2).Infof("NodeUnpublishVolume: unmounting volume %s on %s", volumeID, targetPath)
err := CleanupMountPoint(targetPath, d.mounter, false)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount target %q: %v", targetPath, err)
}
if acquired := d.volumeLocks.TryAcquire(volumeID); !acquired {
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
}
defer d.volumeLocks.Release(volumeID)
klog.V(2).Infof("NodeUnpublishVolume: unmount volume %s on %s successfully", volumeID, targetPath)
return &csi.NodeUnpublishVolumeResponse{}, nil
}
// NodeGetCapabilities return the capabilities of the Node plugin
func (d *Driver) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
return &csi.NodeGetCapabilitiesResponse{
Capabilities: d.NSCap,
}, nil
}
// NodeGetInfo return info of the node on which this plugin is running
func (d *Driver) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
instances, ok := d.cloud.Instances()
if !ok {
return nil, status.Error(codes.Internal, "Failed to get instances from cloud provider")
}
instanceType, err := instances.InstanceType(context.TODO(), types.NodeName(d.NodeID))
if err != nil {
klog.Warningf("Failed to get instance type from Azure cloud provider, nodeName: %v, error: %v", d.NodeID, err)
instanceType = ""
}
topology := &csi.Topology{
Segments: map[string]string{topologyKey: ""},
}
zone, err := d.cloud.GetZone(ctx)
if err != nil {
klog.Warningf("Failed to get zone from Azure cloud provider, nodeName: %v, error: %v", d.NodeID, err)
} else {
if isAvailabilityZone(zone.FailureDomain, d.cloud.Location) {
topology.Segments[topologyKey] = zone.FailureDomain
topology.Segments[WellKnownTopologyKey] = zone.FailureDomain
klog.V(2).Infof("NodeGetInfo, nodeName: %v, zone: %v", d.NodeID, zone.FailureDomain)
}
}
return &csi.NodeGetInfoResponse{
NodeId: d.NodeID,
MaxVolumesPerNode: getMaxDataDiskCount(instanceType),
AccessibleTopology: topology,
}, nil
}
func getMaxDataDiskCount(instanceType string) int64 {
vmsize := strings.ToUpper(instanceType)
maxDataDiskCount, exists := maxDataDiskCountMap[vmsize]
if exists {
klog.V(5).Infof("got a matching size in getMaxDataDiskCount, VM Size: %s, MaxDataDiskCount: %d", vmsize, maxDataDiskCount)
return maxDataDiskCount
}
klog.V(5).Infof("not found a matching size in getMaxDataDiskCount, VM Size: %s, use default volume limit: %d", vmsize, defaultAzureVolumeLimit)
return defaultAzureVolumeLimit
}
func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
if len(req.VolumeId) == 0 {
return nil, status.Error(codes.InvalidArgument, "NodeGetVolumeStats volume ID was empty")
}
if len(req.VolumePath) == 0 {
return nil, status.Error(codes.InvalidArgument, "NodeGetVolumeStats volume path was empty")
}
_, err := os.Stat(req.VolumePath)
if err != nil {
if os.IsNotExist(err) {
return nil, status.Errorf(codes.NotFound, "path %s does not exist", req.VolumePath)
}
return nil, status.Errorf(codes.Internal, "failed to stat file %s: %v", req.VolumePath, err)
}
isBlock, err := hostutil.NewHostUtil().PathIsDevice(req.VolumePath)
if err != nil {
return nil, status.Errorf(codes.NotFound, "failed to determine whether %s is block device: %v", req.VolumePath, err)
}
if isBlock {
bcap, err := getBlockSizeBytes(req.VolumePath, d.mounter)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get block capacity on path %s: %v", req.VolumePath, err)
}
return &csi.NodeGetVolumeStatsResponse{
Usage: []*csi.VolumeUsage{
{
Unit: csi.VolumeUsage_BYTES,
Total: bcap,
},
},
}, nil
}
volumeMetrics, err := volume.NewMetricsStatFS(req.VolumePath).GetMetrics()
if err != nil {
return nil, err
}
available, ok := volumeMetrics.Available.AsInt64()
if !ok {
return nil, status.Errorf(codes.Internal, "failed to transform volume available size(%v)", volumeMetrics.Available)
}
capacity, ok := volumeMetrics.Capacity.AsInt64()
if !ok {
return nil, status.Errorf(codes.Internal, "failed to transform volume capacity size(%v)", volumeMetrics.Capacity)
}
used, ok := volumeMetrics.Used.AsInt64()
if !ok {
return nil, status.Errorf(codes.Internal, "failed to transform volume used size(%v)", volumeMetrics.Used)
}
inodesFree, ok := volumeMetrics.InodesFree.AsInt64()
if !ok {
return nil, status.Errorf(codes.Internal, "failed to transform disk inodes free(%v)", volumeMetrics.InodesFree)
}
inodes, ok := volumeMetrics.Inodes.AsInt64()
if !ok {
return nil, status.Errorf(codes.Internal, "failed to transform disk inodes(%v)", volumeMetrics.Inodes)
}
inodesUsed, ok := volumeMetrics.InodesUsed.AsInt64()
if !ok {
return nil, status.Errorf(codes.Internal, "failed to transform disk inodes used(%v)", volumeMetrics.InodesUsed)
}
return &csi.NodeGetVolumeStatsResponse{
Usage: []*csi.VolumeUsage{
{
Unit: csi.VolumeUsage_BYTES,
Available: available,
Total: capacity,
Used: used,
},
{
Unit: csi.VolumeUsage_INODES,
Available: inodesFree,
Total: inodes,
Used: inodesUsed,
},
},
}, nil
}
// NodeExpandVolume node expand volume
func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
}
capacityBytes := req.GetCapacityRange().GetRequiredBytes()
volSizeBytes := int64(capacityBytes)
requestGiB := volumehelper.RoundUpGiB(volSizeBytes)
volumePath := req.GetVolumePath()
if len(volumePath) == 0 {
return nil, status.Error(codes.InvalidArgument, "volume path must be provided")
}
isBlock, err := hostutil.NewHostUtil().PathIsDevice(volumePath)
if err != nil {
return nil, status.Errorf(codes.NotFound, "failed to determine device path for volumePath [%v]: %v", volumePath, err)
}
if isBlock {
// Noop for Block NodeExpandVolume
klog.V(4).Infof("NodeExpandVolume succeeded on %v to %s, path check is block so this is a no-op", volumeID, volumePath)
return &csi.NodeExpandVolumeResponse{}, nil
}
volumeCapability := req.GetVolumeCapability()
if volumeCapability != nil {
// VolumeCapability is optional, if specified, validate it
caps := []*csi.VolumeCapability{volumeCapability}
if !isValidVolumeCapabilities(caps) {
return nil, status.Error(codes.InvalidArgument, "VolumeCapability is invalid.")
}
if blk := volumeCapability.GetBlock(); blk != nil {
// Noop for Block NodeExpandVolume
// This should not be executed but if somehow it is set to Block we should be cautious
klog.Warningf("NodeExpandVolume succeeded on %v to %s, capability is block but block check failed to identify it", volumeID, volumePath)
return &csi.NodeExpandVolumeResponse{}, nil
}
}
devicePath, err := getDevicePathWithMountPath(volumePath, d.mounter)
if err != nil {
return nil, status.Errorf(codes.NotFound, err.Error())
}
if err := resizeVolume(devicePath, volumePath, d.mounter); err != nil {
return nil, status.Errorf(codes.Internal, "Could not resize volume %q (%q): %v", volumeID, devicePath, err)
}
gotBlockSizeBytes, err := getBlockSizeBytes(devicePath, d.mounter)
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("Could not get size of block volume at path %s: %v", devicePath, err))
}
gotBlockGiB := volumehelper.RoundUpGiB(gotBlockSizeBytes)
if gotBlockGiB < requestGiB {
// Because size was rounded up, getting more size than requested will be a success.
return nil, status.Errorf(codes.Internal, "resize requested for %v, but after resizing volume size was %v", requestGiB, gotBlockGiB)
}
klog.V(2).Infof("NodeExpandVolume succeeded on resizing volume %v to %v", volumeID, gotBlockSizeBytes)
return &csi.NodeExpandVolumeResponse{
CapacityBytes: gotBlockSizeBytes,
}, nil
}
func getFStype(attributes map[string]string) string {
for k, v := range attributes {
switch strings.ToLower(k) {
case fsTypeField:
return strings.ToLower(v)
}
}
return ""
}
// ensureMountPoint: create mount point if not exists
// return <true, nil> if it's already a mounted point otherwise return <false, nil>
func (d *Driver) ensureMountPoint(target string) (bool, error) {
notMnt, err := d.mounter.IsLikelyNotMountPoint(target)
if err != nil && !os.IsNotExist(err) {
if IsCorruptedDir(target) {
notMnt = false
klog.Warningf("detected corrupted mount for targetPath [%s]", target)
} else {
return !notMnt, err
}
}
if !notMnt {
// testing original mount point, make sure the mount link is valid
_, err := ioutil.ReadDir(target)
if err == nil {
klog.V(2).Infof("already mounted to target %s", target)
return !notMnt, nil
}
// mount link is invalid, now unmount and remount later
klog.Warningf("ReadDir %s failed with %v, unmount this directory", target, err)
if err := d.mounter.Unmount(target); err != nil {
klog.Errorf("Unmount directory %s failed with %v", target, err)
return !notMnt, err
}
notMnt = true
return !notMnt, err
}
if runtime.GOOS != "windows" {
// in windows, we will use mklink to mount, will MkdirAll in Mount func
if err := volumehelper.MakeDir(target); err != nil {
klog.Errorf("mkdir failed on target: %s (%v)", target, err)
return !notMnt, err
}
}
return !notMnt, nil
}
func (d *Driver) formatAndMount(source, target, fstype string, options []string) error {
return formatAndMount(source, target, fstype, options, d.mounter)
}
func (d *Driver) getDevicePathWithLUN(lunStr string) (string, error) {
lun, err := getDiskLUN(lunStr)
if err != nil {
return "", err
}
io := &osIOHandler{}
scsiHostRescan(io, d.mounter)
newDevicePath := ""
err = wait.PollImmediate(1*time.Second, 2*time.Minute, func() (bool, error) {
var err error
if newDevicePath, err = findDiskByLun(int(lun), io, d.mounter); err != nil {
return false, fmt.Errorf("azureDisk - findDiskByLun(%v) failed with error(%s)", lun, err)
}
// did we find it?
if newDevicePath != "" {
return true, nil
}
// wait until timeout
return false, nil
})
if err == nil && newDevicePath == "" {
err = fmt.Errorf("azureDisk - findDiskByLun(%v) failed within timeout", lun)
}
return newDevicePath, err
}
func (d *Driver) ensureBlockTargetFile(target string) error {
// Since the block device target path is file, its parent directory should be ensured to be valid.
parentDir := filepath.Dir(target)
if _, err := d.ensureMountPoint(parentDir); err != nil {
return status.Errorf(codes.Internal, "Could not mount target %q: %v", parentDir, err)
}
// Create the mount point as a file since bind mount device node requires it to be a file
klog.V(2).Infof("ensureBlockTargetFile [block]: making target file %s", target)
err := volumehelper.MakeFile(target)
if err != nil {
if removeErr := os.Remove(target); removeErr != nil {
return status.Errorf(codes.Internal, "Could not remove mount target %q: %v", target, removeErr)
}
return status.Errorf(codes.Internal, "Could not create file %q: %v", target, err)
}
return nil
}