From 30e18443b3f5d2e80fe24c45ee30a7a8bff397d1 Mon Sep 17 00:00:00 2001 From: vadlakondaswetha Date: Thu, 19 Dec 2024 09:30:13 +0000 Subject: [PATCH] ADDED COMMENTS --- internal/fs/fs.go | 1 + internal/fs/inode/file.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index 4ac3645ac7..3709dfc1e1 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -1737,6 +1737,7 @@ func (fs *fileSystem) CreateFile( handleID := fs.nextHandleID fs.nextHandleID++ + // Creating new file is always a write operation, hence passing readOnly as false. fs.handles[handleID] = handle.NewFileHandle(child.(*inode.FileInode), fs.fileCacheHandler, fs.cacheFileForRangeRead, fs.metricHandle, false) op.Handle = handleID diff --git a/internal/fs/inode/file.go b/internal/fs/inode/file.go index 89bfc41b78..78aa009c16 100644 --- a/internal/fs/inode/file.go +++ b/internal/fs/inode/file.go @@ -94,8 +94,16 @@ type FileInode struct { // Represents if local file has been unlinked. unlinked bool - bwh *bufferedwrites.BufferedWriteHandler - config *cfg.Config + bwh *bufferedwrites.BufferedWriteHandler + config *cfg.Config + + // Once write is started on the file i.e, bwh is initialized, any fileHandles + // opened in write mode before or after this and not yet closed are considered + // as writing to the file even though they are not writing. + // In case of successful flush, we will set bwh to nil. But in case of error, + // we will keep returning that error to all the fileHandles open during that time + // and set bwh to nil after all fileHandlers are closed. + // writeHandleCount tracks the count of open fileHandles in write mode. writeHandleCount int32 }