Commit 73732d44 authored by Aaron Jacobs's avatar Aaron Jacobs

Refactored and started on Convert.

parent 28f009d4
...@@ -17,10 +17,44 @@ ...@@ -17,10 +17,44 @@
// more. // more.
package fuseops package fuseops
import "github.com/jacobsa/bazilfuse" import (
"github.com/jacobsa/bazilfuse"
"golang.org/x/net/context"
)
// Convert the supplied bazilfuse request struct to an Op. // Convert the supplied bazilfuse request struct to an Op.
// //
// This function is an implementation detail of the fuse package, and must not // This function is an implementation detail of the fuse package, and must not
// be called by anyone else. // be called by anyone else.
func Convert(h *bazilfuse.Header) Op func Convert(r bazilfuse.Request) (o Op) {
var co *commonOp
switch r.(type) {
case *bazilfuse.InitRequest:
to := &InitOp{}
o = to
co = &to.commonOp
default:
panic("TODO")
}
co.init(r)
return
}
// A helper for embedding common behavior.
type commonOp struct {
ctx context.Context
r bazilfuse.Request
}
func (o *commonOp) init(r bazilfuse.Request)
func (o *commonOp) Header() OpHeader
func (o *commonOp) Context() context.Context {
return o.ctx
}
func (o *commonOp) Respond(err error)
...@@ -26,6 +26,9 @@ import ( ...@@ -26,6 +26,9 @@ import (
) )
type Op interface { type Op interface {
// Return the fields common to all operations.
Header() OpHeader
// A context that can be used for long-running operations. // A context that can be used for long-running operations.
Context() context.Context Context() context.Context
...@@ -41,7 +44,16 @@ type Op interface { ...@@ -41,7 +44,16 @@ type Op interface {
// Sent once when mounting the file system. It must succeed in order for the // Sent once when mounting the file system. It must succeed in order for the
// mount to succeed. // mount to succeed.
type InitOp struct { type InitOp struct {
Header OpHeader commonOp
}
func (o *InitOp) Respond(err error) {
if err != nil {
o.commonOp.Respond(err)
return
}
o.r.(*bazilfuse.InitRequest).Respond(&bazilfuse.InitResponse{})
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
...@@ -51,8 +63,6 @@ type InitOp struct { ...@@ -51,8 +63,6 @@ type InitOp struct {
// Look up a child by name within a parent directory. The kernel sends this // Look up a child by name within a parent directory. The kernel sends this
// when resolving user paths to dentry structs, which are then cached. // when resolving user paths to dentry structs, which are then cached.
type LookUpInodeOp struct { type LookUpInodeOp struct {
Header OpHeader
// The ID of the directory inode to which the child belongs. // The ID of the directory inode to which the child belongs.
Parent InodeID Parent InodeID
...@@ -76,8 +86,6 @@ type LookUpInodeOp struct { ...@@ -76,8 +86,6 @@ type LookUpInodeOp struct {
// inode attributes is stale. This is controlled by the AttributesExpiration // inode attributes is stale. This is controlled by the AttributesExpiration
// field of ChildInodeEntry, etc. // field of ChildInodeEntry, etc.
type GetInodeAttributesOp struct { type GetInodeAttributesOp struct {
Header OpHeader
// The inode of interest. // The inode of interest.
Inode InodeID Inode InodeID
...@@ -93,8 +101,6 @@ type GetInodeAttributesOp struct { ...@@ -93,8 +101,6 @@ type GetInodeAttributesOp struct {
// The kernel sends this for obvious cases like chmod(2), and for less obvious // The kernel sends this for obvious cases like chmod(2), and for less obvious
// cases like ftrunctate(2). // cases like ftrunctate(2).
type SetInodeAttributesOp struct { type SetInodeAttributesOp struct {
Header OpHeader
// The inode of interest. // The inode of interest.
Inode InodeID Inode InodeID
...@@ -114,8 +120,6 @@ type SetInodeAttributesOp struct { ...@@ -114,8 +120,6 @@ type SetInodeAttributesOp struct {
// Forget an inode ID previously issued (e.g. by LookUpInode or MkDir). The // Forget an inode ID previously issued (e.g. by LookUpInode or MkDir). The
// kernel sends this when removing an inode from its internal caches. // kernel sends this when removing an inode from its internal caches.
type ForgetInodeOp struct { type ForgetInodeOp struct {
Header OpHeader
// The inode to be forgotten. The kernel guarantees that the node ID will not // The inode to be forgotten. The kernel guarantees that the node ID will not
// be used in further calls to the file system (unless it is reissued by the // be used in further calls to the file system (unless it is reissued by the
// file system). // file system).
...@@ -134,8 +138,6 @@ type ForgetInodeOp struct { ...@@ -134,8 +138,6 @@ type ForgetInodeOp struct {
// http://goo.gl/FZpLu5). But volatile file systems and paranoid non-volatile // http://goo.gl/FZpLu5). But volatile file systems and paranoid non-volatile
// file systems should check for the reasons described below on CreateFile. // file systems should check for the reasons described below on CreateFile.
type MkDirOp struct { type MkDirOp struct {
Header OpHeader
// The ID of parent directory inode within which to create the child. // The ID of parent directory inode within which to create the child.
Parent InodeID Parent InodeID
...@@ -161,8 +163,6 @@ type MkDirOp struct { ...@@ -161,8 +163,6 @@ type MkDirOp struct {
// course particularly applies to file systems that are volatile from the // course particularly applies to file systems that are volatile from the
// kernel's point of view. // kernel's point of view.
type CreateFileOp struct { type CreateFileOp struct {
Header OpHeader
// The ID of parent directory inode within which to create the child file. // The ID of parent directory inode within which to create the child file.
Parent InodeID Parent InodeID
...@@ -199,8 +199,6 @@ type CreateFileOp struct { ...@@ -199,8 +199,6 @@ type CreateFileOp struct {
// //
// Sample implementation in ext2: ext2_rmdir (http://goo.gl/B9QmFf) // Sample implementation in ext2: ext2_rmdir (http://goo.gl/B9QmFf)
type RmDirOp struct { type RmDirOp struct {
Header OpHeader
// The ID of parent directory inode, and the name of the directory being // The ID of parent directory inode, and the name of the directory being
// removed within it. // removed within it.
Parent InodeID Parent InodeID
...@@ -213,8 +211,6 @@ type RmDirOp struct { ...@@ -213,8 +211,6 @@ type RmDirOp struct {
// //
// Sample implementation in ext2: ext2_unlink (http://goo.gl/hY6r6C) // Sample implementation in ext2: ext2_unlink (http://goo.gl/hY6r6C)
type UnlinkOp struct { type UnlinkOp struct {
Header OpHeader
// The ID of parent directory inode, and the name of the file being removed // The ID of parent directory inode, and the name of the file being removed
// within it. // within it.
Parent InodeID Parent InodeID
...@@ -232,8 +228,6 @@ type UnlinkOp struct { ...@@ -232,8 +228,6 @@ type UnlinkOp struct {
// user-space process. On OS X it may not be sent for every open(2) (cf. // user-space process. On OS X it may not be sent for every open(2) (cf.
// https://github.com/osxfuse/osxfuse/issues/199). // https://github.com/osxfuse/osxfuse/issues/199).
type OpenDirOp struct { type OpenDirOp struct {
Header OpHeader
// The ID of the inode to be opened. // The ID of the inode to be opened.
Inode InodeID Inode InodeID
...@@ -253,8 +247,6 @@ type OpenDirOp struct { ...@@ -253,8 +247,6 @@ type OpenDirOp struct {
// Read entries from a directory previously opened with OpenDir. // Read entries from a directory previously opened with OpenDir.
type ReadDirOp struct { type ReadDirOp struct {
Header OpHeader
// The directory inode that we are reading, and the handle previously // The directory inode that we are reading, and the handle previously
// returned by OpenDir when opening that inode. // returned by OpenDir when opening that inode.
Inode InodeID Inode InodeID
...@@ -348,8 +340,6 @@ type ReadDirOp struct { ...@@ -348,8 +340,6 @@ type ReadDirOp struct {
// The kernel guarantees that the handle ID will not be used in further ops // The kernel guarantees that the handle ID will not be used in further ops
// sent to the file system (unless it is reissued by the file system). // sent to the file system (unless it is reissued by the file system).
type ReleaseDirHandleOp struct { type ReleaseDirHandleOp struct {
Header OpHeader
// The handle ID to be released. The kernel guarantees that this ID will not // The handle ID to be released. The kernel guarantees that this ID will not
// be used in further calls to the file system (unless it is reissued by the // be used in further calls to the file system (unless it is reissued by the
// file system). // file system).
...@@ -367,8 +357,6 @@ type ReleaseDirHandleOp struct { ...@@ -367,8 +357,6 @@ type ReleaseDirHandleOp struct {
// process. On OS X it may not be sent for every open(2) // process. On OS X it may not be sent for every open(2)
// (cf.https://github.com/osxfuse/osxfuse/issues/199). // (cf.https://github.com/osxfuse/osxfuse/issues/199).
type OpenFileOp struct { type OpenFileOp struct {
Header OpHeader
// The ID of the inode to be opened. // The ID of the inode to be opened.
Inode InodeID Inode InodeID
...@@ -391,8 +379,6 @@ type OpenFileOp struct { ...@@ -391,8 +379,6 @@ type OpenFileOp struct {
// some reads may be served by the page cache. See notes on WriteFileOp for // some reads may be served by the page cache. See notes on WriteFileOp for
// more. // more.
type ReadFileOp struct { type ReadFileOp struct {
Header OpHeader
// The file inode that we are reading, and the handle previously returned by // The file inode that we are reading, and the handle previously returned by
// CreateFile or OpenFile when opening that inode. // CreateFile or OpenFile when opening that inode.
Inode InodeID Inode InodeID
...@@ -443,8 +429,6 @@ type ReadFileOp struct { ...@@ -443,8 +429,6 @@ type ReadFileOp struct {
// flush request. // flush request.
// //
type WriteFileOp struct { type WriteFileOp struct {
Header OpHeader
// The file inode that we are modifying, and the handle previously returned // The file inode that we are modifying, and the handle previously returned
// by CreateFile or OpenFile when opening that inode. // by CreateFile or OpenFile when opening that inode.
Inode InodeID Inode InodeID
...@@ -498,8 +482,6 @@ type WriteFileOp struct { ...@@ -498,8 +482,6 @@ type WriteFileOp struct {
// See also: FlushFileOp, which may perform a similar function when closing a // See also: FlushFileOp, which may perform a similar function when closing a
// file (but which is not used in "real" file systems). // file (but which is not used in "real" file systems).
type SyncFileOp struct { type SyncFileOp struct {
Header OpHeader
// The file and handle being sync'd. // The file and handle being sync'd.
Inode InodeID Inode InodeID
Handle HandleID Handle HandleID
...@@ -553,8 +535,6 @@ type SyncFileOp struct { ...@@ -553,8 +535,6 @@ type SyncFileOp struct {
// to at least schedule a real flush, and maybe do it immediately in order to // to at least schedule a real flush, and maybe do it immediately in order to
// return any errors that occur. // return any errors that occur.
type FlushFileOp struct { type FlushFileOp struct {
Header OpHeader
// The file and handle being flushed. // The file and handle being flushed.
Inode InodeID Inode InodeID
Handle HandleID Handle HandleID
...@@ -567,8 +547,6 @@ type FlushFileOp struct { ...@@ -567,8 +547,6 @@ type FlushFileOp struct {
// The kernel guarantees that the handle ID will not be used in further calls // The kernel guarantees that the handle ID will not be used in further calls
// to the file system (unless it is reissued by the file system). // to the file system (unless it is reissued by the file system).
type ReleaseFileHandleOp struct { type ReleaseFileHandleOp struct {
Header OpHeader
// The handle ID to be released. The kernel guarantees that this ID will not // The handle ID to be released. The kernel guarantees that this ID will not
// be used in further calls to the file system (unless it is reissued by the // be used in further calls to the file system (unless it is reissued by the
// file system). // file system).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment