qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Juan Quintela <quintela@trasno.org>
Cc: Carsten Otte <cotte@de.ibm.com>,
	markmc@redhat.com, qemu-devel@nongnu.org,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	kraxel@redhat.com, Avi Kivity <avi@redhat.com>,
	Paul Brook <paul@codesourcery.com>
Subject: [Qemu-devel] Re: [PATCH 1/2] qemu/qdev: type safety in reset handler
Date: Wed, 16 Sep 2009 12:34:45 +0300	[thread overview]
Message-ID: <20090916093445.GA1404@redhat.com> (raw)
In-Reply-To: <m3vdjjutwa.fsf@neno.mitica>

On Wed, Sep 16, 2009 at 11:21:41AM +0200, Juan Quintela wrote:
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > Add type safety to qdev reset handlers, by declaring them as
> > DeviceState * rather than void *.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  hw/qdev.c    |   10 ++++++++--
> >  hw/qdev.h    |    3 ++-
> >  hw/rtl8139.c |   10 +++++++---
> >  hw/tcx.c     |   11 +++++++----
> >  4 files changed, 24 insertions(+), 10 deletions(-)
> >
> > diff --git a/hw/qdev.c b/hw/qdev.c
> > index 43b1beb..4913f88 100644
> > --- a/hw/qdev.c
> > +++ b/hw/qdev.c
> > @@ -209,6 +209,12 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> >      return qdev;
> >  }
> >  
> > +static void qdev_reset(void *opaque)
> > +{
> > +	DeviceState *dev = opaque;
> > +	dev->info->reset(dev);
> > +}
> > +
> 
> Is there a plan to remove qdev_reset in the future?

When all devices are converted to qdev,
we can convert opaque to DeviceState.

> >  /* Initialize a device.  Device properties should be set before calling
> >     this function.  IRQs and MMIO regions should be connected/mapped after
> >     calling this function.  */
> > @@ -220,7 +226,7 @@ int qdev_init(DeviceState *dev)
> >      if (rc < 0)
> >          return rc;
> >      if (dev->info->reset)
> > -        qemu_register_reset(dev->info->reset, dev);
> > +        qemu_register_reset(qdev_reset, dev);
> 
> Otherwise, I prefer the old version.  We test if there exist
>   dev->info->reset
> and just after that, we use
>   dev->info->reset()

Good point. I think I'll just move the if (dev->info->reset)
into qdev_reset.

> If the plan is to add type checking to the system, they I would like to
> do something like the patch attached (not compiled, just the idea).
> 
> Add a qdev_register_reset() that takes a dev.
> And at reset time, if there is a dev parameter, we call its reset
> function (all with typecheking), and we maintain the func + opaque until
> everyting is ported (no, I don't now if that will ever happens either)
> 
> For users, normal DO_UPCAST() will do the trick on the reset handler.

As you say, we don't know if everything will ever be ported
to your proposed way. Keeping both around seems much worse
than using a void *.

> Later, Juan.
> diff --git a/vl.c b/vl.c
> index eb01da7..facfc67 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -3198,6 +3198,7 @@ typedef struct QEMUResetEntry {
>      QTAILQ_ENTRY(QEMUResetEntry) entry;
>      QEMUResetHandler *func;
>      void *opaque;
> +    DeviceState *dev;

So we have both opaque and dev, pointing to the same device.  dev is
used only for reset, and opaque for everything else.  And dev takes
precedence if it is set, opaque is ignored on reset, but if not, opaque
is used. At a minimum, all these rules should be documented?

>  } QEMUResetEntry;
> 
>  static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
> @@ -3259,6 +3260,18 @@ void qemu_register_reset(QEMUResetHandler *func, void *opaque)
> 
>      re->func = func;
>      re->opaque = opaque;
> +    re->dev = NULL;
> +    QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
> +}
> +
> +void qdev_register_reset(DeviceState *dev)
> +{
> +    QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
> +
> +    re->func = NULL;
> +    re->opaque = NULL;
> +    re->dev = dev;
> +
>      QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
>  }
> 
> @@ -3281,7 +3294,10 @@ void qemu_system_reset(void)
> 
>      /* reset all devices */
>      QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
> -        re->func(re->opaque);
> +        if (re->dev)
> +            re->dev->info->reset(re->dev);
> +        else
> +            re->func(re->opaque);
>      }
>  }
> 

  parent reply	other threads:[~2009-09-16  9:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1253025151.git.mst@redhat.com>
2009-09-15 14:33 ` [Qemu-devel] [PATCH 1/2] qemu/qdev: type safety in reset handler Michael S. Tsirkin
2009-09-15 14:55   ` [Qemu-devel] " Gerd Hoffmann
2009-09-15 20:20   ` [Qemu-devel] " Blue Swirl
2009-09-15 20:42     ` Michael S. Tsirkin
2009-09-15 21:16       ` [Qemu-devel] " Paolo Bonzini
2009-09-15 21:37         ` Michael S. Tsirkin
2009-09-16 10:13           ` Gerd Hoffmann
2009-09-16 10:14             ` Michael S. Tsirkin
     [not found]   ` <m3vdjjutwa.fsf@neno.mitica>
2009-09-16  9:34     ` Michael S. Tsirkin [this message]
2009-09-16 10:05       ` Gerd Hoffmann
2009-09-16 10:06         ` Michael S. Tsirkin
2009-09-16 10:22           ` Gerd Hoffmann
2009-09-16 10:30             ` Michael S. Tsirkin
2009-09-16 10:47               ` Michael S. Tsirkin
2009-09-16 12:08             ` Michael S. Tsirkin
2009-09-15 14:33 ` [Qemu-devel] [PATCH 2/2] qemu/virtio: fix reset with device removal Michael S. Tsirkin
2009-09-15 15:30   ` [Qemu-devel] " Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090916093445.GA1404@redhat.com \
    --to=mst@redhat.com \
    --cc=avi@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cotte@de.ibm.com \
    --cc=kraxel@redhat.com \
    --cc=markmc@redhat.com \
    --cc=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@trasno.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).