From 630e52c090135634fd60f1cbc3ce10c797e5c7fc Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 05:50:40 +0000 Subject: [PATCH 1/9] fs layer integration --- internal/fs/fs.go | 221 ++++++++++++++++++-------------- internal/fs/fs_test.go | 12 +- internal/fs/hns_bucket_test.go | 68 ++++++++++ internal/fs/inode/dir.go | 76 +++++------ internal/storage/fake/bucket.go | 1 - 5 files changed, 235 insertions(+), 143 deletions(-) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index b2c4a7c5b0..ff0268721e 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -252,9 +252,9 @@ func createFileCacheHandler(serverCfg *ServerConfig) (fileCacheHandler *file.Cac } func makeRootForBucket( - ctx context.Context, - fs *fileSystem, - syncerBucket gcsx.SyncerBucket) inode.DirInode { + ctx context.Context, + fs *fileSystem, + syncerBucket gcsx.SyncerBucket) inode.DirInode { return inode.NewDirInode( fuseops.RootInodeID, inode.NewRootName(""), @@ -967,9 +967,9 @@ func (fs *fileSystem) lookUpOrCreateInodeIfNotStale(ic inode.Core) (in inode.Ino // LOCKS_EXCLUDED(parent) // LOCK_FUNCTION(child) func (fs *fileSystem) lookUpOrCreateChildInode( - ctx context.Context, - parent inode.DirInode, - childName string) (child inode.Inode, err error) { + ctx context.Context, + parent inode.DirInode, + childName string) (child inode.Inode, err error) { // First check if the requested child is a localFileInode. child = fs.lookUpLocalFileInode(parent, childName) if child != nil { @@ -1093,9 +1093,9 @@ func (fs *fileSystem) lookUpLocalFileInode(parent inode.DirInode, childName stri // LOCKS_EXCLUDED(parent) // LOCK_FUNCTION(child) func (fs *fileSystem) lookUpOrCreateChildDirInode( - ctx context.Context, - parent inode.DirInode, - childName string) (child inode.BucketOwnedDirInode, err error) { + ctx context.Context, + parent inode.DirInode, + childName string) (child inode.BucketOwnedDirInode, err error) { in, err := fs.lookUpOrCreateChildInode(ctx, parent, childName) if err != nil { return nil, fmt.Errorf("lookup or create %q: %w", childName, err) @@ -1114,8 +1114,8 @@ func (fs *fileSystem) lookUpOrCreateChildDirInode( // LOCKS_EXCLUDED(fs.mu) // LOCKS_REQUIRED(f) func (fs *fileSystem) syncFile( - ctx context.Context, - f *inode.FileInode) (err error) { + ctx context.Context, + f *inode.FileInode) (err error) { // SyncFile can be triggered for unlinked files if the fileHandle is open by // same or another user. This indicates a potential file clobbering scenario: // - The file was deleted (unlinked) while a handle to it was still open. @@ -1232,8 +1232,8 @@ func (fs *fileSystem) unlockAndDecrementLookupCount(in inode.Inode, N uint64) { // LOCKS_EXCLUDED(fs.mu) // UNLOCK_FUNCTION(in) func (fs *fileSystem) unlockAndMaybeDisposeOfInode( - in inode.Inode, - err *error) { + in inode.Inode, + err *error) { // If there is no error, just unlock. if *err == nil { in.Unlock() @@ -1249,11 +1249,11 @@ func (fs *fileSystem) unlockAndMaybeDisposeOfInode( // // LOCKS_REQUIRED(in) func (fs *fileSystem) getAttributes( - ctx context.Context, - in inode.Inode) ( - attr fuseops.InodeAttributes, - expiration time.Time, - err error) { + ctx context.Context, + in inode.Inode) ( + attr fuseops.InodeAttributes, + expiration time.Time, + err error) { // Call through. attr, err = in.Attributes(ctx) if err != nil { @@ -1314,7 +1314,7 @@ func (fs *fileSystem) fileInodeOrDie(id fuseops.InodeID) (in *inode.FileInode) { // // LOCKS_REQUIRED(fs.mu) func (fs *fileSystem) symlinkInodeOrDie( - id fuseops.InodeID) (in *inode.SymlinkInode) { + id fuseops.InodeID) (in *inode.SymlinkInode) { tmp := fs.inodes[id] in, ok := tmp.(*inode.SymlinkInode) if !ok { @@ -1360,8 +1360,8 @@ func (fs *fileSystem) Destroy() { } func (fs *fileSystem) StatFS( - ctx context.Context, - op *fuseops.StatFSOp) (err error) { + ctx context.Context, + op *fuseops.StatFSOp) (err error) { // Simulate a large amount of free space so that the Finder doesn't refuse to // copy in files. (See issue #125.) Use 2^17 as the block size because that // is the largest that OS X will pass on. @@ -1383,8 +1383,8 @@ func (fs *fileSystem) StatFS( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) LookUpInode( - ctx context.Context, - op *fuseops.LookUpInodeOp) (err error) { + ctx context.Context, + op *fuseops.LookUpInodeOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1419,8 +1419,8 @@ func (fs *fileSystem) LookUpInode( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) GetInodeAttributes( - ctx context.Context, - op *fuseops.GetInodeAttributesOp) (err error) { + ctx context.Context, + op *fuseops.GetInodeAttributesOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1447,8 +1447,8 @@ func (fs *fileSystem) GetInodeAttributes( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) SetInodeAttributes( - ctx context.Context, - op *fuseops.SetInodeAttributesOp) (err error) { + ctx context.Context, + op *fuseops.SetInodeAttributesOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1497,8 +1497,8 @@ func (fs *fileSystem) SetInodeAttributes( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ForgetInode( - ctx context.Context, - op *fuseops.ForgetInodeOp) (err error) { + ctx context.Context, + op *fuseops.ForgetInodeOp) (err error) { // Find the inode. fs.mu.Lock() in := fs.inodeOrDie(op.Inode) @@ -1513,8 +1513,8 @@ func (fs *fileSystem) ForgetInode( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) MkDir( - ctx context.Context, - op *fuseops.MkDirOp) (err error) { + ctx context.Context, + op *fuseops.MkDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1572,8 +1572,8 @@ func (fs *fileSystem) MkDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) MkNode( - ctx context.Context, - op *fuseops.MkNodeOp) (err error) { + ctx context.Context, + op *fuseops.MkNodeOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1612,10 +1612,10 @@ func (fs *fileSystem) MkNode( // LOCKS_EXCLUDED(fs.mu) // LOCK_FUNCTION(child) func (fs *fileSystem) createFile( - ctx context.Context, - parentID fuseops.InodeID, - name string, - mode os.FileMode) (child inode.Inode, err error) { + ctx context.Context, + parentID fuseops.InodeID, + name string, + mode os.FileMode) (child inode.Inode, err error) { // Find the parent. fs.mu.Lock() parent := fs.dirInodeOrDie(parentID) @@ -1708,8 +1708,8 @@ func (fs *fileSystem) createLocalFile(ctx context.Context, parentID fuseops.Inod // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) CreateFile( - ctx context.Context, - op *fuseops.CreateFileOp) (err error) { + ctx context.Context, + op *fuseops.CreateFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1758,8 +1758,8 @@ func (fs *fileSystem) CreateFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) CreateSymlink( - ctx context.Context, - op *fuseops.CreateSymlinkOp) (err error) { + ctx context.Context, + op *fuseops.CreateSymlinkOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1816,20 +1816,20 @@ func (fs *fileSystem) CreateSymlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) RmDir( - // When rm -r or os.RemoveAll call is made, the following calls are made in order - // 1. RmDir (only in the case of os.RemoveAll) - // 2. Unlink all nested files, - // 3. lookupInode call on implicit directory - // 4. Rmdir on the directory. - // - // When type cache ttl is set, we construct an implicitDir even though one doesn't - // exist on GCS (https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/internal/fs/inode/dir.go#L452), - // and thus, we get rmDir call to GCSFuse. - // Whereas when ttl is zero, lookupInode call itself fails and RmDir is not called - // because object is not present in GCS. - - ctx context.Context, - op *fuseops.RmDirOp) (err error) { +// When rm -r or os.RemoveAll call is made, the following calls are made in order +// 1. RmDir (only in the case of os.RemoveAll) +// 2. Unlink all nested files, +// 3. lookupInode call on implicit directory +// 4. Rmdir on the directory. +// +// When type cache ttl is set, we construct an implicitDir even though one doesn't +// exist on GCS (https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/internal/fs/inode/dir.go#L452), +// and thus, we get rmDir call to GCSFuse. +// Whereas when ttl is zero, lookupInode call itself fails and RmDir is not called +// because object is not present in GCS. + + ctx context.Context, + op *fuseops.RmDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1936,8 +1936,8 @@ func (fs *fileSystem) RmDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) Rename( - ctx context.Context, - op *fuseops.RenameOp) (err error) { + ctx context.Context, + op *fuseops.RenameOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1994,19 +1994,44 @@ func (fs *fileSystem) Rename( } return fs.renameNonHierarchicalDir(ctx, oldParent, op.OldName, newParent, op.NewName) } - return fs.renameFile(ctx, oldParent, op.OldName, child.MinObject, newParent, op.NewName) + if child.Bucket.BucketType() == gcs.Hierarchical { + return fs.renameHierarchicalFile(ctx, oldParent, op.OldName, child.MinObject, newParent, op.NewName) + } + return fs.renameNonHierarchicalFile(ctx, oldParent, op.OldName, child.MinObject, newParent, op.NewName) +} + +// LOCKS_EXCLUDED(fs.mu) +// LOCKS_EXCLUDED(oldParent) +// LOCKS_EXCLUDED(newParent) +func (fs *fileSystem) renameHierarchicalFile(ctx context.Context, oldParent inode.DirInode, oldName string, oldObject *gcs.MinObject, newParent inode.DirInode, newName string) error { + oldParent.Lock() + defer oldParent.Unlock() + + if newParent != oldParent { + newParent.Lock() + defer newParent.Unlock() + } + + newFileName := inode.NewFileName(newParent.Name(), newName) + + _, err := oldParent.RenameFile(ctx, oldObject, newFileName.GcsObjectName()) + if err = fs.invalidateChildFileCacheIfExist(oldParent, oldName); err != nil { + return fmt.Errorf("renameHierarchicalFile: while invalidating cache for delete file: %w", err) + } + + return err } // LOCKS_EXCLUDED(fs.mu) // LOCKS_EXCLUDED(oldParent) // LOCKS_EXCLUDED(newParent) -func (fs *fileSystem) renameFile( - ctx context.Context, - oldParent inode.DirInode, - oldName string, - oldObject *gcs.MinObject, - newParent inode.DirInode, - newFileName string) error { +func (fs *fileSystem) renameNonHierarchicalFile( + ctx context.Context, + oldParent inode.DirInode, + oldName string, + oldObject *gcs.MinObject, + newParent inode.DirInode, + newFileName string) error { // Clone into the new location. newParent.Lock() _, err := newParent.CloneToChildFile(ctx, newFileName, oldObject) @@ -2027,7 +2052,7 @@ func (fs *fileSystem) renameFile( &oldObject.MetaGeneration) if err := fs.invalidateChildFileCacheIfExist(oldParent, oldObject.Name); err != nil { - return fmt.Errorf("renameFile: while invalidating cache for delete file: %w", err) + return fmt.Errorf("renameNonHierarchicalFile: while invalidating cache for delete file: %w", err) } oldParent.Unlock() @@ -2147,11 +2172,11 @@ func (fs *fileSystem) renameHierarchicalDir(ctx context.Context, oldParent inode // LOCKS_EXCLUDED(oldParent) // LOCKS_EXCLUDED(newParent) func (fs *fileSystem) renameNonHierarchicalDir( - ctx context.Context, - oldParent inode.DirInode, - oldName string, - newParent inode.DirInode, - newName string) error { + ctx context.Context, + oldParent inode.DirInode, + oldName string, + newParent inode.DirInode, + newName string) error { // Set up a function that throws away the lookup count increment from // lookUpOrCreateChildInode (since the pending inodes are not sent back to @@ -2240,8 +2265,8 @@ func (fs *fileSystem) renameNonHierarchicalDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) Unlink( - ctx context.Context, - op *fuseops.UnlinkOp) (err error) { + ctx context.Context, + op *fuseops.UnlinkOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2289,7 +2314,7 @@ func (fs *fileSystem) Unlink( err = parent.DeleteChildFile( ctx, op.Name, - 0, // Latest generation + 0, // Latest generation nil) // No meta-generation precondition if err != nil { @@ -2306,8 +2331,8 @@ func (fs *fileSystem) Unlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) OpenDir( - ctx context.Context, - op *fuseops.OpenDirOp) (err error) { + ctx context.Context, + op *fuseops.OpenDirOp) (err error) { fs.mu.Lock() // Make sure the inode still exists and is a directory. If not, something has @@ -2337,8 +2362,8 @@ func (fs *fileSystem) OpenDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadDir( - ctx context.Context, - op *fuseops.ReadDirOp) (err error) { + ctx context.Context, + op *fuseops.ReadDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2367,8 +2392,8 @@ func (fs *fileSystem) ReadDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReleaseDirHandle( - ctx context.Context, - op *fuseops.ReleaseDirHandleOp) (err error) { + ctx context.Context, + op *fuseops.ReleaseDirHandleOp) (err error) { fs.mu.Lock() defer fs.mu.Unlock() @@ -2383,8 +2408,8 @@ func (fs *fileSystem) ReleaseDirHandle( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) OpenFile( - ctx context.Context, - op *fuseops.OpenFileOp) (err error) { + ctx context.Context, + op *fuseops.OpenFileOp) (err error) { fs.mu.Lock() // Find the inode. @@ -2417,8 +2442,8 @@ func (fs *fileSystem) OpenFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadFile( - ctx context.Context, - op *fuseops.ReadFileOp) (err error) { + ctx context.Context, + op *fuseops.ReadFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2450,8 +2475,8 @@ func (fs *fileSystem) ReadFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadSymlink( - ctx context.Context, - op *fuseops.ReadSymlinkOp) (err error) { + ctx context.Context, + op *fuseops.ReadSymlinkOp) (err error) { // Find the inode. fs.mu.Lock() in := fs.symlinkInodeOrDie(op.Inode) @@ -2468,8 +2493,8 @@ func (fs *fileSystem) ReadSymlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) WriteFile( - ctx context.Context, - op *fuseops.WriteFileOp) (err error) { + ctx context.Context, + op *fuseops.WriteFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2495,8 +2520,8 @@ func (fs *fileSystem) WriteFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) SyncFile( - ctx context.Context, - op *fuseops.SyncFileOp) (err error) { + ctx context.Context, + op *fuseops.SyncFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2528,8 +2553,8 @@ func (fs *fileSystem) SyncFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) FlushFile( - ctx context.Context, - op *fuseops.FlushFileOp) (err error) { + ctx context.Context, + op *fuseops.FlushFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2555,8 +2580,8 @@ func (fs *fileSystem) FlushFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReleaseFileHandle( - ctx context.Context, - op *fuseops.ReleaseFileHandleOp) (err error) { + ctx context.Context, + op *fuseops.ReleaseFileHandleOp) (err error) { fs.mu.Lock() fileHandle := fs.handles[op.Handle].(*handle.FileHandle) @@ -2574,13 +2599,13 @@ func (fs *fileSystem) ReleaseFileHandle( } func (fs *fileSystem) GetXattr( - ctx context.Context, - op *fuseops.GetXattrOp) (err error) { + ctx context.Context, + op *fuseops.GetXattrOp) (err error) { return syscall.ENOSYS } func (fs *fileSystem) ListXattr( - ctx context.Context, - op *fuseops.ListXattrOp) error { + ctx context.Context, + op *fuseops.ListXattrOp) error { return syscall.ENOSYS } diff --git a/internal/fs/fs_test.go b/internal/fs/fs_test.go index ebb9e4b482..e3dbd8b846 100644 --- a/internal/fs/fs_test.go +++ b/internal/fs/fs_test.go @@ -193,13 +193,13 @@ func (t *fsTest) SetUpTestSuite() { mountCfg := t.mountCfg mountCfg.OpContext = ctx - if mountCfg.ErrorLogger == nil { - mountCfg.ErrorLogger = logger.NewLegacyLogger(logger.LevelError, "fuse_errors: ") - } + //if mountCfg.ErrorLogger == nil { + mountCfg.ErrorLogger = logger.NewLegacyLogger(logger.LevelError, "fuse_errors: ") + //} - if *fDebug { - mountCfg.DebugLogger = logger.NewLegacyLogger(logger.LevelDebug, "fuse: ") - } + //if *fDebug { + mountCfg.DebugLogger = logger.NewLegacyLogger(logger.LevelInfo, "fuse: ") + //} mfs, err = fuse.Mount(mntDir, server, &mountCfg) AssertEq(nil, err) diff --git a/internal/fs/hns_bucket_test.go b/internal/fs/hns_bucket_test.go index ced8f38651..b9f86ae129 100644 --- a/internal/fs/hns_bucket_test.go +++ b/internal/fs/hns_bucket_test.go @@ -379,3 +379,71 @@ func (t *HNSBucketTests) TestCreateLocalFileInSamePathAfterDeletingParentDirecto _, err = os.Stat(filePath) assert.NoError(t.T(), err) } + +func (t *HNSBucketTests) TestRenameFileWithSrcFileDoesNotExist() { + oldDirPath := path.Join(mntDir, "file") + newDirPath := path.Join(mntDir, "file_rename") + + err := os.Rename(oldDirPath, newDirPath) + + assert.Error(t.T(), err) + assert.True(t.T(), strings.Contains(err.Error(), "no such file or directory")) + _, err = os.Stat(newDirPath) + assert.Error(t.T(), err) + assert.True(t.T(), strings.Contains(err.Error(), "no such file or directory")) +} + +func (t *HNSBucketTests) TestRenameFileWithDstDestFileExist() { + oldFilePath := path.Join(mntDir, "foo", "file1.txt") + _, err := os.Stat(oldFilePath) + assert.NoError(t.T(), err) + // In the setup phase, we created file1.txt within the bar directory. + newFilePath := path.Join(mntDir, "foo", "file2.txt") + _, err = os.Stat(newFilePath) + assert.NoError(t.T(), err) + + err = os.Rename(oldFilePath, newFilePath) + + assert.NoError(t.T(), err) + _, err = os.Stat(oldFilePath) + assert.Error(t.T(), err) + assert.True(t.T(), strings.Contains(err.Error(), "no such file or directory")) +} + +func (t *HNSBucketTests) TestRenameFileWithDifferentParent() { + oldFilePath := path.Join(mntDir, "foo", "file1.txt") + _, err := os.Stat(oldFilePath) + assert.NoError(t.T(), err) + // In the setup phase, we created file1.txt within the bar directory. + newFilePath := path.Join(mntDir, "bar", "file3.txt") + _, err = os.Stat(newFilePath) + assert.True(t.T(), strings.Contains(err.Error(), "no such file or directory")) + + err = os.Rename(oldFilePath, newFilePath) + + assert.NoError(t.T(), err) + _, err = os.Stat(oldFilePath) + assert.Error(t.T(), err) + assert.True(t.T(), strings.Contains(err.Error(), "no such file or directory")) + _, err = os.Stat(newFilePath) + assert.NoError(t.T(), err) +} + +func (t *HNSBucketTests) TestRenameFileWithSameParent() { + oldFilePath := path.Join(mntDir, "foo", "file1.txt") + _, err := os.Stat(oldFilePath) + assert.NoError(t.T(), err) + // In the setup phase, we created file1.txt within the bar directory. + newFilePath := path.Join(mntDir, "foo", "file3.txt") + _, err = os.Stat(newFilePath) + assert.True(t.T(), strings.Contains(err.Error(), "no such file or directory")) + + err = os.Rename(oldFilePath, newFilePath) + + assert.NoError(t.T(), err) + _, err = os.Stat(oldFilePath) + assert.Error(t.T(), err) + assert.True(t.T(), strings.Contains(err.Error(), "no such file or directory")) + _, err = os.Stat(newFilePath) + assert.NoError(t.T(), err) +} diff --git a/internal/fs/inode/dir.go b/internal/fs/inode/dir.go index 6d4641ee59..03910fbed3 100644 --- a/internal/fs/inode/dir.go +++ b/internal/fs/inode/dir.go @@ -88,8 +88,8 @@ type DirInode interface { // The contents of the Offset and Inode fields for returned entries is // undefined. ReadEntries( - ctx context.Context, - tok string) (entries []fuseutil.Dirent, newTok string, err error) + ctx context.Context, + tok string) (entries []fuseutil.Dirent, newTok string, err error) // Create an empty child file with the supplied (relative) name, failing with // *gcs.PreconditionError if a backing object already exists in GCS. @@ -129,18 +129,18 @@ type DirInode interface { // metaGeneration may be set to a non-nil pointer giving a meta-generation // precondition, but need not be. DeleteChildFile( - ctx context.Context, - name string, - generation int64, - metaGeneration *int64) (err error) + ctx context.Context, + name string, + generation int64, + metaGeneration *int64) (err error) // Delete the backing object for the child directory with the given // (relative) name if it is not an Implicit Directory. DeleteChildDir( - ctx context.Context, - name string, - isImplicitDir bool, - dirInode DirInode) (err error) + ctx context.Context, + name string, + isImplicitDir bool, + dirInode DirInode) (err error) // LocalFileEntries lists the local files present in the directory. // Local means that the file is not yet present on GCS. @@ -252,18 +252,18 @@ var _ DirInode = &dirInode{} // // REQUIRES: name.IsDir() func NewDirInode( - id fuseops.InodeID, - name Name, - attrs fuseops.InodeAttributes, - implicitDirs bool, - includeFoldersAsPrefixes bool, - enableNonexistentTypeCache bool, - typeCacheTTL time.Duration, - bucket *gcsx.SyncerBucket, - mtimeClock timeutil.Clock, - cacheClock timeutil.Clock, - typeCacheMaxSizeMB int64, - isHNSEnabled bool, + id fuseops.InodeID, + name Name, + attrs fuseops.InodeAttributes, + implicitDirs bool, + includeFoldersAsPrefixes bool, + enableNonexistentTypeCache bool, + typeCacheTTL time.Duration, + bucket *gcsx.SyncerBucket, + mtimeClock timeutil.Clock, + cacheClock timeutil.Clock, + typeCacheMaxSizeMB int64, + isHNSEnabled bool, ) (d DirInode) { if !name.IsDir() { @@ -431,9 +431,9 @@ func findDirInode(ctx context.Context, bucket *gcsx.SyncerBucket, name Name) (*C // Fail if the name already exists. Pass on errors directly. func (d *dirInode) createNewObject( - ctx context.Context, - name Name, - metadata map[string]string) (o *gcs.Object, err error) { + ctx context.Context, + name Name, + metadata map[string]string) (o *gcs.Object, err error) { // Create an empty backing object for the child, failing if it already // exists. var precond int64 @@ -512,7 +512,7 @@ func (d *dirInode) Destroy() (err error) { // LOCKS_REQUIRED(d) func (d *dirInode) Attributes( - ctx context.Context) (attrs fuseops.InodeAttributes, err error) { + ctx context.Context) (attrs fuseops.InodeAttributes, err error) { // Set up basic attributes. attrs = d.attrs attrs.Nlink = 1 @@ -661,8 +661,8 @@ func (d *dirInode) ReadDescendants(ctx context.Context, limit int) (map[Name]*Co // LOCKS_REQUIRED(d) func (d *dirInode) readObjects( - ctx context.Context, - tok string) (cores map[Name]*Core, newTok string, err error) { + ctx context.Context, + tok string) (cores map[Name]*Core, newTok string, err error) { if d.isBucketHierarchical() { d.includeFoldersAsPrefixes = true } @@ -772,8 +772,8 @@ func (d *dirInode) readObjects( } func (d *dirInode) ReadEntries( - ctx context.Context, - tok string) (entries []fuseutil.Dirent, newTok string, err error) { + ctx context.Context, + tok string) (entries []fuseutil.Dirent, newTok string, err error) { var cores map[Name]*Core cores, newTok, err = d.readObjects(ctx, tok) if err != nil { @@ -931,10 +931,10 @@ func (d *dirInode) CreateChildDir(ctx context.Context, name string) (*Core, erro // LOCKS_REQUIRED(d) func (d *dirInode) DeleteChildFile( - ctx context.Context, - name string, - generation int64, - metaGeneration *int64) (err error) { + ctx context.Context, + name string, + generation int64, + metaGeneration *int64) (err error) { d.cache.Erase(name) childName := NewFileName(d.Name(), name) @@ -957,10 +957,10 @@ func (d *dirInode) DeleteChildFile( // LOCKS_REQUIRED(d) func (d *dirInode) DeleteChildDir( - ctx context.Context, - name string, - isImplicitDir bool, - dirInode DirInode) error { + ctx context.Context, + name string, + isImplicitDir bool, + dirInode DirInode) error { d.cache.Erase(name) // If the directory is an implicit directory, then no backing object diff --git a/internal/storage/fake/bucket.go b/internal/storage/fake/bucket.go index 919c3bed50..0781e3205b 100644 --- a/internal/storage/fake/bucket.go +++ b/internal/storage/fake/bucket.go @@ -1051,7 +1051,6 @@ func (b *bucket) MoveObject(ctx context.Context, req *gcs.MoveObjectRequest) (*g b.prevGeneration++ dst.metadata.Generation = b.prevGeneration - // Remove the source object. b.objects = append(b.objects[:srcIndex], b.objects[srcIndex+1:]...) // Insert dest object into our array. From ea3bc3a1f0c7466f57c9814502dced061a198ea1 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 05:51:02 +0000 Subject: [PATCH 2/9] fs layer integration --- internal/fs/fs_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/fs/fs_test.go b/internal/fs/fs_test.go index e3dbd8b846..ebb9e4b482 100644 --- a/internal/fs/fs_test.go +++ b/internal/fs/fs_test.go @@ -193,13 +193,13 @@ func (t *fsTest) SetUpTestSuite() { mountCfg := t.mountCfg mountCfg.OpContext = ctx - //if mountCfg.ErrorLogger == nil { - mountCfg.ErrorLogger = logger.NewLegacyLogger(logger.LevelError, "fuse_errors: ") - //} + if mountCfg.ErrorLogger == nil { + mountCfg.ErrorLogger = logger.NewLegacyLogger(logger.LevelError, "fuse_errors: ") + } - //if *fDebug { - mountCfg.DebugLogger = logger.NewLegacyLogger(logger.LevelInfo, "fuse: ") - //} + if *fDebug { + mountCfg.DebugLogger = logger.NewLegacyLogger(logger.LevelDebug, "fuse: ") + } mfs, err = fuse.Mount(mntDir, server, &mountCfg) AssertEq(nil, err) From f94fc02660942072fcdcf5edee6c056bfc8df9ec Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 05:51:55 +0000 Subject: [PATCH 3/9] formating fix --- internal/fs/fs.go | 190 +++++++++++++++++++++++----------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index ff0268721e..283a4eabd8 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -252,9 +252,9 @@ func createFileCacheHandler(serverCfg *ServerConfig) (fileCacheHandler *file.Cac } func makeRootForBucket( - ctx context.Context, - fs *fileSystem, - syncerBucket gcsx.SyncerBucket) inode.DirInode { + ctx context.Context, + fs *fileSystem, + syncerBucket gcsx.SyncerBucket) inode.DirInode { return inode.NewDirInode( fuseops.RootInodeID, inode.NewRootName(""), @@ -967,9 +967,9 @@ func (fs *fileSystem) lookUpOrCreateInodeIfNotStale(ic inode.Core) (in inode.Ino // LOCKS_EXCLUDED(parent) // LOCK_FUNCTION(child) func (fs *fileSystem) lookUpOrCreateChildInode( - ctx context.Context, - parent inode.DirInode, - childName string) (child inode.Inode, err error) { + ctx context.Context, + parent inode.DirInode, + childName string) (child inode.Inode, err error) { // First check if the requested child is a localFileInode. child = fs.lookUpLocalFileInode(parent, childName) if child != nil { @@ -1093,9 +1093,9 @@ func (fs *fileSystem) lookUpLocalFileInode(parent inode.DirInode, childName stri // LOCKS_EXCLUDED(parent) // LOCK_FUNCTION(child) func (fs *fileSystem) lookUpOrCreateChildDirInode( - ctx context.Context, - parent inode.DirInode, - childName string) (child inode.BucketOwnedDirInode, err error) { + ctx context.Context, + parent inode.DirInode, + childName string) (child inode.BucketOwnedDirInode, err error) { in, err := fs.lookUpOrCreateChildInode(ctx, parent, childName) if err != nil { return nil, fmt.Errorf("lookup or create %q: %w", childName, err) @@ -1114,8 +1114,8 @@ func (fs *fileSystem) lookUpOrCreateChildDirInode( // LOCKS_EXCLUDED(fs.mu) // LOCKS_REQUIRED(f) func (fs *fileSystem) syncFile( - ctx context.Context, - f *inode.FileInode) (err error) { + ctx context.Context, + f *inode.FileInode) (err error) { // SyncFile can be triggered for unlinked files if the fileHandle is open by // same or another user. This indicates a potential file clobbering scenario: // - The file was deleted (unlinked) while a handle to it was still open. @@ -1232,8 +1232,8 @@ func (fs *fileSystem) unlockAndDecrementLookupCount(in inode.Inode, N uint64) { // LOCKS_EXCLUDED(fs.mu) // UNLOCK_FUNCTION(in) func (fs *fileSystem) unlockAndMaybeDisposeOfInode( - in inode.Inode, - err *error) { + in inode.Inode, + err *error) { // If there is no error, just unlock. if *err == nil { in.Unlock() @@ -1249,11 +1249,11 @@ func (fs *fileSystem) unlockAndMaybeDisposeOfInode( // // LOCKS_REQUIRED(in) func (fs *fileSystem) getAttributes( - ctx context.Context, - in inode.Inode) ( - attr fuseops.InodeAttributes, - expiration time.Time, - err error) { + ctx context.Context, + in inode.Inode) ( + attr fuseops.InodeAttributes, + expiration time.Time, + err error) { // Call through. attr, err = in.Attributes(ctx) if err != nil { @@ -1314,7 +1314,7 @@ func (fs *fileSystem) fileInodeOrDie(id fuseops.InodeID) (in *inode.FileInode) { // // LOCKS_REQUIRED(fs.mu) func (fs *fileSystem) symlinkInodeOrDie( - id fuseops.InodeID) (in *inode.SymlinkInode) { + id fuseops.InodeID) (in *inode.SymlinkInode) { tmp := fs.inodes[id] in, ok := tmp.(*inode.SymlinkInode) if !ok { @@ -1360,8 +1360,8 @@ func (fs *fileSystem) Destroy() { } func (fs *fileSystem) StatFS( - ctx context.Context, - op *fuseops.StatFSOp) (err error) { + ctx context.Context, + op *fuseops.StatFSOp) (err error) { // Simulate a large amount of free space so that the Finder doesn't refuse to // copy in files. (See issue #125.) Use 2^17 as the block size because that // is the largest that OS X will pass on. @@ -1383,8 +1383,8 @@ func (fs *fileSystem) StatFS( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) LookUpInode( - ctx context.Context, - op *fuseops.LookUpInodeOp) (err error) { + ctx context.Context, + op *fuseops.LookUpInodeOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1419,8 +1419,8 @@ func (fs *fileSystem) LookUpInode( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) GetInodeAttributes( - ctx context.Context, - op *fuseops.GetInodeAttributesOp) (err error) { + ctx context.Context, + op *fuseops.GetInodeAttributesOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1447,8 +1447,8 @@ func (fs *fileSystem) GetInodeAttributes( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) SetInodeAttributes( - ctx context.Context, - op *fuseops.SetInodeAttributesOp) (err error) { + ctx context.Context, + op *fuseops.SetInodeAttributesOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1497,8 +1497,8 @@ func (fs *fileSystem) SetInodeAttributes( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ForgetInode( - ctx context.Context, - op *fuseops.ForgetInodeOp) (err error) { + ctx context.Context, + op *fuseops.ForgetInodeOp) (err error) { // Find the inode. fs.mu.Lock() in := fs.inodeOrDie(op.Inode) @@ -1513,8 +1513,8 @@ func (fs *fileSystem) ForgetInode( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) MkDir( - ctx context.Context, - op *fuseops.MkDirOp) (err error) { + ctx context.Context, + op *fuseops.MkDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1572,8 +1572,8 @@ func (fs *fileSystem) MkDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) MkNode( - ctx context.Context, - op *fuseops.MkNodeOp) (err error) { + ctx context.Context, + op *fuseops.MkNodeOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1612,10 +1612,10 @@ func (fs *fileSystem) MkNode( // LOCKS_EXCLUDED(fs.mu) // LOCK_FUNCTION(child) func (fs *fileSystem) createFile( - ctx context.Context, - parentID fuseops.InodeID, - name string, - mode os.FileMode) (child inode.Inode, err error) { + ctx context.Context, + parentID fuseops.InodeID, + name string, + mode os.FileMode) (child inode.Inode, err error) { // Find the parent. fs.mu.Lock() parent := fs.dirInodeOrDie(parentID) @@ -1708,8 +1708,8 @@ func (fs *fileSystem) createLocalFile(ctx context.Context, parentID fuseops.Inod // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) CreateFile( - ctx context.Context, - op *fuseops.CreateFileOp) (err error) { + ctx context.Context, + op *fuseops.CreateFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1758,8 +1758,8 @@ func (fs *fileSystem) CreateFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) CreateSymlink( - ctx context.Context, - op *fuseops.CreateSymlinkOp) (err error) { + ctx context.Context, + op *fuseops.CreateSymlinkOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1816,20 +1816,20 @@ func (fs *fileSystem) CreateSymlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) RmDir( -// When rm -r or os.RemoveAll call is made, the following calls are made in order -// 1. RmDir (only in the case of os.RemoveAll) -// 2. Unlink all nested files, -// 3. lookupInode call on implicit directory -// 4. Rmdir on the directory. -// -// When type cache ttl is set, we construct an implicitDir even though one doesn't -// exist on GCS (https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/internal/fs/inode/dir.go#L452), -// and thus, we get rmDir call to GCSFuse. -// Whereas when ttl is zero, lookupInode call itself fails and RmDir is not called -// because object is not present in GCS. - - ctx context.Context, - op *fuseops.RmDirOp) (err error) { + // When rm -r or os.RemoveAll call is made, the following calls are made in order + // 1. RmDir (only in the case of os.RemoveAll) + // 2. Unlink all nested files, + // 3. lookupInode call on implicit directory + // 4. Rmdir on the directory. + // + // When type cache ttl is set, we construct an implicitDir even though one doesn't + // exist on GCS (https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/internal/fs/inode/dir.go#L452), + // and thus, we get rmDir call to GCSFuse. + // Whereas when ttl is zero, lookupInode call itself fails and RmDir is not called + // because object is not present in GCS. + + ctx context.Context, + op *fuseops.RmDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1936,8 +1936,8 @@ func (fs *fileSystem) RmDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) Rename( - ctx context.Context, - op *fuseops.RenameOp) (err error) { + ctx context.Context, + op *fuseops.RenameOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2026,12 +2026,12 @@ func (fs *fileSystem) renameHierarchicalFile(ctx context.Context, oldParent inod // LOCKS_EXCLUDED(oldParent) // LOCKS_EXCLUDED(newParent) func (fs *fileSystem) renameNonHierarchicalFile( - ctx context.Context, - oldParent inode.DirInode, - oldName string, - oldObject *gcs.MinObject, - newParent inode.DirInode, - newFileName string) error { + ctx context.Context, + oldParent inode.DirInode, + oldName string, + oldObject *gcs.MinObject, + newParent inode.DirInode, + newFileName string) error { // Clone into the new location. newParent.Lock() _, err := newParent.CloneToChildFile(ctx, newFileName, oldObject) @@ -2172,11 +2172,11 @@ func (fs *fileSystem) renameHierarchicalDir(ctx context.Context, oldParent inode // LOCKS_EXCLUDED(oldParent) // LOCKS_EXCLUDED(newParent) func (fs *fileSystem) renameNonHierarchicalDir( - ctx context.Context, - oldParent inode.DirInode, - oldName string, - newParent inode.DirInode, - newName string) error { + ctx context.Context, + oldParent inode.DirInode, + oldName string, + newParent inode.DirInode, + newName string) error { // Set up a function that throws away the lookup count increment from // lookUpOrCreateChildInode (since the pending inodes are not sent back to @@ -2265,8 +2265,8 @@ func (fs *fileSystem) renameNonHierarchicalDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) Unlink( - ctx context.Context, - op *fuseops.UnlinkOp) (err error) { + ctx context.Context, + op *fuseops.UnlinkOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2314,7 +2314,7 @@ func (fs *fileSystem) Unlink( err = parent.DeleteChildFile( ctx, op.Name, - 0, // Latest generation + 0, // Latest generation nil) // No meta-generation precondition if err != nil { @@ -2331,8 +2331,8 @@ func (fs *fileSystem) Unlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) OpenDir( - ctx context.Context, - op *fuseops.OpenDirOp) (err error) { + ctx context.Context, + op *fuseops.OpenDirOp) (err error) { fs.mu.Lock() // Make sure the inode still exists and is a directory. If not, something has @@ -2362,8 +2362,8 @@ func (fs *fileSystem) OpenDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadDir( - ctx context.Context, - op *fuseops.ReadDirOp) (err error) { + ctx context.Context, + op *fuseops.ReadDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2392,8 +2392,8 @@ func (fs *fileSystem) ReadDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReleaseDirHandle( - ctx context.Context, - op *fuseops.ReleaseDirHandleOp) (err error) { + ctx context.Context, + op *fuseops.ReleaseDirHandleOp) (err error) { fs.mu.Lock() defer fs.mu.Unlock() @@ -2408,8 +2408,8 @@ func (fs *fileSystem) ReleaseDirHandle( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) OpenFile( - ctx context.Context, - op *fuseops.OpenFileOp) (err error) { + ctx context.Context, + op *fuseops.OpenFileOp) (err error) { fs.mu.Lock() // Find the inode. @@ -2442,8 +2442,8 @@ func (fs *fileSystem) OpenFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadFile( - ctx context.Context, - op *fuseops.ReadFileOp) (err error) { + ctx context.Context, + op *fuseops.ReadFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2475,8 +2475,8 @@ func (fs *fileSystem) ReadFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadSymlink( - ctx context.Context, - op *fuseops.ReadSymlinkOp) (err error) { + ctx context.Context, + op *fuseops.ReadSymlinkOp) (err error) { // Find the inode. fs.mu.Lock() in := fs.symlinkInodeOrDie(op.Inode) @@ -2493,8 +2493,8 @@ func (fs *fileSystem) ReadSymlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) WriteFile( - ctx context.Context, - op *fuseops.WriteFileOp) (err error) { + ctx context.Context, + op *fuseops.WriteFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2520,8 +2520,8 @@ func (fs *fileSystem) WriteFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) SyncFile( - ctx context.Context, - op *fuseops.SyncFileOp) (err error) { + ctx context.Context, + op *fuseops.SyncFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2553,8 +2553,8 @@ func (fs *fileSystem) SyncFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) FlushFile( - ctx context.Context, - op *fuseops.FlushFileOp) (err error) { + ctx context.Context, + op *fuseops.FlushFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2580,8 +2580,8 @@ func (fs *fileSystem) FlushFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReleaseFileHandle( - ctx context.Context, - op *fuseops.ReleaseFileHandleOp) (err error) { + ctx context.Context, + op *fuseops.ReleaseFileHandleOp) (err error) { fs.mu.Lock() fileHandle := fs.handles[op.Handle].(*handle.FileHandle) @@ -2599,13 +2599,13 @@ func (fs *fileSystem) ReleaseFileHandle( } func (fs *fileSystem) GetXattr( - ctx context.Context, - op *fuseops.GetXattrOp) (err error) { + ctx context.Context, + op *fuseops.GetXattrOp) (err error) { return syscall.ENOSYS } func (fs *fileSystem) ListXattr( - ctx context.Context, - op *fuseops.ListXattrOp) error { + ctx context.Context, + op *fuseops.ListXattrOp) error { return syscall.ENOSYS } From 8d596b9b9fdcd998f24d76521c49346e00edd4b6 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 05:52:23 +0000 Subject: [PATCH 4/9] formating fix --- internal/fs/inode/dir.go | 76 ++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/internal/fs/inode/dir.go b/internal/fs/inode/dir.go index 03910fbed3..6d4641ee59 100644 --- a/internal/fs/inode/dir.go +++ b/internal/fs/inode/dir.go @@ -88,8 +88,8 @@ type DirInode interface { // The contents of the Offset and Inode fields for returned entries is // undefined. ReadEntries( - ctx context.Context, - tok string) (entries []fuseutil.Dirent, newTok string, err error) + ctx context.Context, + tok string) (entries []fuseutil.Dirent, newTok string, err error) // Create an empty child file with the supplied (relative) name, failing with // *gcs.PreconditionError if a backing object already exists in GCS. @@ -129,18 +129,18 @@ type DirInode interface { // metaGeneration may be set to a non-nil pointer giving a meta-generation // precondition, but need not be. DeleteChildFile( - ctx context.Context, - name string, - generation int64, - metaGeneration *int64) (err error) + ctx context.Context, + name string, + generation int64, + metaGeneration *int64) (err error) // Delete the backing object for the child directory with the given // (relative) name if it is not an Implicit Directory. DeleteChildDir( - ctx context.Context, - name string, - isImplicitDir bool, - dirInode DirInode) (err error) + ctx context.Context, + name string, + isImplicitDir bool, + dirInode DirInode) (err error) // LocalFileEntries lists the local files present in the directory. // Local means that the file is not yet present on GCS. @@ -252,18 +252,18 @@ var _ DirInode = &dirInode{} // // REQUIRES: name.IsDir() func NewDirInode( - id fuseops.InodeID, - name Name, - attrs fuseops.InodeAttributes, - implicitDirs bool, - includeFoldersAsPrefixes bool, - enableNonexistentTypeCache bool, - typeCacheTTL time.Duration, - bucket *gcsx.SyncerBucket, - mtimeClock timeutil.Clock, - cacheClock timeutil.Clock, - typeCacheMaxSizeMB int64, - isHNSEnabled bool, + id fuseops.InodeID, + name Name, + attrs fuseops.InodeAttributes, + implicitDirs bool, + includeFoldersAsPrefixes bool, + enableNonexistentTypeCache bool, + typeCacheTTL time.Duration, + bucket *gcsx.SyncerBucket, + mtimeClock timeutil.Clock, + cacheClock timeutil.Clock, + typeCacheMaxSizeMB int64, + isHNSEnabled bool, ) (d DirInode) { if !name.IsDir() { @@ -431,9 +431,9 @@ func findDirInode(ctx context.Context, bucket *gcsx.SyncerBucket, name Name) (*C // Fail if the name already exists. Pass on errors directly. func (d *dirInode) createNewObject( - ctx context.Context, - name Name, - metadata map[string]string) (o *gcs.Object, err error) { + ctx context.Context, + name Name, + metadata map[string]string) (o *gcs.Object, err error) { // Create an empty backing object for the child, failing if it already // exists. var precond int64 @@ -512,7 +512,7 @@ func (d *dirInode) Destroy() (err error) { // LOCKS_REQUIRED(d) func (d *dirInode) Attributes( - ctx context.Context) (attrs fuseops.InodeAttributes, err error) { + ctx context.Context) (attrs fuseops.InodeAttributes, err error) { // Set up basic attributes. attrs = d.attrs attrs.Nlink = 1 @@ -661,8 +661,8 @@ func (d *dirInode) ReadDescendants(ctx context.Context, limit int) (map[Name]*Co // LOCKS_REQUIRED(d) func (d *dirInode) readObjects( - ctx context.Context, - tok string) (cores map[Name]*Core, newTok string, err error) { + ctx context.Context, + tok string) (cores map[Name]*Core, newTok string, err error) { if d.isBucketHierarchical() { d.includeFoldersAsPrefixes = true } @@ -772,8 +772,8 @@ func (d *dirInode) readObjects( } func (d *dirInode) ReadEntries( - ctx context.Context, - tok string) (entries []fuseutil.Dirent, newTok string, err error) { + ctx context.Context, + tok string) (entries []fuseutil.Dirent, newTok string, err error) { var cores map[Name]*Core cores, newTok, err = d.readObjects(ctx, tok) if err != nil { @@ -931,10 +931,10 @@ func (d *dirInode) CreateChildDir(ctx context.Context, name string) (*Core, erro // LOCKS_REQUIRED(d) func (d *dirInode) DeleteChildFile( - ctx context.Context, - name string, - generation int64, - metaGeneration *int64) (err error) { + ctx context.Context, + name string, + generation int64, + metaGeneration *int64) (err error) { d.cache.Erase(name) childName := NewFileName(d.Name(), name) @@ -957,10 +957,10 @@ func (d *dirInode) DeleteChildFile( // LOCKS_REQUIRED(d) func (d *dirInode) DeleteChildDir( - ctx context.Context, - name string, - isImplicitDir bool, - dirInode DirInode) error { + ctx context.Context, + name string, + isImplicitDir bool, + dirInode DirInode) error { d.cache.Erase(name) // If the directory is an implicit directory, then no backing object From d06a2eb5933720fb72144a935341259dcd47c290 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 06:03:58 +0000 Subject: [PATCH 5/9] lint fix --- internal/fs/fs.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index 283a4eabd8..d888d4c27a 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -2014,12 +2014,15 @@ func (fs *fileSystem) renameHierarchicalFile(ctx context.Context, oldParent inod newFileName := inode.NewFileName(newParent.Name(), newName) - _, err := oldParent.RenameFile(ctx, oldObject, newFileName.GcsObjectName()) - if err = fs.invalidateChildFileCacheIfExist(oldParent, oldName); err != nil { + if _, err := oldParent.RenameFile(ctx, oldObject, newFileName.GcsObjectName()); err != nil { + return fmt.Errorf("RenameFile: while renaming file: %w", err) + } + + if err := fs.invalidateChildFileCacheIfExist(oldParent, oldName); err != nil { return fmt.Errorf("renameHierarchicalFile: while invalidating cache for delete file: %w", err) } - return err + return nil } // LOCKS_EXCLUDED(fs.mu) From b27156de9248dde3a8e0453c495787c1a264908a Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 10:50:29 +0000 Subject: [PATCH 6/9] rebase --- internal/fs/fs.go | 193 +++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 95 deletions(-) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index d888d4c27a..3f623d7abb 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -252,9 +252,9 @@ func createFileCacheHandler(serverCfg *ServerConfig) (fileCacheHandler *file.Cac } func makeRootForBucket( - ctx context.Context, - fs *fileSystem, - syncerBucket gcsx.SyncerBucket) inode.DirInode { + ctx context.Context, + fs *fileSystem, + syncerBucket gcsx.SyncerBucket) inode.DirInode { return inode.NewDirInode( fuseops.RootInodeID, inode.NewRootName(""), @@ -967,9 +967,9 @@ func (fs *fileSystem) lookUpOrCreateInodeIfNotStale(ic inode.Core) (in inode.Ino // LOCKS_EXCLUDED(parent) // LOCK_FUNCTION(child) func (fs *fileSystem) lookUpOrCreateChildInode( - ctx context.Context, - parent inode.DirInode, - childName string) (child inode.Inode, err error) { + ctx context.Context, + parent inode.DirInode, + childName string) (child inode.Inode, err error) { // First check if the requested child is a localFileInode. child = fs.lookUpLocalFileInode(parent, childName) if child != nil { @@ -1093,9 +1093,9 @@ func (fs *fileSystem) lookUpLocalFileInode(parent inode.DirInode, childName stri // LOCKS_EXCLUDED(parent) // LOCK_FUNCTION(child) func (fs *fileSystem) lookUpOrCreateChildDirInode( - ctx context.Context, - parent inode.DirInode, - childName string) (child inode.BucketOwnedDirInode, err error) { + ctx context.Context, + parent inode.DirInode, + childName string) (child inode.BucketOwnedDirInode, err error) { in, err := fs.lookUpOrCreateChildInode(ctx, parent, childName) if err != nil { return nil, fmt.Errorf("lookup or create %q: %w", childName, err) @@ -1114,8 +1114,8 @@ func (fs *fileSystem) lookUpOrCreateChildDirInode( // LOCKS_EXCLUDED(fs.mu) // LOCKS_REQUIRED(f) func (fs *fileSystem) syncFile( - ctx context.Context, - f *inode.FileInode) (err error) { + ctx context.Context, + f *inode.FileInode) (err error) { // SyncFile can be triggered for unlinked files if the fileHandle is open by // same or another user. This indicates a potential file clobbering scenario: // - The file was deleted (unlinked) while a handle to it was still open. @@ -1232,8 +1232,8 @@ func (fs *fileSystem) unlockAndDecrementLookupCount(in inode.Inode, N uint64) { // LOCKS_EXCLUDED(fs.mu) // UNLOCK_FUNCTION(in) func (fs *fileSystem) unlockAndMaybeDisposeOfInode( - in inode.Inode, - err *error) { + in inode.Inode, + err *error) { // If there is no error, just unlock. if *err == nil { in.Unlock() @@ -1249,11 +1249,11 @@ func (fs *fileSystem) unlockAndMaybeDisposeOfInode( // // LOCKS_REQUIRED(in) func (fs *fileSystem) getAttributes( - ctx context.Context, - in inode.Inode) ( - attr fuseops.InodeAttributes, - expiration time.Time, - err error) { + ctx context.Context, + in inode.Inode) ( + attr fuseops.InodeAttributes, + expiration time.Time, + err error) { // Call through. attr, err = in.Attributes(ctx) if err != nil { @@ -1314,7 +1314,7 @@ func (fs *fileSystem) fileInodeOrDie(id fuseops.InodeID) (in *inode.FileInode) { // // LOCKS_REQUIRED(fs.mu) func (fs *fileSystem) symlinkInodeOrDie( - id fuseops.InodeID) (in *inode.SymlinkInode) { + id fuseops.InodeID) (in *inode.SymlinkInode) { tmp := fs.inodes[id] in, ok := tmp.(*inode.SymlinkInode) if !ok { @@ -1360,8 +1360,8 @@ func (fs *fileSystem) Destroy() { } func (fs *fileSystem) StatFS( - ctx context.Context, - op *fuseops.StatFSOp) (err error) { + ctx context.Context, + op *fuseops.StatFSOp) (err error) { // Simulate a large amount of free space so that the Finder doesn't refuse to // copy in files. (See issue #125.) Use 2^17 as the block size because that // is the largest that OS X will pass on. @@ -1383,8 +1383,8 @@ func (fs *fileSystem) StatFS( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) LookUpInode( - ctx context.Context, - op *fuseops.LookUpInodeOp) (err error) { + ctx context.Context, + op *fuseops.LookUpInodeOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1419,8 +1419,8 @@ func (fs *fileSystem) LookUpInode( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) GetInodeAttributes( - ctx context.Context, - op *fuseops.GetInodeAttributesOp) (err error) { + ctx context.Context, + op *fuseops.GetInodeAttributesOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1447,8 +1447,8 @@ func (fs *fileSystem) GetInodeAttributes( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) SetInodeAttributes( - ctx context.Context, - op *fuseops.SetInodeAttributesOp) (err error) { + ctx context.Context, + op *fuseops.SetInodeAttributesOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1497,8 +1497,8 @@ func (fs *fileSystem) SetInodeAttributes( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ForgetInode( - ctx context.Context, - op *fuseops.ForgetInodeOp) (err error) { + ctx context.Context, + op *fuseops.ForgetInodeOp) (err error) { // Find the inode. fs.mu.Lock() in := fs.inodeOrDie(op.Inode) @@ -1513,8 +1513,8 @@ func (fs *fileSystem) ForgetInode( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) MkDir( - ctx context.Context, - op *fuseops.MkDirOp) (err error) { + ctx context.Context, + op *fuseops.MkDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1572,8 +1572,8 @@ func (fs *fileSystem) MkDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) MkNode( - ctx context.Context, - op *fuseops.MkNodeOp) (err error) { + ctx context.Context, + op *fuseops.MkNodeOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1612,10 +1612,10 @@ func (fs *fileSystem) MkNode( // LOCKS_EXCLUDED(fs.mu) // LOCK_FUNCTION(child) func (fs *fileSystem) createFile( - ctx context.Context, - parentID fuseops.InodeID, - name string, - mode os.FileMode) (child inode.Inode, err error) { + ctx context.Context, + parentID fuseops.InodeID, + name string, + mode os.FileMode) (child inode.Inode, err error) { // Find the parent. fs.mu.Lock() parent := fs.dirInodeOrDie(parentID) @@ -1708,8 +1708,8 @@ func (fs *fileSystem) createLocalFile(ctx context.Context, parentID fuseops.Inod // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) CreateFile( - ctx context.Context, - op *fuseops.CreateFileOp) (err error) { + ctx context.Context, + op *fuseops.CreateFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1758,8 +1758,8 @@ func (fs *fileSystem) CreateFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) CreateSymlink( - ctx context.Context, - op *fuseops.CreateSymlinkOp) (err error) { + ctx context.Context, + op *fuseops.CreateSymlinkOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1816,20 +1816,20 @@ func (fs *fileSystem) CreateSymlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) RmDir( - // When rm -r or os.RemoveAll call is made, the following calls are made in order - // 1. RmDir (only in the case of os.RemoveAll) - // 2. Unlink all nested files, - // 3. lookupInode call on implicit directory - // 4. Rmdir on the directory. - // - // When type cache ttl is set, we construct an implicitDir even though one doesn't - // exist on GCS (https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/internal/fs/inode/dir.go#L452), - // and thus, we get rmDir call to GCSFuse. - // Whereas when ttl is zero, lookupInode call itself fails and RmDir is not called - // because object is not present in GCS. - - ctx context.Context, - op *fuseops.RmDirOp) (err error) { +// When rm -r or os.RemoveAll call is made, the following calls are made in order +// 1. RmDir (only in the case of os.RemoveAll) +// 2. Unlink all nested files, +// 3. lookupInode call on implicit directory +// 4. Rmdir on the directory. +// +// When type cache ttl is set, we construct an implicitDir even though one doesn't +// exist on GCS (https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/internal/fs/inode/dir.go#L452), +// and thus, we get rmDir call to GCSFuse. +// Whereas when ttl is zero, lookupInode call itself fails and RmDir is not called +// because object is not present in GCS. + + ctx context.Context, + op *fuseops.RmDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1936,8 +1936,8 @@ func (fs *fileSystem) RmDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) Rename( - ctx context.Context, - op *fuseops.RenameOp) (err error) { + ctx context.Context, + op *fuseops.RenameOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2022,6 +2022,9 @@ func (fs *fileSystem) renameHierarchicalFile(ctx context.Context, oldParent inod return fmt.Errorf("renameHierarchicalFile: while invalidating cache for delete file: %w", err) } + // Insert new file in type cache. + newParent.InsertFileIntoTypeCache(newName) + return nil } @@ -2029,12 +2032,12 @@ func (fs *fileSystem) renameHierarchicalFile(ctx context.Context, oldParent inod // LOCKS_EXCLUDED(oldParent) // LOCKS_EXCLUDED(newParent) func (fs *fileSystem) renameNonHierarchicalFile( - ctx context.Context, - oldParent inode.DirInode, - oldName string, - oldObject *gcs.MinObject, - newParent inode.DirInode, - newFileName string) error { + ctx context.Context, + oldParent inode.DirInode, + oldName string, + oldObject *gcs.MinObject, + newParent inode.DirInode, + newFileName string) error { // Clone into the new location. newParent.Lock() _, err := newParent.CloneToChildFile(ctx, newFileName, oldObject) @@ -2175,11 +2178,11 @@ func (fs *fileSystem) renameHierarchicalDir(ctx context.Context, oldParent inode // LOCKS_EXCLUDED(oldParent) // LOCKS_EXCLUDED(newParent) func (fs *fileSystem) renameNonHierarchicalDir( - ctx context.Context, - oldParent inode.DirInode, - oldName string, - newParent inode.DirInode, - newName string) error { + ctx context.Context, + oldParent inode.DirInode, + oldName string, + newParent inode.DirInode, + newName string) error { // Set up a function that throws away the lookup count increment from // lookUpOrCreateChildInode (since the pending inodes are not sent back to @@ -2268,8 +2271,8 @@ func (fs *fileSystem) renameNonHierarchicalDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) Unlink( - ctx context.Context, - op *fuseops.UnlinkOp) (err error) { + ctx context.Context, + op *fuseops.UnlinkOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2317,7 +2320,7 @@ func (fs *fileSystem) Unlink( err = parent.DeleteChildFile( ctx, op.Name, - 0, // Latest generation + 0, // Latest generation nil) // No meta-generation precondition if err != nil { @@ -2334,8 +2337,8 @@ func (fs *fileSystem) Unlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) OpenDir( - ctx context.Context, - op *fuseops.OpenDirOp) (err error) { + ctx context.Context, + op *fuseops.OpenDirOp) (err error) { fs.mu.Lock() // Make sure the inode still exists and is a directory. If not, something has @@ -2365,8 +2368,8 @@ func (fs *fileSystem) OpenDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadDir( - ctx context.Context, - op *fuseops.ReadDirOp) (err error) { + ctx context.Context, + op *fuseops.ReadDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2395,8 +2398,8 @@ func (fs *fileSystem) ReadDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReleaseDirHandle( - ctx context.Context, - op *fuseops.ReleaseDirHandleOp) (err error) { + ctx context.Context, + op *fuseops.ReleaseDirHandleOp) (err error) { fs.mu.Lock() defer fs.mu.Unlock() @@ -2411,8 +2414,8 @@ func (fs *fileSystem) ReleaseDirHandle( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) OpenFile( - ctx context.Context, - op *fuseops.OpenFileOp) (err error) { + ctx context.Context, + op *fuseops.OpenFileOp) (err error) { fs.mu.Lock() // Find the inode. @@ -2445,8 +2448,8 @@ func (fs *fileSystem) OpenFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadFile( - ctx context.Context, - op *fuseops.ReadFileOp) (err error) { + ctx context.Context, + op *fuseops.ReadFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2478,8 +2481,8 @@ func (fs *fileSystem) ReadFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadSymlink( - ctx context.Context, - op *fuseops.ReadSymlinkOp) (err error) { + ctx context.Context, + op *fuseops.ReadSymlinkOp) (err error) { // Find the inode. fs.mu.Lock() in := fs.symlinkInodeOrDie(op.Inode) @@ -2496,8 +2499,8 @@ func (fs *fileSystem) ReadSymlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) WriteFile( - ctx context.Context, - op *fuseops.WriteFileOp) (err error) { + ctx context.Context, + op *fuseops.WriteFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2523,8 +2526,8 @@ func (fs *fileSystem) WriteFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) SyncFile( - ctx context.Context, - op *fuseops.SyncFileOp) (err error) { + ctx context.Context, + op *fuseops.SyncFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2556,8 +2559,8 @@ func (fs *fileSystem) SyncFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) FlushFile( - ctx context.Context, - op *fuseops.FlushFileOp) (err error) { + ctx context.Context, + op *fuseops.FlushFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2583,8 +2586,8 @@ func (fs *fileSystem) FlushFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReleaseFileHandle( - ctx context.Context, - op *fuseops.ReleaseFileHandleOp) (err error) { + ctx context.Context, + op *fuseops.ReleaseFileHandleOp) (err error) { fs.mu.Lock() fileHandle := fs.handles[op.Handle].(*handle.FileHandle) @@ -2602,13 +2605,13 @@ func (fs *fileSystem) ReleaseFileHandle( } func (fs *fileSystem) GetXattr( - ctx context.Context, - op *fuseops.GetXattrOp) (err error) { + ctx context.Context, + op *fuseops.GetXattrOp) (err error) { return syscall.ENOSYS } func (fs *fileSystem) ListXattr( - ctx context.Context, - op *fuseops.ListXattrOp) error { + ctx context.Context, + op *fuseops.ListXattrOp) error { return syscall.ENOSYS } From 47961236ce9c061d5edddcfb621724cd06d08e5c Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 10:52:25 +0000 Subject: [PATCH 7/9] rebase --- internal/fs/fs.go | 190 +++++++++++++++++++++++----------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index 3f623d7abb..3e57cf259d 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -252,9 +252,9 @@ func createFileCacheHandler(serverCfg *ServerConfig) (fileCacheHandler *file.Cac } func makeRootForBucket( - ctx context.Context, - fs *fileSystem, - syncerBucket gcsx.SyncerBucket) inode.DirInode { + ctx context.Context, + fs *fileSystem, + syncerBucket gcsx.SyncerBucket) inode.DirInode { return inode.NewDirInode( fuseops.RootInodeID, inode.NewRootName(""), @@ -967,9 +967,9 @@ func (fs *fileSystem) lookUpOrCreateInodeIfNotStale(ic inode.Core) (in inode.Ino // LOCKS_EXCLUDED(parent) // LOCK_FUNCTION(child) func (fs *fileSystem) lookUpOrCreateChildInode( - ctx context.Context, - parent inode.DirInode, - childName string) (child inode.Inode, err error) { + ctx context.Context, + parent inode.DirInode, + childName string) (child inode.Inode, err error) { // First check if the requested child is a localFileInode. child = fs.lookUpLocalFileInode(parent, childName) if child != nil { @@ -1093,9 +1093,9 @@ func (fs *fileSystem) lookUpLocalFileInode(parent inode.DirInode, childName stri // LOCKS_EXCLUDED(parent) // LOCK_FUNCTION(child) func (fs *fileSystem) lookUpOrCreateChildDirInode( - ctx context.Context, - parent inode.DirInode, - childName string) (child inode.BucketOwnedDirInode, err error) { + ctx context.Context, + parent inode.DirInode, + childName string) (child inode.BucketOwnedDirInode, err error) { in, err := fs.lookUpOrCreateChildInode(ctx, parent, childName) if err != nil { return nil, fmt.Errorf("lookup or create %q: %w", childName, err) @@ -1114,8 +1114,8 @@ func (fs *fileSystem) lookUpOrCreateChildDirInode( // LOCKS_EXCLUDED(fs.mu) // LOCKS_REQUIRED(f) func (fs *fileSystem) syncFile( - ctx context.Context, - f *inode.FileInode) (err error) { + ctx context.Context, + f *inode.FileInode) (err error) { // SyncFile can be triggered for unlinked files if the fileHandle is open by // same or another user. This indicates a potential file clobbering scenario: // - The file was deleted (unlinked) while a handle to it was still open. @@ -1232,8 +1232,8 @@ func (fs *fileSystem) unlockAndDecrementLookupCount(in inode.Inode, N uint64) { // LOCKS_EXCLUDED(fs.mu) // UNLOCK_FUNCTION(in) func (fs *fileSystem) unlockAndMaybeDisposeOfInode( - in inode.Inode, - err *error) { + in inode.Inode, + err *error) { // If there is no error, just unlock. if *err == nil { in.Unlock() @@ -1249,11 +1249,11 @@ func (fs *fileSystem) unlockAndMaybeDisposeOfInode( // // LOCKS_REQUIRED(in) func (fs *fileSystem) getAttributes( - ctx context.Context, - in inode.Inode) ( - attr fuseops.InodeAttributes, - expiration time.Time, - err error) { + ctx context.Context, + in inode.Inode) ( + attr fuseops.InodeAttributes, + expiration time.Time, + err error) { // Call through. attr, err = in.Attributes(ctx) if err != nil { @@ -1314,7 +1314,7 @@ func (fs *fileSystem) fileInodeOrDie(id fuseops.InodeID) (in *inode.FileInode) { // // LOCKS_REQUIRED(fs.mu) func (fs *fileSystem) symlinkInodeOrDie( - id fuseops.InodeID) (in *inode.SymlinkInode) { + id fuseops.InodeID) (in *inode.SymlinkInode) { tmp := fs.inodes[id] in, ok := tmp.(*inode.SymlinkInode) if !ok { @@ -1360,8 +1360,8 @@ func (fs *fileSystem) Destroy() { } func (fs *fileSystem) StatFS( - ctx context.Context, - op *fuseops.StatFSOp) (err error) { + ctx context.Context, + op *fuseops.StatFSOp) (err error) { // Simulate a large amount of free space so that the Finder doesn't refuse to // copy in files. (See issue #125.) Use 2^17 as the block size because that // is the largest that OS X will pass on. @@ -1383,8 +1383,8 @@ func (fs *fileSystem) StatFS( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) LookUpInode( - ctx context.Context, - op *fuseops.LookUpInodeOp) (err error) { + ctx context.Context, + op *fuseops.LookUpInodeOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1419,8 +1419,8 @@ func (fs *fileSystem) LookUpInode( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) GetInodeAttributes( - ctx context.Context, - op *fuseops.GetInodeAttributesOp) (err error) { + ctx context.Context, + op *fuseops.GetInodeAttributesOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1447,8 +1447,8 @@ func (fs *fileSystem) GetInodeAttributes( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) SetInodeAttributes( - ctx context.Context, - op *fuseops.SetInodeAttributesOp) (err error) { + ctx context.Context, + op *fuseops.SetInodeAttributesOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1497,8 +1497,8 @@ func (fs *fileSystem) SetInodeAttributes( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ForgetInode( - ctx context.Context, - op *fuseops.ForgetInodeOp) (err error) { + ctx context.Context, + op *fuseops.ForgetInodeOp) (err error) { // Find the inode. fs.mu.Lock() in := fs.inodeOrDie(op.Inode) @@ -1513,8 +1513,8 @@ func (fs *fileSystem) ForgetInode( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) MkDir( - ctx context.Context, - op *fuseops.MkDirOp) (err error) { + ctx context.Context, + op *fuseops.MkDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1572,8 +1572,8 @@ func (fs *fileSystem) MkDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) MkNode( - ctx context.Context, - op *fuseops.MkNodeOp) (err error) { + ctx context.Context, + op *fuseops.MkNodeOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1612,10 +1612,10 @@ func (fs *fileSystem) MkNode( // LOCKS_EXCLUDED(fs.mu) // LOCK_FUNCTION(child) func (fs *fileSystem) createFile( - ctx context.Context, - parentID fuseops.InodeID, - name string, - mode os.FileMode) (child inode.Inode, err error) { + ctx context.Context, + parentID fuseops.InodeID, + name string, + mode os.FileMode) (child inode.Inode, err error) { // Find the parent. fs.mu.Lock() parent := fs.dirInodeOrDie(parentID) @@ -1708,8 +1708,8 @@ func (fs *fileSystem) createLocalFile(ctx context.Context, parentID fuseops.Inod // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) CreateFile( - ctx context.Context, - op *fuseops.CreateFileOp) (err error) { + ctx context.Context, + op *fuseops.CreateFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1758,8 +1758,8 @@ func (fs *fileSystem) CreateFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) CreateSymlink( - ctx context.Context, - op *fuseops.CreateSymlinkOp) (err error) { + ctx context.Context, + op *fuseops.CreateSymlinkOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1816,20 +1816,20 @@ func (fs *fileSystem) CreateSymlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) RmDir( -// When rm -r or os.RemoveAll call is made, the following calls are made in order -// 1. RmDir (only in the case of os.RemoveAll) -// 2. Unlink all nested files, -// 3. lookupInode call on implicit directory -// 4. Rmdir on the directory. -// -// When type cache ttl is set, we construct an implicitDir even though one doesn't -// exist on GCS (https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/internal/fs/inode/dir.go#L452), -// and thus, we get rmDir call to GCSFuse. -// Whereas when ttl is zero, lookupInode call itself fails and RmDir is not called -// because object is not present in GCS. - - ctx context.Context, - op *fuseops.RmDirOp) (err error) { + // When rm -r or os.RemoveAll call is made, the following calls are made in order + // 1. RmDir (only in the case of os.RemoveAll) + // 2. Unlink all nested files, + // 3. lookupInode call on implicit directory + // 4. Rmdir on the directory. + // + // When type cache ttl is set, we construct an implicitDir even though one doesn't + // exist on GCS (https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/internal/fs/inode/dir.go#L452), + // and thus, we get rmDir call to GCSFuse. + // Whereas when ttl is zero, lookupInode call itself fails and RmDir is not called + // because object is not present in GCS. + + ctx context.Context, + op *fuseops.RmDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -1936,8 +1936,8 @@ func (fs *fileSystem) RmDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) Rename( - ctx context.Context, - op *fuseops.RenameOp) (err error) { + ctx context.Context, + op *fuseops.RenameOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2032,12 +2032,12 @@ func (fs *fileSystem) renameHierarchicalFile(ctx context.Context, oldParent inod // LOCKS_EXCLUDED(oldParent) // LOCKS_EXCLUDED(newParent) func (fs *fileSystem) renameNonHierarchicalFile( - ctx context.Context, - oldParent inode.DirInode, - oldName string, - oldObject *gcs.MinObject, - newParent inode.DirInode, - newFileName string) error { + ctx context.Context, + oldParent inode.DirInode, + oldName string, + oldObject *gcs.MinObject, + newParent inode.DirInode, + newFileName string) error { // Clone into the new location. newParent.Lock() _, err := newParent.CloneToChildFile(ctx, newFileName, oldObject) @@ -2178,11 +2178,11 @@ func (fs *fileSystem) renameHierarchicalDir(ctx context.Context, oldParent inode // LOCKS_EXCLUDED(oldParent) // LOCKS_EXCLUDED(newParent) func (fs *fileSystem) renameNonHierarchicalDir( - ctx context.Context, - oldParent inode.DirInode, - oldName string, - newParent inode.DirInode, - newName string) error { + ctx context.Context, + oldParent inode.DirInode, + oldName string, + newParent inode.DirInode, + newName string) error { // Set up a function that throws away the lookup count increment from // lookUpOrCreateChildInode (since the pending inodes are not sent back to @@ -2271,8 +2271,8 @@ func (fs *fileSystem) renameNonHierarchicalDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) Unlink( - ctx context.Context, - op *fuseops.UnlinkOp) (err error) { + ctx context.Context, + op *fuseops.UnlinkOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2320,7 +2320,7 @@ func (fs *fileSystem) Unlink( err = parent.DeleteChildFile( ctx, op.Name, - 0, // Latest generation + 0, // Latest generation nil) // No meta-generation precondition if err != nil { @@ -2337,8 +2337,8 @@ func (fs *fileSystem) Unlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) OpenDir( - ctx context.Context, - op *fuseops.OpenDirOp) (err error) { + ctx context.Context, + op *fuseops.OpenDirOp) (err error) { fs.mu.Lock() // Make sure the inode still exists and is a directory. If not, something has @@ -2368,8 +2368,8 @@ func (fs *fileSystem) OpenDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadDir( - ctx context.Context, - op *fuseops.ReadDirOp) (err error) { + ctx context.Context, + op *fuseops.ReadDirOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2398,8 +2398,8 @@ func (fs *fileSystem) ReadDir( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReleaseDirHandle( - ctx context.Context, - op *fuseops.ReleaseDirHandleOp) (err error) { + ctx context.Context, + op *fuseops.ReleaseDirHandleOp) (err error) { fs.mu.Lock() defer fs.mu.Unlock() @@ -2414,8 +2414,8 @@ func (fs *fileSystem) ReleaseDirHandle( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) OpenFile( - ctx context.Context, - op *fuseops.OpenFileOp) (err error) { + ctx context.Context, + op *fuseops.OpenFileOp) (err error) { fs.mu.Lock() // Find the inode. @@ -2448,8 +2448,8 @@ func (fs *fileSystem) OpenFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadFile( - ctx context.Context, - op *fuseops.ReadFileOp) (err error) { + ctx context.Context, + op *fuseops.ReadFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2481,8 +2481,8 @@ func (fs *fileSystem) ReadFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReadSymlink( - ctx context.Context, - op *fuseops.ReadSymlinkOp) (err error) { + ctx context.Context, + op *fuseops.ReadSymlinkOp) (err error) { // Find the inode. fs.mu.Lock() in := fs.symlinkInodeOrDie(op.Inode) @@ -2499,8 +2499,8 @@ func (fs *fileSystem) ReadSymlink( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) WriteFile( - ctx context.Context, - op *fuseops.WriteFileOp) (err error) { + ctx context.Context, + op *fuseops.WriteFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2526,8 +2526,8 @@ func (fs *fileSystem) WriteFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) SyncFile( - ctx context.Context, - op *fuseops.SyncFileOp) (err error) { + ctx context.Context, + op *fuseops.SyncFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2559,8 +2559,8 @@ func (fs *fileSystem) SyncFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) FlushFile( - ctx context.Context, - op *fuseops.FlushFileOp) (err error) { + ctx context.Context, + op *fuseops.FlushFileOp) (err error) { if fs.newConfig.FileSystem.IgnoreInterrupts { // When ignore interrupts config is set, we are creating a new context not // cancellable by parent context. @@ -2586,8 +2586,8 @@ func (fs *fileSystem) FlushFile( // LOCKS_EXCLUDED(fs.mu) func (fs *fileSystem) ReleaseFileHandle( - ctx context.Context, - op *fuseops.ReleaseFileHandleOp) (err error) { + ctx context.Context, + op *fuseops.ReleaseFileHandleOp) (err error) { fs.mu.Lock() fileHandle := fs.handles[op.Handle].(*handle.FileHandle) @@ -2605,13 +2605,13 @@ func (fs *fileSystem) ReleaseFileHandle( } func (fs *fileSystem) GetXattr( - ctx context.Context, - op *fuseops.GetXattrOp) (err error) { + ctx context.Context, + op *fuseops.GetXattrOp) (err error) { return syscall.ENOSYS } func (fs *fileSystem) ListXattr( - ctx context.Context, - op *fuseops.ListXattrOp) error { + ctx context.Context, + op *fuseops.ListXattrOp) error { return syscall.ENOSYS } From 8b2ea3e96bc98ea57c20ce5e06e901d7609543b5 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 10:53:35 +0000 Subject: [PATCH 8/9] undo unnecessary change --- internal/storage/fake/bucket.go | 49 +++++++++++++++++---------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/internal/storage/fake/bucket.go b/internal/storage/fake/bucket.go index 0781e3205b..74db5e07cd 100644 --- a/internal/storage/fake/bucket.go +++ b/internal/storage/fake/bucket.go @@ -232,8 +232,8 @@ func (b *bucket) checkInvariants() { // // LOCKS_REQUIRED(b.mu) func (b *bucket) mintObject( - req *gcs.CreateObjectRequest, - contents []byte) (o fakeObject) { + req *gcs.CreateObjectRequest, + contents []byte) (o fakeObject) { md5Sum := md5.Sum(contents) crc32c := crc32.Checksum(contents, crc32cTable) @@ -413,7 +413,7 @@ func createOrUpdateFakeObject(b *bucket, req *gcs.CreateObjectRequest, contents // LOCKS_REQUIRED(b.mu) func (b *bucket) createObjectLocked( - req *gcs.CreateObjectRequest) (o *gcs.Object, err error) { + req *gcs.CreateObjectRequest) (o *gcs.Object, err error) { // Check that the name is legal. err = checkName(req.Name) if err != nil { @@ -437,7 +437,7 @@ func (b *bucket) createObjectLocked( // // LOCKS_REQUIRED(b.mu) func (b *bucket) newReaderLocked( - req *gcs.ReadObjectRequest) (r io.Reader, index int, err error) { + req *gcs.ReadObjectRequest) (r io.Reader, index int, err error) { // Find the object with the requested name. index = b.objects.find(req.Name) if index == len(b.objects) { @@ -544,8 +544,8 @@ func (b *bucket) BucketType() gcs.BucketType { // LOCKS_EXCLUDED(b.mu) func (b *bucket) ListObjects( - ctx context.Context, - req *gcs.ListObjectsRequest) (listing *gcs.Listing, err error) { + ctx context.Context, + req *gcs.ListObjectsRequest) (listing *gcs.Listing, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -593,7 +593,7 @@ func (b *bucket) ListObjects( // Save the result, but only if it's not a duplicate. resultPrefix := name[:resultPrefixLimit] if len(listing.CollapsedRuns) == 0 || - listing.CollapsedRuns[len(listing.CollapsedRuns)-1] != resultPrefix { + listing.CollapsedRuns[len(listing.CollapsedRuns)-1] != resultPrefix { listing.CollapsedRuns = append(listing.CollapsedRuns, resultPrefix) } @@ -660,8 +660,8 @@ func (b *bucket) ListObjects( // LOCKS_EXCLUDED(b.mu) func (b *bucket) NewReader( - ctx context.Context, - req *gcs.ReadObjectRequest) (rc io.ReadCloser, err error) { + ctx context.Context, + req *gcs.ReadObjectRequest) (rc io.ReadCloser, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -676,8 +676,8 @@ func (b *bucket) NewReader( // LOCKS_EXCLUDED(b.mu) func (b *bucket) CreateObject( - ctx context.Context, - req *gcs.CreateObjectRequest) (o *gcs.Object, err error) { + ctx context.Context, + req *gcs.CreateObjectRequest) (o *gcs.Object, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -707,8 +707,8 @@ func (b *bucket) FinalizeUpload(ctx context.Context, w gcs.Writer) (*gcs.MinObje // LOCKS_EXCLUDED(b.mu) func (b *bucket) CopyObject( - ctx context.Context, - req *gcs.CopyObjectRequest) (o *gcs.Object, err error) { + ctx context.Context, + req *gcs.CopyObjectRequest) (o *gcs.Object, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -730,7 +730,7 @@ func (b *bucket) CopyObject( // Does it have the correct generation? if req.SrcGeneration != 0 && - b.objects[srcIndex].metadata.Generation != req.SrcGeneration { + b.objects[srcIndex].metadata.Generation != req.SrcGeneration { err = &gcs.NotFoundError{ Err: fmt.Errorf( "object %s generation %d not found", req.SrcName, req.SrcGeneration), @@ -778,8 +778,8 @@ func (b *bucket) CopyObject( // LOCKS_EXCLUDED(b.mu) func (b *bucket) ComposeObjects( - ctx context.Context, - req *gcs.ComposeObjectsRequest) (o *gcs.Object, err error) { + ctx context.Context, + req *gcs.ComposeObjectsRequest) (o *gcs.Object, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -853,7 +853,7 @@ func (b *bucket) ComposeObjects( // LOCKS_EXCLUDED(b.mu) func (b *bucket) StatObject(ctx context.Context, - req *gcs.StatObjectRequest) (m *gcs.MinObject, e *gcs.ExtendedObjectAttributes, err error) { + req *gcs.StatObjectRequest) (m *gcs.MinObject, e *gcs.ExtendedObjectAttributes, err error) { // If ExtendedObjectAttributes are requested without fetching from gcs enabled, panic. if !req.ForceFetchFromGcs && req.ReturnExtendedObjectAttributes { panic("invalid StatObjectRequest: ForceFetchFromGcs: false and ReturnExtendedObjectAttributes: true") @@ -882,8 +882,8 @@ func (b *bucket) StatObject(ctx context.Context, // LOCKS_EXCLUDED(b.mu) func (b *bucket) UpdateObject( - ctx context.Context, - req *gcs.UpdateObjectRequest) (o *gcs.Object, err error) { + ctx context.Context, + req *gcs.UpdateObjectRequest) (o *gcs.Object, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -913,7 +913,7 @@ func (b *bucket) UpdateObject( // Does the meta-generation precondition check out? if req.MetaGenerationPrecondition != nil && - obj.MetaGeneration != *req.MetaGenerationPrecondition { + obj.MetaGeneration != *req.MetaGenerationPrecondition { err = &gcs.PreconditionError{ Err: fmt.Errorf( "object %q has meta-generation %d", @@ -969,8 +969,8 @@ func (b *bucket) UpdateObject( // LOCKS_EXCLUDED(b.mu) func (b *bucket) DeleteObject( - ctx context.Context, - req *gcs.DeleteObjectRequest) (err error) { + ctx context.Context, + req *gcs.DeleteObjectRequest) (err error) { b.mu.Lock() defer b.mu.Unlock() @@ -982,7 +982,7 @@ func (b *bucket) DeleteObject( // Don't do anything if the generation is wrong. if req.Generation != 0 && - b.objects[index].metadata.Generation != req.Generation { + b.objects[index].metadata.Generation != req.Generation { return } @@ -1025,7 +1025,7 @@ func (b *bucket) MoveObject(ctx context.Context, req *gcs.MoveObjectRequest) (*g // Does it have the correct generation? if req.SrcGeneration != 0 && - b.objects[srcIndex].metadata.Generation != req.SrcGeneration { + b.objects[srcIndex].metadata.Generation != req.SrcGeneration { err = &gcs.NotFoundError{ Err: fmt.Errorf("object %s generation %d not found", req.SrcName, req.SrcGeneration), } @@ -1051,6 +1051,7 @@ func (b *bucket) MoveObject(ctx context.Context, req *gcs.MoveObjectRequest) (*g b.prevGeneration++ dst.metadata.Generation = b.prevGeneration + // Remove the source object. b.objects = append(b.objects[:srcIndex], b.objects[srcIndex+1:]...) // Insert dest object into our array. From 1b89dd3701d6fda0f1598e49dc1571268c4a77da Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 27 Dec 2024 10:53:52 +0000 Subject: [PATCH 9/9] undo unnecessary change --- internal/storage/fake/bucket.go | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/internal/storage/fake/bucket.go b/internal/storage/fake/bucket.go index 74db5e07cd..919c3bed50 100644 --- a/internal/storage/fake/bucket.go +++ b/internal/storage/fake/bucket.go @@ -232,8 +232,8 @@ func (b *bucket) checkInvariants() { // // LOCKS_REQUIRED(b.mu) func (b *bucket) mintObject( - req *gcs.CreateObjectRequest, - contents []byte) (o fakeObject) { + req *gcs.CreateObjectRequest, + contents []byte) (o fakeObject) { md5Sum := md5.Sum(contents) crc32c := crc32.Checksum(contents, crc32cTable) @@ -413,7 +413,7 @@ func createOrUpdateFakeObject(b *bucket, req *gcs.CreateObjectRequest, contents // LOCKS_REQUIRED(b.mu) func (b *bucket) createObjectLocked( - req *gcs.CreateObjectRequest) (o *gcs.Object, err error) { + req *gcs.CreateObjectRequest) (o *gcs.Object, err error) { // Check that the name is legal. err = checkName(req.Name) if err != nil { @@ -437,7 +437,7 @@ func (b *bucket) createObjectLocked( // // LOCKS_REQUIRED(b.mu) func (b *bucket) newReaderLocked( - req *gcs.ReadObjectRequest) (r io.Reader, index int, err error) { + req *gcs.ReadObjectRequest) (r io.Reader, index int, err error) { // Find the object with the requested name. index = b.objects.find(req.Name) if index == len(b.objects) { @@ -544,8 +544,8 @@ func (b *bucket) BucketType() gcs.BucketType { // LOCKS_EXCLUDED(b.mu) func (b *bucket) ListObjects( - ctx context.Context, - req *gcs.ListObjectsRequest) (listing *gcs.Listing, err error) { + ctx context.Context, + req *gcs.ListObjectsRequest) (listing *gcs.Listing, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -593,7 +593,7 @@ func (b *bucket) ListObjects( // Save the result, but only if it's not a duplicate. resultPrefix := name[:resultPrefixLimit] if len(listing.CollapsedRuns) == 0 || - listing.CollapsedRuns[len(listing.CollapsedRuns)-1] != resultPrefix { + listing.CollapsedRuns[len(listing.CollapsedRuns)-1] != resultPrefix { listing.CollapsedRuns = append(listing.CollapsedRuns, resultPrefix) } @@ -660,8 +660,8 @@ func (b *bucket) ListObjects( // LOCKS_EXCLUDED(b.mu) func (b *bucket) NewReader( - ctx context.Context, - req *gcs.ReadObjectRequest) (rc io.ReadCloser, err error) { + ctx context.Context, + req *gcs.ReadObjectRequest) (rc io.ReadCloser, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -676,8 +676,8 @@ func (b *bucket) NewReader( // LOCKS_EXCLUDED(b.mu) func (b *bucket) CreateObject( - ctx context.Context, - req *gcs.CreateObjectRequest) (o *gcs.Object, err error) { + ctx context.Context, + req *gcs.CreateObjectRequest) (o *gcs.Object, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -707,8 +707,8 @@ func (b *bucket) FinalizeUpload(ctx context.Context, w gcs.Writer) (*gcs.MinObje // LOCKS_EXCLUDED(b.mu) func (b *bucket) CopyObject( - ctx context.Context, - req *gcs.CopyObjectRequest) (o *gcs.Object, err error) { + ctx context.Context, + req *gcs.CopyObjectRequest) (o *gcs.Object, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -730,7 +730,7 @@ func (b *bucket) CopyObject( // Does it have the correct generation? if req.SrcGeneration != 0 && - b.objects[srcIndex].metadata.Generation != req.SrcGeneration { + b.objects[srcIndex].metadata.Generation != req.SrcGeneration { err = &gcs.NotFoundError{ Err: fmt.Errorf( "object %s generation %d not found", req.SrcName, req.SrcGeneration), @@ -778,8 +778,8 @@ func (b *bucket) CopyObject( // LOCKS_EXCLUDED(b.mu) func (b *bucket) ComposeObjects( - ctx context.Context, - req *gcs.ComposeObjectsRequest) (o *gcs.Object, err error) { + ctx context.Context, + req *gcs.ComposeObjectsRequest) (o *gcs.Object, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -853,7 +853,7 @@ func (b *bucket) ComposeObjects( // LOCKS_EXCLUDED(b.mu) func (b *bucket) StatObject(ctx context.Context, - req *gcs.StatObjectRequest) (m *gcs.MinObject, e *gcs.ExtendedObjectAttributes, err error) { + req *gcs.StatObjectRequest) (m *gcs.MinObject, e *gcs.ExtendedObjectAttributes, err error) { // If ExtendedObjectAttributes are requested without fetching from gcs enabled, panic. if !req.ForceFetchFromGcs && req.ReturnExtendedObjectAttributes { panic("invalid StatObjectRequest: ForceFetchFromGcs: false and ReturnExtendedObjectAttributes: true") @@ -882,8 +882,8 @@ func (b *bucket) StatObject(ctx context.Context, // LOCKS_EXCLUDED(b.mu) func (b *bucket) UpdateObject( - ctx context.Context, - req *gcs.UpdateObjectRequest) (o *gcs.Object, err error) { + ctx context.Context, + req *gcs.UpdateObjectRequest) (o *gcs.Object, err error) { b.mu.Lock() defer b.mu.Unlock() @@ -913,7 +913,7 @@ func (b *bucket) UpdateObject( // Does the meta-generation precondition check out? if req.MetaGenerationPrecondition != nil && - obj.MetaGeneration != *req.MetaGenerationPrecondition { + obj.MetaGeneration != *req.MetaGenerationPrecondition { err = &gcs.PreconditionError{ Err: fmt.Errorf( "object %q has meta-generation %d", @@ -969,8 +969,8 @@ func (b *bucket) UpdateObject( // LOCKS_EXCLUDED(b.mu) func (b *bucket) DeleteObject( - ctx context.Context, - req *gcs.DeleteObjectRequest) (err error) { + ctx context.Context, + req *gcs.DeleteObjectRequest) (err error) { b.mu.Lock() defer b.mu.Unlock() @@ -982,7 +982,7 @@ func (b *bucket) DeleteObject( // Don't do anything if the generation is wrong. if req.Generation != 0 && - b.objects[index].metadata.Generation != req.Generation { + b.objects[index].metadata.Generation != req.Generation { return } @@ -1025,7 +1025,7 @@ func (b *bucket) MoveObject(ctx context.Context, req *gcs.MoveObjectRequest) (*g // Does it have the correct generation? if req.SrcGeneration != 0 && - b.objects[srcIndex].metadata.Generation != req.SrcGeneration { + b.objects[srcIndex].metadata.Generation != req.SrcGeneration { err = &gcs.NotFoundError{ Err: fmt.Errorf("object %s generation %d not found", req.SrcName, req.SrcGeneration), }