You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@mesos.apache.org by "DevinLeamy (via GitHub)" <gi...@apache.org> on 2024/04/05 14:12:13 UTC
[PR] [cgroups2] Introduce interface to get cgroups nested inside of a cgroup. [mesos]
DevinLeamy opened a new pull request, #549:
URL: https://github.com/apache/mesos/pull/549
Introduces
```
cgroups2::get(cgroup)
```
which returns the cgroups inside of the given cgroup.
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@mesos.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [cgroups2] Introduce interface to get cgroups nested inside of a cgroup. [mesos]
Posted by "bmahler (via GitHub)" <gi...@apache.org>.
bmahler merged PR #549:
URL: https://github.com/apache/mesos/pull/549
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@mesos.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [cgroups2] Introduce interface to get cgroups nested inside of a cgroup. [mesos]
Posted by "DevinLeamy (via GitHub)" <gi...@apache.org>.
DevinLeamy commented on code in PR #549:
URL: https://github.com/apache/mesos/pull/549#discussion_r1553735456
##########
src/linux/cgroups2.cpp:
##########
@@ -306,6 +308,45 @@ bool exists(const string& cgroup)
}
+Try<set<string>> get(const string& cgroup)
+{
+ const string& path = cgroups2::path(cgroup);
+ char* paths[] = {const_cast<char*>(path.c_str()), nullptr};
+
+ FTS* tree = fts_open(paths, FTS_NOCHDIR, nullptr);
+ if (tree == nullptr) {
+ return ErrnoError("Failed to start traversing filesystem");
+ }
+
+ FTSENT* node;
+ set<string> cgroups;
+ while ((node = fts_read(tree)) != nullptr) {
+ // Use post-order walk here. fts_level is the depth of the traversal,
+ // numbered from -1 to N, where the file/dir was found. The traversal root
+ // itself is numbered 0. fts_info includes flags for the current node.
+ // FTS_DP indicates a directory being visited in postorder.
+ if (node->fts_level > 0 && node->fts_info & FTS_DP) {
+ string _cgroup = strings::trim(
+ node->fts_path + MOUNT_POINT.length(), "/");
+ cgroups.insert(_cgroup);
+ }
+ }
+
+ if (errno != 0) {
+ Error error =
+ ErrnoError("Failed to read a node while traversing the filesystem");
+ fts_close(tree);
+ return error;
+ }
+
+ if (fts_close(tree) != 0) {
+ return ErrnoError("Failed to stop traversing file system");
+ }
+
+ return cgroups;
+}
Review Comment:
Not reinventing the wheel here, this is largely taken from `cgroups::get`. Ideally, we could use `std::filesystem::recursive_directory_iterator`, but it's a C++17 addition and we compile with C++11.
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@mesos.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [cgroups2] Introduce interface to get cgroups nested inside of a cgroup. [mesos]
Posted by "DevinLeamy (via GitHub)" <gi...@apache.org>.
DevinLeamy commented on code in PR #549:
URL: https://github.com/apache/mesos/pull/549#discussion_r1553739387
##########
src/linux/cgroups2.cpp:
##########
@@ -306,6 +308,45 @@ bool exists(const string& cgroup)
}
+Try<set<string>> get(const string& cgroup)
+{
+ const string& path = cgroups2::path(cgroup);
+ char* paths[] = {const_cast<char*>(path.c_str()), nullptr};
+
+ FTS* tree = fts_open(paths, FTS_NOCHDIR, nullptr);
+ if (tree == nullptr) {
+ return ErrnoError("Failed to start traversing filesystem");
+ }
+
+ FTSENT* node;
+ set<string> cgroups;
+ while ((node = fts_read(tree)) != nullptr) {
+ // Use post-order walk here. fts_level is the depth of the traversal,
+ // numbered from -1 to N, where the file/dir was found. The traversal root
+ // itself is numbered 0. fts_info includes flags for the current node.
+ // FTS_DP indicates a directory being visited in postorder.
+ if (node->fts_level > 0 && node->fts_info & FTS_DP) {
+ string _cgroup = strings::trim(
+ node->fts_path + MOUNT_POINT.length(), "/");
+ cgroups.insert(_cgroup);
+ }
+ }
+
+ if (errno != 0) {
+ Error error =
+ ErrnoError("Failed to read a node while traversing the filesystem");
+ fts_close(tree);
+ return error;
+ }
+
+ if (fts_close(tree) != 0) {
+ return ErrnoError("Failed to stop traversing file system");
+ }
+
+ return cgroups;
+}
Review Comment:
`cgroups::get`: https://github.com/apache/mesos/blob/b23908fa9c520a941111bf4c56ceee64d14331f1/src/linux/cgroups.cpp#L770
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@mesos.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org