DevinLeamy commented on code in PR #509:
URL: https://github.com/apache/mesos/pull/509#discussion_r1520063442
##########
src/linux/ebpf.cpp:
##########
@@ -151,6 +163,52 @@ Try<Nothing> attach(int fd, const string& cgroup)
return Nothing();
}
+
+Try<vector<uint32_t>> attached(const string& cgroup)
+{
+ Try<int> cgroup_fd = os::open(cgroup, O_DIRECTORY | O_RDONLY | O_CLOEXEC);
+ if (cgroup_fd.isError()) {
+ return Error("Failed to open '" + cgroup + "': " + cgroup_fd.error());
+ }
+
+ // Program ids are unsigned 32-bit integers. We assume that a maximum
+ // of 32 programs are attached to a cgroup; there should only be 0 or 1 but
+ // we allow for more to be safe. We initialize our query buffer with -1 so
+ // we can distinguish between a returned program id and filler values.
+ //
+ // Example: [1, 7, 3, -1, -1, -1, ..., -1] => [1, 7, 3] are program ids.
+ const int MAX_IDS = 32;
+ vector<int32_t> buffer(MAX_IDS, -1);
+
+ bpf_attr attr;
+ memset(&attr, 0, sizeof(attr));
+ attr.query.target_fd = *cgroup_fd;
+ attr.query.attach_type = BPF_CGROUP_DEVICE;
+ attr.query.prog_cnt = MAX_IDS;
+ attr.query.prog_ids = reinterpret_cast<uint64_t>(buffer.data());
+
+ Try<int, ErrnoError> result = bpf(BPF_PROG_QUERY, &attr, sizeof(attr));
+
+ if (result.isError()) {
+ os::close(*cgroup_fd);
+ return Error(
+ "BPF syscall to find a program ids attached to '" + cgroup +
+ "' failed: " + result.error().message);
Review Comment:
Went with the second one.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]