-
Notifications
You must be signed in to change notification settings - Fork 1.1k
linux: add fanotify(7) API bindings. #1699
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @gnzlbg (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Looks like there's some test failures to sort out 😓 It seems like like none of the I'm less certain what could be at fault with the other jobs and probably need some assistance to make progress there. |
Hey, thanks for the PR! I haven't reviewed deeply yet but I think we should add Lines 2224 to 2229 in 276eaa2
|
@JohnTitor Thanks for the quick pointer! I've applied this suggestion in 501762b. |
@JohnTitor Thanks for the detailed review! I believe I've addressed all of your review feedback and this branch is ready for a second pass when you have a chance. |
Great! Now some targets pass CI. I'll take a look at the log after taking a bath but at a glance:
|
Progress! 🎉 Thanks for your help :-)
After some fiddling I got the |
I noticed all of the tasks that failed with this error seem to be using I tried the first possible solution listed and removed the Re-running the x86_64-unknown-linux-musl target's tests locally showed a different failure at this point:
The When I reverted 42ac577 and f082b99 the target's tests passed locally 🎉 I'll push the relevant commits to this branch and see how a full CI run goes. 🤞 Edit: pushed 7aea581, 3d2f23b and 4938233. Hope I'm on the right track here. It's also possible I've been barking up the wrong tree 😆 |
Seems like this might have been the case. Other targets that were passing before (e.g. |
Thanks!
That's fair but some other targets still complain that, hmm it's odd, I'll investigate. |
It felt odd to me too. I poked at it a little bit more this morning and using |
So, I think we can switch |
Cool, 👍 I implemented that suggestion in 2eab0f8. Almost there! It looks like CI is green across the board now with the exception of two tasks:
Not sure what's up with this one. I'll try to repro locally and see what I can figure out. I can't see any failed tests in the test output on Azure 🤔
I used the I gave a quick first shot at using @JohnTitor Q for you: If I move the Thanks! |
I decided to try this route in 0bef8ef, happy to adjust if required. |
Both this and the style check are passing now (locally and in CI) 🎉 Unfortunately there's a handful of new task failures 😓 Three of them are "BuildChannelsLinux" tasks. There's also one "SemverOSX" failure that looks to be caused by a missing crate. Looking through the failures they all seem unrelated to my |
After merging master again the "SemverOSX" failure went away 🤷♂️ As for the "BuildChannelsLinux" failures I was able to figure out the problem and I was wrong about it being unrelated to the diffs in this branch. The root cause was bdd80b6 and my use of the To continue supporting Rust versions < 1.25 I split the That did the trick! All green across the board now 🎆 🏁 |
@JohnTitor This branch is ready for another review pass when you have a chance. Thank you! |
That's correct!
The semver check depends on nightly rustc API and I fix it when noticing usually :) Okay, finally I'd say "LGTM", the last work is to squash commits since they're verbose a bit to merge as-is. Thanks for separating commits, it made my reviews easy :) |
8b30245
to
7b199bb
Compare
Great! I squashed all of my work down to one commit: 46b18b8
Glad to hear it :-) Thanks for the reviews! |
Ohh, you messed up the branch, try to rebase/squash again? |
0e49ca1
to
01b4fc7
Compare
The `fanotify` API[0] is a linux-specific API for notification and interception of filesystem events. In some ways it is similar to `inotify`, but with different advantages/tradeoffs. It is particularly well suited to full filesystem/mount monitoring (vs per directory) and for allowing/denying access to files (`inotify` lacks this capability). The `fanotify` API has been updated several times since it was enabled in Linux 2.6.37. Presently I've only included support for the original `fanotify` features, and the `FAN_MARK_FILESYSTEM` addition made in Linux 4.20. There are subsequent updates in 5.0 and 5.1 not covered in this initial commit. This commit adds the relevant constants and types from `uapi/linux/fanotify.h`[1] and two new functions (`fanotify_init`[2] and `fanotify_wrap`[3]) to `src/unix/linux_like/linux/mod.rs`. While I believe this API is also present on Android I have presently limited my attention to Linux. Although this commit focuses on Linux 4.20.x's `fanotify` API/constants I have skipped adding constants for `FAN_ALL_CLASS_BITS`, `FAN_ALL_INIT_FLAGS`, `FAN_ALL_MARK_FLAGS`, `FAN_ALL_EVENTS`, `FAN_ALL_PERM_EVENTS` and `FAN_ALL_OUTGOING_EVENTS` even though they are present in this kernel version's headers. These defines were deprecated[4] in later releases with instructions to not use them in new programs or extend them with new values. It would be a shame for new Rust programs to use deprecated #defines! [0]: http://man7.org/linux/man-pages/man7/fanotify.7.html [1]: https://github.com/torvalds/linux/blob/d54f4fba889b205e9cd8239182ca5d27d0ac3bc2/include/uapi/linux/fanotify.h [2]: http://man7.org/linux/man-pages/man2/fanotify_init.2.html [3]: http://man7.org/linux/man-pages/man2/fanotify_mark.2.html [4]: torvalds/linux@23c9dee#diff-4c9ca62be6bf38cc08f7ea9daf16e379
01b4fc7
to
5c7a82a
Compare
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.
Awesome, thanks for the work!
feat: add new constants from fanotify linux api Since it's introduction in Linux and in this repo (#1699), several new features have been introduced in the fanotify API. In the original fanotify API, only a limited set of events was supported. In particular, there was no support for create, delete, and move events. The support for those events was added in Linux 5.1. This PR adds missing constants from `fanotify.h` to support the newest features.
feat: add new constants from fanotify linux api Since it's introduction in Linux and in this repo (#1699), several new features have been introduced in the fanotify API. In the original fanotify API, only a limited set of events was supported. In particular, there was no support for create, delete, and move events. The support for those events was added in Linux 5.1. This PR adds missing constants from `fanotify.h` to support the newest features.
feat: add new constants from fanotify linux api Since it's introduction in Linux and in this repo (#1699), several new features have been introduced in the fanotify API. In the original fanotify API, only a limited set of events was supported. In particular, there was no support for create, delete, and move events. The support for those events was added in Linux 5.1. This PR adds missing constants from `fanotify.h` to support the newest features.
The
fanotify
API is a Linux-specific API for notification and interception of filesystem events. In some ways it is similar toinotify
, but with different advantages/tradeoffs. It is particularly well suited to full filesystem/mount monitoring (vs operating per directory/file likeinotify
) and for allowing/denying access to files (inotify
lacks this capability).The
fanotify
API has been updated several times since it was enabled in Linux 2.6.37. Presently I've only included support for the originalfanotify
features, and theFAN_MARK_FILESYSTEM
addition made in Linux 4.20. There are subsequent updates in 5.0 and 5.1 not covered in this initial commit.This commit adds the relevant constants and types from
uapi/linux/fanotify.h
and two new functions (fanotify_init
(man page) andfanotify_mark
(man page)) tosrc/unix/linux_like/linux/mod.rs
. While I believe this API is also present on Android I have presently limited my attention to Linux.Although this commit focuses on Linux 4.20.x's
fanotify
API/constants I have skipped adding constants forFAN_ALL_CLASS_BITS
,FAN_ALL_INIT_FLAGS
,FAN_ALL_MARK_FLAGS
,FAN_ALL_EVENTS
,FAN_ALL_PERM_EVENTS
andFAN_ALL_OUTGOING_EVENTS
even though they are present in this kernel version's headers. These defines were deprecated in later releases with instructions to not use them in new programs or extend them with new values. It would be a shame for new Rust programs to use deprecated#defines
!Note to reviewers: I'm very new to Rust and the
libc
crate. I've tried my best to match project guidelines for contributing but friendly advice/pointers are welcome! I've also tested my work by building some WIPnix
wrappers on top of thelibc
work and porting an example program from thefanotify
man page to Rust: https://github.com/cpu/rfanotify. I've had success running this program on Linux 4.4.0, 5.0.0 and 5.5.8Edit: I also understand this Crate is understaffed. This is a side project and doesn't need immediate attention