-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_jobs_sendrecvoptions.go
105 lines (85 loc) · 3.06 KB
/
build_jobs_sendrecvoptions.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
93
94
95
96
97
98
99
100
101
102
103
104
105
package job
import (
"errors"
"fmt"
"github.com/dsh2dsh/zrepl/config"
"github.com/dsh2dsh/zrepl/daemon/filters"
"github.com/dsh2dsh/zrepl/endpoint"
"github.com/dsh2dsh/zrepl/util/nodefault"
"github.com/dsh2dsh/zrepl/zfs"
)
type SendingJobConfig interface {
GetFilesystems() config.FilesystemsFilter
GetSendOptions() *config.SendOptions // must not be nil
}
func buildSenderConfig(in SendingJobConfig, jobID endpoint.JobID) (*endpoint.SenderConfig, error) {
fsf, err := filters.DatasetMapFilterFromConfig(in.GetFilesystems())
if err != nil {
return nil, fmt.Errorf("cannot build filesystem filter: %w", err)
}
sendOpts := in.GetSendOptions()
bwlim, err := buildBandwidthLimitConfig(&sendOpts.BandwidthLimit)
if err != nil {
return nil, fmt.Errorf("cannot build bandwith limit config: %w", err)
}
sc := &endpoint.SenderConfig{
FSF: fsf,
JobID: jobID,
Encrypt: &nodefault.Bool{B: sendOpts.Encrypted},
SendRaw: sendOpts.Raw,
SendProperties: sendOpts.SendProperties,
SendBackupProperties: sendOpts.BackupProperties,
SendLargeBlocks: sendOpts.LargeBlocks,
SendCompressed: sendOpts.Compressed,
SendEmbeddedData: sendOpts.EmbeddedData,
SendSaved: sendOpts.Saved,
BandwidthLimit: bwlim,
ExecPipe: sendOpts.ExecPipe,
}
if err := sc.Validate(); err != nil {
return nil, fmt.Errorf("cannot build sender config: %w", err)
}
return sc, nil
}
type ReceivingJobConfig interface {
GetRootFS() string
GetAppendClientIdentity() bool
GetRecvOptions() *config.RecvOptions
}
func buildReceiverConfig(in ReceivingJobConfig, jobID endpoint.JobID) (rc endpoint.ReceiverConfig, err error) {
rootFs, err := zfs.NewDatasetPath(in.GetRootFS())
if err != nil {
return rc, errors.New("root_fs is not a valid zfs filesystem path")
}
if rootFs.Length() <= 0 {
return rc, errors.New("root_fs must not be empty") // duplicates error check of receiver
}
recvOpts := in.GetRecvOptions()
bwlim, err := buildBandwidthLimitConfig(&recvOpts.BandwidthLimit)
if err != nil {
return rc, fmt.Errorf("cannot build bandwith limit config: %w", err)
}
placeholderEncryption, err := endpoint.PlaceholderCreationEncryptionPropertyString(recvOpts.Placeholder.Encryption)
if err != nil {
options := []string{}
for _, v := range endpoint.PlaceholderCreationEncryptionPropertyValues() {
options = append(options, endpoint.PlaceholderCreationEncryptionProperty(v).String())
}
return rc, fmt.Errorf("placeholder encryption value %q is invalid, must be one of %s",
recvOpts.Placeholder.Encryption, options)
}
rc = endpoint.ReceiverConfig{
JobID: jobID,
RootWithoutClientComponent: rootFs,
AppendClientIdentity: in.GetAppendClientIdentity(),
InheritProperties: recvOpts.Properties.Inherit,
OverrideProperties: recvOpts.Properties.Override,
BandwidthLimit: bwlim,
PlaceholderEncryption: placeholderEncryption,
ExecPipe: recvOpts.ExecPipe,
}
if err := rc.Validate(); err != nil {
return rc, fmt.Errorf("cannot build receiver config: %w", err)
}
return rc, nil
}