From d93547cd32c19ee725f279f9b9f9b5ea1ce628f0 Mon Sep 17 00:00:00 2001 From: Illyoung Choi Date: Fri, 23 Jun 2023 11:23:57 -0700 Subject: [PATCH] Assign inode for virtual dir entry --- go.mod | 4 +-- go.sum | 8 +++--- irodsfs/dir.go | 63 +++++++++++++++++++++++++++++++++++------------- irodsfs/file.go | 2 +- irodsfs/inode.go | 12 +++++++++ utils/number.go | 8 ++++++ 6 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 irodsfs/inode.go create mode 100644 utils/number.go diff --git a/go.mod b/go.mod index a04b9b8..1d78ae6 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.18 require ( github.com/cyverse/go-irodsclient v0.11.2 - github.com/cyverse/irodsfs-common v0.0.0-20230308234020-6ab739dff839 + github.com/cyverse/irodsfs-common v0.0.0-20230623171151-5e4370b83339 github.com/cyverse/irodsfs-monitor v0.0.0-20220809235922-daf13261a2dc - github.com/cyverse/irodsfs-pool v0.6.12 + github.com/cyverse/irodsfs-pool v0.6.13 github.com/hanwen/go-fuse/v2 v2.1.0 github.com/pkg/profile v1.7.0 github.com/rs/xid v1.3.0 diff --git a/go.sum b/go.sum index c72756b..a63edc7 100644 --- a/go.sum +++ b/go.sum @@ -16,12 +16,12 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cyverse/go-irodsclient v0.11.2 h1:nhVG3Nyzf4eoFFqAcWAvqeHVecsu0yz7CCp/rIQQSE4= github.com/cyverse/go-irodsclient v0.11.2/go.mod h1:Qs1cjnDN1RaBaUcaZCsRGPFqCffg/cExSBIm466nvTw= -github.com/cyverse/irodsfs-common v0.0.0-20230308234020-6ab739dff839 h1:rOi3lMYkCQxJDGq9r13o8Eda5T6kDlVxr+bXl3ZAWFg= -github.com/cyverse/irodsfs-common v0.0.0-20230308234020-6ab739dff839/go.mod h1:6nBmND4wMHyiU4znH2MqXb6RCTqT0SVH8bbv0zH9wWo= +github.com/cyverse/irodsfs-common v0.0.0-20230623171151-5e4370b83339 h1:hxwOJ0nTrilI/sv6TNVdmSN4t+yB82Uo2/7AoiVtN5g= +github.com/cyverse/irodsfs-common v0.0.0-20230623171151-5e4370b83339/go.mod h1:6nBmND4wMHyiU4znH2MqXb6RCTqT0SVH8bbv0zH9wWo= github.com/cyverse/irodsfs-monitor v0.0.0-20220809235922-daf13261a2dc h1:gIpG0ETQOEZloFwB5iU2zljVsoUDTpUEl/3WF19gLNk= github.com/cyverse/irodsfs-monitor v0.0.0-20220809235922-daf13261a2dc/go.mod h1:8UE1mT26+0vAsqS9UJ6Q/vlKq3da6FLdt5p6Tt1AIC4= -github.com/cyverse/irodsfs-pool v0.6.12 h1:NSFi1PEO7HYHfmr4ttXy9tK8rqszfkOFWUBQTD6qDog= -github.com/cyverse/irodsfs-pool v0.6.12/go.mod h1:OePYtZFHvmjJLqdZPeTciz5Hkuj/jRViM05F/wdRQVM= +github.com/cyverse/irodsfs-pool v0.6.13 h1:1k+2AgahxCsCkuGog3fKDvzpG4PUptltKtm0Q+zsr4I= +github.com/cyverse/irodsfs-pool v0.6.13/go.mod h1:SIydk5Kq+cfmm1ilx8I3tyfyUvO2mYI29y444LtoEx8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/irodsfs/dir.go b/irodsfs/dir.go index f8b542b..53717b9 100644 --- a/irodsfs/dir.go +++ b/irodsfs/dir.go @@ -49,16 +49,23 @@ func (dir *Dir) newSubFileInode(ctx context.Context, entryID int64, path string) func (dir *Dir) getStableAttr() fusefs.StableAttr { return fusefs.StableAttr{ - Mode: fuse.S_IFDIR, - Ino: uint64(dir.entryID), + Mode: uint32(fuse.S_IFDIR), + Ino: getInodeIDFromEntryID(dir.entryID), Gen: 0, } } func (dir *Dir) setAttrOut(vpathEntry *irodsfs_common_vpath.VPathEntry, out *fuse.Attr) { + logger := log.WithFields(log.Fields{ + "package": "irodsfs", + "struct": "Dir", + "function": "setAttrOut", + }) + if vpathEntry.Type == irodsfs_common_vpath.VPathVirtualDir { // vpath - out.Ino = uint64(vpathEntry.VirtualDirEntry.ID) + logger.Debugf("vpath virtual dir - path: %s ino: %d", vpathEntry.Path, getInodeIDFromEntryID(vpathEntry.VirtualDirEntry.ID)) + out.Ino = getInodeIDFromEntryID(vpathEntry.VirtualDirEntry.ID) out.Uid = dir.fs.uid out.Gid = dir.fs.gid out.SetTimes(&vpathEntry.VirtualDirEntry.ModifyTime, &vpathEntry.VirtualDirEntry.ModifyTime, &vpathEntry.VirtualDirEntry.ModifyTime) @@ -66,7 +73,7 @@ func (dir *Dir) setAttrOut(vpathEntry *irodsfs_common_vpath.VPathEntry, out *fus out.Mode = uint32(fuse.S_IFDIR | 0o500) } else if vpathEntry.Type == irodsfs_common_vpath.VPathIRODS { // irods - out.Ino = uint64(vpathEntry.IRODSEntry.ID) + out.Ino = getInodeIDFromEntryID(vpathEntry.IRODSEntry.ID) out.Uid = dir.fs.uid out.Gid = dir.fs.gid out.SetTimes(&vpathEntry.IRODSEntry.ModifyTime, &vpathEntry.IRODSEntry.ModifyTime, &vpathEntry.IRODSEntry.ModifyTime) @@ -732,37 +739,48 @@ func (dir *Dir) Readdir(ctx context.Context) (fusefs.DirStream, syscall.Errno) { if vpathEntry.Type == irodsfs_common_vpath.VPathVirtualDir { if vpathEntry.Path == dir.path { - dirEntries := make([]fuse.DirEntry, len(vpathEntry.VirtualDirEntry.DirEntries)) + dirEntries := make([]fuse.DirEntry, len(vpathEntry.VirtualDirEntry.DirEntries)+2) + + dirEntries[0] = fuse.DirEntry{ + Ino: 0, + Mode: uint32(fuse.S_IFDIR), + Name: ".", + } + dirEntries[1] = fuse.DirEntry{ + Ino: 0, + Mode: uint32(fuse.S_IFDIR), + Name: "..", + } for idx, entry := range vpathEntry.VirtualDirEntry.DirEntries { if entry.Type == irodsfs_common_vpath.VPathVirtualDir { dirEntry := fuse.DirEntry{ - Ino: uint64(entry.VirtualDirEntry.ID), - Mode: fuse.S_IFDIR, + Ino: getInodeIDFromEntryID(entry.VirtualDirEntry.ID), + Mode: uint32(fuse.S_IFDIR), Name: entry.VirtualDirEntry.Name, } - dirEntries[idx] = dirEntry + dirEntries[idx+2] = dirEntry } else if entry.Type == irodsfs_common_vpath.VPathIRODS { entryType := uint32(fuse.S_IFREG) switch entry.IRODSEntry.Type { case irodsclient_fs.FileEntry: - entryType = fuse.S_IFREG + entryType = uint32(fuse.S_IFREG) case irodsclient_fs.DirectoryEntry: - entryType = fuse.S_IFDIR + entryType = uint32(fuse.S_IFDIR) default: logger.Errorf("unknown entry type - %s", entry.Type) return nil, syscall.EREMOTEIO } dirEntry := fuse.DirEntry{ - Ino: uint64(entry.IRODSEntry.ID), + Ino: getInodeIDFromEntryID(entry.IRODSEntry.ID), Mode: entryType, Name: irodsfs_common_utils.GetFileName(entry.Path), } - dirEntries[idx] = dirEntry + dirEntries[idx+2] = dirEntry } else { logger.Errorf("unknown VPath Entry type : %s", entry.Type) return nil, syscall.EREMOTEIO @@ -785,28 +803,39 @@ func (dir *Dir) Readdir(ctx context.Context) (fusefs.DirStream, syscall.Errno) { return nil, syscall.EREMOTEIO } - dirEntries := make([]fuse.DirEntry, len(irodsEntries)) + dirEntries := make([]fuse.DirEntry, len(irodsEntries)+2) + + dirEntries[0] = fuse.DirEntry{ + Ino: 0, + Mode: uint32(fuse.S_IFDIR), + Name: ".", + } + dirEntries[1] = fuse.DirEntry{ + Ino: 0, + Mode: uint32(fuse.S_IFDIR), + Name: "..", + } for idx, irodsEntry := range irodsEntries { entryType := uint32(fuse.S_IFREG) switch irodsEntry.Type { case irodsclient_fs.FileEntry: - entryType = fuse.S_IFREG + entryType = uint32(fuse.S_IFREG) case irodsclient_fs.DirectoryEntry: - entryType = fuse.S_IFDIR + entryType = uint32(fuse.S_IFDIR) default: logger.Errorf("unknown entry type - %s", irodsEntry.Type) return nil, syscall.EREMOTEIO } dirEntry := fuse.DirEntry{ - Ino: uint64(irodsEntry.ID), + Ino: getInodeIDFromEntryID(irodsEntry.ID), Mode: entryType, Name: irodsEntry.Name, } - dirEntries[idx] = dirEntry + dirEntries[idx+2] = dirEntry } return fusefs.NewListDirStream(dirEntries), fusefs.OK diff --git a/irodsfs/file.go b/irodsfs/file.go index d507c39..399dfaf 100644 --- a/irodsfs/file.go +++ b/irodsfs/file.go @@ -40,7 +40,7 @@ func NewFile(fs *IRODSFS, entryID int64, path string) *File { func (file *File) getStableAttr() fusefs.StableAttr { return fusefs.StableAttr{ Mode: fuse.S_IFREG, - Ino: uint64(file.entryID), + Ino: getInodeIDFromEntryID(file.entryID), Gen: 0, } } diff --git a/irodsfs/inode.go b/irodsfs/inode.go new file mode 100644 index 0000000..b54631e --- /dev/null +++ b/irodsfs/inode.go @@ -0,0 +1,12 @@ +package irodsfs + +import "github.com/cyverse/irodsfs/utils" + +func getInodeIDFromEntryID(id int64) uint64 { + if id < 0 { + // virtual + return uint64(utils.MaxInt) + uint64(-1*id) + } + + return uint64(id) +} diff --git a/utils/number.go b/utils/number.go new file mode 100644 index 0000000..b06fc05 --- /dev/null +++ b/utils/number.go @@ -0,0 +1,8 @@ +package utils + +const ( + MaxUint = ^uint(0) + MinUint = 0 + MaxInt = int(MaxUint >> 1) + MinInt = -MaxInt - 1 +)