mirror of
https://github.com/hanzoai/s3.git
synced 2026-10-30 14:59:09 +00:00
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.
- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
"Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
(replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
keep their upstream import paths with zero churn. Internal identifiers and
import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
help/usage/flag strings, shell autocomplete program name, and the product name
in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
(e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
`cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
updated to ignore the `s3` build output.
113 lines
2.6 KiB
Go
113 lines
2.6 KiB
Go
package mount
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
)
|
|
|
|
type FileHandleToInode struct {
|
|
sync.RWMutex
|
|
inode2fh map[uint64]*FileHandle
|
|
fh2inode map[FileHandleId]uint64
|
|
}
|
|
|
|
func NewFileHandleToInode() *FileHandleToInode {
|
|
return &FileHandleToInode{
|
|
inode2fh: make(map[uint64]*FileHandle),
|
|
fh2inode: make(map[FileHandleId]uint64),
|
|
}
|
|
}
|
|
|
|
func (i *FileHandleToInode) GetFileHandle(fh FileHandleId) *FileHandle {
|
|
i.RLock()
|
|
defer i.RUnlock()
|
|
inode, found := i.fh2inode[fh]
|
|
if found {
|
|
return i.inode2fh[inode]
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (i *FileHandleToInode) FindFileHandle(inode uint64) (fh *FileHandle, found bool) {
|
|
i.RLock()
|
|
defer i.RUnlock()
|
|
fh, found = i.inode2fh[inode]
|
|
return
|
|
}
|
|
|
|
// MarkInodeRenamed sets isRenamed on any file handle associated with the
|
|
// given inode. This prevents the async flush from recreating a renamed
|
|
// file's metadata under its old path.
|
|
func (i *FileHandleToInode) MarkInodeRenamed(inode uint64) {
|
|
i.RLock()
|
|
defer i.RUnlock()
|
|
if fh, ok := i.inode2fh[inode]; ok {
|
|
fh.isRenamed = true
|
|
}
|
|
}
|
|
|
|
func (i *FileHandleToInode) AcquireFileHandle(wfs *WFS, inode uint64, entry *filer_pb.Entry) *FileHandle {
|
|
i.Lock()
|
|
defer i.Unlock()
|
|
fh, found := i.inode2fh[inode]
|
|
if !found {
|
|
fh = newFileHandle(wfs, FileHandleId(util.RandomUint64()), inode, entry)
|
|
i.inode2fh[inode] = fh
|
|
i.fh2inode[fh.fh] = inode
|
|
} else {
|
|
fh.counter++
|
|
}
|
|
if fh.GetEntry().GetEntry() != entry {
|
|
fh.SetEntry(entry)
|
|
}
|
|
return fh
|
|
}
|
|
|
|
func (i *FileHandleToInode) ReleaseByHandle(fh FileHandleId) *FileHandle {
|
|
i.Lock()
|
|
defer i.Unlock()
|
|
|
|
inode, found := i.fh2inode[fh]
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
fhHandle, fhFound := i.inode2fh[inode]
|
|
if !fhFound {
|
|
delete(i.fh2inode, fh)
|
|
return nil
|
|
}
|
|
|
|
// If the counter is already <= 0, a prior Release already started the
|
|
// drain. Return nil to prevent double-processing.
|
|
if fhHandle.counter <= 0 {
|
|
return nil
|
|
}
|
|
|
|
fhHandle.counter--
|
|
if fhHandle.counter <= 0 {
|
|
if fhHandle.asyncFlushPending {
|
|
// Handle stays in fhMap so rename/unlink can still find it
|
|
// via FindFileHandle during the background drain.
|
|
return fhHandle
|
|
}
|
|
delete(i.inode2fh, inode)
|
|
delete(i.fh2inode, fhHandle.fh)
|
|
return fhHandle
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemoveFileHandle removes a handle from both maps. Called after an async
|
|
// drain completes to clean up the handle that was intentionally kept in the
|
|
// maps during the flush.
|
|
func (i *FileHandleToInode) RemoveFileHandle(fh FileHandleId, inode uint64) {
|
|
i.Lock()
|
|
defer i.Unlock()
|
|
delete(i.inode2fh, inode)
|
|
delete(i.fh2inode, fh)
|
|
}
|