diff options
author | Fabricio Voznika <fvoznika@google.com> | 2019-05-07 10:53:50 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-05-07 10:55:09 -0700 |
commit | e5432fa1b365edcebf9c8c01e2c40ade3014f282 (patch) | |
tree | f5cfa1035bee9fc11c6000e51f67ca92d30932bd | |
parent | 14f0e7618e28dac78ca7b00ec61fcec062159009 (diff) |
Remove defers from gofer.contextFile
Most are single line methods in hot paths.
PiperOrigin-RevId: 247050267
Change-Id: I428d78723fe00b57483185899dc8fa9e1f01e2ea
-rw-r--r-- | pkg/sentry/fs/gofer/context_file.go | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/pkg/sentry/fs/gofer/context_file.go b/pkg/sentry/fs/gofer/context_file.go index d512afefc..842a34af8 100644 --- a/pkg/sentry/fs/gofer/context_file.go +++ b/pkg/sentry/fs/gofer/context_file.go @@ -28,156 +28,156 @@ type contextFile struct { func (c *contextFile) walk(ctx context.Context, names []string) ([]p9.QID, contextFile, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) q, f, err := c.file.Walk(names) if err != nil { + ctx.UninterruptibleSleepFinish(false) return nil, contextFile{}, err } + ctx.UninterruptibleSleepFinish(false) return q, contextFile{file: f}, nil } func (c *contextFile) statFS(ctx context.Context) (p9.FSStat, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.StatFS() + s, err := c.file.StatFS() + ctx.UninterruptibleSleepFinish(false) + return s, err } func (c *contextFile) getAttr(ctx context.Context, req p9.AttrMask) (p9.QID, p9.AttrMask, p9.Attr, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.GetAttr(req) + q, m, a, err := c.file.GetAttr(req) + ctx.UninterruptibleSleepFinish(false) + return q, m, a, err } func (c *contextFile) setAttr(ctx context.Context, valid p9.SetAttrMask, attr p9.SetAttr) error { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.SetAttr(valid, attr) + err := c.file.SetAttr(valid, attr) + ctx.UninterruptibleSleepFinish(false) + return err } func (c *contextFile) rename(ctx context.Context, directory contextFile, name string) error { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Rename(directory.file, name) + err := c.file.Rename(directory.file, name) + ctx.UninterruptibleSleepFinish(false) + return err } func (c *contextFile) close(ctx context.Context) error { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Close() + err := c.file.Close() + ctx.UninterruptibleSleepFinish(false) + return err } func (c *contextFile) open(ctx context.Context, mode p9.OpenFlags) (*fd.FD, p9.QID, uint32, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Open(mode) + f, q, u, err := c.file.Open(mode) + ctx.UninterruptibleSleepFinish(false) + return f, q, u, err } func (c *contextFile) readAt(ctx context.Context, p []byte, offset uint64) (int, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.ReadAt(p, offset) + n, err := c.file.ReadAt(p, offset) + ctx.UninterruptibleSleepFinish(false) + return n, err } func (c *contextFile) writeAt(ctx context.Context, p []byte, offset uint64) (int, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.WriteAt(p, offset) + n, err := c.file.WriteAt(p, offset) + ctx.UninterruptibleSleepFinish(false) + return n, err } func (c *contextFile) fsync(ctx context.Context) error { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.FSync() + err := c.file.FSync() + ctx.UninterruptibleSleepFinish(false) + return err } func (c *contextFile) create(ctx context.Context, name string, flags p9.OpenFlags, permissions p9.FileMode, uid p9.UID, gid p9.GID) (*fd.FD, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - fd, _, _, _, err := c.file.Create(name, flags, permissions, uid, gid) + ctx.UninterruptibleSleepFinish(false) return fd, err } func (c *contextFile) mkdir(ctx context.Context, name string, permissions p9.FileMode, uid p9.UID, gid p9.GID) (p9.QID, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Mkdir(name, permissions, uid, gid) + q, err := c.file.Mkdir(name, permissions, uid, gid) + ctx.UninterruptibleSleepFinish(false) + return q, err } func (c *contextFile) symlink(ctx context.Context, oldName string, newName string, uid p9.UID, gid p9.GID) (p9.QID, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Symlink(oldName, newName, uid, gid) + q, err := c.file.Symlink(oldName, newName, uid, gid) + ctx.UninterruptibleSleepFinish(false) + return q, err } func (c *contextFile) link(ctx context.Context, target *contextFile, newName string) error { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Link(target.file, newName) + err := c.file.Link(target.file, newName) + ctx.UninterruptibleSleepFinish(false) + return err } func (c *contextFile) mknod(ctx context.Context, name string, permissions p9.FileMode, major uint32, minor uint32, uid p9.UID, gid p9.GID) (p9.QID, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Mknod(name, permissions, major, minor, uid, gid) + q, err := c.file.Mknod(name, permissions, major, minor, uid, gid) + ctx.UninterruptibleSleepFinish(false) + return q, err } func (c *contextFile) unlinkAt(ctx context.Context, name string, flags uint32) error { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.UnlinkAt(name, flags) + err := c.file.UnlinkAt(name, flags) + ctx.UninterruptibleSleepFinish(false) + return err } func (c *contextFile) readdir(ctx context.Context, offset uint64, count uint32) ([]p9.Dirent, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Readdir(offset, count) + d, err := c.file.Readdir(offset, count) + ctx.UninterruptibleSleepFinish(false) + return d, err } func (c *contextFile) readlink(ctx context.Context) (string, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Readlink() + s, err := c.file.Readlink() + ctx.UninterruptibleSleepFinish(false) + return s, err } func (c *contextFile) flush(ctx context.Context) error { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Flush() + err := c.file.Flush() + ctx.UninterruptibleSleepFinish(false) + return err } func (c *contextFile) walkGetAttr(ctx context.Context, names []string) ([]p9.QID, contextFile, p9.AttrMask, p9.Attr, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - q, f, m, a, err := c.file.WalkGetAttr(names) if err != nil { + ctx.UninterruptibleSleepFinish(false) return nil, contextFile{}, p9.AttrMask{}, p9.Attr{}, err } + ctx.UninterruptibleSleepFinish(false) return q, contextFile{file: f}, m, a, nil } func (c *contextFile) connect(ctx context.Context, flags p9.ConnectFlags) (*fd.FD, error) { ctx.UninterruptibleSleepStart(false) - defer ctx.UninterruptibleSleepFinish(false) - - return c.file.Connect(flags) + f, err := c.file.Connect(flags) + ctx.UninterruptibleSleepFinish(false) + return f, err } |