@@ -85,6 +85,10 @@ type JailerConfig struct {
85
85
// CgroupVersion is the version of the cgroup filesystem to use.
86
86
CgroupVersion string
87
87
88
+ // CgroupArgs are cgroup settings applied by the jailer. Each arg must be
89
+ // formatted like <cgroup_file>=<value>, like "cpu.shares=10"
90
+ CgroupArgs []string
91
+
88
92
// Stdout specifies the IO writer for STDOUT to use when spawning the jailer.
89
93
Stdout io.Writer
90
94
// Stderr specifies the IO writer for STDERR to use when spawning the jailer.
@@ -109,6 +113,7 @@ type JailerCommandBuilder struct {
109
113
daemonize bool
110
114
firecrackerArgs []string
111
115
cgroupVersion string
116
+ cgroupArgs []string
112
117
113
118
stdin io.Reader
114
119
stdout io.Writer
@@ -143,6 +148,10 @@ func (b JailerCommandBuilder) Args() []string {
143
148
args = append (args , "--cgroup" , fmt .Sprintf ("cpuset.cpus=%s" , cpulist ))
144
149
}
145
150
151
+ for _ , cgroupArg := range b .cgroupArgs {
152
+ args = append (args , "--cgroup" , cgroupArg )
153
+ }
154
+
146
155
if len (b .cgroupVersion ) > 0 {
147
156
args = append (args , "--cgroup-version" , b .cgroupVersion )
148
157
}
@@ -204,13 +213,30 @@ func (b JailerCommandBuilder) WithExecFile(path string) JailerCommandBuilder {
204
213
return b
205
214
}
206
215
207
- // WithNumaNode uses the specfied node for the jailer. This represents the numa
216
+ // WithNumaNode uses the specified node for the jailer. This represents the numa
208
217
// node that the process will get assigned to.
218
+ // Note: this is a convenience function that just sets the values of the cgroup
219
+ // files "cpuset.mems" and "cpuset.cpus".
220
+ // If those files are also configured using WithCgroupArgs, the values passed to
221
+ // WithCgroupArgs will take precedence.
209
222
func (b JailerCommandBuilder ) WithNumaNode (node int ) JailerCommandBuilder {
210
223
b .node = node
211
224
return b
212
225
}
213
226
227
+ // WithCgroupArgs sets cgroup file values to be set by the jailer.
228
+ // Each arg must be of the form <cgroup_file>=<value>.
229
+ // Each call to this function resets the cgroup arguments, rather than
230
+ // appending.
231
+ //
232
+ // Example:
233
+ //
234
+ // b = b.WithCgroupArgs("cpu.shares=10")
235
+ func (b JailerCommandBuilder ) WithCgroupArgs (cgroupArgs ... string ) JailerCommandBuilder {
236
+ b .cgroupArgs = cgroupArgs
237
+ return b
238
+ }
239
+
214
240
// WithChrootBaseDir will set the given path as the chroot base directory. This
215
241
// specifies where chroot jails are built and defaults to /srv/jailer.
216
242
func (b JailerCommandBuilder ) WithChrootBaseDir (path string ) JailerCommandBuilder {
@@ -348,6 +374,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
348
374
WithChrootBaseDir (cfg .JailerCfg .ChrootBaseDir ).
349
375
WithDaemonize (cfg .JailerCfg .Daemonize ).
350
376
WithCgroupVersion (cfg .JailerCfg .CgroupVersion ).
377
+ WithCgroupArgs (cfg .JailerCfg .CgroupArgs ... ).
351
378
WithFirecrackerArgs (fcArgs ... ).
352
379
WithStdout (stdout ).
353
380
WithStderr (stderr )
0 commit comments