@@ -683,8 +683,7 @@ func WithUser(userstr string) SpecOpts {
683683 return err
684684 }
685685
686- mounts = tryReadonlyMounts (mounts )
687- return mount .WithTempMount (ctx , mounts , f )
686+ return mount .WithReadonlyTempMount (ctx , mounts , f )
688687 default :
689688 return fmt .Errorf ("invalid USER value %s" , userstr )
690689 }
@@ -744,8 +743,7 @@ func WithUserID(uid uint32) SpecOpts {
744743 return err
745744 }
746745
747- mounts = tryReadonlyMounts (mounts )
748- return mount .WithTempMount (ctx , mounts , setUser )
746+ return mount .WithReadonlyTempMount (ctx , mounts , setUser )
749747 }
750748}
751749
@@ -789,8 +787,7 @@ func WithUsername(username string) SpecOpts {
789787 return err
790788 }
791789
792- mounts = tryReadonlyMounts (mounts )
793- return mount .WithTempMount (ctx , mounts , setUser )
790+ return mount .WithReadonlyTempMount (ctx , mounts , setUser )
794791 } else if s .Windows != nil {
795792 s .Process .User .Username = username
796793 } else {
@@ -868,8 +865,7 @@ func WithAdditionalGIDs(userstr string) SpecOpts {
868865 return err
869866 }
870867
871- mounts = tryReadonlyMounts (mounts )
872- return mount .WithTempMount (ctx , mounts , setAdditionalGids )
868+ return mount .WithReadonlyTempMount (ctx , mounts , setAdditionalGids )
873869 }
874870}
875871
@@ -930,8 +926,7 @@ func WithAppendAdditionalGroups(groups ...string) SpecOpts {
930926 return err
931927 }
932928
933- mounts = tryReadonlyMounts (mounts )
934- return mount .WithTempMount (ctx , mounts , setAdditionalGids )
929+ return mount .WithReadonlyTempMount (ctx , mounts , setAdditionalGids )
935930 }
936931}
937932
@@ -1426,24 +1421,6 @@ func WithDevShmSize(kb int64) SpecOpts {
14261421 }
14271422}
14281423
1429- // tryReadonlyMounts is used by the options which are trying to get user/group
1430- // information from container's rootfs. Since the option does read operation
1431- // only, this helper will append ReadOnly mount option to prevent linux kernel
1432- // from syncing whole filesystem in umount syscall.
1433- //
1434- // TODO(fuweid):
1435- //
1436- // Currently, it only works for overlayfs. I think we can apply it to other
1437- // kinds of filesystem. Maybe we can return `ro` option by `snapshotter.Mount`
1438- // API, when the caller passes that experimental annotation
1439- // `containerd.io/snapshot/readonly.mount` something like that.
1440- func tryReadonlyMounts (mounts []mount.Mount ) []mount.Mount {
1441- if len (mounts ) == 1 && mounts [0 ].Type == "overlay" {
1442- mounts [0 ].Options = append (mounts [0 ].Options , "ro" )
1443- }
1444- return mounts
1445- }
1446-
14471424// WithWindowsDevice adds a device exposed to a Windows (WCOW or LCOW) Container
14481425func WithWindowsDevice (idType , id string ) SpecOpts {
14491426 return func (_ context.Context , _ Client , _ * containers.Container , s * Spec ) error {
0 commit comments