Skip to content

Commit bf0547b

Browse files
committed
EXPERIMENTAL Hotplug memory for real
Changing maxmem property of a running domain allows qmemman to read new information and balance appropriately. For the maxmem property to accurately reflect current state for clients to query, it is forbidden to change it for a running non memory balanced domain.
1 parent fb06e73 commit bf0547b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

qubes/vm/qubesvm.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,6 +2898,33 @@ def create_qdb_entries(self):
28982898

28992899
self.fire_event("domain-qdb-create")
29002900

2901+
@qubes.events.handler("property-pre-set:maxmem")
2902+
def on_property_pre_set_maxmem(self, event, name, newvalue, oldvalue=None):
2903+
# pylint: disable=unused-argument
2904+
if newvalue == oldvalue:
2905+
return
2906+
if not self.is_halted() and not self.is_memory_balancing_possible():
2907+
raise qubes.exc.QubesVMNotHaltedError(
2908+
"Can't change maxmem of VM {!s}, because it's Halted.".format(
2909+
self
2910+
)
2911+
)
2912+
2913+
@qubes.events.handler("property-set:maxmem")
2914+
def on_property_set_maxmem(self, event, name, newvalue, oldvalue=None):
2915+
# pylint: disable=unused-argument
2916+
if not newvalue or newvalue == oldvalue:
2917+
return
2918+
if not (
2919+
qmemman_present and self.use_memory_hotplug and self.is_running()
2920+
):
2921+
return
2922+
self.app.vmm.xs.write(
2923+
"",
2924+
f"/local/domain/{self.xid}/memory/hotplug-max",
2925+
str(newvalue * 1024),
2926+
)
2927+
29012928
# TODO async; update this in constructor
29022929
def _update_libvirt_domain(self):
29032930
"""Re-initialise :py:attr:`libvirt_domain`."""

0 commit comments

Comments
 (0)