Skip to content

Commit c4b56cb

Browse files
authored
Create rootfs directory in shim. (google#30)
Signed-off-by: Lantao Liu <[email protected]>
1 parent 8a76657 commit c4b56cb

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pkg/v1/shim/service.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (_ *
125125
})
126126
}
127127

128+
rootfs := filepath.Join(r.Bundle, "rootfs")
129+
if err := os.Mkdir(rootfs, 0711); err != nil && !os.IsExist(err) {
130+
return nil, err
131+
}
132+
128133
config := &proc.CreateConfig{
129134
ID: r.ID,
130135
Bundle: r.Bundle,
@@ -136,7 +141,6 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (_ *
136141
Stderr: r.Stderr,
137142
Options: r.Options,
138143
}
139-
rootfs := filepath.Join(r.Bundle, "rootfs")
140144
defer func() {
141145
if err != nil {
142146
if err2 := mount.UnmountAll(rootfs, 0); err2 != nil {

pkg/v2/service.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
287287
Options: m.Options,
288288
})
289289
}
290+
291+
rootfs := filepath.Join(r.Bundle, "rootfs")
292+
if err := os.Mkdir(rootfs, 0711); err != nil && !os.IsExist(err) {
293+
return nil, err
294+
}
295+
290296
config := &proc.CreateConfig{
291297
ID: r.ID,
292298
Bundle: r.Bundle,
@@ -301,7 +307,6 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
301307
if err := s.writeRuntime(r.Bundle, opts.BinaryName); err != nil {
302308
return nil, err
303309
}
304-
rootfs := filepath.Join(r.Bundle, "rootfs")
305310
defer func() {
306311
if err != nil {
307312
if err2 := mount.UnmountAll(rootfs, 0); err2 != nil {
@@ -327,6 +332,7 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
327332
s.platform,
328333
config,
329334
&opts,
335+
rootfs,
330336
)
331337
if err != nil {
332338
return nil, errdefs.ToGRPC(err)
@@ -698,13 +704,12 @@ func getTopic(e interface{}) string {
698704
return runtime.TaskUnknownTopic
699705
}
700706

701-
func newInit(ctx context.Context, path, workDir, namespace string, platform rproc.Platform, r *proc.CreateConfig, options *options.Options) (*proc.Init, error) {
707+
func newInit(ctx context.Context, path, workDir, namespace string, platform rproc.Platform, r *proc.CreateConfig, options *options.Options, rootfs string) (*proc.Init, error) {
702708
spec, err := utils.ReadSpec(r.Bundle)
703709
if err != nil {
704710
return nil, errors.Wrap(err, "read oci spec")
705711
}
706712
runsc.FormatLogPath(r.ID, options.RunscConfig)
707-
rootfs := filepath.Join(path, "rootfs")
708713
runtime := proc.NewRunsc(options.Root, path, namespace, options.BinaryName, options.RunscConfig)
709714
p := proc.New(r.ID, runtime, rproc.Stdio{
710715
Stdin: r.Stdin,

0 commit comments

Comments
 (0)