Skip to content

Support OpenWRT and wmediumd snapshot/restore - #3197

Open
Elie-Kh wants to merge 1 commit into
google:mainfrom
Elie-Kh:openwrt-snapres-support
Open

Elie-Kh wants to merge 1 commit into
google:mainfrom
Elie-Kh:openwrt-snapres-support

Conversation

@Elie-Kh

@Elie-Kh Elie-Kh commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Enable proper snapshot save and restore for OpenWRT AP instances and their vhost-user mac80211_hwsim connections in wmediumd:

  • Patch external wmediumd to implement vhost-user device state save (SLEEP + GET_VRING_BASE + DEVICE_STATE) and restore (DEVICE_STATE + SET_VRING_ADDR + SET_VRING_BASE + SET_VRING_KICK + SET_VRING_CALL + WAKE) callbacks so existing vhost-user clients can reconnect and resume without losing station/queue state or spinning on stale EPOLLHUP events.
  • Update CvdBootStateMachine to explicitly resume the OpenWRT crosvm instance (crosvm resume <sock> --full) upon guest restore completion, replacing the previous service network restart LuciRPC workaround.
  • Check that the OpenWRT snapshot directory exists before passing --restore to crosvm when launching OpenWrt, falling back to a cold boot with a warning if absent.
  • Cache the discovered OpenWRT IP address in OpenwrtControlServiceImpl so IP lookups continue to succeed after restoring from a snapshot when launcher.log no longer emits fresh boot logs.

Bug: 335361533
Test: Verified snapshot take and restore with OpenWRT Wi-Fi enabled
TAG=agy
CONV=5df97b60-361a-4803-9dc9-6c486b536214

@Elie-Kh
Elie-Kh requested a review from Databean September 17, 2026 23:22
@Databean
Databean requested a review from jemoreira September 18, 2026 00:21

@Databean Databean left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Added @jemoreira for the wmediumd changes for vhost-user experience

Comment on lines +1 to +5
From 4d439a3686758dde1a6707781988f2a4efdd57f3 Mon Sep 17 00:00:00 2001
From: Elie Kheirallah <khei@google.com>
Date: Fri, 4 Sep 2026 17:40:12 +0000
Subject: [PATCH] wmediumd: Implement device state save and restore for
snapshot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a plan to send this wmediumd upstream as well? Honestly I'm not sure what the upstream is at this point, https://github.com/ramonfontes/wmediumd looks like it has the most recent changes, but the code imported to Android is based on this version: https://github.com/bcopeland/wmediumd , and that's also what this build_external code references.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's probably worth investigating deltas. If we aren't too divergent from https://github.com/ramonfontes/wmediumd, it might be worthwhile consolidating.

Comment thread base/cvd/cuttlefish/host/commands/run_cvd/boot_state_machine.cc Outdated
}
}
if (openwrt_restored) {
const auto openwrt_sock = instance_.OpenwrtCrosvmSocketPath();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have WaitForUnixSocket with a ListeningWithoutConnect variation. The difference is one will periodically try to connect, and the other will not.

Comment on lines +430 to +437
SubprocessOptions(), WEXITED);
CHECK(infop.has_value())
<< "Failed to execute crosvm resume for OpenWRT: "
<< infop.error();
CHECK_EQ(infop->si_code, CLD_EXITED);
CHECK_EQ(infop->si_status, 0)
<< "crosvm resume for OpenWRT returned non-zero code "
<< infop->si_status;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can use the fewer-arguments version of Execute which has comparable behavior and a simpler return type:

int Execute(std::vector<std::string> command) {
// NOLINTNEXTLINE(misc-include-cleaner): <sys/wait.h> provides siginfo_t
const Result<siginfo_t> result =
Execute(std::move(command), SubprocessOptions(), WEXITED);
if (result.has_value() && result->si_code == CLD_EXITED) {
return result->si_status; // NOLINT(misc-include-cleaner): <signal.h>
} else {
return -1;
}
}

@Elie-Kh
Elie-Kh force-pushed the openwrt-snapres-support branch 5 times, most recently from ef38f2d to 2ce0b5d Compare September 18, 2026 19:41
Enable proper snapshot save and restore for OpenWRT AP instances and
their vhost-user mac80211_hwsim connections in wmediumd:

- Patch external wmediumd to implement vhost-user device state save
  (SLEEP + GET_VRING_BASE + DEVICE_STATE) and restore (DEVICE_STATE +
  SET_VRING_ADDR + SET_VRING_BASE + SET_VRING_KICK + SET_VRING_CALL +
  WAKE) callbacks so existing vhost-user clients can reconnect and
  resume without losing station/queue state or spinning on stale EPOLLHUP
  events.
- Update CvdBootStateMachine to explicitly resume the OpenWRT crosvm
  instance (`crosvm resume <sock> --full`) upon guest restore completion,
  replacing the previous `service network restart` LuciRPC workaround.
- Check that the OpenWRT snapshot directory exists before passing
  `--restore` to crosvm when launching OpenWrt, falling back to a cold
  boot with a warning if absent.
- Cache the discovered OpenWRT IP address in OpenwrtControlServiceImpl
  so IP lookups continue to succeed after restoring from a snapshot
  when launcher.log no longer emits fresh boot logs.

Bug: 335361533
Test: Verified snapshot take and restore with OpenWRT Wi-Fi enabled
TAG=agy
CONV=5df97b60-361a-4803-9dc9-6c486b536214
@Elie-Kh
Elie-Kh force-pushed the openwrt-snapres-support branch from 2ce0b5d to 095d508 Compare September 18, 2026 19:42
Comment on lines +4 to +5
Subject: [PATCH] wmediumd: Implement device state save and restore for
snapshot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It occurs to me also that because we don't have an internal build of wmediumd, this PR might cause problems for Google employees trying to use the internal Cuttlefish host tools build to launch non-git_main devices like AOSP builds because they'll be using the latest run_cvd but an older build of wmediumd.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point.. Have we had a precedence of this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two similar cases I can think of, neither with a satisfying / relevant conclusion:

  • secure_env has had additional feature work on git_main, and I'm pushing to get that ported to the github project.
  • netsim has had additional feature work on git_main. We're trying to temporarily roll back shipping netsim in our debian package until netsim finalizes their own github release that we can rely on.

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.

3 participants