[openstack-nova] support non blocking libvirt operations

Pádraig Brady pbrady at fedoraproject.org
Fri Mar 16 19:27:14 UTC 2012


commit 165acf4bd9023ecb183a48249d22f2dc31214b6d
Author: Pádraig Brady <P at draigBrady.com>
Date:   Fri Mar 16 19:23:02 2012 +0000

    support non blocking libvirt operations

 0006-nonblocking-libvirt-mode-using-tpool.patch |   80 +++++++++++++++++++++++
 nova.conf                                       |    1 +
 openstack-nova.spec                             |    3 +
 3 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/0006-nonblocking-libvirt-mode-using-tpool.patch b/0006-nonblocking-libvirt-mode-using-tpool.patch
new file mode 100644
index 0000000..767864c
--- /dev/null
+++ b/0006-nonblocking-libvirt-mode-using-tpool.patch
@@ -0,0 +1,80 @@
+From a85610802a0646da3a88468de65aeda5f9ea1cef Mon Sep 17 00:00:00 2001
+From: Yun Mao <yunmao at gmail.com>
+Date: Tue, 13 Mar 2012 16:15:19 -0400
+Subject: [PATCH] nonblocking libvirt mode using tpool
+
+Add an option libvirt_nonblocking (disabled by default) to use a thread
+pool to execute all libvirt API calls. Previously all the calls except
+one in firewall.py are blocking in the eventlet thread model.
+
+Change-Id: I665ed7a629bb029011b181e8d2844fc2276502d9
+
+Conflicts:
+
+	etc/nova/nova.conf.sample
+---
+ nova/virt/libvirt/connection.py |   15 ++++++++++++++-
+ nova/virt/libvirt/firewall.py   |    8 +++++++-
+ 2 files changed, 21 insertions(+), 2 deletions(-)
+
+diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py
+index d8f1465..2785a5d 100644
+--- a/nova/virt/libvirt/connection.py
++++ b/nova/virt/libvirt/connection.py
+@@ -49,6 +49,8 @@ import sys
+ import uuid
+ 
+ from eventlet import greenthread
++from eventlet import tpool
++
+ from xml.dom import minidom
+ from xml.etree import ElementTree
+ 
+@@ -156,6 +158,10 @@ libvirt_opts = [
+                help='Number of seconds to wait for instance to shut down after'
+                     ' soft reboot request is made. We fall back to hard reboot'
+                     ' if instance does not shutdown within this window.'),
++    cfg.BoolOpt('libvirt_nonblocking',
++                default=False,
++                help='Use a separated OS thread pool to realize non-blocking'
++                     ' libvirt calls')
+     ]
+ 
+ FLAGS = flags.FLAGS
+@@ -251,9 +257,16 @@ class LibvirtConnection(driver.ComputeDriver):
+     def _get_connection(self):
+         if not self._wrapped_conn or not self._test_connection():
+             LOG.debug(_('Connecting to libvirt: %s'), self.uri)
+-            self._wrapped_conn = self._connect(self.uri,
++            if not FLAGS.libvirt_nonblocking:
++                self._wrapped_conn = self._connect(self.uri,
+                                                self.read_only)
++            else:
++                self._wrapped_conn = tpool.proxy_call(
++                    (libvirt.virDomain, libvirt.virConnect),
++                    self._connect, self.uri, self.read_only)
++
+         return self._wrapped_conn
++
+     _conn = property(_get_connection)
+ 
+     def _test_connection(self):
+diff --git a/nova/virt/libvirt/firewall.py b/nova/virt/libvirt/firewall.py
+index 04b3cf4..dd491ea 100644
+--- a/nova/virt/libvirt/firewall.py
++++ b/nova/virt/libvirt/firewall.py
+@@ -144,7 +144,13 @@ class NWFilterFirewall(base_firewall.FirewallDriver):
+         if callable(xml):
+             xml = xml()
+         # execute in a native thread and block current greenthread until done
+-        tpool.execute(self._conn.nwfilterDefineXML, xml)
++        if not FLAGS.libvirt_nonblocking:
++            # NOTE(maoy): the original implementation is to have the API called
++            # in the thread pool no matter what.
++            tpool.execute(self._conn.nwfilterDefineXML, xml)
++        else:
++            # NOTE(maoy): self._conn is a eventlet.tpool.Proxy object
++            self._conn.nwfilterDefineXML(xml)
+ 
+     def unfilter_instance(self, instance, network_info):
+         """Clear out the nwfilter rules."""
diff --git a/nova.conf b/nova.conf
index a1b4cf3..7cb9931 100644
--- a/nova.conf
+++ b/nova.conf
@@ -7,6 +7,7 @@ dhcpbridge_flagfile = /etc/nova/nova.conf
 force_dhcp_release = True
 injected_network_template = /usr/share/nova/interfaces.template
 libvirt_xml_template = /usr/share/nova/libvirt.xml.template
+libvirt_nonblocking = True
 vpn_client_template = /usr/share/nova/client.ovpn.template
 credentials_template = /usr/share/nova/novarc.template
 network_manager = nova.network.manager.FlatDHCPManager
diff --git a/openstack-nova.spec b/openstack-nova.spec
index 784451d..bacab4e 100644
--- a/openstack-nova.spec
+++ b/openstack-nova.spec
@@ -39,6 +39,7 @@ Patch0002: 0002-Add-VIF-and-interface-drivers-for-the-Linux-Bridge-p.patch
 Patch0003: 0003-Adds-soft-reboot-support-to-libvirt.patch
 Patch0004: 0004-Allows-new-style-config-to-be-used-for-flagfile.patch
 Patch0005: 0005-Fix-_sync_power_states-to-obtain-correct-state.patch
+Patch0006: 0006-nonblocking-libvirt-mode-using-tpool.patch
 
 BuildArch:        noarch
 BuildRequires:    intltool
@@ -179,6 +180,7 @@ This package contains documentation files for nova.
 %patch0003 -p1
 %patch0004 -p1
 %patch0005 -p1
+%patch0006 -p1
 
 find . \( -name .gitignore -o -name .placeholder \) -delete
 
@@ -371,6 +373,7 @@ fi
 %changelog
 * Fri Mar  8 2012 Pádraig Brady <P at draigBrady.com> - 2012.1-0.8.e4
 - Include an upstream fix for errors logged when syncing power states
+- Support non blocking libvirt operations
 
 * Fri Mar  6 2012 Alan Pevec <apevec at redhat.com> - 2012.1-0.7.e4
 - Fixup permissions on nova config files


More information about the scm-commits mailing list