/
custom_mount.go
60 lines (50 loc) · 1.46 KB
/
custom_mount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package mount
import (
"regexp"
"github.com/libopenstorage/openstorage/pkg/keylock"
)
// CustomLoad defines the mounter.Load callback function for customer mounters
type CustomLoad func([]*regexp.Regexp, DeviceMap, PathMap) error
// CustomReload defines the mounter.Reload callback function for customer mounters
type CustomReload func(string, DeviceMap, PathMap) error
// CustomMounter defines the CustomMount function that retursn the load and reload callbacks
type CustomMounter func() (CustomLoad, CustomReload)
// CustomMounterHandler implements the Mounter interface
type CustomMounterHandler struct {
Mounter
cl CustomLoad
cr CustomReload
}
// NewCustomMounter returns a new CustomMounter
func NewCustomMounter(
devRegexes []*regexp.Regexp,
mountImpl MountImpl,
customMounter CustomMounter,
allowedDirs []string,
) (*CustomMounterHandler, error) {
m := &CustomMounterHandler{
Mounter: Mounter{
mountImpl: mountImpl,
mounts: make(DeviceMap),
paths: make(PathMap),
allowedDirs: allowedDirs,
kl: keylock.New(),
},
}
cl, cr := customMounter()
m.cl = cl
m.cr = cr
err := m.Load(devRegexes)
if err != nil {
return nil, err
}
return m, nil
}
// Load mount table
func (c *CustomMounterHandler) Load(devRegexes []*regexp.Regexp) error {
return c.cl(devRegexes, c.mounts, c.paths)
}
// Reload mount table for a device
func (c *CustomMounterHandler) Reload(device string) error {
return c.cr(device, c.mounts, c.paths)
}