azure-storage-fuse/internal/base_component.go

333 строки
8.0 KiB
Go
Исходник Обычный вид История

2022-02-09 19:42:28 +03:00
/*
_____ _____ _____ ____ ______ _____ ------
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| --- | | | | |-----| |---- | | |-----| |----- ------
| | | | | | | | | | | | |
| ____| |_____ | ____| | ____| | |_____| _____| |_____ |_____
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
Copyright © 2020-2022 Microsoft Corporation. All rights reserved.
Author : <blobfusedev@microsoft.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
*/
package internal
import (
2022-02-16 01:29:44 +03:00
"blobfuse2/common"
2022-02-09 19:42:28 +03:00
"blobfuse2/internal/handlemap"
"context"
"syscall"
2022-02-09 19:42:28 +03:00
)
// BaseComponent : Base implementation of the component interface
2022-02-09 19:42:28 +03:00
type BaseComponent struct {
compName string
next Component
}
const name = "BaseComponent"
var _ Component = &BaseComponent{}
////////////////////////////////////////
// Default Component Implementation
// Pipeline participation related methods
func (base *BaseComponent) Name() string {
return base.compName
}
func (base *BaseComponent) SetName(name string) {
base.compName = name
}
func (base *BaseComponent) Configure() error {
return nil
}
func (base *BaseComponent) Priority() ComponentPriority {
return EComponentPriority.LevelMid()
}
func (base *BaseComponent) SetNextComponent(c Component) {
if base.next == nil {
base.next = c
} else {
panic("base.next not implemented")
}
}
func (base *BaseComponent) NextComponent() Component {
return base.next
}
func (base *BaseComponent) Start(ctx context.Context) error {
return nil
}
func (base *BaseComponent) Stop() error {
return nil
}
// Directory operations
func (base *BaseComponent) CreateDir(options CreateDirOptions) error {
if base.next != nil {
return base.next.CreateDir(options)
}
return nil
}
func (base *BaseComponent) DeleteDir(options DeleteDirOptions) error {
if base.next != nil {
return base.next.DeleteDir(options)
}
return nil
}
func (base *BaseComponent) IsDirEmpty(options IsDirEmptyOptions) bool {
if base.next != nil {
return base.next.IsDirEmpty(options)
}
return false
}
func (base *BaseComponent) OpenDir(options OpenDirOptions) error {
if base.next != nil {
return base.next.OpenDir(options)
}
return nil
}
func (base *BaseComponent) ReadDir(options ReadDirOptions) (attr []*ObjAttr, err error) {
if base.next != nil {
return base.next.ReadDir(options)
}
return attr, err
}
func (base *BaseComponent) StreamDir(options StreamDirOptions) ([]*ObjAttr, string, error) {
if base.next != nil {
return base.next.StreamDir(options)
}
return nil, "", nil
}
func (base *BaseComponent) CloseDir(options CloseDirOptions) error {
if base.next != nil {
return base.next.CloseDir(options)
}
return nil
}
func (base *BaseComponent) RenameDir(options RenameDirOptions) error {
if base.next != nil {
return base.next.RenameDir(options)
}
return nil
}
// File operations
func (base *BaseComponent) CreateFile(options CreateFileOptions) (*handlemap.Handle, error) {
if base.next != nil {
return base.next.CreateFile(options)
}
return nil, nil
}
func (base *BaseComponent) DeleteFile(options DeleteFileOptions) error {
if base.next != nil {
return base.next.DeleteFile(options)
}
return nil
}
func (base *BaseComponent) OpenFile(options OpenFileOptions) (*handlemap.Handle, error) {
if base.next != nil {
return base.next.OpenFile(options)
}
return nil, nil
}
func (base *BaseComponent) CloseFile(options CloseFileOptions) error {
if base.next != nil {
return base.next.CloseFile(options)
}
return nil
}
func (base *BaseComponent) RenameFile(options RenameFileOptions) error {
if base.next != nil {
return base.next.RenameFile(options)
}
return nil
}
func (base *BaseComponent) ReadFile(options ReadFileOptions) (b []byte, err error) {
if base.next != nil {
return base.next.ReadFile(options)
}
return b, err
}
func (base *BaseComponent) ReadInBuffer(options ReadInBufferOptions) (int, error) {
if base.next != nil {
return base.next.ReadInBuffer(options)
}
return 0, nil
}
func (base *BaseComponent) WriteFile(options WriteFileOptions) (int, error) {
if base.next != nil {
return base.next.WriteFile(options)
}
return 0, nil
}
func (base *BaseComponent) TruncateFile(options TruncateFileOptions) error {
if base.next != nil {
return base.next.TruncateFile(options)
}
return nil
}
func (base *BaseComponent) CopyToFile(options CopyToFileOptions) error {
if base.next != nil {
return base.next.CopyToFile(options)
}
return nil
}
func (base *BaseComponent) CopyFromFile(options CopyFromFileOptions) error {
if base.next != nil {
return base.next.CopyFromFile(options)
}
return nil
}
func (base *BaseComponent) SyncFile(options SyncFileOptions) error {
if base.next != nil {
return base.next.SyncFile(options)
}
return nil
}
func (base *BaseComponent) SyncDir(options SyncDirOptions) error {
if base.next != nil {
return base.next.SyncDir(options)
}
return nil
}
func (base *BaseComponent) FlushFile(options FlushFileOptions) error {
if base.next != nil {
return base.next.FlushFile(options)
}
return nil
}
func (base *BaseComponent) ReleaseFile(options ReleaseFileOptions) error {
if base.next != nil {
return base.next.ReleaseFile(options)
}
return nil
}
func (base *BaseComponent) UnlinkFile(options UnlinkFileOptions) error {
if base.next != nil {
return base.next.UnlinkFile(options)
}
return nil
}
// Symlink operations
func (base *BaseComponent) CreateLink(options CreateLinkOptions) error {
if base.next != nil {
return base.next.CreateLink(options)
}
return nil
}
func (base *BaseComponent) ReadLink(options ReadLinkOptions) (string, error) {
if base.next != nil {
return base.next.ReadLink(options)
}
return "", nil
}
// Filesystem level operations
func (base *BaseComponent) GetAttr(options GetAttrOptions) (*ObjAttr, error) {
if base.next != nil {
return base.next.GetAttr(options)
}
return &ObjAttr{}, nil
}
func (base *BaseComponent) GetFileBlockOffsets(options GetFileBlockOffsetsOptions) (*common.BlockOffsetList, error) {
if base.next != nil {
return base.next.GetFileBlockOffsets(options)
}
return &common.BlockOffsetList{}, nil
}
2022-02-09 19:42:28 +03:00
func (base *BaseComponent) SetAttr(options SetAttrOptions) error {
if base.next != nil {
return base.next.SetAttr(options)
}
return nil
}
func (base *BaseComponent) Chmod(options ChmodOptions) error {
if base.next != nil {
return base.next.Chmod(options)
}
return nil
}
func (base *BaseComponent) Chown(options ChownOptions) error {
if base.next != nil {
return base.next.Chown(options)
}
return nil
}
func (base *BaseComponent) InvalidateObject(name string) {
if base.next != nil {
base.next.InvalidateObject(name)
}
}
2022-02-16 01:29:44 +03:00
Native (C) pread/pwrite to improve performance (#752) * Adding more fuse options for optimization * Correcting logs for fuse3 * Removing nullpath feature as fuse3 does not support it * Remove symlink cache as fuse3 does not support that * Convert expected err log to warn * Removing dead code * Try file read using native C api * Try early pread to improve perf * Adding dynamic profiler and disable native pread call * Log error when profiler fails to start * Try prefetching data into memory for disk-file * Make dynamic profiler available in both foreground and daemon mode * Move read/write call to native calls * Add call to update the file-cache when native read/writes are invoked * Remove cache updating call for better perf * Remove readahead logic from file-cache * Clear handle map dead code * convert fd to uint64 instead of int * Adding basic infra for read ahead in native code * Clean up code, remove read-ahead logic and make direct read the default option * Correcting the flag name for offload-io * Correcting spell mistakes and adding comments * Correcting fsync test failure * Correct fuse3 UT for fsync and handle conversion * Resolve compilation failure for filehandle struct * Add logic to update the cache on every 1K operations on a handle * Resolve failure with flush when native write is enable * Add read-ahead logic in native code * Compilation failure resolution on fuse2 * Correcting memset params * Correcting spell error * Add GOGC and MAXPROCS value for perf tuning * Reduce min file size and correct read ahead buffer size for smaller fiels * Replace fsync with close of duplciate handle * Correcting write flow file corruption issue * Handle write in file-cache instead of libfuse as the other approach is corrupting data somewhere * File-cache to refresh cache on eveyr 1K operations and data validation test to wait for 2 seconds after copy * Replace file-cache read/write calls with syscalls * Enable native read/write again with read ahead disabled * Remove cache update from read calls * Remove read ahead logic completly * Cleanup libfuse compo and e2e test changes * Delete emptry directories recursively till root * Changes as per review comments * Fix issue with block-size running into overflow of number of blocks * Add blocksize and file size to logs * Make blocksize function to work on file size instead of fi object and add UT for blocksize calculations * Adding more ut case * Add some breather between upload and test * FileCacheTimeout test case to wait untill file is deleted from local system * FileCacheTimeout test case to wait untill file is deleted from local system * Codespell error fix * Restructuring code as per review comments and internal discussions * Code spell fixes * Stop updating cache on read * Adjusting cache update operation counter * Correcting libfuse_read flow and adding option to enable offload option manually * Correcting file_cache UT configs * Adding dynamic profiler config in base config
2022-05-19 08:02:23 +03:00
func (base *BaseComponent) FileUsed(name string) error {
if base.next != nil {
base.next.FileUsed(name)
}
return nil
}
func (base *BaseComponent) StatFs() (*syscall.Statfs_t, bool, error) {
if base.next != nil {
return base.next.StatFs()
}
return nil, false, nil
}