diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2019-04-05 15:48:26 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-05 15:49:39 -0700 |
commit | ee7e6d33b2a017a53bebfdc55d182f53474d4d7d (patch) | |
tree | 91c302c8844f62f9c168e571231ecf4cb5e3fbb7 /pkg/sentry/fs/inode_overlay.go | |
parent | f44f2f73b068658ddf632586e2178e372fcd1cbd (diff) |
Use string type for extended attribute values, instead of []byte.
Strings are a better fit for this usage because they are immutable in Go, and
can contain arbitrary bytes. It also allows us to avoid casting bytes to string
(and the associated allocation) in the hot path when checking for overlay
whiteouts.
PiperOrigin-RevId: 242208856
Change-Id: I7699ae6302492eca71787dd0b72e0a5a217a3db2
Diffstat (limited to 'pkg/sentry/fs/inode_overlay.go')
-rw-r--r-- | pkg/sentry/fs/inode_overlay.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/pkg/sentry/fs/inode_overlay.go b/pkg/sentry/fs/inode_overlay.go index 6e1dfecf9..254646176 100644 --- a/pkg/sentry/fs/inode_overlay.go +++ b/pkg/sentry/fs/inode_overlay.go @@ -25,12 +25,12 @@ import ( ) func overlayHasWhiteout(parent *Inode, name string) bool { - buf, err := parent.Getxattr(XattrOverlayWhiteout(name)) - return err == nil && string(buf) == "y" + s, err := parent.Getxattr(XattrOverlayWhiteout(name)) + return err == nil && s == "y" } func overlayCreateWhiteout(parent *Inode, name string) error { - return parent.InodeOperations.Setxattr(parent, XattrOverlayWhiteout(name), []byte("y")) + return parent.InodeOperations.Setxattr(parent, XattrOverlayWhiteout(name), "y") } func overlayWriteOut(ctx context.Context, o *overlayEntry) error { @@ -491,28 +491,28 @@ func overlayUnstableAttr(ctx context.Context, o *overlayEntry) (UnstableAttr, er return attr, err } -func overlayGetxattr(o *overlayEntry, name string) ([]byte, error) { +func overlayGetxattr(o *overlayEntry, name string) (string, error) { // Hot path. This is how the overlay checks for whiteout files. // Avoid defers. var ( - b []byte + s string err error ) // Don't forward the value of the extended attribute if it would // unexpectedly change the behavior of a wrapping overlay layer. if strings.HasPrefix(XattrOverlayPrefix, name) { - return nil, syserror.ENODATA + return "", syserror.ENODATA } o.copyMu.RLock() if o.upper != nil { - b, err = o.upper.Getxattr(name) + s, err = o.upper.Getxattr(name) } else { - b, err = o.lower.Getxattr(name) + s, err = o.lower.Getxattr(name) } o.copyMu.RUnlock() - return b, err + return s, err } func overlayListxattr(o *overlayEntry) (map[string]struct{}, error) { |