|
|
4b3140 |
From c81248e53bd43a2132ce0b0a5aee4951c8618b6f Mon Sep 17 00:00:00 2001
|
|
|
4b3140 |
From: Jan Chaloupka <jchaloup@redhat.com>
|
|
|
4b3140 |
Date: Thu, 7 Aug 2014 07:17:23 +0200
|
|
|
4b3140 |
Subject: [PATCH] retry to set control file
|
|
|
4b3140 |
|
|
|
4b3140 |
---
|
|
|
4b3140 |
src/api.c | 35 +++++++++++++++++++++++++++++++++++
|
|
|
4b3140 |
1 file changed, 35 insertions(+)
|
|
|
4b3140 |
|
|
|
4b3140 |
diff --git a/src/api.c b/src/api.c
|
|
|
4b3140 |
index ae8396e..03c8068 100644
|
|
|
4b3140 |
--- a/src/api.c
|
|
|
4b3140 |
+++ b/src/api.c
|
|
|
4b3140 |
@@ -1432,6 +1432,8 @@ static int cg_set_control_value(char *path, const char *val)
|
|
|
4b3140 |
return 0;
|
|
|
4b3140 |
}
|
|
|
4b3140 |
|
|
|
4b3140 |
+
|
|
|
4b3140 |
+
|
|
|
4b3140 |
/** cgroup_modify_cgroup modifies the cgroup control files.
|
|
|
4b3140 |
* struct cgroup *cgroup: The name will be the cgroup to be modified.
|
|
|
4b3140 |
* The values will be the values to be modified, those not mentioned
|
|
|
4b3140 |
@@ -1449,6 +1451,9 @@ int cgroup_modify_cgroup(struct cgroup *cgroup)
|
|
|
4b3140 |
int i;
|
|
|
4b3140 |
int error = 0;
|
|
|
4b3140 |
int ret;
|
|
|
4b3140 |
+ int retry_list[CG_CONTROLLER_MAX];
|
|
|
4b3140 |
+ int retry_index;
|
|
|
4b3140 |
+ struct control_value **cvalues;
|
|
|
4b3140 |
|
|
|
4b3140 |
if (!cgroup_initialized)
|
|
|
4b3140 |
return ECGROUPNOTINITIALIZED;
|
|
|
4b3140 |
@@ -1469,6 +1474,8 @@ int cgroup_modify_cgroup(struct cgroup *cgroup)
|
|
|
4b3140 |
if (!cg_build_path(cgroup->name, base,
|
|
|
4b3140 |
cgroup->controller[i]->name))
|
|
|
4b3140 |
continue;
|
|
|
4b3140 |
+
|
|
|
4b3140 |
+ retry_index = -1;
|
|
|
4b3140 |
for (j = 0; j < cgroup->controller[i]->index; j++) {
|
|
|
4b3140 |
ret = asprintf(&path, "%s%s", base,
|
|
|
4b3140 |
cgroup->controller[i]->values[j]->name);
|
|
|
4b3140 |
@@ -1485,12 +1492,40 @@ int cgroup_modify_cgroup(struct cgroup *cgroup)
|
|
|
4b3140 |
* the user as fatal */
|
|
|
4b3140 |
if (error && !cgroup->controller[i]->values[j]->dirty) {
|
|
|
4b3140 |
error = 0;
|
|
|
4b3140 |
+ /* Let's retry to set it in the second round */
|
|
|
4b3140 |
+ ++retry_index;
|
|
|
4b3140 |
+ retry_list[retry_index] = j;
|
|
|
4b3140 |
continue;
|
|
|
4b3140 |
}
|
|
|
4b3140 |
if (error)
|
|
|
4b3140 |
goto err;
|
|
|
4b3140 |
cgroup->controller[i]->values[j]->dirty = false;
|
|
|
4b3140 |
}
|
|
|
4b3140 |
+ if (retry_index > -1) {
|
|
|
4b3140 |
+ for (j = 0; j <= retry_index; j++) {
|
|
|
4b3140 |
+ cvalues = cgroup->controller[i]->values;
|
|
|
4b3140 |
+ ret = asprintf(&path, "%s%s", base,
|
|
|
4b3140 |
+ cvalues[retry_list[j]]->name);
|
|
|
4b3140 |
+ if (ret < 0) {
|
|
|
4b3140 |
+ last_errno = errno;
|
|
|
4b3140 |
+ error = ECGOTHER;
|
|
|
4b3140 |
+ goto err;
|
|
|
4b3140 |
+ }
|
|
|
4b3140 |
+ error = cg_set_control_value(path,
|
|
|
4b3140 |
+ cvalues[retry_list[j]]->value);
|
|
|
4b3140 |
+ free(path);
|
|
|
4b3140 |
+ path = NULL;
|
|
|
4b3140 |
+ /* don't consider error in files directly
|
|
|
4b3140 |
+ * written by the user as fatal */
|
|
|
4b3140 |
+ if (error && !cvalues[retry_list[j]]->dirty) {
|
|
|
4b3140 |
+ error = 0;
|
|
|
4b3140 |
+ continue;
|
|
|
4b3140 |
+ }
|
|
|
4b3140 |
+ if (error)
|
|
|
4b3140 |
+ goto err;
|
|
|
4b3140 |
+ cvalues[retry_list[j]]->dirty = false;
|
|
|
4b3140 |
+ }
|
|
|
4b3140 |
+ }
|
|
|
4b3140 |
}
|
|
|
4b3140 |
err:
|
|
|
4b3140 |
return error;
|
|
|
4b3140 |
--
|
|
|
4b3140 |
1.9.3
|
|
|
4b3140 |
|