diff --git a/component/azstorage/config.go b/component/azstorage/config.go index fa8e9cb8e9..b76f22c520 100644 --- a/component/azstorage/config.go +++ b/component/azstorage/config.go @@ -37,6 +37,7 @@ import ( "errors" "fmt" "reflect" + "strconv" "strings" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob" @@ -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 diff --git a/component/block_cache/block_cache.go b/component/block_cache/block_cache.go index 50465ba007..beacb1c9b8 100755 --- a/component/block_cache/block_cache.go +++ b/component/block_cache/block_cache.go @@ -1957,7 +1957,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 diff --git a/component/block_cache/frsize_helper.go b/component/block_cache/frsize_helper.go new file mode 100644 index 0000000000..fe3c0b178a --- /dev/null +++ b/component/block_cache/frsize_helper.go @@ -0,0 +1,7 @@ +// frsize_helper.go +//go:build !arm +package block_cache + +func assignFrSize(val uint64) int64 { + return int64(val) +} diff --git a/component/block_cache/frsize_helper_armv7.go b/component/block_cache/frsize_helper_armv7.go new file mode 100644 index 0000000000..aa53ba2b2a --- /dev/null +++ b/component/block_cache/frsize_helper_armv7.go @@ -0,0 +1,7 @@ +// frsize_helper_armv7.go +//go:build arm +package block_cache + +func assignFrSize(val uint64) int32 { + return int32(val) +} diff --git a/component/file_cache/file_cache.go b/component/file_cache/file_cache.go index dc0186d0fa..2637578d13 100644 --- a/component/file_cache/file_cache.go +++ b/component/file_cache/file_cache.go @@ -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 { @@ -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 } diff --git a/component/libfuse/libfuse_handler.go b/component/libfuse/libfuse_handler.go index efb68baa69..bb4da79779 100644 --- a/component/libfuse/libfuse_handler.go +++ b/component/libfuse/libfuse_handler.go @@ -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 +// #include // #include "libfuse_wrapper.h" // #include "extension_handler.h" import "C" //nolint @@ -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 { @@ -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. @@ -480,7 +494,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 } @@ -619,11 +633,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 } @@ -654,13 +668,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)}) @@ -705,7 +719,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), }) @@ -722,12 +736,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)) diff --git a/component/libfuse/libfuse_handler_test_wrapper.go b/component/libfuse/libfuse_handler_test_wrapper.go index 87301a19c8..029d899dea 100644 --- a/component/libfuse/libfuse_handler_test_wrapper.go +++ b/component/libfuse/libfuse_handler_test_wrapper.go @@ -376,7 +376,7 @@ func testTruncate(suite *libfuseTestSuite) { options := internal.TruncateFileOptions{Name: name, OldSize: -1, NewSize: 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) } @@ -389,7 +389,7 @@ func testTruncateError(suite *libfuseTestSuite) { options := internal.TruncateFileOptions{Name: name, OldSize: -1, NewSize: 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) } @@ -401,14 +401,14 @@ func testFTruncate(suite *libfuseTestSuite) { size := int64(1024) handle := handlemap.NewHandle(name) - 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)) fi := C.fuse_file_info_t{} - fi.fh = C.ulong(uintptr(unsafe.Pointer(ret_val))) + fi.fh = C.uint64_t(uintptr(unsafe.Pointer(ret_val))) options := internal.TruncateFileOptions{Handle: handle, Name: name, OldSize: -1, NewSize: size} suite.mock.EXPECT().TruncateFile(options).Return(nil) - err := libfuse_truncate(path, C.long(size), &fi) + err := libfuse_truncate(path, C.off_t(size), &fi) suite.assert.Equal(C.int(0), err) } @@ -420,14 +420,14 @@ func testFTruncateError(suite *libfuseTestSuite) { size := int64(1024) handle := handlemap.NewHandle(name) - 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)) fi := C.fuse_file_info_t{} - fi.fh = C.ulong(uintptr(unsafe.Pointer(ret_val))) + fi.fh = C.uint64_t(uintptr(unsafe.Pointer(ret_val))) options := internal.TruncateFileOptions{Handle: handle, Name: name, OldSize: -1, NewSize: size} suite.mock.EXPECT().TruncateFile(options).Return(errors.New("failed to truncate file")) - err := libfuse_truncate(path, C.long(size), &fi) + err := libfuse_truncate(path, C.off_t(size), &fi) suite.assert.Equal(C.int(-C.EIO), err) }