Page MenuHomeFreeBSD

Implement AT_RENAME_EXCHANGE flag for VFS and tmpfs
Needs ReviewPublic

Authored by kib on Fri, Jun 19, 9:23 AM.
Tags
None
Referenced Files
F161695702: D57658.id180482.diff
Mon, Jul 6, 12:52 AM
Unknown Object (File)
Sun, Jul 5, 2:06 AM
Unknown Object (File)
Sat, Jul 4, 11:29 PM
Unknown Object (File)
Fri, Jul 3, 1:14 PM
Unknown Object (File)
Thu, Jul 2, 3:17 PM
Unknown Object (File)
Thu, Jul 2, 10:34 AM
Unknown Object (File)
Thu, Jul 2, 10:24 AM
Unknown Object (File)
Thu, Jul 2, 8:43 AM

Details

Reviewers
markj
jah

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

kib requested review of this revision.Fri, Jun 19, 9:23 AM

Rumors are that it is not too much work to add ZFS support.

I am sure that UFS is hard due to SU and esp. SU+J. I am adding Kirk in case he is interested.

I promise to handle msdosfs if any of large fs (AKA UFS or ZFS) get the flag.

sys/kern/vfs_syscalls.c
3789โ€“3792

The Linux man pages I looked at seem to indicate EINVAL should be returned if both NOREPLACE and EXCHANGE are set, since they're mutually exclusive. Do we need to be concerned about that level of compatibility? The below check that returns EEXIST will still avoid modifying the target file in that case.

sys/kern/vfs_syscalls.c
3789โ€“3792

It's probably worth mirroring the Linux behaviour here.

kib marked 2 inline comments as done.

The sys/kern/vfs_syscalls.c and sys/sys/fcntl.h changes LGTM with one small note

sys/sys/fcntl.h
263

Perhaps /* Atomically exchange from and to */

kib marked an inline comment as done.

Add doc comment for AT_RENAME_EXCHANGE

Do we have to do something w/ namecache?

Do we have to do something w/ namecache?

It is up to fs. Yes, there is a missing part for tmpfs when namecache is enabled.

Update namecache on rename exchange for tmpfs.

I've applied the patch to my tree and will give it a try in Halifax next week.
For reference, OpenZFS commit that added Linux support: https://github.com/openzfs/zfs/commit/dbf6108b4df92341eea40d0b41792ac16eabc514

Thanks to Air Canada giving me an unexpected few hours in YYZ I had a chance to try this out. One remaining issue w/ the tmpfs support - missing directory timestamp update.

Update atime/mtime for the directories

I now have a kernel panic from an attempt to swap with source missing, e.g.

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
 
int main(void) {
    close(open("target", O_CREAT | O_WRONLY, 0644));
    renameat2(AT_FDCWD, "does_not_exist", AT_FDCWD, "target", RENAME_EXCHANGE);
}

Handle NULL result from namei(RENAME)

Handle 'option MAC' case for fromnd.
Do not leak fromnd on fvp == NULL.

Does filemon_wrapper_rename() need an update? I guess it should emit two records, one for each direction of the rename, but I'm not sure. cc @sjg @stevek

lib/libsys/rename.2
151

Which error number is returned if the filesystem does not support this? It should be documented.

Are there any command-line utilities in the base system which could make use of this?

sys/fs/tmpfs/tmpfs_vnops.c
984

guarantees

sys/kern/vfs_syscalls.c
3816

Do we need to set WILLBEDIR in the other direction?

kib marked 3 inline comments as done.Wed, Jun 24, 3:43 PM

Does filemon_wrapper_rename() need an update? I guess it should emit two records, one for each direction of the rename, but I'm not sure. cc @sjg @stevek

This thing does not even wrap renameat(2), neither it wraps renameat2(2).

Are there any command-line utilities in the base system which could make use of this?

Might be, but I do not have an example that I can thought of.

lib/libsys/rename.2
151

It is already documented below, in the renameat2() error section. It was done when renameat2() was added.

kib marked an inline comment as done.

Set WILLBEDIR for fromnd of tvp is VDIR.

In D57658#1325551, @kib wrote:

Set WILLBEDIR for fromnd of tvp is VDIR.

As a note, I think that WILLBEDIR is not too critical there. It basically allows to have slash after the file name to not choke the namei() parser. VWRITE vs. VWRITE | VACCESS seems to be irrelevant at all because we overwrite the same dirent.

This cannot be implemented in UFS since a requirement of its consistency model is that the on-disk image is always consistent. If the directory entries being swapped are in two different disk blocks, then there is no order of writing that will have a consistent filesystem. The only way to ensure consistency is to have a journal that can correct the unwritten directory name with its updated inode number.

This cannot be implemented in UFS since a requirement of its consistency model is that the on-disk image is always consistent. If the directory entries being swapped are in two different disk blocks, then there is no order of writing that will have a consistent filesystem. The only way to ensure consistency is to have a journal that can correct the unwritten directory name with its updated inode number.

In other words, it cannot be implemented for SU, but can for async and for SU+J, do you agree?

In D57658#1331128, @kib wrote:

This cannot be implemented in UFS since a requirement of its consistency model is that the on-disk image is always consistent. If the directory entries being swapped are in two different disk blocks, then there is no order of writing that will have a consistent filesystem. The only way to ensure consistency is to have a journal that can correct the unwritten directory name with its updated inode number.

In other words, it cannot be implemented for SU, but can for async and for SU+J, do you agree?

SUJ only journals things that SU is tracking. It is not a general journalling mechanism. So, if SU cannot do it, then SUJ cannot do it either. Since async makes no promises about consistency, it could implement anything it wants. But I would be loath to say that you have to run async in order to get a certain feature as I would not want to encourage use of async. My attitude is that UFS reliability has been a hallmark of its existence and I do not want to introduce a feature that removes its reliability. Especially a feature which is of such little use.