Merge pull request #13512 from msekletar/freezer

core: introduce support for cgroup freezer
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-05-01 07:52:29 +02:00
committed by GitHub
27 changed files with 926 additions and 24 deletions
+22 -3
View File
@@ -149,6 +149,17 @@ bool cg_ns_supported(void) {
return enabled;
}
bool cg_freezer_supported(void) {
static thread_local int supported = -1;
if (supported >= 0)
return supported;
supported = cg_all_unified() > 0 && access("/sys/fs/cgroup/init.scope/cgroup.freeze", F_OK) == 0;
return supported;
}
int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) {
_cleanup_free_ char *fs = NULL;
int r;
@@ -1684,12 +1695,13 @@ int cg_get_attribute_as_uint64(const char *controller, const char *path, const c
return 0;
}
int cg_get_keyed_attribute(
int cg_get_keyed_attribute_full(
const char *controller,
const char *path,
const char *attribute,
char **keys,
char **ret_values) {
char **ret_values,
CGroupKeyMode mode) {
_cleanup_free_ char *filename = NULL, *contents = NULL;
const char *p;
@@ -1701,7 +1713,8 @@ int cg_get_keyed_attribute(
* all keys to retrieve. The 'ret_values' parameter should be passed as string size with the same number of
* entries as 'keys'. On success each entry will be set to the value of the matching key.
*
* If the attribute file doesn't exist at all returns ENOENT, if any key is not found returns ENXIO. */
* If the attribute file doesn't exist at all returns ENOENT, if any key is not found returns ENXIO. If mode
* is set to GG_KEY_MODE_GRACEFUL we ignore missing keys and return those that were parsed successfully. */
r = cg_get_path(controller, path, attribute, &filename);
if (r < 0)
@@ -1749,6 +1762,9 @@ int cg_get_keyed_attribute(
p += strspn(p, NEWLINE);
}
if (mode & CG_KEY_MODE_GRACEFUL)
goto done;
r = -ENXIO;
fail:
@@ -1759,6 +1775,9 @@ fail:
done:
memcpy(ret_values, v, sizeof(char*) * n);
if (mode & CG_KEY_MODE_GRACEFUL)
return n_done;
return 0;
}
+24 -1
View File
@@ -180,9 +180,31 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path);
int cg_rmdir(const char *controller, const char *path);
typedef enum {
CG_KEY_MODE_GRACEFUL = 1 << 0,
} CGroupKeyMode;
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value);
int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret);
int cg_get_keyed_attribute(const char *controller, const char *path, const char *attribute, char **keys, char **values);
int cg_get_keyed_attribute_full(const char *controller, const char *path, const char *attribute, char **keys, char **values, CGroupKeyMode mode);
static inline int cg_get_keyed_attribute(
const char *controller,
const char *path,
const char *attribute,
char **keys,
char **ret_values) {
return cg_get_keyed_attribute_full(controller, path, attribute, keys, ret_values, 0);
}
static inline int cg_get_keyed_attribute_graceful(
const char *controller,
const char *path,
const char *attribute,
char **keys,
char **ret_values) {
return cg_get_keyed_attribute_full(controller, path, attribute, keys, ret_values, CG_KEY_MODE_GRACEFUL);
}
int cg_get_attribute_as_uint64(const char *controller, const char *path, const char *attribute, uint64_t *ret);
@@ -238,6 +260,7 @@ int cg_mask_to_string(CGroupMask mask, char **ret);
int cg_kernel_controllers(Set **controllers);
bool cg_ns_supported(void);
bool cg_freezer_supported(void);
int cg_all_unified(void);
int cg_hybrid_unified(void);
+9
View File
@@ -108,6 +108,15 @@ static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(unit_active_state, UnitActiveState);
static const char* const freezer_state_table[_FREEZER_STATE_MAX] = {
[FREEZER_RUNNING] = "running",
[FREEZER_FREEZING] = "freezing",
[FREEZER_FROZEN] = "frozen",
[FREEZER_THAWING] = "thawing",
};
DEFINE_STRING_TABLE_LOOKUP(freezer_state, FreezerState);
static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
[AUTOMOUNT_DEAD] = "dead",
[AUTOMOUNT_WAITING] = "waiting",
+12
View File
@@ -48,6 +48,15 @@ typedef enum UnitActiveState {
_UNIT_ACTIVE_STATE_INVALID = -1
} UnitActiveState;
typedef enum FreezerState {
FREEZER_RUNNING,
FREEZER_FREEZING,
FREEZER_FROZEN,
FREEZER_THAWING,
_FREEZER_STATE_MAX,
_FREEZER_STATE_INVALID = -1
} FreezerState;
typedef enum AutomountState {
AUTOMOUNT_DEAD,
AUTOMOUNT_WAITING,
@@ -253,6 +262,9 @@ UnitLoadState unit_load_state_from_string(const char *s) _pure_;
const char *unit_active_state_to_string(UnitActiveState i) _const_;
UnitActiveState unit_active_state_from_string(const char *s) _pure_;
const char *freezer_state_to_string(FreezerState i) _const_;
FreezerState freezer_state_from_string(const char *s) _pure_;
const char* automount_state_to_string(AutomountState i) _const_;
AutomountState automount_state_from_string(const char *s) _pure_;