@@ -31,16 +31,6 @@ import (
3131 "gvisor.dev/gvisor/pkg/sync"
3232)
3333
34- // _OVL_XATTR_PREFIX is an extended attribute key prefix to identify overlayfs
35- // attributes.
36- // Linux: fs/overlayfs/overlayfs.h:OVL_XATTR_PREFIX
37- const _OVL_XATTR_PREFIX = linux .XATTR_TRUSTED_PREFIX + "overlay."
38-
39- // _OVL_XATTR_OPAQUE is an extended attribute key whose value is set to "y" for
40- // opaque directories.
41- // Linux: fs/overlayfs/overlayfs.h:OVL_XATTR_OPAQUE
42- const _OVL_XATTR_OPAQUE = _OVL_XATTR_PREFIX + "opaque"
43-
4434func isWhiteout (stat * linux.Statx ) bool {
4535 return stat .Mode & linux .S_IFMT == linux .S_IFCHR && stat .RdevMajor == 0 && stat .RdevMinor == 0
4636}
@@ -310,7 +300,7 @@ func (fs *filesystem) lookupLocked(ctx context.Context, parent *dentry, name str
310300 Root : childVD ,
311301 Start : childVD ,
312302 }, & vfs.GetXattrOptions {
313- Name : _OVL_XATTR_OPAQUE ,
303+ Name : fs . xattrOpaque ,
314304 Size : 1 ,
315305 })
316306 return ! (err == nil && opaqueVal == "y" )
@@ -745,7 +735,7 @@ func (fs *filesystem) MkdirAt(ctx context.Context, rp *vfs.ResolvingPath, opts v
745735 // the new directory should not be merged with, so mark as opaque.
746736 // See fs/overlayfs/dir.c:ovl_create_over_whiteout() -> ovl_set_opaque().
747737 if err := vfsObj .SetXattrAt (ctx , fs .creds , & pop , & vfs.SetXattrOptions {
748- Name : _OVL_XATTR_OPAQUE ,
738+ Name : fs . xattrOpaque ,
749739 Value : "y" ,
750740 }); err != nil {
751741 if cleanupErr := vfsObj .RmdirAt (ctx , fs .creds , & pop ); cleanupErr != nil {
@@ -763,7 +753,7 @@ func (fs *filesystem) MkdirAt(ctx context.Context, rp *vfs.ResolvingPath, opts v
763753 // fs.lookupLocked(). Allow it to fail since this is an optimization.
764754 // See fs/overlayfs/dir.c:ovl_create_upper() -> ovl_set_opaque().
765755 _ = vfsObj .SetXattrAt (ctx , fs .creds , & pop , & vfs.SetXattrOptions {
766- Name : _OVL_XATTR_OPAQUE ,
756+ Name : fs . xattrOpaque ,
767757 Value : "y" ,
768758 })
769759 }
@@ -1322,7 +1312,7 @@ func (fs *filesystem) RenameAt(ctx context.Context, rp *vfs.ResolvingPath, oldPa
13221312 }
13231313 if renamed .isDir () {
13241314 if err := vfsObj .SetXattrAt (ctx , fs .creds , & newpop , & vfs.SetXattrOptions {
1325- Name : _OVL_XATTR_OPAQUE ,
1315+ Name : fs . xattrOpaque ,
13261316 Value : "y" ,
13271317 }); err != nil {
13281318 panic (fmt .Sprintf ("unrecoverable overlayfs inconsistency: failed to make renamed directory opaque: %v" , err ))
@@ -1689,8 +1679,8 @@ func (fs *filesystem) UnlinkAt(ctx context.Context, rp *vfs.ResolvingPath) error
16891679
16901680// isOverlayXattr returns whether the given extended attribute configures the
16911681// overlay.
1692- func isOverlayXattr (name string ) bool {
1693- return strings .HasPrefix (name , _OVL_XATTR_PREFIX )
1682+ func ( fs * filesystem ) isOverlayXattr (name string ) bool {
1683+ return strings .HasPrefix (name , fs . xattrPrefix )
16941684}
16951685
16961686// ListXattrAt implements vfs.FilesystemImpl.ListXattrAt.
@@ -1717,7 +1707,7 @@ func (fs *filesystem) listXattr(ctx context.Context, d *dentry, size uint64) ([]
17171707 // Filter out all overlay attributes.
17181708 n := 0
17191709 for _ , name := range names {
1720- if ! isOverlayXattr (name ) {
1710+ if ! fs . isOverlayXattr (name ) {
17211711 names [n ] = name
17221712 n ++
17231713 }
@@ -1745,7 +1735,7 @@ func (fs *filesystem) getXattr(ctx context.Context, d *dentry, creds *auth.Crede
17451735
17461736 // Return EOPNOTSUPP when fetching an overlay attribute.
17471737 // See fs/overlayfs/super.c:ovl_own_xattr_get().
1748- if isOverlayXattr (opts .Name ) {
1738+ if fs . isOverlayXattr (opts .Name ) {
17491739 return "" , linuxerr .EOPNOTSUPP
17501740 }
17511741
@@ -1783,7 +1773,7 @@ func (fs *filesystem) setXattrLocked(ctx context.Context, d *dentry, mnt *vfs.Mo
17831773
17841774 // Return EOPNOTSUPP when setting an overlay attribute.
17851775 // See fs/overlayfs/super.c:ovl_own_xattr_set().
1786- if isOverlayXattr (opts .Name ) {
1776+ if fs . isOverlayXattr (opts .Name ) {
17871777 return linuxerr .EOPNOTSUPP
17881778 }
17891779
@@ -1828,7 +1818,7 @@ func (fs *filesystem) removeXattrLocked(ctx context.Context, d *dentry, mnt *vfs
18281818 // Like SetXattrAt, return EOPNOTSUPP when removing an overlay attribute.
18291819 // Linux passes the remove request to xattr_handler->set.
18301820 // See fs/xattr.c:vfs_removexattr().
1831- if isOverlayXattr (name ) {
1821+ if fs . isOverlayXattr (name ) {
18321822 return linuxerr .EOPNOTSUPP
18331823 }
18341824
0 commit comments