Skip to content

Commit

Permalink
Open file when it is actually read or written
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Dec 15, 2023
1 parent c832feb commit d8a6a47
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 105 deletions.
21 changes: 3 additions & 18 deletions irodsfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ func (file *File) Truncate(ctx context.Context, size uint64) syscall.Errno {
callFtruncate := false
handlesOpened := file.fs.fileHandleMap.ListByPath(irodsEntry.Path)
for _, handle := range handlesOpened {
if handle.fileHandle.IsWriteMode() {
if handle.openMode.IsWrite() {
// is writing
logger.Infof("Found opened file handle %q - %q", handle.file.path, handle.fileHandle.GetID())
logger.Infof("Found opened file handle %q - %q", handle.file.path, handle.GetID())

errno := handle.Truncate(ctx, size)
if errno != 0 {
Expand Down Expand Up @@ -533,7 +533,7 @@ func (file *File) Open(ctx context.Context, flags uint32) (fusefs.FileHandle, ui
return nil, 0, syscall.EREMOTEIO
}

fileHandle, errno := IRODSOpen(ctx, file.fs, file, irodsPath, flags)
fileHandle, errno := IRODSOpenLazy(ctx, file.fs, file, irodsPath, flags)
if errno != fusefs.OK {
return nil, 0, errno
}
Expand Down Expand Up @@ -570,11 +570,6 @@ func (file *File) Getlk(ctx context.Context, fh fusefs.FileHandle, owner uint64,
return syscall.EREMOTEIO
}

if fileHandle.fileHandle == nil {
logger.Errorf("failed to get a file handle - %q", fileHandle.file.path)
return syscall.EREMOTEIO
}

return fileHandle.GetLocalLock(ctx, owner, lk, flags, out)
}

Expand Down Expand Up @@ -602,11 +597,6 @@ func (file *File) Setlk(ctx context.Context, fh fusefs.FileHandle, owner uint64,
return syscall.EREMOTEIO
}

if fileHandle.fileHandle == nil {
logger.Errorf("failed to get a file handle - %q", fileHandle.file.path)
return syscall.EREMOTEIO
}

return fileHandle.SetLocalLock(ctx, owner, lk, flags)
}

Expand Down Expand Up @@ -634,11 +624,6 @@ func (file *File) Setlkw(ctx context.Context, fh fusefs.FileHandle, owner uint64
return syscall.EREMOTEIO
}

if fileHandle.fileHandle == nil {
logger.Errorf("failed to get a file handle - %q", fileHandle.file.path)
return syscall.EREMOTEIO
}

return fileHandle.SetLocalLockW(ctx, owner, lk, flags)
}

Expand Down
Loading

0 comments on commit d8a6a47

Please sign in to comment.