qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Andreas Faerber <andreas.faerber@web.de>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 10/23] qdev: remove baked in notion of aliases
Date: Tue, 31 Jan 2012 08:44:17 +0100	[thread overview]
Message-ID: <4F279BD1.8010608@redhat.com> (raw)
In-Reply-To: <1327957741-5842-10-git-send-email-aliguori@us.ibm.com>

On 01/30/2012 10:08 PM, Anthony Liguori wrote:
> +/*
> + * Aliases were a bad idea from the start.  Let's keep them
> + * from spreading further.
> + */
> +static const char *qdev_class_get_alias(DeviceClass *dc)
> +{
> +    const char *typename = object_class_get_name(OBJECT_CLASS(dc));
> +
> +    if (strcmp(typename, "virtio-blk-pci") == 0) {
> +        return "virtio-blk";
> +    } else if (strcmp(typename, "virtio-net-pci") == 0) {
> +        return "virtio-net";
> +    } else if (strcmp(typename, "virtio-serial-pci") == 0) {
> +        return "virtio-serial";
> +    } else if (strcmp(typename, "virtio-balloon-pci") == 0) {
> +        return "virtio-balloon";
> +    } else if (strcmp(typename, "virtio-blk-s390") == 0) {
> +        return "virtio-blk";
> +    } else if (strcmp(typename, "virtio-net-s390") == 0) {
> +        return "virtio-net";
> +    } else if (strcmp(typename, "virtio-serial-s390") == 0) {
> +        return "virtio-serial";
> +    } else if (strcmp(typename, "lsi53c895a") == 0) {
> +        return "lsi";
> +    } else if (strcmp(typename, "ich9-ahci") == 0) {
> +        return "ahci";
> +    }
> +
> +    return NULL;
> +}
> +
> +static bool qdev_class_has_alias(DeviceClass *dc)
> +{
> +    return (qdev_class_get_alias(dc) != NULL);
> +}
> +
>   const char *qdev_fw_name(DeviceState *dev)
>   {
>       DeviceClass *dc = DEVICE_GET_CLASS(dev);
>
>       if (dc->fw_name) {
>           return dc->fw_name;
> -    } else if (dc->alias) {
> -        return dc->alias;
> +    } else if (qdev_class_has_alias(dc)) {
> +        return qdev_class_get_alias(dc);
>       }
>
>       return object_get_typename(OBJECT(dev));
> @@ -161,8 +197,8 @@ static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
>       if (dc->bus_info) {
>           error_printf(", bus %s", dc->bus_info->name);
>       }
> -    if (dc->alias) {
> -        error_printf(", alias \"%s\"", dc->alias);
> +    if (qdev_class_has_alias(dc)) {
> +        error_printf(", alias \"%s\"", qdev_class_get_alias(dc));
>       }
>       if (dc->desc) {
>           error_printf(", desc \"%s\"", dc->desc);
> @@ -188,6 +224,27 @@ static int set_property(const char *name, const char *value, void *opaque)
>       return 0;
>   }
>
> +static const char *find_typename_by_alias(const char *alias)
> +{
> +    /* I don't think s390 aliasing could have ever worked... */

Yes, because s390 doesn't have PCI.

> +    if (strcmp(alias, "virtio-blk") == 0) {
> +        return "virtio-blk-pci";
> +    } else if (strcmp(alias, "virtio-net") == 0) {
> +        return "virtio-net-pci";
> +    } else if (strcmp(alias, "virtio-serial") == 0) {
> +        return "virtio-serial-pci";
> +    } else if (strcmp(alias, "virtio-balloon") == 0) {
> +        return "virtio-balloon-pci";
> +    } else if (strcmp(alias, "lsi") == 0) {
> +        return "lsi53c895a";
> +    } else if (strcmp(alias, "ahci") == 0) {
> +        return "ich9-ahci";
> +    }
> +
> +    return NULL;
> +}
> +


Please change this to a table so that you can have:

     if (object_class_by_name(table[i].name) &&
         strcmp(alias, table[i].alias) == 0) {
         return table[i].name;
     }

and for the other direction

     if (object_class_by_name(table[i].name) &&
         strcmp(name, table[i].name) == 0) {
         return table[i].alias;
     }

Paolo

  reply	other threads:[~2012-01-31  7:44 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-30 21:08 [Qemu-devel] [PATCH 01/23] usb-hid: simplify class initialization a bit Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 03/23] qdev: make DeviceInfo private Anthony Liguori
2012-01-30 22:31   ` Andreas Färber
2012-01-30 21:08 ` [Qemu-devel] [PATCH 04/23] qdev: remove info from class Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 05/23] qdev: allow classes to overload qdev functions Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 06/23] qdev: refactor device creation to allow bus_info to be set only in class Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 07/23] qdev: kill off DeviceInfo list Anthony Liguori
2012-01-31 13:51   ` Andreas Färber
2012-01-30 21:08 ` [Qemu-devel] [PATCH 08/23] qdev: register all types natively through QEMU Object Model Anthony Liguori
2012-01-30 22:29   ` Peter Maydell
2012-01-30 22:43     ` Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 09/23] qdev: kill of DeviceInfo Anthony Liguori
2012-01-31 13:34   ` Andreas Färber
2012-02-01 19:46   ` Peter Maydell
2012-02-01 19:56     ` Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 10/23] qdev: remove baked in notion of aliases Anthony Liguori
2012-01-31  7:44   ` Paolo Bonzini [this message]
2012-01-30 21:08 ` [Qemu-devel] [PATCH 11/23] qom: allow object_class_foreach to take additional parameters to refine search Anthony Liguori
2012-01-31 13:42   ` Andreas Färber
2012-01-30 21:08 ` [Qemu-devel] [PATCH 12/23] qom: add new command to search for types Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 13/23] qdev: split out common init to instance_init Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 14/23] qdev: refactor away qdev_create_from_info Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 15/23] qdev: split out UI portions into a new function Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 16/23] qdev: nuke qdev_init_chardev() Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 17/23] qom: move properties from qdev to object Anthony Liguori
2012-01-31  7:46   ` Paolo Bonzini
2012-02-01 20:01     ` Anthony Liguori
2012-02-01 20:33       ` Paolo Bonzini
2012-01-30 21:08 ` [Qemu-devel] [PATCH 18/23] qom: accept any compatible type when setting a link property Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 19/23] qdev: implement cleanup logic in finalize Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 20/23] info qdm: do not require a parent_bus to be set Anthony Liguori
2012-01-30 21:08 ` [Qemu-devel] [PATCH 21/23] object: sure up reference counting Anthony Liguori
2012-01-31  7:49   ` Paolo Bonzini
2012-02-01 19:47   ` Peter Maydell
2012-02-01 19:55     ` Anthony Liguori
2012-01-30 21:09 ` [Qemu-devel] [PATCH 22/23] container: make a decendent of Object Anthony Liguori
2012-01-31  7:50   ` Paolo Bonzini
2012-01-31  9:21     ` Andreas Färber
2012-01-31  9:31       ` Paolo Bonzini
2012-02-01 19:48   ` Peter Maydell
2012-01-30 21:09 ` [Qemu-devel] [PATCH 23/23] not-for-upstream: fix device_del Anthony Liguori
2012-01-30 21:16 ` [Qemu-devel] [PATCH 00/23] qom: use Type system to register all devices Anthony Liguori
2012-01-30 22:46   ` Anthony Liguori
2012-02-01 19:55   ` Peter Maydell
2012-02-01 20:10     ` Anthony Liguori

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=4F279BD1.8010608@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=andreas.faerber@web.de \
    --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).