forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_disk_manager.go
92 lines (76 loc) · 2.9 KB
/
linux_disk_manager.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package disk
import (
"fmt"
"time"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
"github.com/pivotal-golang/clock"
boshdevutil "github.com/cloudfoundry/bosh-agent/platform/deviceutil"
)
type linuxDiskManager struct {
partitioner Partitioner
rootDevicePartitioner Partitioner
partedPartitioner Partitioner
formatter Formatter
mounter Mounter
mountsSearcher MountsSearcher
fs boshsys.FileSystem
logger boshlog.Logger
runner boshsys.CmdRunner
}
type LinuxDiskManagerOpts struct {
BindMount bool
PartitionerType string
}
func NewLinuxDiskManager(
logger boshlog.Logger,
runner boshsys.CmdRunner,
fs boshsys.FileSystem,
opts LinuxDiskManagerOpts,
) (manager Manager) {
var mounter Mounter
var mountsSearcher MountsSearcher
// By default we want to use most reliable source of
// mount information which is /proc/mounts
mountsSearcher = NewProcMountsSearcher(fs)
// Bind mounting in a container (warden) will not allow
// reliably determine which device backs a mount point,
// so we use less reliable source of mount information:
// the mount command which returns information from /etc/mtab.
if opts.BindMount {
mountsSearcher = NewCmdMountsSearcher(runner)
}
mounter = NewLinuxMounter(runner, mountsSearcher, 1*time.Second)
if opts.BindMount {
mounter = NewLinuxBindMounter(mounter)
}
var partitioner Partitioner
switch opts.PartitionerType {
case "parted":
partitioner = NewPartedPartitioner(logger, runner, clock.NewClock())
case "":
partitioner = NewSfdiskPartitioner(logger, runner, clock.NewClock())
default:
panic(fmt.Sprintf("Unknown partitioner type '%s'", opts.PartitionerType))
}
return linuxDiskManager{
partitioner: partitioner,
rootDevicePartitioner: NewRootDevicePartitioner(logger, runner, uint64(20*1024*1024)),
partedPartitioner: NewPartedPartitioner(logger, runner, clock.NewClock()),
formatter: NewLinuxFormatter(runner, fs),
mounter: mounter,
mountsSearcher: mountsSearcher,
fs: fs,
logger: logger,
runner: runner,
}
}
func (m linuxDiskManager) GetPartitioner() Partitioner { return m.partitioner }
func (m linuxDiskManager) GetPartedPartitioner() Partitioner { return m.partedPartitioner }
func (m linuxDiskManager) GetRootDevicePartitioner() Partitioner { return m.rootDevicePartitioner }
func (m linuxDiskManager) GetFormatter() Formatter { return m.formatter }
func (m linuxDiskManager) GetMounter() Mounter { return m.mounter }
func (m linuxDiskManager) GetMountsSearcher() MountsSearcher { return m.mountsSearcher }
func (m linuxDiskManager) GetDiskUtil(diskPath string) boshdevutil.DeviceUtil {
return NewDiskUtil(diskPath, m.runner, m.mounter, m.fs, m.logger)
}