Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > ebe084c140192657f9094e135a84202c > files > 156

libvirt-0.8.2-29.el5.src.rpm

From 185a7b7a4235ad0a4d6a6adc73f4f89212532047 Mon Sep 17 00:00:00 2001
Message-Id: <185a7b7a4235ad0a4d6a6adc73f4f89212532047.1287067706.git.jdenemar@redhat.com>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 1 Oct 2010 16:45:55 +0200
Subject: [PATCH] xen: Fix virDomain{At,De}tachDevice

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=638520

According to API documentation virDomain{At,De}tachDevice calls are
supposed to only work on active guests for device hotplug. For anything
beyond that, their *Flags variants have to be used.

Despite the variant which was acked on libvirt mailing list
(https://www.redhat.com/archives/libvir-list/2010-January/msg00385.html)
commit ed9c14a7ef86d7a45a6d57cbfee5410fca428633 (by Jim Fehlig)
introduced automagic behavior of these API calls for xen driver. Since
January, these calls always change persistent configuration of a guest
and if the guest is currently active, they also hot(un)plug the device.

That change didn't follow API documentation and also broke device
hot(un)plug for older xend implementations which do not support changing
persistent configuration of a guest and hot(un)plugging in one step.

This patch should not break anything for active guests. On the other
hand, changing inactive guests is not supported any more.
(cherry picked from commit 093973aabe7e3e9b49cf5e86fe1fc4488773b80f)
---
 src/xen/xen_driver.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 5dc80c1..348fd5b 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1437,10 +1437,16 @@ xenUnifiedDomainAttachDevice (virDomainPtr dom, const char *xml)
 {
     GET_PRIVATE(dom->conn);
     int i;
-    unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
+    unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE;
 
-    if (dom->id >= 0)
-        flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
+    /*
+     * HACK: xend with xendConfigVersion >= 3 does not support changing live
+     * config without touching persistent config, we add the extra flag here
+     * to make this API work
+     */
+    if (priv->opened[XEN_UNIFIED_XEND_OFFSET] &&
+        priv->xendConfigVersion >= 3)
+        flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
     for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (priv->opened[i] && drivers[i]->domainAttachDeviceFlags &&
@@ -1470,10 +1476,16 @@ xenUnifiedDomainDetachDevice (virDomainPtr dom, const char *xml)
 {
     GET_PRIVATE(dom->conn);
     int i;
-    unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
+    unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE;
 
-    if (dom->id >= 0)
-        flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
+    /*
+     * HACK: xend with xendConfigVersion >= 3 does not support changing live
+     * config without touching persistent config, we add the extra flag here
+     * to make this API work
+     */
+    if (priv->opened[XEN_UNIFIED_XEND_OFFSET] &&
+        priv->xendConfigVersion >= 3)
+        flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
     for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (priv->opened[i] && drivers[i]->domainDetachDeviceFlags &&
-- 
1.7.3.1