Skip to content

VM manager: keep hand-set hostdev guest address on form save; fix multifunction=off read as on - #2811

Open
luuvasara wants to merge 1 commit into
unraid:masterfrom
luuvasara:fix/vm-hostdev-roundtrip
Open

luuvasara wants to merge 1 commit into
unraid:masterfrom
luuvasara:fix/vm-hostdev-roundtrip

Conversation

@luuvasara

@luuvasara luuvasara commented Nov 1, 2026 •

Copy link
Copy Markdown

Note for reviewers: this is a proof of concept. It shows that the problem is real, reproducible and fixable with a small change; refining the code is welcome, and it was tested through the real VM form on Unraid 7.3.4 (see Tests). The more useful discussion, though, is why saving the VM form has been allowed to throw away settings people made by hand for years, although the change that introduced this code (#361, 2018-08-13) says its purpose was "keeping custom XML modifications done by the user while the VM gets updated via the GUI", and how Unraid would prefer to resolve it, with this approach or a better one. In particular:

  • data loss of user configuration: a one-field form save silently removes hand-set settings (PCI guest addresses and aliases, clock timers, sound address and codec, input devices, graphics attributes), with no warning and no way back except a copy the user happened to make;
  • the uncertainty it leaves users with: they do not know which edits survive a form save, so they keep XML backups, re-apply edits after every change, or avoid the form view altogether (quotes below);
  • the workaround culture that grew around it: "copy your XML first", "paste your changes in again", a second editor in a container, user scripts that patch the XML. None of these is documented by Unraid, and each one has to be rediscovered by every new user;
  • the time since the stated goal: the goal was written in 2018, the code comment // settings not in the GUI, but maybe customized is still in the function, and the same report has been filed every year since 2017 (11 of the 12 years 2015-2026, figures below), while each later change made the form own one more section without saying that the leftovers should be discarded;
  • a design question for the maintainers: which settings should the form own, which should it carry through untouched, and should unknown XML be preserved as a rule (this PR does it per section, with a deliberately small scope).

Two small fixes in the VM manager, related to https://forums.unraid.net/topic/111226/ .

  1. libvirt.php (hostdev read-back): $x ?? "" ? "on" : "off" parses as ($x ?? "") ? "on" : "off", so multifunction='off' was shown as "on". It now returns "on" only for multifunction='on'.
  2. libvirt_helpers.php array_update_recursive(): when a passthrough device in the form matches one in the stored XML, the stored entry is replaced by the regenerated one, so a guest <address> set by hand in XML view is lost on the next form save. The stored address is now kept when the form did not generate one. Values the form owns are unchanged: boot order and ROM come from the form as before, and a stored multifunction address is not kept (so switching Multifunction to Off still removes it). Devices removed in the form are still removed; new devices get nothing.

Companion PR #2812 keeps the clock, sound, input and graphics settings the form has no field for; the two touch different lines and merge in either order.

Tests

  • Both changed code paths, run with PHP from master and from this branch: multifunction on/off/absent; a hand-set guest address is kept; an address the form sets wins; a device removed in the form is still removed; a new device gets nothing; switching Multifunction from On to Off drops the stored multifunction address. Master shows multifunction='off' as "on" and drops the hand-set address.
  • On Unraid 7.3.4 through the real VM form (together with the companion PR): libvirt accepted every saved definition. The hostdev path itself was not exercised there because the test server has no PCI device to pass through.

Background: prior reports and timeline

array_update_recursive() replaces a stored passthrough device by the regenerated one when the form contains the same device, and the form writes a guest <address> only for its own multifunction layout and a few Q35 cases. The multifunction read-back in libvirt.php tests the attribute for truthiness. The list below is what was found in public threads, GitHub and the release notes.

Pattern

  • 32 reports (a post saying that a form save or GUI edit overwrote, reverted or removed XML the user had edited by hand, or asking for that to stop) in public threads from 2015 to 2026, any section: 2015: 1, 2017: 2, 2018: 1, 2019: 6, 2020: 5, 2021: 4, 2022: 2, 2023: 3, 2024: 2, 2025: 4, 2026: 2 (forum 18 in 10 threads, Reddit 12 in 8 threads, other 2). No report found for 2016.
  • 9 of the 32 are about this PR's subject (hand-set hostdev guest address, bus/function, multifunction, aliases): 2020: 2, 2021: 2, 2022: 1, 2023: 1, 2025: 1, 2026: 2. None of them mentions multifunction='off' showing as On; that part is visible only in the code.
  • Answers received (25 posts): re-apply after every save 7, keep a copy of the XML 7, use a different editor 5, edit only in XML view 2, patch with a script 2, use a tool in the guest 2. Seven replies came from forum staff roles or a staff-like account (2015 to 2024-05-27); none after that. One reply, 2024-05-27 ("Multifunction is in next release"), is the only mention of a change.
  • Code: the multifunction read-back has tested a string for truthiness since it was added on 2023-10-14 (->value ? "on" : "off", 83d02ea, PR VM multifunction support #1464, merged 2023-10-17), so multifunction='off' has been read as On since then; the current spelling nodeValue ?? "" ? "on" : "off" is from b844237 (2025-02-17). The hostdev replace in array_update_recursive() dates from 2018-08-15 (345a640, part of VMs: preserve XML custom settings in VM config updates #361). Checked against webgui master 9754759 (2026-10-29).

Timeline (items relevant to this PR)

Date Event Link
2015-08-15 First report found: custom lines for USB controller pass-through "are removed" by any GUI edit; a forum moderator: "This is an acknowledged issue, but there is no timescale for a fix/workaround." https://forums.unraid.net/topic/40527-xml-edits-are-wiped-every-time-a-vm-is-edited/
2015-08-17 A forum account (not listed in the current Staff Directory): "Yes, this is a known issue. XML editor is for testing "not yet built in" functionality. It is "use at your own risk"" and "We can put the indication in there to make sure folks are aware." same
2018-08-13 #361 opened by its author: "This update is about keeping custom XML modifications done by the user while the VM gets updated via the GUI". Merged 2018-08-23; the only comment from the Lime Technology account is "Amazing" #361
2018-08-14/15 In #361 the author: "I need to make support for USB + PCI devices, these are not properly added or removed." The stored hostdev is replaced by the form's (345a640) same
2020-02-03 Request: "If any edit is done via the GUI, it will revert the bus + function back to the default method, requiring additional edits." https://forums.unraid.net/topic/88139-automatic-vm-xml-amendment-for-multi-function-devices-eg-group-gpu-hdmi-audio-to-the-same-bus
2020-07-17 Blog guide: "If you make any custom changes to a VM XML file, the next time you make an edit to the same VM via the GUI editor, those changes will be wiped." https://mediaserver8.blogspot.com/2020/07/problems-passing-through-gpu-to-unraid.html
2021-05-09 "if I forget and make any edit via the VM template in the webUI, then it will "undo" this multifunction option." https://forums.unraid.net/topic/108358-vm-template-add-ui-option-for-configuring-multifunctionon-for-pcie-passthrough-devices/
2021-07-10 One form save changes the GPU audio function from bus 0x04 to 0x05 and removes every alias; VM "fails to boot". A forum administrator: "Unraid does not preserve any custom edits to the XML" https://forums.unraid.net/topic/111226-vm/
2022-07-17 Reddit answer: "You will probably need to redo the multifunction=on step + ensure that both gpu and audio are on the same bus in the xml afterwards though." https://www.reddit.com/r/unRAID/comments/w1cq94/vm_gpu_passthrough_works_but_does_not_recognize/
2023-10-14 83d02ea "Initial commit of multifunction support" (#1464, merged 2023-10-17, 0 comments): adds the form option and the read-back that treats the string "off" as On #1464
2024-02-10 A forum administrator, on a GPU whose audio sat on another bus: "You will need to do a manual edit of the XML and if you make an update via the forms page you will loose the changes." https://forums.unraid.net/topic/153043-cant-install-amd-drivers-on-windows11-vm/
2024-03-29 The same administrator lists "Better XML persistance" among possible features; a forum moderator replies "silently discarded or reverted is not a solution." https://forums.unraid.net/topic/159936-vm-manager-feature-requests/
2024-05-27 A user: "Often time i have to go in and edit xml or swap to fix a change and lose my XML edits."; administrator reply: "Multifunction is in next release." same
2025-02-17 b844237 "Fix: PHP Fixes" rewrites the read-back line as nodeValue ?? "" ? "on" : "off" (same behaviour) commit b844237
2025-08-03 "It would be good if we could set a manual override for the guest address for hostdevs from the UI form view. Or at least prevent the form view from removing manual address edits done in the XML view." and "They also get removed if added via XML and then the VM is edited in the form view." No reply in the thread (last post 2026-03-06) https://forums.unraid.net/topic/159936-vm-manager-feature-requests/
2026-01-10 "And it keeps on happening 5 years later... even on v7.2.3..." https://forums.unraid.net/topic/111226-vm/
2026-05-08 "This issue should be looked at by the dev team. We cannot have the GUI breaking up what is done in the XML or other way around. Not acceptable." same
2026-11-01 This PR link to add

Reports without a fix or staff response

Official guidance

  • Docs, "VM setup": the 7.x feature list includes "Inline XML view/edit: Instantly view or copy the XML generated by the WebGUI; switch to XML mode for advanced edits." The passages I read do not say whether a later form save keeps those edits (the page was read in search-selected passages, about 8 of 25 thousand characters).
  • 2015-08-17, forum account (not listed in the Staff Directory): "XML editor is for testing "not yet built in" functionality. It is "use at your own risk"" and the advice to copy the XML first.
  • 2021-07-10, forum administrator: "Unraid does not preserve any custom edits to the XML".
  • 2024-02-10, forum administrator: "if you make an update via the forms page you will loose the changes."
  • 6.11.0 release notes (2022-09-23): "Added support for specifying custom VNC ports in VM manager form editor. Custom port number specified using XML editor will be preserved when switching to forms-based editor." and "WebGUI: Fix: preserve vnc port settings" (https://docs.unraid.net/unraid-os/release-notes/6.11.0/). That is the only release-note statement about preserving XML edits that I found; it covers one attribute.
  • Code, array_update_recursive(): // settings not in the GUI, but maybe customized.

Impact

  • VM does not start after a one-field form save (2021-07-10): "if I make a single change via the unRAID web GUI to the VM (while VM is off), unRAID significantly changes the XML version of the VM config and breaks the VM (fails to boot)." and "I literally can't make changes to the VM after it's been created without it failing to boot on the next startup." The posted before/after shows the GPU audio function moving from bus 0x04 to bus 0x05 and every alias removed.
  • GPU pass-through that needs the video and audio functions on one bus: "This can cause compatibility / performance issues in some cases, most notably but not exclusive to MacOS VM." (2020-02-03); "This can cause all kinds of issues so needs to be fixed." (2020-07-17); a forum administrator on a card whose drivers would not install: "I suspect you need to change to multifunction as AMD expects them to be on the same bus." (2024-02-10); a multi-port network card seen by the guest as one interface unless the four functions share one slot, "if I forget and make any edit via the VM template in the webUI, then it will "undo" this multifunction option." (2021-05-09).
  • A Windows licence: a bug report on a Q35 VM that stopped booting after the graphics setting was changed in the form (posted 2024-07, 6.12.10; opening post only, replies did not render): "I have already lost my Windows Key because of hardware changes due to this. A XML copy of previous settings when editing would a nice Feature Request." That report is about the graphics change, not proven to be this loss. I found no thread that ties a changed PCI guest address after a form save to a Windows reactivation or a driver reinstall, so this PR does not claim it.
  • Users keep backups and avoid the form: "I end up copying the XML and saving it as a backup." (2019-12-07); "I make backups of my XML configs so if I accidentally make GUI edits, I can fix." (2020-07-30); "I've developed a habit of making a copy of my xml before any edits, then pasting in the changed bits as necessary." (2025-06-29); "since then I'm scared to change the storage while it's functional lol" (2023-09-29, after a different edit broke a VM); a user on 2025-01-06 asking "I think there was a new feature to add XML changes so GUI changes didn't change them when editing here?".
  • Others give up on the form: "I just use the virt-manager docker image to edit my VM settings." (2019-12-07); "Totally agree" with calling the editor the "worst VM "editor" ever made" (2019-12-07); an external script exists only to redo the GPU layout: "those are overwritten if I make any changes in Unraid's form view" (README of a GPU XML fixer, last push 2023-08-12).

Why a fix in the current release line
Unraid 8 was announced on 2026-08-17 as a base-OS change ("Unraid 8 is moving to a Fedora base, built on Universal Blue's uCore."), with a closed beta, open beta and release candidates still to come and no release date ("it'll ship when it's ready", https://unraid.net/blog/unraid-8-announced). Unraid's support policy covers "the current public minor series" and "the previous public minor series" (https://docs.unraid.net/unraid-os/updating-unraid/release-types/); a change merged now reaches servers through those releases.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 45855e84-f670-43ba-a94c-c34875bc7e64
Commits

Reviewing files that changed from the base of the PR and between 9754759 and f118961.

Files selected for processing: 2
  • emhttp/plugins/dynamix.vm.manager/include/libvirt.php
  • emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant