@@ -58,14 +58,22 @@ const (
58
58
Nonefs = "none"
59
59
)
60
60
61
+ // SelfOverlayFilestoreDirPrefix is the prefix in the directory name of the
62
+ // self overlay filestore directory.
63
+ const SelfOverlayFilestoreDirPrefix = ".gvisor.overlay.img."
64
+
61
65
// SelfOverlayFilestoreDir returns the directory path in which self overlay filestore
62
66
// files are stored for a given mount.
63
67
func SelfOverlayFilestoreDir (mountSrc , cid string ) string {
64
68
// We will place filestore files in a gvisor specific hidden directory inside
65
69
// the mount being overlayed itself. The same volume can be overlay-ed by
66
70
// multiple containers. So make the filestore directory unique to container
67
71
// by suffixing the container ID.
68
- return path .Join (mountSrc , ".gvisor.overlay.img." + cid )
72
+ return path .Join (mountSrc , selfOverlayFilestoreDirName (cid ))
73
+ }
74
+
75
+ func selfOverlayFilestoreDirName (cid string ) string {
76
+ return SelfOverlayFilestoreDirPrefix + cid
69
77
}
70
78
71
79
// tmpfs has some extra supported options that we must pass through.
@@ -341,9 +349,12 @@ type containerMounter struct {
341
349
// productName is the value to show in
342
350
// /sys/devices/virtual/dmi/id/product_name.
343
351
productName string
352
+
353
+ // cid is the container ID for the container.
354
+ cid string
344
355
}
345
356
346
- func newContainerMounter (info * containerInfo , k * kernel.Kernel , hints * podMountHints , productName string ) * containerMounter {
357
+ func newContainerMounter (info * containerInfo , k * kernel.Kernel , hints * podMountHints , productName string , cid string ) * containerMounter {
347
358
return & containerMounter {
348
359
root : info .spec .Root ,
349
360
mounts : compileMounts (info .spec , info .conf ),
@@ -352,6 +363,7 @@ func newContainerMounter(info *containerInfo, k *kernel.Kernel, hints *podMountH
352
363
k : k ,
353
364
hints : hints ,
354
365
productName : productName ,
366
+ cid : cid ,
355
367
}
356
368
}
357
369
@@ -457,8 +469,7 @@ func (c *containerMounter) createMountNamespace(ctx context.Context, conf *confi
457
469
return mns , nil
458
470
}
459
471
460
- func useOverlayFilestoreFD (conf * config.Config , isDir bool ) bool {
461
- overlay2 := conf .GetOverlay2 ()
472
+ func useOverlayFilestoreFD (overlay2 config.Overlay2 , isDir bool ) bool {
462
473
if ! overlay2 .IsBackedByHostFile () {
463
474
return false
464
475
}
@@ -473,7 +484,7 @@ func useOverlayFilestoreFD(conf *config.Config, isDir bool) bool {
473
484
// layer using tmpfs, and return overlay mount options. "cleanup" must be called
474
485
// after the options have been used to mount the overlay, to release refs on
475
486
// lower and upper mounts.
476
- func (c * containerMounter ) configureOverlay (ctx context.Context , conf * config.Config , creds * auth.Credentials , lowerOpts * vfs.MountOptions , lowerFSName string , useFilestoreFD func (conf * config.Config , isDir bool ) bool ) (* vfs.MountOptions , func (), error ) {
487
+ func (c * containerMounter ) configureOverlay (ctx context.Context , conf * config.Config , creds * auth.Credentials , lowerOpts * vfs.MountOptions , lowerFSName string , useFilestoreFD func (overlay2 config.Overlay2 , isDir bool ) bool ) (* vfs.MountOptions , func (), error ) {
477
488
// First copy options from lower layer to upper layer and overlay. Clear
478
489
// filesystem specific options.
479
490
upperOpts := * lowerOpts
@@ -514,7 +525,8 @@ func (c *containerMounter) configureOverlay(ctx context.Context, conf *config.Co
514
525
tmpfsOpts := tmpfs.FilesystemOpts {
515
526
RootFileType : uint16 (rootType ),
516
527
}
517
- if useFilestoreFD != nil && useFilestoreFD (conf , rootType == linux .S_IFDIR ) {
528
+ overlay2 := conf .GetOverlay2 ()
529
+ if useFilestoreFD != nil && useFilestoreFD (overlay2 , rootType == linux .S_IFDIR ) {
518
530
tmpfsOpts .FilestoreFD = c .overlayFilestoreFDs .removeAsFD ()
519
531
}
520
532
upperOpts .GetFilesystemOptions .InternalData = tmpfsOpts
@@ -554,6 +566,18 @@ func (c *containerMounter) configureOverlay(ctx context.Context, conf *config.Co
554
566
}
555
567
}
556
568
569
+ // If host filestore is being used and it is backed by self, then we need to
570
+ // hide the filestore from the containerized application.
571
+ if overlay2 .IsBackedBySelf () && useFilestoreFD != nil && useFilestoreFD (overlay2 , rootType == linux .S_IFDIR ) {
572
+ if err := overlay .CreateWhiteout (ctx , c .k .VFS (), creds , & vfs.PathOperation {
573
+ Root : upperRootVD ,
574
+ Start : upperRootVD ,
575
+ Path : fspath .Parse (selfOverlayFilestoreDirName (c .cid )),
576
+ }); err != nil {
577
+ return nil , nil , fmt .Errorf ("failed to create whiteout to hide self overlay filestore: %w" , err )
578
+ }
579
+ }
580
+
557
581
// Propagate the lower layer's root's owner, group, and mode to the upper
558
582
// layer's root for consistency with VFS1.
559
583
err = c .k .VFS ().SetStatAt (ctx , creds , & vfs.PathOperation {
0 commit comments