2012-12-05 17:49:11 +01:00
|
|
|
/*
|
2016-06-15 20:54:52 +02:00
|
|
|
* qdev property parsing
|
2012-12-05 17:49:11 +01:00
|
|
|
* (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"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-11 23:05:12 +01:00
|
|
|
#include "hw/qdev-properties-system.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2020-09-30 18:49:46 +02:00
|
|
|
#include "qapi/visitor.h"
|
|
|
|
#include "qapi/qapi-types-block.h"
|
|
|
|
#include "qapi/qapi-types-machine.h"
|
|
|
|
#include "qapi/qapi-types-migration.h"
|
2012-12-23 00:39:34 +01:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2020-09-30 18:49:46 +02:00
|
|
|
#include "qemu/ctype.h"
|
|
|
|
#include "qemu/cutils.h"
|
|
|
|
#include "qemu/units.h"
|
2020-12-11 23:05:11 +01:00
|
|
|
#include "qemu/uuid.h"
|
2020-09-30 18:49:46 +02:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qdev-prop-internal.h"
|
|
|
|
|
|
|
|
#include "audio/audio.h"
|
|
|
|
#include "chardev/char-fe.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"
|
2020-09-30 18:49:46 +02:00
|
|
|
#include "net/net.h"
|
|
|
|
#include "hw/pci/pci.h"
|
2020-09-18 10:09:09 +02:00
|
|
|
#include "util/block-helpers.h"
|
2012-12-05 17:49:11 +01:00
|
|
|
|
2020-12-11 23:05:08 +01:00
|
|
|
static bool check_prop_still_unset(Object *obj, const char *name,
|
qdev: Improve netdev property override error a bit
qdev_prop_set_netdev() fails when the property already has a non-null
value. Seems to go back to commit 30c367ed44
"qdev-properties-system.c: Allow vlan or netdev for -device, not
both", v1.7.0. Board code doesn't expect failure, and crashes:
$ qemu-system-x86_64 --nodefaults -nic user -netdev user,id=nic0 -global e1000.netdev=nic0
Unexpected error in error_set_from_qdev_prop_error() at /work/armbru/qemu/hw/core/qdev-properties.c:1101:
qemu-system-x86_64: Property 'e1000.netdev' doesn't take value '__org.qemu.nic0
'
Aborted (core dumped)
-device and device_add handle the failure:
$ qemu-system-x86_64 -nodefaults -netdev user,id=net0 -netdev user,id=net1 -device e1000,netdev=net0,netdev=net1
qemu-system-x86_64: -device e1000,netdev=net0,netdev=net1: Property 'e1000.netdev' doesn't take value 'net1'
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -netdev user,id=net0 -netdev user,id=net1 -global e1000.netdev=net0
QEMU 5.0.50 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: warning: netdev net0 has no peer
qemu-system-x86_64: warning: netdev net1 has no peer
device_add e1000,netdev=net1
Error: Property 'e1000.netdev' doesn't take value 'net1'
Perhaps netdev property override could be made to work. Perhaps it
should. I'm not the right guy to figure this out. What I can do is
improve the error message a bit:
(qemu) device_add e1000,netdev=net1
Error: -global e1000.netdev=... conflicts with netdev=net1
Cc: Jason Wang <jasowang@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-11-armbru@redhat.com>
2020-06-22 11:42:21 +02:00
|
|
|
const void *old_val, const char *new_val,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2020-12-11 23:05:08 +01:00
|
|
|
const GlobalProperty *prop = qdev_find_global_prop(obj, name);
|
qdev: Improve netdev property override error a bit
qdev_prop_set_netdev() fails when the property already has a non-null
value. Seems to go back to commit 30c367ed44
"qdev-properties-system.c: Allow vlan or netdev for -device, not
both", v1.7.0. Board code doesn't expect failure, and crashes:
$ qemu-system-x86_64 --nodefaults -nic user -netdev user,id=nic0 -global e1000.netdev=nic0
Unexpected error in error_set_from_qdev_prop_error() at /work/armbru/qemu/hw/core/qdev-properties.c:1101:
qemu-system-x86_64: Property 'e1000.netdev' doesn't take value '__org.qemu.nic0
'
Aborted (core dumped)
-device and device_add handle the failure:
$ qemu-system-x86_64 -nodefaults -netdev user,id=net0 -netdev user,id=net1 -device e1000,netdev=net0,netdev=net1
qemu-system-x86_64: -device e1000,netdev=net0,netdev=net1: Property 'e1000.netdev' doesn't take value 'net1'
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -netdev user,id=net0 -netdev user,id=net1 -global e1000.netdev=net0
QEMU 5.0.50 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: warning: netdev net0 has no peer
qemu-system-x86_64: warning: netdev net1 has no peer
device_add e1000,netdev=net1
Error: Property 'e1000.netdev' doesn't take value 'net1'
Perhaps netdev property override could be made to work. Perhaps it
should. I'm not the right guy to figure this out. What I can do is
improve the error message a bit:
(qemu) device_add e1000,netdev=net1
Error: -global e1000.netdev=... conflicts with netdev=net1
Cc: Jason Wang <jasowang@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-11-armbru@redhat.com>
2020-06-22 11:42:21 +02:00
|
|
|
|
|
|
|
if (!old_val) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop) {
|
|
|
|
error_setg(errp, "-global %s.%s=... conflicts with %s=%s",
|
|
|
|
prop->driver, prop->property, name, new_val);
|
|
|
|
} else {
|
|
|
|
/* Error message is vague, but a better one would be hard */
|
|
|
|
error_setg(errp, "%s=%s conflicts, and override is not implemented",
|
|
|
|
name, new_val);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-22 11:42:20 +02:00
|
|
|
/* --- drive --- */
|
|
|
|
|
|
|
|
static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
2020-06-22 11:42:20 +02:00
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
void **ptr = object_field_prop_ptr(obj, prop);
|
2020-06-22 11:42:20 +02:00
|
|
|
const char *value;
|
2012-12-05 17:49:11 +01:00
|
|
|
char *p;
|
|
|
|
|
2020-06-22 11:42:20 +02:00
|
|
|
if (*ptr) {
|
|
|
|
value = blk_name(*ptr);
|
|
|
|
if (!*value) {
|
|
|
|
BlockDriverState *bs = blk_bs(*ptr);
|
|
|
|
if (bs) {
|
|
|
|
value = bdrv_get_node_name(bs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
value = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
p = g_strdup(value);
|
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
|
|
|
}
|
|
|
|
|
2020-06-22 11:42:20 +02:00
|
|
|
static void set_drive_helper(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, bool iothread, Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
2020-06-22 11:42:20 +02:00
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
void **ptr = object_field_prop_ptr(obj, prop);
|
2012-12-05 17:49:11 +01:00
|
|
|
char *str;
|
2020-06-22 11:42:20 +02:00
|
|
|
BlockBackend *blk;
|
|
|
|
bool blk_created = false;
|
|
|
|
int ret;
|
2012-12-05 17:49:11 +01:00
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 18:06:02 +02:00
|
|
|
if (!visit_type_str(v, name, &str, errp)) {
|
2012-12-05 17:49:11 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-06-22 11:42:20 +02:00
|
|
|
|
2020-06-22 11:42:22 +02:00
|
|
|
/*
|
|
|
|
* TODO Should this really be an error? If no, the old value
|
|
|
|
* needs to be released before we store the new one.
|
|
|
|
*/
|
2020-12-11 23:05:08 +01:00
|
|
|
if (!check_prop_still_unset(obj, name, *ptr, str, errp)) {
|
2020-06-22 11:42:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:49:11 +01:00
|
|
|
if (!*str) {
|
|
|
|
g_free(str);
|
|
|
|
*ptr = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-07 13:59:18 +02:00
|
|
|
blk = blk_by_name(str);
|
2016-06-21 20:46:05 +02:00
|
|
|
if (!blk) {
|
|
|
|
BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL);
|
|
|
|
if (bs) {
|
2019-04-29 17:40:14 +02:00
|
|
|
/*
|
|
|
|
* If the device supports iothreads, it will make sure to move the
|
|
|
|
* block node to the right AioContext if necessary (or fail if this
|
|
|
|
* isn't possible because of other users). Devices that are not
|
|
|
|
* aware of iothreads require their BlockBackends to be in the main
|
|
|
|
* AioContext.
|
|
|
|
*/
|
|
|
|
AioContext *ctx = iothread ? bdrv_get_aio_context(bs) :
|
|
|
|
qemu_get_aio_context();
|
|
|
|
blk = blk_new(ctx, 0, BLK_PERM_ALL);
|
2016-06-21 20:46:05 +02:00
|
|
|
blk_created = true;
|
2017-01-13 19:02:32 +01:00
|
|
|
|
|
|
|
ret = blk_insert_bs(blk, bs, errp);
|
|
|
|
if (ret < 0) {
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-06-21 20:46:05 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-07 13:59:18 +02:00
|
|
|
if (!blk) {
|
2015-06-26 15:22:36 +02:00
|
|
|
error_setg(errp, "Property '%s.%s' can't find value '%s'",
|
2020-12-11 23:05:16 +01:00
|
|
|
object_get_typename(OBJECT(dev)), name, str);
|
2016-06-21 20:46:05 +02:00
|
|
|
goto fail;
|
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);
|
|
|
|
|
block/qdev: Fix NULL access when using BB twice
BlockBackend has only a single pointer to its guest device, so it makes
sure that only a single guest device is attached to it. device-add
returns an error if you try to attach a second device to a BB. In order
to make the error message nicer, -device that manually connects to a
if=none block device get a different message than -drive that implicitly
creates a guest device. The if=... option is stored in DriveInfo.
However, since blockdev-add exists, not every BlockBackend has a
DriveInfo any more. Check that it exists before we dereference it.
QMP reproducer resulting in a segfault:
{"execute":"blockdev-add","arguments":{"options":{"id":"disk","driver":"file","filename":"/tmp/test.img"}}}
{"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
{"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-06-23 09:30:01 +02:00
|
|
|
if (dinfo && dinfo->type != IF_NONE) {
|
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
|
|
|
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);
|
|
|
|
}
|
2016-06-21 20:46:05 +02:00
|
|
|
goto fail;
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
2016-06-21 20:46:05 +02:00
|
|
|
|
2014-10-07 13:59:18 +02:00
|
|
|
*ptr = blk;
|
2016-06-21 20:46:05 +02:00
|
|
|
|
|
|
|
fail:
|
|
|
|
if (blk_created) {
|
|
|
|
/* If we need to keep a reference, blk_attach_dev() took it */
|
|
|
|
blk_unref(blk);
|
|
|
|
}
|
2020-06-22 11:42:20 +02:00
|
|
|
|
|
|
|
g_free(str);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-22 11:42:20 +02:00
|
|
|
static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2019-04-29 17:40:14 +02:00
|
|
|
{
|
2020-06-22 11:42:20 +02:00
|
|
|
set_drive_helper(obj, v, name, opaque, false, errp);
|
2019-04-29 17:40:14 +02:00
|
|
|
}
|
|
|
|
|
2020-06-22 11:42:20 +02:00
|
|
|
static void set_drive_iothread(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2019-04-29 17:40:14 +02:00
|
|
|
{
|
2020-06-22 11:42:20 +02:00
|
|
|
set_drive_helper(obj, v, name, opaque, true, errp);
|
2019-04-29 17:40:14 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2020-12-11 23:05:27 +01:00
|
|
|
BlockBackend **ptr = object_field_prop_ptr(obj, prop);
|
2012-12-05 17:49:11 +01:00
|
|
|
|
|
|
|
if (*ptr) {
|
2017-03-28 18:12:46 +02:00
|
|
|
AioContext *ctx = blk_get_aio_context(*ptr);
|
|
|
|
|
|
|
|
aio_context_acquire(ctx);
|
2012-12-05 17:49:11 +01:00
|
|
|
blockdev_auto_del(*ptr);
|
2016-06-21 20:46:05 +02:00
|
|
|
blk_detach_dev(*ptr, dev);
|
2017-03-28 18:12:46 +02:00
|
|
|
aio_context_release(ctx);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 04:14:54 +02:00
|
|
|
const PropertyInfo qdev_prop_drive = {
|
2014-02-08 11:01:56 +01:00
|
|
|
.name = "str",
|
2016-06-21 20:46:05 +02:00
|
|
|
.description = "Node name or ID of a block device to use as a backend",
|
2012-12-05 17:49:11 +01:00
|
|
|
.get = get_drive,
|
|
|
|
.set = set_drive,
|
|
|
|
.release = release_drive,
|
|
|
|
};
|
|
|
|
|
2019-04-29 17:40:14 +02:00
|
|
|
const PropertyInfo qdev_prop_drive_iothread = {
|
|
|
|
.name = "str",
|
|
|
|
.description = "Node name or ID of a block device to use as a backend",
|
|
|
|
.get = get_drive,
|
|
|
|
.set = set_drive_iothread,
|
|
|
|
.release = release_drive,
|
|
|
|
};
|
|
|
|
|
2012-12-05 17:49:11 +01:00
|
|
|
/* --- character device --- */
|
|
|
|
|
2016-10-22 11:52:51 +02:00
|
|
|
static void get_chr(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
2020-12-11 23:05:27 +01:00
|
|
|
CharBackend *be = object_field_prop_ptr(obj, opaque);
|
2016-10-22 11:52:51 +02:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = g_strdup(be->chr && be->chr->label ? be->chr->label : "");
|
|
|
|
visit_type_str(v, name, &p, errp);
|
|
|
|
g_free(p);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
2016-10-22 11:52:51 +02:00
|
|
|
static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
CharBackend *be = object_field_prop_ptr(obj, prop);
|
2016-12-07 14:20:22 +01:00
|
|
|
Chardev *s;
|
2016-10-22 11:52:51 +02:00
|
|
|
char *str;
|
2012-12-05 17:49:11 +01:00
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 18:06:02 +02:00
|
|
|
if (!visit_type_str(v, name, &str, errp)) {
|
2016-10-22 11:52:51 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-12-05 17:49:11 +01:00
|
|
|
|
2020-06-22 11:42:23 +02:00
|
|
|
/*
|
|
|
|
* TODO Should this really be an error? If no, the old value
|
|
|
|
* needs to be released before we store the new one.
|
|
|
|
*/
|
2020-12-11 23:05:08 +01:00
|
|
|
if (!check_prop_still_unset(obj, name, be->chr, str, errp)) {
|
2020-06-22 11:42:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-22 11:52:51 +02:00
|
|
|
if (!*str) {
|
|
|
|
g_free(str);
|
|
|
|
be->chr = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2012-12-05 17:49:11 +01:00
|
|
|
|
2016-10-22 11:52:51 +02:00
|
|
|
s = qemu_chr_find(str);
|
|
|
|
if (s == NULL) {
|
|
|
|
error_setg(errp, "Property '%s.%s' can't find value '%s'",
|
2020-12-11 23:05:16 +01:00
|
|
|
object_get_typename(obj), name, str);
|
2016-11-07 10:59:22 +01:00
|
|
|
} else if (!qemu_chr_fe_init(be, s, errp)) {
|
2016-10-22 11:52:58 +02:00
|
|
|
error_prepend(errp, "Property '%s.%s' can't take value '%s': ",
|
2020-12-11 23:05:16 +01:00
|
|
|
object_get_typename(obj), name, str);
|
2016-10-22 11:52:51 +02:00
|
|
|
}
|
2016-11-07 10:59:22 +01:00
|
|
|
g_free(str);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
2016-10-22 11:52:51 +02:00
|
|
|
static void release_chr(Object *obj, const char *name, void *opaque)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
2016-10-22 11:52:51 +02:00
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
CharBackend *be = object_field_prop_ptr(obj, prop);
|
2016-10-22 11:52:51 +02:00
|
|
|
|
2017-01-26 21:49:13 +01:00
|
|
|
qemu_chr_fe_deinit(be, false);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
2017-07-14 04:14:54 +02:00
|
|
|
const 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,
|
|
|
|
};
|
|
|
|
|
2020-09-30 18:49:46 +02:00
|
|
|
/* --- mac address --- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* accepted syntax versions:
|
|
|
|
* 01:02:03:04:05:06
|
|
|
|
* 01-02-03-04-05-06
|
|
|
|
*/
|
|
|
|
static void get_mac(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
MACAddr *mac = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
char buffer[2 * 6 + 5 + 1];
|
|
|
|
char *p = buffer;
|
|
|
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
|
mac->a[0], mac->a[1], mac->a[2],
|
|
|
|
mac->a[3], mac->a[4], mac->a[5]);
|
|
|
|
|
|
|
|
visit_type_str(v, name, &p, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
MACAddr *mac = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
int i, pos;
|
|
|
|
char *str;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (!visit_type_str(v, name, &str, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, pos = 0; i < 6; i++, pos += 3) {
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (!qemu_isxdigit(str[pos])) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
if (!qemu_isxdigit(str[pos + 1])) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
if (i == 5) {
|
|
|
|
if (str[pos + 2] != '\0') {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (str[pos + 2] != ':' && str[pos + 2] != '-') {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (qemu_strtol(str + pos, &p, 16, &val) < 0 || val > 0xff) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
mac->a[i] = val;
|
|
|
|
}
|
|
|
|
g_free(str);
|
|
|
|
return;
|
|
|
|
|
|
|
|
inval:
|
2020-12-11 23:05:15 +01:00
|
|
|
error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
|
2020-09-30 18:49:46 +02:00
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_macaddr = {
|
|
|
|
.name = "str",
|
|
|
|
.description = "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
|
|
|
|
.get = get_mac,
|
|
|
|
.set = set_mac,
|
|
|
|
};
|
|
|
|
|
|
|
|
void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
|
|
|
|
const uint8_t *value)
|
|
|
|
{
|
|
|
|
char str[2 * 6 + 5 + 1];
|
|
|
|
snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
|
value[0], value[1], value[2], value[3], value[4], value[5]);
|
|
|
|
|
|
|
|
object_property_set_str(OBJECT(dev), name, str, &error_abort);
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:49:11 +01:00
|
|
|
/* --- 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
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
NICPeers *peers_ptr = object_field_prop_ptr(obj, prop);
|
2014-10-13 07:16:37 +02:00
|
|
|
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
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
NICPeers *peers_ptr = object_field_prop_ptr(obj, 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
|
|
|
int queues, err = 0, i = 0;
|
|
|
|
char *str;
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 18:06:02 +02:00
|
|
|
if (!visit_type_str(v, name, &str, errp)) {
|
2014-10-13 07:16:37 +02:00
|
|
|
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,
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 05:50:23 +02:00
|
|
|
NET_CLIENT_DRIVER_NIC,
|
2013-01-30 12:12:28 +01:00
|
|
|
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]->peer) {
|
2014-10-13 07:16:37 +02:00
|
|
|
err = -EEXIST;
|
|
|
|
goto out;
|
2013-01-30 12:12:28 +01:00
|
|
|
}
|
|
|
|
|
qdev: Improve netdev property override error a bit
qdev_prop_set_netdev() fails when the property already has a non-null
value. Seems to go back to commit 30c367ed44
"qdev-properties-system.c: Allow vlan or netdev for -device, not
both", v1.7.0. Board code doesn't expect failure, and crashes:
$ qemu-system-x86_64 --nodefaults -nic user -netdev user,id=nic0 -global e1000.netdev=nic0
Unexpected error in error_set_from_qdev_prop_error() at /work/armbru/qemu/hw/core/qdev-properties.c:1101:
qemu-system-x86_64: Property 'e1000.netdev' doesn't take value '__org.qemu.nic0
'
Aborted (core dumped)
-device and device_add handle the failure:
$ qemu-system-x86_64 -nodefaults -netdev user,id=net0 -netdev user,id=net1 -device e1000,netdev=net0,netdev=net1
qemu-system-x86_64: -device e1000,netdev=net0,netdev=net1: Property 'e1000.netdev' doesn't take value 'net1'
$ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -netdev user,id=net0 -netdev user,id=net1 -global e1000.netdev=net0
QEMU 5.0.50 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: warning: netdev net0 has no peer
qemu-system-x86_64: warning: netdev net1 has no peer
device_add e1000,netdev=net1
Error: Property 'e1000.netdev' doesn't take value 'net1'
Perhaps netdev property override could be made to work. Perhaps it
should. I'm not the right guy to figure this out. What I can do is
improve the error message a bit:
(qemu) device_add e1000,netdev=net1
Error: -global e1000.netdev=... conflicts with netdev=net1
Cc: Jason Wang <jasowang@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-11-armbru@redhat.com>
2020-06-22 11:42:21 +02:00
|
|
|
/*
|
|
|
|
* TODO Should this really be an error? If no, the old value
|
|
|
|
* needs to be released before we store the new one.
|
|
|
|
*/
|
2020-12-11 23:05:08 +01:00
|
|
|
if (!check_prop_still_unset(obj, name, ncs[i], str, errp)) {
|
2014-10-13 07:16:37 +02:00
|
|
|
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:
|
2020-12-11 23:05:15 +01:00
|
|
|
error_set_from_qdev_prop_error(errp, err, obj, name, str);
|
2014-10-13 07:16:37 +02:00
|
|
|
g_free(str);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
2017-07-14 04:14:54 +02:00
|
|
|
const 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,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-19 01:06:49 +02:00
|
|
|
/* --- audiodev --- */
|
|
|
|
static void get_audiodev(Object *obj, Visitor *v, const char* name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
|
2019-08-19 01:06:49 +02:00
|
|
|
char *p = g_strdup(audio_get_id(card));
|
|
|
|
|
|
|
|
visit_type_str(v, name, &p, errp);
|
|
|
|
g_free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_audiodev(Object *obj, Visitor *v, const char* name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
|
2019-08-19 01:06:49 +02:00
|
|
|
AudioState *state;
|
|
|
|
int err = 0;
|
|
|
|
char *str;
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 18:06:02 +02:00
|
|
|
if (!visit_type_str(v, name, &str, errp)) {
|
2019-08-19 01:06:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = audio_state_by_name(str);
|
|
|
|
|
|
|
|
if (!state) {
|
|
|
|
err = -ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
card->state = state;
|
|
|
|
|
|
|
|
out:
|
2020-12-11 23:05:15 +01:00
|
|
|
error_set_from_qdev_prop_error(errp, err, obj, name, str);
|
2019-08-19 01:06:49 +02:00
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_audiodev = {
|
|
|
|
.name = "str",
|
|
|
|
.description = "ID of an audiodev to use as a backend",
|
|
|
|
/* release done on shutdown */
|
|
|
|
.get = get_audiodev,
|
|
|
|
.set = set_audiodev,
|
|
|
|
};
|
|
|
|
|
2020-07-07 18:05:59 +02:00
|
|
|
bool qdev_prop_set_drive_err(DeviceState *dev, const char *name,
|
qdev: Make qdev_prop_set_drive() match the other helpers
qdev_prop_set_drive() can fail. None of the other qdev_prop_set_FOO()
can; they abort on error.
To clean up this inconsistency, rename qdev_prop_set_drive() to
qdev_prop_set_drive_err(), and create a qdev_prop_set_drive() that
aborts on error.
Coccinelle script to update callers:
@ depends on !(file in "hw/core/qdev-properties-system.c")@
expression dev, name, value;
symbol error_abort;
@@
- qdev_prop_set_drive(dev, name, value, &error_abort);
+ qdev_prop_set_drive(dev, name, value);
@@
expression dev, name, value, errp;
@@
- qdev_prop_set_drive(dev, name, value, errp);
+ qdev_prop_set_drive_err(dev, name, value, errp);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200622094227.1271650-14-armbru@redhat.com>
2020-06-22 11:42:24 +02:00
|
|
|
BlockBackend *value, Error **errp)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
2016-06-21 20:46:05 +02:00
|
|
|
const char *ref = "";
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
ref = blk_name(value);
|
|
|
|
if (!*ref) {
|
2017-03-10 21:05:50 +01:00
|
|
|
const BlockDriverState *bs = blk_bs(value);
|
2016-06-21 20:46:05 +02:00
|
|
|
if (bs) {
|
|
|
|
ref = bdrv_get_node_name(bs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 18:05:59 +02:00
|
|
|
return object_property_set_str(OBJECT(dev), name, ref, errp);
|
2012-12-05 17:49:11 +01:00
|
|
|
}
|
|
|
|
|
qdev: Make qdev_prop_set_drive() match the other helpers
qdev_prop_set_drive() can fail. None of the other qdev_prop_set_FOO()
can; they abort on error.
To clean up this inconsistency, rename qdev_prop_set_drive() to
qdev_prop_set_drive_err(), and create a qdev_prop_set_drive() that
aborts on error.
Coccinelle script to update callers:
@ depends on !(file in "hw/core/qdev-properties-system.c")@
expression dev, name, value;
symbol error_abort;
@@
- qdev_prop_set_drive(dev, name, value, &error_abort);
+ qdev_prop_set_drive(dev, name, value);
@@
expression dev, name, value, errp;
@@
- qdev_prop_set_drive(dev, name, value, errp);
+ qdev_prop_set_drive_err(dev, name, value, errp);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200622094227.1271650-14-armbru@redhat.com>
2020-06-22 11:42:24 +02:00
|
|
|
void qdev_prop_set_drive(DeviceState *dev, const char *name,
|
|
|
|
BlockBackend *value)
|
|
|
|
{
|
|
|
|
qdev_prop_set_drive_err(dev, name, value, &error_abort);
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:49:11 +01:00
|
|
|
void qdev_prop_set_chr(DeviceState *dev, const char *name,
|
2016-12-07 14:20:22 +01:00
|
|
|
Chardev *value)
|
2012-12-05 17:49:11 +01:00
|
|
|
{
|
|
|
|
assert(!value || value->label);
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 18:05:54 +02:00
|
|
|
object_property_set_str(OBJECT(dev), name, value ? value->label : "",
|
|
|
|
&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);
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 18:05:54 +02:00
|
|
|
object_property_set_str(OBJECT(dev), name, value ? value->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 &&
|
2020-09-14 15:56:17 +02:00
|
|
|
object_property_find(OBJECT(dev), "vectors")) {
|
2012-12-05 17:49:11 +01:00
|
|
|
qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
|
|
|
|
}
|
|
|
|
nd->instantiated = 1;
|
|
|
|
}
|
2020-09-30 18:49:46 +02:00
|
|
|
|
|
|
|
/* --- lost tick policy --- */
|
|
|
|
|
|
|
|
QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_losttickpolicy = {
|
|
|
|
.name = "LostTickPolicy",
|
|
|
|
.enum_table = &LostTickPolicy_lookup,
|
|
|
|
.get = qdev_propinfo_get_enum,
|
|
|
|
.set = qdev_propinfo_set_enum,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_enum,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- blocksize --- */
|
|
|
|
|
|
|
|
static void set_blocksize(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
uint32_t *ptr = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
uint64_t value;
|
2020-09-18 10:09:09 +02:00
|
|
|
Error *local_err = NULL;
|
2020-09-30 18:49:46 +02:00
|
|
|
|
|
|
|
if (!visit_type_size(v, name, &value, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-18 10:09:09 +02:00
|
|
|
check_block_size(dev->id ? : "", name, value, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
2020-09-30 18:49:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*ptr = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_blocksize = {
|
|
|
|
.name = "size",
|
|
|
|
.description = "A power of two between " MIN_BLOCK_SIZE_STR
|
|
|
|
" and " MAX_BLOCK_SIZE_STR,
|
|
|
|
.get = qdev_propinfo_get_size32,
|
|
|
|
.set = set_blocksize,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_uint,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- Block device error handling policy --- */
|
|
|
|
|
|
|
|
QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError) != sizeof(int));
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_blockdev_on_error = {
|
|
|
|
.name = "BlockdevOnError",
|
|
|
|
.description = "Error handling policy, "
|
|
|
|
"report/ignore/enospc/stop/auto",
|
|
|
|
.enum_table = &BlockdevOnError_lookup,
|
|
|
|
.get = qdev_propinfo_get_enum,
|
|
|
|
.set = qdev_propinfo_set_enum,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_enum,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- BIOS CHS translation */
|
|
|
|
|
|
|
|
QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation) != sizeof(int));
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_bios_chs_trans = {
|
|
|
|
.name = "BiosAtaTranslation",
|
|
|
|
.description = "Logical CHS translation algorithm, "
|
|
|
|
"auto/none/lba/large/rechs",
|
|
|
|
.enum_table = &BiosAtaTranslation_lookup,
|
|
|
|
.get = qdev_propinfo_get_enum,
|
|
|
|
.set = qdev_propinfo_set_enum,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_enum,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- FDC default drive types */
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_fdc_drive_type = {
|
|
|
|
.name = "FdcDriveType",
|
|
|
|
.description = "FDC drive type, "
|
|
|
|
"144/288/120/none/auto",
|
|
|
|
.enum_table = &FloppyDriveType_lookup,
|
|
|
|
.get = qdev_propinfo_get_enum,
|
|
|
|
.set = qdev_propinfo_set_enum,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_enum,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- MultiFDCompression --- */
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_multifd_compression = {
|
|
|
|
.name = "MultiFDCompression",
|
|
|
|
.description = "multifd_compression values, "
|
|
|
|
"none/zlib/zstd",
|
|
|
|
.enum_table = &MultiFDCompression_lookup,
|
|
|
|
.get = qdev_propinfo_get_enum,
|
|
|
|
.set = qdev_propinfo_set_enum,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_enum,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- Reserved Region --- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Accepted syntax:
|
|
|
|
* <low address>:<high address>:<type>
|
|
|
|
* where low/high addresses are uint64_t in hexadecimal
|
|
|
|
* and type is a non-negative decimal integer
|
|
|
|
*/
|
|
|
|
static void get_reserved_region(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
ReservedRegion *rr = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
char buffer[64];
|
|
|
|
char *p = buffer;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = snprintf(buffer, sizeof(buffer), "0x%"PRIx64":0x%"PRIx64":%u",
|
|
|
|
rr->low, rr->high, rr->type);
|
|
|
|
assert(rc < sizeof(buffer));
|
|
|
|
|
|
|
|
visit_type_str(v, name, &p, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_reserved_region(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
ReservedRegion *rr = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
Error *local_err = NULL;
|
|
|
|
const char *endptr;
|
|
|
|
char *str;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
visit_type_str(v, name, &str, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = qemu_strtou64(str, &endptr, 16, &rr->low);
|
|
|
|
if (ret) {
|
|
|
|
error_setg(errp, "start address of '%s'"
|
|
|
|
" must be a hexadecimal integer", name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (*endptr != ':') {
|
|
|
|
goto separator_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = qemu_strtou64(endptr + 1, &endptr, 16, &rr->high);
|
|
|
|
if (ret) {
|
|
|
|
error_setg(errp, "end address of '%s'"
|
|
|
|
" must be a hexadecimal integer", name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (*endptr != ':') {
|
|
|
|
goto separator_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = qemu_strtoui(endptr + 1, &endptr, 10, &rr->type);
|
|
|
|
if (ret) {
|
|
|
|
error_setg(errp, "type of '%s'"
|
|
|
|
" must be a non-negative decimal integer", name);
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
separator_error:
|
|
|
|
error_setg(errp, "reserved region fields must be separated with ':'");
|
|
|
|
out:
|
|
|
|
g_free(str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_reserved_region = {
|
|
|
|
.name = "reserved_region",
|
|
|
|
.description = "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0",
|
|
|
|
.get = get_reserved_region,
|
|
|
|
.set = set_reserved_region,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- pci address --- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bus-local address, i.e. "$slot" or "$slot.$fn"
|
|
|
|
*/
|
|
|
|
static void set_pci_devfn(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
int32_t value, *ptr = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
unsigned int slot, fn, n;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (!visit_type_str(v, name, &str, NULL)) {
|
|
|
|
if (!visit_type_int32(v, name, &value, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (value < -1 || value > 255) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
|
2020-11-13 09:26:26 +01:00
|
|
|
name ? name : "null", "a value between -1 and 255");
|
2020-09-30 18:49:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*ptr = value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) {
|
|
|
|
fn = 0;
|
|
|
|
if (sscanf(str, "%x%n", &slot, &n) != 1) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (str[n] != '\0' || fn > 7 || slot > 31) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
*ptr = slot << 3 | fn;
|
|
|
|
g_free(str);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2020-12-11 23:05:15 +01:00
|
|
|
error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
|
2020-09-30 18:49:46 +02:00
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
2020-12-11 23:05:04 +01:00
|
|
|
static int print_pci_devfn(Object *obj, Property *prop, char *dest,
|
2020-09-30 18:49:46 +02:00
|
|
|
size_t len)
|
|
|
|
{
|
2020-12-11 23:05:27 +01:00
|
|
|
int32_t *ptr = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
|
|
|
|
if (*ptr == -1) {
|
|
|
|
return snprintf(dest, len, "<unset>");
|
|
|
|
} else {
|
|
|
|
return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_pci_devfn = {
|
|
|
|
.name = "int32",
|
|
|
|
.description = "Slot and optional function number, example: 06.0 or 06",
|
|
|
|
.print = print_pci_devfn,
|
|
|
|
.get = qdev_propinfo_get_int32,
|
|
|
|
.set = set_pci_devfn,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_int,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- pci host address --- */
|
|
|
|
|
|
|
|
static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
PCIHostDeviceAddress *addr = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
char buffer[] = "ffff:ff:ff.f";
|
|
|
|
char *p = buffer;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Catch "invalid" device reference from vfio-pci and allow the
|
|
|
|
* default buffer representing the non-existent device to be used.
|
|
|
|
*/
|
|
|
|
if (~addr->domain || ~addr->bus || ~addr->slot || ~addr->function) {
|
|
|
|
rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%0d",
|
|
|
|
addr->domain, addr->bus, addr->slot, addr->function);
|
|
|
|
assert(rc == sizeof(buffer) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
visit_type_str(v, name, &p, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse [<domain>:]<bus>:<slot>.<func>
|
|
|
|
* if <domain> is not supplied, it's assumed to be 0.
|
|
|
|
*/
|
|
|
|
static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
PCIHostDeviceAddress *addr = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
char *str, *p;
|
2020-11-20 14:04:54 +01:00
|
|
|
char *e;
|
2020-09-30 18:49:46 +02:00
|
|
|
unsigned long val;
|
|
|
|
unsigned long dom = 0, bus = 0;
|
|
|
|
unsigned int slot = 0, func = 0;
|
|
|
|
|
|
|
|
if (!visit_type_str(v, name, &str, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = str;
|
2020-11-20 14:04:54 +01:00
|
|
|
val = strtoul(p, &e, 16);
|
|
|
|
if (e == p || *e != ':') {
|
2020-09-30 18:49:46 +02:00
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
bus = val;
|
|
|
|
|
2020-11-20 14:04:54 +01:00
|
|
|
p = e + 1;
|
|
|
|
val = strtoul(p, &e, 16);
|
|
|
|
if (e == p) {
|
2020-09-30 18:49:46 +02:00
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
if (*e == ':') {
|
|
|
|
dom = bus;
|
|
|
|
bus = val;
|
2020-11-20 14:04:54 +01:00
|
|
|
p = e + 1;
|
|
|
|
val = strtoul(p, &e, 16);
|
|
|
|
if (e == p) {
|
2020-09-30 18:49:46 +02:00
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
slot = val;
|
|
|
|
|
|
|
|
if (*e != '.') {
|
|
|
|
goto inval;
|
|
|
|
}
|
2020-11-20 14:04:54 +01:00
|
|
|
p = e + 1;
|
|
|
|
val = strtoul(p, &e, 10);
|
|
|
|
if (e == p) {
|
2020-09-30 18:49:46 +02:00
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
func = val;
|
|
|
|
|
2020-11-20 14:04:54 +01:00
|
|
|
if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) {
|
2020-09-30 18:49:46 +02:00
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*e) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr->domain = dom;
|
|
|
|
addr->bus = bus;
|
|
|
|
addr->slot = slot;
|
|
|
|
addr->function = func;
|
|
|
|
|
|
|
|
g_free(str);
|
|
|
|
return;
|
|
|
|
|
|
|
|
inval:
|
2020-12-11 23:05:15 +01:00
|
|
|
error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
|
2020-09-30 18:49:46 +02:00
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_pci_host_devaddr = {
|
|
|
|
.name = "str",
|
|
|
|
.description = "Address (bus/device/function) of "
|
|
|
|
"the host device, example: 04:10.0",
|
|
|
|
.get = get_pci_host_devaddr,
|
|
|
|
.set = set_pci_host_devaddr,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_off_auto_pcibar = {
|
|
|
|
.name = "OffAutoPCIBAR",
|
|
|
|
.description = "off/auto/bar0/bar1/bar2/bar3/bar4/bar5",
|
|
|
|
.enum_table = &OffAutoPCIBAR_lookup,
|
|
|
|
.get = qdev_propinfo_get_enum,
|
|
|
|
.set = qdev_propinfo_set_enum,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_enum,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- PCIELinkSpeed 2_5/5/8/16 -- */
|
|
|
|
|
|
|
|
static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
PCIExpLinkSpeed *p = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
int speed;
|
|
|
|
|
|
|
|
switch (*p) {
|
|
|
|
case QEMU_PCI_EXP_LNK_2_5GT:
|
|
|
|
speed = PCIE_LINK_SPEED_2_5;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_5GT:
|
|
|
|
speed = PCIE_LINK_SPEED_5;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_8GT:
|
|
|
|
speed = PCIE_LINK_SPEED_8;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_16GT:
|
|
|
|
speed = PCIE_LINK_SPEED_16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Unreachable */
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2020-12-11 23:05:16 +01:00
|
|
|
visit_type_enum(v, name, &speed, prop->info->enum_table, errp);
|
2020-09-30 18:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
PCIExpLinkSpeed *p = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
int speed;
|
|
|
|
|
2020-12-11 23:05:16 +01:00
|
|
|
if (!visit_type_enum(v, name, &speed, prop->info->enum_table,
|
2020-09-30 18:49:46 +02:00
|
|
|
errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (speed) {
|
|
|
|
case PCIE_LINK_SPEED_2_5:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_2_5GT;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_SPEED_5:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_5GT;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_SPEED_8:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_8GT;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_SPEED_16:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_16GT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Unreachable */
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_pcie_link_speed = {
|
|
|
|
.name = "PCIELinkSpeed",
|
|
|
|
.description = "2_5/5/8/16",
|
|
|
|
.enum_table = &PCIELinkSpeed_lookup,
|
|
|
|
.get = get_prop_pcielinkspeed,
|
|
|
|
.set = set_prop_pcielinkspeed,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_enum,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */
|
|
|
|
|
|
|
|
static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
PCIExpLinkWidth *p = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
int width;
|
|
|
|
|
|
|
|
switch (*p) {
|
|
|
|
case QEMU_PCI_EXP_LNK_X1:
|
|
|
|
width = PCIE_LINK_WIDTH_1;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_X2:
|
|
|
|
width = PCIE_LINK_WIDTH_2;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_X4:
|
|
|
|
width = PCIE_LINK_WIDTH_4;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_X8:
|
|
|
|
width = PCIE_LINK_WIDTH_8;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_X12:
|
|
|
|
width = PCIE_LINK_WIDTH_12;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_X16:
|
|
|
|
width = PCIE_LINK_WIDTH_16;
|
|
|
|
break;
|
|
|
|
case QEMU_PCI_EXP_LNK_X32:
|
|
|
|
width = PCIE_LINK_WIDTH_32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Unreachable */
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2020-12-11 23:05:16 +01:00
|
|
|
visit_type_enum(v, name, &width, prop->info->enum_table, errp);
|
2020-09-30 18:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
PCIExpLinkWidth *p = object_field_prop_ptr(obj, prop);
|
2020-09-30 18:49:46 +02:00
|
|
|
int width;
|
|
|
|
|
2020-12-11 23:05:16 +01:00
|
|
|
if (!visit_type_enum(v, name, &width, prop->info->enum_table,
|
2020-09-30 18:49:46 +02:00
|
|
|
errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (width) {
|
|
|
|
case PCIE_LINK_WIDTH_1:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_X1;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_WIDTH_2:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_X2;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_WIDTH_4:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_X4;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_WIDTH_8:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_X8;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_WIDTH_12:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_X12;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_WIDTH_16:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_X16;
|
|
|
|
break;
|
|
|
|
case PCIE_LINK_WIDTH_32:
|
|
|
|
*p = QEMU_PCI_EXP_LNK_X32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Unreachable */
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_pcie_link_width = {
|
|
|
|
.name = "PCIELinkWidth",
|
|
|
|
.description = "1/2/4/8/12/16/32",
|
|
|
|
.enum_table = &PCIELinkWidth_lookup,
|
|
|
|
.get = get_prop_pcielinkwidth,
|
|
|
|
.set = set_prop_pcielinkwidth,
|
|
|
|
.set_default_value = qdev_propinfo_set_default_value_enum,
|
|
|
|
};
|
2020-12-11 23:05:11 +01:00
|
|
|
|
|
|
|
/* --- UUID --- */
|
|
|
|
|
|
|
|
static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
QemuUUID *uuid = object_field_prop_ptr(obj, prop);
|
2020-12-11 23:05:11 +01:00
|
|
|
char buffer[UUID_FMT_LEN + 1];
|
|
|
|
char *p = buffer;
|
|
|
|
|
|
|
|
qemu_uuid_unparse(uuid, buffer);
|
|
|
|
|
|
|
|
visit_type_str(v, name, &p, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define UUID_VALUE_AUTO "auto"
|
|
|
|
|
|
|
|
static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
Property *prop = opaque;
|
2020-12-11 23:05:27 +01:00
|
|
|
QemuUUID *uuid = object_field_prop_ptr(obj, prop);
|
2020-12-11 23:05:11 +01:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (!visit_type_str(v, name, &str, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(str, UUID_VALUE_AUTO)) {
|
|
|
|
qemu_uuid_generate(uuid);
|
|
|
|
} else if (qemu_uuid_parse(str, uuid) < 0) {
|
2020-12-11 23:05:15 +01:00
|
|
|
error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
|
2020-12-11 23:05:11 +01:00
|
|
|
}
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_default_uuid_auto(ObjectProperty *op, const Property *prop)
|
|
|
|
{
|
|
|
|
object_property_set_default_str(op, UUID_VALUE_AUTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyInfo qdev_prop_uuid = {
|
|
|
|
.name = "str",
|
|
|
|
.description = "UUID (aka GUID) or \"" UUID_VALUE_AUTO
|
|
|
|
"\" for random value (default)",
|
|
|
|
.get = get_uuid,
|
|
|
|
.set = set_uuid,
|
|
|
|
.set_default_value = set_default_uuid_auto,
|
|
|
|
};
|