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

Bridging on Linux QEMU #3463

Open
wants to merge 17 commits into
base: fix-get-bridged
Choose a base branch
from
Open

Bridging on Linux QEMU #3463

wants to merge 17 commits into from

Conversation

luis4a0
Copy link
Contributor

@luis4a0 luis4a0 commented Apr 5, 2024

This PR implements the bridging feature on the QEMU backend on Linux.

Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 28.12500% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 88.66%. Comparing base (2f4ac45) to head (04a9ddb).

Files Patch % Lines
...backends/qemu/linux/qemu_platform_detail_linux.cpp 26.92% 19 Missing ⚠️
...orm/backends/qemu/qemu_virtual_machine_factory.cpp 0.00% 4 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           fix-get-bridged    #3463      +/-   ##
===================================================
- Coverage            88.80%   88.66%   -0.14%     
===================================================
  Files                  254      254              
  Lines                14115    14139      +24     
===================================================
+ Hits                 12535    12537       +2     
- Misses                1580     1602      +22     

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

@luis4a0 luis4a0 force-pushed the qemu-bridging branch 3 times, most recently from 4c55b42 to da6e35c Compare April 12, 2024 14:09
@luis4a0 luis4a0 force-pushed the qemu-bridging branch 3 times, most recently from 0cb2e99 to 15de003 Compare April 19, 2024 12:59
@luis4a0 luis4a0 force-pushed the qemu-bridging branch 3 times, most recently from 837f43c to 7c3919f Compare April 24, 2024 11:42
CMakeLists.txt Show resolved Hide resolved
@@ -247,7 +238,7 @@ auto mp::LXDVirtualMachineFactory::networks() const -> std::vector<NetworkInterf
ret.push_back(std::move(network));

for (auto& net : ret)
if (net.needs_authorization && find_bridge_with(ret, net.id) != ret.cend())
if (net.needs_authorization && MP_BACKEND.find_bridge_with(ret, net.id) != ret.cend())
net.needs_authorization = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to match https://github.com/canonical/multipass/pull/3463/files#diff-77064bb2fbd2589b9a34679c3e6bde02dc7ad8b0b22931195d4d687e8aef2720R232? It makes it easier to see that the logic is the same in both places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, changed in the base branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

This still isn't changed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, sorry, I didn't get it. I changed it as you propose, but I used &= instead of = to maintain exactly the same logic (i.e., the same exact truth table).

src/platform/backends/shared/linux/backend_utils.cpp Outdated Show resolved Hide resolved

std::string mp::QemuPlatformDetail::bridge_name_for(const std::string& iface_name) const
{
return MP_BACKEND.bridge_name(iface_name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really understand what is going on here. This bridge_name_for thing has become pretty complex. This is what I see:

  1. the daemon calls VirtualMachineFactory::bridge_name_for. This is implemented to:
    1. return an empty string by default.
      1. this covers libvirt and VirtualBox, which have no specific implementation
    2. In LXD, it returns mp::Backend::bridge_name().
    3. In QEMU, it delegates on QemuPlatform::bridge_name_for, which:
      1. returns an empty string by default (covers macOS, as there is no specific implementation there)
      2. again calls mp::Backend::bridge_name() on Linux
    4. On Hyper-V, it incorrectly returns a hardcoded "External Virtual Switch" string (bug we've discussed)

This complexity is complemented by tests and mocks. But the only functional bit here is mp::Backend::bridge_name(), on Linux, where we create bridges. However, and this is the crucial part, IIANM this function shouldn't be used at all in the first place! The daemon should not be looking for the bridge based on the name at all, but based on its members, as we've established when we discussed the bug in Hyper-V.

Note that information on bridge members is readily available on our return from VirtualMachineFactory::networks(). We just need to run a find that is the same for all backends. And this find is implemented. It's the one you just moved here.

So you could just replace this call [https://github.com/canonical/multipass/blob/main/src/daemon/daemon.cpp#L3523] with a call to find_bridge_with. That would fix the behavior and get rid of all this code... Am I missing something??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @ricab, thanks! Well, what you are proposing is exactly what I am implementing as the fix to the Hyper-V bug here. What do you think in finishing that fix, merging and then rebasing this branch on top of that? That way, the history will reflect exactly what change does what and this PR will only add bridging to QEMU on Linux.

Otherwise, I can fix everything here. The resulting code will be the same but, you know, the change here can be seen as a drive-by change.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, I can leave that here, merge this and fix later on the other PR. In any case, both PR's will go to 1.14 IIRC.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I looked at that PR but did not see this. And since this one is adding to the bridge_name stuff... But OK, yes, what you propose is perfectly fine! As long as it does the right thing and removes the obsolete code in the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, I'll let you know when I commit to the other PR. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, this was all addressed in the other PR. I changed the base of this PR, so now it's on top of the get fix.

This is not anymore needed because networks() is implemented in
both Linux and macOS.
This commit removes expectations on throwing from
add_network_interface() and networks() tests.
@luis4a0 luis4a0 changed the base branch from main to fix-get-bridged May 10, 2024 13:03
@luis4a0
Copy link
Contributor Author

luis4a0 commented May 10, 2024

Hey @sharder996! Thanks for the review! I addressed all your comments, plus rebasing on the fix for get. Now the code should look better, so it's ready for another round of review. Thanks!

Copy link
Contributor

@sharder996 sharder996 left a comment

Choose a reason for hiding this comment

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

Ok, just a few more questions. Otherwise, the code looks good, but I am unable to functionally test since my laptop running Linux died and I haven't setup a replacement yet.

@luis4a0
Copy link
Contributor Author

luis4a0 commented May 13, 2024

Hey @sharder996! I addressed your two points. this is ready for another round of review. Thanks!

Copy link
Collaborator

@townsend2010 townsend2010 left a comment

Choose a reason for hiding this comment

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

Hey @luis4a0,

Just a couple of copyright things inline below. :) Thanks!

* QEMU Bridge Helper
*
* Copyright IBM, Corp. 2011
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a Copyright (C) Canonical, Ltd. here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, added.

* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
* Richa Marwaha <rmarwah@linux.vnet.ibm.com>
* Corey Bryant <coreyb@linux.vnet.ibm.com>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Feel free to add your name here too, but up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I didn't make functional changes. But I added it in order to blame someone if something goes wrong ;)

It is a stripped-down version of the QEMU bridge helper.
@luis4a0
Copy link
Contributor Author

luis4a0 commented May 14, 2024

@sharder996 I addressed the point I didn't address in the last round, so this is ready again for review. Thanks!

@sharder996
Copy link
Contributor

@luis4a0 Got my PC up and dual-booting with Ubuntu so I did some more functional testing. There are a couple of things that I noticed that seem a bit odd:

  1. If I take a snapshot of an instance before and after setting local.foo.bridged=true, then restore the first snapshot (before adding the bridge) and then restore the second snapshot (after adding the bridge), when I start the instance the bridge does not get initialized. Only after restarting the instance does the bridge come up.

  2. Also, since I recently moved I am on a different network and had to create a new bridge for that network. As such, I have an extra bridge in multipass networks which was for the old network and does nothing. Deleting the bridge with ip link will make it go away, but when I restart the Multipass daemon it comes back.

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.

None yet

4 participants