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

.

parent b77b21f6
......@@ -307,9 +307,13 @@ type BigFile struct {
// XXX do we need to keep it here explicitly?
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.Size(). It is constant during liftime of a transaction
// (we do only read-only txn) XXX -> organization overview.
zbfSize int64
// TODO
// 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) (
}
}()
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
// simultanously created while we were not holding bfroot.mu
bfroot.mu.Lock()
......@@ -436,9 +446,10 @@ func (bfroot *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (
}
bf := &BigFile{
txnCtx: txnCtx,
zconn: zconn,
zbf: zbf,
txnCtx: txnCtx,
zconn: zconn,
zbf: zbf,
zbfSize: zbfSize,
}
bfdata := &BigFileData{
......@@ -470,26 +481,15 @@ func (bfdata *BigFileData) GetAttr(out *fuse.Attr, _ nodefs.File, fctx *fuse.Con
// XXX locking
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.Size = uint64(size)
out.Size = uint64(bf.zbfSize)
// .Blocks
// .Blksize
// FIXME lastChange should cover all bigfile data, not only ZBigFile itself
//mtime := &bfdata.lastChange.Time().Time
lastChange := bfdata.bigfile.zbf.PSerial()
lastChange := bf.zbf.PSerial()
mtime := lastChange.Time().Time
out.SetTimes(/*atime=*/nil, /*mtime=*/&mtime, /*ctime=*/&mtime)
......@@ -505,17 +505,26 @@ func (bfdata *BigFileData) Read(_ nodefs.File, dest []byte, off int64, fctx *fus
bf := bfdata.bigfile
zbf := bf.zbf
// XXX better ctx = transaction.PutIntoContext(ctx, txn)
ctx, cancel := xcontext.Merge(asctx(fctx), bf.txnCtx)
defer cancel()
// cap read request to file size
end := off + int64(len(dest)) // XXX overflow?
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
// (we can load only whole ZBlk* blocks)
end := off + int64(len(dest)) // XXX overflow?
aoff := off - (off % zbf.blksize)
aend := end + (zbf.blksize - (end % zbf.blksize))
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
wg, ctx := errgroup.WithContext(ctx)
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