mirror of https://gitee.com/openkylin/qemu.git
qdev: add vlan property
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
2ef924b416
commit
851bec091d
|
@ -310,6 +310,40 @@ PropertyInfo qdev_prop_netdev = {
|
|||
.print = print_netdev,
|
||||
};
|
||||
|
||||
/* --- vlan --- */
|
||||
|
||||
static int parse_vlan(DeviceState *dev, Property *prop, const char *str)
|
||||
{
|
||||
VLANState **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
int id;
|
||||
|
||||
if (sscanf(str, "%d", &id) != 1)
|
||||
return -1;
|
||||
*ptr = qemu_find_vlan(id, 1);
|
||||
if (*ptr == NULL)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
|
||||
{
|
||||
VLANState **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
|
||||
if (*ptr) {
|
||||
return snprintf(dest, len, "%d", (*ptr)->id);
|
||||
} else {
|
||||
return snprintf(dest, len, "<null>");
|
||||
}
|
||||
}
|
||||
|
||||
PropertyInfo qdev_prop_vlan = {
|
||||
.name = "vlan",
|
||||
.type = PROP_TYPE_VLAN,
|
||||
.size = sizeof(VLANClientState*),
|
||||
.parse = parse_vlan,
|
||||
.print = print_vlan,
|
||||
};
|
||||
|
||||
/* --- pointer --- */
|
||||
|
||||
static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
|
||||
|
@ -524,6 +558,11 @@ void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *v
|
|||
qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
|
||||
}
|
||||
|
||||
void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
|
||||
{
|
||||
qdev_prop_set(dev, name, &value, PROP_TYPE_VLAN);
|
||||
}
|
||||
|
||||
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
|
||||
{
|
||||
qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
|
||||
|
|
|
@ -81,6 +81,7 @@ enum PropertyType {
|
|||
PROP_TYPE_CHR,
|
||||
PROP_TYPE_STRING,
|
||||
PROP_TYPE_NETDEV,
|
||||
PROP_TYPE_VLAN,
|
||||
PROP_TYPE_PTR,
|
||||
};
|
||||
|
||||
|
@ -193,6 +194,8 @@ extern PropertyInfo qdev_prop_chr;
|
|||
extern PropertyInfo qdev_prop_ptr;
|
||||
extern PropertyInfo qdev_prop_macaddr;
|
||||
extern PropertyInfo qdev_prop_drive;
|
||||
extern PropertyInfo qdev_prop_netdev;
|
||||
extern PropertyInfo qdev_prop_vlan;
|
||||
extern PropertyInfo qdev_prop_pci_devfn;
|
||||
|
||||
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
|
||||
|
@ -234,6 +237,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
|
|||
DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
|
||||
#define DEFINE_PROP_NETDEV(_n, _s, _f) \
|
||||
DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
|
||||
#define DEFINE_PROP_VLAN(_n, _s, _f) \
|
||||
DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
|
||||
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
|
||||
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
|
||||
#define DEFINE_PROP_MACADDR(_n, _s, _f) \
|
||||
|
@ -253,6 +258,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_netdev(DeviceState *dev, const char *name, VLANClientState *value);
|
||||
void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *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. */
|
||||
|
|
Loading…
Reference in New Issue