DevinLeamy commented on code in PR #519:
URL: https://github.com/apache/mesos/pull/519#discussion_r1530377439


##########
src/linux/cgroups2.cpp:
##########
@@ -295,4 +296,152 @@ Try<set<string>> enabled(const string& cgroup)
 
 } // namespace controllers {
 
+namespace devices {
+
+const int ALLOW_ACCESS = 1;
+
+const int DENY_ACCESS = 0;
+
+// Utility class to construct an eBPF program to whitelist or blacklist
+// select device accesses.
+class DeviceProgram
+{
+public:
+  DeviceProgram() : program{ebpf::Program(BPF_PROG_TYPE_CGROUP_DEVICE)}
+  {
+    program.append({
+        // r2: Type ('c', 'b', '?')
+        BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 0),
+        BPF_ALU32_IMM(BPF_AND, BPF_REG_2, 0xFFFF),
+        // r3: Access ('r', 'w', 'm')
+        BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, 0),
+        BPF_ALU32_IMM(BPF_RSH, BPF_REG_3, 16),
+        // r4: Major Version
+        BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1, 4),
+        // r5: Minor Version
+        BPF_LDX_MEM(BPF_W, BPF_REG_5, BPF_REG_1, 8)});
+  }
+
+  Try<Nothing> allow(const Entry entry) { return addDevice(entry, true); }
+
+  Try<Nothing> deny(const Entry entry) { return addDevice(entry, false); }
+
+  Try<Nothing> addDevice(const Entry entry, bool allow)

Review Comment:
   Actually, since it's only in the`*.cpp` file I'm keeping it public. I would 
have assumed that I could mark it public and still have access within 
`cgroups2.cpp`, but that doesn't look to be the case.



-- 
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]

Reply via email to