@@ -23,6 +23,7 @@ import (
2323 "github.com/containerd/containerd/events"
2424 "github.com/containerd/containerd/images"
2525 "github.com/containerd/containerd/runtime/linux/runctypes"
26+ v2runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
2627 "github.com/containerd/typeurl"
2728 "github.com/docker/docker/errdefs"
2829 "github.com/docker/docker/libcontainerd/queue"
@@ -45,21 +46,27 @@ type client struct {
4546 logger * logrus.Entry
4647 ns string
4748
48- backend libcontainerdtypes.Backend
49- eventQ queue.Queue
50- oomMu sync.Mutex
51- oom map [string ]bool
49+ backend libcontainerdtypes.Backend
50+ eventQ queue.Queue
51+ oomMu sync.Mutex
52+ oom map [string ]bool
53+ useShimV2 bool
54+ v2runcoptionsMu sync.Mutex
55+ // v2runcoptions is used for copying options specified on Create() to Start()
56+ v2runcoptions map [string ]v2runcoptions.Options
5257}
5358
5459// NewClient creates a new libcontainerd client from a containerd client
55- func NewClient (ctx context.Context , cli * containerd.Client , stateDir , ns string , b libcontainerdtypes.Backend ) (libcontainerdtypes.Client , error ) {
60+ func NewClient (ctx context.Context , cli * containerd.Client , stateDir , ns string , b libcontainerdtypes.Backend , useShimV2 bool ) (libcontainerdtypes.Client , error ) {
5661 c := & client {
57- client : cli ,
58- stateDir : stateDir ,
59- logger : logrus .WithField ("module" , "libcontainerd" ).WithField ("namespace" , ns ),
60- ns : ns ,
61- backend : b ,
62- oom : make (map [string ]bool ),
62+ client : cli ,
63+ stateDir : stateDir ,
64+ logger : logrus .WithField ("module" , "libcontainerd" ).WithField ("namespace" , ns ),
65+ ns : ns ,
66+ backend : b ,
67+ oom : make (map [string ]bool ),
68+ useShimV2 : useShimV2 ,
69+ v2runcoptions : make (map [string ]v2runcoptions.Options ),
6370 }
6471
6572 go c .processEventStream (ctx , ns )
@@ -126,9 +133,13 @@ func (c *client) Create(ctx context.Context, id string, ociSpec *specs.Spec, run
126133 bdir := c .bundleDir (id )
127134 c .logger .WithField ("bundle" , bdir ).WithField ("root" , ociSpec .Root .Path ).Debug ("bundle dir created" )
128135
136+ rt := runtimeName
137+ if c .useShimV2 {
138+ rt = shimV2RuntimeName
139+ }
129140 newOpts := []containerd.NewContainerOpts {
130141 containerd .WithSpec (ociSpec ),
131- containerd .WithRuntime (runtimeName , runtimeOptions ),
142+ containerd .WithRuntime (rt , runtimeOptions ),
132143 WithBundle (bdir , ociSpec ),
133144 }
134145 opts = append (opts , newOpts ... )
@@ -140,6 +151,13 @@ func (c *client) Create(ctx context.Context, id string, ociSpec *specs.Spec, run
140151 }
141152 return wrapError (err )
142153 }
154+ if c .useShimV2 {
155+ if x , ok := runtimeOptions .(* v2runcoptions.Options ); ok {
156+ c .v2runcoptionsMu .Lock ()
157+ c .v2runcoptions [id ] = * x
158+ c .v2runcoptionsMu .Unlock ()
159+ }
160+ }
143161 return nil
144162}
145163
@@ -200,11 +218,26 @@ func (c *client) Start(ctx context.Context, id, checkpointDir string, withStdin
200218
201219 if runtime .GOOS != "windows" {
202220 taskOpts = append (taskOpts , func (_ context.Context , _ * containerd.Client , info * containerd.TaskInfo ) error {
203- info .Options = & runctypes.CreateOptions {
204- IoUid : uint32 (uid ),
205- IoGid : uint32 (gid ),
206- NoPivotRoot : os .Getenv ("DOCKER_RAMDISK" ) != "" ,
221+ if c .useShimV2 {
222+ // For v2, we need to inherit options specified on Create
223+ c .v2runcoptionsMu .Lock ()
224+ opts , ok := c .v2runcoptions [id ]
225+ c .v2runcoptionsMu .Unlock ()
226+ if ! ok {
227+ opts = v2runcoptions.Options {}
228+ }
229+ opts .IoUid = uint32 (uid )
230+ opts .IoGid = uint32 (gid )
231+ opts .NoPivotRoot = os .Getenv ("DOCKER_RAMDISK" ) != ""
232+ info .Options = & opts
233+ } else {
234+ info .Options = & runctypes.CreateOptions {
235+ IoUid : uint32 (uid ),
236+ IoGid : uint32 (gid ),
237+ NoPivotRoot : os .Getenv ("DOCKER_RAMDISK" ) != "" ,
238+ }
207239 }
240+
208241 return nil
209242 })
210243 } else {
@@ -466,6 +499,9 @@ func (c *client) Delete(ctx context.Context, containerID string) error {
466499 c .oomMu .Lock ()
467500 delete (c .oom , containerID )
468501 c .oomMu .Unlock ()
502+ c .v2runcoptionsMu .Lock ()
503+ delete (c .v2runcoptions , containerID )
504+ c .v2runcoptionsMu .Unlock ()
469505 if os .Getenv ("LIBCONTAINERD_NOCLEAN" ) != "1" {
470506 if err := os .RemoveAll (bundle ); err != nil {
471507 c .logger .WithError (err ).WithFields (logrus.Fields {
0 commit comments