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.
This commit is contained in:
Rafal Wojtczuk 2010-07-22 14:54:34 +02:00 committed by Joanna Rutkowska
parent a5f11913be
commit 4cf0a61858
4 changed files with 37 additions and 3 deletions

View File

@ -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()

View File

@ -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

View File

@ -0,0 +1,18 @@
#include <xenctrl.h>
#include <stdio.h>
#include <stdlib.h>
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;
}

View File

@ -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