X Tutup
Skip to content

Commit 47f2397

Browse files
crosbymichaeltonistiigi
authored andcommitted
Add no pivot root support
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent aa97632 commit 47f2397

File tree

9 files changed

+182
-141
lines changed

9 files changed

+182
-141
lines changed

api/grpc/server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (s *apiServer) CreateContainer(ctx context.Context, c *types.CreateContaine
3838
e.Stdout = c.Stdout
3939
e.Stderr = c.Stderr
4040
e.Labels = c.Labels
41+
e.NoPivotRoot = c.NoPivotRoot
4142
e.StartResponse = make(chan supervisor.StartResponse, 1)
4243
createContainerConfigCheckpoint(e, c)
4344
s.sv.SendTask(e)

api/grpc/types/api.pb.go

Lines changed: 122 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/types/api.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ message CreateContainerRequest {
3535
string stdout = 5; // path to file where stdout will be written (optional)
3636
string stderr = 6; // path to file where stderr will be written (optional)
3737
repeated string labels = 7;
38+
bool noPivotRoot = 8;
3839
}
3940

4041
message CreateContainerResponse {

containerd-shim/process.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,17 @@ func (p *process) start() error {
116116
if p.checkpoint.UnixSockets {
117117
add("--ext-unix-sk")
118118
}
119+
if p.state.NoPivotRoot {
120+
add("--no-pivot")
121+
}
119122
} else {
120123
args = append(args, "start",
121124
"--bundle", p.bundle,
122125
"--console", p.consolePath,
123126
)
127+
if p.state.NoPivotRoot {
128+
args = append(args, "--no-pivot")
129+
}
124130
}
125131
args = append(args,
126132
"-d",

ctr/container.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ var startCommand = cli.Command{
124124
Value: &cli.StringSlice{},
125125
Usage: "set labels for the container",
126126
},
127+
cli.BoolFlag{
128+
Name: "no-pivot",
129+
Usage: "do not use pivot root",
130+
},
127131
},
128132
Action: func(context *cli.Context) {
129133
var (
@@ -149,13 +153,14 @@ var startCommand = cli.Command{
149153
tty bool
150154
c = getClient(context)
151155
r = &types.CreateContainerRequest{
152-
Id: id,
153-
BundlePath: bpath,
154-
Checkpoint: context.String("checkpoint"),
155-
Stdin: s.stdin,
156-
Stdout: s.stdout,
157-
Stderr: s.stderr,
158-
Labels: context.StringSlice("label"),
156+
Id: id,
157+
BundlePath: bpath,
158+
Checkpoint: context.String("checkpoint"),
159+
Stdin: s.stdin,
160+
Stdout: s.stdout,
161+
Stderr: s.stderr,
162+
Labels: context.StringSlice("label"),
163+
NoPivotRoot: context.Bool("no-pivot"),
159164
}
160165
)
161166
restoreAndCloseStdin = func() {

runtime/container.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,42 @@ func NewStdio(stdin, stdout, stderr string) Stdio {
8282
}
8383
}
8484

85+
type ContainerOpts struct {
86+
Root string
87+
ID string
88+
Bundle string
89+
Runtime string
90+
RuntimeArgs []string
91+
Labels []string
92+
NoPivotRoot bool
93+
}
94+
8595
// New returns a new container
86-
func New(root, id, bundle, runtimeName string, runtimeArgs, labels []string) (Container, error) {
96+
func New(opts ContainerOpts) (Container, error) {
8797
c := &container{
88-
root: root,
89-
id: id,
90-
bundle: bundle,
91-
labels: labels,
98+
root: opts.Root,
99+
id: opts.ID,
100+
bundle: opts.Bundle,
101+
labels: opts.Labels,
92102
processes: make(map[string]*process),
93-
runtime: runtimeName,
94-
runtimeArgs: runtimeArgs,
103+
runtime: opts.Runtime,
104+
runtimeArgs: opts.RuntimeArgs,
105+
noPivotRoot: opts.NoPivotRoot,
95106
}
96-
if err := os.Mkdir(filepath.Join(root, id), 0755); err != nil {
107+
if err := os.Mkdir(filepath.Join(c.root, c.id), 0755); err != nil {
97108
return nil, err
98109
}
99-
f, err := os.Create(filepath.Join(root, id, StateFile))
110+
f, err := os.Create(filepath.Join(c.root, c.id, StateFile))
100111
if err != nil {
101112
return nil, err
102113
}
103114
defer f.Close()
104115
if err := json.NewEncoder(f).Encode(state{
105-
Bundle: bundle,
106-
Labels: labels,
107-
Runtime: runtimeName,
108-
RuntimeArgs: runtimeArgs,
116+
Bundle: c.bundle,
117+
Labels: c.labels,
118+
Runtime: c.runtime,
119+
RuntimeArgs: c.runtimeArgs,
120+
NoPivotRoot: opts.NoPivotRoot,
109121
}); err != nil {
110122
return nil, err
111123
}
@@ -129,6 +141,7 @@ func Load(root, id string) (Container, error) {
129141
labels: s.Labels,
130142
runtime: s.Runtime,
131143
runtimeArgs: s.RuntimeArgs,
144+
noPivotRoot: s.NoPivotRoot,
132145
processes: make(map[string]*process),
133146
}
134147
dirs, err := ioutil.ReadDir(filepath.Join(root, id))
@@ -177,6 +190,7 @@ type container struct {
177190
processes map[string]*process
178191
labels []string
179192
oomFds []int
193+
noPivotRoot bool
180194
}
181195

182196
func (c *container) ID() string {

runtime/process_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ func populateProcessStateForEncoding(config *processConfig, uid int, gid int) Pr
3939
Stdout: config.stdio.Stdout,
4040
Stderr: config.stdio.Stderr,
4141
RuntimeArgs: config.c.runtimeArgs,
42+
NoPivotRoot: config.c.noPivotRoot,
4243
}
4344
}

runtime/runtime.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type state struct {
6060
Stderr string `json:"stderr"`
6161
Runtime string `json:"runtime"`
6262
RuntimeArgs []string `json:"runtimeArgs"`
63+
NoPivotRoot bool `json:"noPivotRoot"`
6364
}
6465

6566
type ProcessState struct {
@@ -69,6 +70,7 @@ type ProcessState struct {
6970
Stdout string `json:"containerdStdout"`
7071
Stderr string `json:"containerdStderr"`
7172
RuntimeArgs []string `json:"runtimeArgs"`
73+
NoPivotRoot bool `json:"noPivotRoot"`
7274

7375
PlatformProcessState
7476
}

supervisor/create.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ type StartTask struct {
1616
Stdin string
1717
StartResponse chan StartResponse
1818
Labels []string
19+
NoPivotRoot bool
1920
}
2021

2122
func (s *Supervisor) start(t *StartTask) error {
2223
start := time.Now()
23-
container, err := runtime.New(s.stateDir, t.ID, t.BundlePath, s.runtime, s.runtimeArgs, t.Labels)
24+
container, err := runtime.New(runtime.ContainerOpts{
25+
Root: s.stateDir,
26+
ID: t.ID,
27+
Bundle: t.BundlePath,
28+
Runtime: s.runtime,
29+
RuntimeArgs: s.runtimeArgs,
30+
Labels: t.Labels,
31+
NoPivotRoot: t.NoPivotRoot,
32+
})
2433
if err != nil {
2534
return err
2635
}

0 commit comments

Comments
 (0)
X Tutup