Commit 524a7603 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Fix fsInode.TestDoubleOpen()

parent efb4ad35
...@@ -170,15 +170,16 @@ func (me *fsInode) GetAttr(file File, context *Context) (fi *os.FileInfo, code S ...@@ -170,15 +170,16 @@ func (me *fsInode) GetAttr(file File, context *Context) (fi *os.FileInfo, code S
} }
func (me *fsInode) Chmod(file File, perms uint32, context *Context) (code Status) { func (me *fsInode) Chmod(file File, perms uint32, context *Context) (code Status) {
if file == nil { files := me.inode.getWritableFiles()
file = me.inode.getWritableFile() for _, f := range files {
}
if file != nil {
// TODO - pass context // TODO - pass context
code = file.Chmod(perms) code = f.Chmod(perms)
} if !code.Ok() {
break
}
}
if file == nil || code == ENOSYS { if len(files) == 0 || code == ENOSYS {
code = me.inode.mount.fs.Chmod(me.GetPath(), perms, context) code = me.inode.mount.fs.Chmod(me.GetPath(), perms, context)
} }
return code return code
...@@ -186,11 +187,15 @@ func (me *fsInode) Chmod(file File, perms uint32, context *Context) (code Status ...@@ -186,11 +187,15 @@ func (me *fsInode) Chmod(file File, perms uint32, context *Context) (code Status
func (me *fsInode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) { func (me *fsInode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) {
if file != nil { files := me.inode.getWritableFiles()
for _, f := range files {
// TODO - pass context // TODO - pass context
code = file.Chown(uid, gid) code = f.Chown(uid, gid)
if !code.Ok() {
break
}
} }
if file == nil || code == ENOSYS { if len(files) == 0 || code == ENOSYS {
// TODO - can we get just FATTR_GID but not FATTR_UID ? // TODO - can we get just FATTR_GID but not FATTR_UID ?
code = me.inode.mount.fs.Chown(me.GetPath(), uid, gid, context) code = me.inode.mount.fs.Chown(me.GetPath(), uid, gid, context)
} }
...@@ -198,26 +203,31 @@ func (me *fsInode) Chown(file File, uid uint32, gid uint32, context *Context) (c ...@@ -198,26 +203,31 @@ func (me *fsInode) Chown(file File, uid uint32, gid uint32, context *Context) (c
} }
func (me *fsInode) Truncate(file File, size uint64, context *Context) (code Status) { func (me *fsInode) Truncate(file File, size uint64, context *Context) (code Status) {
if file == nil { files := me.inode.getWritableFiles()
file = me.inode.getWritableFile() for _, f := range files {
} // TODO - pass context
if file != nil { log.Println("truncating file", f)
code = file.Truncate(size) code = f.Truncate(size)
if !code.Ok() {
break
}
} }
if file == nil || code == ENOSYS { if len(files) == 0 || code == ENOSYS {
code = me.inode.mount.fs.Truncate(me.GetPath(), size, context) code = me.inode.mount.fs.Truncate(me.GetPath(), size, context)
} }
return code return code
} }
func (me *fsInode) Utimens(file File, atime uint64, mtime uint64, context *Context) (code Status) { func (me *fsInode) Utimens(file File, atime uint64, mtime uint64, context *Context) (code Status) {
if file == nil { files := me.inode.getWritableFiles()
file = me.inode.getWritableFile() for _, f := range files {
} // TODO - pass context
if file != nil { code = f.Utimens(atime, mtime)
code = file.Utimens(atime, mtime) if !code.Ok() {
break
}
} }
if file == nil || code == ENOSYS { if len(files) == 0 || code == ENOSYS {
code = me.inode.mount.fs.Utimens(me.GetPath(), atime, mtime, context) code = me.inode.mount.fs.Utimens(me.GetPath(), atime, mtime, context)
} }
return code return code
......
...@@ -260,16 +260,16 @@ func (me *inode) getAnyFile() (file File) { ...@@ -260,16 +260,16 @@ func (me *inode) getAnyFile() (file File) {
} }
// Returns an open writable file for the given inode. // Returns an open writable file for the given inode.
func (me *inode) getWritableFile() (file File) { func (me *inode) getWritableFiles() (files []File) {
me.OpenFilesMutex.Lock() me.OpenFilesMutex.Lock()
defer me.OpenFilesMutex.Unlock() defer me.OpenFilesMutex.Unlock()
for _, f := range me.OpenFiles { for _, f := range me.OpenFiles {
if f.OpenFlags & O_ANYWRITE != 0 { if f.OpenFlags & O_ANYWRITE != 0 {
return f.file files = append(files, f.file)
} }
} }
return nil return files
} }
const initDirSize = 20 const initDirSize = 20
......
...@@ -159,15 +159,21 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out ...@@ -159,15 +159,21 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out
} }
node := me.getInodeData(header.NodeId) node := me.getInodeData(header.NodeId)
fi, code := node.fsInode.GetAttr(f, &header.Context)
if code.Ok() && input.Valid&FATTR_MODE != 0 { if code.Ok() && input.Valid&FATTR_MODE != 0 {
permissions := uint32(07777) & input.Mode permissions := uint32(07777) & input.Mode
code = node.fsInode.Chmod(f, permissions, &header.Context) code = node.fsInode.Chmod(f, permissions, &header.Context)
fi.Mode = (fi.Mode &^ 07777) | permissions
} }
if code.Ok() && (input.Valid&(FATTR_UID|FATTR_GID) != 0) { if code.Ok() && (input.Valid&(FATTR_UID|FATTR_GID) != 0) {
code = node.fsInode.Chown(f, uint32(input.Uid), uint32(input.Gid), &header.Context) code = node.fsInode.Chown(f, uint32(input.Uid), uint32(input.Gid), &header.Context)
fi.Uid = int(input.Uid)
fi.Gid = int(input.Gid)
} }
if code.Ok() && input.Valid&FATTR_SIZE != 0 { if code.Ok() && input.Valid&FATTR_SIZE != 0 {
code = node.fsInode.Truncate(f, input.Size, &header.Context) code = node.fsInode.Truncate(f, input.Size, &header.Context)
fi.Size = int64(input.Size)
} }
if code.Ok() && (input.Valid&(FATTR_ATIME|FATTR_MTIME|FATTR_ATIME_NOW|FATTR_MTIME_NOW) != 0) { if code.Ok() && (input.Valid&(FATTR_ATIME|FATTR_MTIME|FATTR_ATIME_NOW|FATTR_MTIME_NOW) != 0) {
atime := uint64(input.Atime*1e9) + uint64(input.Atimensec) atime := uint64(input.Atime*1e9) + uint64(input.Atimensec)
...@@ -182,18 +188,17 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out ...@@ -182,18 +188,17 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out
// TODO - if using NOW, mtime and atime may differ. // TODO - if using NOW, mtime and atime may differ.
code = node.fsInode.Utimens(f, atime, mtime, &header.Context) code = node.fsInode.Utimens(f, atime, mtime, &header.Context)
fi.Atime_ns = int64(atime)
fi.Mtime_ns = int64(mtime)
} }
if !code.Ok() { if !code.Ok() {
return nil, code return nil, code
} }
fi, code := node.fsInode.GetAttr(f, &header.Context)
out = &AttrOut{} out = &AttrOut{}
if fi != nil { out.Attr.Ino = header.NodeId
out.Attr.Ino = header.NodeId node.mount.fileInfoToAttr(fi, out)
node.mount.fileInfoToAttr(fi, out)
}
return out, code return out, code
} }
......
...@@ -892,7 +892,7 @@ func TestDoubleOpen(t *testing.T) { ...@@ -892,7 +892,7 @@ func TestDoubleOpen(t *testing.T) {
output, err := ioutil.ReadAll(roFile) output, err := ioutil.ReadAll(roFile)
CheckSuccess(err) CheckSuccess(err)
if len(output) != 0 { if len(output) != 0 {
t.Errorf("After r/w truncation, r/o file should be empty too:", output) t.Errorf("After r/w truncation, r/o file should be empty too: %q", string(output))
} }
disabled := true disabled := true
......
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