Commit 0e64f33a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 657da1d0
...@@ -261,9 +261,7 @@ import ( ...@@ -261,9 +261,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
//"github.com/pkg/errors" "github.com/pkg/errors"
//pickle "github.com/kisielk/og-rek" // XXX should be temp here?
) )
// BigFileRoot represents "/bigfile" // BigFileRoot represents "/bigfile"
...@@ -278,15 +276,19 @@ type BigFileRoot struct { ...@@ -278,15 +276,19 @@ type BigFileRoot struct {
// BigFileDir represents "/bigfile/<bigfileX>" // BigFileDir represents "/bigfile/<bigfileX>"
type BigFileDir struct { type BigFileDir struct {
nodefs.Node nodefs.Node
oid zodb.Oid
root *BigFileRoot zdb *zodb.DB
// zconn *zodb.Conn
//oid zodb.Oid
//root *BigFileRoot
} }
// BigFileHead represents "/bigfile/<bigfileX>/head" // BigFileHead represents "/bigfile/<bigfileX>/head"
// XXX -> BigFileRev (with head | @tid) ? // XXX -> BigFileRev (with head | @tid) ?
type BigFileHead struct { type BigFileHead struct {
nodefs.Node nodefs.Node
x *BigFileDir //x *BigFileDir
data *BigFileData data *BigFileData
//at *BigFileAt //at *BigFileAt
...@@ -297,13 +299,13 @@ type BigFileHead struct { ...@@ -297,13 +299,13 @@ type BigFileHead struct {
// XXX also @<tidX>/data ? // XXX also @<tidX>/data ?
type BigFileData struct { type BigFileData struct {
nodefs.Node nodefs.Node
parent *BigFileHead // XXX name //parent *BigFileHead
topoid zodb.Oid // oid of ZBigFile zconn *zodb.Connection // ZODB connection via whcih .zbf is accessed
blksize int64 // ZBigFile.blksize XXX if it is changed - invalidate all? allowed to change? zbf *ZBigFile
head zodb.Tid // current view of ZODB // TODO
lastChange zodb.Tid // last change to whole bigfile as of .head view // lastChange zodb.Tid // last change to whole bigfile as of .zconn.At view
} }
...@@ -318,38 +320,38 @@ func NewBigFileRoot(zstor zodb.IStorage) *BigFileRoot { ...@@ -318,38 +320,38 @@ func NewBigFileRoot(zstor zodb.IStorage) *BigFileRoot {
} }
} }
func NewBigFileDir(oid zodb.Oid, root *BigFileRoot) *BigFileDir { // func NewBigFileDir(oid zodb.Oid, root *BigFileRoot) *BigFileDir {
bx := &BigFileDir{ // bx := &BigFileDir{
Node: nodefs.NewDefaultNode(), // Node: nodefs.NewDefaultNode(),
oid: oid, // oid: oid,
root: root, // //root: root,
} // }
//
return bx // return bx
} // }
func NewBigFileHead(x *BigFileDir) *BigFileHead {
f := &BigFileHead{Node: nodefs.NewDefaultNode(), x: x}
f.data = NewBigFileData(f)
// XXX + .at
return f // func NewBigFileHead(x *BigFileDir) *BigFileHead {
} // f := &BigFileHead{Node: nodefs.NewDefaultNode(), x: x}
// f.data = NewBigFileData(f)
//
// // XXX + .at
//
// return f
// }
func NewBigFileData(head *BigFileHead) *BigFileData { // func NewBigFileData(head *BigFileHead) *BigFileData {
return &BigFileData{Node: nodefs.NewDefaultNode(), parent: head} // return &BigFileData{Node: nodefs.NewDefaultNode(), parent: head}
} // }
// Mkdir receives client request to create /bigfile/<bigfileX>. // Mkdir receives client request to create /bigfile/<bigfileX>.
func (br *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (*nodefs.Inode, fuse.Status) { func (bfroot *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (*nodefs.Inode, fuse.Status) {
oid, err := zodb.ParseOid(name) oid, err := zodb.ParseOid(name)
if err != nil { if err != nil {
log.Printf("/bigfile: mkdir %q: not-oid", name) log.Printf("/bigfile: mkdir %q: not-oid", name)
...@@ -358,51 +360,35 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (*nod ...@@ -358,51 +360,35 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (*nod
// XXX ok to ignore mode? // XXX ok to ignore mode?
br.mu.Lock() // check to see if dir(oid) is already there
bfroot.mu.Lock()
_, already := bfroot.tab[oid]
bfroot.mu.Unlock()
if _, already := br.tab[oid]; already { if already {
return nil, fuse.Status(syscall.EEXIST) return nil, fuse.Status(syscall.EEXIST)
} }
br.mu.Unlock() // no - without bfroot lock proceed to load corresponding objects from ZODB
ctx := asctx(fctx) ctx := asctx(fctx)
_ = ctx
return nil, fuse.ENOSYS // XXX temp
// xbf, err := zconn.Get(ctx, oid)
// check err
// check if xbf.(*ZBigFile)
/* XXX kill
buf, _, err := br.zstor.Load(ctx, zodb.Xid{Oid: oid, At: zodb.TidMax}) // FIXME At, use serial
if err != nil {
switch errors.Cause(err).(type) {
case *zodb.NoObjectError:
return nil, fuse.EINVAL
case *zodb.NoDataError:
return nil, fuse.EINVAL // XXX ok?
default:
log.Printf("/bigfile: mkdir %q: %s", name, err)
return nil, fuse.EIO
}
}
pybf, err := zodb.PyData(buf.Data).Decode() // XXX create txn
// create new DB/Connection for this bigfile
zdb := zodb.NewDB(bfroot.zstor)
zconn, err := zdb.Open(ctx, &zodb.ConnOptions{}) // XXX .NoSync=true ?
if err != nil { if err != nil {
log.Printf("/bigfile: mkdir %q: %s", name, err) log.Printf("/bigfile: mkdir %q: %s", name, err)
return nil, fuse.EIO return nil, fuse.EIO
} }
*/
/* XXX reenable (.zpy not yet here) // XXX txn.Abort(), put conn back on error
pybf, err := br.zpy.Load(ctx, zodb.Xid{Oid: oid, At: zodb.TidMax}) // FIXME At, use serial
xzbf, err := zconn.Get(ctx, oid)
if err != nil { if err != nil {
switch errors.Cause(err).(type) { switch errors.Cause(err).(type) {
case *zodb.NoObjectError: case *zodb.NoObjectError:
// XXX log?
return nil, fuse.EINVAL return nil, fuse.EINVAL
case *zodb.NoDataError: case *zodb.NoDataError:
// XXX log?
return nil, fuse.EINVAL // XXX ok? return nil, fuse.EINVAL // XXX ok?
default: default:
log.Printf("/bigfile: mkdir %q: %s", name, err) log.Printf("/bigfile: mkdir %q: %s", name, err)
...@@ -410,34 +396,50 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (*nod ...@@ -410,34 +396,50 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (*nod
} }
} }
// XXX -> pyclass.FullName() != "wendelin.bigfile.file_zodb" + ".ZBigFile" zbf, ok := xzbf.(*ZBigFile)
pybfClass := pickle.Class{Module: "wendelin.bigfile.file_zodb", Name: ".ZBigFile"} if !ok {
if pybf.PyClass() != pybfClass { log.Printf("/bigfile: mkdir %q: %T is not a ZBigFile", name, xzbf)
// XXX log?
return nil, fuse.EINVAL return nil, fuse.EINVAL
} }
// XXX other checks?
// relock bfroot and either mkdir or EEXIST if the directory was maybe
// simultanously created while we were not holding bfroot.mu
bfroot.mu.Lock()
_, already = bfroot.tab[oid]
if already {
bfroot.mu.Unlock()
return nil, fuse.Status(syscall.EEXIST)
}
br.mu.Lock() bfdir := &BigFileDir{
defer br.mu.Unlock() Node: nodefs.NewDefaultNode(),
zdb: zdb,
}
// XXX recheck - maybe it was already created while we were not holding br.mu bfhead := &BigFileHead{
Node: nodefs.NewDefaultNode(),
}
bx := NewBigFileX(oid, br) bfdata := &BigFileData{
br.tab[oid] = bx Node: nodefs.NewDefaultNode(),
zconn: zconn,
zbf: zbf,
}
bh := NewBigFileHead(bx) bfhead.data = bfdata
mkdir(br, name, bx) // XXX takes treeLock - ok under br.mu ? bfroot.tab[oid] = bfdir
mkdir(bx, "head", bh) bfroot.mu.Unlock()
mkfile(bh, "data", bh.data)
// mkdir takes filesystem treeLock - do it outside bfroot.mu
mkdir(bfroot, name, bfdir)
mkdir(bfdir, "head", bfhead)
mkfile(bfhead, "data", bfdata)
// XXX mkfile(bh, "at", bh.at) // XXX mkfile(bh, "at", bh.at)
// XXX mkfile(bh, "invalidations", bh.inv) // XXX mkfile(bh, "invalidations", bh.inv)
return bx.Inode(), fuse.OK return bfdir.Inode(), fuse.OK
*/
} }
// XXX do we need to support rmdir? (probably no) // XXX do we need to support rmdir? (probably no)
......
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