2012-12-05 17:49:11 +01:00
|
|
|
/*
|
|
|
|
* qdev property parsing and global properties
|
|
|
|
* (parts specific for qemu-system-*)
|
|
|
|
*
|
|
|
|
* This file is based on code from hw/qdev-properties.c from
|
|
|
|
* commit 074a86fccd185616469dfcdc0e157f438aebba18,
|
|
|
|
* Copyright (c) Gerd Hoffmann <kraxel@redhat.com> and other contributors.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:29 +01:00
|
|
|
#include "qemu/osdep.h"
|
2012-12-23 00:39:34 +01:00
|
|
|
#include "net/net.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/qdev.h"
|
2012-12-23 00:39:34 +01:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2014-10-07 13:59:18 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2012-12-23 00:39:34 +01:00
|
|
|
#include "sysemu/blockdev.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/block/block.h"
|
2012-12-05 17:49:11 +01:00
|
|
|
#include "net/hub.h"
|
2012-12-23 00:39:34 +01:00
|
|
|
#include "qapi/visitor.h"
|
2013-04-08 16:55:25 +02:00
|
|
|
#include "sysemu/char.h"
|
2014-03-03 11:30:07 +01:00
|
|
|
#include "sysemu/iothread.h"
|
2012-12-05 17:49:11 +01:00
|
|
|
|
|
|
|
static void get_pointer(Object *obj, Visitor *v, Property *prop,
|
2014-03-03 11:30:06 +01:00
|
|
|
char *(*print)(void *ptr),
|
2012-12-05 17:49:11 +01:00
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
void **ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
char *p;
|
|
|
|
|
2014-03-03 11:30:06 +01:00
|
|
|
p = *ptr ? print(*ptr) : g_strdup("");
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_str(v, name, &p, errp);
|
2014-03-03 11:30:06 +01:00
|
|
|
g_free(p);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_pointer(Object *obj, Visitor *v, Property *prop,
|
2015-06-26 15:22:36 +02:00
|
|
|
void (*parse)(DeviceState *dev, const char *str,
|
|
|
|
void **ptr, const char *propname,
|
|
|
|
Error **errp),
|
2012-12-05 17:49:11 +01:00
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Error *local_err = NULL;
|
|
|
|
void **ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
char *str;
|
|
|
|
|
2013-01-09 03:58:10 +01:00
|
|
|
if (dev->realized) {
|
2013-03-25 14:40:44 +01:00
|
|
|
qdev_prop_set_after_realize(dev, name, errp);
|
2012-12-05 17:49:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_str(v, name, &str, &local_err);
|
2012-12-05 17:49:11 +01:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!*str) {
|
|
|
|
g_free(str);
|
|
|
|
*ptr = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2015-06-26 15:22:36 +02:00
|
|
|
parse(dev, str, ptr, prop->name, errp);
|
2012-12-05 17:49:11 +01:00
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- drive --- */
|
|
|
|
|
2015-06-26 15:22:36 +02:00
|
|
|
static void parse_drive(DeviceState *dev, const char *str, void **ptr,
|
|
|
|
const char *propname, Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
2014-10-07 13:59:18 +02:00
|
|
|
BlockBackend *blk;
|
2012-12-05 17:49:11 +01:00
|
|
|
|
2014-10-07 13:59:18 +02:00
|
|
|
blk = blk_by_name(str);
|
|
|
|
if (!blk) {
|
2015-06-26 15:22:36 +02:00
|
|
|
error_setg(errp, "Property '%s.%s' can't find value '%s'",
|
|
|
|
object_get_typename(OBJECT(dev)), propname, str);
|
|
|
|
return;
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
2014-10-07 13:59:18 +02:00
|
|
|
if (blk_attach_dev(blk, dev) < 0) {
|
qdev-properties-system: Improve error message for drive assignment conflict
If the user forgot if=none on their drive specification they're likely
to get an error message because the drive is assigned once automatically
by QEMU and once by the manual id=/drive= user command line specification.
Improve the error message produced in this case to explicitly guide the
user towards if=none.
We rephrase the "drive conflict but not for an if=something" error as
well to keep the wording in line.
The two cases that change are:
(1) Drive specified as to be auto-connected and also manually connected
(and the board does handle this if= type):
qemu-system-x86_64 -nodefaults -display none \
-drive if=scsi,file=tmp.qcow2,id=foo -device ide-hd,drive=foo
Previously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive'
can't take value 'foo', it's in use
Now:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in
use because it has been automatically connected to another device (did
you need 'if=none' in the drive options?)
(2) Drive specified to be manually connected in two different ways:
qemu-system-x86_64 -nodefaults -display none \
-drive if=none,file=tmp.qcow2,id=foo -device ide-hd,drive=foo \
-device ide-hd,drive=foo
Previously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive'
can't take value 'foo', it's in use
Now:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in
use by another device
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1435068107-12594-3-git-send-email-peter.maydell@linaro.org
2015-06-26 15:22:36 +02:00
|
|
|
DriveInfo *dinfo = blk_legacy_dinfo(blk);
|
|
|
|
|
|
|
|
if (dinfo->type != IF_NONE) {
|
|
|
|
error_setg(errp, "Drive '%s' is already in use because "
|
|
|
|
"it has been automatically connected to another "
|
|
|
|
"device (did you need 'if=none' in the drive options?)",
|
|
|
|
str);
|
|
|
|
} else {
|
|
|
|
error_setg(errp, "Drive '%s' is already in use by another device",
|
|
|
|
str);
|
|
|
|
}
|
2015-06-26 15:22:36 +02:00
|
|
|
return;
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
2014-10-07 13:59:18 +02:00
|
|
|
*ptr = blk;
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void release_drive(Object *obj, const char *name, void *opaque)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
2014-10-07 13:59:18 +02:00
|
|
|
BlockBackend **ptr = qdev_get_prop_ptr(dev, prop);
|
2012-12-05 17:49:11 +01:00
|
|
|
|
|
|
|
if (*ptr) {
|
2014-10-07 13:59:18 +02:00
|
|
|
blk_detach_dev(*ptr, dev);
|
2012-12-05 17:49:11 +01:00
|
|
|
blockdev_auto_del(*ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 11:30:06 +01:00
|
|
|
static char *print_drive(void *ptr)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
2014-10-07 13:59:18 +02:00
|
|
|
return g_strdup(blk_name(ptr));
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
get_pointer(obj, v, opaque, print_drive, name, errp);
|
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
set_pointer(obj, v, opaque, parse_drive, name, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_drive = {
|
2014-02-08 11:01:56 +01:00
|
|
|
.name = "str",
|
2014-10-07 08:33:20 +02:00
|
|
|
.description = "ID of a drive to use as a backend",
|
2012-12-05 17:49:11 +01:00
|
|
|
.get = get_drive,
|
|
|
|
.set = set_drive,
|
|
|
|
.release = release_drive,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- character device --- */
|
|
|
|
|
2015-06-26 15:22:36 +02:00
|
|
|
static void parse_chr(DeviceState *dev, const char *str, void **ptr,
|
|
|
|
const char *propname, Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
CharDriverState *chr = qemu_chr_find(str);
|
|
|
|
if (chr == NULL) {
|
2015-06-26 15:22:36 +02:00
|
|
|
error_setg(errp, "Property '%s.%s' can't find value '%s'",
|
|
|
|
object_get_typename(OBJECT(dev)), propname, str);
|
|
|
|
return;
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
2013-03-27 20:29:39 +01:00
|
|
|
if (qemu_chr_fe_claim(chr) != 0) {
|
2015-06-26 15:22:36 +02:00
|
|
|
error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use",
|
|
|
|
object_get_typename(OBJECT(dev)), propname, str);
|
|
|
|
return;
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
*ptr = chr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_chr(Object *obj, const char *name, void *opaque)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
|
2013-03-26 11:07:59 +01:00
|
|
|
CharDriverState *chr = *ptr;
|
2012-12-05 17:49:11 +01:00
|
|
|
|
2013-03-26 11:07:59 +01:00
|
|
|
if (chr) {
|
|
|
|
qemu_chr_add_handlers(chr, NULL, NULL, NULL, NULL);
|
2013-03-27 20:29:39 +01:00
|
|
|
qemu_chr_fe_release(chr);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-03 11:30:06 +01:00
|
|
|
static char *print_chr(void *ptr)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
CharDriverState *chr = ptr;
|
2014-03-03 11:30:06 +01:00
|
|
|
const char *val = chr->label ? chr->label : "";
|
2012-12-05 17:49:11 +01:00
|
|
|
|
2014-03-03 11:30:06 +01:00
|
|
|
return g_strdup(val);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void get_chr(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
get_pointer(obj, v, opaque, print_chr, name, errp);
|
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
set_pointer(obj, v, opaque, parse_chr, name, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_chr = {
|
2014-02-08 11:01:56 +01:00
|
|
|
.name = "str",
|
2014-10-07 08:33:20 +02:00
|
|
|
.description = "ID of a chardev to use as a backend",
|
2012-12-05 17:49:11 +01:00
|
|
|
.get = get_chr,
|
|
|
|
.set = set_chr,
|
|
|
|
.release = release_chr,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- netdev device --- */
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void get_netdev(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-10-13 07:16:37 +02:00
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
char *p = g_strdup(peers_ptr->ncs[0] ? peers_ptr->ncs[0]->name : "");
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_str(v, name, &p, errp);
|
2014-10-13 07:16:37 +02:00
|
|
|
g_free(p);
|
|
|
|
}
|
2012-12-05 17:49:11 +01:00
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void set_netdev(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
2014-10-13 07:16:37 +02:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
|
2013-01-30 12:12:28 +01:00
|
|
|
NetClientState **ncs = peers_ptr->ncs;
|
|
|
|
NetClientState *peers[MAX_QUEUE_NUM];
|
2014-10-13 07:16:37 +02:00
|
|
|
Error *local_err = NULL;
|
|
|
|
int queues, err = 0, i = 0;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (dev->realized) {
|
|
|
|
qdev_prop_set_after_realize(dev, name, errp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_str(v, name, &str, &local_err);
|
2014-10-13 07:16:37 +02:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2012-12-05 17:49:11 +01:00
|
|
|
|
2013-01-30 12:12:28 +01:00
|
|
|
queues = qemu_find_net_clients_except(str, peers,
|
|
|
|
NET_CLIENT_OPTIONS_KIND_NIC,
|
|
|
|
MAX_QUEUE_NUM);
|
|
|
|
if (queues == 0) {
|
2014-10-13 07:16:37 +02:00
|
|
|
err = -ENOENT;
|
|
|
|
goto out;
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
2013-01-30 12:12:28 +01:00
|
|
|
|
|
|
|
if (queues > MAX_QUEUE_NUM) {
|
2014-10-13 07:16:37 +02:00
|
|
|
error_setg(errp, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
|
|
|
|
str, queues, MAX_QUEUE_NUM);
|
|
|
|
goto out;
|
2013-01-30 12:12:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < queues; i++) {
|
|
|
|
if (peers[i] == NULL) {
|
2014-10-13 07:16:37 +02:00
|
|
|
err = -ENOENT;
|
|
|
|
goto out;
|
2013-01-30 12:12:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peers[i]->peer) {
|
2014-10-13 07:16:37 +02:00
|
|
|
err = -EEXIST;
|
|
|
|
goto out;
|
2013-01-30 12:12:28 +01:00
|
|
|
}
|
|
|
|
|
2013-11-08 03:13:09 +01:00
|
|
|
if (ncs[i]) {
|
2014-10-13 07:16:37 +02:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
2013-11-08 03:13:09 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 12:12:28 +01:00
|
|
|
ncs[i] = peers[i];
|
|
|
|
ncs[i]->queue_index = i;
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
2013-01-30 12:12:28 +01:00
|
|
|
|
2014-05-26 12:04:08 +02:00
|
|
|
peers_ptr->queues = queues;
|
2013-01-30 12:12:28 +01:00
|
|
|
|
2014-10-13 07:16:37 +02:00
|
|
|
out:
|
|
|
|
error_set_from_qdev_prop_error(errp, err, dev, prop, str);
|
|
|
|
g_free(str);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_netdev = {
|
2014-02-08 11:01:56 +01:00
|
|
|
.name = "str",
|
2014-10-07 08:33:20 +02:00
|
|
|
.description = "ID of a netdev to use as a backend",
|
2012-12-05 17:49:11 +01:00
|
|
|
.get = get_netdev,
|
|
|
|
.set = set_netdev,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- vlan --- */
|
|
|
|
|
|
|
|
static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
|
|
|
|
{
|
|
|
|
NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
|
|
|
|
if (*ptr) {
|
|
|
|
int id;
|
|
|
|
if (!net_hub_id_for_client(*ptr, &id)) {
|
|
|
|
return snprintf(dest, len, "%d", id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return snprintf(dest, len, "<null>");
|
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void get_vlan(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
int32_t id = -1;
|
|
|
|
|
|
|
|
if (*ptr) {
|
|
|
|
int hub_id;
|
|
|
|
if (!net_hub_id_for_client(*ptr, &hub_id)) {
|
|
|
|
id = hub_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_int32(v, name, &id, errp);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void set_vlan(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
2013-01-30 12:12:28 +01:00
|
|
|
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
NetClientState **ptr = &peers_ptr->ncs[0];
|
2012-12-05 17:49:11 +01:00
|
|
|
Error *local_err = NULL;
|
|
|
|
int32_t id;
|
|
|
|
NetClientState *hubport;
|
|
|
|
|
2013-01-09 03:58:10 +01:00
|
|
|
if (dev->realized) {
|
2013-03-25 14:40:44 +01:00
|
|
|
qdev_prop_set_after_realize(dev, name, errp);
|
2012-12-05 17:49:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_int32(v, name, &id, &local_err);
|
2012-12-05 17:49:11 +01:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (id == -1) {
|
|
|
|
*ptr = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2013-11-08 03:13:09 +01:00
|
|
|
if (*ptr) {
|
|
|
|
error_set_from_qdev_prop_error(errp, -EINVAL, dev, prop, name);
|
|
|
|
return;
|
|
|
|
}
|
2012-12-05 17:49:11 +01:00
|
|
|
|
|
|
|
hubport = net_hub_port_find(id);
|
|
|
|
if (!hubport) {
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
|
|
|
name, prop->info->name);
|
2012-12-05 17:49:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*ptr = hubport;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_vlan = {
|
2014-02-08 11:01:56 +01:00
|
|
|
.name = "int32",
|
2014-10-07 08:33:20 +02:00
|
|
|
.description = "Integer VLAN id to connect to",
|
2012-12-05 17:49:11 +01:00
|
|
|
.print = print_vlan,
|
|
|
|
.get = get_vlan,
|
|
|
|
.set = set_vlan,
|
|
|
|
};
|
|
|
|
|
2015-03-09 19:17:26 +01:00
|
|
|
void qdev_prop_set_drive(DeviceState *dev, const char *name,
|
|
|
|
BlockBackend *value, Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
2015-03-09 19:17:26 +01:00
|
|
|
object_property_set_str(OBJECT(dev), value ? blk_name(value) : "",
|
|
|
|
name, errp);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void qdev_prop_set_chr(DeviceState *dev, const char *name,
|
|
|
|
CharDriverState *value)
|
|
|
|
{
|
|
|
|
assert(!value || value->label);
|
|
|
|
object_property_set_str(OBJECT(dev),
|
2014-01-02 03:48:08 +01:00
|
|
|
value ? value->label : "", name, &error_abort);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void qdev_prop_set_netdev(DeviceState *dev, const char *name,
|
|
|
|
NetClientState *value)
|
|
|
|
{
|
|
|
|
assert(!value || value->name);
|
|
|
|
object_property_set_str(OBJECT(dev),
|
2014-01-02 03:48:08 +01:00
|
|
|
value ? value->name : "", name, &error_abort);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
|
|
|
|
{
|
|
|
|
qdev_prop_set_macaddr(dev, "mac", nd->macaddr.a);
|
|
|
|
if (nd->netdev) {
|
|
|
|
qdev_prop_set_netdev(dev, "netdev", nd->netdev);
|
|
|
|
}
|
|
|
|
if (nd->nvectors != DEV_NVECTORS_UNSPECIFIED &&
|
|
|
|
object_property_find(OBJECT(dev), "vectors", NULL)) {
|
|
|
|
qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
|
|
|
|
}
|
|
|
|
nd->instantiated = 1;
|
|
|
|
}
|
|
|
|
|
2015-03-13 13:35:14 +01:00
|
|
|
static int qdev_add_one_global(void *opaque, QemuOpts *opts, Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
GlobalProperty *g;
|
|
|
|
|
|
|
|
g = g_malloc0(sizeof(*g));
|
|
|
|
g->driver = qemu_opt_get(opts, "driver");
|
|
|
|
g->property = qemu_opt_get(opts, "property");
|
|
|
|
g->value = qemu_opt_get(opts, "value");
|
2014-08-08 21:03:31 +02:00
|
|
|
g->user_provided = true;
|
2012-12-05 17:49:11 +01:00
|
|
|
qdev_prop_register_global(g);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemu_add_globals(void)
|
|
|
|
{
|
2015-03-13 13:35:14 +01:00
|
|
|
qemu_opts_foreach(qemu_find_opts("global"),
|
|
|
|
qdev_add_one_global, NULL, NULL);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|