Commit 9ce137f2 authored by Kirill Smelkov's avatar Kirill Smelkov

X wcfs moved -> wendelin.core

parent d02cfee4
package main
import (
"flag"
"fmt"
"log"
"os"
"time"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
)
// dir represents a directory in the filesystem.
type dir struct {
nodefs.Node
}
// file represents a file in the filesystem.
type file struct {
nodefs.Node
}
// fileHandle represents opened file.
type fileHandle struct {
nodefs.File
content []byte
}
// XXX recheck whether Lookup is needed
func (d *dir) Lookup(out *fuse.Attr, name string, _ *fuse.Context) (*nodefs.Inode, fuse.Status) {
ientry := d.Inode().GetChild(name)
if ientry == nil {
return nil, fuse.ENOENT
}
// XXX fill out
return ientry, fuse.OK
}
var nopen = 0
func (f *file) Open(flags uint32, _ *fuse.Context) (nodefs.File, fuse.Status) {
_, name := f.Inode().Parent()
nopen++ // XXX -> atomic
data := fmt.Sprintf("%04d %s\n", nopen, name)
h := &fileHandle{File: nodefs.NewDefaultFile(), content: []byte(data)}
// force direct-io to disable pagecache: we alway return different data
// and st_size=0 (like in /proc).
return &nodefs.WithFlags{
File: h,
FuseFlags: fuse.FOPEN_DIRECT_IO,
}, fuse.OK
}
func (fh *fileHandle) Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
l := int64(len(dest))
// XXX demonstrate we can indeed serve different content to different openings.
if l >= 1 {
l = 1
time.Sleep(1*time.Second)
}
end := off + l
if ldata := int64(len(fh.content)); end > ldata {
end = ldata
}
res := fh.content[off:end]
fmt.Printf("read [%d:%d] -> %q\n", off, end, res)
return fuse.ReadResultData(res), fuse.OK
}
func (d *dir) mkdir(name string) *dir {
child := &dir{Node: nodefs.NewDefaultNode()}
d.Inode().NewChild(name, true, child)
return child
}
func (d *dir) mkfile(name string) *file {
child := &file{Node: nodefs.NewDefaultNode()}
d.Inode().NewChild(name, false, child)
return child
}
func main() {
debug := flag.Bool("d", true, "debug")
flag.Parse()
if len(flag.Args()) != 1 {
log.Fatalf("Usage: %s mntpt", os.Args[0])
}
mntpt := flag.Args()[0]
root := &dir{Node: nodefs.NewDefaultNode()}
opts := nodefs.NewOptions()
if *debug {
opts.Debug = true
}
server, _, err := nodefs.MountRoot(mntpt, root, opts)
if err != nil {
log.Fatal(err) // XXX err ctx?
}
// NOTE cannot make entries before mount because Inode.AddChild does
// not work before that (panics on nil deref to mountRootXXX)
root.mkdir("aaa")
root.mkfile("hello.txt")
server.Serve() // XXX error?
}
digraph {
wcfs -> wcfs_simple;
wcfs -> ZODB_go_inv;
wcfs -> Sinvtree;
wcfs -> δR;
wcfs_simple -> Btree_read;
wcfs_simple -> ZBlk_read;
client -> wcfs_spawn;
client -> δR;
client -> nowcfs;
wcfs [label="wcfs"]
wcfs_simple [label="wcfs no\ninvalidations"]
client [label="client"]
wcfs_spawn [label="spawn wcfs"]
nowcfs [label="!wcfs mode"]
ZODB_go_inv [label="ZODB/go\ninvalidations"]
Btree_read [label="BTree read"]
ZBlk_read [label="ZBigFile / ZBlk* read"]
Sinvtree [label="server: inv. tree"]
δR [label="δR encoding"]
test [label="? tests"]
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: %3 Pages: 1 -->
<svg width="864pt" height="206pt"
viewBox="0.00 0.00 863.69 205.74" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 201.7401)">
<title>%3</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-201.7401 859.6909,-201.7401 859.6909,4 -4,4"/>
<!-- wcfs -->
<g id="node1" class="node">
<title>wcfs</title>
<ellipse fill="none" stroke="#000000" cx="342.0456" cy="-179.7401" rx="27.0966" ry="18"/>
<text text-anchor="middle" x="342.0456" y="-176.0401" font-family="Times,serif" font-size="14.00" fill="#000000">wcfs</text>
</g>
<!-- wcfs_simple -->
<g id="node2" class="node">
<title>wcfs_simple</title>
<ellipse fill="none" stroke="#000000" cx="129.0456" cy="-98.8701" rx="60.623" ry="26.7407"/>
<text text-anchor="middle" x="129.0456" y="-102.6701" font-family="Times,serif" font-size="14.00" fill="#000000">wcfs no</text>
<text text-anchor="middle" x="129.0456" y="-87.6701" font-family="Times,serif" font-size="14.00" fill="#000000">invalidations</text>
</g>
<!-- wcfs&#45;&gt;wcfs_simple -->
<g id="edge1" class="edge">
<title>wcfs&#45;&gt;wcfs_simple</title>
<path fill="none" stroke="#000000" d="M318.2464,-170.7982C289.8538,-160.1201 240.9589,-141.6981 199.0456,-125.7401 194.301,-123.9337 189.3775,-122.0541 184.4396,-120.1654"/>
<polygon fill="#000000" stroke="#000000" points="185.5598,-116.8466 174.9694,-116.5393 183.0567,-123.3838 185.5598,-116.8466"/>
</g>
<!-- ZODB_go_inv -->
<g id="node3" class="node">
<title>ZODB_go_inv</title>
<ellipse fill="none" stroke="#000000" cx="269.0456" cy="-98.8701" rx="60.623" ry="26.7407"/>
<text text-anchor="middle" x="269.0456" y="-102.6701" font-family="Times,serif" font-size="14.00" fill="#000000">ZODB/go</text>
<text text-anchor="middle" x="269.0456" y="-87.6701" font-family="Times,serif" font-size="14.00" fill="#000000">invalidations</text>
</g>
<!-- wcfs&#45;&gt;ZODB_go_inv -->
<g id="edge2" class="edge">
<title>wcfs&#45;&gt;ZODB_go_inv</title>
<path fill="none" stroke="#000000" d="M327.9704,-164.1476C319.622,-154.8991 308.7181,-142.8196 298.5632,-131.5699"/>
<polygon fill="#000000" stroke="#000000" points="300.9919,-129.0371 291.6932,-123.9593 295.7958,-133.7276 300.9919,-129.0371"/>
</g>
<!-- Sinvtree -->
<g id="node4" class="node">
<title>Sinvtree</title>
<ellipse fill="none" stroke="#000000" cx="414.0456" cy="-98.8701" rx="66.0889" ry="18"/>
<text text-anchor="middle" x="414.0456" y="-95.1701" font-family="Times,serif" font-size="14.00" fill="#000000">server: inv. tree</text>
</g>
<!-- wcfs&#45;&gt;Sinvtree -->
<g id="edge3" class="edge">
<title>wcfs&#45;&gt;Sinvtree</title>
<path fill="none" stroke="#000000" d="M355.9279,-164.1476C366.0124,-152.8207 379.8773,-137.2477 391.5356,-124.1531"/>
<polygon fill="#000000" stroke="#000000" points="394.4204,-126.1765 398.4559,-116.3803 389.1922,-121.5217 394.4204,-126.1765"/>
</g>
<!-- δR -->
<g id="node5" class="node">
<title>δR</title>
<ellipse fill="none" stroke="#000000" cx="554.0456" cy="-98.8701" rx="55.7903" ry="18"/>
<text text-anchor="middle" x="554.0456" y="-95.1701" font-family="Times,serif" font-size="14.00" fill="#000000">δR encoding</text>
</g>
<!-- wcfs&#45;&gt;δR -->
<g id="edge4" class="edge">
<title>wcfs&#45;&gt;δR</title>
<path fill="none" stroke="#000000" d="M366.3483,-171.1484C395.5899,-160.7334 446.1138,-142.4915 489.0456,-125.7401 496.006,-123.0242 503.3525,-120.0716 510.5028,-117.1505"/>
<polygon fill="#000000" stroke="#000000" points="512.1604,-120.2533 520.077,-113.212 509.4973,-113.7796 512.1604,-120.2533"/>
</g>
<!-- Btree_read -->
<g id="node6" class="node">
<title>Btree_read</title>
<ellipse fill="none" stroke="#000000" cx="50.0456" cy="-18" rx="50.0912" ry="18"/>
<text text-anchor="middle" x="50.0456" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">BTree read</text>
</g>
<!-- wcfs_simple&#45;&gt;Btree_read -->
<g id="edge5" class="edge">
<title>wcfs_simple&#45;&gt;Btree_read</title>
<path fill="none" stroke="#000000" d="M104.9137,-74.167C95.0785,-64.0989 83.7372,-52.4892 73.9278,-42.4475"/>
<polygon fill="#000000" stroke="#000000" points="76.2668,-39.8333 66.7753,-35.1257 71.2595,-44.7248 76.2668,-39.8333"/>
</g>
<!-- ZBlk_read -->
<g id="node7" class="node">
<title>ZBlk_read</title>
<ellipse fill="none" stroke="#000000" cx="208.0456" cy="-18" rx="89.8845" ry="18"/>
<text text-anchor="middle" x="208.0456" y="-14.3" font-family="Times,serif" font-size="14.00" fill="#000000">ZBigFile / ZBlk* read</text>
</g>
<!-- wcfs_simple&#45;&gt;ZBlk_read -->
<g id="edge6" class="edge">
<title>wcfs_simple&#45;&gt;ZBlk_read</title>
<path fill="none" stroke="#000000" d="M153.1774,-74.167C162.7957,-64.321 173.8543,-53.0007 183.512,-43.1143"/>
<polygon fill="#000000" stroke="#000000" points="186.093,-45.4809 190.5772,-35.8818 181.0856,-40.5894 186.093,-45.4809"/>
</g>
<!-- client -->
<g id="node8" class="node">
<title>client</title>
<ellipse fill="none" stroke="#000000" cx="680.0456" cy="-179.7401" rx="30.5947" ry="18"/>
<text text-anchor="middle" x="680.0456" y="-176.0401" font-family="Times,serif" font-size="14.00" fill="#000000">client</text>
</g>
<!-- client&#45;&gt;δR -->
<g id="edge8" class="edge">
<title>client&#45;&gt;δR</title>
<path fill="none" stroke="#000000" d="M659.2392,-166.3861C639.8634,-153.9502 610.6331,-135.1894 587.8985,-120.5978"/>
<polygon fill="#000000" stroke="#000000" points="589.5328,-117.4878 579.2265,-115.0319 585.7518,-123.3789 589.5328,-117.4878"/>
</g>
<!-- wcfs_spawn -->
<g id="node9" class="node">
<title>wcfs_spawn</title>
<ellipse fill="none" stroke="#000000" cx="680.0456" cy="-98.8701" rx="51.9908" ry="18"/>
<text text-anchor="middle" x="680.0456" y="-95.1701" font-family="Times,serif" font-size="14.00" fill="#000000">spawn wcfs</text>
</g>
<!-- client&#45;&gt;wcfs_spawn -->
<g id="edge7" class="edge">
<title>client&#45;&gt;wcfs_spawn</title>
<path fill="none" stroke="#000000" d="M680.0456,-161.3894C680.0456,-151.3599 680.0456,-138.7154 680.0456,-127.4265"/>
<polygon fill="#000000" stroke="#000000" points="683.5457,-127.1481 680.0456,-117.1481 676.5457,-127.1481 683.5457,-127.1481"/>
</g>
<!-- nowcfs -->
<g id="node10" class="node">
<title>nowcfs</title>
<ellipse fill="none" stroke="#000000" cx="803.0456" cy="-98.8701" rx="52.7911" ry="18"/>
<text text-anchor="middle" x="803.0456" y="-95.1701" font-family="Times,serif" font-size="14.00" fill="#000000">!wcfs mode</text>
</g>
<!-- client&#45;&gt;nowcfs -->
<g id="edge9" class="edge">
<title>client&#45;&gt;nowcfs</title>
<path fill="none" stroke="#000000" d="M700.633,-166.2043C719.5906,-153.74 748.0404,-135.0349 770.1469,-120.5002"/>
<polygon fill="#000000" stroke="#000000" points="772.1452,-123.3752 778.5781,-114.9569 768.2995,-117.5262 772.1452,-123.3752"/>
</g>
<!-- test -->
<g id="node11" class="node">
<title>test</title>
<ellipse fill="none" stroke="#000000" cx="761.0456" cy="-179.7401" rx="32.4942" ry="18"/>
<text text-anchor="middle" x="761.0456" y="-176.0401" font-family="Times,serif" font-size="14.00" fill="#000000">? tests</text>
</g>
</g>
</svg>
This diff is collapsed.
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