Skip to content
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

repo: Add an API to get min-free-space-* reserved bytes #1715

Closed
wants to merge 5 commits into from

Conversation

uajain
Copy link

@uajain uajain commented Aug 30, 2018

Copy link
Member

@pwithnall pwithnall left a comment

Choose a reason for hiding this comment

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

A few comments. I’d be pretty keen to see a unit test for this too, otherwise there’s zero code in libostree.git which actually calls this new function.

src/libostree/ostree-repo.c Outdated Show resolved Hide resolved
src/libostree/ostree-repo.c Outdated Show resolved Hide resolved
src/libostree/ostree-repo.c Outdated Show resolved Hide resolved
src/libostree/ostree-repo.c Outdated Show resolved Hide resolved
src/libostree/ostree-repo.h Outdated Show resolved Hide resolved
src/libostree/ostree-repo.c Outdated Show resolved Hide resolved
src/libostree/ostree-repo.c Outdated Show resolved Hide resolved
Copy link
Member

@pwithnall pwithnall left a comment

Choose a reason for hiding this comment

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

I still think this would really benefit from a unit test.

if (self->reserved_blocks > G_MAXUINT64 / self->txn.blocksize)
{
g_mutex_unlock (&self->txn_lock);
return glnx_throw (error, "min-free-space value(in bytes) was too high");
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to include the maximum permitted value in this error message. For example:

return glnx_throw ("min-free-space value is greater than the maximum allowed value of %" G_GUINT64_FORMAT " bytes", G_MAXUINT64 / self->txn.blocksize);

* If the configuration value of min-free-space-* value is too high(overflow)
* then @error is set with status code %G_IO_ERROR_FAILED.
*
* Returns: Value(in bytes) of min-free-space-* config option
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Put a space before ( here and in the paragraph above.


g_assert (self->txn.blocksize != 0);
if (self->reserved_blocks > G_MAXUINT64 / self->txn.blocksize)
return glnx_throw (error, "min-free-space(in bytes) value was too high");
Copy link
Member

Choose a reason for hiding this comment

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

(Make sure this error message is the same as whatever you change the one above to be.)

@uajain uajain force-pushed the expose-min-free-space branch 2 times, most recently from ae8c3eb to cadfb9b Compare August 31, 2018 15:35
const char *values_to_test[] = { "500MB",
"0MB",
// "17179869185GB", /* Overflow parameter: bytes > G_MAXUINT64 */
// "17179869183GB", /* bytes approx. under G_MAXUINT64 */ //TODO: Bypass failure
Copy link
Member

Choose a reason for hiding this comment

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

Do both of these values error out in ostree_repo_prepare_transaction()? If so, that’s probably the best testing we’re going to get, and there’s no point in coming up with contortions to get more coverage.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, they both error out in ostree_repo_prepare_transaction with different appropriate error messages.

If so, that’s probably the best testing we’re going to get, and there’s no point in coming up with > contortions to get more coverage.

Can you explain this a bit more? Does it mean there is no need for 0MB, 500MB test etc.?

Copy link
Member

Choose a reason for hiding this comment

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

As in, don’t try and make the prepare_transaction() call artificially succeed so you can test those large values with the get_min_free_space_bytes() call.

g_return_val_if_fail (self->in_transaction == TRUE, 0);

g_assert (self->txn.blocksize != 0);
if (self->reserved_blocks > G_MAXUINT64 / self->txn.blocksize)
Copy link
Author

Choose a reason for hiding this comment

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

@pwithnall So I was asking about this check. Do we check(again) for overflows here when min_free_space_calculate_reserved_blocks() already does it before setting self->reserved_blocks ?

Copy link
Member

Choose a reason for hiding this comment

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

calculate_reserved_blocks() does a different check, though; it checks for overflow with a << 20 shift. You should only remove the check here if you can statically guarantee that if << 20 won’t overflow, then * self->txn.blocksize won’t overflow. You can do that by checking in prepare_transaction() that self->txn.blocksize < 2^20. That would be a good change to make, because you could then drop the GError argument from get_min_free_space_bytes().

@uajain uajain force-pushed the expose-min-free-space branch 2 times, most recently from cd17970 to 2a188fc Compare September 3, 2018 10:21
Umang Jain added 2 commits September 3, 2018 15:55
when converted to bytes

In a subsequent commit, we add a public API to read the value of
min-free-space-* value in bytes. The value for free space check
is enforced in terms of block size instead of bytes. Therefore,
for consistency we check while preparing the transaction that the
value doesn't overflow when converted to bytes.

https://phabricator.endlessm.com/T23694

config = ostree_repo_copy_config (repo);

while (values_to_test[i] != NULL)
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Use a for loop for this. That saves you having to manually increment i on every loop path below.

i.e. for (i = 0; values_to_test[i] != NULL; i++)

@uajain
Copy link
Author

uajain commented Sep 3, 2018

@cgwalters @jlebon Can you take a look ? it's LGTM from @pwithnall's side now.
Thank you.

const char *values_to_test[] = { "500MB",
"0MB",
"17179869185GB", /* Overflow parameter: bytes > G_MAXUINT64 */
NULL
Copy link
Member

Choose a reason for hiding this comment

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

It'd be slightly cleaner I think to have this be an array of 2-tuple (struct) { const char *val; bool should_succeeed } and assert that error is set if and only if should_succeed.

That said, up to you, I don't mind merging as is.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the suggestion.

Pushed a fixup commit.

@cgwalters
Copy link
Member

test-symbols.sh wanted leading whitespace in front of symbol names, I pushed a fixup!. Thanks for the patch!

@rh-atomic-bot r+ 9ba887d

@rh-atomic-bot
Copy link

⌛ Testing commit 9ba887d with merge 472a693...

rh-atomic-bot pushed a commit that referenced this pull request Sep 4, 2018
when converted to bytes

In a subsequent commit, we add a public API to read the value of
min-free-space-* value in bytes. The value for free space check
is enforced in terms of block size instead of bytes. Therefore,
for consistency we check while preparing the transaction that the
value doesn't overflow when converted to bytes.

https://phabricator.endlessm.com/T23694

Closes: #1715
Approved by: cgwalters
rh-atomic-bot pushed a commit that referenced this pull request Sep 4, 2018
@rh-atomic-bot
Copy link

💔 Test failed - status-atomicjenkins

@cgwalters
Copy link
Member

cgwalters commented Sep 4, 2018 via email

@rh-atomic-bot
Copy link

⌛ Testing commit 9ba887d with merge a70d2f6...

rh-atomic-bot pushed a commit that referenced this pull request Sep 4, 2018
@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: cgwalters
Pushing a70d2f6 to master...

mwleeds pushed a commit to mwleeds/ostree that referenced this pull request Sep 24, 2018
…onverted to bytes

In a subsequent commit, we add a public API to read the value of
min-free-space-* value in bytes. The value for free space check
is enforced in terms of block size instead of bytes. Therefore,
for consistency we check while preparing the transaction that the
value doesn't overflow when converted to bytes.

https://phabricator.endlessm.com/T23694

Closes: ostreedev#1715
Approved by: cgwalters

(cherry-picked from 3814d07)
mwleeds pushed a commit to mwleeds/ostree that referenced this pull request Sep 24, 2018
mwleeds pushed a commit to mwleeds/ostree that referenced this pull request Sep 24, 2018
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.

None yet

4 participants