Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion component/azstorage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"errors"
"fmt"
"reflect"
"strconv"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
Expand Down Expand Up @@ -338,7 +339,7 @@ func ParseAndValidateConfig(az *AzStorage, opt AzStorageOptions) error {

if opt.BlockSize != 0 {
if opt.BlockSize > blockblob.MaxStageBlockBytes {
log.Err("ParseAndValidateConfig : Block size is too large. Block size has to be smaller than %s Bytes", blockblob.MaxStageBlockBytes)
log.Err("ParseAndValidateConfig : Block size is too large. Block size has to be smaller than %s Bytes", strconv.FormatInt(blockblob.MaxStageBlockBytes, 10))
return errors.New("block size is too large")
}
az.stConfig.blockSize = opt.BlockSize * 1024 * 1024
Expand Down
2 changes: 1 addition & 1 deletion component/block_cache/block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ func (bc *BlockCache) StatFs() (*syscall.Statfs_t, bool, error) {
log.Debug("BlockCache::StatFs : statfs err [%s].", err.Error())
return nil, false, err
}
statfs.Frsize = int64(bc.blockSize)
statfs.Frsize = assignFrSize(bc.blockSize)
statfs.Blocks = uint64(maxCacheSize) / uint64(bc.blockSize)
statfs.Bavail = uint64(math.Max(0, available)) / uint64(bc.blockSize)
statfs.Bfree = statfs.Bavail
Expand Down
7 changes: 7 additions & 0 deletions component/block_cache/frsize_helper_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// frsize_helper_amd64.go
// go:build amd64 && linux
package block_cache

func assignFrSize(val uint64) int64 {
return int64(val)
}
7 changes: 7 additions & 0 deletions component/block_cache/frsize_helper_arm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// frsize_helper_arm.go
// go:build arm && linux
package block_cache

func assignFrSize(val uint64) int32 {
return int32(val)
}
8 changes: 4 additions & 4 deletions component/file_cache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ func newObjAttr(path string, info fs.FileInfo) *internal.ObjAttr {
Name: info.Name(),
Size: info.Size(),
Mode: info.Mode(),
Mtime: time.Unix(stat.Mtim.Sec, stat.Mtim.Nsec),
Atime: time.Unix(stat.Atim.Sec, stat.Atim.Nsec),
Ctime: time.Unix(stat.Ctim.Sec, stat.Ctim.Nsec),
Mtime: time.Unix(int64(stat.Mtim.Sec), int64(stat.Mtim.Nsec)),
Atime: time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)),
Ctime: time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec)),
}

if info.Mode()&os.ModeSymlink != 0 {
Expand Down Expand Up @@ -845,7 +845,7 @@ func (fc *FileCache) isDownloadRequired(localPath string, blobPath string, flock

lmt = finfo.ModTime()
if time.Since(finfo.ModTime()).Seconds() > fc.cacheTimeout &&
time.Since(time.Unix(stat.Ctim.Sec, stat.Ctim.Nsec)).Seconds() > fc.cacheTimeout {
time.Since(time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec))).Seconds() > fc.cacheTimeout {
log.Debug("FileCache::isDownloadRequired : %s not valid as per time checks", localPath)
downloadRequired = true
}
Expand Down
40 changes: 27 additions & 13 deletions component/libfuse/libfuse_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ package libfuse

// #cgo CFLAGS: -DFUSE_USE_VERSION=39 -D_FILE_OFFSET_BITS=64
// #cgo LDFLAGS: -lfuse3 -ldl
// #define _LARGEFILE64_SOURCE
// #include <sys/types.h>
// #include <unistd.h>
// #include "libfuse_wrapper.h"
// #include "extension_handler.h"
import "C" //nolint
Expand Down Expand Up @@ -79,6 +82,17 @@ const (
C_EACCES = int(-C.EACCES)
)

func platformWordSize() int {
return int(unsafe.Sizeof(int(0)) * 8) // 32 or 64
}

func platformMask(val int) int {
if platformWordSize() == 32 {
return int(int16(uint16(val) & 0xFFFF)) // ARMv7: use 16-bit logic
}
return int(int32(uint32(val) & 0xFFFFFFFF)) // AMD64: use 32-bit logic
}

// Note: libfuse prepends "/" to the path.
// trimFusePath trims the first character from the path provided by libfuse
func trimFusePath(path *C.char) string {
Expand Down Expand Up @@ -349,7 +363,7 @@ func (lf *Libfuse) fillStat(attr *internal.ObjAttr, stbuf *C.stat_t) {
(*stbuf).st_uid = C.uint(lf.ownerUID)
(*stbuf).st_gid = C.uint(lf.ownerGID)
(*stbuf).st_nlink = 1
(*stbuf).st_size = C.long(attr.Size)
(*stbuf).st_size = C.off64_t(attr.Size)

// Populate mode
// Backing storage implementation has support for mode.
Expand Down Expand Up @@ -479,7 +493,7 @@ func libfuse_opendir(path *C.char, fi *C.fuse_file_info_t) C.int {
})

handlemap.Add(handle)
fi.fh = C.ulong(uintptr(unsafe.Pointer(handle)))
fi.fh = C.uint64_t(uintptr(unsafe.Pointer(handle)))

return 0
}
Expand Down Expand Up @@ -559,7 +573,7 @@ func libfuse_readdir(_ *C.char, buf unsafe.Pointer, filler C.fuse_fill_dir_t, of
fuseFS.fillStat(cacheInfo.children[segmentIdx], &stbuf)

name := C.CString(cacheInfo.children[segmentIdx].Name)
if 0 != C.fill_dir_entry(filler, buf, name, &stbuf, idx+1) {
if 0 != C.fill_dir_entry(filler, buf, name, &stbuf, C.off_t(idx+1)) {
C.free(unsafe.Pointer(name))
break
}
Expand Down Expand Up @@ -618,11 +632,11 @@ func libfuse_statfs(path *C.char, buf *C.statvfs_t) C.int {
if populated {
(*buf).f_bsize = C.ulong(attr.Bsize)
(*buf).f_frsize = C.ulong(attr.Frsize)
(*buf).f_blocks = C.ulong(attr.Blocks)
(*buf).f_bavail = C.ulong(attr.Bavail)
(*buf).f_bfree = C.ulong(attr.Bfree)
(*buf).f_files = C.ulong(attr.Files)
(*buf).f_ffree = C.ulong(attr.Ffree)
(*buf).f_blocks = C.__fsblkcnt64_t(attr.Blocks)
(*buf).f_bavail = C.__fsblkcnt64_t(attr.Bavail)
(*buf).f_bfree = C.__fsblkcnt64_t(attr.Bfree)
(*buf).f_files = C.__fsblkcnt64_t(attr.Files)
(*buf).f_ffree = C.__fsblkcnt64_t(attr.Ffree)
(*buf).f_flag = C.ulong(attr.Flags)
return 0
}
Expand Down Expand Up @@ -653,13 +667,13 @@ func libfuse_create(path *C.char, mode C.mode_t, fi *C.fuse_file_info_t) C.int {
}

handlemap.Add(handle)
ret_val := C.allocate_native_file_object(0, C.ulong(uintptr(unsafe.Pointer(handle))), 0)
ret_val := C.allocate_native_file_object(0, C.uint64_t(uintptr(unsafe.Pointer(handle))), 0)
if !handle.Cached() {
ret_val.fd = 0
}

log.Trace("Libfuse::libfuse_create : %s, handle %d", name, handle.ID)
fi.fh = C.ulong(uintptr(unsafe.Pointer(ret_val)))
fi.fh = C.uint64_t(uintptr(unsafe.Pointer(ret_val)))

libfuseStatsCollector.PushEvents(createFile, name, map[string]interface{}{md: fs.FileMode(uint32(mode) & 0xffffffff)})

Expand Down Expand Up @@ -704,7 +718,7 @@ func libfuse_open(path *C.char, fi *C.fuse_file_info_t) C.int {
handle, err := fuseFS.NextComponent().OpenFile(
internal.OpenFileOptions{
Name: name,
Flags: int(int(fi.flags) & 0xffffffff),
Flags: platformMask(int(fi.flags)),
Mode: fs.FileMode(fuseFS.filePermission),
})

Expand All @@ -721,12 +735,12 @@ func libfuse_open(path *C.char, fi *C.fuse_file_info_t) C.int {

handlemap.Add(handle)
//fi.fh = C.ulong(uintptr(unsafe.Pointer(handle)))
ret_val := C.allocate_native_file_object(C.ulong(handle.UnixFD), C.ulong(uintptr(unsafe.Pointer(handle))), C.ulong(handle.Size))
ret_val := C.allocate_native_file_object(C.uint64_t(handle.UnixFD), C.uint64_t(uintptr(unsafe.Pointer(handle))), C.uint64_t(handle.Size))
if !handle.Cached() {
ret_val.fd = 0
}
log.Trace("Libfuse::libfuse_open : %s, handle %d", name, handle.ID)
fi.fh = C.ulong(uintptr(unsafe.Pointer(ret_val)))
fi.fh = C.uint64_t(uintptr(unsafe.Pointer(ret_val)))

// increment open file handles count
libfuseStatsCollector.UpdateStats(stats_manager.Increment, openHandles, (int64)(1))
Expand Down
4 changes: 2 additions & 2 deletions component/libfuse/libfuse_handler_test_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func testTruncate(suite *libfuseTestSuite) {
options := internal.TruncateFileOptions{Name: name, Size: size}
suite.mock.EXPECT().TruncateFile(options).Return(nil)

err := libfuse_truncate(path, C.long(size), nil)
err := libfuse_truncate(path, C.off_t(size), nil)
suite.assert.Equal(C.int(0), err)
}

Expand All @@ -389,7 +389,7 @@ func testTruncateError(suite *libfuseTestSuite) {
options := internal.TruncateFileOptions{Name: name, Size: size}
suite.mock.EXPECT().TruncateFile(options).Return(errors.New("failed to truncate file"))

err := libfuse_truncate(path, C.long(size), nil)
err := libfuse_truncate(path, C.off_t(size), nil)
suite.assert.Equal(C.int(-C.EIO), err)
}

Expand Down
Loading