Page MenuHomeFreeBSD

linux(4): Add a dedicated statat() implementation
ClosedPublic

Authored by dchagin on Jun 13 2022, 6:26 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 10 2024, 5:55 PM
Unknown Object (File)
Jan 26 2024, 7:30 PM
Unknown Object (File)
Jan 26 2024, 7:30 PM
Unknown Object (File)
Dec 20 2023, 5:20 AM
Unknown Object (File)
Dec 19 2023, 10:12 AM
Unknown Object (File)
Dec 12 2023, 11:26 PM
Unknown Object (File)
Nov 29 2023, 8:55 PM
Unknown Object (File)
Nov 29 2023, 9:33 AM

Details

Summary

Get rid of calling Linux stat translation hook and specific to Linux
handling of non-node dirfd from kern_statat.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Jun 13 2022, 7:12 PM

Thnak you, but it looks like I was a little hasty, there are still a few problems here.

  1. Conversion of st_rdev , which is not hard to do without this hook.
  2. Conversion of st_dev. The point is that the standard file descriptors are not reopened for emulated process at exec or at chroot time (jails?) and they points to the devfs mounted to the /dev instead of /path/to/chroot/dev or compat.linux.emul_path/dev.

So st_dev (filled from f_fsid) returned by fstat() and stat() are differs.

I'm stiil ponders how to fix that.

unfortunatelly it is not possible to convert native struct stat
without a hook, propose to replace it by sysent method

This revision now requires review to proceed.Apr 19 2023, 12:01 PM

Given the translate_vnhook_major_minor problem looks like what you really want is a dedicated Linux stat func.

This patch is just a bunch of churn which improves one bit (fewer args) at the expense of more memory accesses, which is questionable at best.

In D35474#903481, @mjg wrote:

Given the translate_vnhook_major_minor problem looks like what you really want is a dedicated Linux stat func.

This patch is just a bunch of churn which improves one bit (fewer args) at the expense of more memory accesses, which is questionable at best.

Hmm, usually we try to avoid of dedicated linux implementation, however I fully agree with you here. @kib, what are you think? Leave kern_statat() as is (with seven arguments), replace by sysent hook or replace by dedicated linuxulator method?

The more I look at it the more I'm confident this is the wrong way of going about it.

int
linux_driver_get_major_minor(const char *node, int *major, int *minor)
{
[snip]
        sz = sizeof("pts/") - 1;
        if (strncmp(node, "pts/", sz) == 0 && node[sz] != '\0') {

and others of the sort.

I think devfs should have dedicated handlers for these to fill it up as needed, even possibly with a sysent func like sv_devfs_stat. Then by the time the buffer leaves VOP_STAT it is all sorted out.

In D35474#903700, @mjg wrote:

The more I look at it the more I'm confident this is the wrong way of going about it.

int
linux_driver_get_major_minor(const char *node, int *major, int *minor)
{
[snip]
        sz = sizeof("pts/") - 1;
        if (strncmp(node, "pts/", sz) == 0 && node[sz] != '\0') {

and others of the sort.

I think devfs should have dedicated handlers for these to fill it up as needed, even possibly with a sysent func like sv_devfs_stat. Then by the time the buffer leaves VOP_STAT it is all sorted out.

Yeah, you are right, adding hook to devfs_getattr() solves all of current conversion problems. Till 14.0 I want to fix this crap ))

Block and character special nodes can exist on non-devfs type fs, and block nodes cannot exist on devfs. Moving the hook into devfs vop_stat limits the useful functionality.

In D35474#903834, @kib wrote:

Block and character special nodes can exist on non-devfs type fs, and block nodes cannot exist on devfs. Moving the hook into devfs vop_stat limits the useful functionality.

indeed, thanks

Dedicated,
note that I have yet another linuxism for statat,
fd = open();
fstatat(fd, "", &st, 0) return ENOENT in Linux

dchagin retitled this revision from Get rid of Linux dev translation hook to kern_statat to linux(4): Add a dedicated statat() implementation.Apr 22 2023, 7:12 PM
dchagin edited the summary of this revision. (Show Details)
dchagin edited reviewers, added: Linux Emulation; removed: manu.
sys/compat/linux/linux_stats.c
69

Is flag in FreeBSD flags namespace, or does it contain Linux AT_ flags?

sys/compat/linux/linux_stats.c
69

flag is converted to the FreeBSD namespace by callers, I'd prefer to leave linux_kern_statat() close to the FreeBSD

kib added inline comments.
sys/compat/freebsd32/freebsd32_misc.c
2287

If the line fits, I suggest unwrap this and most of the other kern_statat() instances.

This revision is now accepted and ready to land.Apr 22 2023, 10:58 PM

last call to get this in

sys/kern/vfs_syscalls.c
2445

why is this bit disappearing?

sys/kern/vfs_syscalls.c
2445

this is specific to Linux handling of non-vnode fd, added by 9446d9e88,
and broken by 628c3b30