Skip to content

Commit

Permalink
Fix build breakage after API changes from bazil.org/fuse.
Browse files Browse the repository at this point in the history
  • Loading branch information
anupcshan committed Mar 17, 2015
1 parent 6efb59b commit b7c4df3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion buddyfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (bfs BuddyFS) CreateNewFSMetadata() *FSMeta {
blkGen: bfs.blkGen, Dirs: []Block{}, Files: []Block{}, Lock: sync.RWMutex{}}}
}

func (bfs *BuddyFS) Root() (fs.Node, fuse.Error) {
func (bfs *BuddyFS) Root() (fs.Node, error) {
bfs.Lock.Lock()
defer bfs.Lock.Unlock()

Expand Down
27 changes: 14 additions & 13 deletions buddyfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/buddyfs/gobuddyfs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"golang.org/x/net/context"
)

type MockKVStore struct {
Expand Down Expand Up @@ -197,12 +198,12 @@ func TestMkdirWithDuplicate(t *testing.T) {

root, _ := bfs.Root()

node, err := root.(*gobuddyfs.FSMeta).Mkdir(&fuse.MkdirRequest{Name: "foo"}, make(fs.Intr))
node, err := root.(*gobuddyfs.FSMeta).Mkdir(&fuse.MkdirRequest{Name: "foo"}, context.TODO())
assert.NoError(t, err)
assert.NotNil(t, node, "Newly created directory node should not be nil")

// Create duplicate directory
node, err = root.(*gobuddyfs.FSMeta).Mkdir(&fuse.MkdirRequest{Name: "foo"}, make(fs.Intr))
node, err = root.(*gobuddyfs.FSMeta).Mkdir(&fuse.MkdirRequest{Name: "foo"}, context.TODO())
assert.Error(t, err, "Duplicate directory name")
assert.Nil(t, node)
}
Expand All @@ -215,15 +216,15 @@ func TestParallelMkdirWithDuplicate(t *testing.T) {

const parallelism = 10
nodes := make([]fs.Node, parallelism)
errs := make([]fuse.Error, parallelism)
errs := make([]error, parallelism)
dones := make([]chan bool, parallelism)

for i := 0; i < parallelism; i++ {
dones[i] = make(chan bool)
}

mkdir := func(node *fs.Node, err *fuse.Error, done chan bool) {
*node, *err = root.(*gobuddyfs.FSMeta).Mkdir(&fuse.MkdirRequest{Name: "foo"}, make(fs.Intr))
mkdir := func(node *fs.Node, err *error, done chan bool) {
*node, *err = root.(*gobuddyfs.FSMeta).Mkdir(&fuse.MkdirRequest{Name: "foo"}, context.TODO())
done <- true
}

Expand Down Expand Up @@ -265,12 +266,12 @@ func TestCreateWithDuplicate(t *testing.T) {

root, _ := bfs.Root()

node, _, err := root.(*gobuddyfs.FSMeta).Create(&fuse.CreateRequest{Name: "foo"}, nil, make(fs.Intr))
node, _, err := root.(*gobuddyfs.FSMeta).Create(&fuse.CreateRequest{Name: "foo"}, nil, context.TODO())
assert.NoError(t, err)
assert.NotNil(t, node, "Newly created file node should not be nil")

// Create duplicate file
node, _, err = root.(*gobuddyfs.FSMeta).Create(&fuse.CreateRequest{Name: "foo"}, nil, make(fs.Intr))
node, _, err = root.(*gobuddyfs.FSMeta).Create(&fuse.CreateRequest{Name: "foo"}, nil, context.TODO())
assert.Error(t, err, "Duplicate file name")
assert.Nil(t, node)
}
Expand All @@ -283,15 +284,15 @@ func TestParallelCreateWithDuplicate(t *testing.T) {

const parallelism = 10
nodes := make([]fs.Node, parallelism)
errs := make([]fuse.Error, parallelism)
errs := make([]error, parallelism)
dones := make([]chan bool, parallelism)

for i := 0; i < parallelism; i++ {
dones[i] = make(chan bool)
}

mkdir := func(node *fs.Node, err *fuse.Error, done chan bool) {
*node, _, *err = root.(*gobuddyfs.FSMeta).Create(&fuse.CreateRequest{Name: "foo"}, nil, make(fs.Intr))
mkdir := func(node *fs.Node, err *error, done chan bool) {
*node, _, *err = root.(*gobuddyfs.FSMeta).Create(&fuse.CreateRequest{Name: "foo"}, nil, context.TODO())
done <- true
}

Expand Down Expand Up @@ -335,15 +336,15 @@ func TestParallelCreate(t *testing.T) {

const parallelism = 100
nodes := make([]fs.Node, parallelism)
errs := make([]fuse.Error, parallelism)
errs := make([]error, parallelism)
dones := make([]chan bool, parallelism)

for i := 0; i < parallelism; i++ {
dones[i] = make(chan bool)
}

mkdir := func(node *fs.Node, err *fuse.Error, done chan bool, name string) {
*node, _, *err = root.(*gobuddyfs.FSMeta).Create(&fuse.CreateRequest{Name: name}, nil, make(fs.Intr))
mkdir := func(node *fs.Node, err *error, done chan bool, name string) {
*node, _, *err = root.(*gobuddyfs.FSMeta).Create(&fuse.CreateRequest{Name: name}, nil, context.TODO())
done <- true
}

Expand Down
21 changes: 11 additions & 10 deletions dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"syscall"

"github.com/golang/glog"
"golang.org/x/net/context"

"bazil.org/fuse"
"bazil.org/fuse/fs"
Expand Down Expand Up @@ -45,15 +46,15 @@ func (dir Dir) Attr() fuse.Attr {
return fuse.Attr{Mode: os.ModeDir | 0555, Inode: uint64(dir.Id)}
}

func (dir *Dir) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
func (dir *Dir) Lookup(name string, ctx context.Context) (fs.Node, error) {
dir.Lock.RLock()
defer dir.Lock.RUnlock()

_, _, node, err := dir.LookupUnlocked(name, intr)
_, _, node, err := dir.LookupUnlocked(name, ctx)
return node, err
}

func (dir *Dir) LookupUnlocked(name string, intr fs.Intr) (bool, int, fs.Node, fuse.Error) {
func (dir *Dir) LookupUnlocked(name string, ctx context.Context) (bool, int, fs.Node, error) {
for dirId := range dir.Dirs {
if dir.Dirs[dirId].Name == name {
var dirDir Dir
Expand Down Expand Up @@ -91,7 +92,7 @@ func (dir *Dir) LookupUnlocked(name string, intr fs.Intr) (bool, int, fs.Node, f
return false, 0, nil, fuse.ENOENT
}

func (dir *Dir) Mkdir(req *fuse.MkdirRequest, intr fs.Intr) (fs.Node, fuse.Error) {
func (dir *Dir) Mkdir(req *fuse.MkdirRequest, ctx context.Context) (fs.Node, error) {
if glog.V(2) {
glog.Infof("Mkdir %s %d", req.Name, len(req.Name))
}
Expand All @@ -103,7 +104,7 @@ func (dir *Dir) Mkdir(req *fuse.MkdirRequest, intr fs.Intr) (fs.Node, fuse.Error
dir.Lock.Lock()
defer dir.Lock.Unlock()

_, _, _, err := dir.LookupUnlocked(req.Name, intr)
_, _, _, err := dir.LookupUnlocked(req.Name, ctx)
if err != fuse.ENOENT {
return nil, fuse.Errno(syscall.EEXIST)
}
Expand All @@ -128,7 +129,7 @@ func (dir *Dir) Mkdir(req *fuse.MkdirRequest, intr fs.Intr) (fs.Node, fuse.Error
return newDir, nil
}

func (dir *Dir) Remove(req *fuse.RemoveRequest, intr fs.Intr) fuse.Error {
func (dir *Dir) Remove(req *fuse.RemoveRequest, ctx context.Context) error {
if glog.V(2) {
glog.Infof("Removing %s %d", req.Name, len(req.Name))
}
Expand All @@ -139,7 +140,7 @@ func (dir *Dir) Remove(req *fuse.RemoveRequest, intr fs.Intr) fuse.Error {

dir.Lock.Lock()
defer dir.Lock.Unlock()
isDir, posn, node, err := dir.LookupUnlocked(req.Name, intr)
isDir, posn, node, err := dir.LookupUnlocked(req.Name, ctx)

if err != nil {
return err
Expand Down Expand Up @@ -177,7 +178,7 @@ func (dir *Dir) Remove(req *fuse.RemoveRequest, intr fs.Intr) fuse.Error {
return fuse.ENOSYS
}

func (dir *Dir) Create(req *fuse.CreateRequest, resp *fuse.CreateResponse, intr fs.Intr) (fs.Node, fs.Handle, fuse.Error) {
func (dir *Dir) Create(req *fuse.CreateRequest, resp *fuse.CreateResponse, ctx context.Context) (fs.Node, fs.Handle, error) {
if glog.V(2) {
glog.Infof("Creating file %s %d", req.Name, len(req.Name))
}
Expand All @@ -189,7 +190,7 @@ func (dir *Dir) Create(req *fuse.CreateRequest, resp *fuse.CreateResponse, intr
dir.Lock.Lock()
defer dir.Lock.Unlock()

_, _, _, err := dir.LookupUnlocked(req.Name, intr)
_, _, _, err := dir.LookupUnlocked(req.Name, ctx)
if err != fuse.ENOENT {
return nil, nil, fuse.Errno(syscall.EEXIST)
}
Expand All @@ -213,7 +214,7 @@ func (dir *Dir) Create(req *fuse.CreateRequest, resp *fuse.CreateResponse, intr
return newFile, newFile, nil
}

func (dir *Dir) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
func (dir *Dir) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
dirEnts := []fuse.Dirent{}

for dirId := range dir.Dirs {
Expand Down
21 changes: 11 additions & 10 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"github.com/golang/glog"
"golang.org/x/net/context"
)

// TODO: Determine a mechanism to spill over metadata chunks into more block(s).
Expand All @@ -31,7 +32,7 @@ type File struct {

var _ Marshalable = new(File)

func (file *File) Open(req *fuse.OpenRequest, res *fuse.OpenResponse, intr fs.Intr) (fs.Handle, fuse.Error) {
func (file *File) Open(req *fuse.OpenRequest, res *fuse.OpenResponse, ctx context.Context) (fs.Handle, error) {
if glog.V(2) {
glog.Infoln("Open called")
}
Expand Down Expand Up @@ -89,7 +90,7 @@ func blkCount(size uint64, BLK_SIZE uint64) uint64 {

// TODO: Should the return type be a standard error instead?
// TODO: Unit tests!
func (file *File) setSize(size uint64) fuse.Error {
func (file *File) setSize(size uint64) error {
newBlockCount := blkCount(size, BLOCK_SIZE)

if newBlockCount < uint64(len(file.Blocks)) {
Expand Down Expand Up @@ -127,7 +128,7 @@ func (file *File) setSize(size uint64) fuse.Error {
return nil
}

func (file *File) Setattr(req *fuse.SetattrRequest, res *fuse.SetattrResponse, intr fs.Intr) fuse.Error {
func (file *File) Setattr(req *fuse.SetattrRequest, res *fuse.SetattrResponse, ctx context.Context) error {
if glog.V(2) {
glog.Infoln("Setattr called")
glog.Infoln("Req: ", req)
Expand All @@ -149,13 +150,13 @@ func (file *File) Setattr(req *fuse.SetattrRequest, res *fuse.SetattrResponse, i

if metaChanges {
// There are metadata changes to the file, write back before proceeding.
return file.Flush(nil, intr)
return file.Flush(nil, ctx)
}

return nil
}

func (file *File) Write(req *fuse.WriteRequest, res *fuse.WriteResponse, intr fs.Intr) fuse.Error {
func (file *File) Write(req *fuse.WriteRequest, res *fuse.WriteResponse, ctx context.Context) error {
dataBytes := len(req.Data)
if glog.V(2) {
glog.Infof("Writing %d byte(s) at offset %d", dataBytes, req.Offset)
Expand Down Expand Up @@ -261,7 +262,7 @@ func (file File) Attr() fuse.Attr {
Blocks: uint64(len(file.Blocks)), Size: file.Size}
}

func (file *File) Release(req *fuse.ReleaseRequest, intr fs.Intr) fuse.Error {
func (file *File) Release(req *fuse.ReleaseRequest, ctx context.Context) error {
if glog.V(2) {
glog.Infoln("Release", file.Name)
}
Expand All @@ -274,7 +275,7 @@ func (file *File) Forget() {
}
}

func (file *File) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
func (file *File) Flush(req *fuse.FlushRequest, ctx context.Context) error {
if glog.V(2) {
glog.Infoln("FLUSH", file.Name, file.IsDirty())
}
Expand All @@ -301,14 +302,14 @@ func (file *File) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
return nil
}

func (file *File) Fsync(req *fuse.FsyncRequest, intr fs.Intr) fuse.Error {
func (file *File) Fsync(req *fuse.FsyncRequest, ctx context.Context) error {
if glog.V(2) {
glog.Infoln("FSYNC", file.Name, file.IsDirty())
}
return file.Flush(nil, intr)
return file.Flush(nil, ctx)
}

func (file *File) Read(req *fuse.ReadRequest, res *fuse.ReadResponse, intr fs.Intr) fuse.Error {
func (file *File) Read(req *fuse.ReadRequest, res *fuse.ReadResponse, ctx context.Context) error {
if glog.V(2) {
glog.Infof("Reading %d byte(s) at offset %d", req.Size, req.Offset)
}
Expand Down

0 comments on commit b7c4df3

Please sign in to comment.