[libvirt] [libvirt-glib 2/3] Add LibvirtGConfigDomainChardevSourceSpiceVmc

Christophe Fergeau cfergeau at redhat.com
Tue Mar 13 15:15:59 UTC 2012


Hey,

On Tue, Mar 13, 2012 at 01:22:09AM +0100, Marc-André Lureau wrote:
> On Mon, Mar 12, 2012 at 5:56 PM, Christophe Fergeau <cfergeau at redhat.com> wrote:
> > Ping for this patch and for 3/3 ?
> 
> ./test-domain-create gives:
> 
>     <channel type="spicevmc">
>       <target type="channel-target-virtio"/>
>     </channel>
> 
> Where we expect this:
> 
>     <channel type='spicevmc'>
>       <target type='virtio' name='com.redhat.spice.0'/>
>       <address type='virtio-serial' controller='0' bus='0' port='1'/>
>     </channel>

The "address" element is optional, see
http://libvirt.org/formatdomain.html#elementCharChannel "The optional
address element can tie the channel to a particular type='virtio-serial'
controller."
It seems libvirt will still do the right thing if it's omitted:
http://libvirt.org/formatdomain.html#elementsAddress
I tend to only add API in libvirt-gconfig when there's a need for it, but I
can look into adding API to set the address element if you think that's
needed now.

Similarly, the "name" attribute is optional, and defaults to
'com.redhat.spice.0'. It can be set with
vir_config_domain_channel_set_target_name

While looking at this, I've found that I need to squash this in this patch:

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h
index 6b2ab20..8bbe634 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h
@@ -62,9 +62,6 @@ GType gvir_config_domain_chardev_source_spicevmc_get_type(void);
 GVirConfigDomainChardevSourceSpiceVmc *gvir_config_domain_chardev_source_spicevmc_new(void);
 GVirConfigDomainChardevSourceSpiceVmc *gvir_config_domain_chardev_source_spicevmc_new_from_xml(const gchar *xml,
                                                                               GError **error);
-void gvir_config_domain_source_spicevmc_set_path(GVirConfigDomainChardevSourceSpiceVmc *spicevmc,
-                                                 const char *path);
-
 G_END_DECLS
 
 #endif /* __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_H__ */

Christophe

> 
> 
> > Christophe
> >
> > On Tue, Mar 06, 2012 at 05:38:33PM +0100, Christophe Fergeau wrote:
> >> This is needed to be able to add the SPICE agent channels
> >> ---
> >>  libvirt-gconfig/Makefile.am                        |    2 +
> >>  ...ibvirt-gconfig-domain-chardev-source-spicevmc.c |   80 ++++++++++++++++++++
> >>  ...ibvirt-gconfig-domain-chardev-source-spicevmc.h |   70 +++++++++++++++++
> >>  libvirt-gconfig/libvirt-gconfig.h                  |    1 +
> >>  libvirt-gconfig/libvirt-gconfig.sym                |    4 +
> >>  libvirt-gconfig/tests/test-domain-create.c         |   14 ++++
> >>  6 files changed, 171 insertions(+), 0 deletions(-)
> >>  create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c
> >>  create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h
> >>
> >> diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
> >> index 03a5507..d9e87b5 100644
> >> --- a/libvirt-gconfig/Makefile.am
> >> +++ b/libvirt-gconfig/Makefile.am
> >> @@ -17,6 +17,7 @@ GCONFIG_HEADER_FILES = \
> >>                       libvirt-gconfig-domain-chardev.h \
> >>                       libvirt-gconfig-domain-chardev-source.h \
> >>                       libvirt-gconfig-domain-chardev-source-pty.h \
> >> +                     libvirt-gconfig-domain-chardev-source-spicevmc.h \
> >>                       libvirt-gconfig-domain-clock.h \
> >>                       libvirt-gconfig-domain-console.h \
> >>                       libvirt-gconfig-domain-device.h \
> >> @@ -68,6 +69,7 @@ GCONFIG_SOURCE_FILES = \
> >>                       libvirt-gconfig-domain-chardev.c \
> >>                       libvirt-gconfig-domain-chardev-source.c \
> >>                       libvirt-gconfig-domain-chardev-source-pty.c \
> >> +                     libvirt-gconfig-domain-chardev-source-spicevmc.c \
> >>                       libvirt-gconfig-domain-clock.c \
> >>                       libvirt-gconfig-domain-console.c \
> >>                       libvirt-gconfig-domain-device.c \
> >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c
> >> new file mode 100644
> >> index 0000000..22eabf5
> >> --- /dev/null
> >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c
> >> @@ -0,0 +1,80 @@
> >> +/*
> >> + * libvirt-gconfig-domain-chardev-source-spicevmc.c: libvirt domain chardev spicevmc configuration
> >> + *
> >> + * Copyright (C) 2012 Red Hat, Inc.
> >> + *
> >> + * This library is free software; you can redistribute it and/or
> >> + * modify it under the terms of the GNU Lesser General Public
> >> + * License as published by the Free Software Foundation; either
> >> + * version 2.1 of the License, or (at your option) any later version.
> >> + *
> >> + * This library is distributed in the hope that it will be useful,
> >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> >> + * Lesser General Public License for more details.
> >> + *
> >> + * You should have received a copy of the GNU Lesser General Public
> >> + * License along with this library; if not, write to the Free Software
> >> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> >> + *
> >> + * Author: Christophe Fergeau <cfergeau at redhat.com>
> >> + */
> >> +
> >> +#include <config.h>
> >> +
> >> +#include "libvirt-gconfig/libvirt-gconfig.h"
> >> +#include "libvirt-gconfig/libvirt-gconfig-private.h"
> >> +
> >> +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_GET_PRIVATE(obj)                         \
> >> +        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC, GVirConfigDomainChardevSourceSpiceVmcPrivate))
> >> +
> >> +struct _GVirConfigDomainChardevSourceSpiceVmcPrivate
> >> +{
> >> +    gboolean unused;
> >> +};
> >> +
> >> +G_DEFINE_TYPE(GVirConfigDomainChardevSourceSpiceVmc, gvir_config_domain_chardev_source_spicevmc, GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE);
> >> +
> >> +
> >> +static void gvir_config_domain_chardev_source_spicevmc_class_init(GVirConfigDomainChardevSourceSpiceVmcClass *klass)
> >> +{
> >> +    g_type_class_add_private(klass, sizeof(GVirConfigDomainChardevSourceSpiceVmcPrivate));
> >> +}
> >> +
> >> +
> >> +static void gvir_config_domain_chardev_source_spicevmc_init(GVirConfigDomainChardevSourceSpiceVmc *source)
> >> +{
> >> +    g_debug("Init GVirConfigDomainChardevSourceSpiceVmc=%p", source);
> >> +
> >> +    source->priv = GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_GET_PRIVATE(source);
> >> +}
> >> +
> >> +
> >> +GVirConfigDomainChardevSourceSpiceVmc *gvir_config_domain_chardev_source_spicevmc_new(void)
> >> +{
> >> +    GVirConfigObject *object;
> >> +
> >> +    /* the name of the root node is just a placeholder, it will be
> >> +     * overwritten when the GVirConfigDomainChardevSourceSpiceVmc is attached to a
> >> +     * GVirConfigDomainChardevSourceSpiceVmc
> >> +     */
> >> +    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC, "dummy", NULL);
> >> +    gvir_config_object_set_attribute(object, "type", "spicevmc", NULL);
> >> +    return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC(object);
> >> +}
> >> +
> >> +
> >> +GVirConfigDomainChardevSourceSpiceVmc *gvir_config_domain_chardev_source_spicevmc_new_from_xml(const gchar *xml,
> >> +                                                                              GError **error)
> >> +{
> >> +    GVirConfigObject *object;
> >> +
> >> +    /* the name of the root node is just a placeholder, it will be
> >> +     * overwritten when the GVirConfigDomainChardevSourceSpiceVmc is attached to a
> >> +     * GVirConfigDomainChardevSourceSpiceVmc
> >> +     */
> >> +    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC,
> >> +                                             "dummy", NULL, xml, error);
> >> +    gvir_config_object_set_attribute(object, "type", "spicevmc", NULL);
> >> +    return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC(object);
> >> +}
> >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h
> >> new file mode 100644
> >> index 0000000..6b2ab20
> >> --- /dev/null
> >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h
> >> @@ -0,0 +1,70 @@
> >> +/*
> >> + * libvirt-gconfig-domain-chardev-source-spicevmc.h: libvirt domain chardev spicevmc configuration
> >> + *
> >> + * Copyright (C) 2012 Red Hat, Inc.
> >> + *
> >> + * This library is free software; you can redistribute it and/or
> >> + * modify it under the terms of the GNU Lesser General Public
> >> + * License as published by the Free Software Foundation; either
> >> + * version 2.1 of the License, or (at your option) any later version.
> >> + *
> >> + * This library is distributed in the hope that it will be useful,
> >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> >> + * Lesser General Public License for more details.
> >> + *
> >> + * You should have received a copy of the GNU Lesser General Public
> >> + * License along with this library; if not, write to the Free Software
> >> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> >> + *
> >> + * Author: Christophe Fergeau <cfergeau at redhat.com>
> >> + */
> >> +
> >> +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
> >> +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
> >> +#endif
> >> +
> >> +#ifndef __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_H__
> >> +#define __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_H__
> >> +
> >> +G_BEGIN_DECLS
> >> +
> >> +#define GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC            (gvir_config_domain_chardev_source_spicevmc_get_type ())
> >> +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC, GVirConfigDomainChardevSourceSpiceVmc))
> >> +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC, GVirConfigDomainChardevSourceSpiceVmcClass))
> >> +#define GVIR_CONFIG_IS_DOMAIN_CHARDEV_SOURCE_SPICE_VMC(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC))
> >> +#define GVIR_CONFIG_IS_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC))
> >> +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC, GVirConfigDomainChardevSourceSpiceVmcClass))
> >> +
> >> +typedef struct _GVirConfigDomainChardevSourceSpiceVmc GVirConfigDomainChardevSourceSpiceVmc;
> >> +typedef struct _GVirConfigDomainChardevSourceSpiceVmcPrivate GVirConfigDomainChardevSourceSpiceVmcPrivate;
> >> +typedef struct _GVirConfigDomainChardevSourceSpiceVmcClass GVirConfigDomainChardevSourceSpiceVmcClass;
> >> +
> >> +struct _GVirConfigDomainChardevSourceSpiceVmc
> >> +{
> >> +    GVirConfigDomainChardevSource parent;
> >> +
> >> +    GVirConfigDomainChardevSourceSpiceVmcPrivate *priv;
> >> +
> >> +    /* Do not add fields to this struct */
> >> +};
> >> +
> >> +struct _GVirConfigDomainChardevSourceSpiceVmcClass
> >> +{
> >> +    GVirConfigDomainChardevSourceClass parent_class;
> >> +
> >> +    gpointer padding[20];
> >> +};
> >> +
> >> +
> >> +GType gvir_config_domain_chardev_source_spicevmc_get_type(void);
> >> +
> >> +GVirConfigDomainChardevSourceSpiceVmc *gvir_config_domain_chardev_source_spicevmc_new(void);
> >> +GVirConfigDomainChardevSourceSpiceVmc *gvir_config_domain_chardev_source_spicevmc_new_from_xml(const gchar *xml,
> >> +                                                                              GError **error);
> >> +void gvir_config_domain_source_spicevmc_set_path(GVirConfigDomainChardevSourceSpiceVmc *spicevmc,
> >> +                                                 const char *path);
> >> +
> >> +G_END_DECLS
> >> +
> >> +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC_H__ */
> >> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
> >> index cb28e23..b1eede2 100644
> >> --- a/libvirt-gconfig/libvirt-gconfig.h
> >> +++ b/libvirt-gconfig/libvirt-gconfig.h
> >> @@ -33,6 +33,7 @@
> >>  #include <libvirt-gconfig/libvirt-gconfig-domain-chardev.h>
> >>  #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h>
> >>  #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h>
> >> +#include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h>
> >>  #include <libvirt-gconfig/libvirt-gconfig-domain-channel.h>
> >>  #include <libvirt-gconfig/libvirt-gconfig-domain-clock.h>
> >>  #include <libvirt-gconfig/libvirt-gconfig-domain-console.h>
> >> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
> >> index 1329c17..ffde0bc 100644
> >> --- a/libvirt-gconfig/libvirt-gconfig.sym
> >> +++ b/libvirt-gconfig/libvirt-gconfig.sym
> >> @@ -51,6 +51,10 @@ LIBVIRT_GCONFIG_0.0.4 {
> >>       gvir_config_domain_chardev_source_pty_new_from_xml;
> >>       gvir_config_domain_source_pty_set_path;
> >>
> >> +     gvir_config_domain_chardev_source_spicevmc_get_type;
> >> +     gvir_config_domain_chardev_source_spicevmc_new;
> >> +     gvir_config_domain_chardev_source_spicevmc_new_from_xml;
> >> +
> >>       gvir_config_domain_clock_get_type;
> >>       gvir_config_domain_clock_offset_get_type;
> >>       gvir_config_domain_clock_new;
> >> diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
> >> index a92413d..b24d133 100644
> >> --- a/libvirt-gconfig/tests/test-domain-create.c
> >> +++ b/libvirt-gconfig/tests/test-domain-create.c
> >> @@ -181,6 +181,20 @@ int main(int argc, char **argv)
> >>      g_object_unref(G_OBJECT(pty));
> >>      devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(console));
> >>
> >> +    /* spice agent channel */
> >> +    GVirConfigDomainChannel *channel;
> >> +    GVirConfigDomainChardevSourceSpiceVmc *spicevmc;
> >> +
> >> +    channel = gvir_config_domain_channel_new();
> >> +    gvir_config_domain_channel_set_target_type(channel,
> >> +                                               GVIR_CONFIG_DOMAIN_CHANNEL_TARGET_VIRTIO);
> >> +    spicevmc = gvir_config_domain_chardev_source_spicevmc_new();
> >> +    gvir_config_domain_chardev_set_source(GVIR_CONFIG_DOMAIN_CHARDEV(channel),
> >> +                                          GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(spicevmc));
> >> +    g_object_unref(G_OBJECT(spicevmc));
> >> +    devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(channel));
> >> +
> >> +
> >>      gvir_config_domain_set_devices(domain, devices);
> >>      g_list_foreach(devices, (GFunc)g_object_unref, NULL);
> >>      g_list_free(devices);
> >> --
> >> 1.7.7.6
> >>
> >> --
> >> libvir-list mailing list
> >> libvir-list at redhat.com
> >> https://www.redhat.com/mailman/listinfo/libvir-list
> >
> > --
> > libvir-list mailing list
> > libvir-list at redhat.com
> > https://www.redhat.com/mailman/listinfo/libvir-list
> 
> 
> 
> -- 
> Marc-André Lureau
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120313/b99bd24d/attachment-0001.sig>


More information about the libvir-list mailing list