Re: [libvirt] [PATCH 07/18] domain_conf: introduce virDomainGraphicsListenAddAddress

2016-04-08 Thread Ján Tomko
On Mon, Apr 04, 2016 at 03:20:24PM +0200, Pavel Hrdina wrote:
> This effectively removes virDomainGraphicsListenSetAddress which was
> used only to change the address of listen structure and possible change
> the listen type.  The new function will auto-expand the listens array
> and add a new listen.
> 
> The old function was used on pre-allocated array of listens and in most
> cases it only "add" a new listen.  The two remaining uses can access the
> listen structure directly.
> 
> Signed-off-by: Pavel Hrdina 
> ---
>  src/conf/domain_conf.c| 34 +++---
>  src/conf/domain_conf.h|  6 +++---
>  src/libvirt_private.syms  |  2 +-
>  src/qemu/qemu_command.c   |  6 ++
>  src/qemu/qemu_parse_command.c |  4 +++-
>  src/qemu/qemu_process.c   | 15 +++
>  src/vbox/vbox_common.c|  3 +--
>  src/vmx/vmx.c |  2 +-
>  src/xenconfig/xen_common.c| 12 +---
>  src/xenconfig/xen_sxpr.c  |  4 ++--
>  src/xenconfig/xen_xl.c|  4 +---
>  11 files changed, 41 insertions(+), 51 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 42050b0..c79a432 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -10741,7 +10741,7 @@ 
> virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
>  /* There were no  elements, so we can just
>   * directly set listenAddr as listens[0]->address */
>  if (listenAddr && def->nListens == 0 &&
> -virDomainGraphicsListenSetAddress(def, 0, listenAddr, -1, true) < 0)
> +virDomainGraphicsListenAddAddress(def, 0, listenAddr) < 0)
>  goto error;
>  
>  ret = 0;
> @@ -23820,31 +23820,27 @@ 
> virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i)
>  }
>  
>  
> -/* Make a copy of up to len characters of address, and store it in
> - * listens[i].address. If setType is true, set the listen's type
> - * to 'address', otherwise leave type alone. */
>  int
> -virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def,
> -  size_t i, const char *address,
> -  int len, bool setType)
> +virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def,
> +  int pos,

I would go even further and delete the pos argument too.
Every single caller uses 0 and only calls it when def->nListens == 0.

> +  const char *address)
>  {
> -virDomainGraphicsListenDefPtr listenInfo
> -= virDomainGraphicsGetListen(def, i, true);
> +virDomainGraphicsListenDef listen;
>  
> -if (!listenInfo)
> -return -1;
> +memset(, 0, sizeof(listen));
>  
> -if (setType)
> -listenInfo->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
> +listen.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
>  
> -if (!address) {
> -VIR_FREE(listenInfo->address);
> -return 0;
> -}
> +if (VIR_STRDUP(listen.address, address) < 0)
> +goto error;
> +
> +if (VIR_INSERT_ELEMENT_COPY(def->listens, pos, def->nListens, listen) < 
> 0)

This would become APPEND_ELEMENT_COPY.

ACK

Jan

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 07/18] domain_conf: introduce virDomainGraphicsListenAddAddress

2016-04-04 Thread Pavel Hrdina
This effectively removes virDomainGraphicsListenSetAddress which was
used only to change the address of listen structure and possible change
the listen type.  The new function will auto-expand the listens array
and add a new listen.

The old function was used on pre-allocated array of listens and in most
cases it only "add" a new listen.  The two remaining uses can access the
listen structure directly.

Signed-off-by: Pavel Hrdina 
---
 src/conf/domain_conf.c| 34 +++---
 src/conf/domain_conf.h|  6 +++---
 src/libvirt_private.syms  |  2 +-
 src/qemu/qemu_command.c   |  6 ++
 src/qemu/qemu_parse_command.c |  4 +++-
 src/qemu/qemu_process.c   | 15 +++
 src/vbox/vbox_common.c|  3 +--
 src/vmx/vmx.c |  2 +-
 src/xenconfig/xen_common.c| 12 +---
 src/xenconfig/xen_sxpr.c  |  4 ++--
 src/xenconfig/xen_xl.c|  4 +---
 11 files changed, 41 insertions(+), 51 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 42050b0..c79a432 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10741,7 +10741,7 @@ 
virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
 /* There were no  elements, so we can just
  * directly set listenAddr as listens[0]->address */
 if (listenAddr && def->nListens == 0 &&
-virDomainGraphicsListenSetAddress(def, 0, listenAddr, -1, true) < 0)
+virDomainGraphicsListenAddAddress(def, 0, listenAddr) < 0)
 goto error;
 
 ret = 0;
@@ -23820,31 +23820,27 @@ 
virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def, size_t i)
 }
 
 
-/* Make a copy of up to len characters of address, and store it in
- * listens[i].address. If setType is true, set the listen's type
- * to 'address', otherwise leave type alone. */
 int
-virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def,
-  size_t i, const char *address,
-  int len, bool setType)
+virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def,
+  int pos,
+  const char *address)
 {
-virDomainGraphicsListenDefPtr listenInfo
-= virDomainGraphicsGetListen(def, i, true);
+virDomainGraphicsListenDef listen;
 
-if (!listenInfo)
-return -1;
+memset(, 0, sizeof(listen));
 
-if (setType)
-listenInfo->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
+listen.type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
 
-if (!address) {
-VIR_FREE(listenInfo->address);
-return 0;
-}
+if (VIR_STRDUP(listen.address, address) < 0)
+goto error;
+
+if (VIR_INSERT_ELEMENT_COPY(def->listens, pos, def->nListens, listen) < 0)
+goto error;
 
-if (VIR_STRNDUP(listenInfo->address, address, len) < 0)
-return -1;
 return 0;
+ error:
+VIR_FREE(listen.address);
+return -1;
 }
 
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fe9faeb..ed3d818 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2818,9 +2818,9 @@ int 
virDomainGraphicsListenSetType(virDomainGraphicsDefPtr def, size_t i, int va
 const char *virDomainGraphicsListenGetAddress(virDomainGraphicsDefPtr def,
   size_t i)
 ATTRIBUTE_NONNULL(1);
-int virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def,
-  size_t i, const char *address,
-  int len, bool setType)
+int virDomainGraphicsListenAddAddress(virDomainGraphicsDefPtr def,
+  int pos,
+  const char *address)
 ATTRIBUTE_NONNULL(1);
 const char *virDomainGraphicsListenGetNetwork(virDomainGraphicsDefPtr def,
   size_t i)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 684f06c..cc1c969 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -300,10 +300,10 @@ virDomainGetFilesystemForTarget;
 virDomainGraphicsAuthConnectedTypeFromString;
 virDomainGraphicsAuthConnectedTypeToString;
 virDomainGraphicsDefFree;
+virDomainGraphicsListenAddAddress;
 virDomainGraphicsListenGetAddress;
 virDomainGraphicsListenGetNetwork;
 virDomainGraphicsListenGetType;
-virDomainGraphicsListenSetAddress;
 virDomainGraphicsListenSetNetwork;
 virDomainGraphicsListenSetType;
 virDomainGraphicsSpiceChannelModeTypeFromString;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2d0ca97..140bf98 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7274,8 +7274,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr 
cfg,
 listenAddr = netAddr;
 /* store the address we found in the  element so it
  * will show up in status. */
-