| 977 | } |
| 978 | |
| 979 | bool RuntimeManager::ApplyForwards(const std::string& vm_id) { |
| 980 | auto session = FindSession(vm_id); |
| 981 | if (!session) return false; |
| 982 | auto record = store_.Get(vm_id); |
| 983 | if (!record) return false; |
| 984 | |
| 985 | // Mirror the persisted spec onto the live session so a guest-initiated |
| 986 | // reboot path (which copies session->spec into the next start) does not |
| 987 | // lose the change before the next StartVm refresh from store_. |
| 988 | session->spec.host_forwards = record->spec.host_forwards; |
| 989 | session->spec.guest_forwards = record->spec.guest_forwards; |
| 990 | |
| 991 | ipc::Message message; |
| 992 | message.channel = ipc::Channel::kControl; |
| 993 | message.kind = ipc::Kind::kRequest; |
| 994 | message.type = "runtime.update_network"; |
| 995 | message.vm_id = vm_id; |
| 996 | // The runtime expects link_up alongside the forward set; we never want to |
| 997 | // bring the link down here, only re-apply forwards on top of it. |
| 998 | message.fields["link_up"] = "true"; |
| 999 | // Host -> Guest (qemu hostfwd, listens on host). |
| 1000 | message.fields["forward_count"] = std::to_string(record->spec.host_forwards.size()); |
| 1001 | for (size_t i = 0; i < record->spec.host_forwards.size(); ++i) { |
| 1002 | message.fields["forward_" + std::to_string(i)] = |
| 1003 | record->spec.host_forwards[i].ToHostfwd(); |
| 1004 | } |
| 1005 | // Guest -> Host (qemu guestfwd, exposes a host service inside the slirp |
| 1006 | // subnet at guest_ip:guest_port). Same effective set as BuildRuntimeArgs |
| 1007 | // so a `host.llm_proxy.set` follow-up can re-publish the proxy guestfwd |
| 1008 | // to running VMs without a reboot. |
| 1009 | const auto effective_gf = EffectiveGuestForwards(record->spec); |
| 1010 | message.fields["guestfwd_count"] = std::to_string(effective_gf.size()); |
| 1011 | for (size_t i = 0; i < effective_gf.size(); ++i) { |
| 1012 | message.fields["guestfwd_" + std::to_string(i)] = effective_gf[i].ToGuestfwd(); |
| 1013 | } |
| 1014 | return SendRuntime(session, message); |
| 1015 | } |
| 1016 | |
| 1017 | bool RuntimeManager::ApplySharedFolders(const std::string& vm_id) { |
| 1018 | auto session = FindSession(vm_id); |
no test coverage detected