-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[freebsd] add support for the FreeBSD >= 13 namecache #180
Conversation
The nc_hash field changed from a doubly linked list to a singly linked list in commit 2b86f9d6d013a9ad8b1f8d03286018e785d5b3f6.
@emaste can you look at and validate this change, please? |
@@ -545,7 +545,11 @@ struct namecache { | |||
# else | |||
LIST_ENTRY(namecache) nc_src; /* source vnode list */ | |||
TAILQ_ENTRY(namecache) nc_dst; /* destination vnode list */ | |||
# if __FreeBSD_version >= 1300000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1300105
is the __FreeBSD_version
bump after 2b86f9d6d013a9ad8b1f8d03286018e785d5b3f6.
Thank you. I am now thinking this is the wrong approach, and we should drop use of the namecache entirely, especially on newer FreeBSD versions. Even with this patch, msdosfs gives incomplete "/mountpoint/ -- /filename" paths, and zfs still doesn't work. cd9660 was broken since FreeBSD 6. And it keep going through ABI breaking changes. Using the namecache is too fragile, and simply unmaintainable. On the other hand, a 16 line patch to |
@DamjanJovanovic sounds good. Let's see how your investigation goes. |
Indeed this is the best approach and (something like this) has been discussed in the past as the path forward for lsof. I hadn't looked into details before though, it's great that the patch seems like it will be straightforward. |
In my freebsd-nokvm branch, so far, lsof can:
The flow of control through lsof is pretty simple. Execution starts in How were my changes made? On FreeBSD >= 7:
There is now thousands of lines of vnode-specific code to convert from using kernel data to using kinfo_file and the like. So far I've managed to eliminate kvm and namecache access from the core of lsof, but kvm usage may be much harder to eliminate completely. It is used for reporting on all kinds of things, eg. file locks, which seems unavailable through other APIs. So it may have to continue existing and be used in certain cases, possibly with degraded functionality when it's unavailable. |
Excellent. FreeBSD 6.x was EOL as of November 30, 2010, so we could remove the compatibility code in the near future as well.
If we can make a list of the information that lsof typically reports that is not available from a proper API these can be added to the kernel. |
For starters:
|
So I've gotten quite far now. All vnodes, pipes, fifos, unix sockets, even some new things like pts, work. Can search by filename etc. Still need to do kqueue, TCP/UDP sockets, pipe's "buffer_size" / "in" / "out" fields (a kernel patch is easy), byte range locks, KF_FD_TYPE_CTTY, and a few other details. Then I'll clean up and prepare a nice patch set with incremental changes that can be reviewed and merged. I'll be dropping support for legacy FreeBSD versions after all: they're already very broken anyway, eg. procfs only works on FreeBSD < 5, dev/rdev values seem wrong on FreeBSD 13 and change endlessly between versions, namecache doesn't fully work even with the patch here. Also kvm will continue to be used, for cases where there's no other way, but it will be optional and lsof will do what it can without it. |
Sounds very cool. |
I've now finished and submitted those changes as a new pull request: Closing this one. Thank you. |
The nc_hash field changed from a doubly linked list
to a singly linked list in commit 2b86f9d6d013a9ad8b1f8d03286018e785d5b3f6.