Skip to contentSkip to conversation

qdev: Fix bus dependency of DeviceState::hotpluggable getter

PATCH In review Andreas Färber 3 participants 5 messages Mar 7, 2014 – Mar 10, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qdev: Fix bus dependency of DeviceState::hotpluggable getter

Commit 1a37eca107cece3ed454bae29eef0bd1fac4a244 (qdev: add "hotpluggable" property to Device) added a property "hotpluggable" to each device, with its getter accessing parent_bus->allow_hotplug.

Add a NULL check.

---
 hw/core/qdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev.c +2 -1
index 749c83a..cb07863 100644
@@ -735,7 +735,8 @@ static bool device_get_hotpluggable(Object *obj, Error **err)
     DeviceClass *dc = DEVICE_GET_CLASS(obj);
     DeviceState *dev = DEVICE(obj);
 
-    return dc->hotpluggable && dev->parent_bus->allow_hotplug;
+    return dc->hotpluggable && (dev->parent_bus == NULL ||
+                                dev->parent_bus->allow_hotplug);
 }
 
 static void device_initfn(Object *obj)
Signature · 1 line
1.8.4.5
#1 lore raw
Quoted 8 lines · Andreas Färber

Commit 1a37eca107cece3ed454bae29eef0bd1fac4a244 (qdev: add "hotpluggable" property to Device) added a property "hotpluggable" to each device, with its getter accessing parent_bus->allow_hotplug.

Add a NULL check.

Fair enough but I'm guessing we should
assume devices without a parent are not
hotpluggable, should we not?

Without a bus what handles hotplug?

Quoted 9 lines
---
 hw/core/qdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev.c +0 -0
index 749c83a..cb07863 100644

hw/core/qdev.c static bool device_get_hotpluggable(Object *obj, Error **err) · line 739

Quoted 6 lines
hw/core/qdev.c +2 -1
@@ -735,7 +735,8 @@ static bool device_get_hotpluggable(Object *obj, Error **err)
     DeviceClass *dc = DEVICE_GET_CLASS(obj);
     DeviceState *dev = DEVICE(obj);
 
-    return dc->hotpluggable && dev->parent_bus->allow_hotplug;
+    return dc->hotpluggable && (dev->parent_bus == NULL ||
+                                dev->parent_bus->allow_hotplug);

So maybe this should be:

hw/core/qdev.c static bool device_get_hotpluggable(Object *obj, Error **err) · line 741

Quoted 2 lines
hw/core/qdev.c +0 -0
    return dc->hotpluggable && dev->parent_bus &&
                               dev->parent_bus->allow_hotplug;

?

Quoted 5 lines
hw/core/qdev.c +0 -0
 }

static void device_initfn(Object *obj)

Signature · 1 line
1.8.4.5
#2 lore raw

Am 09.03.2014 17:40, schrieb Michael S. Tsirkin:

Quoted 7 lines · Andreas Färber
Quoted 6 lines

Commit 1a37eca107cece3ed454bae29eef0bd1fac4a244 (qdev: add "hotpluggable" property to Device) added a property "hotpluggable" to each device, with its getter accessing parent_bus->allow_hotplug.

Add a NULL check.

Quoted 8 lines
Quoted 2 lines

Fair enough but I'm guessing we should
assume devices without a parent are not
hotpluggable, should we not?

Without a bus what handles hotplug?

The device has to, in its realize function.

Quoted 17 lines
Quoted 9 lines
---
 hw/core/qdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev.c +0 -0
index 749c83a..cb07863 100644

hw/core/qdev.c static bool device_get_hotpluggable(Object *obj, Error **err) · line 739

Quoted 6 lines
hw/core/qdev.c +2 -1
@@ -735,7 +735,8 @@ static bool device_get_hotpluggable(Object *obj, Error **err)
     DeviceClass *dc = DEVICE_GET_CLASS(obj);
     DeviceState *dev = DEVICE(obj);
 
-    return dc->hotpluggable && dev->parent_bus->allow_hotplug;
+    return dc->hotpluggable && (dev->parent_bus == NULL ||
+                                dev->parent_bus->allow_hotplug);

So maybe this should be:

Quoted 4 lines

hw/core/qdev.c static bool device_get_hotpluggable(Object *obj, Error **err) · line 741

Quoted 2 lines
hw/core/qdev.c +0 -0
    return dc->hotpluggable && dev->parent_bus &&
                               dev->parent_bus->allow_hotplug;

?

Hmm... that would render non-x86 CPUs non-hotpluggable. I guess we need to check dc->bus_type for a NULL value and if non-NULL use your variant and otherwise mine. I'll give it some more thought.

Thanks,
Andreas

Quoted 6 lines
Quoted 6 lines
hw/core/qdev.c +0 -0
 }

static void device_initfn(Object *obj)

Signature · 1 line
1.8.4.5
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw
Quoted 40 lines · Andreas Färber

Am 09.03.2014 17:40, schrieb Michael S. Tsirkin:

Quoted 7 lines · Andreas Färber
Quoted 6 lines

Commit 1a37eca107cece3ed454bae29eef0bd1fac4a244 (qdev: add "hotpluggable" property to Device) added a property "hotpluggable" to each device, with its getter accessing parent_bus->allow_hotplug.

Add a NULL check.

Quoted 8 lines
Quoted 2 lines

Fair enough but I'm guessing we should
assume devices without a parent are not
hotpluggable, should we not?

Without a bus what handles hotplug?

The device has to, in its realize function.

Quoted 17 lines
Quoted 9 lines
---
 hw/core/qdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev.c +0 -0
index 749c83a..cb07863 100644

hw/core/qdev.c static bool device_get_hotpluggable(Object *obj, Error **err) · line 739

Quoted 6 lines
hw/core/qdev.c +2 -1
@@ -735,7 +735,8 @@ static bool device_get_hotpluggable(Object *obj, Error **err)
     DeviceClass *dc = DEVICE_GET_CLASS(obj);
     DeviceState *dev = DEVICE(obj);
 
-    return dc->hotpluggable && dev->parent_bus->allow_hotplug;
+    return dc->hotpluggable && (dev->parent_bus == NULL ||
+                                dev->parent_bus->allow_hotplug);

So maybe this should be:

Quoted 4 lines

hw/core/qdev.c static bool device_get_hotpluggable(Object *obj, Error **err) · line 741

Quoted 2 lines
hw/core/qdev.c +0 -0
    return dc->hotpluggable && dev->parent_bus &&
                               dev->parent_bus->allow_hotplug;

?

Quoted 7 lines

Hmm... that would render non-x86 CPUs non-hotpluggable. I guess we need to check dc->bus_type for a NULL value and if non-NULL use your variant and otherwise mine.
I'll give it some more thought.

Thanks,
Andreas

Or clear dc->hotpluggable if there's no parent bus and we don't want to allow hotplug.

I'm beginning to think your patch is the right one after all...

Quoted 11 lines
Quoted 7 lines
Quoted 7 lines
hw/core/qdev.c +0 -0
 }

static void device_initfn(Object *obj)

Signature · 1 line
1.8.4.5
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#4 lore raw
Quoted 46 lines · On Sun, 9 Mar 2014 18:55:05 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 45 lines · Andreas Färber

Am 09.03.2014 17:40, schrieb Michael S. Tsirkin:

Quoted 7 lines · Andreas Färber
Quoted 6 lines

Commit 1a37eca107cece3ed454bae29eef0bd1fac4a244 (qdev: add "hotpluggable" property to Device) added a property "hotpluggable" to each device, with its getter accessing parent_bus->allow_hotplug.

Add a NULL check.

Quoted 8 lines
Quoted 2 lines

Fair enough but I'm guessing we should
assume devices without a parent are not
hotpluggable, should we not?

Without a bus what handles hotplug?

The device has to, in its realize function.

Quoted 17 lines
Quoted 9 lines
---
 hw/core/qdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev.c +0 -0
index 749c83a..cb07863 100644

hw/core/qdev.c static bool device_get_hotpluggable(Object *obj, Error **err) · line 739

Quoted 6 lines
hw/core/qdev.c +2 -1
@@ -735,7 +735,8 @@ static bool device_get_hotpluggable(Object *obj, Error **err)
     DeviceClass *dc = DEVICE_GET_CLASS(obj);
     DeviceState *dev = DEVICE(obj);
 
-    return dc->hotpluggable && dev->parent_bus->allow_hotplug;
+    return dc->hotpluggable && (dev->parent_bus == NULL ||
+                                dev->parent_bus->allow_hotplug);

So maybe this should be:

Quoted 4 lines

hw/core/qdev.c static bool device_get_hotpluggable(Object *obj, Error **err) · line 741

Quoted 2 lines
hw/core/qdev.c +0 -0
    return dc->hotpluggable && dev->parent_bus &&
                               dev->parent_bus->allow_hotplug;

?

Hmm... that would render non-x86 CPUs non-hotpluggable. I guess we need to check dc->bus_type for a NULL value and if non-NULL use your variant and otherwise mine.
I'll give it some more thought.

Quoted 8 lines
Quoted 2 lines

Thanks,
Andreas

Or clear dc->hotpluggable if there's no parent bus and we don't want to allow hotplug.

I'm beginning to think your patch is the right one after all...

Before hotplug rework all devices were assumed to be hotpluggable, the non-hotpluggable ones explicitly cleared dc->hotpluggable in class_init(), rework hasn't changed it so Andreas's patch looks better as to not block hotplug on bus-less devices.

Later if we implement bus-less hotplug with link<>s, we can add link<> set hook to that will call hotplug handler in the same manner as it's done for bus based devices.

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 7 lines
hw/core/qdev.c +0 -0
 }

static void device_initfn(Object *obj)

Signature · 1 line
1.8.4.5
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg