Refactored inode time tracking.

geesefs-0-30-9
Aaron Jacobs 2015-03-06 05:23:44 +11:00
parent 62bda89ca9
commit ab18be2378
2 changed files with 26 additions and 11 deletions

View File

@ -74,7 +74,7 @@ func NewMemFS(
Mode: 0700 | os.ModeDir,
}
fs.inodes[fuse.RootInodeID] = newInode(rootAttrs)
fs.inodes[fuse.RootInodeID] = newInode(clock, rootAttrs)
// Set up invariant checking.
fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants)
@ -163,7 +163,7 @@ func (fs *memFS) getInodeForReadingOrDie(id fuse.InodeID) (inode *inode) {
func (fs *memFS) allocateInode(
attrs fuse.InodeAttributes) (id fuse.InodeID, inode *inode) {
// Create and lock the inode.
inode = newInode(attrs)
inode = newInode(fs.clock, attrs)
inode.mu.Lock()
// Re-use a free ID if possible. Otherwise mint a new one.
@ -281,15 +281,10 @@ func (fs *memFS) MkDir(
// Set up attributes from the child, using the credentials of the calling
// process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8).
now := fs.clock.Now()
childAttrs := fuse.InodeAttributes{
Mode: req.Mode,
Atime: now,
Mtime: now,
Ctime: now,
Crtime: now,
Uid: req.Header.Uid,
Gid: req.Header.Gid,
Mode: req.Mode,
Uid: req.Header.Uid,
Gid: req.Header.Gid,
}
// Allocate a child.

View File

@ -22,6 +22,7 @@ import (
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/gcloud/syncutil"
"github.com/jacobsa/gcsfuse/timeutil"
)
// Common attributes for files and directories.
@ -30,6 +31,12 @@ import (
// been unlinked, including creating a new file. Make sure we don't screw up
// and reuse an inode ID while it is still in use.
type inode struct {
/////////////////////////
// Dependencies
/////////////////////////
clock timeutil.Clock
/////////////////////////
// Constant data
/////////////////////////
@ -84,9 +91,22 @@ type inode struct {
// Helpers
////////////////////////////////////////////////////////////////////////
// Create a new inode with the supplied attributes, which need not contain
// time-related information (the inode object will take care of that).
// Initially the link count is one.
func newInode(attrs fuse.InodeAttributes) (in *inode) {
func newInode(
clock timeutil.Clock,
attrs fuse.InodeAttributes) (in *inode) {
// Update time info.
now := clock.Now()
attrs.Atime = now
attrs.Mtime = now
attrs.Ctime = now
attrs.Crtime = now
// Create the object.
in = &inode{
clock: clock,
linkCount: 1,
dir: (attrs.Mode&os.ModeDir != 0),
attributes: attrs,