Skip to content

Commit d03d5e3

Browse files
sfc-gh-guwangEdSchouten
authored andcommitted
Replace FUSE's direct_mount option with mount_method
When enabling direct_mount, go-fuse attempts to create a FUSE mount directly, using the mount(2) system call. If that fails, it falls back to using the fusermount utility. What's annoying is that this causes any errors returned by mount(2) to be suppressed. go-fuse solved this by adding a DirectMountStrict option, which disables the fallback behaviour. This change exposes go-fuse's DirectMountStrict feature. Instead of adding a separate boolean flag for it, we promote the existing direct_mount configuration option to an enumeration named mount_method. This means that if your configuration previously contained: directMount: true, You need to replace it with either one of the lines below, depending on whether you want to still fall back to calling fusermount: mountMethod: 'DIRECT', mountMethod: 'DIRECT_AND_FUSERMOUNT', Fixes: buildbarn#156
1 parent b7b3bc4 commit d03d5e3

File tree

3 files changed

+250
-156
lines changed

3 files changed

+250
-156
lines changed

pkg/filesystem/virtual/configuration/fuse_mount_enabled.go

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import (
88

99
"github.com/buildbarn/bb-remote-execution/pkg/filesystem/virtual"
1010
"github.com/buildbarn/bb-remote-execution/pkg/filesystem/virtual/fuse"
11+
pb "github.com/buildbarn/bb-remote-execution/pkg/proto/configuration/filesystem/virtual"
1112
"github.com/buildbarn/bb-storage/pkg/clock"
1213
"github.com/buildbarn/bb-storage/pkg/filesystem"
1314
"github.com/buildbarn/bb-storage/pkg/program"
1415
"github.com/buildbarn/bb-storage/pkg/util"
1516
go_fuse "github.com/hanwen/go-fuse/v2/fuse"
1617
"github.com/jmespath/go-jmespath"
18+
19+
"google.golang.org/grpc/codes"
20+
"google.golang.org/grpc/status"
1721
)
1822

1923
func (m *fuseMount) Expose(terminationGroup program.Group, rootDirectory virtual.Directory) error {
@@ -45,6 +49,35 @@ func (m *fuseMount) Expose(terminationGroup program.Group, rootDirectory virtual
4549
// Launch the FUSE server.
4650
removeStaleMounts(m.mountPath)
4751
deterministicTimestamp := uint64(filesystem.DeterministicFileModificationTimestamp.Unix())
52+
mountOptions := &go_fuse.MountOptions{
53+
// The name isn't strictly necessary, but is
54+
// filled in to prevent runc from crashing with
55+
// this error:
56+
// https://github.com/opencontainers/runc/blob/v1.0.0-rc10/libcontainer/mount/mount_linux.go#L69
57+
//
58+
// Newer versions of runc use an improved parser
59+
// that's more reliable:
60+
// https://github.com/moby/sys/blob/master/mountinfo/mountinfo_linux.go
61+
FsName: m.fsName,
62+
AllowOther: m.configuration.AllowOther,
63+
// Speed up workloads that perform many tiny
64+
// writes. This means data is only guaranteed to
65+
// make it into the virtual file system after
66+
// calling close()/fsync()/munmap()/msync().
67+
EnableWritebackCache: true,
68+
}
69+
70+
switch m.configuration.MountMethod {
71+
case pb.FUSEMountConfiguration_FUSERMOUNT:
72+
// go-fuse uses fusermount by default.
73+
case pb.FUSEMountConfiguration_DIRECT:
74+
mountOptions.DirectMountStrict = true
75+
case pb.FUSEMountConfiguration_DIRECT_AND_FUSERMOUNT:
76+
mountOptions.DirectMount = true
77+
default:
78+
return status.Error(codes.InvalidArgument, "Invalid mount method")
79+
}
80+
4881
server, err := go_fuse.NewServer(
4982
fuse.NewMetricsRawFileSystem(
5083
fuse.NewDefaultAttributesInjectingRawFileSystem(
@@ -61,24 +94,8 @@ func (m *fuseMount) Expose(terminationGroup program.Group, rootDirectory virtual
6194
}),
6295
clock.SystemClock),
6396
m.mountPath,
64-
&go_fuse.MountOptions{
65-
// The name isn't strictly necessary, but is
66-
// filled in to prevent runc from crashing with
67-
// this error:
68-
// https://github.com/opencontainers/runc/blob/v1.0.0-rc10/libcontainer/mount/mount_linux.go#L69
69-
//
70-
// Newer versions of runc use an improved parser
71-
// that's more reliable:
72-
// https://github.com/moby/sys/blob/master/mountinfo/mountinfo_linux.go
73-
FsName: m.fsName,
74-
AllowOther: m.configuration.AllowOther,
75-
DirectMount: m.configuration.DirectMount,
76-
// Speed up workloads that perform many tiny
77-
// writes. This means data is only guaranteed to
78-
// make it into the virtual file system after
79-
// calling close()/fsync()/munmap()/msync().
80-
EnableWritebackCache: true,
81-
})
97+
mountOptions,
98+
)
8299
if err != nil {
83100
return util.StatusWrap(err, "Failed to create FUSE server")
84101
}

0 commit comments

Comments
 (0)