Merge branch 'master' of git.qubes-os.org:/var/lib/qubes/git/marmarek/core

This commit is contained in:
Joanna Rutkowska 2011-03-25 15:51:26 +01:00
commit da398e93a8
11 changed files with 182 additions and 25 deletions

4
appvm/.gitignore vendored
View File

@ -1,3 +1,7 @@
qubes_add_pendrive_script
qubes_penctl
qvm-open-in-dvm
dvm_file_editor
qfile-agent
qfile-agent-dvm
qfile-unpacker

View File

@ -31,10 +31,12 @@ if [ $# != 2 ]; then
fi
mkdir -p $APPSDIR
echo "--> Converting Appmenu Templates..."
find $SRCDIR -name "*.desktop" -exec /usr/lib/qubes/convert_apptemplate2vm.sh {} $APPSDIR $VMNAME $VMDIR \;
if [ "$SRCDIR" != "none" ]; then
echo "--> Converting Appmenu Templates..."
find $SRCDIR -name "*.desktop" -exec /usr/lib/qubes/convert_apptemplate2vm.sh {} $APPSDIR $VMNAME $VMDIR \;
/usr/lib/qubes/convert_dirtemplate2vm.sh $SRCDIR/qubes-vm.directory.template $APPSDIR/$VMNAME-vm.directory $VMNAME $VMDIR
/usr/lib/qubes/convert_dirtemplate2vm.sh $SRCDIR/qubes-vm.directory.template $APPSDIR/$VMNAME-vm.directory $VMNAME $VMDIR
fi
echo "--> Adding Apps to the Menu..."
xdg-desktop-menu install $APPSDIR/*.directory $APPSDIR/*.desktop

View File

@ -18,7 +18,7 @@ def main():
print templ, 'is not a template'
sys.exit(1)
for vm in qvm_collection.values():
if vm.is_appvm() and vm.template_vm.qid == tvm.qid:
if vm.template_vm is not None and vm.template_vm.qid == tvm.qid:
vm.create_config_file()
main()

View File

@ -199,6 +199,9 @@ class QubesVm(object):
self.uses_default_netvm = uses_default_netvm
self.netvm_vm = netvm_vm
# Create template_vm property - used in AppVM, NetVM, ProxyVM
self.template_vm = None
# We use it in remove from disk to avoid removing rpm files (for templates)
self.installed_by_rpm = installed_by_rpm
@ -473,6 +476,11 @@ class QubesVm(object):
return os.path.getsize(self.private_img)
def resize_private_img(self, size):
f_private = open (self.private_img, "a+b")
f_private.truncate (size)
f_private.close ()
def create_xenstore_entries(self, xid):
if dry_run:
return
@ -1492,7 +1500,11 @@ class QubesAppVm(QubesCowVm):
self.create_appmenus (verbose)
def create_appmenus(self, verbose):
subprocess.check_call ([qubes_appmenu_create_cmd, self.template_vm.appmenus_templates_dir, self.name])
if self.template_vm is not None:
subprocess.check_call ([qubes_appmenu_create_cmd, self.template_vm.appmenus_templates_dir, self.name])
else:
# Only add apps to menu
subprocess.check_call ([qubes_appmenu_create_cmd, "none", self.name])
def write_firewall_conf(self, conf):
root = xml.etree.ElementTree.Element(

View File

@ -121,19 +121,25 @@ def main():
files_to_backup += file_to_backup(vm.icon_path)
files_to_backup += file_to_backup(vm.conf_file)
#files_to_backup += file_to_backup(vm.dir_path + "/apps")
if vm.is_updateable():
files_to_backup += file_to_backup(vm.dir_path + "/apps")
if os.path.exists (vm.firewall_conf):
files_to_backup += file_to_backup(vm.firewall_conf)
if vm.is_updateable():
sz = vm.get_disk_usage(vm.root_img)
files_to_backup += file_to_backup(vm.root_img, sz)
vm_sz += sz
sz = vm.get_disk_usage(vm.volatile_img)
files_to_backup += file_to_backup(vm.volatile_img, sz)
vm_sz += sz
s = ""
fmt="{{0:>{0}}} |".format(fields_to_display[0]["width"] + 1)
s += fmt.format(vm.name)
fmt="{{0:>{0}}} |".format(fields_to_display[1]["width"] + 1)
s += fmt.format("AppVM" + (" + COW" if vm.is_updateable() else ""))
s += fmt.format("AppVM" + (" + Sys" if vm.is_updateable() else ""))
fmt="{{0:>{0}}} |".format(fields_to_display[2]["width"] + 1)
s += fmt.format(size_to_human(vm_sz))

View File

@ -25,12 +25,14 @@ from qubes.qubes import QubesException
from qubes.qubes import qubes_store_filename
from qubes.qubes import qubes_base_dir
from qubes.qubes import qubes_templates_dir
from qubes.qubes import qubes_appvms_dir
from optparse import OptionParser
import os
import time
import subprocess
import sys
import re
def size_to_human (size):
if size < 1024:
@ -58,8 +60,9 @@ fields = {
"updbl" : {"func": "'Yes' if vm.is_updateable() else ''"},
"template": {"func": "'n/a' if vm.is_template() or vm.is_netvm() else\
backup_collection[vm.template_vm.qid].name"},
"template": {"func": "'n/a' if vm.is_template() or vm.template_vm is None else\
find_template_name(backup_collection[vm.template_vm.qid].name,\
options.replace_template)"},
"netvm": {"func": "'n/a' if vm.is_netvm() else\
('*' if vm.uses_default_netvm else '') +\
@ -102,6 +105,14 @@ def restore_vm_dir (backup_dir, src_dir, dst_dir):
print "*** Error while copying file {0} to {1}".format(backup_src_dir, dest_dir)
exit (1)
def find_template_name(template, replaces):
rx_replace = re.compile("(.*):(.*)")
for r in replaces:
m = rx_replace.match(r)
if m.group(1) == template:
return m.group(2)
return template
def main():
usage = "usage: %prog [options] <backup-dir>"
@ -116,6 +127,12 @@ def main():
parser.add_option ("--skip-conflicting", action="store_true", dest="skip_conflicting", default=False,
help="Do not restore VMs that are already present on the host")
parser.add_option ("--recreate-conf-files", action="store_true", dest="recreate_conf", default=False,
help="Recreate conf files after restore")
parser.add_option ("--replace-template", action="append", dest="replace_template", default=[],
help="Restore VMs using another template, syntax: old-template-name:new-template-name (might be repeated)")
(options, args) = parser.parse_args ()
if (len (args) != 1):
@ -191,12 +208,12 @@ def main():
there_are_conflicting_vms = True
good_to_go = False # Do not overwrite VMs on the host!
if vm.is_appvm():
templatevm_name = vm.template_vm.name
if vm.template_vm is not None:
templatevm_name = find_template_name(vm.template_vm.name, options.replace_template)
template_vm_on_host = host_collection.get_vm_by_name (templatevm_name)
# No template on the host?
if not ((template_vm_on_host is not None) and template_vm_on_host.is_template):
if not ((template_vm_on_host is not None) and template_vm_on_host.is_template()):
# Maybe the (custom) template is in the backup?
template_vm_on_backup = backup_collection.get_vm_by_name (templatevm_name)
@ -279,14 +296,7 @@ def main():
continue
if vm.is_appvm():
restore_vm_file (backup_dir, vm.private_img)
restore_vm_file (backup_dir, vm.icon_path)
restore_vm_file (backup_dir, vm.conf_file)
if vm.is_updateable():
restore_vm_file (backup_dir, vm.root_img)
restore_vm_dir (backup_dir, vm.dir_path, qubes_appvms_dir);
elif vm.is_template():
restore_vm_dir (backup_dir, vm.dir_path, qubes_templates_dir);
else:
@ -323,7 +333,13 @@ def main():
for vm in [ vm for vm in vms_to_restore if vm.is_appvm()]:
print "-> Adding AppVM {0}...".format(vm.name)
template_vm = host_collection.get_vm_by_name(vm.template_vm.name)
template_vm = None
recreate_conf = options.recreate_conf
if vm.template_vm is not None:
template_name = find_template_name(vm.template_vm.name, options.replace_template)
template_vm = host_collection.get_vm_by_name(template_name)
if template_name != vm.template_vm.name:
recreate_conf = True
if not vm.uses_default_netvm:
uses_default_netvm = False
@ -336,27 +352,30 @@ def main():
vm = host_collection.add_new_appvm(vm.name, template_vm,
conf_file=vm.conf_file,
dir_path=vm.dir_path,
updateable=updateable,
label=vm.label)
vm.updateable = updateable
if not uses_default_netvm:
vm.uses_default_netvm = False
vm.netvm_vm = netvm_vm
if template_vm is not None and recreate_conf:
print "--> Recreating config file..."
vm.create_config_file()
vm.create_appmenus(verbose=True)
try:
vm.verify_files()
except QubesException as err:
print "ERROR: {0}".format(err)
print "*** Skiping VM: {0}".vm.name
print "*** Skiping VM: {0}".format(vm.name)
host_collection.pop(vm.qid)
try:
vm.add_to_xen_storage()
except (IOError, OSError) as err:
print "ERROR: {0}".format(err)
print "*** Skiping VM: {0}".vm.name
print "*** Skiping VM: {0}".format(vm.name)
host_collection.pop(vm.qid)

109
dom0/qvm-tools/qvm-grow-private Executable file
View File

@ -0,0 +1,109 @@
#!/usr/bin/python2.6
#
# The Qubes OS Project, http://www.qubes-os.org
#
# Copyright (C) 2011 Marek Marczykowski <marmarek@mimuw.edu.pl>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
from qubes.qubes import QubesVmCollection
from qubes.qubes import QubesException
from optparse import OptionParser
import subprocess
import os
import re
qvm_run_path = "/usr/bin/qvm-run"
def parse_size(size):
units = [ ('K', 1024), ('KB', 1024),
('M', 1024*1024), ('MB', 1024*1024),
('G', 1024*1024*1024), ('GB', 1024*1024*1024),
]
size = size.strip().upper()
if size.isdigit():
return size
for unit, multiplier in units:
if size.endswith(unit):
size = size[:-len(unit)].strip()
return int(size)*multiplier
print "Invalid size: {0}.".format(size)
exit(1)
def main():
usage = "usage: %prog <vm-name> <size>"
parser = OptionParser (usage)
(options, args) = parser.parse_args ()
if (len (args) != 2):
parser.error ("You must specify VM name and new size!")
vmname = args[0]
size = args[1]
qvm_collection = QubesVmCollection()
qvm_collection.lock_db_for_reading()
qvm_collection.load()
qvm_collection.unlock_db()
vm = qvm_collection.get_vm_by_name(vmname)
if vm is None:
print "A VM with the name '{0}' does not exist in the system.".format(vmname)
exit(1)
if vm.is_running() and os.geteuid() != 0:
print "You must be root to grow private.img on running VM."
exit(1)
size_bytes = parse_size(size)
if size_bytes < vm.get_private_img_sz():
print "Cannot shrink private.img ({0} < {1})".format(size_bytes, vm.get_private_img_sz())
exit(1)
try:
vm.resize_private_img(size_bytes)
except (IOError, OSError, QubesException) as err:
print "ERROR: {0}".format(err)
exit (1)
if vm.is_running():
# find loop device
p = subprocess.Popen (["losetup", "--associated", vm.private_img],
stdout=subprocess.PIPE)
result = p.communicate()
m = re.match(r"^(/dev/loop\d+):\s", result[0])
if m is None:
print "ERROR: Cannot find loop device!"
exit(1)
loop_dev = m.group(1)
# resize loop device
retcode = subprocess.check_call(["losetup", "--set-capacity", loop_dev])
retcode = subprocess.check_call([qvm_run_path, "-uroot", vmname,
"resize2fs /dev/xvdb" ])
else:
retcode = subprocess.check_call(["resize2fs", "-f", vm.private_img])
exit (0)
main()

3
qrexec/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
qrexec_agent
qrexec_client
qrexec_daemon

View File

@ -51,9 +51,9 @@ python -m compileall qvm-core qmemman
python -O -m compileall qvm-core qmemman
make -C restore
make -C ../common
make -C ../qrexec
make -C ../vchan
make -C ../u2mfn
make -C ../qrexec
%install

1
u2mfn/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
libu2mfn.so

1
vchan/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
libvchan.so