From f0b5b2b7ee1e41d8547afdab29337b102f9a8030 Mon Sep 17 00:00:00 2001 From: Srinivas Yeleti Date: Thu, 28 Nov 2024 17:44:43 +0530 Subject: [PATCH] current implementation of open file when opened in O_WRONLY will truncate the file to zero. This is incorrect behaviour. We don't see it in the normal scenario as write-back cache is on by default. Hence all the open calls with O_WRONLY will be redirected O_RDWR. To simulate this turn of the write-back cache and then open file in O_WRONLY. --- component/block_cache/block_cache.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/component/block_cache/block_cache.go b/component/block_cache/block_cache.go index f4e15dae2..d7d191aa4 100644 --- a/component/block_cache/block_cache.go +++ b/component/block_cache/block_cache.go @@ -382,7 +382,7 @@ func (bc *BlockCache) CreateFile(options internal.CreateFileOptions) (*handlemap // OpenFile: Create a handle for the file user has requested to open func (bc *BlockCache) OpenFile(options internal.OpenFileOptions) (*handlemap.Handle, error) { - log.Trace("BlockCache::OpenFile : name=%s, flags=%d, mode=%s", options.Name, options.Flags, options.Mode) + log.Trace("BlockCache::OpenFile : name=%s, flags=%X, mode=%s", options.Name, options.Flags, options.Mode) attr, err := bc.NextComponent().GetAttr(internal.GetAttrOptions{Name: options.Name}) if err != nil { @@ -397,7 +397,7 @@ func (bc *BlockCache) OpenFile(options internal.OpenFileOptions) (*handlemap.Han log.Debug("BlockCache::OpenFile : Size of file handle.Size %v", handle.Size) bc.prepareHandleForBlockCache(handle) - if options.Flags&os.O_TRUNC != 0 || (options.Flags&os.O_WRONLY != 0 && options.Flags&os.O_APPEND == 0) { + if options.Flags&os.O_TRUNC != 0 { // If file is opened in truncate or wronly mode then we need to wipe out the data consider current file size as 0 log.Debug("BlockCache::OpenFile : Truncate %v to 0", options.Name) handle.Size = 0