-
Notifications
You must be signed in to change notification settings - Fork 679
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
Add support for 'posix_fallocate' #779
Conversation
src/fcntl.rs
Outdated
/// | ||
/// Ensure disk space is allocated for the file referred to by the file descriptor | ||
/// fd for the bytes in the range starting at offset and continuing for len bytes. | ||
#[cfg(any(target_os = "linux"))] |
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.
This #[cfg()]
statement is too narrow. In addition to Linux, libc already defines posix_fallocate
for FreeBSD, Dragonfly, and Android. NetBSD has it too, though libc lacks the definition for NetBSD. Please broaden the definition. You will also need a matching #[cfg()]
statement on the tests, or else nix's tests won't build on platforms that don't define this function.
@SanchayanMaity You still planning on working on this? |
@Susurrus Yes, I plan to work on this. Got busy with a few things last week. Will work on it today. |
How to fix the build for darwin? |
The build failed on Darwin because libc doesn't define |
@asomers @SanchayanMaity I just checked on my mac running 10.11.6 and there is no definition of Also, this needs a rebase so that it'll run on all the current targets |
src/fcntl.rs
Outdated
/// | ||
/// Ensure disk space is allocated for the file referred to by the file descriptor | ||
/// fd for the bytes in the range starting at offset and continuing for len bytes. | ||
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "android", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] |
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.
Please wrap long lines.
src/fcntl.rs
Outdated
/// Allocate file space. | ||
/// | ||
/// Ensure disk space is allocated for the file referred to by the file descriptor | ||
/// fd for the bytes in the range starting at offset and continuing for len bytes. |
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.
Please add a link to http://pubs.opengroup.org/onlinepubs/9699919799/ .
test/test_fcntl.rs
Outdated
let tmp = NamedTempFile::new().unwrap(); | ||
|
||
let fd = tmp.as_raw_fd(); | ||
posix_fallocate(fd, 0, 100).unwrap(); |
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.
This test will fail if /tmp's filesystem doesn't support posix_fallocate
. ZFS, for example, does not. POSIX stupidly requires that posix_fallocate
return EINVAL
in that case. So you should skip the rest of the test if you get that errno.
@SanchayanMaity Any time to wrap up this PR? It's pretty close to being able to be merged. |
@Susurrus Will pick this up again. Sorry for the delay. Was in between jobs. |
src/fcntl.rs
Outdated
/// Allocate file space. | ||
/// | ||
/// Ensure disk space is allocated for the file referred to by file | ||
/// descriptor fd for the bytes in the range starting at offset and |
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.
parameter names like fd
and offset
should be in backticks.
src/fcntl.rs
Outdated
/// Ensure disk space is allocated for the file referred to by file | ||
/// descriptor fd for the bytes in the range starting at offset and | ||
/// continuing for len bytes. | ||
/// http://pubs.opengroup.org/onlinepubs/9699919799/ |
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.
The link is wrong. I think you probably linked to the wrong iframe. Also, for consistency with other Nix functions, you should format the link like this:
/// # References
///
/// [`posix_fallocate`](http://whatever)
src/fcntl.rs
Outdated
/// descriptor fd for the bytes in the range starting at offset and | ||
/// continuing for len bytes. | ||
/// http://pubs.opengroup.org/onlinepubs/9699919799/ | ||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] |
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.
You still need to wrap long lines here and elsewhere.
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.
This list should also be alphabetized.
src/fcntl.rs
Outdated
/// descriptor fd for the bytes in the range starting at offset and | ||
/// continuing for len bytes. | ||
/// http://pubs.opengroup.org/onlinepubs/9699919799/ | ||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] |
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.
This list should also be alphabetized.
test/test_fcntl.rs
Outdated
let ret = posix_fallocate(fd, 0, 100).unwrap(); | ||
|
||
match Errno::result(ret) { | ||
Err(Error::Sys(Errno::EINVAL)) => { |
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.
Clippy will get mad about this, a match
where only 1 arm is checked. Please rewrite this using if ret.is_some()
, but keep the comment there so it's clear what's going on.
Long-term it'd be better to actually check somehow before the test is run if this will work and skip the test otherwise. Adding a TODO
here would be helpful for that.
test/test_fcntl.rs
Outdated
@@ -143,3 +146,27 @@ mod linux_android { | |||
assert_eq!(100, read(fd, &mut buf).unwrap()); | |||
} | |||
} | |||
|
|||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] |
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.
Please alphabetize this and line wrap it also.
test/test_fcntl.rs
Outdated
@@ -1,10 +1,13 @@ | |||
use nix::errno::{Errno}; |
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.
Please remove unnecessary braces here and elsewhere.
@SanchayanMaity Do you have time to come back and finish up this PR in the near future? It's been a while since you last updated it. |
You'll need to correct your CHANGELOG entries such that they end up in the UNRELEASED section. |
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.
All LGTM now. I'll wait to see if @Susurrus has any comments before I merge it.
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.
A few minor changes then this should be good.
src/fcntl.rs
Outdated
|
||
/// Allocate file space. | ||
/// | ||
/// Ensure disk space is allocated for the file referred to by file |
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.
"to by the file"
CHANGELOG.md
Outdated
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. | |||
This project adheres to [Semantic Versioning](http://semver.org/). | |||
|
|||
## [Unreleased] | |||
- Add nix::sys::posix_fallocate |
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.
This should be under the "Added" section and rephrased like "Added nix::sys::posix_fallocate
". Please also list the platforms that it was added for since it wasn't all platforms nix
supports.
src/fcntl.rs
Outdated
/// # References | ||
/// | ||
/// [`posix_fallocate`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html) | ||
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", |
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.
posix_fallocate
is not defined in libc
for DragonFlyBSD and OpenBSD and I couldn't find it in the public sources for those OSes either. I think this and the tests should be removed for those platforms.
src/fcntl.rs
Outdated
/// [`posix_fallocate`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html) | ||
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", | ||
target_os = "linux", target_os = "openbsd"))] | ||
pub fn posix_fallocate(fd: RawFd, offset: libc::off_t, |
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.
Please annotate this as #[inline]
since it's a very small wrapper around the bare libc
call.
@SanchayanMaity Want to take care of these comments so we can get this merged? |
@Susurrus Yes, of course. Been busy lately. I will send out a patch tomorrow addressing your feedback. |
Please change the CHANGELOG entry to be under the current UNRELEASED section, as this didn't make it into the 0.10 release. Then it LGTM. @asomers if you want another look-over, now's the time as I'll merge it as soon as this gets updated. |
Please move your changelog entry under the "Added" section within the "[UNRELEASED]" section and squash these commits into 1. Then we'll merge! |
let fd = tmp.as_raw_fd(); | ||
let ret = posix_fallocate(fd, 0, 100); | ||
if ret.is_ok() { | ||
// The test will fail if /tmp's filesystem doesn't support |
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.
You shouldn't ignore all errors, just EINVAL
.
Superseded by #1105 |
No description provided.