[libvirt] [glib] Don't overwrite filesystem type when writing format
Christophe Fergeau
cfergeau at redhat.com
Tue Jul 7 15:31:39 UTC 2015
Hey,
On Tue, Jul 07, 2015 at 04:26:02PM +0200, Cédric Bosdonnat wrote:
> When setting filesystem driver format first and type, only the type
> remained and vice-versa.
> ---
> libvirt-gconfig/libvirt-gconfig-domain-filesys.c | 8 ++++++--
> tests/test-gconfig.c | 2 +-
> tests/xml/gconfig-domain-device-filesys.xml | 2 +-
> 3 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-filesys.c b/libvirt-gconfig/libvirt-gconfig-domain-filesys.c
> index 9b73af5..4e33d5f 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain-filesys.c
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-filesys.c
> @@ -125,7 +125,9 @@ void gvir_config_domain_filesys_set_driver_type(GVirConfigDomainFilesys *filesys
> GVirConfigObject *node;
>
> g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_FILESYS(filesys));
> - node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(filesys), "driver");
> + node = gvir_config_object_get_child(GVIR_CONFIG_OBJECT(filesys), "driver");
> + if (!node)
> + node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(filesys), "driver");
This is unintuitive, but after looking at the code and a quick test, I
think _add_child() will create the node if it does not exist, and return
the existing node if it already exists. So I think this could become:
+ node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(filesys), "driver");
> g_return_if_fail(GVIR_CONFIG_IS_OBJECT(node));
> if (type != GVIR_CONFIG_DOMAIN_FILESYS_DRIVER_DEFAULT)
> gvir_config_object_set_attribute_with_type(
> @@ -143,7 +145,9 @@ void gvir_config_domain_filesys_set_driver_format(GVirConfigDomainFilesys *files
> GVirConfigObject *node;
>
> g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_FILESYS(filesys));
> - node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(filesys), "driver");
> + node = gvir_config_object_get_child(GVIR_CONFIG_OBJECT(filesys), "driver");
> + if (!node)
> + node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(filesys), "driver");
and same here.
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150707/07185992/attachment-0001.sig>
More information about the libvir-list
mailing list