From patchwork Wed Oct 21 13:25:23 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 36557 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 56B68B7B72 for ; Thu, 22 Oct 2009 00:58:52 +1100 (EST) Received: from localhost ([127.0.0.1]:54744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0biD-00014Z-Cf for incoming@patchwork.ozlabs.org; Wed, 21 Oct 2009 09:58:49 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0bCO-0007lX-Tb for qemu-devel@nongnu.org; Wed, 21 Oct 2009 09:25:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0bCJ-0007ei-OG for qemu-devel@nongnu.org; Wed, 21 Oct 2009 09:25:56 -0400 Received: from [199.232.76.173] (port=55710 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0bCJ-0007eU-HW for qemu-devel@nongnu.org; Wed, 21 Oct 2009 09:25:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63643) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0bCI-0007OP-Oo for qemu-devel@nongnu.org; Wed, 21 Oct 2009 09:25:51 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9LDPnLQ004200 for ; Wed, 21 Oct 2009 09:25:50 -0400 Received: from zweiblum.home.kraxel.org (vpn2-9-113.ams2.redhat.com [10.36.9.113]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9LDPjgA026967; Wed, 21 Oct 2009 09:25:46 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id CF08A7010A; Wed, 21 Oct 2009 15:25:43 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 21 Oct 2009 15:25:23 +0200 Message-Id: <1256131543-28416-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1256131543-28416-1-git-send-email-kraxel@redhat.com> References: <1256131543-28416-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 02/22] qdev: mac addr property fixups X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make the mac property use the newly added type for the mac address. Signed-off-by: Gerd Hoffmann --- hw/qdev-properties.c | 31 +++++++++++++++++++++---------- hw/qdev.h | 3 ++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 5c627fa..1d68125 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -1,4 +1,5 @@ #include "sysemu.h" +#include "net.h" #include "qdev.h" void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) @@ -274,7 +275,7 @@ PropertyInfo qdev_prop_ptr = { */ static int parse_mac(DeviceState *dev, Property *prop, const char *str) { - uint8_t *mac = qdev_get_prop_ptr(dev, prop); + MACAddr *mac = qdev_get_prop_ptr(dev, prop); int i, pos; char *p; @@ -283,26 +284,31 @@ static int parse_mac(DeviceState *dev, Property *prop, const char *str) return -1; if (!qemu_isxdigit(str[pos+1])) return -1; - if (i == 5 && str[pos+2] != '\0') - return -1; - if (str[pos+2] != ':' && str[pos+2] != '-') - return -1; - mac[i] = strtol(str+pos, &p, 16); + if (i == 5) { + if (str[pos+2] != '\0') + return -1; + } else { + if (str[pos+2] != ':' && str[pos+2] != '-') + return -1; + } + mac->a[i] = strtol(str+pos, &p, 16); } return 0; } static int print_mac(DeviceState *dev, Property *prop, char *dest, size_t len) { - uint8_t *mac = qdev_get_prop_ptr(dev, prop); + MACAddr *mac = qdev_get_prop_ptr(dev, prop); + return snprintf(dest, len, "%02x:%02x:%02x:%02x:%02x:%02x", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + mac->a[0], mac->a[1], mac->a[2], + mac->a[3], mac->a[4], mac->a[5]); } PropertyInfo qdev_prop_macaddr = { - .name = "mac-addr", + .name = "macaddr", .type = PROP_TYPE_MACADDR, - .size = 6, + .size = sizeof(MACAddr), .parse = parse_mac, .print = print_mac, }; @@ -454,6 +460,11 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu qdev_prop_set(dev, name, &value, PROP_TYPE_CHR); } +void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value) +{ + qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR); +} + void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) { qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); diff --git a/hw/qdev.h b/hw/qdev.h index 8cd843e..118e886 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -230,7 +230,7 @@ extern PropertyInfo qdev_prop_pci_devfn; #define DEFINE_PROP_DRIVE(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) #define DEFINE_PROP_MACADDR(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, uint8_t[6]) + DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) #define DEFINE_PROP_END_OF_LIST() \ {} @@ -246,6 +246,7 @@ void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value); void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value); +void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); /* FIXME: Remove opaque pointer properties. */ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_set_defaults(DeviceState *dev, Property *props);