Commit 6f46ced3 authored by Ivan Krasin's avatar Ivan Krasin

Get rid of returning os.Error within dispatch switch. Now I had to add several...

Get rid of returning os.Error within dispatch switch. Now I had to add several panics. TODO: remve them in the future
parent 2f1a241e
...@@ -72,28 +72,28 @@ func dispatch(fs FileSystem, in_data []byte, c *managerClient, toW chan [][]byte ...@@ -72,28 +72,28 @@ func dispatch(fs FileSystem, in_data []byte, c *managerClient, toW chan [][]byte
fmt.Printf("Opcode: %v, NodeId: %v, h: %v\n", h.Opcode, h.NodeId, h) fmt.Printf("Opcode: %v, NodeId: %v, h: %v\n", h.Opcode, h.NodeId, h)
switch h.Opcode { switch h.Opcode {
case FUSE_INIT: case FUSE_INIT:
out, err = initFuse(fs, h, r, c) out = initFuse(fs, h, r, c)
case FUSE_FORGET: case FUSE_FORGET:
return return
case FUSE_GETATTR: case FUSE_GETATTR:
out, err = getAttr(fs, h, r, c) out = getAttr(fs, h, r, c)
case FUSE_GETXATTR: case FUSE_GETXATTR:
out, err = getXAttr(h, r, c) out = getXAttr(h, r, c)
case FUSE_OPENDIR: case FUSE_OPENDIR:
out, err = openDir(h, r, c) out = openDir(h, r, c)
case FUSE_READDIR: case FUSE_READDIR:
out, err = readDir(h, r, c) out = readDir(h, r, c)
case FUSE_LOOKUP: case FUSE_LOOKUP:
out, err = lookup(h, r, c) out = lookup(h, r, c)
case FUSE_RELEASEDIR: case FUSE_RELEASEDIR:
out, err = releaseDir(h, r, c) out = releaseDir(h, r, c)
default: default:
errors <- os.NewError(fmt.Sprintf("Unsupported OpCode: %d", h.Opcode)) errors <- os.NewError(fmt.Sprintf("Unsupported OpCode: %d", h.Opcode))
out, err = serialize(h, ENOSYS, nil) out = serialize(h, ENOSYS, nil)
} }
if err != nil { if err != nil {
errors <- err errors <- err
out, err = serialize(h, EIO, nil) out = serialize(h, EIO, nil)
} }
if out == nil || len(out) == 0 { if out == nil || len(out) == 0 {
fmt.Printf("out is empty\n") fmt.Printf("out is empty\n")
...@@ -104,18 +104,17 @@ func dispatch(fs FileSystem, in_data []byte, c *managerClient, toW chan [][]byte ...@@ -104,18 +104,17 @@ func dispatch(fs FileSystem, in_data []byte, c *managerClient, toW chan [][]byte
toW <- out toW <- out
} }
func serialize(h *InHeader, res Status, out interface{}) (data [][]byte, err os.Error) { func serialize(h *InHeader, res Status, out interface{}) (data [][]byte) {
b := new(bytes.Buffer) b := new(bytes.Buffer)
out_data := make([]byte, 0) out_data := make([]byte, 0)
fmt.Printf("OpCode: %v result: %v\n", h.Opcode, res) fmt.Printf("OpCode: %v result: %v\n", h.Opcode, res)
if out != nil && res == OK { if out != nil && res == OK {
fmt.Printf("out = %v, out == nil: %v\n", out, out == nil) fmt.Printf("out = %v, out == nil: %v\n", out, out == nil)
err = binary.Write(b, binary.LittleEndian, out) err := binary.Write(b, binary.LittleEndian, out)
if err == nil { if err == nil {
out_data = b.Bytes() out_data = b.Bytes()
} else { } else {
err = os.NewError(fmt.Sprintf("Can serialize out: %v", err)) panic(fmt.Sprintf("Can't serialize out: %v, err: %v", out, err))
return
} }
} }
fmt.Printf("out_data: %v, len(out_data): %d, SizeOfOutHeader: %d\n", out_data, len(out_data), SizeOfOutHeader) fmt.Printf("out_data: %v, len(out_data): %d, SizeOfOutHeader: %d\n", out_data, len(out_data), SizeOfOutHeader)
...@@ -124,20 +123,20 @@ func serialize(h *InHeader, res Status, out interface{}) (data [][]byte, err os. ...@@ -124,20 +123,20 @@ func serialize(h *InHeader, res Status, out interface{}) (data [][]byte, err os.
hout.Status = res hout.Status = res
hout.Length = uint32(len(out_data) + SizeOfOutHeader) hout.Length = uint32(len(out_data) + SizeOfOutHeader)
b = new(bytes.Buffer) b = new(bytes.Buffer)
err = binary.Write(b, binary.LittleEndian, &hout) err := binary.Write(b, binary.LittleEndian, &hout)
if err != nil { if err != nil {
return panic("Can't serialize OutHeader")
} }
_, _ = b.Write(out_data) _, _ = b.Write(out_data)
data = [][]byte{b.Bytes()} data = [][]byte{b.Bytes()}
return return
} }
func initFuse(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.Error) { func initFuse(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data [][]byte) {
in := new(InitIn) in := new(InitIn)
err = binary.Read(r, binary.LittleEndian, in) err := binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
return return serialize(h, EIO, nil)
} }
fmt.Printf("in: %v\n", in) fmt.Printf("in: %v\n", in)
if in.Major != FUSE_KERNEL_VERSION { if in.Major != FUSE_KERNEL_VERSION {
...@@ -157,11 +156,11 @@ func initFuse(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data [ ...@@ -157,11 +156,11 @@ func initFuse(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data [
return serialize(h, OK, out) return serialize(h, OK, out)
} }
func getAttr(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.Error) { func getAttr(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data [][]byte) {
in := new(GetAttrIn) in := new(GetAttrIn)
err = binary.Read(r, binary.LittleEndian, in) err := binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
return return serialize(h, EIO, nil)
} }
fmt.Printf("FUSE_GETATTR: %v, Fh: %d\n", in, in.Fh) fmt.Printf("FUSE_GETATTR: %v, Fh: %d\n", in, in.Fh)
out := new(AttrOut) out := new(AttrOut)
...@@ -176,26 +175,22 @@ func getAttr(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data [] ...@@ -176,26 +175,22 @@ func getAttr(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data []
if attr != nil { if attr != nil {
out.Attr = *attr out.Attr = *attr
} else { } else {
err = os.NewError("fs.GetAttr returned nil as an Attr") return serialize(h, EIO, nil)
return
} }
out.Ino = h.NodeId out.Ino = h.NodeId
data, err = serialize(h, res, out) return serialize(h, res, out)
return
} }
func getXAttr(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.Error) { func getXAttr(h *InHeader, r io.Reader, c *managerClient) (data [][]byte) {
out := new(GetXAttrOut) out := new(GetXAttrOut)
data, err = serialize(h, OK, out) return serialize(h, OK, out)
return
} }
func openDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.Error) { func openDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte) {
in := new(OpenIn) in := new(OpenIn)
err = binary.Read(r, binary.LittleEndian, in) err := binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
data, _ = serialize(h, EIO, nil) return serialize(h, EIO, nil)
return
} }
fmt.Printf("FUSE_OPENDIR: %v\n", in) fmt.Printf("FUSE_OPENDIR: %v\n", in)
resp := c.openDir(h.NodeId) resp := c.openDir(h.NodeId)
...@@ -204,16 +199,14 @@ func openDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os. ...@@ -204,16 +199,14 @@ func openDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.
} }
out := new(OpenOut) out := new(OpenOut)
out.Fh = resp.fh out.Fh = resp.fh
data, err = serialize(h, OK, out) return serialize(h, OK, out)
return
} }
func readDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.Error) { func readDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte) {
in := new(ReadIn) in := new(ReadIn)
err = binary.Read(r, binary.LittleEndian, in) err := binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
data, _ = serialize(h, EIO, nil) return serialize(h, EIO, nil)
return
} }
fmt.Printf("FUSE_READDIR: %v\n", in) fmt.Printf("FUSE_READDIR: %v\n", in)
resp := c.getDirReader(h.NodeId, in.Fh) resp := c.getDirReader(h.NodeId, in.Fh)
...@@ -227,16 +220,12 @@ func readDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os. ...@@ -227,16 +220,12 @@ func readDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.
dirResp := <-dirRespChan dirResp := <-dirRespChan
fmt.Printf("received %v\n", dirResp) fmt.Printf("received %v\n", dirResp)
if dirResp.status != OK { if dirResp.status != OK {
data, _ = serialize(h, dirResp.status, nil) return serialize(h, dirResp.status, nil)
return
} }
if dirResp.entries == nil { if dirResp.entries == nil {
fmt.Printf("No entries\n") return serialize(h, OK, nil)
data, err = serialize(h, OK, nil)
return
} }
fmt.Printf("len(dirResp.entries): %v\n", len(dirResp.entries))
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
off := in.Offset off := in.Offset
for _, entry := range dirResp.entries { for _, entry := range dirResp.entries {
...@@ -248,8 +237,7 @@ func readDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os. ...@@ -248,8 +237,7 @@ func readDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.
dirent.Typ = (entry.mode & 0170000) >> 12 dirent.Typ = (entry.mode & 0170000) >> 12
err = binary.Write(buf, binary.LittleEndian, dirent) err = binary.Write(buf, binary.LittleEndian, dirent)
if err != nil { if err != nil {
fmt.Printf("AAA!!! binary.Write failed\n") panic("Serialization of Dirent failed")
os.Exit(1)
} }
buf.Write([]byte(entry.name)) buf.Write([]byte(entry.name))
buf.WriteByte(0) buf.WriteByte(0)
...@@ -259,13 +247,10 @@ func readDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os. ...@@ -259,13 +247,10 @@ func readDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.
} }
} }
out := buf.Bytes() out := buf.Bytes()
fmt.Printf("out: %v\n", out) return serialize(h, OK, out)
res := OK
data, err = serialize(h, res, out)
return
} }
func lookup(h *InHeader, r *bytes.Buffer, c *managerClient) (data [][]byte, err os.Error) { func lookup(h *InHeader, r *bytes.Buffer, c *managerClient) (data [][]byte) {
filename := string(r.Bytes()) filename := string(r.Bytes())
fmt.Printf("filename: %s\n", filename) fmt.Printf("filename: %s\n", filename)
resp := c.lookup(h.NodeId, filename) resp := c.lookup(h.NodeId, filename)
...@@ -277,17 +262,14 @@ func lookup(h *InHeader, r *bytes.Buffer, c *managerClient) (data [][]byte, err ...@@ -277,17 +262,14 @@ func lookup(h *InHeader, r *bytes.Buffer, c *managerClient) (data [][]byte, err
out.Attr = *resp.attr out.Attr = *resp.attr
out.AttrValid = 60 out.AttrValid = 60
out.EntryValid = 60 out.EntryValid = 60
res := OK return serialize(h, OK, out)
data, err = serialize(h, res, out)
return
} }
func releaseDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte, err os.Error) { func releaseDir(h *InHeader, r io.Reader, c *managerClient) (data [][]byte) {
in := new(ReleaseIn) in := new(ReleaseIn)
err = binary.Read(r, binary.LittleEndian, in) err := binary.Read(r, binary.LittleEndian, in)
if err != nil { if err != nil {
data, err = serialize(h, EIO, nil) return serialize(h, EIO, nil)
return
} }
fmt.Printf("FUSE_RELEASEDIR: %v\n", in) fmt.Printf("FUSE_RELEASEDIR: %v\n", in)
resp := c.closeDir(h.NodeId, in.Fh) resp := c.closeDir(h.NodeId, in.Fh)
...@@ -333,7 +315,7 @@ type managerResponse struct { ...@@ -333,7 +315,7 @@ type managerResponse struct {
nodeId uint64 nodeId uint64
fh uint64 fh uint64
dirReq chan *dirRequest dirReq chan *dirRequest
status Status status Status
attr *Attr attr *Attr
path string path string
} }
......
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