mesos-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [mesos] cf-natali commented on a change in pull request #355: Handle EBUSY when destroying a cgroup.
Date Thu, 09 Apr 2020 17:58:09 GMT
cf-natali commented on a change in pull request #355: Handle EBUSY when destroying a cgroup.
URL: https://github.com/apache/mesos/pull/355#discussion_r406378922
 
 

 ##########
 File path: src/linux/cgroups.cpp
 ##########
 @@ -263,6 +265,98 @@ static Try<Nothing> cloneCpusetCpusMems(
   return Nothing();
 }
 
+
+// Removes a cgroup from a given hierachy.
+// @param   hierarchy  Path to hierarchy root.
+// @param   cgroup     Path of the cgroup relative to the hierarchy root.
+// @return  Some if the operation succeeds.
+//          Error if the operation fails.
+Future<Nothing> remove(const string& hierarchy, const string& cgroup)
+{
+  const string path = path::join(hierarchy, cgroup);
+
+  // We retry on EBUSY as a workaround for kernel bug
+  // https://lkml.org/lkml/2020/1/15/1349 and others which cause rmdir to fail
+  // with EBUSY even though the cgroup appears empty.
+
+  Duration delay;
+  int retry = 10;
+
+  return loop(
+      [=]() mutable {
+        auto timeout = process::after(delay);
+        delay = (delay == Duration()) ? Milliseconds(1) : delay * 2;
+        return timeout;
+      },
+      [=](const Nothing&) mutable -> Future<ControlFlow<Nothing>> {
+        if (::rmdir(path.c_str()) == 0) {
+          return process::Break();
+        } else if ((errno == EBUSY) && (retry > 0)) {
+          --retry;
+          return process::Continue();
+        } else {
+          // If the `cgroup` still exists in the hierarchy, treat this as
+          // an error; otherwise, treat this as a success since the `cgroup`
+          // has actually been cleaned up.
+          if (os::exists(path::join(hierarchy, cgroup))) {
+            return Failure(
+              "Failed to remove directory '" + path + "': " +
+              os::strerror(errno));
+          }
+          return process::Break();
+        }
+      }
+    );
+}
+
+// Removes a list of cgroups from a given hierachy.
+// The cgroups are removed in order, so this function can be used to remove a
+// cgroup hierarchy in a bottom-up fashion.
+// @param   hierarchy  Path to hierarchy root.
+// @param   cgroups    Path of the cgroups relative to the hierarchy root.
+// @return  Some if the operation succeeds.
+//          Error if the operation fails.
+Future<Nothing> remove(const string& hierarchy, const vector<string>&
cgroups)
+{
+  size_t cgroup_index = 0;
+
+  return loop(
+      [=]() mutable -> Future<bool> {
+        if (cgroup_index == cgroups.size()) {
+          // No more cgroup to remove.
+          return false;
+        }
+        Future<Nothing> removed = internal::remove(
+                                        hierarchy, cgroups[cgroup_index]);
+        ++cgroup_index;
+        return removed.then(
+          [=](const Future<Nothing>& removed) -> Future<bool> {
+            if (removed.isReady()) {
+              return true;
+            }
+            if (removed.isFailed()) {
+              return Failure(removed.failure());
+            }
+            return false;
+          }
+        );
+      },
+      [](const Future<bool>& removed) mutable -> Future<ControlFlow<Nothing>>
{
+        if (removed.isReady()) {
+          if (!removed.get()) {
+            // No more cgroup to remove.
+            return process::Break();
+          }
+          return process::Continue();
+        }
+        if (removed.isFailed()) {
+          return Failure(removed.failure());
+        }
+        return process::Break();
+      }
+    );
 
 Review comment:
   Indeed, that's much simpler, wasn't aware of that.
   Thanks!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message