Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

mount: Log params and validate #171

Merged
merged 1 commit into from
Mar 21, 2018
Merged
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
28 changes: 28 additions & 0 deletions mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
package main

import (
"fmt"
"os"
"path/filepath"
"strings"
"syscall"

"github.com/kata-containers/agent/pkg/uevent"
pb "github.com/kata-containers/agent/protocols/grpc"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"google.golang.org/grpc/codes"
grpcStatus "google.golang.org/grpc/status"
Expand Down Expand Up @@ -68,6 +70,32 @@ func createDestinationDir(dest string) error {
func mount(source, destination, fsType string, flags int, options string) error {
var absSource string

// Log before validation. This is useful to debug cases where the gRPC
// protocol version being used by the client is out-of-sync with the
// agents version. gRPC message members are strictly ordered, so it's
// quite possible that if the protocol changes, the client may
// try to pass a valid mountpoint, but the gRPC layer may change that
// through the member ordering to be a mount *option* for example.
agentLog.WithFields(logrus.Fields{
"mount-source": source,
"mount-destination": destination,
"mount-fstype": fsType,
"mount-flags": flags,
"mount-options": options,
}).Debug()

if source == "" {
return fmt.Errorf("need mount source")
}

if destination == "" {
return fmt.Errorf("need mount destination")
}

if fsType == "" {
return fmt.Errorf("need mount FS type")
}

if fsType != type9pFs {
var err error

Expand Down
31 changes: 31 additions & 0 deletions mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,34 @@ func TestAddStoragesNoopHandlerFailure(t *testing.T) {

testAddStoragesFailure(t, storages)
}

func TestMount(t *testing.T) {
assert := assert.New(t)

type testData struct {
source string
destination string
fsType string
flags int
options string

expectError bool
}

data := []testData{
{"", "", "", 0, "", true},
{"", "/foo", "9p", 0, "", true},
{"proc", "", "9p", 0, "", true},
{"proc", "/proc", "", 0, "", true},
}

for i, d := range data {
err := mount(d.source, d.destination, d.fsType, d.flags, d.options)

if d.expectError {
assert.Errorf(err, "test %d (%+v)", i, d)
} else {
assert.NoErrorf(err, "test %d (%+v)", i, d)
}
}
}