Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linux/qemu] Qemu bridging v2 #3573

Merged
merged 19 commits into from
Aug 28, 2024
Merged

[linux/qemu] Qemu bridging v2 #3573

merged 19 commits into from
Aug 28, 2024

Conversation

sharder996
Copy link
Contributor

@sharder996 sharder996 commented Jul 9, 2024

Public side of #647

The spec for this feature can be found here.

This second version of QEMU network bridging was required because of the change in implementation of find_bridge_with(). Since most of bridged networks was already available on macOS/QEMU and implemented, this PR is mostly just for enabling and wiring up the function calls needed to create a network interface on Linux.

The key difference on Linux is the presence of bridge_helper.c. Below is an excerpt from the spec on the purpose of the bridge helper:

Finally, to use bridges on QEMU, on Linux, we will use a bridge helper. The QEMU bridge helper, shipped with QEMU, is a simple program which checks a file in /etc/ to see if using a certain bridge is allowed; then it sets up the devices needed for QEMU to use the bridge. Access to this file would be denied in our snap. Instead, our approach will be to fork the source of the bridge helper and remove the need to check for this file, thus allowing all the bridges we create. Then, from the QEMU command line, we must specify the path to our binary, for avoiding executing the default bridge helper.

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 82.35294% with 6 lines in your changes missing coverage. Please review.

Project coverage is 88.89%. Comparing base (d596d32) to head (64f0649).
Report is 187 commits behind head on main.

Files Patch % Lines
...backends/qemu/linux/qemu_platform_detail_linux.cpp 80.95% 4 Missing ⚠️
...orm/backends/qemu/qemu_virtual_machine_factory.cpp 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3573      +/-   ##
==========================================
+ Coverage   88.83%   88.89%   +0.05%     
==========================================
  Files         253      254       +1     
  Lines       14170    14250      +80     
==========================================
+ Hits        12588    12667      +79     
- Misses       1582     1583       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sharder996, thank you for your work on this. I did a quick pass and I have a couple of questions.

CMakeLists.txt Outdated Show resolved Hide resolved
@georgeliao
Copy link
Contributor

georgeliao commented Jul 18, 2024

@sharder996
Since I was not in the discussions, it would be nice to have a context introduction. Something like why bridge_helper executable is needed on linux but not on macos. What was the state of the code before and why did you do some refactoring? Thanks.

@sharder996
Copy link
Contributor Author

Does clang-format format test_qemu_linux_platform.cpp the same as the linter in CI for anyone else? Don't know why is doesn't format the same for me.

@ricab
Copy link
Collaborator

ricab commented Jul 23, 2024

@sharder996 are you perhaps using a different version than CI? Different versions have different ideas of what the format should be.

@georgeliao
Copy link
Contributor

@sharder996
Check the clang-format executable version, check the clang-format configuration file your local IDE uses is the in-repo one by changing the file and see if re-apply formatting makes a difference.

Copy link
Contributor

@georgeliao georgeliao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharder996
It looks very good. I only have a few minor comments. The unit test coverage is not high enough, it is easy to add these tests as well. However, on the other side, the uncovered part does not have any actual logic, so it is ok to skip them. I will leave it to you whether you want to push the test coverage up.

Funcitonal testing was done as well, it works fine on linux and macos.

CMakeLists.txt Outdated Show resolved Hide resolved
@@ -192,27 +195,46 @@ QStringList mp::QemuPlatformDetail::vm_platform_args(const VirtualMachineDescrip
<< QString::fromStdString(fmt::format("tap,ifname={},script=no,downscript=no,model=virtio-net-pci,mac={}",
tap_device_name, vm_desc.default_mac_address));

auto bridge_helper_path = QCoreApplication::applicationDirPath() + "/bridge_helper";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open for discussion:
we use the hardcoded executable name in CMake and here. It makes more sense to use a variable in CMake and pass it here. The idiom to do this is also simple. Just changing something in the cmake file multipass/src/platform/backends/qemu/linux/CMakeLists.txt.

set(BRIDGE_HELPER_EXEC_NAME "bridge_helper")
add_library(qemu_platform_detail
  dnsmasq_process_spec.cpp
  dnsmasq_server.cpp
  firewall_config.cpp
  qemu_platform_detail_linux.cpp)
target_compile_definitions(qemu_platform_detail PRIVATE BRIDGE_HELPER_EXEC_NAME_CPP="${BRIDGE_HELPER_EXEC_NAME}")

...
and using BRIDGE_HELPER_EXEC_NAME in the below cmake script and use BRIDGE_HELPER_EXEC_NAME_CPP in the c++ code here.

I know that we also have sshfs_server in the pattern. So it is open for discussion whether we want to change them both, or whether we want it to be in a different PR or not. Maybe @ricab also has an opinion on this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not difficult to do, I would say yes. If you start running into trouble and needing to invest more time for any reason, I would say leave it.

src/platform/backends/qemu/linux/bridge_helper.c Outdated Show resolved Hide resolved
tests/qemu/linux/test_qemu_platform_detail.cpp Outdated Show resolved Hide resolved
tests/qemu/test_qemu_backend.cpp Outdated Show resolved Hide resolved
tests/qemu/test_qemu_backend.cpp Outdated Show resolved Hide resolved
@sharder996
Copy link
Contributor Author

@georgeliao As for the missing test line coverage. Having no logic to actually test was the reason why I didn't pursue it.

georgeliao
georgeliao previously approved these changes Aug 26, 2024
Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, well done!

@ricab ricab added this pull request to the merge queue Aug 27, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 27, 2024
@ricab ricab added this pull request to the merge queue Aug 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 28, 2024
@ricab ricab merged commit c9f3ace into main Aug 28, 2024
13 of 14 checks passed
@ricab ricab deleted the qemu-bridging-v2 branch August 28, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants