Skip to content

Commit 7eadf80

Browse files
committed
Squashed commit of the following:
commit 92aa40e Author: weizhichen <[email protected]> Date: Fri Mar 24 00:38:44 2023 +0000 fix ut commit f1238c6 Author: weizhichen <[email protected]> Date: Wed Mar 22 07:57:01 2023 +0000 fix ut commit 114cdaf Author: weizhichen <[email protected]> Date: Wed Mar 22 07:46:33 2023 +0000 fix ut commit 67440cd Author: weizhichen <[email protected]> Date: Wed Mar 22 07:14:27 2023 +0000 fix gomod commit a2144d9 Author: weizhichen <[email protected]> Date: Wed Mar 22 07:08:42 2023 +0000 fix ut commit 411a3d4 Author: weizhichen <[email protected]> Date: Wed Mar 22 06:46:53 2023 +0000 fix commit 7c9a5c9 Author: weizhichen <[email protected]> Date: Tue Mar 21 06:31:42 2023 +0000 update vendor commit fcc9364 Author: weizhichen <[email protected]> Date: Tue Mar 21 03:45:44 2023 +0000 fix ut commit 9dcc6fa Author: weizhichen <[email protected]> Date: Mon Mar 20 13:52:54 2023 +0000 fix commit 0900961 Author: weizhichen <[email protected]> Date: Mon Mar 20 11:18:01 2023 +0000 add ut commit cd9c5dd Author: weizhichen <[email protected]> Date: Mon Mar 20 06:08:45 2023 +0000 Revert "fix: add workaround for blobfuse2 mount issue" This reverts commit fa9f8a5. commit 10e8617 Author: weizhichen <[email protected]> Date: Mon Mar 20 06:08:28 2023 +0000 fix : wait for blobfuse2 mount
1 parent 2b26492 commit 7eadf80

File tree

3 files changed

+91
-11
lines changed

3 files changed

+91
-11
lines changed

pkg/blob/nodeserver.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ import (
4646
mount_azure_blob "sigs.k8s.io/blob-csi-driver/pkg/blobfuse-proxy/pb"
4747
)
4848

49+
const (
50+
waitForMountInterval = 20 * time.Millisecond
51+
waitForMountTimeout = 3 * time.Second
52+
)
53+
4954
type MountClient struct {
5055
service mount_azure_blob.MountServiceClient
5156
}
@@ -182,11 +187,7 @@ func (d *Driver) mountBlobfuseInsideDriver(args string, protocol string, authEnv
182187
cmd.Env = append(os.Environ(), authEnv...)
183188
output, err := cmd.CombinedOutput()
184189
klog.V(2).Infof("mount output: %s\n", string(output))
185-
if err == nil && protocol == Fuse2 {
186-
// todo: remove this when https://github.com/Azure/azure-storage-fuse/issues/1079 is fixed
187-
klog.V(2).Infof("sleep 2s, waiting for blobfuse2 mount complete")
188-
time.Sleep(2 * time.Second)
189-
}
190+
190191
return string(output), err
191192
}
192193

@@ -399,6 +400,12 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
399400
return nil, err
400401
}
401402

403+
// wait a few seconds to make sure blobfuse mount is successful
404+
// please refer to https://github.com/Azure/azure-storage-fuse/pull/1088 for more details
405+
if err := waitForMount(targetPath, waitForMountInterval, waitForMountTimeout); err != nil {
406+
return nil, fmt.Errorf("failed to wait for mount: %w", err)
407+
}
408+
402409
klog.V(2).Infof("volume(%s) mount on %q succeeded", volumeID, targetPath)
403410
return &csi.NodeStageVolumeResponse{}, nil
404411
}
@@ -568,3 +575,24 @@ func (d *Driver) ensureMountPoint(target string, perm os.FileMode) (bool, error)
568575
}
569576
return !notMnt, nil
570577
}
578+
579+
func waitForMount(path string, intervel, timeout time.Duration) error {
580+
timeAfter := time.After(timeout)
581+
timeTick := time.Tick(intervel)
582+
583+
for {
584+
select {
585+
case <-timeTick:
586+
notMount, err := mount.New("").IsLikelyNotMountPoint(path)
587+
if err != nil {
588+
return err
589+
}
590+
if !notMount {
591+
klog.V(2).Infof("blobfuse mount at %s success", path)
592+
return nil
593+
}
594+
case <-timeAfter:
595+
return fmt.Errorf("timeout waiting for mount %s", path)
596+
}
597+
}
598+
}

pkg/blob/nodeserver_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
"path/filepath"
2525
"reflect"
2626
"runtime"
27+
"strings"
2728
"syscall"
2829
"testing"
30+
"time"
2931

3032
"google.golang.org/grpc"
3133
"google.golang.org/grpc/codes"
@@ -754,3 +756,59 @@ func TestMountBlobfuseInsideDriver(t *testing.T) {
754756
// the error should be of type exec.ExitError
755757
assert.NotNil(t, err)
756758
}
759+
760+
func Test_waitForMount(t *testing.T) {
761+
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
762+
t.Skip("Skipping test on ", runtime.GOOS)
763+
}
764+
765+
tmpDir, err := os.MkdirTemp("", "")
766+
assert.NoError(t, err)
767+
defer os.RemoveAll(tmpDir)
768+
769+
type args struct {
770+
path string
771+
intervel time.Duration
772+
timeout time.Duration
773+
}
774+
775+
tests := []struct {
776+
name string
777+
args args
778+
wantErr bool
779+
subErrMsg string
780+
}{
781+
{
782+
name: "test error timeout",
783+
args: args{
784+
path: tmpDir,
785+
intervel: 1 * time.Millisecond,
786+
timeout: 10 * time.Millisecond,
787+
},
788+
wantErr: true,
789+
subErrMsg: "timeout",
790+
},
791+
{
792+
name: "test error no such file or directory",
793+
args: args{
794+
path: "/no/such/file/or/directory",
795+
intervel: 1 * time.Millisecond,
796+
timeout: 10 * time.Millisecond,
797+
},
798+
wantErr: true,
799+
subErrMsg: "no such file or directory",
800+
},
801+
}
802+
803+
for _, tt := range tests {
804+
t.Run(tt.name, func(t *testing.T) {
805+
err := waitForMount(tt.args.path, tt.args.intervel, tt.args.timeout)
806+
if (err != nil) != tt.wantErr {
807+
t.Errorf("waitForMount() error = %v, wantErr %v", err, tt.wantErr)
808+
}
809+
if err != nil && !strings.Contains(err.Error(), tt.subErrMsg) {
810+
t.Errorf("waitForMount() error = %v, wantErr %v", err, tt.subErrMsg)
811+
}
812+
})
813+
}
814+
}

pkg/blobfuse-proxy/server/server.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"os/exec"
2424
"strings"
2525
"sync"
26-
"time"
2726

2827
"google.golang.org/grpc"
2928
"k8s.io/klog/v2"
@@ -96,11 +95,6 @@ func (server *MountServer) MountAzureBlob(ctx context.Context,
9695
if err != nil {
9796
return &result, fmt.Errorf("%w %s", err, result.Output)
9897
}
99-
if protocol == blob.Fuse2 || server.blobfuseVersion == BlobfuseV2 {
100-
// todo: remove this when https://github.com/Azure/azure-storage-fuse/issues/1079 is fixed
101-
klog.V(2).Infof("sleep 2s, waiting for blobfuse2 mount complete\n")
102-
time.Sleep(2 * time.Second)
103-
}
10498
return &result, nil
10599
}
106100

0 commit comments

Comments
 (0)