@@ -12,7 +12,6 @@ import (
12
12
"github.com/containerd/containerd/namespaces"
13
13
"github.com/containerd/containerd/oci"
14
14
"github.com/containerd/containerd/pkg/userns"
15
- "github.com/containerd/continuity/fs"
16
15
"github.com/docker/docker/pkg/idtools"
17
16
"github.com/mitchellh/hashstructure/v2"
18
17
"github.com/moby/buildkit/executor"
@@ -215,6 +214,7 @@ func GenerateSpec(ctx context.Context, meta executor.Meta, mounts []executor.Mou
215
214
type mountRef struct {
216
215
mount mount.Mount
217
216
unmount func () error
217
+ subRefs map [string ]mountRef
218
218
}
219
219
220
220
type submounts struct {
@@ -233,10 +233,17 @@ func (s *submounts) subMount(m mount.Mount, subPath string) (mount.Mount, error)
233
233
return mount.Mount {}, err
234
234
}
235
235
if mr , ok := s .m [h ]; ok {
236
- sm , err := sub (mr .mount , subPath )
236
+ if sm , ok := mr .subRefs [subPath ]; ok {
237
+ return sm .mount , nil
238
+ }
239
+ sm , unmount , err := sub (mr .mount , subPath )
237
240
if err != nil {
238
241
return mount.Mount {}, err
239
242
}
243
+ mr .subRefs [subPath ] = mountRef {
244
+ mount : sm ,
245
+ unmount : unmount ,
246
+ }
240
247
return sm , nil
241
248
}
242
249
@@ -261,12 +268,17 @@ func (s *submounts) subMount(m mount.Mount, subPath string) (mount.Mount, error)
261
268
Options : opts ,
262
269
},
263
270
unmount : lm .Unmount ,
271
+ subRefs : map [string ]mountRef {},
264
272
}
265
273
266
- sm , err := sub (s .m [h ].mount , subPath )
274
+ sm , unmount , err := sub (s .m [h ].mount , subPath )
267
275
if err != nil {
268
276
return mount.Mount {}, err
269
277
}
278
+ s .m [h ].subRefs [subPath ] = mountRef {
279
+ mount : sm ,
280
+ unmount : unmount ,
281
+ }
270
282
return sm , nil
271
283
}
272
284
@@ -276,6 +288,9 @@ func (s *submounts) cleanup() {
276
288
for _ , m := range s .m {
277
289
func (m mountRef ) {
278
290
go func () {
291
+ for _ , sm := range m .subRefs {
292
+ sm .unmount ()
293
+ }
279
294
m .unmount ()
280
295
wg .Done ()
281
296
}()
@@ -284,15 +299,6 @@ func (s *submounts) cleanup() {
284
299
wg .Wait ()
285
300
}
286
301
287
- func sub (m mount.Mount , subPath string ) (mount.Mount , error ) {
288
- src , err := fs .RootPath (m .Source , subPath )
289
- if err != nil {
290
- return mount.Mount {}, err
291
- }
292
- m .Source = src
293
- return m , nil
294
- }
295
-
296
302
func specMapping (s []idtools.IDMap ) []specs.LinuxIDMapping {
297
303
var ids []specs.LinuxIDMapping
298
304
for _ , item := range s {
0 commit comments