@@ -85,6 +85,10 @@ type JailerConfig struct {
8585 // CgroupVersion is the version of the cgroup filesystem to use.
8686 CgroupVersion string
8787
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+
8892 // Stdout specifies the IO writer for STDOUT to use when spawning the jailer.
8993 Stdout io.Writer
9094 // Stderr specifies the IO writer for STDERR to use when spawning the jailer.
@@ -109,6 +113,7 @@ type JailerCommandBuilder struct {
109113 daemonize bool
110114 firecrackerArgs []string
111115 cgroupVersion string
116+ cgroupArgs []string
112117
113118 stdin io.Reader
114119 stdout io.Writer
@@ -143,6 +148,10 @@ func (b JailerCommandBuilder) Args() []string {
143148 args = append (args , "--cgroup" , fmt .Sprintf ("cpuset.cpus=%s" , cpulist ))
144149 }
145150
151+ for _ , cgroupArg := range b .cgroupArgs {
152+ args = append (args , "--cgroup" , cgroupArg )
153+ }
154+
146155 if len (b .cgroupVersion ) > 0 {
147156 args = append (args , "--cgroup-version" , b .cgroupVersion )
148157 }
@@ -204,13 +213,30 @@ func (b JailerCommandBuilder) WithExecFile(path string) JailerCommandBuilder {
204213 return b
205214}
206215
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
208217// 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.
209222func (b JailerCommandBuilder ) WithNumaNode (node int ) JailerCommandBuilder {
210223 b .node = node
211224 return b
212225}
213226
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+
214240// WithChrootBaseDir will set the given path as the chroot base directory. This
215241// specifies where chroot jails are built and defaults to /srv/jailer.
216242func (b JailerCommandBuilder ) WithChrootBaseDir (path string ) JailerCommandBuilder {
@@ -348,6 +374,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
348374 WithChrootBaseDir (cfg .JailerCfg .ChrootBaseDir ).
349375 WithDaemonize (cfg .JailerCfg .Daemonize ).
350376 WithCgroupVersion (cfg .JailerCfg .CgroupVersion ).
377+ WithCgroupArgs (cfg .JailerCfg .CgroupArgs ... ).
351378 WithFirecrackerArgs (fcArgs ... ).
352379 WithStdout (stdout ).
353380 WithStderr (stderr )
0 commit comments