Skip to content

Commit

Permalink
current implementation of open file when opened in O_WRONLY will trun…
Browse files Browse the repository at this point in the history
…cate 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.
  • Loading branch information
syeleti-msft committed Nov 28, 2024
1 parent 2c4ec6a commit f0b5b2b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions component/block_cache/block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit f0b5b2b

Please sign in to comment.