spapr: Don't use spapr_drc_needed() in CAS code

We currently don't support hotplug of devices between boot and CAS. If
this happens a CAS reboot is triggered. We detect this during CAS using
the spapr_drc_needed() function which is essentially a VMStateDescription
.needed callback. Even if the condition for CAS reboot happens to be the
same as for DRC migration, it looks wrong to piggyback a migration helper
for this.

Introduce a helper with slightly more explicit name and use it in both CAS
and DRC migration code. Since a subsequent patch will enhance this helper
to cover the case of hot unplug, let's go for spapr_drc_transient(). While
here convert spapr_hotplugged_dev_before_cas() to the "transient" wording as
well.

This doesn't change any behaviour.

Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <158169248180.3465937.9531405453362718771.stgit@bahia.lan>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Greg Kurz 2020-02-14 16:01:22 +01:00 committed by David Gibson
parent b2fb7a4368
commit 4b63db1289
3 changed files with 26 additions and 12 deletions

View File

@ -456,23 +456,31 @@ void spapr_drc_reset(SpaprDrc *drc)
} }
} }
bool spapr_drc_needed(void *opaque) bool spapr_drc_transient(SpaprDrc *drc)
{ {
SpaprDrc *drc = (SpaprDrc *)opaque;
SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
/* If no dev is plugged in there is no need to migrate the DRC state */ /*
* If no dev is plugged in there is no need to migrate the DRC state
* nor to reset the DRC at CAS.
*/
if (!drc->dev) { if (!drc->dev) {
return false; return false;
} }
/* /*
* We need to migrate the state if it's not equal to the expected * We need to reset the DRC at CAS or to migrate the DRC state if it's
* long-term state, which is the same as the coldplugged initial * not equal to the expected long-term state, which is the same as the
* state */ * coldplugged initial state.
*/
return (drc->state != drck->ready_state); return (drc->state != drck->ready_state);
} }
static bool spapr_drc_needed(void *opaque)
{
return spapr_drc_transient(opaque);
}
static const VMStateDescription vmstate_spapr_drc = { static const VMStateDescription vmstate_spapr_drc = {
.name = "spapr_drc", .name = "spapr_drc",
.version_id = 1, .version_id = 1,

View File

@ -1640,20 +1640,24 @@ static uint32_t cas_check_pvr(SpaprMachineState *spapr, PowerPCCPU *cpu,
return best_compat; return best_compat;
} }
static bool spapr_hotplugged_dev_before_cas(void) static bool spapr_transient_dev_before_cas(void)
{ {
Object *drc_container, *obj; Object *drc_container;
ObjectProperty *prop; ObjectProperty *prop;
ObjectPropertyIterator iter; ObjectPropertyIterator iter;
drc_container = container_get(object_get_root(), "/dr-connector"); drc_container = container_get(object_get_root(), "/dr-connector");
object_property_iter_init(&iter, drc_container); object_property_iter_init(&iter, drc_container);
while ((prop = object_property_iter_next(&iter))) { while ((prop = object_property_iter_next(&iter))) {
SpaprDrc *drc;
if (!strstart(prop->type, "link<", NULL)) { if (!strstart(prop->type, "link<", NULL)) {
continue; continue;
} }
obj = object_property_get_link(drc_container, prop->name, NULL); drc = SPAPR_DR_CONNECTOR(object_property_get_link(drc_container,
if (spapr_drc_needed(obj)) { prop->name, NULL));
if (spapr_drc_transient(drc)) {
return true; return true;
} }
} }
@ -1830,7 +1834,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
spapr_irq_update_active_intc(spapr); spapr_irq_update_active_intc(spapr);
if (spapr_hotplugged_dev_before_cas()) { if (spapr_transient_dev_before_cas()) {
spapr->cas_reboot = true; spapr->cas_reboot = true;
} }

View File

@ -278,7 +278,9 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask);
void spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp); void spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp);
void spapr_drc_detach(SpaprDrc *drc); void spapr_drc_detach(SpaprDrc *drc);
bool spapr_drc_needed(void *opaque);
/* Returns true if a hot plug/unplug request is pending */
bool spapr_drc_transient(SpaprDrc *drc);
static inline bool spapr_drc_unplug_requested(SpaprDrc *drc) static inline bool spapr_drc_unplug_requested(SpaprDrc *drc)
{ {