Skip to content

Migrate quota module to libc FFI types #750

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

Merged
merged 1 commit into from
Sep 1, 2017
Merged

Conversation

Susurrus
Copy link
Contributor

No description provided.

@Susurrus Susurrus force-pushed the quota_ffi branch 2 times, most recently from b8f4007 to 1117842 Compare August 29, 2017 05:11
@Susurrus Susurrus changed the title Migrate quota module to libc FFI types WIP: Migrate quota module to libc FFI types Aug 29, 2017
@Susurrus
Copy link
Contributor Author

Need to add setters for the various quota limits and also add some examples: 1 retrieving the quota limits, one enabling and settings limits, and one modifying limits.

@Susurrus Susurrus changed the title WIP: Migrate quota module to libc FFI types Migrate quota module to libc FFI types Aug 29, 2017
@Susurrus
Copy link
Contributor Author

I don't see why this code shouldn't also work across all Linux, rather than just x86/x86_64 and arm, so I've also made that change, we'll see if anything fails. I'm not running any actual tests using this API, but maybe I'll try and contrive one that would work so we can confirm this.

@Susurrus
Copy link
Contributor Author

This is ready for review if someone's up for it.

src/sys/quota.rs Outdated
pub type QuotaSubCmd = c_int;
impl QuotaCmd {
fn as_int(&self) -> c_int {
(((self.0 as i32) << 8) | ((self.1 as i32) & 0x00ff)) as c_int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work. The QuotaSubCmd values are constants, defined by libc with values like 0x100, 0x200, etc. So you should eliminate the shift.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was in there already, so I actually didn't take a look at it at all! But the implementation follows from the QCMD() macro in /usr/include/linux/quota.h, so I'm not certain what the problem is. on Linux QSYNC for example is a 24-bit value, we shift it up 8 bits and then or-in a 2 bit value at the bottom. That seems fine to me. What are you looking at that makes you think this is incorrect?

I actually think we should block until QCMD is added to libc and actually make this rely on that instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was looking at the BSD definitions for quota commands, which are also similar to the Linux definitions when _LINUX_QUOTA_VERSION < 2

QIF_TIMES;
QIF_ALL;
/// Set the absolute limit on disk quota blocks allocated.
pub fn set_blocks_hard_limit(&mut self, limit: u64) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this method also set QIF_BLIMITS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. If anything, it should unset it. This API basically has two modes: reading the current state and modifying the existing state. The QIF_ values are used to indicate which values are set in both cases. So in case you read, modify, then write, we actually want to completely ignore the value set in the struct, as it might be left-over from a read, and instead force the user to specify it explicitly for this specific write operation. That way there's no confusion.

I think we could simplify the API by doing something like what you suggest but actually use separate fields to track reading and writing and then setting the writing_valid_fields field to the proper flags when any of the appropriate set_* functions are called might work. Thoughts?

@Susurrus
Copy link
Contributor Author

Waiting on rust-lang/libc#747 to resolve Linux/MIPS build errors.

@asomers
Copy link
Member

asomers commented Aug 30, 2017

Would it be possible to add some tests?

@Susurrus
Copy link
Contributor Author

@polachok You originally added this API, do you have any tests or examples that you could possibly volunteer here so we could expand a test suite for this API? I'm not too familiar with this API, so would appreciate any input from someone more knowledgable.

@asomers I already pinged @polachok via email yesterday asking this same thing basically and haven't heard anything, so I dunno if we'll get a response. I'd prefer to merge this and come back and extend our test suite later. i don't really want to spend the time to dive deep into this API know when my priority is closing #748.

@polachok
Copy link
Contributor

Sorry for late response, I haven't got a chance to use the API after adding it (besides basic tests I don't have know), so I'm ok with whatever you have. We can fix it later if there's something wrong.

@Susurrus
Copy link
Contributor Author

Susurrus commented Sep 1, 2017

@polachok Thanks for chiming in here, really appreciate it.

@asomers You fine merging this as-is?

@asomers
Copy link
Member

asomers commented Sep 1, 2017

Fine? No. I'm slightly depressed whenever I add untested code. But your changes don't add new code so much as refactor existing code, so I guess it's ok.

bors r+

bors bot added a commit that referenced this pull request Sep 1, 2017
750: Migrate quota module to libc FFI types r=asomers a=Susurrus
@Susurrus
Copy link
Contributor Author

Susurrus commented Sep 1, 2017

Yeah, it's definitely not ideal. I'd like to vastly improve our test coverage (I'd actually like to look at tarpaulin for doing that also), but part of this refactoring does improve our testing because we're outsourcing some of that work to libc at least.

The next step as part of my work towards a 1.0 release will be to get every subsystem testable (though I dunno how much will require root).

@bors
Copy link
Contributor

bors bot commented Sep 1, 2017

@bors bors bot merged commit 1db4d18 into nix-rust:master Sep 1, 2017
@Susurrus Susurrus deleted the quota_ffi branch September 1, 2017 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants