Commit 82ab4b09 authored by Cyrill Troxler's avatar Cyrill Troxler
Browse files

Add experimental s3backer mounter

This also adds some generic handling of stale umounts.
Fuse returns immediately and does not indicate that
the mounter has finished writing to the backend.
The process finding is sort of hacky as I could not
find a better way to get to the PID from a fuse mount.
parent 108364fb
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -158,6 +158,12 @@
  packages = ["."]
  revision = "3864e76763d94a6df2f9960b16a20a33da9f9a66"

[[projects]]
  branch = "master"
  name = "github.com/mitchellh/go-ps"
  packages = ["."]
  revision = "4fdf99ab29366514c69ccccddab5dc58b8d84062"

[[projects]]
  name = "github.com/onsi/ginkgo"
  packages = [
@@ -372,6 +378,6 @@
[solve-meta]
  analyzer-name = "dep"
  analyzer-version = 1
  inputs-digest = "659f47734b56af7fba146039231841e82cc4c3c95dff2814ec3688e967790a50"
  inputs-digest = "a655e5231fe7b5c962579c8f032338c53177a95a3160bef4628f0761f714f730"
  solver-name = "gps-cdcl"
  solver-version = 1
+4 −0
Original line number Diff line number Diff line
@@ -41,3 +41,7 @@
[[constraint]]
  name = "gopkg.in/ini.v1"
  version = "1.38.1"

[[constraint]]
  branch = "master"
  name = "github.com/mitchellh/go-ps"
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ build:
	if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi
	CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/s3driver ./cmd/s3driver
test:
	docker build -t $(TEST_IMAGE_TAG) -f test/Dockerfile .
	docker build -t $(TEST_IMAGE_TAG) -f test/Dockerfile.s3backer .
	docker run --rm --privileged -v $(PWD):$(PROJECT_DIR):ro -v /dev:/dev $(TEST_IMAGE_TAG)
container: build
	docker build -t $(IMAGE_TAG) -f cmd/s3driver/Dockerfile.s3ql .
+43 −4
Original line number Diff line number Diff line
package s3

import "fmt"
import (
	"fmt"
	"os/exec"

	"github.com/golang/glog"
	"k8s.io/kubernetes/pkg/util/mount"
)

// Mounter interface which can be implemented
// by the different mounter types
@@ -14,6 +20,7 @@ const (
	s3fsMounterType     = "s3fs"
	goofysMounterType   = "goofys"
	s3qlMounterType     = "s3ql"
	s3backerMounterType = "s3backer"
)

// newMounter returns a new mounter depending on the mounterType parameter
@@ -28,6 +35,38 @@ func newMounter(bucket string, cfg *Config) (Mounter, error) {
	case s3qlMounterType:
		return newS3qlMounter(bucket, cfg)

	case s3backerMounterType:
		return newS3backerMounter(bucket, cfg)

	}
	return nil, fmt.Errorf("Error mounting bucket %s, invalid mounter specified: %s", bucket, cfg.Mounter)
}

func fuseMount(path string, command string, args []string) error {
	cmd := exec.Command(command, args...)

	out, err := cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("Error fuseMount command: %s\nargs: %s\noutput: %s", command, args, out)
	}

	return nil
}

func fuseUnmount(path string, command string) error {
	if err := mount.New("").Unmount(path); err != nil {
		return err
	}
	// as fuse quits immediately, we will try to wait until the process is done
	process, err := findFuseMountProcess(path, command)
	if err != nil {
		glog.Errorf("Error getting PID of fuse mount: %s", err)
		return nil
	}
	if process == nil {
		glog.Warningf("Unable to find PID of fuse mount %s, it must have finished already", path)
		return nil
	}
	glog.Infof("Found fuse pid %v of mount %s, checking if it still runs", process.Pid, path)
	return waitForProcess(process, 1)
}
+5 −3
Original line number Diff line number Diff line
@@ -7,10 +7,12 @@ import (
	"context"

	goofysApi "github.com/kahing/goofys/api"
	"k8s.io/kubernetes/pkg/util/mount"
)

const defaultRegion = "us-east-1"
const (
	goofysCmd     = "goofys"
	defaultRegion = "us-east-1"
)

// Implements Mounter
type goofysMounter struct {
@@ -64,5 +66,5 @@ func (goofys *goofysMounter) Mount(targetPath string) error {
}

func (goofys *goofysMounter) Unmount(targetPath string) error {
	return mount.New("").Unmount(targetPath)
	return fuseUnmount(targetPath, goofysCmd)
}
Loading