qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@linux.vnet.ibm.com>
To: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: rusty@rustcorp.com.au, mst@redhat.com, qemu-devel@nongnu.org,
	virtualization@lists.linux-foundation.org
Subject: Re: [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers
Date: Thu, 11 Dec 2014 15:46:23 +0100	[thread overview]
Message-ID: <20141211154623.4a73fef9@oc7435384737.ibm.com> (raw)
In-Reply-To: <1418304322-7546-5-git-send-email-cornelia.huck@de.ibm.com>

On Thu, 11 Dec 2014 14:25:06 +0100
Cornelia Huck <cornelia.huck@de.ibm.com> wrote:

> Add a helper function for checking whether a bit is set in the guest
> features for a vdev as well as one that works on a feature bit set.
> 
> Convert code that open-coded this: It cleans up the code and makes it
> easier to extend the guest feature bits.
> 
> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
...
> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> index ef48550..56c92fb 100644
> --- a/hw/scsi/virtio-scsi.c
> +++ b/hw/scsi/virtio-scsi.c
> @@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
>       *
>       * TODO: always disable this workaround for virtio 1.0 devices.
>       */
> -    if ((vdev->guest_features & VIRTIO_F_ANY_LAYOUT) == 0) {
> +    if (!virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT)) {

Wait ... this does not only look like a clean-up, but also like a
bug-fix to me, since it should have been "(1 << VIRTIO_F_ANY_LAYOUT)"
instead of "VIRTIO_F_ANY_LAYOUT" in the original code instead?

So in case this patch queue takes a little bit longer 'til it gets
upstream, do we might want to submit a separate patch for fixing this
issue first?

>          req_size = req->elem.out_sg[0].iov_len;
>          resp_size = req->elem.in_sg[0].iov_len;
>      }
> @@ -748,7 +748,7 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)
>      VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
>      VirtIODevice *vdev = VIRTIO_DEVICE(s);
> 
> -    if (((vdev->guest_features >> VIRTIO_SCSI_F_CHANGE) & 1) &&
> +    if (virtio_has_feature(vdev, VIRTIO_SCSI_F_CHANGE) &&
>          dev->type != TYPE_ROM) {
>          virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE,
>                                 sense.asc | (sense.ascq << 8));
> @@ -769,7 +769,7 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,
>          blk_op_block_all(sd->conf.blk, s->blocker);
>      }
> 
> -    if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
> +    if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
>          virtio_scsi_push_event(s, sd,
>                                 VIRTIO_SCSI_T_TRANSPORT_RESET,
>                                 VIRTIO_SCSI_EVT_RESET_RESCAN);
> @@ -783,7 +783,7 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,
>      VirtIOSCSI *s = VIRTIO_SCSI(vdev);
>      SCSIDevice *sd = SCSI_DEVICE(dev);
> 
> -    if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
> +    if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
>          virtio_scsi_push_event(s, sd,
>                                 VIRTIO_SCSI_T_TRANSPORT_RESET,
>                                 VIRTIO_SCSI_EVT_RESET_REMOVED);
...
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 2fede2e..f6c0379 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -278,6 +278,17 @@ static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit)
>      *features &= ~(1 << fbit);
>  }
> 
> +static inline bool __virtio_has_feature(uint32_t features, unsigned int fbit)
> +{
> +    assert(fbit < 32);
> +    return !!(features & (1 << fbit));
> +}
> +
> +static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit)
> +{
> +    return __virtio_has_feature(vdev->guest_features, fbit);
> +}
> +

I've got to say that I'm a little bit unhappy with the naming of the
functions - and in contrast to the Linux kernel code, I think it is
also quite uncommon in the QEMU sources to use function names with
double underscores at the beginning.

Could you maybe rename the second function to "virtio_vdev_has_feature"
instead? And then remove the double underscores from the first function?

 Thomas

  reply	other threads:[~2014-12-11 14:46 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-11 13:25 [Qemu-devel] [PATCH RFC v6 00/20] qemu: towards virtio-1 host support Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 01/20] linux-headers/virtio_config: Update with VIRTIO_F_VERSION_1 Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 02/20] virtio: cull virtio_bus_set_vdev_features Cornelia Huck
2015-01-22  1:24   ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 03/20] virtio: feature bit manipulation helpers Cornelia Huck
2014-12-11 14:29   ` Thomas Huth
2015-01-22  1:25   ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 04/20] virtio: add feature checking helpers Cornelia Huck
2014-12-11 14:46   ` Thomas Huth [this message]
2014-12-11 17:05     ` Michael S. Tsirkin
2014-12-12  8:37       ` Cornelia Huck
2014-12-12 10:07     ` Cornelia Huck
2015-01-22  1:28   ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 05/20] virtio: support more feature bits Cornelia Huck
2014-12-12 10:06   ` Thomas Huth
2014-12-12 10:17     ` Cornelia Huck
2015-01-22  1:40       ` David Gibson
2015-01-22  1:43   ` David Gibson
2015-01-28 15:59     ` Cornelia Huck
2015-01-29  0:11       ` David Gibson
2015-01-29  9:24         ` Thomas Huth
2015-01-29 10:01           ` David Gibson
2015-01-29 10:54             ` Michael S. Tsirkin
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 06/20] virtio: endianness checks for virtio 1.0 devices Cornelia Huck
2015-01-20 10:29   ` Stefan Hajnoczi
2015-01-22  1:54   ` David Gibson
2015-01-23 16:09     ` Greg Kurz
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 07/20] virtio: allow virtio-1 queue layout Cornelia Huck
2015-01-22  2:06   ` David Gibson
2015-01-28 16:07     ` Cornelia Huck
2015-01-29  0:14       ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 08/20] dataplane: allow virtio-1 devices Cornelia Huck
2015-01-20 10:43   ` Stefan Hajnoczi
2015-01-20 12:56     ` Cornelia Huck
2015-01-20 14:47       ` Stefan Hajnoczi
2015-01-22  2:12   ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 09/20] s390x/css: Add a callback for when subchannel gets disabled Cornelia Huck
2015-01-20 10:50   ` Stefan Hajnoczi
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 10/20] s390x/virtio-ccw: add virtio set-revision call Cornelia Huck
2015-01-20 11:00   ` Stefan Hajnoczi
2015-01-20 11:08   ` Stefan Hajnoczi
2015-01-21 11:23     ` Cornelia Huck
2015-01-21 11:51       ` Thomas Huth
2015-01-21 12:39         ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 11/20] s390x/virtio-ccw: support virtio-1 set_vq format Cornelia Huck
2015-01-20 11:06   ` Stefan Hajnoczi
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 12/20] virtio: disallow late feature changes for virtio-1 Cornelia Huck
2014-12-12 10:55   ` Thomas Huth
2014-12-12 11:18     ` Cornelia Huck
2014-12-12 11:25       ` Thomas Huth
2015-01-20 11:14         ` Stefan Hajnoczi
2015-01-22  2:15   ` David Gibson
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 13/20] virtio: allow to fail setting status Cornelia Huck
2014-12-30 12:25   ` Michael S. Tsirkin
2015-01-07 16:13     ` Cornelia Huck
2015-01-07 19:08       ` Michael S. Tsirkin
2015-01-08  7:20         ` Cornelia Huck
2015-01-08  8:09           ` Michael S. Tsirkin
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 14/20] s390x/virtio-ccw: enable virtio 1.0 Cornelia Huck
2015-01-20 11:15   ` Stefan Hajnoczi
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 15/20] virtio-net: no writeable mac for virtio-1 Cornelia Huck
2015-01-20 11:19   ` Stefan Hajnoczi
2015-01-22 16:31     ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 16/20] virtio-net: support longer header Cornelia Huck
2015-01-20 13:18   ` Stefan Hajnoczi
2015-01-21 16:06     ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 17/20] virtio-net: enable virtio 1.0 Cornelia Huck
2014-12-16 13:10   ` Michael S. Tsirkin
2014-12-18 16:57     ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 18/20] virtio: support revision-specific features Cornelia Huck
2014-12-28  8:32   ` Michael S. Tsirkin
2015-01-07 16:22     ` Cornelia Huck
2015-01-07 19:10       ` Michael S. Tsirkin
2015-01-30 14:08         ` Cornelia Huck
2015-02-01 21:29           ` Michael S. Tsirkin
2015-02-02 14:10             ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 19/20] virtio-blk: revision specific feature bits Cornelia Huck
2014-12-28 10:24   ` Michael S. Tsirkin
2015-01-07 16:29     ` Cornelia Huck
2015-01-07 19:11       ` Michael S. Tsirkin
2015-01-30 14:10         ` Cornelia Huck
2014-12-11 13:25 ` [Qemu-devel] [PATCH RFC v6 20/20] vhost: 64 bit features Cornelia Huck

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=20141211154623.4a73fef9@oc7435384737.ibm.com \
    --to=thuth@linux.vnet.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    --cc=virtualization@lists.linux-foundation.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).