Re: [libvirt] [libvirt PATCH v2 1/4] domain_conf: split out virBlkioDevice and virDomainBlkiotune definitions

2018-09-12 Thread Michal Privoznik
On 09/12/2018 10:57 AM, Fabiano Fidêncio wrote:
> Let's move those to their own newly created files
> (src/util/virblkio.{c,h}) as this will help us to easily start sharing
> the cgroup code that's duplicated between QEMU and LXC.
> 
> Signed-off-by: Fabiano Fidêncio 
> ---
>  src/Makefile.am  |  1 +
>  src/conf/domain_conf.c   | 11 +
>  src/conf/domain_conf.h   | 27 ++---
>  src/util/Makefile.inc.am |  2 ++
>  src/util/virblkio.c  | 37 
>  src/util/virblkio.h  | 52 
>  6 files changed, 95 insertions(+), 35 deletions(-)
>  create mode 100644 src/util/virblkio.c
>  create mode 100644 src/util/virblkio.h
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 2a3ed0d42d..926085ff2d 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -671,6 +671,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
>   util/viratomic.c \
>   util/viratomic.h \
>   util/virbitmap.c \
> + util/virblkio.c \
>   util/virbuffer.c \
>   util/vircgroup.c \
>   util/vircommand.c \

This is not needed. setuid_rpc_client is trying to be very minimalistic
library which is then statically linked to virt-login-shell. The aim is
to have something small, thus auditable and yet capable of talking to
libvirtd through RPC.

> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 7e14cea128..6ce50f712a 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -59,6 +59,7 @@
>  #include "virnetdevmacvlan.h"
>  #include "virhostdev.h"
>  #include "virmdev.h"
> +#include "virblkio.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_DOMAIN
>  
> @@ -1205,16 +1206,6 @@ virDomainXMLOptionGetSaveCookie(virDomainXMLOptionPtr 
> xmlopt)
>  }
>  
>  
> -void
> -virBlkioDeviceArrayClear(virBlkioDevicePtr devices,
> - int ndevices)
> -{
> -size_t i;
> -
> -for (i = 0; i < ndevices; i++)
> -VIR_FREE(devices[i].path);
> -}
> -
>  /**
>   * virDomainBlkioDeviceParseXML
>   *
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index e30a4b2fe7..e9e6b6d6c4 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -57,6 +57,7 @@
>  # include "virtypedparam.h"
>  # include "virsavecookie.h"
>  # include "virresctrl.h"
> +# include "virblkio.h"
>  
>  /* forward declarations of all device types, required by
>   * virDomainDeviceDef
> @@ -2084,17 +2085,6 @@ struct _virDomainClockDef {
>  };
>  
>  
> -typedef struct _virBlkioDevice virBlkioDevice;
> -typedef virBlkioDevice *virBlkioDevicePtr;
> -struct _virBlkioDevice {
> -char *path;
> -unsigned int weight;
> -unsigned int riops;
> -unsigned int wiops;
> -unsigned long long rbps;
> -unsigned long long wbps;
> -};
> -
>  typedef enum {
>  VIR_DOMAIN_RNG_MODEL_VIRTIO,
>  
> @@ -2184,9 +2174,6 @@ struct _virDomainPanicDef {
>  };
>  
>  
> -void virBlkioDeviceArrayClear(virBlkioDevicePtr deviceWeights,
> -  int ndevices);
> -
>  typedef struct _virDomainResourceDef virDomainResourceDef;
>  typedef virDomainResourceDef *virDomainResourceDefPtr;
>  struct _virDomainResourceDef {
> @@ -2260,16 +2247,6 @@ struct _virDomainVcpuDef {
>  virObjectPtr privateData;
>  };
>  
> -typedef struct _virDomainBlkiotune virDomainBlkiotune;
> -typedef virDomainBlkiotune *virDomainBlkiotunePtr;
> -
> -struct _virDomainBlkiotune {
> -unsigned int weight;
> -
> -size_t ndevices;
> -virBlkioDevicePtr devices;
> -};
> -
>  typedef struct _virDomainMemtune virDomainMemtune;
>  typedef virDomainMemtune *virDomainMemtunePtr;
>  
> @@ -2402,7 +2379,7 @@ struct _virDomainDef {
>  char *title;
>  char *description;
>  
> -virDomainBlkiotune blkio;
> +virBlkioTune blkio;
>  virDomainMemtune mem;
>  
>  virDomainVcpuDefPtr *vcpus;
> diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
> index a22265606c..13f415b23c 100644
> --- a/src/util/Makefile.inc.am
> +++ b/src/util/Makefile.inc.am
> @@ -17,6 +17,8 @@ UTIL_SOURCES = \
>   util/virauthconfig.h \
>   util/virbitmap.c \
>   util/virbitmap.h \
> + util/virblkio.c \
> + util/virblkio.h \
>   util/virbuffer.c \
>   util/virbuffer.h \
>   util/virperf.c \
> diff --git a/src/util/virblkio.c b/src/util/virblkio.c
> new file mode 100644
> index 00..9711077ee8
> --- /dev/null
> +++ b/src/util/virblkio.c
> @@ -0,0 +1,37 @@
> +/*
> + * virblkio.c: Block IO helpers
> + *
> + * Copyright (C) 2018 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 

[libvirt] [libvirt PATCH v2 1/4] domain_conf: split out virBlkioDevice and virDomainBlkiotune definitions

2018-09-12 Thread Fabiano Fidêncio
Let's move those to their own newly created files
(src/util/virblkio.{c,h}) as this will help us to easily start sharing
the cgroup code that's duplicated between QEMU and LXC.

Signed-off-by: Fabiano Fidêncio 
---
 src/Makefile.am  |  1 +
 src/conf/domain_conf.c   | 11 +
 src/conf/domain_conf.h   | 27 ++---
 src/util/Makefile.inc.am |  2 ++
 src/util/virblkio.c  | 37 
 src/util/virblkio.h  | 52 
 6 files changed, 95 insertions(+), 35 deletions(-)
 create mode 100644 src/util/virblkio.c
 create mode 100644 src/util/virblkio.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 2a3ed0d42d..926085ff2d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -671,6 +671,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
util/viratomic.c \
util/viratomic.h \
util/virbitmap.c \
+   util/virblkio.c \
util/virbuffer.c \
util/vircgroup.c \
util/vircommand.c \
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7e14cea128..6ce50f712a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -59,6 +59,7 @@
 #include "virnetdevmacvlan.h"
 #include "virhostdev.h"
 #include "virmdev.h"
+#include "virblkio.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -1205,16 +1206,6 @@ virDomainXMLOptionGetSaveCookie(virDomainXMLOptionPtr 
xmlopt)
 }
 
 
-void
-virBlkioDeviceArrayClear(virBlkioDevicePtr devices,
- int ndevices)
-{
-size_t i;
-
-for (i = 0; i < ndevices; i++)
-VIR_FREE(devices[i].path);
-}
-
 /**
  * virDomainBlkioDeviceParseXML
  *
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e30a4b2fe7..e9e6b6d6c4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -57,6 +57,7 @@
 # include "virtypedparam.h"
 # include "virsavecookie.h"
 # include "virresctrl.h"
+# include "virblkio.h"
 
 /* forward declarations of all device types, required by
  * virDomainDeviceDef
@@ -2084,17 +2085,6 @@ struct _virDomainClockDef {
 };
 
 
-typedef struct _virBlkioDevice virBlkioDevice;
-typedef virBlkioDevice *virBlkioDevicePtr;
-struct _virBlkioDevice {
-char *path;
-unsigned int weight;
-unsigned int riops;
-unsigned int wiops;
-unsigned long long rbps;
-unsigned long long wbps;
-};
-
 typedef enum {
 VIR_DOMAIN_RNG_MODEL_VIRTIO,
 
@@ -2184,9 +2174,6 @@ struct _virDomainPanicDef {
 };
 
 
-void virBlkioDeviceArrayClear(virBlkioDevicePtr deviceWeights,
-  int ndevices);
-
 typedef struct _virDomainResourceDef virDomainResourceDef;
 typedef virDomainResourceDef *virDomainResourceDefPtr;
 struct _virDomainResourceDef {
@@ -2260,16 +2247,6 @@ struct _virDomainVcpuDef {
 virObjectPtr privateData;
 };
 
-typedef struct _virDomainBlkiotune virDomainBlkiotune;
-typedef virDomainBlkiotune *virDomainBlkiotunePtr;
-
-struct _virDomainBlkiotune {
-unsigned int weight;
-
-size_t ndevices;
-virBlkioDevicePtr devices;
-};
-
 typedef struct _virDomainMemtune virDomainMemtune;
 typedef virDomainMemtune *virDomainMemtunePtr;
 
@@ -2402,7 +2379,7 @@ struct _virDomainDef {
 char *title;
 char *description;
 
-virDomainBlkiotune blkio;
+virBlkioTune blkio;
 virDomainMemtune mem;
 
 virDomainVcpuDefPtr *vcpus;
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index a22265606c..13f415b23c 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -17,6 +17,8 @@ UTIL_SOURCES = \
util/virauthconfig.h \
util/virbitmap.c \
util/virbitmap.h \
+   util/virblkio.c \
+   util/virblkio.h \
util/virbuffer.c \
util/virbuffer.h \
util/virperf.c \
diff --git a/src/util/virblkio.c b/src/util/virblkio.c
new file mode 100644
index 00..9711077ee8
--- /dev/null
+++ b/src/util/virblkio.c
@@ -0,0 +1,37 @@
+/*
+ * virblkio.c: Block IO helpers
+ *
+ * Copyright (C) 2018 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, see
+ * .
+ *
+ * Authors:
+ *  Fabiano Fidêncio 
+ */
+
+#include 
+
+#include "viralloc.h"
+#include "virblkio.h"
+
+void
+virBlkioDeviceArrayClear(virBlkioDevicePtr devices,
+ int ndevices)
+{
+size_t i;
+
+for (i