mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
mount: refuse RENAME_EXCHANGE instead of renaming over the target (#12921)
* mount: refuse RENAME_EXCHANGE instead of renaming over the target renameat2(a, b, RENAME_EXCHANGE) asks for the two names to be swapped atomically. Rename let the flag through and went on as a plain rename, so a was moved over b, b's content was gone, and the call reported success. The filer's rename moves one entry and cannot swap two, so the mount now answers EINVAL, which is what renameat2(2) returns for a flag the file system does not support, and callers fall back on it. RenameWhiteout was 3, which is RENAME_NOREPLACE|RENAME_EXCHANGE; the flag is 1<<2. Both values, and any other flag the mount does not implement, now get the same EINVAL (3 answered ENOTSUP, 4 already EINVAL). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * mount: trim the rename flag comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: MapleWhiteZZZ <18653045+MapleWhiteZZZ@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
This commit is contained in:
2 files changed
+46
-6
No files matched your search
@@ -192,9 +192,9 @@ renameat2()
|
||||
*/
|
||||
const (
|
||||
RenameEmptyFlag = 0
|
||||
RenameNoReplace = 1
|
||||
RenameExchange = 2
|
||||
RenameWhiteout = 3
|
||||
RenameNoReplace = 1 << 0
|
||||
RenameExchange = 1 << 1
|
||||
RenameWhiteout = 1 << 2
|
||||
)
|
||||
|
||||
func (wfs *WFS) Rename(cancel <-chan struct{}, in *fuse.RenameIn, oldName string, newName string) (code fuse.Status) {
|
||||
@@ -210,12 +210,10 @@ func (wfs *WFS) Rename(cancel <-chan struct{}, in *fuse.RenameIn, oldName string
|
||||
return s
|
||||
}
|
||||
|
||||
// The filer moves one entry: it can neither swap two nor leave a whiteout.
|
||||
switch in.Flags {
|
||||
case RenameEmptyFlag:
|
||||
case RenameNoReplace:
|
||||
case RenameExchange:
|
||||
case RenameWhiteout:
|
||||
return fuse.ENOTSUP
|
||||
default:
|
||||
return fuse.EINVAL
|
||||
}
|
||||
|
||||
@@ -190,6 +190,48 @@ func renameFile(wfs *WFS, oldDirInode, newDirInode uint64, oldName, newName stri
|
||||
}, oldName, newName)
|
||||
}
|
||||
|
||||
// An unsupported flag must not fall through to a plain rename over the target.
|
||||
func TestRenameRefusesFlagsItDoesNotImplement(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
flags uint32
|
||||
}{
|
||||
{"exchange", RenameExchange},
|
||||
{"whiteout", RenameWhiteout},
|
||||
{"noreplace-and-exchange", RenameNoReplace | RenameExchange},
|
||||
{"unknown", 1 << 5},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
wfs, fake, dirInode, _ := newRenameRaceWFS(t)
|
||||
file := func(name string, inode uint64) *filer_pb.Entry {
|
||||
return &filer_pb.Entry{
|
||||
Name: name,
|
||||
Attributes: &filer_pb.FuseAttributes{FileMode: 0o644, Uid: 123, Gid: 456, Mtime: 1, Crtime: 1, Inode: inode},
|
||||
}
|
||||
}
|
||||
fake.mu.Lock()
|
||||
fake.entries["/checkpoints/a"] = file("a", 11)
|
||||
fake.entries["/checkpoints/b"] = file("b", 22)
|
||||
fake.mu.Unlock()
|
||||
|
||||
code := wfs.Rename(make(chan struct{}), &fuse.RenameIn{
|
||||
InHeader: fuse.InHeader{NodeId: dirInode, Caller: fuse.Caller{Owner: fuse.Owner{Uid: 123, Gid: 456}}},
|
||||
Newdir: dirInode,
|
||||
Flags: tc.flags,
|
||||
}, "a", "b")
|
||||
if code != fuse.EINVAL {
|
||||
t.Fatalf("rename with flags %#x: %v, want EINVAL", tc.flags, code)
|
||||
}
|
||||
fake.mu.Lock()
|
||||
defer fake.mu.Unlock()
|
||||
a, b := fake.entries["/checkpoints/a"], fake.entries["/checkpoints/b"]
|
||||
if a.GetAttributes().GetInode() != 11 || b.GetAttributes().GetInode() != 22 {
|
||||
t.Fatalf("after the refused rename a=%v b=%v, want both where they were", a, b)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func waitFor(t *testing.T, what string, ch chan struct{}) {
|
||||
t.Helper()
|
||||
select {
|
||||
|
||||
Reference in new issue
Block a user