Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
554 lines
20 KiB
Go
554 lines
20 KiB
Go
package mount
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/go-fuse/v2/fuse"
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/cluster/lock_manager"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
/**
|
|
* Create and open a file
|
|
*
|
|
* If the file does not exist, first create it with the specified
|
|
* mode, and then open it.
|
|
*
|
|
* If this method is not implemented or under Linux kernel
|
|
* versions earlier than 2.6.15, the mknod() and open() methods
|
|
* will be called instead.
|
|
*/
|
|
func (wfs *WFS) Create(cancel <-chan struct{}, in *fuse.CreateIn, name string, out *fuse.CreateOut) (code fuse.Status) {
|
|
var s fuse.Status
|
|
if name, s = checkName(name); s != fuse.OK {
|
|
return s
|
|
}
|
|
|
|
dirFullPath, code := wfs.inodeToPath.GetPath(in.NodeId)
|
|
if code != fuse.OK {
|
|
return code
|
|
}
|
|
|
|
entryFullPath := dirFullPath.Child(name)
|
|
var inode uint64
|
|
|
|
newEntry, _, code := wfs.maybeLoadEntry(entryFullPath)
|
|
if code == fuse.OK {
|
|
if newEntry == nil || newEntry.Attributes == nil {
|
|
return fuse.EIO
|
|
}
|
|
if in.Flags&syscall.O_EXCL != 0 {
|
|
glog.V(0).Infof("Create O_EXCL %s: already exists (uid=%d gid=%d mode=%o)",
|
|
entryFullPath, newEntry.Attributes.Uid, newEntry.Attributes.Gid, newEntry.Attributes.FileMode)
|
|
return fuse.Status(syscall.EEXIST)
|
|
}
|
|
inode = wfs.inodeToPath.Lookup(entryFullPath, newEntry.Attributes.Crtime, false, len(newEntry.HardLinkId) > 0, newEntry.Attributes.Inode, true)
|
|
fileHandle, status := wfs.AcquireHandle(inode, in.Flags, in.Uid, in.Gid)
|
|
if status != fuse.OK {
|
|
return status
|
|
}
|
|
if in.Flags&syscall.O_TRUNC != 0 && in.Flags&fuse.O_ANYWRITE != 0 {
|
|
if code = wfs.truncateEntry(entryFullPath, newEntry); code != fuse.OK {
|
|
wfs.ReleaseHandle(fileHandle.fh)
|
|
return code
|
|
}
|
|
newEntry = fileHandle.GetEntry().GetEntry()
|
|
}
|
|
|
|
wfs.outputPbEntry(&out.EntryOut, inode, newEntry)
|
|
out.Fh = uint64(fileHandle.fh)
|
|
out.OpenFlags = 0
|
|
return fuse.OK
|
|
}
|
|
if code != fuse.ENOENT {
|
|
return code
|
|
}
|
|
|
|
inode, newEntry, code = wfs.createRegularFile(dirFullPath, name, in.Mode, in.Uid, in.Gid, 0, !wfs.option.EagerFilerCreate, true)
|
|
if code == fuse.Status(syscall.EEXIST) && in.Flags&syscall.O_EXCL == 0 {
|
|
// Race: another process created the file between our check and create.
|
|
// Reopen the winner's entry.
|
|
newEntry, _, code = wfs.maybeLoadEntry(entryFullPath)
|
|
if code != fuse.OK {
|
|
return code
|
|
}
|
|
if newEntry == nil || newEntry.Attributes == nil {
|
|
return fuse.EIO
|
|
}
|
|
inode = wfs.inodeToPath.Lookup(entryFullPath, newEntry.Attributes.Crtime, false, len(newEntry.HardLinkId) > 0, newEntry.Attributes.Inode, true)
|
|
fileHandle, status := wfs.AcquireHandle(inode, in.Flags, in.Uid, in.Gid)
|
|
if status != fuse.OK {
|
|
return status
|
|
}
|
|
if in.Flags&syscall.O_TRUNC != 0 && in.Flags&fuse.O_ANYWRITE != 0 {
|
|
if code = wfs.truncateEntry(entryFullPath, newEntry); code != fuse.OK {
|
|
wfs.ReleaseHandle(fileHandle.fh)
|
|
return code
|
|
}
|
|
newEntry = fileHandle.GetEntry().GetEntry()
|
|
}
|
|
wfs.outputPbEntry(&out.EntryOut, inode, newEntry)
|
|
out.Fh = uint64(fileHandle.fh)
|
|
out.OpenFlags = 0
|
|
return fuse.OK
|
|
} else if code != fuse.OK {
|
|
return code
|
|
} else {
|
|
inode = wfs.inodeToPath.Lookup(entryFullPath, newEntry.Attributes.Crtime, false, false, inode, true)
|
|
}
|
|
|
|
wfs.outputPbEntry(&out.EntryOut, inode, newEntry)
|
|
|
|
// For deferred creates, bypass AcquireHandle (which calls maybeReadEntry
|
|
// and would fail since the entry is not yet on the filer or in the meta cache).
|
|
// We already have the entry from createRegularFile, so create the handle directly.
|
|
fileHandle, existed := wfs.fhMap.AcquireFileHandle(wfs, inode, newEntry, 0, 0)
|
|
if existed {
|
|
// A create is authoritative for the entry it just made, so it takes
|
|
// effect even on a handle that outlived a previous incarnation.
|
|
fileHandle.SetEntry(newEntry)
|
|
}
|
|
fileHandle.RememberPath(entryFullPath)
|
|
// Mark dirty so the deferred filer create happens on Flush, even if the
|
|
// file is closed without any writes. An eager create has already
|
|
// persisted the entry, so its handle starts clean.
|
|
fileHandle.dirtyMetadata = !wfs.option.EagerFilerCreate
|
|
|
|
// Acquire DLM lock for new file creation (Create bypasses AcquireHandle
|
|
// so we must acquire the lock here). Always lock on Create since file
|
|
// creation is inherently a write operation.
|
|
if wfs.lockClient != nil && fileHandle.dlmLock == nil {
|
|
owner := fmt.Sprintf("mount-%d", wfs.signature)
|
|
fileHandle.dlmLock = wfs.lockClient.NewBlockingLongLivedLock(
|
|
string(entryFullPath), owner, lock_manager.LiveLockTTL,
|
|
)
|
|
glog.V(1).Infof("DLM lock acquired for new file %s", entryFullPath)
|
|
}
|
|
|
|
out.Fh = uint64(fileHandle.fh)
|
|
out.OpenFlags = 0
|
|
|
|
return fuse.OK
|
|
}
|
|
|
|
/** Create a file node
|
|
*
|
|
* This is called for creation of all non-directory, non-symlink
|
|
* nodes. If the filesystem defines a create() method, then for
|
|
* regular files that will be called instead.
|
|
*/
|
|
func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out *fuse.EntryOut) (code fuse.Status) {
|
|
|
|
var s fuse.Status
|
|
if name, s = checkName(name); s != fuse.OK {
|
|
return s
|
|
}
|
|
|
|
dirFullPath, code := wfs.inodeToPath.GetPath(in.NodeId)
|
|
if code != fuse.OK {
|
|
return
|
|
}
|
|
|
|
inode, newEntry, code := wfs.createRegularFile(dirFullPath, name, in.Mode, in.Uid, in.Gid, in.Rdev, false, false)
|
|
if code != fuse.OK {
|
|
return code
|
|
}
|
|
|
|
// this is to increase nlookup counter
|
|
entryFullPath := dirFullPath.Child(name)
|
|
inode = wfs.inodeToPath.Lookup(entryFullPath, newEntry.Attributes.Crtime, false, false, inode, true)
|
|
|
|
wfs.outputPbEntry(out, inode, newEntry)
|
|
|
|
return fuse.OK
|
|
|
|
}
|
|
|
|
/** Remove a file */
|
|
func (wfs *WFS) Unlink(cancel <-chan struct{}, header *fuse.InHeader, name string) (code fuse.Status) {
|
|
|
|
// Sanitize before it reaches DeleteEntryRequest.Name; see sanitizeFuseName.
|
|
name = sanitizeFuseName(name)
|
|
|
|
dirFullPath, code := wfs.inodeToPath.GetPath(header.NodeId)
|
|
if code != fuse.OK {
|
|
if code == fuse.ENOENT {
|
|
return fuse.OK
|
|
}
|
|
return code
|
|
}
|
|
entryFullPath := dirFullPath.Child(name)
|
|
|
|
entry, _, code := wfs.maybeLoadEntry(entryFullPath)
|
|
if code != fuse.OK {
|
|
if code == fuse.ENOENT {
|
|
return fuse.OK
|
|
}
|
|
return code
|
|
}
|
|
|
|
if wormEnforced, _ := wfs.wormEnforcedForEntry(entryFullPath, entry); wormEnforced {
|
|
return fuse.EPERM
|
|
}
|
|
|
|
// For hard-linked files, serialize all concurrent mutations on the
|
|
// same HardLinkId so the filer-side blob decrement and the mount-side
|
|
// sibling cache sync are observed atomically by other unlinkers.
|
|
// Without this, two concurrent unlinks on different links of the same
|
|
// file both read the same pre-decrement counter and both stamp their
|
|
// siblings to counter-1, leaving the cache one higher than the blob.
|
|
// Re-load the entry under the lock so we see any sibling update a
|
|
// prior holder just applied.
|
|
if entry != nil && len(entry.HardLinkId) > 0 {
|
|
hlKey := string(entry.HardLinkId)
|
|
lock := wfs.hardLinkLockTable.AcquireLock("unlink", hlKey, util.ExclusiveLock)
|
|
defer wfs.hardLinkLockTable.ReleaseLock(hlKey, lock)
|
|
// If another thread unlinked the entry while we waited for the
|
|
// lock, the file is already gone — return OK like the initial
|
|
// maybeLoadEntry path above. Do not fall back to the stale
|
|
// pre-lock snapshot: proceeding with its HardLinkCounter would
|
|
// reintroduce the stale-base update the lock is meant to prevent.
|
|
fresh, _, freshCode := wfs.maybeLoadEntry(entryFullPath)
|
|
if freshCode == fuse.ENOENT {
|
|
return fuse.OK
|
|
}
|
|
if freshCode != fuse.OK {
|
|
return freshCode
|
|
}
|
|
entry = fresh
|
|
}
|
|
|
|
// POSIX: enforce sticky bit on the parent directory.
|
|
if dirEntry, _, dirCode := wfs.maybeLoadEntry(dirFullPath); dirCode == fuse.OK && dirEntry != nil && dirEntry.Attributes != nil {
|
|
targetUid := uint32(0)
|
|
if entry != nil && entry.Attributes != nil {
|
|
targetUid = entry.Attributes.Uid
|
|
}
|
|
if code := checkStickyBit(dirEntry.Attributes.FileMode, dirEntry.Attributes.Uid, targetUid, header.Uid); code != fuse.OK {
|
|
return code
|
|
}
|
|
}
|
|
|
|
// Before deleting from the filer, mark any draining async-flush handle
|
|
// as deleted and wait for it to complete. Without this, the async flush
|
|
// can race with the filer delete and recreate the just-unlinked entry
|
|
// (the worker checks isDeleted, but it may have already passed that check
|
|
// before Unlink sets the flag). By waiting here, any in-flight flush
|
|
// finishes first; even if it recreated the entry, the filer delete below
|
|
// will remove it again.
|
|
if inode, found := wfs.inodeToPath.GetInode(entryFullPath); found {
|
|
wfs.markHandleDeleted(inode)
|
|
wfs.waitForPendingAsyncFlush(inode)
|
|
} else if entry != nil && entry.Attributes != nil && entry.Attributes.Inode != 0 {
|
|
inodeFromEntry := entry.Attributes.Inode
|
|
wfs.markHandleDeleted(inodeFromEntry)
|
|
wfs.waitForPendingAsyncFlush(inodeFromEntry)
|
|
}
|
|
|
|
// first, ensure the filer store can correctly delete
|
|
glog.V(3).Infof("remove file: %v", entryFullPath)
|
|
// Always let the filer decide whether to delete chunks based on its authoritative data.
|
|
// The filer has the correct hard link count and will only delete chunks when appropriate.
|
|
deleteReq := &filer_pb.DeleteEntryRequest{
|
|
// See weedfs_dir_mkrm.go Mkdir for why Directory is sanitized.
|
|
Directory: dirFullPath.Sanitized(),
|
|
Name: name,
|
|
IsDeleteData: true,
|
|
Signatures: []int32{wfs.signature},
|
|
}
|
|
resp, err := wfs.streamDeleteEntry(context.Background(), deleteReq)
|
|
if err != nil {
|
|
glog.V(0).Infof("remove %s: %v", entryFullPath, err)
|
|
return fuse.OK
|
|
}
|
|
|
|
var event *filer_pb.SubscribeMetadataResponse
|
|
if resp != nil && resp.MetadataEvent != nil {
|
|
event = resp.MetadataEvent
|
|
} else {
|
|
event = metadataDeleteEvent(string(dirFullPath), name, false)
|
|
}
|
|
if applyErr := wfs.applyLocalMetadataEvent(context.Background(), event); applyErr != nil {
|
|
glog.Warningf("unlink %s: best-effort metadata apply failed: %v", entryFullPath, applyErr)
|
|
wfs.inodeToPath.InvalidateChildrenCache(dirFullPath)
|
|
}
|
|
wfs.inodeToPath.TouchDirectory(dirFullPath)
|
|
wfs.touchDirMtimeCtimeBest(dirFullPath)
|
|
|
|
// For hard-linked files, the filer's DeleteHardLink decremented the
|
|
// shared blob, but the sibling link entries in the local metacache
|
|
// still carry the pre-unlink HardLinkCounter, and the kernel has
|
|
// cached attrs on the shared inode. Resolve the shared inode before
|
|
// removing the path from inodeToPath, then propagate the decrement
|
|
// to every sibling cache entry and invalidate the kernel attr cache
|
|
// so subsequent lstats on other links see the new nlink — pjdfstest
|
|
// link/00.t asserts this after `unlink n0` leaves n1/n2 behind.
|
|
isHardLink := entry != nil && entry.Attributes != nil && len(entry.HardLinkId) > 0 && entry.HardLinkCounter > 1
|
|
var sharedInode uint64
|
|
if isHardLink {
|
|
sharedInode = entry.Attributes.Inode
|
|
if sharedInode == 0 {
|
|
if resolved, found := wfs.inodeToPath.GetInode(entryFullPath); found {
|
|
sharedInode = resolved
|
|
}
|
|
}
|
|
}
|
|
|
|
wfs.inodeToPath.RemovePath(entryFullPath, nil)
|
|
|
|
if isHardLink && sharedInode != 0 {
|
|
decremented := proto.Clone(entry).(*filer_pb.Entry)
|
|
decremented.HardLinkCounter = entry.HardLinkCounter - 1
|
|
now := time.Now()
|
|
decremented.Attributes.Ctime = now.Unix()
|
|
decremented.Attributes.CtimeNs = int32(now.Nanosecond())
|
|
wfs.syncHardLinkSiblings(sharedInode, decremented, entryFullPath)
|
|
}
|
|
|
|
return fuse.OK
|
|
|
|
}
|
|
|
|
func (wfs *WFS) createRegularFile(dirFullPath util.FullPath, name string, mode uint32, uid, gid, rdev uint32, deferFilerCreate bool, skipExistenceCheck bool) (inode uint64, newEntry *filer_pb.Entry, code fuse.Status) {
|
|
if wfs.IsOverQuotaWithUncommitted() {
|
|
return 0, nil, fuse.Status(syscall.ENOSPC)
|
|
}
|
|
|
|
// Load the parent directory to validate it exists (the create RPC sets
|
|
// SkipCheckParentDirectory, so this is the only parent check). With
|
|
// default_permissions the kernel already verified write+search on it before
|
|
// Create/Mknod, so skip only the mode-bit check and its group lookup.
|
|
parentEntry, _, parentStatus := wfs.maybeLoadEntry(dirFullPath)
|
|
if parentStatus != fuse.OK {
|
|
return 0, nil, parentStatus
|
|
}
|
|
if parentEntry == nil || parentEntry.Attributes == nil {
|
|
return 0, nil, fuse.EIO
|
|
}
|
|
if !wfs.option.DefaultPermissions {
|
|
// Map parent dir uid/gid from filer-space to local-space so the
|
|
// permission check compares like with like (caller uid/gid are local).
|
|
parentUid, parentGid := parentEntry.Attributes.Uid, parentEntry.Attributes.Gid
|
|
if wfs.option.UidGidMapper != nil {
|
|
parentUid, parentGid = wfs.option.UidGidMapper.FilerToLocal(parentUid, parentGid)
|
|
}
|
|
if !hasAccess(uid, gid, parentUid, parentGid, parentEntry.Attributes.FileMode, fuse.W_OK|fuse.X_OK) {
|
|
return 0, nil, fuse.Status(syscall.EACCES)
|
|
}
|
|
}
|
|
|
|
entryFullPath := dirFullPath.Child(name)
|
|
if !skipExistenceCheck {
|
|
if _, _, status := wfs.maybeLoadEntry(entryFullPath); status == fuse.OK {
|
|
return 0, nil, fuse.Status(syscall.EEXIST)
|
|
} else if status != fuse.ENOENT {
|
|
return 0, nil, status
|
|
}
|
|
}
|
|
fileMode := toOsFileMode(mode)
|
|
now := time.Now().Unix()
|
|
inode = wfs.inodeToPath.AllocateInode(entryFullPath, now)
|
|
|
|
newEntry = &filer_pb.Entry{
|
|
Name: name,
|
|
IsDirectory: false,
|
|
Attributes: &filer_pb.FuseAttributes{
|
|
Mtime: now,
|
|
Crtime: now,
|
|
Ctime: now,
|
|
FileMode: uint32(fileMode),
|
|
Uid: uid,
|
|
Gid: gid,
|
|
TtlSec: wfs.option.TtlSec,
|
|
Rdev: rdev,
|
|
Inode: inode,
|
|
},
|
|
}
|
|
|
|
if deferFilerCreate || wfs.option.WritebackCache {
|
|
// Insert a local placeholder into the metadata cache so that
|
|
// maybeLoadEntry() can find the file immediately (e.g., duplicate-
|
|
// create checks, stat, readdir).
|
|
// We use InsertEntry directly instead of applyLocalMetadataEvent to avoid
|
|
// triggering directory hot-threshold eviction that would wipe the entry.
|
|
if insertErr := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(string(dirFullPath), newEntry), 0); insertErr != nil {
|
|
glog.Warningf("createFile %s: insert local entry: %v", entryFullPath, insertErr)
|
|
}
|
|
wfs.inodeToPath.TouchDirectory(dirFullPath)
|
|
wfs.touchDirMtimeCtimeBest(dirFullPath)
|
|
|
|
if deferFilerCreate {
|
|
// Fully deferred: the caller (Create) will build a file handle
|
|
// directly from newEntry. The actual filer entry is created by
|
|
// flushMetadataToFiler on close.
|
|
glog.V(3).Infof("createFile %s: deferred to flush", entryFullPath)
|
|
} else {
|
|
// Async create: Mknod with writeback caching. The node is
|
|
// visible locally; fire the filer RPC in the background.
|
|
wfs.asyncCreateEntry(dirFullPath, newEntry)
|
|
glog.V(3).Infof("createFile %s: async create", entryFullPath)
|
|
}
|
|
return inode, newEntry, fuse.OK
|
|
}
|
|
|
|
wfs.mapPbIdFromLocalToFiler(newEntry)
|
|
defer wfs.mapPbIdFromFilerToLocal(newEntry)
|
|
|
|
request := &filer_pb.CreateEntryRequest{
|
|
Directory: string(dirFullPath),
|
|
Entry: newEntry,
|
|
Signatures: []int32{wfs.signature},
|
|
SkipCheckParentDirectory: true,
|
|
}
|
|
|
|
glog.V(1).Infof("createFile: %v", request)
|
|
resp, err := wfs.streamCreateEntry(context.Background(), request)
|
|
if err != nil {
|
|
glog.V(0).Infof("createFile %s: %v", entryFullPath, err)
|
|
} else {
|
|
event := resp.GetMetadataEvent()
|
|
if event == nil {
|
|
event = metadataCreateEvent(string(dirFullPath), newEntry)
|
|
}
|
|
if applyErr := wfs.applyLocalMetadataEvent(context.Background(), event); applyErr != nil {
|
|
glog.Warningf("createFile %s: best-effort metadata apply failed: %v", entryFullPath, applyErr)
|
|
wfs.inodeToPath.InvalidateChildrenCache(dirFullPath)
|
|
}
|
|
wfs.inodeToPath.TouchDirectory(dirFullPath)
|
|
wfs.touchDirMtimeCtimeBest(dirFullPath)
|
|
}
|
|
|
|
glog.V(3).Infof("createFile %s: %v", entryFullPath, err)
|
|
|
|
if err != nil {
|
|
return 0, nil, grpcErrorToFuseStatus(err)
|
|
}
|
|
|
|
return inode, newEntry, fuse.OK
|
|
}
|
|
|
|
// markHandleDeleted flags the inode's open handle so its flushes stop writing
|
|
// the entry back, and reports which mark this was. Taken and released under
|
|
// the handle's flush lock: a flush already holding it finishes before the
|
|
// caller's delete runs, and any later flush sees the flag; setting the flag
|
|
// bare raced the flush's own check and resurrected the entry right after the
|
|
// delete.
|
|
func (wfs *WFS) markHandleDeleted(inode uint64) uint64 {
|
|
fh, found := wfs.fhMap.FindFileHandle(inode)
|
|
if !found {
|
|
return 0
|
|
}
|
|
fhActiveLock := wfs.fhLockTable.AcquireLock("markHandleDeleted", fh.fh, util.ExclusiveLock)
|
|
fh.isDeleted = true
|
|
fh.deleteEpoch++
|
|
epoch := fh.deleteEpoch
|
|
wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
|
|
return epoch
|
|
}
|
|
|
|
// clearHandleDeleted lifts a mark whose delete did not go through. Only the
|
|
// mark epoch names: an unlink that raised the flag after it owns the entry's
|
|
// fate and keeps it.
|
|
func (wfs *WFS) clearHandleDeleted(inode uint64, epoch uint64) {
|
|
if epoch == 0 {
|
|
return
|
|
}
|
|
fh, found := wfs.fhMap.FindFileHandle(inode)
|
|
if !found {
|
|
return
|
|
}
|
|
fhActiveLock := wfs.fhLockTable.AcquireLock("clearHandleDeleted", fh.fh, util.ExclusiveLock)
|
|
if fh.deleteEpoch == epoch {
|
|
fh.isDeleted = false
|
|
}
|
|
wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
|
|
}
|
|
|
|
// asyncCreateEntry sends a CreateEntry RPC to the filer in the background.
|
|
// The entry is already in the local meta cache; this persists it to the filer.
|
|
// Used by Mknod with writeback caching — the node is visible locally right away.
|
|
//
|
|
// If the filer RPC fails after retries, the local cache entry is removed so the
|
|
// phantom file does not persist across cache invalidation or mount restart.
|
|
func (wfs *WFS) asyncCreateEntry(dirFullPath util.FullPath, entry *filer_pb.Entry) {
|
|
// Clone so the goroutine has its own copy for uid/gid mapping.
|
|
requestEntry := proto.Clone(entry).(*filer_pb.Entry)
|
|
dir := string(dirFullPath)
|
|
entryPath := dirFullPath.Child(entry.Name)
|
|
go func() {
|
|
wfs.mapPbIdFromLocalToFiler(requestEntry)
|
|
request := &filer_pb.CreateEntryRequest{
|
|
Directory: dir,
|
|
Entry: requestEntry,
|
|
Signatures: []int32{wfs.signature},
|
|
SkipCheckParentDirectory: true,
|
|
}
|
|
err := retryMetadataFlush(context.Background(), func() error {
|
|
resp, createErr := wfs.streamCreateEntry(context.Background(), request)
|
|
if createErr != nil {
|
|
return createErr
|
|
}
|
|
event := resp.GetMetadataEvent()
|
|
if event == nil {
|
|
event = metadataCreateEvent(dir, requestEntry)
|
|
}
|
|
if applyErr := wfs.applyLocalMetadataEvent(context.Background(), event); applyErr != nil {
|
|
glog.Warningf("async createFile %s: metadata apply: %v", entryPath, applyErr)
|
|
wfs.inodeToPath.InvalidateChildrenCache(dirFullPath)
|
|
}
|
|
return nil
|
|
}, func(nextAttempt, totalAttempts int, backoff time.Duration, err error) {
|
|
glog.Warningf("async createFile %s: retrying (attempt %d/%d) after %v: %v",
|
|
entryPath, nextAttempt, totalAttempts, backoff, err)
|
|
})
|
|
if err != nil {
|
|
glog.Errorf("async createFile %s: failed after retries: %v — removing local entry", entryPath, err)
|
|
wfs.metaCache.DeleteEntry(context.Background(), entryPath)
|
|
wfs.inodeToPath.InvalidateChildrenCache(dirFullPath)
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (wfs *WFS) truncateEntry(entryFullPath util.FullPath, entry *filer_pb.Entry) fuse.Status {
|
|
if entry == nil {
|
|
return fuse.EIO
|
|
}
|
|
if entry.Attributes == nil {
|
|
entry.Attributes = &filer_pb.FuseAttributes{}
|
|
}
|
|
|
|
entry.Content = nil
|
|
entry.Chunks = nil
|
|
entry.Attributes.FileSize = 0
|
|
truncNow := time.Now()
|
|
entry.Attributes.Mtime = truncNow.Unix()
|
|
entry.Attributes.MtimeNs = int32(truncNow.Nanosecond())
|
|
entry.Attributes.Ctime = truncNow.Unix()
|
|
entry.Attributes.CtimeNs = int32(truncNow.Nanosecond())
|
|
|
|
if code := wfs.saveEntry(entryFullPath, entry); code != fuse.OK {
|
|
return code
|
|
}
|
|
|
|
if inode, found := wfs.inodeToPath.GetInode(entryFullPath); found {
|
|
wfs.invalidateOpenMtimeCache(inode)
|
|
if fh, fhFound := wfs.fhMap.FindFileHandle(inode); fhFound {
|
|
fhActiveLock := fh.wfs.fhLockTable.AcquireLock("truncateEntry", fh.fh, util.ExclusiveLock)
|
|
fh.ResetDirtyPages()
|
|
fh.SetEntry(entry)
|
|
fh.setAuthoritativeBase(proto.Clone(entry).(*filer_pb.Entry))
|
|
fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
|
|
}
|
|
}
|
|
|
|
return fuse.OK
|
|
}
|