-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
volumes.go
73 lines (62 loc) · 1.52 KB
/
volumes.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
package machine
import (
"crypto/sha256"
"encoding/hex"
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
)
type Volume interface {
Kind() VolumeKind
}
type VolumeKind string
var (
VirtIOFsVk VolumeKind = "virtiofs"
NinePVk VolumeKind = "9p"
)
type VirtIoFs struct {
VolumeKind
ReadOnly bool
Source string
Tag string
Target string
}
func (v VirtIoFs) Kind() string {
return string(VirtIOFsVk)
}
// generateTag generates a tag for VirtIOFs mounts.
// AppleHV requires tags to be 36 bytes or fewer.
// SHA256 the path, then truncate to 36 bytes
func (v VirtIoFs) generateTag() string {
sum := sha256.Sum256([]byte(v.Target))
stringSum := hex.EncodeToString(sum[:])
return stringSum[:36]
}
func (v VirtIoFs) ToMount() vmconfigs.Mount {
return vmconfigs.Mount{
ReadOnly: v.ReadOnly,
Source: v.Source,
Tag: v.Tag,
Target: v.Target,
Type: v.Kind(),
}
}
// NewVirtIoFsMount describes a machine volume mount for virtio-fs. With virtio-fs
// the source/target are described as a "shared dir". With this style of volume mount
// the Tag is used as the descriptor value for the mount (in Linux).
func NewVirtIoFsMount(src, target string, readOnly bool) VirtIoFs {
vfs := VirtIoFs{
ReadOnly: readOnly,
Source: src,
Target: target,
}
vfs.Tag = vfs.generateTag()
return vfs
}
func MountToVirtIOFs(mnt *vmconfigs.Mount) VirtIoFs {
return VirtIoFs{
VolumeKind: VirtIOFsVk,
ReadOnly: mnt.ReadOnly,
Source: mnt.Source,
Tag: mnt.Tag,
Target: mnt.Target,
}
}