Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] support mapped btrfs devices on Linux #48

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 2 additions & 0 deletions cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
defaultServerCount = 1
)

var defaultBindMounts = []string{"/dev/mapper:/dev/mapper"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this shouldn't be in defaultBindMounts, since it's not default, but only added in specific cases, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sortof, it checks if it exists so it's a defaultBindMount but only applied when it exists. Could change that naming, but not sure what that'd get us since it's still sorta a default.


// CheckTools checks if the docker API server is responding
func CheckTools(c *cli.Context) error {
log.Print("Checking docker...")
Expand Down
56 changes: 56 additions & 0 deletions cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package run

import (
"fmt"
"log"
"math/rand"
"os"
"net"
"strconv"
"strings"
Expand Down Expand Up @@ -90,6 +92,60 @@ func ValidateHostname(name string) error {
return nil
}

// checkDefaultBindMounts takes a volumes slice and a defaults slice
// and appends the volumes to the defaults, with respect to already set vaules
// in defaults in volumes, so as to not cause duplication of the same string.
func checkDefaultBindMounts(volumes []string, defaults []string) []string {
newVols := make([]string, 0)
destHm := make(map[string]int)

// populate the desthm with indexes in the defaults
for i, v := range defaults {
p := strings.Split(v, ":")
if len(p) != 2 {
continue
}

destPath := p[1]
destHm[destPath] = i
}

// check if we overrode a default in the -v, if so, remove
// that default bind mount from ever being processed.
for _, v := range volumes {
p := strings.Split(v, ":")
if len(p) != 2 {
continue
}

destPath := p[1]
if i, ok := destHm[destPath]; ok {
defaults[i] = defaults[len(defaults)-1]
defaults[len(defaults)-1] = ""
defaults = defaults[:len(defaults)-1]
}
}

// add the defaults, checking to ensure that the local path (if it's a :) exists
for _, v := range defaults {
p := strings.Split(v, ":")
if len(p) > 1 {
// check if the path of a local:remote exists
if _, err := os.Stat(p[0]); os.IsNotExist(err) {
continue
}

log.Printf("Including extra mount '%s' due to local path existing", v)
}

newVols = append(newVols, v)
}

newVols = append(newVols, volumes...)

return newVols
}

func parseApiPort(portSpec string) (*apiPort, error) {
var port *apiPort
split := strings.Split(portSpec, ":")
Expand Down