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

Adjust min-free-space-percent config option to accept specfic size #1616

Closed
wants to merge 2 commits into from

Conversation

uajain
Copy link

@uajain uajain commented Jun 7, 2018

No description provided.


char unit = dup_str[i];
dup_str[i] = '\0';
gint size = g_ascii_strtoull (dup_str, NULL, 10);
Copy link
Member

Choose a reason for hiding this comment

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

guint64 again.

@@ -150,7 +150,7 @@ struct OstreeRepo {
uid_t owner_uid; /* Cache of repo's owner uid */
uid_t target_owner_uid; /* Ensure files are chowned to this uid/gid */
gid_t target_owner_gid;
guint min_free_space_percent; /* See the min-free-space-percent config option */
const char *min_free_space_str; /* See the 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.

I'm in favor of adding min-free-space as an alias for min-free-space-percent, but AFAICS this patch isn't doing that yet.

min_free_space_str_validate (char *min_free_space_str)
{
GRegex *percent_regex = g_regex_new ("^([0-9]|[1-9][0-9])%$" , 0,0, NULL);
GRegex *size_regex = g_regex_new ("^[0-9]+(G|M|T)B$", 0,0, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

g_autoptr() here - these are leaked currently. (Also we tend to use g_once_init...() for regexps, see elsewhere in the code)

/* If changing this, be sure to change the man page too */
const char *default_min_free_space = "3";
const char *default_min_free_space = "3%";
Copy link
Member

Choose a reason for hiding this comment

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

Well...but we have a backcompat hazard here as we didn't previously require %. So perhaps it is best to introduce a new config option.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or interpret a bare number as a percentage for the back compat case?

Copy link
Author

Choose a reason for hiding this comment

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

@ramcq Won't it give a wrong idea? For e.g.
(i) min-free-space-percent=3
(ii) min-free-space-percent=150MB
or am I missing something?

I wonder if adding an alias and introducing new config option are same thing? Do we have an exisitng alias case which I can look-up?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if adding an alias and introducing new config option are same thing

They're different. I was leaning towards an alias at first, but I think we need to add a new option to sanely differentiate. We could in theory require G|M|T for sizes but...it's ugly to have the option named -percent when it's not.

If we have two options, an interesting question arises if we want to support setting both simultaneously - I'd be fine trying to do so, I'd also be fine making it an error for now.

I want to be clear here: Is this just an idea of yours or are you planning to actually ship a non-zero min-free-space in EndlessOS?

Copy link
Author

Choose a reason for hiding this comment

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

If we have two options, an interesting question arises if we want to support setting both simultaneously - I'd be fine trying to do so, I'd also be fine making it an error for now.

I think, making it an error sounds logical to me here.

I want to be clear here: Is this just an idea of yours or are you planning to actually ship a non-zero min-free-space in EndlessOS?

It's not just an idea but a step in direction of #1602 (comment) . Also, min-free-space (% or specific size) should guard against possibility of hitting ENOSPC. So yes, Endless would be very much interesting in this as it provides a bit more fine tuning of the config option.

Choose a reason for hiding this comment

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

Endless certainly wants to ship something that does this kind of thing.

Copy link
Author

Choose a reason for hiding this comment

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

@cgwalters Quick question: If both min-free-space and min-free-space-percent are specified in the config file(for some odd reasons), do we error that out, or treat one of them as default (say min-free-space) and proceed ahead with discarding the other one ?

@@ -2771,18 +2784,22 @@ reload_core_config (OstreeRepo *self,
self->zlib_compression_level = OSTREE_ARCHIVE_DEFAULT_COMPRESSION_LEVEL;
}

{ g_autofree char *min_free_space_percent_str = NULL;
{ g_autofree char *min_free_space_str = NULL;
self->min_free_space_str = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

g_clear_pointer (&self->min_free_space_str, g_free)

if (self->min_free_space_percent > 99)
return glnx_throw (error, "Invalid min-free-space-percent '%s'", min_free_space_percent_str);
if (min_free_space_str_validate (min_free_space_str))
self->min_free_space_str = g_strdup (min_free_space_str);
Copy link
Member

Choose a reason for hiding this comment

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

self->min_free_space_str = g_steal_pointer (&min_free_space_str); and avoid an extra strdup.

GRegex *size_regex = g_regex_new ("^[0-9]+(G|M|T)B$", 0,0, NULL);

if (g_regex_match (percent_regex, min_free_space_str, 0, NULL) ||
g_regex_match (size_regex, min_free_space_str, 0, NULL))
Copy link
Member

Choose a reason for hiding this comment

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

If we're going to use regexps it feels like we might as well use capture groups to get the data out, then min_free_space_str_parse() would just need to handle a (G|M|T)B suffix.

break;
default:
g_warning ("Should not be reached, min_free_space_parse\n");
}
Copy link
Member

Choose a reason for hiding this comment

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

Indentation seems off in various places like this.

@cgwalters
Copy link
Member

Also can you add commit messages to your commits?

Similar to min-free-space-percent but it supports specific sizes
(in MB, GB or TB). Also, making min-free-space-percent and -size
mutually exclusive.

min-free-space-percent does not give a fine tuning of the free disk
space that a user might decide to keep. It can translate to very large
size (e.g. 1% = ~10GB on 1TB HDD) or very small (e.g. 1% = ~330MB on 32GB
system like Endless devices). Hence, it makes sense to introduce a config
option to honor specific size as per the user.
@uajain
Copy link
Author

uajain commented Jun 12, 2018

Updated the PR. I have kept the same min-free-space-percent option as default (instead of min-free-space-size) for now; But in near future, it makes sense to keep min-free-space-size as default. Also, it needs some discussion to decide on the default value.

@jlebon
Copy link
Member

jlebon commented Jun 13, 2018

This looks sane to me. I added a test to itest-pull-space.sh as well.
@rh-atomic-bot r+ b7729cd

@rh-atomic-bot
Copy link

⌛ Testing commit b7729cd with merge 31809d3...

@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: jlebon
Pushing 31809d3 to master...

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

6 participants