* [Qemu-devel] Device initialisation problem:
@ 2009-11-13 18:30 Ian Molton
2009-11-14 1:38 ` [Qemu-devel] Device initialisation problem: partially solved Ian Molton
0 siblings, 1 reply; 2+ messages in thread
From: Ian Molton @ 2009-11-13 18:30 UTC (permalink / raw)
To: qemu-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I'm trying to use the qption parser to parse my device option string,
which is formatted like this:
- -vrng dev=/dev/foo,rate=10K
and I mostly got things to work by using this, in vl.c:
static int virtio_rng_parse(const char *arg)
{
QemuOpts *opts;
if (strcmp(arg, "none") == 0) {
return 0;
}
if (!strncmp(arg, "dev", 3)) {
/* have params -> parse them */
opts = qemu_opts_parse(&qemu_device_opts, arg, NULL);
if (!opts)
return -1;
} else {
/* create empty opts */
opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
}
qemu_opt_set(opts, "driver", "virtio-rng-pci");
return 0;
}
However when I tried to create my own opts layout so that I could take
advantage of the OPT_SIZE option type, I ran into problems.
I defined the following:
QemuOptsList qemu_rng_opts = {
.name = "virtio-rng-pci",
.head = QTAILQ_HEAD_INITIALIZER(qemu_rng_opts.head),
.desc = {
{
.name = "dev",
.type = QEMU_OPT_STRING,
},
{
.name = "rate",
.type = QEMU_OPT_SIZE,
},
{ /* end if list */ }
}
};
And modified the code in vl.c to read:
static int virtio_rng_parse(const char *arg)
{
QemuOpts *opts;
if (strcmp(arg, "none") == 0) {
return 0;
}
if (!strncmp(arg, "dev", 3)) {
/* have params -> parse them */
opts = qemu_opts_parse(&qemu_rng_opts, arg, NULL);
if (!opts)
return -1;
} else {
/* create empty opts */
opts = qemu_opts_create(&qemu_rng_opts, NULL, 0);
}
// qemu_opt_set(opts, "driver", "virtio-rng-pci");
return 0;
}
But now my driver does not get registered.
So it seems I can use &qemu_device_opts and forego the nice parsing, or
I can get nice parsing and not have a device.
What am I missing here ?
- -Ian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQIcBAEBAgAGBQJK/aXQAAoJEFIjE1w7L6YHvP0P/3/lGjI4B2zbfmlzLDtilxD+
ov1w5DezKcca8ib/u/v/q63mxuS2/n8cMsb4blAR2qgSP9QgVL1XRey0HfbOZFOe
K7HRlP+nqb80jBrpIMGlMBi4Y7AEJbzfxpWCGVyRYaOYl9KmF1pLnrfcbkVvbIww
5EV1VAPoR1364XJ+gJkx2HqRo2Y4CaQd3v+TAUmPXbGIhxVAfwNdeNp7CIXVnd3p
JibjGQCFkBv83NrBVozHo0OZP3+tEjek483/ouvY28EcxkrHqJ+VHbis+y/R1mud
9LeMDF7M8UleBy4wUfxtCQUZVdcoFmpAuo5rbzNA4fG+OfXtvy3SeEo/8gJ9C4b+
1rIkB2k7XluJmuZcWM+4YP/NiUo0c0K+EUzoRULesRsqo7ti/KvnrK+HIiVJRnns
WHVQ9I7b9YTyPYPifPd4A6nZwdzLvjbtrpr/ww+WTk7tp3xDkrQ3JadCdpgEbmjj
yMIIg7Gqep0pBlrJkqUKfumfyxK4d0j3nRSqx3PFPysisEauPYNhjUL4ILX/9IKf
5YrA1nYEwtn33RjRTKPt/Bp8m7z8nBJN33LTI6YJS0IPCdTRZajwiN7YkhtZ5kBz
U2p0Yvmo7yzNFU3pXCs8C4TfIdzOOnKh3APFVZgR1+Bzm8SMeo69vGNhrXOyIh5Y
28888cHL9Jovri04HrBb
=NLeC
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] Device initialisation problem: partially solved.
2009-11-13 18:30 [Qemu-devel] Device initialisation problem: Ian Molton
@ 2009-11-14 1:38 ` Ian Molton
0 siblings, 0 replies; 2+ messages in thread
From: Ian Molton @ 2009-11-14 1:38 UTC (permalink / raw)
To: qemu-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Further investigation seems to have highlighted the problem:
My code is correctly decoding the OPT_SIZE parameter into the
'value.uint' field in a QemuOpt
I've also got the devices properties set up, so that the device may
receive its data.
Eg.
in vl.c
static int virtio_rng_parse(const char *arg)
{
QemuOpts *opts;
if (strcmp(arg, "none") == 0) {
return 0;
}
if (!strncmp(arg, "dev", 3)) {
/* have params -> parse them */
opts = qemu_opts_parse(&qemu_rng_opts, arg, NULL);
if (!opts)
return -1;
} else {
/* create empty opts */
opts = qemu_opts_create(&qemu_rng_opts, NULL, 0);
}
qemu_opt_set(opts, "driver", "virtio-rng-pci");
return 0;
}
and in hw/virtio.c I have:
,{
.qdev.name = "virtio-rng-pci",
.qdev.size = sizeof(VirtIOPCIProxy),
.init = virtio_rng_init_pci,
.exit = virtio_exit_pci,
.qdev.props = (Property[]) {
DEFINE_RNG_PROPERTIES(VirtIOPCIProxy, rng),
DEFINE_PROP_END_OF_LIST(),
},
.qdev.reset = virtio_pci_reset,
}
Where DEFINE_RNG_PROPERTIES is defined as:
#define DEFINE_RNG_PROPERTIES(_state, _conf) \
DEFINE_PROP_STRING("dev", _state, _conf.device), \
DEFINE_PROP_UINT32("rate", _state, _conf.rate, 0)
So as you can see, I was expecting the rate property to be decoded as an
OPT_SIZE type and that value to be fed into conf.rate
This doesn't happen because in hw/qemu.c we have:
qemu_opt_foreach(opts, set_property, qdev, 1)
Which is doing:
QTAILQ_FOREACH(opt, &opts->head, next) {
rc = func(opt->name, ******opt->str******, opaque);
IOW, its not passing the nicely decoded OPT_SIZE, but the original
string value.
I cant see a 'nice' solution to this right now, the choices being to
either reimplement the OPT_SIZE parser as a property parser, which seems
horribly inefficient, or to create a new property parser that does a
nasty hack on the offset of opt->str in order to access opt->value.uint,
which seems horribly evil.
Am I missing something here? It seems there is some confusion as to
wether the property code should do the parsing or the options code. Or
both - but then we need some way to tell the properties code to use the
pre-parsed data in circumstances like mine.
Either that or I'm too tired and should go to bed...
- -Ian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQIcBAEBAgAGBQJK/gn4AAoJEFIjE1w7L6YHRw4QAJIkm756yClRneGJY18qH3QH
k5cFR3EaRjC/Q3eKGQ7TeX3HA/KCjpVbyTLxjjqFenVGApMCIAWbVWwjXe3YvI7t
IAG1WOACJTtb3h2uNTf3LFFs3ca6YRy0jhe/pAxoIOZfl6J76PNISa3ly/2+W+2D
OXgoT2mIqDTOtAEMDp3V6JPec+Qz0tAIRsEDuT94ZsRKJCQxvOPyXtreAJMaAAZn
6P0tEzC5gSKKDM5P5p8yT+ZrUgWGNC7iKUJ7t1nHuPV6a/7GezW9whWOPokfn1LG
V3Yil0mdPzbwW/UD+HtDS1mgsvGRDu12q6UhDe/kJp+Mr+Oripq3/UwkqP5tKpAl
MfrJjjT06Q6YwyKvYi3PUYIZeTdtF8VuoHHJA1XEhuQrIrje7jFVMTDy4S6b3Nq4
SvK+x2ni12z5ojUpInWw9ZP4wUFoMzFdGQ7PBoQhN1oTsC1m3NfdL+UUw4wSuLw/
mK93oQz4y9GaFDrajtPL7TFbbyb5PIBmZWq27M5EjEPFMXxZaACQPsXGz16RJRrA
Ck8T+eCDEJ4eOnBN2HDObx1IkQoXJ7K/mGzYj+sPZWhoGpCkDbBLmjL4dtrYUWaa
ae40GymfnkzGmXlRdPjgEXr3CXuTAWaTiqyxWXGMmv90elgyN9wE/o9lajqaO6Ha
LVkIKNHGfYvBpFoAZRZP
=Eeqz
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-11-14 1:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-13 18:30 [Qemu-devel] Device initialisation problem: Ian Molton
2009-11-14 1:38 ` [Qemu-devel] Device initialisation problem: partially solved Ian Molton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.