From 4cf0a6185895d4ebd939c09ba242eaab89d0a0e2 Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Thu, 22 Jul 2010 14:54:34 +0200 Subject: [PATCH] Before restoring DVM, check for available xen memory As we already do xm mem-set 0 800 in qubes_core, this is a correct check. Now, there should be no errors from qubes_restore in normal circumstances. --- dom0/pendrive_swapper/qfilexchgd | 10 ++++++++++ dom0/restore/Makefile | 9 +++++++-- dom0/restore/xenfreepages.c | 18 ++++++++++++++++++ rpm_spec/core-dom0.spec | 3 ++- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 dom0/restore/xenfreepages.c diff --git a/dom0/pendrive_swapper/qfilexchgd b/dom0/pendrive_swapper/qfilexchgd index be7f4650..03d3cc8f 100755 --- a/dom0/pendrive_swapper/qfilexchgd +++ b/dom0/pendrive_swapper/qfilexchgd @@ -187,6 +187,16 @@ class DomainState: def handle_transfer_disposable(self, transaction_seq): + mem_for_dvm = 400 + xenfreepages_s = subprocess.Popen(["/usr/lib/qubes/xenfreepages"],stdout=subprocess.PIPE).stdout.readline() + xenfree_mb = int(xenfreepages_s)*4096/1024/1024 + if xenfree_mb < mem_for_dvm: + errmsg = 'Not enough memory to create DVM: ' + errmsg +='have ' + str(xenfree_mb) + 'MB, need ' + errmsg +=str(mem_for_dvm) + 'MB. Terminate some appVM and retry.' + subprocess.call(['/usr/bin/kdialog', '--sorry', errmsg]) + return False + qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_writing() qvm_collection.load() diff --git a/dom0/restore/Makefile b/dom0/restore/Makefile index e279bbb6..e5f1addb 100644 --- a/dom0/restore/Makefile +++ b/dom0/restore/Makefile @@ -1,9 +1,14 @@ CC=gcc -all: qubes_restore xenstore-watch +all: qubes_restore xenstore-watch xenfreepages qubes_restore: qubes_restore.o $(CC) -o qubes_restore qubes_restore.o -lxenstore xenstore-watch: xenstore-watch.o $(CC) -o xenstore-watch xenstore-watch.o -lxenstore + +xenfreepages: xenfreepages.o + $(CC) -o xenfreepages xenfreepages.o -lxenctrl + clean: - rm -f *.o *~ qubes_restore xenstore-watch + rm -f *.o *~ qubes_restore xenstore-watch xenfreepages + diff --git a/dom0/restore/xenfreepages.c b/dom0/restore/xenfreepages.c new file mode 100644 index 00000000..ced36dbb --- /dev/null +++ b/dom0/restore/xenfreepages.c @@ -0,0 +1,18 @@ +#include +#include +#include +struct xen_sysctl_physinfo xphysinfo; +main() +{ + int handle = xc_interface_open(); + if (handle == -1) { + perror("xc_interface_open"); + exit(1); + } + if (xc_physinfo(handle, &xphysinfo)) { + perror("xc_physinfo"); + exit(1); + } + printf("%lld", xphysinfo.free_pages); + return 0; +} diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index ef2d1ed5..456d959c 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -79,7 +79,7 @@ cp aux-tools/remove_appvm_appmenus.sh $RPM_BUILD_ROOT/usr/lib/qubes cp pendrive_swapper/qubes_pencmd $RPM_BUILD_ROOT/usr/lib/qubes cp restore/xenstore-watch restore/qvm-create-default-dvm $RPM_BUILD_ROOT/usr/bin -cp restore/qubes_restore $RPM_BUILD_ROOT/usr/lib/qubes +cp restore/qubes_restore restore/xenfreepages $RPM_BUILD_ROOT/usr/lib/qubes cp restore/qubes_prepare_saved_domain.sh $RPM_BUILD_ROOT/usr/lib/qubes mkdir -p $RPM_BUILD_ROOT/var/lib/qubes @@ -221,3 +221,4 @@ fi /usr/lib/qubes/qubes_restore /usr/lib/qubes/qubes_prepare_saved_domain.sh /etc/xen/scripts/block.qubes +%attr(4750,root,qubes) /usr/lib/qubes/xenfreepages