Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 52 additions & 14 deletions pkg/filesystem/virtual/configuration/nfsv4_mount_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,48 @@ func (m *nfsv4Mount) mount(terminationGroup program.Group, rpcServer *rpcserver.
if !ok {
return status.Error(codes.InvalidArgument, "Darwin specific NFSv4 server configuration options not provided")
}

// Expose the NFSv4 server on a UNIX socket.
osConfiguration := darwinConfiguration.Darwin
if err := os.Remove(osConfiguration.SocketPath); err != nil && !os.IsNotExist(err) {
return util.StatusWrapf(err, "Could not remove stale socket for NFSv4 server %#v", osConfiguration.SocketPath)
}
sock, err := net.Listen("unix", osConfiguration.SocketPath)
if err != nil {
return util.StatusWrap(err, "Failed to create listening socket for NFSv4 server")

// Expose the NFSv4 server.
var sock net.Listener
var socketType string
var serverAddress string
var tcpAddr *net.TCPAddr

switch transport := osConfiguration.Transport.(type) {
case *pb.NFSv4DarwinMountConfiguration_SocketPath:
if err := os.Remove(transport.SocketPath); err != nil && !os.IsNotExist(err) {
return util.StatusWrapf(err, "Could not remove stale socket for NFSv4 server %#v", transport.SocketPath)
}
var err error
sock, err = net.Listen("unix", transport.SocketPath)
if err != nil {
return util.StatusWrap(err, "Failed to create listening socket for NFSv4 server")
}
// "ticotsord" is the X/Open Transport Interface (XTI)
// equivalent of AF_LOCAL with SOCK_STREAM.
socketType = "ticotsord"
serverAddress = transport.SocketPath

case *pb.NFSv4DarwinMountConfiguration_TcpAddress:
var err error
sock, err = net.Listen("tcp", transport.TcpAddress)
if err != nil {
return util.StatusWrapf(err, "Failed to create TCP listener for NFSv4 server on %#v", transport.TcpAddress)
}
socketType = "tcp"
tcpAddr = sock.Addr().(*net.TCPAddr)
if tcpAddr.IP.IsUnspecified() {
// Binding to all interfaces; use loopback for the kernel to connect.
serverAddress = "127.0.0.1"
} else {
serverAddress = tcpAddr.IP.String()
}

default:
return status.Error(codes.InvalidArgument, "No transport configuration provided")
}

// TODO: Run this as part of the program.Group, so that it gets
// cleaned up upon shutdown.
go func() {
Expand Down Expand Up @@ -181,24 +213,30 @@ func (m *nfsv4Mount) mount(terminationGroup program.Group, rpcServer *rpcserver.
attrMask[0] |= (1 << nfs_sys_prot.NFS_MATTR_ATTRCACHE_DIR_MIN) | (1 << nfs_sys_prot.NFS_MATTR_ATTRCACHE_DIR_MAX)
writeAttributeCachingDuration(&m.childDirectoriesAttributeCaching, &attrVals)

// "ticotsord" is the X/Open Transport Interface (XTI)
// equivalent of AF_LOCAL with SOCK_STREAM.
attrMask[0] |= 1 << nfs_sys_prot.NFS_MATTR_SOCKET_TYPE
nfs_sys_prot.WriteNfsMattrSocketType(&attrVals, "ticotsord")
nfs_sys_prot.WriteNfsMattrSocketType(&attrVals, socketType)

// For TCP transport, set NFS_PORT before FS_LOCATIONS.
if tcpAddr != nil {
attrMask[0] |= 1 << nfs_sys_prot.NFS_MATTR_NFS_PORT
nfs_sys_prot.WriteNfsMattrNfsPort(&attrVals, uint32(tcpAddr.Port))
}

attrMask[0] |= 1 << nfs_sys_prot.NFS_MATTR_FS_LOCATIONS
fsLocations := nfs_sys_prot.NfsFsLocations{
NfslLocation: []nfs_sys_prot.NfsFsLocation{{
NfslServer: []nfs_sys_prot.NfsFsServer{{
NfssName: m.fsName,
NfssAddress: []string{osConfiguration.SocketPath},
NfssAddress: []string{serverAddress},
}},
}},
}
fsLocations.WriteTo(&attrVals)

attrMask[0] |= 1 << nfs_sys_prot.NFS_MATTR_LOCAL_NFS_PORT
nfs_sys_prot.WriteNfsMattrLocalNfsPort(&attrVals, osConfiguration.SocketPath)
if tcpAddr == nil {
attrMask[0] |= 1 << nfs_sys_prot.NFS_MATTR_LOCAL_NFS_PORT
nfs_sys_prot.WriteNfsMattrLocalNfsPort(&attrVals, serverAddress)
}

if m.leavesAttributeCaching == NoAttributeCaching {
attrMask[1] |= 1 << (nfs_sys_prot.NFS_MATTR_READLINK_NOCACHE - 32)
Expand Down
65 changes: 55 additions & 10 deletions pkg/proto/configuration/filesystem/virtual/virtual.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 24 additions & 13 deletions pkg/proto/configuration/filesystem/virtual/virtual.proto
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,30 @@ message NFSv4MountConfiguration {
}

message NFSv4DarwinMountConfiguration {
// Path on which to bind the UNIX socket of the NFSv4 server. The
// kernel will connect to this socket when mounting.
//
// NOTE: No facilities are provided to set the ownership or
// permissions on the socket file. On most operating systems, the
// socket file will have mode 0777. How the mode is interpreted when
// changed is inconsistent between operating systems. Some require the
// socket to be writable in order to connect, while others ignore the
// permissions altogether.
//
// It is therefore strongly advised that socket files are placed
// inside directories that have access controls set up properly.
string socket_path = 1;
// Transport configuration for the NFSv4 server.
oneof transport {
// Path on which to bind the UNIX socket of the NFSv4 server. The
// kernel will connect to this socket when mounting.
//
// NOTE: No facilities are provided to set the ownership or
// permissions on the socket file. On most operating systems, the
// socket file will have mode 0777. How the mode is interpreted when
// changed is inconsistent between operating systems. Some require the
// socket to be writable in order to connect, while others ignore the
// permissions altogether.
//
// It is therefore strongly advised that socket files are placed
// inside directories that have access controls set up properly.
string socket_path = 1;

// TCP address on which to bind the NFSv4 server (e.g.,
// "localhost:2049", "127.0.0.1:2049", or ":2049"). The kernel will
// connect to this address when mounting.
//
// If a wildcard address is specified (e.g., ":2049" or
// "0.0.0.0:2049"), the kernel will connect via loopback.
string tcp_address = 6;
}

// Was 'minimum_directories_attribute_cache_timeout' and
// 'maximum_directories_attribute_cache_timeout'. These options are
Expand Down
Loading