Commit dc73e9f1 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse: add SetAttrTimeout, SetEntryTimeout, SetTimeout to AttrOut/EntryOut

parent d0fca860
...@@ -64,8 +64,8 @@ func (m *fileSystemMount) setOwner(attr *fuse.Attr) { ...@@ -64,8 +64,8 @@ func (m *fileSystemMount) setOwner(attr *fuse.Attr) {
} }
func (m *fileSystemMount) fillEntry(out *fuse.EntryOut) { func (m *fileSystemMount) fillEntry(out *fuse.EntryOut) {
splitDuration(m.options.EntryTimeout, &out.EntryValid, &out.EntryValidNsec) out.SetEntryTimeout(m.options.EntryTimeout)
splitDuration(m.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec) out.SetAttrTimeout(m.options.AttrTimeout)
m.setOwner(&out.Attr) m.setOwner(&out.Attr)
if out.Mode&fuse.S_IFDIR == 0 && out.Nlink == 0 { if out.Mode&fuse.S_IFDIR == 0 && out.Nlink == 0 {
out.Nlink = 1 out.Nlink = 1
...@@ -73,7 +73,7 @@ func (m *fileSystemMount) fillEntry(out *fuse.EntryOut) { ...@@ -73,7 +73,7 @@ func (m *fileSystemMount) fillEntry(out *fuse.EntryOut) {
} }
func (m *fileSystemMount) fillAttr(out *fuse.AttrOut, nodeId uint64) { func (m *fileSystemMount) fillAttr(out *fuse.AttrOut, nodeId uint64) {
splitDuration(m.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec) out.SetTimeout(m.options.AttrTimeout)
m.setOwner(&out.Attr) m.setOwner(&out.Attr)
if out.Ino == 0 { if out.Ino == 0 {
out.Ino = nodeId out.Ino = nodeId
...@@ -179,7 +179,7 @@ func (m *fileSystemMount) registerFileHandle(node *Inode, dir *connectorDir, f F ...@@ -179,7 +179,7 @@ func (m *fileSystemMount) registerFileHandle(node *Inode, dir *connectorDir, f F
func (m *fileSystemMount) negativeEntry(out *fuse.EntryOut) bool { func (m *fileSystemMount) negativeEntry(out *fuse.EntryOut) bool {
if m.options.NegativeTimeout > 0.0 { if m.options.NegativeTimeout > 0.0 {
out.NodeId = 0 out.NodeId = 0
splitDuration(m.options.NegativeTimeout, &out.EntryValid, &out.EntryValidNsec) out.SetEntryTimeout(m.options.NegativeTimeout)
return true return true
} }
return false return false
......
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package nodefs
import "time"
func splitDuration(dt time.Duration, secs *uint64, nsecs *uint32) {
ns := int64(dt)
*nsecs = uint32(ns % 1e9)
*secs = uint64(ns / 1e9)
}
...@@ -7,6 +7,7 @@ package fuse ...@@ -7,6 +7,7 @@ package fuse
import ( import (
"io" "io"
"syscall" "syscall"
"time"
) )
const ( const (
...@@ -433,6 +434,18 @@ type EntryOut struct { ...@@ -433,6 +434,18 @@ type EntryOut struct {
Attr Attr
} }
func (o *EntryOut) SetEntryTimeout(dt time.Duration) {
ns := int64(dt)
o.EntryValidNsec = uint32(ns % 1e9)
o.EntryValid = uint64(ns / 1e9)
}
func (o *EntryOut) SetAttrTimeout(dt time.Duration) {
ns := int64(dt)
o.AttrValidNsec = uint32(ns % 1e9)
o.AttrValid = uint64(ns / 1e9)
}
type AttrOut struct { type AttrOut struct {
AttrValid uint64 AttrValid uint64
AttrValidNsec uint32 AttrValidNsec uint32
...@@ -440,6 +453,12 @@ type AttrOut struct { ...@@ -440,6 +453,12 @@ type AttrOut struct {
Attr Attr
} }
func (o *AttrOut) SetTimeout(dt time.Duration) {
ns := int64(dt)
o.AttrValidNsec = uint32(ns % 1e9)
o.AttrValid = uint64(ns / 1e9)
}
type CreateOut struct { type CreateOut struct {
EntryOut EntryOut
OpenOut OpenOut
......
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