Skip to content

Commit

Permalink
Merge pull request #152 from elijah/elijah-patch-1
Browse files Browse the repository at this point in the history
Fix travis builds and update version numbers.
  • Loading branch information
gondor authored Jan 25, 2018
2 parents a26e6b3 + c698569 commit f4554bf
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.5.1
- 1.7.0
- tip
script:
- go test ./...
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ The method below will install the sysvinit and /etc/default options that can be
1. Install the Package

```
$ wget https://github.com/ContainX/docker-volume-netshare/releases/download/v0.20/docker-volume-netshare_0.20_amd64.deb
$ sudo dpkg -i docker-volume-netshare_0.20_amd64.deb
$ wget https://github.com/ContainX/docker-volume-netshare/releases/download/v0.34/docker-volume-netshare_0.34_amd64.deb
$ sudo dpkg -i docker-volume-netshare_0.34_amd64.deb
```

2. Modify the startup options in `/etc/default/docker-volume-netshare`
Expand Down
25 changes: 13 additions & 12 deletions netshare/drivers/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package drivers

import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
"os"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
)

const (
Expand Down Expand Up @@ -41,7 +42,7 @@ func NewCephDriver(root string, username string, password string, context string
return d
}

func (n cephDriver) Mount(r volume.MountRequest) volume.Response {
func (n cephDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) {
log.Debugf("Entering Mount: %v", r)
n.m.Lock()
defer n.m.Unlock()
Expand All @@ -50,22 +51,22 @@ func (n cephDriver) Mount(r volume.MountRequest) volume.Response {
if n.mountm.HasMount(r.Name) && n.mountm.Count(r.Name) > 0 {
log.Infof("Using existing CEPH volume mount: %s", hostdir)
n.mountm.Increment(r.Name)
return volume.Response{Mountpoint: hostdir}
return &volume.MountResponse{Mountpoint: hostdir}, nil
}

log.Infof("Mounting CEPH volume %s on %s", source, hostdir)
if err := createDest(hostdir); err != nil {
return volume.Response{Err: err.Error()}
return nil, err
}

if err := n.mountVolume(r.Name, source, hostdir); err != nil {
return volume.Response{Err: err.Error()}
return nil, err
}
n.mountm.Add(r.Name, hostdir)
return volume.Response{Mountpoint: hostdir}
return &volume.MountResponse{Mountpoint: hostdir}, nil
}

func (n cephDriver) Unmount(r volume.UnmountRequest) volume.Response {
func (n cephDriver) Unmount(r *volume.UnmountRequest) error {
log.Debugf("Entering Unmount: %v", r)

n.m.Lock()
Expand All @@ -76,24 +77,24 @@ func (n cephDriver) Unmount(r volume.UnmountRequest) volume.Response {
if n.mountm.Count(r.Name) > 1 {
log.Printf("Skipping unmount for %s - in use by other containers", r.Name)
n.mountm.Decrement(r.Name)
return volume.Response{}
return nil
}
n.mountm.Decrement(r.Name)
}

log.Infof("Unmounting volume name %s from %s", r.Name, hostdir)

if err := run(fmt.Sprintf("umount %s", hostdir)); err != nil {
return volume.Response{Err: err.Error()}
return err
}

n.mountm.DeleteIfNotManaged(r.Name)

if err := os.RemoveAll(hostdir); err != nil {
return volume.Response{Err: err.Error()}
return err
}

return volume.Response{}
return nil
}

func (n cephDriver) fixSource(name, id string) string {
Expand Down
27 changes: 14 additions & 13 deletions netshare/drivers/cifs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func parseNetRC(path string) *netrc.Netrc {
}

// Mount do the mounting
func (c CifsDriver) Mount(r volume.MountRequest) volume.Response {
func (c CifsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) {
c.m.Lock()
defer c.m.Unlock()
hostdir := mountpoint(c.root, r.Name)
Expand All @@ -98,34 +98,34 @@ func (c CifsDriver) Mount(r volume.MountRequest) volume.Response {
if err := run(fmt.Sprintf("mountpoint -q %s", hostdir)); err != nil {
log.Infof("Existing CIFS volume not mounted, force remount.")
} else {
return volume.Response{Mountpoint: hostdir}
return &volume.MountResponse{Mountpoint: hostdir}, nil
}
}

log.Infof("Mounting CIFS volume %s on %s", source, hostdir)

if err := createDest(hostdir); err != nil {
return volume.Response{Err: err.Error()}
return nil, err
}

if err := c.mountVolume(r.Name, source, hostdir, c.getCreds(host)); err != nil {
return volume.Response{Err: err.Error()}
return nil, err
}
c.mountm.Add(r.Name, hostdir)

if c.mountm.GetOption(resolvedName, ShareOpt) != "" && c.mountm.GetOptionAsBool(resolvedName, CreateOpt) {
log.Infof("Mount: Share and Create options enabled - using %s as sub-dir mount", resolvedName)
datavol := filepath.Join(hostdir, resolvedName)
if err := createDest(filepath.Join(hostdir, resolvedName)); err != nil {
return volume.Response{Err: err.Error()}
return nil, err
}
hostdir = datavol
}
return volume.Response{Mountpoint: hostdir}
return &volume.MountResponse{Mountpoint: hostdir}, nil
}

// Unmount do the unmounting
func (c CifsDriver) Unmount(r volume.UnmountRequest) volume.Response {
func (c CifsDriver) Unmount(r *volume.UnmountRequest) error {
c.m.Lock()
defer c.m.Unlock()
hostdir := mountpoint(c.root, r.Name)
Expand All @@ -135,15 +135,15 @@ func (c CifsDriver) Unmount(r volume.UnmountRequest) volume.Response {
if c.mountm.Count(r.Name) > 1 {
log.Infof("Skipping unmount for %s - in use by other containers", r.Name)
c.mountm.Decrement(r.Name)
return volume.Response{}
return nil
}
c.mountm.Decrement(r.Name)
}

log.Infof("Unmounting volume %s from %s", source, hostdir)

if err := run(fmt.Sprintf("umount %s", hostdir)); err != nil {
return volume.Response{Err: err.Error()}
return err
}

c.mountm.DeleteIfNotManaged(r.Name)
Expand All @@ -157,7 +157,7 @@ func (c CifsDriver) Unmount(r volume.UnmountRequest) volume.Response {
// return volume.Response{Err: err.Error()}
// }

return volume.Response{}
return nil
}

func (c CifsDriver) fixSource(name string) string {
Expand Down Expand Up @@ -217,9 +217,10 @@ func (c CifsDriver) mountVolume(name, source, dest string, creds *CifsCreds) err
}

if user != "" {
opts.WriteString(fmt.Sprintf("username=%s,", user))
// escape single quotes in password character as it will be quoted in command line
opts.WriteString(fmt.Sprintf("username='%s',", strings.Replace(user, "'", "\\'", -1)))
if pass != "" {
opts.WriteString(fmt.Sprintf("password=%s,", pass))
opts.WriteString(fmt.Sprintf("password='%s',", strings.Replace(pass, "'", "\\'", -1)))
}
} else {
opts.WriteString("guest,")
Expand All @@ -245,7 +246,7 @@ func (c CifsDriver) mountVolume(name, source, dest string, creds *CifsCreds) err

opts.WriteString(fmt.Sprintf("%s %s", source, dest))
cmd := fmt.Sprintf("mount -t cifs -o %s", opts.String())
log.Debugf("Executing: %s\n", strings.Replace(cmd, "password="+pass, "password=****", 1))
log.Debugf("Executing: %s\n", strings.Replace(cmd, "password='"+pass+"'", "password='****'", 1))
return run(cmd)
}

Expand Down
39 changes: 20 additions & 19 deletions netshare/drivers/driver.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package drivers

import (
"sync"

log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
"sync"
)

type volumeDriver struct {
Expand All @@ -20,7 +21,7 @@ func newVolumeDriver(root string) volumeDriver {
}
}

func (v volumeDriver) Create(r volume.Request) volume.Response {
func (v volumeDriver) Create(r *volume.CreateRequest) error {
log.Debugf("Entering Create: name: %s, options %v", r.Name, r.Options)

v.m.Lock()
Expand All @@ -37,35 +38,35 @@ func (v volumeDriver) Create(r volume.Request) volume.Response {

dest := mountpoint(v.root, resName)
if err := createDest(dest); err != nil {
return volume.Response{Err: err.Error()}
return err
}

v.mountm.Create(resName, dest, r.Options)
return volume.Response{}
return nil
}

func (v volumeDriver) Remove(r volume.Request) volume.Response {
func (v volumeDriver) Remove(r *volume.RemoveRequest) error {

resolvedName, _ := resolveName(r.Name)

log.Debugf("Entering Remove: name: %s, resolved-name: %s, options %v", r.Name, resolvedName, r.Options)
log.Debugf("Entering Remove: name: %s, resolved-name: %s", r.Name, resolvedName)
v.m.Lock()
defer v.m.Unlock()

if err := v.mountm.Delete(resolvedName); err != nil {
return volume.Response{Err: err.Error()}
return err
}
return volume.Response{}
return nil
}

func (v volumeDriver) Path(r volume.Request) volume.Response {
func (v volumeDriver) Path(r *volume.PathRequest) (*volume.PathResponse, error) {
resolvedName, _ := resolveName(r.Name)

log.Debugf("Host path for %s (%s) is at %s", r.Name, resolvedName, mountpoint(v.root, resolvedName))
return volume.Response{Mountpoint: mountpoint(v.root, resolvedName)}
return &volume.PathResponse{Mountpoint: mountpoint(v.root, resolvedName)}, nil
}

func (v volumeDriver) Get(r volume.Request) volume.Response {
func (v volumeDriver) Get(r *volume.GetRequest) (*volume.GetResponse, error) {
log.Debugf("Entering Get: %v", r)
v.m.Lock()
defer v.m.Unlock()
Expand All @@ -75,19 +76,19 @@ func (v volumeDriver) Get(r volume.Request) volume.Response {

if v.mountm.HasMount(resolvedName) {
log.Debugf("Get: mount found for %s, host directory: %s", resolvedName, hostdir)
return volume.Response{Volume: &volume.Volume{Name: resolvedName, Mountpoint: hostdir}}
return &volume.GetResponse{Volume: &volume.Volume{Name: resolvedName, Mountpoint: hostdir}}, nil
}
return volume.Response{}
return nil, nil
}

func (v volumeDriver) List(r volume.Request) volume.Response {
log.Debugf("Entering List: %v", r)
return volume.Response{Volumes: v.mountm.GetVolumes(v.root)}
func (v volumeDriver) List() (*volume.ListResponse, error) {
log.Debugf("Entering List")
return &volume.ListResponse{Volumes: v.mountm.GetVolumes(v.root)}, nil
}

func (v volumeDriver) Capabilities(r volume.Request) volume.Response {
log.Debugf("Entering Capabilities: %v", r)
return volume.Response{
func (v volumeDriver) Capabilities() *volume.CapabilitiesResponse {
// log.Debugf("Entering Capabilities: %v", r)
return &volume.CapabilitiesResponse{
Capabilities: volume.Capability{
Scope: "local",
},
Expand Down
33 changes: 17 additions & 16 deletions netshare/drivers/efs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package drivers

import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
"os"
"regexp"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/docker/go-plugins-helpers/volume"
)

const (
Expand All @@ -15,10 +16,10 @@ const (

type efsDriver struct {
volumeDriver
resolve bool
region string
resolver *Resolver
dnscache map[string]string
resolve bool
region string
resolver *Resolver
dnscache map[string]string
}

func NewEFSDriver(root, nameserver string, resolve bool) efsDriver {
Expand All @@ -41,7 +42,7 @@ func NewEFSDriver(root, nameserver string, resolve bool) efsDriver {
return d
}

func (e efsDriver) Mount(r volume.MountRequest) volume.Response {
func (e efsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) {
e.m.Lock()
defer e.m.Unlock()
hostdir := mountpoint(e.root, r.Name)
Expand All @@ -50,23 +51,23 @@ func (e efsDriver) Mount(r volume.MountRequest) volume.Response {
if e.mountm.HasMount(r.Name) && e.mountm.Count(r.Name) > 0 {
log.Infof("Using existing EFS volume mount: %s", hostdir)
e.mountm.Increment(r.Name)
return volume.Response{Mountpoint: hostdir}
return &volume.MountResponse{Mountpoint: hostdir}, nil
}

log.Infof("Mounting EFS volume %s on %s", source, hostdir)

if err := createDest(hostdir); err != nil {
return volume.Response{Err: err.Error()}
return nil, err
}

if err := e.mountVolume(source, hostdir); err != nil {
return volume.Response{Err: err.Error()}
return nil, err
}
e.mountm.Add(r.Name, hostdir)
return volume.Response{Mountpoint: hostdir}
return &volume.MountResponse{Mountpoint: hostdir}, nil
}

func (e efsDriver) Unmount(r volume.UnmountRequest) volume.Response {
func (e efsDriver) Unmount(r *volume.UnmountRequest) error {
e.m.Lock()
defer e.m.Unlock()
hostdir := mountpoint(e.root, r.Name)
Expand All @@ -76,24 +77,24 @@ func (e efsDriver) Unmount(r volume.UnmountRequest) volume.Response {
if e.mountm.Count(r.Name) > 1 {
log.Infof("Skipping unmount for %s - in use by other containers", hostdir)
e.mountm.Decrement(r.Name)
return volume.Response{}
return nil
}
e.mountm.Decrement(r.Name)
}

log.Infof("Unmounting volume %s from %s", source, hostdir)

if err := run(fmt.Sprintf("umount %s", hostdir)); err != nil {
return volume.Response{Err: err.Error()}
return err
}

e.mountm.DeleteIfNotManaged(r.Name)

if err := os.RemoveAll(r.Name); err != nil {
return volume.Response{Err: err.Error()}
return err
}

return volume.Response{}
return nil
}

func (e efsDriver) fixSource(name, id string) string {
Expand Down
Loading

0 comments on commit f4554bf

Please sign in to comment.