Commit 6364dc14 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b77b21f6
...@@ -307,9 +307,13 @@ type BigFile struct { ...@@ -307,9 +307,13 @@ type BigFile struct {
// XXX do we need to keep it here explicitly? // XXX do we need to keep it here explicitly?
zconn *zodb.Connection zconn *zodb.Connection
// ZBigFile top-level object. Kept always activated (XXX clarify) // ZBigFile top-level object. Kept activated during lifetime of current transaction.
zbf *ZBigFile zbf *ZBigFile
// zbf.Size(). It is constant during liftime of a transaction
// (we do only read-only txn) XXX -> organization overview.
zbfSize int64
// TODO // TODO
// lastChange zodb.Tid // last change to whole bigfile as of .zconn.At view // lastChange zodb.Tid // last change to whole bigfile as of .zconn.At view
} }
...@@ -417,6 +421,12 @@ func (bfroot *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) ( ...@@ -417,6 +421,12 @@ func (bfroot *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (
} }
}() }()
zbfSize, err := zbf.Size(ctx)
if err != nil {
log.Errorf("/bigfile: mkdir %q: %s", name, err)
return nil, fuse.EIO
}
// relock bfroot and either mkdir or EEXIST if the directory was maybe // relock bfroot and either mkdir or EEXIST if the directory was maybe
// simultanously created while we were not holding bfroot.mu // simultanously created while we were not holding bfroot.mu
bfroot.mu.Lock() bfroot.mu.Lock()
...@@ -439,6 +449,7 @@ func (bfroot *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) ( ...@@ -439,6 +449,7 @@ func (bfroot *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (
txnCtx: txnCtx, txnCtx: txnCtx,
zconn: zconn, zconn: zconn,
zbf: zbf, zbf: zbf,
zbfSize: zbfSize,
} }
bfdata := &BigFileData{ bfdata := &BigFileData{
...@@ -470,26 +481,15 @@ func (bfdata *BigFileData) GetAttr(out *fuse.Attr, _ nodefs.File, fctx *fuse.Con ...@@ -470,26 +481,15 @@ func (bfdata *BigFileData) GetAttr(out *fuse.Attr, _ nodefs.File, fctx *fuse.Con
// XXX locking // XXX locking
bf := bfdata.bigfile bf := bfdata.bigfile
zbf := bfdata.bigfile.zbf
// XXX better ctx = transaction.PutIntoContext(ctx, txn)
ctx, cancel := xcontext.Merge(asctx(fctx), bf.txnCtx)
defer cancel()
size, err := zbf.Size(ctx)
if err != nil {
log.Errorf("%s", err) // XXX errctx
return fuse.EIO // XXX extract EFBIG when it is the cause?
}
out.Mode = fuse.S_IFREG | 0444 out.Mode = fuse.S_IFREG | 0444
out.Size = uint64(size) out.Size = uint64(bf.zbfSize)
// .Blocks // .Blocks
// .Blksize // .Blksize
// FIXME lastChange should cover all bigfile data, not only ZBigFile itself // FIXME lastChange should cover all bigfile data, not only ZBigFile itself
//mtime := &bfdata.lastChange.Time().Time //mtime := &bfdata.lastChange.Time().Time
lastChange := bfdata.bigfile.zbf.PSerial() lastChange := bf.zbf.PSerial()
mtime := lastChange.Time().Time mtime := lastChange.Time().Time
out.SetTimes(/*atime=*/nil, /*mtime=*/&mtime, /*ctime=*/&mtime) out.SetTimes(/*atime=*/nil, /*mtime=*/&mtime, /*ctime=*/&mtime)
...@@ -505,17 +505,26 @@ func (bfdata *BigFileData) Read(_ nodefs.File, dest []byte, off int64, fctx *fus ...@@ -505,17 +505,26 @@ func (bfdata *BigFileData) Read(_ nodefs.File, dest []byte, off int64, fctx *fus
bf := bfdata.bigfile bf := bfdata.bigfile
zbf := bf.zbf zbf := bf.zbf
// XXX better ctx = transaction.PutIntoContext(ctx, txn) // cap read request to file size
ctx, cancel := xcontext.Merge(asctx(fctx), bf.txnCtx) end := off + int64(len(dest)) // XXX overflow?
defer cancel() if end > bf.zbfSize {
end = bf.zbfSize
}
if end <= off {
// XXX off >= size -> EINVAL? (but when size=0 kernel issues e.g. [0 +4K) read)
return fuse.ReadResultData(nil), fuse.OK
}
// widen read request to be aligned with blksize granularity // widen read request to be aligned with blksize granularity
// (we can load only whole ZBlk* blocks) // (we can load only whole ZBlk* blocks)
end := off + int64(len(dest)) // XXX overflow?
aoff := off - (off % zbf.blksize) aoff := off - (off % zbf.blksize)
aend := end + (zbf.blksize - (end % zbf.blksize)) aend := end + (zbf.blksize - (end % zbf.blksize))
dest = make([]byte, aend - aoff) // ~> [off:aend] in file dest = make([]byte, aend - aoff) // ~> [off:aend] in file
// XXX better ctx = transaction.PutIntoContext(ctx, txn)
ctx, cancel := xcontext.Merge(asctx(fctx), bf.txnCtx)
defer cancel()
// read/load all block(s) in parallel // read/load all block(s) in parallel
wg, ctx := errgroup.WithContext(ctx) wg, ctx := errgroup.WithContext(ctx)
for blkoff := aoff; blkoff < aend; blkoff += zbf.blksize { for blkoff := aoff; blkoff < aend; blkoff += zbf.blksize {
......
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