Blame SOURCES/kvm-s390x-pci-properly-fail-if-the-zPCI-device-cannot-be.patch

ae23c9
From c66f28ded3ebb8926eeed2ce6abea53053359c99 Mon Sep 17 00:00:00 2001
ae23c9
From: Cornelia Huck <cohuck@redhat.com>
ae23c9
Date: Wed, 17 Apr 2019 13:57:24 +0100
ae23c9
Subject: [PATCH 07/24] s390x/pci: properly fail if the zPCI device cannot be
ae23c9
 created
ae23c9
ae23c9
RH-Author: Cornelia Huck <cohuck@redhat.com>
ae23c9
Message-id: <20190417135741.25297-8-cohuck@redhat.com>
ae23c9
Patchwork-id: 85792
ae23c9
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v2 07/24] s390x/pci: properly fail if the zPCI device cannot be created
ae23c9
Bugzilla: 1699070
ae23c9
RH-Acked-by: David Hildenbrand <david@redhat.com>
ae23c9
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ae23c9
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
ae23c9
ae23c9
From: David Hildenbrand <david@redhat.com>
ae23c9
ae23c9
Right now, errors during realize()/pre_plug/plug of the zPCI device
ae23c9
would result in QEMU crashing instead of failing nicely when creating
ae23c9
a zPCI device for a PCI device.
ae23c9
ae23c9
Reviewed-by: Thomas Huth <thuth@redhat.com>
ae23c9
Reviewed-by: Collin Walling <walling@linux.ibm.com>
ae23c9
Signed-off-by: David Hildenbrand <david@redhat.com>
ae23c9
Message-Id: <20181113121710.18490-1-david@redhat.com>
ae23c9
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
ae23c9
(cherry picked from commit b6e67ecc7b6e8938982ab94820c079f24845f623)
ae23c9
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
ae23c9
ae23c9
Changes:
ae23c9
  We don't have 4b5766488f ("error: Fix use of error_prepend() with
ae23c9
  &error_fatal, &error_abort") downstream.
ae23c9
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 hw/s390x/s390-pci-bus.c | 25 +++++++++++++++++++------
ae23c9
 1 file changed, 19 insertions(+), 6 deletions(-)
ae23c9
ae23c9
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
ae23c9
index f253774..e6f5d91 100644
ae23c9
--- a/hw/s390x/s390-pci-bus.c
ae23c9
+++ b/hw/s390x/s390-pci-bus.c
ae23c9
@@ -780,17 +780,31 @@ static void s390_pci_msix_free(S390PCIBusDevice *pbdev)
ae23c9
 }
ae23c9
 
ae23c9
 static S390PCIBusDevice *s390_pci_device_new(S390pciState *s,
ae23c9
-                                             const char *target)
ae23c9
+                                             const char *target, Error **errp)
ae23c9
 {
ae23c9
-    DeviceState *dev = NULL;
ae23c9
+    Error *local_err = NULL;
ae23c9
+    DeviceState *dev;
ae23c9
 
ae23c9
     dev = qdev_try_create(BUS(s->bus), TYPE_S390_PCI_DEVICE);
ae23c9
     if (!dev) {
ae23c9
+        error_setg(errp, "zPCI device could not be created");
ae23c9
         return NULL;
ae23c9
     }
ae23c9
 
ae23c9
-    qdev_prop_set_string(dev, "target", target);
ae23c9
-    qdev_init_nofail(dev);
ae23c9
+    object_property_set_str(OBJECT(dev), target, "target", &local_err);
ae23c9
+    if (local_err) {
ae23c9
+        object_unparent(OBJECT(dev));
ae23c9
+        error_prepend(&local_err, "zPCI device could not be created: ");
ae23c9
+        error_propagate(errp, local_err);
ae23c9
+        return NULL;
ae23c9
+    }
ae23c9
+    object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
ae23c9
+    if (local_err) {
ae23c9
+        object_unparent(OBJECT(dev));
ae23c9
+        error_prepend(&local_err, "zPCI device could not be created: ");
ae23c9
+        error_propagate(errp, local_err);
ae23c9
+        return NULL;
ae23c9
+    }
ae23c9
 
ae23c9
     return S390_PCI_DEVICE(dev);
ae23c9
 }
ae23c9
@@ -865,9 +879,8 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
ae23c9
 
ae23c9
         pbdev = s390_pci_find_dev_by_target(s, dev->id);
ae23c9
         if (!pbdev) {
ae23c9
-            pbdev = s390_pci_device_new(s, dev->id);
ae23c9
+            pbdev = s390_pci_device_new(s, dev->id, errp);
ae23c9
             if (!pbdev) {
ae23c9
-                error_setg(errp, "create zpci device failed");
ae23c9
                 return;
ae23c9
             }
ae23c9
         }
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9