From: Juan Quintela <quintela@redhat.com>
To: Jan Kiszka <jan.kiszka@web.de>
Cc: Blue Swirl <blauwirbel@gmail.com>,
qemu-devel <qemu-devel@nongnu.org>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] Re: [PATCH] fdc: Fix vmsave/restore regression
Date: Thu, 12 Nov 2009 15:37:56 +0100 [thread overview]
Message-ID: <m3k4xvq057.fsf@neno.mitica> (raw)
In-Reply-To: <4AFC09E2.6060404@web.de> (Jan Kiszka's message of "Thu, 12 Nov 2009 14:13:06 +0100")
Jan Kiszka <jan.kiszka@web.de> wrote:
> Juan Quintela wrote:
>> Jan Kiszka <jan.kiszka@web.de> wrote:
>>> *** NOTE ***
>>> 'git shortlog|grep "reset + vmsd"' shows 10 such conversions. I only
>>> briefly checked the first one, and it looks similar broken. Could
>>> someone have a second look at them? Maybe it is also better to define a
>>> vmsd opaque in DeviceInfo, which would also allow to solve this issue
>>> differently.
>>>
>>
>> I searched for .qdev.vmsd, and all the other uses are right as far as I
>> can see.
>
> Maybe it works, but it doesn't look clean to me.
It is how qdev works :p
> E.g. tcx.c,
> vmstate_tcx_post_load: it should be called with the DeviceState as
> opaque value, right? Then I'm missing container_of(d, TCXState,
> busdev.qdev).
typedef struct TCXState {
SysBusDevice busdev;
...
}
struct SysBusDevice {
DeviceState qdev;
....
}
As you can see, if you have a pointer to a TCXState, you also have a
pointer to a DeviceState (some for PCIDevice).
It needs to be the 1st value, tcx.c should really use DO_UPCAST() and
not container_of. If the DeviceState is not the 1st field, qdev stops
working.
int qdev_init(DeviceState *dev)
{
...
qemu_register_reset(qdev_reset, dev);
if (dev->info->vmsd)
vmstate_register(-1, dev->info->vmsd, dev);
....
}
As you can see, if we are using qdev, what we need to check is that the
type of vmstate_foo is the same that the qdev type.
static const VMStateDescription vmstate_tcx = {
...
.fields = (VMStateField []) {
VMSTATE_UINT16(height, TCXState),
...
}
Important bit here is TCXState
static SysBusDeviceInfo tcx_info = {
...
.qdev.size = sizeof(TCXState),
^^^^^^^^
See that the value that we are creating is a TCXState, then things are
right.
.qdev.vmsd = &vmstate_tcx,
....
};
qdev abuses void * to create OOP in C (vmstate does the same), there is
not a simple way to typecheck more this. What we need is that the
functions that we put in the SysBusDeviceInfo in this case, all expect a
value of type TCXState in this case. It is ok that they use a subset
from the start (SysBusDevice or DeviceState), but we can't do much more
than that.
What we do with reset:
static void tcx_reset(DeviceState *d)
{
TCXState *s = container_of(d, TCXState, busdev.qdev);
....
}
is not different that
static void tcx_reset(void *opaque)
{
TCXState *s = opaque;
....
}
And in the case of vmstate, we have to sent values that are not qdev
based yet, i.e. we can't use this trick. We could de a
vmstate_qdev_register() with the other type, but will not help so much
(VMStateDescription has to still use void * inside).
Later, Juan.
prev parent reply other threads:[~2009-11-12 14:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-11 22:53 [Qemu-devel] [PATCH] fdc: Fix vmsave/restore regression Jan Kiszka
2009-11-11 23:28 ` [Qemu-devel] " Juan Quintela
2009-11-12 13:00 ` Juan Quintela
2009-11-12 13:13 ` Jan Kiszka
2009-11-12 14:37 ` Juan Quintela [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3k4xvq057.fsf@neno.mitica \
--to=quintela@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=jan.kiszka@web.de \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).