Today in POSIX surprises: `ln -f` is not *quite* atomic due to the combined semantics of link() and rename(); it racily uses a temp file and if the stars align might unlink() an identially-named temp file created by another process.
-
-
Replying to @marcan42
I've been repeatedly surprised by the number of colleagues who believe that link(2) and/or symlink(2) will atomically overwrite an existing file, without needing to unlink(2) the target and thus open the attendant race condition.
1 reply 0 retweets 1 like -
Replying to @dlkingauthor
Well you can rename() over the target, and that works perfectly well for symlinks. The problem is that rename() has a stupidly defined corner case where it returns *successfully* and yet *does nothing* when both sides are the same inode. And that opens up another race.
2 replies 1 retweet 6 likes -
Replying to @marcan42 @dlkingauthor
oh, yuck. on modern linux, you could probably work around that by using renameat2() with RENAME_EXCHANGE and then always unlinking the source afterwards?
1 reply 0 retweets 3 likes -
Replying to @tehjh @dlkingauthor
Ah, I was looking for something like that. Yeah, that ought to work. That might actually solve the (unrelated) use case I was trying to solve when investigating this... hmm.
1 reply 0 retweets 1 like -
(I need to atomically exchange two hard links to the same inode or atomically overwrite a hard link with an identical hard link... if that sounds pointless, that's because it is in POSIX terms... but it isn't on CephFS due to an implementation detail!)
1 reply 0 retweets 2 likes -
Replying to @marcan42 @dlkingauthor
nope, vfs_rename() bails out immediately if source==target
1 reply 0 retweets 0 likes
Meh. Wonder if libcephfs does the same check of if it'll fly there. My current best plan is link(src, tmp); symlink(tmp, tmp2); rename(tmp2, src); stat(other_hardlink); rename(tmp, src);. Involves a temporary symlink but should keep src accessible while doing what I want.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.