From 993d34e7d51006060a7daed0ac98e8c1503b06b9 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Tue, 15 Mar 2011 18:28:28 +0100 Subject: [PATCH 1/3] Allow labels for NetVM/ProxyVM. Require it in qvm-create. --- dom0/qvm-core/qubes.py | 30 ++++++++++++++++++++++++------ dom0/qvm-tools/qvm-create | 30 ++++++++++++++---------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/dom0/qvm-core/qubes.py b/dom0/qvm-core/qubes.py index 316c7759..c067e188 100755 --- a/dom0/qvm-core/qubes.py +++ b/dom0/qvm-core/qubes.py @@ -1098,6 +1098,7 @@ class QubesNetVm(QubesCowVm): updateable=str(self.updateable), private_img=self.private_img, installed_by_rpm=str(self.installed_by_rpm), + label=self.label.name, ) return element @@ -1242,6 +1243,7 @@ class QubesProxyVm(QubesNetVm): netvm_qid=str(self.netvm_vm.qid) if self.netvm_vm is not None else "none", private_img=self.private_img, installed_by_rpm=str(self.installed_by_rpm), + label=self.label.name, ) return element @@ -1593,12 +1595,13 @@ class QubesVmCollection(dict): def add_new_netvm(self, name, template_vm, dir_path = None, conf_file = None, - private_img = None): + private_img = None, + label = None): qid = self.get_new_unused_qid() netid = self.get_new_unused_netid() vm = QubesNetVm (qid=qid, name=name, template_vm=template_vm, - netid=netid, + netid=netid, label=label, private_img=private_img, dir_path=dir_path, conf_file=conf_file) @@ -1613,12 +1616,13 @@ class QubesVmCollection(dict): def add_new_proxyvm(self, name, template_vm, dir_path = None, conf_file = None, - private_img = None): + private_img = None, + label = None): qid = self.get_new_unused_qid() netid = self.get_new_unused_netid() vm = QubesProxyVm (qid=qid, name=name, template_vm=template_vm, - netid=netid, + netid=netid, label=label, private_img=private_img, dir_path=dir_path, conf_file=conf_file, netvm_vm = self.get_default_fw_netvm_vm()) @@ -1836,7 +1840,7 @@ class QubesVmCollection(dict): try: kwargs = {} attr_list = ("qid", "netid", "name", "dir_path", "conf_file", - "private_img", "template_qid", "updateable", + "private_img", "template_qid", "updateable", "label", ) for attribute in attr_list: @@ -1855,6 +1859,13 @@ class QubesVmCollection(dict): kwargs["template_vm"] = template_vm kwargs["netid"] = int(kwargs["netid"]) + if kwargs["label"] is not None: + if kwargs["label"] not in QubesVmLabels: + print "ERROR: incorrect label for VM '{0}'".format(kwargs["name"]) + kwargs.pop ("label") + else: + kwargs["label"] = QubesVmLabels[kwargs["label"]] + vm = QubesNetVm(**kwargs) self[vm.qid] = vm @@ -1869,7 +1880,7 @@ class QubesVmCollection(dict): try: kwargs = {} attr_list = ("qid", "netid", "name", "dir_path", "conf_file", "updateable", - "private_img", "template_qid") + "private_img", "template_qid", "label") for attribute in attr_list: kwargs[attribute] = element.get(attribute) @@ -1887,6 +1898,13 @@ class QubesVmCollection(dict): kwargs["template_vm"] = template_vm kwargs["netid"] = int(kwargs["netid"]) + if kwargs["label"] is not None: + if kwargs["label"] not in QubesVmLabels: + print "ERROR: incorrect label for VM '{0}'".format(kwargs["name"]) + kwargs.pop ("label") + else: + kwargs["label"] = QubesVmLabels[kwargs["label"]] + vm = QubesProxyVm(**kwargs) self[vm.qid] = vm diff --git a/dom0/qvm-tools/qvm-create b/dom0/qvm-tools/qvm-create index aa567b98..a16f19ba 100755 --- a/dom0/qvm-tools/qvm-create +++ b/dom0/qvm-tools/qvm-create @@ -67,21 +67,19 @@ def main(): if options.netvm and options.proxyvm: parser.error ("You must specify at most one of --proxy and --net") - label = None - if not options.proxyvm and not options.netvm: - if options.label is None: - print "You must choose a label for the new VM by passing the --label option." - print "Possible values are:" - for l in QubesVmLabels.values(): - print "* {0}".format(l.name) - exit (1) + if options.label is None: + print "You must choose a label for the new VM by passing the --label option." + print "Possible values are:" + for l in QubesVmLabels.values(): + print "* {0}".format(l.name) + exit (1) - if options.label not in QubesVmLabels: - print "Wrong label name, supported values are the following:" - for l in QubesVmLabels.values(): - print "* {0}".format(l.name) - exit (1) - label = QubesVmLabels[options.label] + if options.label not in QubesVmLabels: + print "Wrong label name, supported values are the following:" + for l in QubesVmLabels.values(): + print "* {0}".format(l.name) + exit (1) + label = QubesVmLabels[options.label] qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_writing() @@ -113,7 +111,7 @@ def main(): vm = None if options.netvm: - vm = qvm_collection.add_new_netvm(vmname, template_vm) + vm = qvm_collection.add_new_netvm(vmname, template_vm, label = label) net_devices = find_net_devices() print "Found the following net devices in your system:" @@ -126,7 +124,7 @@ def main(): vm.pcidevs = dev_str elif options.proxyvm: - vm = qvm_collection.add_new_proxyvm(vmname, template_vm) + vm = qvm_collection.add_new_proxyvm(vmname, template_vm, label = label) else: vm = qvm_collection.add_new_appvm(vmname, template_vm, label = label) try: From 63b06516b79079614bb72c614d1582116d603538 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Tue, 15 Mar 2011 18:51:31 +0100 Subject: [PATCH 2/3] Do not add new vm to xen storage in qvm-create - it is done by core --- dom0/qvm-tools/qvm-create | 1 - 1 file changed, 1 deletion(-) diff --git a/dom0/qvm-tools/qvm-create b/dom0/qvm-tools/qvm-create index a16f19ba..3a05cdbf 100755 --- a/dom0/qvm-tools/qvm-create +++ b/dom0/qvm-tools/qvm-create @@ -129,7 +129,6 @@ def main(): vm = qvm_collection.add_new_appvm(vmname, template_vm, label = label) try: vm.create_on_disk(verbose=options.verbose) - vm.add_to_xen_storage() except (IOError, OSError) as err: print "ERROR: {0}".format(err) From 2818f6dfe1eeda76c186e22abba62f8dde434732 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Tue, 15 Mar 2011 19:47:26 +0100 Subject: [PATCH 3/3] Move xenstore-watch for VM from AppVM to common. Add to core-common.spec --- appvm/.gitignore | 1 - appvm/Makefile | 4 +--- common/.gitignore | 1 + common/Makefile | 4 +++- {appvm => common}/xenstore-watch.c | 0 rpm_spec/core-commonvm.spec | 12 +++++++++--- 6 files changed, 14 insertions(+), 8 deletions(-) rename {appvm => common}/xenstore-watch.c (100%) diff --git a/appvm/.gitignore b/appvm/.gitignore index 23680333..edd6d099 100644 --- a/appvm/.gitignore +++ b/appvm/.gitignore @@ -1,4 +1,3 @@ qubes_add_pendrive_script qubes_penctl qvm-open-in-dvm -xenstore-watch diff --git a/appvm/Makefile b/appvm/Makefile index 0ef375a7..858a665b 100644 --- a/appvm/Makefile +++ b/appvm/Makefile @@ -1,14 +1,12 @@ CC=gcc CFLAGS=-Wall -all: qubes_penctl qubes_add_pendrive_script qvm-open-in-dvm xenstore-watch +all: qubes_penctl qubes_add_pendrive_script qvm-open-in-dvm qubes_penctl: qubes_penctl.o $(CC) -o qubes_penctl qubes_penctl.o -lxenstore qubes_add_pendrive_script: qubes_add_pendrive_script.o $(CC) -o qubes_add_pendrive_script qubes_add_pendrive_script.o -lxenstore qvm-open-in-dvm: qvm-open-in-dvm.o $(CC) -o qvm-open-in-dvm qvm-open-in-dvm.o -lxenstore -xenstore-watch: xenstore-watch.o - $(CC) -o xenstore-watch xenstore-watch.o -lxenstore clean: rm -f qubes_penctl qubes_add_pendrive_script qvm-open-in-dvm xenstore-watch *.o *~ diff --git a/common/.gitignore b/common/.gitignore index 03034a95..b87d6e19 100644 --- a/common/.gitignore +++ b/common/.gitignore @@ -1 +1,2 @@ meminfo-writer +xenstore-watch diff --git a/common/Makefile b/common/Makefile index 85888a90..4f8df460 100644 --- a/common/Makefile +++ b/common/Makefile @@ -1,7 +1,9 @@ CC=gcc CFLAGS=-Wall -g -O3 -all: meminfo-writer +all: meminfo-writer xenstore-watch meminfo-writer: meminfo-writer.o $(CC) -g -o meminfo-writer meminfo-writer.o -lxenstore +xenstore-watch: xenstore-watch.o + $(CC) -o xenstore-watch xenstore-watch.o -lxenstore clean: rm -f meminfo-writer *.o *~ diff --git a/appvm/xenstore-watch.c b/common/xenstore-watch.c similarity index 100% rename from appvm/xenstore-watch.c rename to common/xenstore-watch.c diff --git a/rpm_spec/core-commonvm.spec b/rpm_spec/core-commonvm.spec index 6705c28b..1ee16a7d 100644 --- a/rpm_spec/core-commonvm.spec +++ b/rpm_spec/core-commonvm.spec @@ -39,6 +39,9 @@ Requires: fedora-release = 13 %description The Qubes core files for installation inside a Qubes VM. +%build +make + %pre if [ "$1" != 1 ] ; then @@ -62,10 +65,12 @@ mkdir -p $RPM_BUILD_ROOT/etc/sysconfig cp iptables $RPM_BUILD_ROOT/etc/sysconfig/ mkdir -p $RPM_BUILD_ROOT/etc/yum.repos.d cp ../appvm/qubes.repo $RPM_BUILD_ROOT/etc/yum.repos.d -mkdir -p $RPM_BUILD_ROOT/sbin -cp ../common/qubes_serial_login $RPM_BUILD_ROOT/sbin +mkdir -p $RPM_BUILD_ROOT/sbin +cp qubes_serial_login $RPM_BUILD_ROOT/sbin +mkdir -p $RPM_BUILD_ROOT/usr/bin +cp xenstore-watch $RPM_BUILD_ROOT/usr/bin mkdir -p $RPM_BUILD_ROOT/etc -cp ../common/serial.conf $RPM_BUILD_ROOT/var/lib/qubes/ +cp serial.conf $RPM_BUILD_ROOT/var/lib/qubes/ %triggerin -- initscripts cp /var/lib/qubes/serial.conf /etc/init/serial.conf @@ -164,3 +169,4 @@ rm -rf $RPM_BUILD_ROOT /var/lib/qubes /etc/yum.repos.d/qubes.repo /sbin/qubes_serial_login +/usr/bin/xenstore-watch