On 25.11.2015 17:03, Kevin Wolf wrote: > Am 09.11.2015 um 23:39 hat Max Reitz geschrieben: >> Make use of the BDS-BB removal and insertion notifiers to remove or set >> up, respectively, virtio-scsi's op blockers. >> >> Signed-off-by: Max Reitz <[email protected]> > >> @@ -797,6 +830,29 @@ static void virtio_scsi_hotunplug(HotplugHandler >> *hotplug_dev, DeviceState *dev, >> if (s->ctx) { >> blk_op_unblock_all(sd->conf.blk, s->blocker); >> } >> + >> + QTAILQ_FOREACH(insert_notifier, &s->insert_notifiers, next) { >> + if (insert_notifier->sd == sd) { >> + break; >> + } >> + } >> + if (insert_notifier) { >> + notifier_remove(&insert_notifier->n); >> + QTAILQ_REMOVE(&s->insert_notifiers, insert_notifier, next); >> + g_free(insert_notifier); >> + } > > Why a separate if block instead of just doing that inside the loop?
Because I unconsciously try to reduce indentation.
Also, because when I wrote the code, to me it was "Find the relevant
notifier -- destroy that notifier", and that's how this pattern came about.
I personally still like it more the way I did it, but I can very well
imagine that I'm the only one who thinks so. Therefore, I wouldn't mind
changing it (besides the effort involved to change it).
Max
>> + QTAILQ_FOREACH(remove_notifier, &s->remove_notifiers, next) {
>> + if (remove_notifier->sd == sd) {
>> + break;
>> + }
>> + }
>> + if (remove_notifier) {
>> + notifier_remove(&remove_notifier->n);
>> + QTAILQ_REMOVE(&s->remove_notifiers, remove_notifier, next);
>> + g_free(remove_notifier);
>> + }
>> +
>> qdev_simple_device_unplug_cb(hotplug_dev, dev, errp);
>> }
>
> Kevin
>
signature.asc
Description: OpenPGP digital signature
