qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: peter.maydell@linaro.org, e.voevodin@samsung.com,
	mark.burton@greensocs.com, qemu-devel@nongnu.org,
	cornelia.huck@de.ibm.com, afaerber@suse.de,
	fred.konrad@greensocs.com
Subject: Re: [Qemu-devel] [RFC PATCH v2 1/3] virtio-bus : Introduce VirtioBus.
Date: Mon, 26 Nov 2012 16:40:54 +0100	[thread overview]
Message-ID: <20121126154054.GA25839@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <87k3t8qvrg.fsf@codemonkey.ws>

On Mon, Nov 26, 2012 at 08:33:23AM -0600, Anthony Liguori wrote:
> fred.konrad@greensocs.com writes:
> 
> > From: KONRAD Frederic <fred.konrad@greensocs.com>
> >
> > This patch create a new VirtioBus, which can be added to Virtio transports like
> > virtio-pci, virtio-mmio,...
> >
> > One VirtIODevice can be connected to this device, like virtio-blk in the 3rd
> > patch.
> >
> > The VirtioBus shares through a VirtioBusInfo structure :
> >
> >     * two callbacks with the transport : init_cb and exit_cb, which must be
> >       called by the VirtIODevice, after the initialization and before the
> >       destruction, to put the right PCI IDs and/or stop the event fd.
> >
> >     * a VirtIOBindings structure.
> >
> > Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> > ---
> >  hw/Makefile.objs |   1 +
> >  hw/virtio-bus.c  | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  hw/virtio-bus.h  |  58 ++++++++++++++++++++++
> >  3 files changed, 207 insertions(+)
> >  create mode 100644 hw/virtio-bus.c
> >  create mode 100644 hw/virtio-bus.h
> >
> > diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> > index ea46f81..bd14d1b 100644
> > --- a/hw/Makefile.objs
> > +++ b/hw/Makefile.objs
> > @@ -2,6 +2,7 @@ common-obj-y = usb/ ide/
> >  common-obj-y += loader.o
> >  common-obj-$(CONFIG_VIRTIO) += virtio-console.o
> >  common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
> > +common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
> >  common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
> >  common-obj-y += fw_cfg.o
> >  common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
> > diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
> > new file mode 100644
> > index 0000000..991b6f5
> > --- /dev/null
> > +++ b/hw/virtio-bus.c
> > @@ -0,0 +1,148 @@
> > +/*
> > + * VirtioBus
> > + *
> > + *  Copyright (C) 2012 : GreenSocs Ltd
> > + *      http://www.greensocs.com/ , email: info@greensocs.com
> > + *
> > + *  Developed by :
> > + *  Frederic Konrad   <fred.konrad@greensocs.com>
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation, either version 2 of the License, or
> > + * (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License along
> > + * with this program; if not, see <http://www.gnu.org/licenses/>.
> > + *
> > + */
> > +
> > +#include "hw.h"
> > +#include "qemu-error.h"
> > +#include "qdev.h"
> > +#include "virtio-bus.h"
> > +#include "virtio.h"
> > +
> > +#define DEBUG_VIRTIO_BUS 1
> > +
> > +#define DPRINTF(fmt, ...) if (DEBUG_VIRTIO_BUS) {                        \
> > +                            printf("virtio_bus: " fmt , ## __VA_ARGS__); \
> > +                          }
> 
> #ifdef DEBUG_VIRTIO_BUS
> #define DPRINTF(fmt, ...) ...
> #else
> #define DPRINTF(fmt, ...) do { } while (0)
> #endif
> 
> You're leaving a dangling if clause which can do very strange things if
> used before an else statement.

This should be:

#define DEBUG_VIRTIO_BUS 1

#define DPRINTF(fmt, ...) \
    do { \
        if (DEBUG_VIRTIO_BUS) { \
            printf("virtio_bus: " fmt , ## __VA_ARGS__); \
        } \
    } while (0)

This way there's no dangling else statement problem.  But it also
ensures the we always compile the debug print, thereby avoiding bitrot
you get from #ifdef ... #else ... #endif.

Stefan

  parent reply	other threads:[~2012-11-26 15:41 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-22 14:50 [Qemu-devel] [RFC PATCH v2 0/3] Virtio-refactoring fred.konrad
2012-11-22 14:50 ` [Qemu-devel] [RFC PATCH v2 1/3] virtio-bus : Introduce VirtioBus fred.konrad
2012-11-23 12:08   ` Cornelia Huck
2012-11-23 14:12     ` Konrad Frederic
2012-11-23 14:35       ` Cornelia Huck
2012-11-26 13:55     ` Konrad Frederic
2012-11-26 14:03       ` Cornelia Huck
2012-11-23 12:23   ` Stefan Hajnoczi
2012-11-23 14:21     ` Konrad Frederic
2012-11-23 16:13       ` Stefan Hajnoczi
2012-11-24 22:29   ` Andreas Färber
2012-11-26 14:33   ` Anthony Liguori
2012-11-26 14:37     ` Peter Maydell
2012-11-26 16:59       ` Anthony Liguori
2012-11-29 12:37         ` Konrad Frederic
2012-11-29 13:09           ` Peter Maydell
2012-11-29 13:47             ` Konrad Frederic
2012-11-29 13:53               ` Peter Maydell
2012-11-29 13:55               ` Andreas Färber
2012-11-29 14:28                 ` Konrad Frederic
2012-11-29 13:52           ` Anthony Liguori
2012-11-26 14:45     ` Andreas Färber
2012-11-26 16:55       ` Anthony Liguori
2012-11-26 15:33     ` Konrad Frederic
2012-11-26 15:40     ` Stefan Hajnoczi [this message]
2012-11-22 14:50 ` [Qemu-devel] [RFC PATCH v2 2/3] virtio-pci : add a virtio-bus interface fred.konrad
2012-11-23 12:11   ` Cornelia Huck
2012-11-23 12:29   ` Stefan Hajnoczi
2012-11-23 12:34     ` Peter Maydell
2012-11-23 14:23       ` Konrad Frederic
2012-11-23 14:26         ` Peter Maydell
2012-11-23 14:33           ` Konrad Frederic
2012-11-26 14:43   ` Anthony Liguori
2012-11-22 14:50 ` [Qemu-devel] [RFC PATCH v2 3/3] virtio-blk : add the virtio-blk device fred.konrad
2012-11-23 12:32   ` Stefan Hajnoczi
2012-11-22 15:08 ` [Qemu-devel] [RFC PATCH v2 0/3] Virtio-refactoring Peter Maydell
2012-11-22 15:15   ` KONRAD Frédéric
2012-11-23 12:38 ` Stefan Hajnoczi
2012-11-23 14:29   ` Konrad Frederic
2012-11-23 16:18     ` Stefan Hajnoczi
2012-11-26  9:00       ` Konrad Frederic

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=20121126154054.GA25839@stefanha-thinkpad.redhat.com \
    --to=stefanha@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=e.voevodin@samsung.com \
    --cc=fred.konrad@greensocs.com \
    --cc=mark.burton@greensocs.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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).