From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [RFC PATCH v2 2/5] qdev: mac addr property fixups
Date: Wed, 7 Oct 2009 14:36:33 +0200 [thread overview]
Message-ID: <1254918996-26050-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1254918996-26050-1-git-send-email-kraxel@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
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..c231f74 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_t *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)[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_t *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)[0], (*mac)[1], (*mac)[2],
+ (*mac)[3], (*mac)[4], (*mac)[5]);
}
PropertyInfo qdev_prop_macaddr = {
- .name = "mac-addr",
+ .name = "macaddr",
.type = PROP_TYPE_MACADDR,
- .size = 6,
+ .size = sizeof(macaddr_t),
.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, macaddr_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 893ae92..9c66501 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -229,7 +229,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_t)
#define DEFINE_PROP_END_OF_LIST() \
{}
@@ -245,6 +245,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);
--
1.6.2.5
next prev parent reply other threads:[~2009-10-07 12:36 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-07 12:36 [Qemu-devel] [RfC PATCH v2 0/5] qdev-ify network cards Gerd Hoffmann
2009-10-07 12:36 ` [Qemu-devel] [RFC PATCH v2 1/5] net: macaddr tweaks Gerd Hoffmann
2009-10-07 13:05 ` Anthony Liguori
2009-10-07 13:14 ` Gerd Hoffmann
2009-10-07 13:23 ` Anthony Liguori
2009-10-07 12:36 ` Gerd Hoffmann [this message]
2009-10-07 12:36 ` [Qemu-devel] [RFC PATCH v2 3/5] ne2k: work without vlan Gerd Hoffmann
2009-10-07 13:06 ` Anthony Liguori
2009-10-07 13:15 ` Gerd Hoffmann
2009-10-07 12:36 ` [Qemu-devel] [RFC PATCH v2 4/5] ne2k_isa: qdev-ify Gerd Hoffmann
2009-10-07 13:50 ` Mark McLoughlin
2009-10-07 14:07 ` Gerd Hoffmann
2009-10-07 12:36 ` [Qemu-devel] [RFC PATCH v2 5/5] ne2k_isa: add property for option rom loading Gerd Hoffmann
2009-10-07 13:08 ` Anthony Liguori
2009-10-07 13:21 ` Gerd Hoffmann
2009-10-07 13:28 ` Anthony Liguori
2009-10-07 14:00 ` Gerd Hoffmann
2009-10-07 14:17 ` Anthony Liguori
2009-10-07 14:27 ` Gerd Hoffmann
2009-10-07 18:34 ` Anthony Liguori
2009-10-12 10:13 ` 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=1254918996-26050-3-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--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).