Esempio n. 1
0
func (s *fileSystemServer) ServeOps(c *fuse.Connection) {
	// When we are done, we clean up by waiting for all in-flight ops then
	// destroying the file system.
	defer func() {
		s.opsInFlight.Wait()
		s.fs.Destroy()
	}()

	for {
		op, err := c.ReadOp()
		if err == io.EOF {
			break
		}

		if err != nil {
			panic(err)
		}

		s.opsInFlight.Add(1)
		go s.handleOp(op)
	}
}
Esempio n. 2
0
func (s *fileSystemServer) handleOp(
	c *fuse.Connection,
	ctx context.Context,
	op interface{}) {
	defer s.opsInFlight.Done()

	// Dispatch to the appropriate method.
	var err error
	switch typed := op.(type) {
	default:
		err = fuse.ENOSYS

	case *fuseops.LookUpInodeOp:
		err = s.fs.LookUpInode(ctx, typed)

	case *fuseops.GetInodeAttributesOp:
		err = s.fs.GetInodeAttributes(ctx, typed)

	case *fuseops.SetInodeAttributesOp:
		err = s.fs.SetInodeAttributes(ctx, typed)

	case *fuseops.ForgetInodeOp:
		err = s.fs.ForgetInode(ctx, typed)

	case *fuseops.MkDirOp:
		err = s.fs.MkDir(ctx, typed)

	case *fuseops.CreateFileOp:
		err = s.fs.CreateFile(ctx, typed)

	case *fuseops.CreateSymlinkOp:
		err = s.fs.CreateSymlink(ctx, typed)

	case *fuseops.RenameOp:
		err = s.fs.Rename(ctx, typed)

	case *fuseops.RmDirOp:
		err = s.fs.RmDir(ctx, typed)

	case *fuseops.UnlinkOp:
		err = s.fs.Unlink(ctx, typed)

	case *fuseops.OpenDirOp:
		err = s.fs.OpenDir(ctx, typed)

	case *fuseops.ReadDirOp:
		err = s.fs.ReadDir(ctx, typed)

	case *fuseops.ReleaseDirHandleOp:
		err = s.fs.ReleaseDirHandle(ctx, typed)

	case *fuseops.OpenFileOp:
		err = s.fs.OpenFile(ctx, typed)

	case *fuseops.ReadFileOp:
		err = s.fs.ReadFile(ctx, typed)

	case *fuseops.WriteFileOp:
		err = s.fs.WriteFile(ctx, typed)

	case *fuseops.SyncFileOp:
		err = s.fs.SyncFile(ctx, typed)

	case *fuseops.FlushFileOp:
		err = s.fs.FlushFile(ctx, typed)

	case *fuseops.ReleaseFileHandleOp:
		err = s.fs.ReleaseFileHandle(ctx, typed)

	case *fuseops.ReadSymlinkOp:
		err = s.fs.ReadSymlink(ctx, typed)
	}

	c.Reply(ctx, err)
}