提交 489786a5 作者: Steven Allen

files: update for MFS changes

1. Update to use the new `Open` function.
2. Use `Flush()` instead of `Sync()` as sync was removed as useless (this should
have been calling `Flush()` all along).

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 08cc5da5
......@@ -551,7 +551,7 @@ Examples:
return fmt.Errorf("%s was not a file", path)
}
rfd, err := fi.Open(mfs.OpenReadOnly, false)
rfd, err := fi.Open(mfs.Flags{Read: true})
if err != nil {
return err
}
......@@ -736,7 +736,7 @@ stat' on the file or any of its ancestors.
fi.RawLeaves = rawLeaves
}
wfd, err := fi.Open(mfs.OpenWriteOnly, flush)
wfd, err := fi.Open(mfs.Flags{Write: true, Sync: flush})
if err != nil {
return err
}
......
......@@ -402,12 +402,13 @@ func (fi *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fus
return nil
}
// Fsync flushes the content in the file to disk, but does not
// update the dag tree internally
// Fsync flushes the content in the file to disk.
func (fi *FileNode) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
// This needs to perform a *full* flush because, in MFS, a write isn't
// persisted until the root is updated.
errs := make(chan error, 1)
go func() {
errs <- fi.fi.Sync()
errs <- fi.fi.Flush()
}()
select {
case err := <-errs:
......@@ -418,7 +419,8 @@ func (fi *FileNode) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
}
func (fi *File) Forget() {
err := fi.fi.Sync()
// TODO(steb): this seems like a place where we should be *uncaching*, not flushing.
err := fi.fi.Flush()
if err != nil {
log.Debug("forget file error: ", err)
}
......@@ -434,19 +436,11 @@ func (dir *Directory) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Nod
}
func (fi *FileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
var mfsflag int
switch {
case req.Flags.IsReadOnly():
mfsflag = mfs.OpenReadOnly
case req.Flags.IsWriteOnly():
mfsflag = mfs.OpenWriteOnly
case req.Flags.IsReadWrite():
mfsflag = mfs.OpenReadWrite
default:
return nil, errors.New("unsupported flag type")
}
fd, err := fi.fi.Open(mfsflag, true)
fd, err := fi.fi.Open(mfs.Flags{
Read: req.Flags.IsReadOnly() || req.Flags.IsReadWrite(),
Write: req.Flags.IsWriteOnly() || req.Flags.IsReadWrite(),
Sync: true,
})
if err != nil {
return nil, err
}
......@@ -502,19 +496,11 @@ func (dir *Directory) Create(ctx context.Context, req *fuse.CreateRequest, resp
nodechild := &FileNode{fi: fi}
var openflag int
switch {
case req.Flags.IsReadOnly():
openflag = mfs.OpenReadOnly
case req.Flags.IsWriteOnly():
openflag = mfs.OpenWriteOnly
case req.Flags.IsReadWrite():
openflag = mfs.OpenReadWrite
default:
return nil, nil, errors.New("unsupported open mode")
}
fd, err := fi.Open(openflag, true)
fd, err := fi.Open(mfs.Flags{
Read: req.Flags.IsReadOnly() || req.Flags.IsReadWrite(),
Write: req.Flags.IsWriteOnly() || req.Flags.IsReadWrite(),
Sync: true,
})
if err != nil {
return nil, nil, err
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论