From 0c0f34ba9b6c3f5e437600c60f44af407ba890cf Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Tue, 13 Jul 2010 04:32:42 +0200 Subject: [PATCH] DVM: manage savefiles Instead of hardcoded savefile name, use a symlink in /var/run/qubes. Tools should set this symlink to a correct savefile. Also, test whether the savefile is older than the template root.img. --- dom0/init.d/qubes_core | 23 ++++++++++++++++++++++- dom0/pendrive_swapper/qfilexchgd | 15 ++++++++++++++- rpm_spec/core-dom0.spec | 2 ++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/dom0/init.d/qubes_core b/dom0/init.d/qubes_core index 043c456b..8dc9a10c 100755 --- a/dom0/init.d/qubes_core +++ b/dom0/init.d/qubes_core @@ -16,7 +16,27 @@ # Source function library. . /etc/rc.d/init.d/functions - +setup_dvm_files() +{ + ROOT=/var/lib/qubes/dvmdata/savefile_root + DEFAULT=/var/lib/qubes/dvmdata/default_savefile + if ! [ -f $DEFAULT ] ; then return ; fi + if ! [ -f $ROOT ] ; then return ; fi + if [ $ROOT -nt $DEFAULT ] ; then + echo DVM require reconfiguration + return + fi + if [ -f /var/lib/qubes/dvmdata/dont_use_shm ] ; then + ln -s $DEFAULT /var/run/qubes/current_savefile + else + mkdir -m 770 /dev/shm/qubes + chown root.qubes /dev/shm/qubes + cp $DEFAULT /dev/shm/qubes/current_savefile + chown root.qubes /dev/shm/qubes/current_savefile + chmod 660 /dev/shm/qubes/current_savefile + ln -s /dev/shm/qubes/current_savefile /var/run/qubes/current_savefile + fi +} start() { @@ -35,6 +55,7 @@ start() chmod 660 /var/run/qubes/dispVM_seq xm mem-set 0 800 cp /var/lib/qubes/qubes.xml /var/lib/qubes/backup/qubes-$(date +%F-%T).xml + setup_dvm_files touch /var/lock/subsys/qubes_core success echo diff --git a/dom0/pendrive_swapper/qfilexchgd b/dom0/pendrive_swapper/qfilexchgd index 4874b7ed..9068cf10 100755 --- a/dom0/pendrive_swapper/qfilexchgd +++ b/dom0/pendrive_swapper/qfilexchgd @@ -34,6 +34,7 @@ from qubes.qubes import QubesDaemonPidfile filename_seq = 50 pen_cmd = '/usr/lib/qubes/qubes_pencmd' disposable_domains_dict = {} +current_savefile = '/var/run/qubes/current_savefile' def get_next_filename_seq(): global filename_seq @@ -196,7 +197,7 @@ class DomainState: qvm_collection.unlock_db() return False retcode = subprocess.call(['/usr/bin/qubes_restore', - '/dev/shm/qubes/disposable_savefile', + current_savefile, '-c', vm.label.color, '-i', vm.label.icon, '-l', str(vm.label.index)]) @@ -230,8 +231,20 @@ class DomainState: return True def handle_transfer(self, vmname, transaction_seq): + dvmdata_dir = '/var/lib/qubes/dvmdata/' if vmname != 'disposable': return self.handle_transfer_regular(vmname, transaction_seq) + if not os.path.isfile(current_savefile): + subprocess.call(['/usr/bin/kdialog', '--sorry', 'There is no current savefile defined; run Qubes Manager']) + return False + if not os.path.isfile(dvmdata_dir+'default_savefile') or not os.path.isfile(dvmdata_dir+'savefile_root'): + subprocess.call(['/usr/bin/kdialog', '--sorry', 'Default savefile misconfiguration; run Qubes Manager']) + return False + dvm_mtime = os.stat(current_savefile).st_mtime + root_mtime = os.stat(dvmdata_dir+'savefile_root').st_mtime + if dvm_mtime < root_mtime: + subprocess.call(['/usr/bin/kdialog', '--sorry', 'Your current savefile is outdated, as you have updated the template VM. Run Qubes Manager and recreate the savefile']) + return False return self.handle_transfer_disposable(transaction_seq) class XS_Watcher: diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index 4de584e6..cdfd5e67 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -86,6 +86,7 @@ mkdir -p $RPM_BUILD_ROOT/var/lib/qubes/vm-templates mkdir -p $RPM_BUILD_ROOT/var/lib/qubes/appvms mkdir -p $RPM_BUILD_ROOT/var/lib/qubes/backup +mkdir -p $RPM_BUILD_ROOT/var/lib/qubes/dvmdata mkdir -p $RPM_BUILD_ROOT/usr/share/qubes/icons cp icons/*.png $RPM_BUILD_ROOT/usr/share/qubes/icons @@ -205,6 +206,7 @@ fi %attr(770,root,qubes) %dir /var/lib/qubes/vm-templates %attr(770,root,qubes) %dir /var/lib/qubes/appvms %attr(770,root,qubes) %dir /var/lib/qubes/backup +%attr(770,root,qubes) %dir /var/lib/qubes/dvmdata %dir /usr/share/qubes/icons/*.png /etc/yum.repos.d/qubes.repo /usr/bin/qubes_setup_dnat_to_ns