Skip to content

Commit 4916843

Browse files
committed
fix merge conflicts
2 parents dc90c6a + ef4b683 commit 4916843

File tree

7 files changed

+92
-267
lines changed

7 files changed

+92
-267
lines changed

config.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"description": "NFS/EFS/Samba/Ceph plugin for Docker",
3+
"documentation": "https://netshare.containx.io",
4+
"entrypoint": [
5+
"/docker-volume-netshare"
6+
],
7+
"env": [
8+
{
9+
"name": "DEBUG",
10+
"settable": [
11+
"value"
12+
],
13+
"value": "0"
14+
}
15+
],
16+
"interface": {
17+
"socket": "netshare.sock",
18+
"types": [
19+
"docker.volumedriver/1.0"
20+
]
21+
},
22+
"linux": {
23+
"capabilities": [
24+
"CAP_SYS_ADMIN"
25+
],
26+
"devices": [
27+
{
28+
"path": "/dev/fuse"
29+
}
30+
]
31+
},
32+
"mounts": [
33+
{
34+
"destination": "/mnt/state",
35+
"options": [
36+
"rbind"
37+
],
38+
"source": "/var/lib/docker/plugins/",
39+
"type": "bind"
40+
}
41+
],
42+
"network": {
43+
"type": "host"
44+
},
45+
"propagatedmount": "/mnt/volumes"
46+
}

netshare/drivers/ceph.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ type cephDriver struct {
2323
cephopts map[string]string
2424
}
2525

26-
//var (
27-
// EmptyMap = map[string]string{}
28-
//)
29-
3026
func NewCephDriver(root string, username string, password string, context string, cephmount string, cephport string, localmount string, cephopts string) cephDriver {
3127
d := cephDriver{
3228
volumeDriver: newVolumeDriver(root),

netshare/drivers/cifs.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,29 @@ func (c cifsDriver) Mount(r volume.MountRequest) volume.Response {
6767
c.m.Lock()
6868
defer c.m.Unlock()
6969
hostdir := mountpoint(c.root, r.Name)
70-
source := c.fixSource(r.Name, r.ID)
70+
source := c.fixSource(r.Name)
7171
host := c.parseHost(r.Name)
7272

73+
resolvedName, resOpts := resolveName(r.Name)
74+
7375
log.Infof("Mount: %s, ID: %s", r.Name, r.ID)
7476

77+
// Support adhoc mounts (outside of docker volume create)
78+
// need to adjust source for ShareOpt
79+
if resOpts != nil {
80+
if share, found := resOpts[ShareOpt]; found {
81+
source = c.fixSource(share)
82+
}
83+
}
84+
7585
if c.mountm.HasMount(r.Name) && c.mountm.Count(r.Name) > 0 {
7686
log.Infof("Using existing CIFS volume mount: %s", hostdir)
7787
c.mountm.Increment(r.Name)
78-
return volume.Response{Mountpoint: hostdir}
88+
if err := run(fmt.Sprintf("mountpoint -q %s", hostdir)); err != nil {
89+
log.Infof("Existing CIFS volume not mounted, force remount.")
90+
} else {
91+
return volume.Response{Mountpoint: hostdir}
92+
}
7993
}
8094

8195
log.Infof("Mounting CIFS volume %s on %s", source, hostdir)
@@ -88,14 +102,23 @@ func (c cifsDriver) Mount(r volume.MountRequest) volume.Response {
88102
return volume.Response{Err: err.Error()}
89103
}
90104
c.mountm.Add(r.Name, hostdir)
105+
106+
if c.mountm.GetOption(resolvedName, ShareOpt) != "" && c.mountm.GetOptionAsBool(resolvedName, CreateOpt) {
107+
log.Infof("Mount: Share and Create options enabled - using %s as sub-dir mount", resolvedName)
108+
datavol := filepath.Join(hostdir, resolvedName)
109+
if err := createDest(filepath.Join(hostdir, resolvedName)); err != nil {
110+
return volume.Response{Err: err.Error()}
111+
}
112+
hostdir = datavol
113+
}
91114
return volume.Response{Mountpoint: hostdir}
92115
}
93116

94117
func (c cifsDriver) Unmount(r volume.UnmountRequest) volume.Response {
95118
c.m.Lock()
96119
defer c.m.Unlock()
97120
hostdir := mountpoint(c.root, r.Name)
98-
source := c.fixSource(r.Name, r.ID)
121+
source := c.fixSource(r.Name)
99122

100123
if c.mountm.HasMount(r.Name) {
101124
if c.mountm.Count(r.Name) > 1 {
@@ -121,7 +144,7 @@ func (c cifsDriver) Unmount(r volume.UnmountRequest) volume.Response {
121144
return volume.Response{}
122145
}
123146

124-
func (c cifsDriver) fixSource(name, id string) string {
147+
func (c cifsDriver) fixSource(name string) string {
125148
if c.mountm.HasOption(name, ShareOpt) {
126149
return "//" + c.mountm.GetOption(name, ShareOpt)
127150
}

netshare/drivers/mounts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (m *mountManager) Increment(name string) int {
141141

142142
func (m *mountManager) Decrement(name string) int {
143143
c, found := m.mounts[name]
144-
if found {
144+
if found && c.connections > 0 {
145145
c.connections--
146146
}
147147
return 0

netshare/drivers/nfs.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ func (n nfsDriver) Mount(r volume.MountRequest) volume.Response {
5757
if n.mountm.HasMount(resolvedName) && n.mountm.Count(resolvedName) > 0 {
5858
log.Infof("Using existing NFS volume mount: %s", hostdir)
5959
n.mountm.Increment(resolvedName)
60-
if err := run(fmt.Sprintf("mountpoint -q %s", hostdir)); err != nil {
60+
if err := run(fmt.Sprintf("grep -c %s /proc/mounts", hostdir)); err != nil {
6161
log.Infof("Existing NFS volume not mounted, force remount.")
6262
} else {
63+
n.mountm.Increment(resolvedName)
6364
return volume.Response{Mountpoint: hostdir}
6465
}
6566
}
@@ -74,10 +75,11 @@ func (n nfsDriver) Mount(r volume.MountRequest) volume.Response {
7475
n.mountm.Create(resolvedName, hostdir, resOpts)
7576
}
7677

78+
n.mountm.Add(resolvedName, hostdir)
79+
7780
if err := n.mountVolume(resolvedName, source, hostdir, n.version); err != nil {
7881
return volume.Response{Err: err.Error()}
7982
}
80-
n.mountm.Add(resolvedName, hostdir)
8183

8284
if n.mountm.GetOption(resolvedName, ShareOpt) != "" && n.mountm.GetOptionAsBool(resolvedName, CreateOpt) {
8385
log.Infof("Mount: Share and Create options enabled - using %s as sub-dir mount", resolvedName)
@@ -119,9 +121,14 @@ func (n nfsDriver) Unmount(r volume.UnmountRequest) volume.Response {
119121

120122
n.mountm.DeleteIfNotManaged(resolvedName)
121123

122-
if err := os.RemoveAll(hostdir); err != nil {
123-
return volume.Response{Err: err.Error()}
124-
}
124+
// Check if directory is empty. This command will return "err" if empty
125+
if err := run(fmt.Sprintf("ls -1 %s | grep .", hostdir)); err == nil {
126+
log.Warnf("Directory %s not empty after unmount. Skipping RemoveAll call.", hostdir)
127+
} else {
128+
if err := os.RemoveAll(hostdir); err != nil {
129+
return volume.Response{Err: err.Error()}
130+
}
131+
}
125132

126133
return volume.Response{}
127134
}

0 commit comments

Comments
 (0)