diff mbox

[RFC,06/10] qdev: add stubs for vmstate register/unregister functions

Message ID 1354303642-4283-7-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost Nov. 30, 2012, 7:27 p.m. UTC
Add vmstate stub functions, so that qdev.o can be used without savevm.o
when vmstate support is not necessary (i.e. by *-user).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Originally submitted as:
  Subject: qdev-core: isolate vmstate handling into separate functions

Changes v1 -> v2:
 - Add GCC_WEAK_DECL to function declarations

Changes v2 -> v3:
 - Subject: qdev: add weak aliases for vmstate handling on qdev.c
 - Make vmstate_register_with_alias_id()/vmstate_unregister()
   have GCC_WEAK versions, instead of creating a new function
 - Kept qdev_get_vmsd() inside qdev.c

Changss v3 -> v4:
 - Use the new QEMU_WEAK_ALIAS system instead of GCC_WEAK

Changes v4 -> v5:
 - Use the new libqemustub.a, instead of QEMU_WEAK_ALIAS

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 stubs/Makefile.objs |  1 +
 stubs/vmstate.c     | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 stubs/vmstate.c

Comments

Igor Mammedov Dec. 3, 2012, 9:49 p.m. UTC | #1
On Fri, 30 Nov 2012 17:27:18 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Add vmstate stub functions, so that qdev.o can be used without savevm.o
> when vmstate support is not necessary (i.e. by *-user).
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Originally submitted as:
>   Subject: qdev-core: isolate vmstate handling into separate functions
> 
> Changes v1 -> v2:
>  - Add GCC_WEAK_DECL to function declarations
> 
> Changes v2 -> v3:
>  - Subject: qdev: add weak aliases for vmstate handling on qdev.c
>  - Make vmstate_register_with_alias_id()/vmstate_unregister()
>    have GCC_WEAK versions, instead of creating a new function
>  - Kept qdev_get_vmsd() inside qdev.c
> 
> Changss v3 -> v4:
>  - Use the new QEMU_WEAK_ALIAS system instead of GCC_WEAK
> 
> Changes v4 -> v5:
>  - Use the new libqemustub.a, instead of QEMU_WEAK_ALIAS
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  stubs/Makefile.objs |  1 +
>  stubs/vmstate.c     | 17 +++++++++++++++++
>  2 files changed, 18 insertions(+)
>  create mode 100644 stubs/vmstate.c
> 
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index 035b29a..5557079 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -5,4 +5,5 @@ stub-obj-y += fdset-get-fd.o
>  stub-obj-y += fdset-remove-fd.o
>  stub-obj-y += get-fd.o
>  stub-obj-y += set-fd-handler.o
> +stub-obj-y += vmstate.o
>  stub-obj-$(CONFIG_WIN32) += fd-register.o
> diff --git a/stubs/vmstate.c b/stubs/vmstate.c
> new file mode 100644
> index 0000000..bb17884
> --- /dev/null
> +++ b/stubs/vmstate.c
> @@ -0,0 +1,17 @@
> +#include "qemu-common.h"
> +#include "vmstate.h"
> +
> +int vmstate_register_with_alias_id(DeviceState *dev,
> +                                               int instance_id,
> +                                               const VMStateDescription *vmsd,
> +                                               void *base, int alias_id,
> +                                               int required_for_version)
> +{
> +    return 0;
> +}
> +
> +void vmstate_unregister(DeviceState *dev,
> +                                    const VMStateDescription *vmsd,
> +                                    void *opaque)
> +{
> +}
> -- 
> 1.7.11.7
> 
commit 3bc2f570ec9f description says, there should be a 1 object
file per stub /with a corresponding file name if 3bc2f570ec9f is used as a
model/.

Paolo,
 Is it ok to put several related stub functions in one file?
Eduardo Habkost Dec. 4, 2012, 12:49 p.m. UTC | #2
On Mon, Dec 03, 2012 at 10:49:56PM +0100, Igor Mammedov wrote:
> On Fri, 30 Nov 2012 17:27:18 -0200
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > Add vmstate stub functions, so that qdev.o can be used without savevm.o
> > when vmstate support is not necessary (i.e. by *-user).
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> > Originally submitted as:
> >   Subject: qdev-core: isolate vmstate handling into separate functions
> > 
> > Changes v1 -> v2:
> >  - Add GCC_WEAK_DECL to function declarations
> > 
> > Changes v2 -> v3:
> >  - Subject: qdev: add weak aliases for vmstate handling on qdev.c
> >  - Make vmstate_register_with_alias_id()/vmstate_unregister()
> >    have GCC_WEAK versions, instead of creating a new function
> >  - Kept qdev_get_vmsd() inside qdev.c
> > 
> > Changss v3 -> v4:
> >  - Use the new QEMU_WEAK_ALIAS system instead of GCC_WEAK
> > 
> > Changes v4 -> v5:
> >  - Use the new libqemustub.a, instead of QEMU_WEAK_ALIAS
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  stubs/Makefile.objs |  1 +
> >  stubs/vmstate.c     | 17 +++++++++++++++++
> >  2 files changed, 18 insertions(+)
> >  create mode 100644 stubs/vmstate.c
> > 
> > diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> > index 035b29a..5557079 100644
> > --- a/stubs/Makefile.objs
> > +++ b/stubs/Makefile.objs
> > @@ -5,4 +5,5 @@ stub-obj-y += fdset-get-fd.o
> >  stub-obj-y += fdset-remove-fd.o
> >  stub-obj-y += get-fd.o
> >  stub-obj-y += set-fd-handler.o
> > +stub-obj-y += vmstate.o
> >  stub-obj-$(CONFIG_WIN32) += fd-register.o
> > diff --git a/stubs/vmstate.c b/stubs/vmstate.c
> > new file mode 100644
> > index 0000000..bb17884
> > --- /dev/null
> > +++ b/stubs/vmstate.c
> > @@ -0,0 +1,17 @@
> > +#include "qemu-common.h"
> > +#include "vmstate.h"
> > +
> > +int vmstate_register_with_alias_id(DeviceState *dev,
> > +                                               int instance_id,
> > +                                               const VMStateDescription *vmsd,
> > +                                               void *base, int alias_id,
> > +                                               int required_for_version)
> > +{
> > +    return 0;
> > +}
> > +
> > +void vmstate_unregister(DeviceState *dev,
> > +                                    const VMStateDescription *vmsd,
> > +                                    void *opaque)
> > +{
> > +}
> > -- 
> > 1.7.11.7
> > 
> commit 3bc2f570ec9f description says, there should be a 1 object
> file per stub /with a corresponding file name if 3bc2f570ec9f is used as a
> model/.

Well, the commit description says that "if you place each function in a
separate source file, object files for unused functions will not be
taken in", I don't see it as a requirement. In this case, pulling both
stubs is a feature: if a binary ends up using the vmstate_register stub,
we really want it to use the vmstate_unregister stub as well.

> 
> Paolo,
>  Is it ok to put several related stub functions in one file?
> 
> -- 
> Regards,
>   Igor
>
Paolo Bonzini Dec. 4, 2012, 1:08 p.m. UTC | #3
Il 04/12/2012 13:49, Eduardo Habkost ha scritto:
> Well, the commit description says that "if you place each function in a
> separate source file, object files for unused functions will not be
> taken in", I don't see it as a requirement. In this case, pulling both
> stubs is a feature: if a binary ends up using the vmstate_register stub,
> we really want it to use the vmstate_unregister stub as well.

I think Eduardo is right.  In the beginning I was thinking more of
having one function per file, but then in some cases the functions are
clearly related.

For example, if you have monitor_printf/monitor_vprintf, you have two
choices:

- put both of them in the same file, as done here for vmstate.

- put each in a separate file.  In this case, it doesn't really make
sense to implement only one, so the monitor_printf stub should use
va_start/va_end to forward to monitor_vprintf.

In the second case, the monitor_printf stub is not even a stub anymore,
because the same function will always be usable.  This makes it much
better to put both of them in the same file, IMHO.

Paolo
diff mbox

Patch

diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 035b29a..5557079 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -5,4 +5,5 @@  stub-obj-y += fdset-get-fd.o
 stub-obj-y += fdset-remove-fd.o
 stub-obj-y += get-fd.o
 stub-obj-y += set-fd-handler.o
+stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
diff --git a/stubs/vmstate.c b/stubs/vmstate.c
new file mode 100644
index 0000000..bb17884
--- /dev/null
+++ b/stubs/vmstate.c
@@ -0,0 +1,17 @@ 
+#include "qemu-common.h"
+#include "vmstate.h"
+
+int vmstate_register_with_alias_id(DeviceState *dev,
+                                               int instance_id,
+                                               const VMStateDescription *vmsd,
+                                               void *base, int alias_id,
+                                               int required_for_version)
+{
+    return 0;
+}
+
+void vmstate_unregister(DeviceState *dev,
+                                    const VMStateDescription *vmsd,
+                                    void *opaque)
+{
+}