Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed May 2, 2024
1 parent e1f1409 commit 0b8d7f1
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 117 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/jacobsa/syncutil v0.0.0-20180201203307-228ac8e5a6c3
github.com/jacobsa/timeutil v0.0.0-20170205232429-577e5acbbcf6
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/stretchr/testify v1.9.0
github.com/urfave/cli v1.22.14
go.opencensus.io v0.24.0
golang.org/x/net v0.22.0
Expand Down Expand Up @@ -46,6 +47,7 @@ require (
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand All @@ -61,6 +63,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/pkg/xattr v0.4.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/prometheus v0.35.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
Expand Down
38 changes: 16 additions & 22 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/googlecloudplatform/gcsfuse/v2/internal/locker"
"github.com/googlecloudplatform/gcsfuse/v2/internal/logger"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/gcs"
. "github.com/googlecloudplatform/gcsfuse/v2/internal/util"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseutil"
Expand Down Expand Up @@ -1309,13 +1310,6 @@ func (fs *fileSystem) StatFS(
return
}

// isolateContextFromParentContext creates a copy of the parent context which is
// not cancelled when parent context is cancelled.
func isolateContextFromParentContext(ctx context.Context) (context.Context, context.CancelFunc) {
ctx = context.WithoutCancel(ctx)
return context.WithCancel(ctx)
}

// LOCKS_EXCLUDED(fs.mu)
func (fs *fileSystem) LookUpInode(
ctx context.Context,
Expand All @@ -1324,7 +1318,7 @@ func (fs *fileSystem) LookUpInode(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the parent directory in question.
Expand Down Expand Up @@ -1360,7 +1354,7 @@ func (fs *fileSystem) GetInodeAttributes(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the inode.
Expand Down Expand Up @@ -1388,7 +1382,7 @@ func (fs *fileSystem) SetInodeAttributes(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the inode.
Expand Down Expand Up @@ -1454,7 +1448,7 @@ func (fs *fileSystem) MkDir(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the parent.
Expand Down Expand Up @@ -1513,7 +1507,7 @@ func (fs *fileSystem) MkNode(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
if (op.Mode & (iofs.ModeNamedPipe | iofs.ModeSocket)) != 0 {
Expand Down Expand Up @@ -1643,7 +1637,7 @@ func (fs *fileSystem) CreateFile(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Create the child.
Expand Down Expand Up @@ -1692,7 +1686,7 @@ func (fs *fileSystem) CreateSymlink(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the parent.
Expand Down Expand Up @@ -1762,7 +1756,7 @@ func (fs *fileSystem) RmDir(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the parent.
Expand Down Expand Up @@ -1864,7 +1858,7 @@ func (fs *fileSystem) Rename(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the old and new parents.
Expand Down Expand Up @@ -2083,7 +2077,7 @@ func (fs *fileSystem) Unlink(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the parent.
Expand Down Expand Up @@ -2158,7 +2152,7 @@ func (fs *fileSystem) ReadDir(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the handle.
Expand Down Expand Up @@ -2230,7 +2224,7 @@ func (fs *fileSystem) ReadFile(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Save readOp in context for access in logs.
Expand Down Expand Up @@ -2281,7 +2275,7 @@ func (fs *fileSystem) WriteFile(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the inode.
Expand All @@ -2308,7 +2302,7 @@ func (fs *fileSystem) SyncFile(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the inode.
Expand Down Expand Up @@ -2341,7 +2335,7 @@ func (fs *fileSystem) FlushFile(
// When ignore interrupts config is set, we are creating a new context not
// cancellable by parent context.
var cancel context.CancelFunc
ctx, cancel = isolateContextFromParentContext(ctx)
ctx, cancel = IsolateContextFromParentContext(ctx)
defer cancel()
}
// Find the inode.
Expand Down
40 changes: 0 additions & 40 deletions internal/fs/interrupt_test.go

This file was deleted.

8 changes: 8 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package util

import (
"context"
"encoding/json"
"fmt"
"math"
Expand Down Expand Up @@ -102,3 +103,10 @@ func BytesToHigherMiBs(bytes uint64) uint64 {
const bytesInOneMiB uint64 = 1 << 20
return uint64(math.Ceil(float64(bytes) / float64(bytesInOneMiB)))
}

// IsolateContextFromParentContext creates a copy of the parent context which is
// not cancelled when parent context is cancelled.
func IsolateContextFromParentContext(ctx context.Context) (context.Context, context.CancelFunc) {
ctx = context.WithoutCancel(ctx)
return context.WithCancel(ctx)
}
Loading

0 comments on commit 0b8d7f1

Please sign in to comment.