This is an automated email from the ASF dual-hosted git repository. bmahler pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push: new fbb120740 [cgroups] Add helper to find overlapping device access. fbb120740 is described below commit fbb120740e05b4dc45b3873f3bca9f8632a53e6b Author: Jason Zhou <jasonzhou...@gmail.com> AuthorDate: Wed Jul 24 16:08:31 2024 -0400 [cgroups] Add helper to find overlapping device access. Currently, we have to directly compare member variables to see if one Access object would overlap that of another, which isn't very clear to people that would be reading the code. We add a helper to abstract away the logic to see if the accesses specified in one Access instance would overlap with that of another. Review: https://reviews.apache.org/r/75107/ --- src/linux/cgroups.cpp | 8 ++++++++ src/linux/cgroups.hpp | 1 + src/tests/containerizer/cgroups_tests.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/linux/cgroups.cpp b/src/linux/cgroups.cpp index 3dae320bd..e58c2977a 100644 --- a/src/linux/cgroups.cpp +++ b/src/linux/cgroups.cpp @@ -2946,6 +2946,14 @@ bool Entry::encompasses(const Entry& other) const bool Entry::Access::none() const { return !mknod && !read && !write; } +bool Entry::Access::overlaps(const Entry::Access& other) const +{ + return (read && other.read) + || (write && other.write) + || (mknod && other.mknod); +} + + bool Entry::Selector::has_wildcard() const { return major.isNone() || minor.isNone() || type == Entry::Selector::Type::ALL; diff --git a/src/linux/cgroups.hpp b/src/linux/cgroups.hpp index 4fefb5c3b..c50ec59e3 100644 --- a/src/linux/cgroups.hpp +++ b/src/linux/cgroups.hpp @@ -963,6 +963,7 @@ struct Entry bool write; bool mknod; bool none() const; + bool overlaps(const Access& other) const; }; Selector selector; diff --git a/src/tests/containerizer/cgroups_tests.cpp b/src/tests/containerizer/cgroups_tests.cpp index e4ca7933b..7e6bb0659 100644 --- a/src/tests/containerizer/cgroups_tests.cpp +++ b/src/tests/containerizer/cgroups_tests.cpp @@ -1493,6 +1493,36 @@ TEST(DevicesTest, AccessNoneTest) } +TEST(DeviceTest, AccessOverlapsTest) +{ + cgroups::devices::Entry::Access access; + cgroups::devices::Entry::Access other; + access.read = true; + access.write = true; + access.mknod = true; + + other.read = false; + other.write = false; + other.mknod = false; + EXPECT_FALSE(access.overlaps(other)); + + other.read = true; + other.write = false; + other.mknod = false; + EXPECT_TRUE(access.overlaps(other)); + + other.read = false; + other.write = true; + other.mknod = false; + EXPECT_TRUE(access.overlaps(other)); + + other.read = false; + other.write = false; + other.mknod = true; + EXPECT_TRUE(access.overlaps(other)); +} + + TEST(DeviceTest, SelectorWildcardTest) { cgroups::devices::Entry::Selector selector;