Re: [libvirt] [PATCHv2 8/8] virtio-rng: Add rate limiting options for virtio-RNG

2013-02-22 Thread Eric Blake
On 02/21/2013 07:47 AM, Peter Krempa wrote:
 Qemu's implementation of virtio RNG supports rate limiting of the
 entropy used. This patch exposes the option to tune this fucntionality.

s/fucntionality/functionality/

 
 This patch is based on qemu commit 904d6f588063fb5ad2b61998acdf1e73fb4
 
 The rate limiting is exported in the XML as:
 devices
   ...
   rng model='virtio'
 rate period='1234'4321/rate

So period='nnn', if provided, is in milliseconds?

 backend model='random'/
   /rng
   ...
 ---
 
 Notes:
 Version 2:
 - Qemu uses bytes/period, adapt the value according to that
 

 @@ -4315,6 +4316,14 @@ qemu-kvm -net nic,model=? /dev/null
li'virtio' mdash; supported by qemu and virtio-rng kernel 
 module/li
  /ul
/dd
 +  dtcoderate/code/dt
 +  dd
 +p
 +  The rate parameter allows to limit the rate that the entropy can be
 +  read from the source. The value is in bits that the device is 
 allowed
 +  to read in the selected period. The default period is 1000ms or 1 
 second.
 +/p

This documentation didn't quite make it clear that 'period' is an
optional attribute in milliseconds.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCHv2 8/8] virtio-rng: Add rate limiting options for virtio-RNG

2013-02-21 Thread Peter Krempa
Qemu's implementation of virtio RNG supports rate limiting of the
entropy used. This patch exposes the option to tune this fucntionality.

This patch is based on qemu commit 904d6f588063fb5ad2b61998acdf1e73fb4

The rate limiting is exported in the XML as:
devices
  ...
  rng model='virtio'
rate period='1234'4321/rate
backend model='random'/
  /rng
  ...
---

Notes:
Version 2:
- Qemu uses bytes/period, adapt the value according to that

 docs/formatdomain.html.in  |  9 +
 docs/schemas/domaincommon.rng  | 18 +-
 src/conf/domain_conf.c | 17 +
 src/conf/domain_conf.h |  2 ++
 src/qemu/qemu_command.c|  9 +
 .../qemuxml2argv-virtio-rng-random.args|  2 +-
 .../qemuxml2argv-virtio-rng-random.xml |  1 +
 7 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index e8cd086..b264460 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4293,6 +4293,7 @@ qemu-kvm -net nic,model=? /dev/null
   ...
   lt;devicesgt;
 lt;rng model='virtio'gt;
+  lt;rate period=2000gt;1234lt;/rategt;
   lt;backend model='random'gt;/dev/randomlt;/backendgt;
   lt;!-- OR --gt;
   lt;backend model='egd' type='udp'gt;
@@ -4315,6 +4316,14 @@ qemu-kvm -net nic,model=? /dev/null
   li'virtio' mdash; supported by qemu and virtio-rng kernel 
module/li
 /ul
   /dd
+  dtcoderate/code/dt
+  dd
+p
+  The rate parameter allows to limit the rate that the entropy can be
+  read from the source. The value is in bits that the device is allowed
+  to read in the selected period. The default period is 1000ms or 1 
second.
+/p
+  /dd
   dtcodebackend/code/dt
   dd
 p
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 8330a50..da53095 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3522,7 +3522,12 @@
   valuevirtio/value
 /choice
   /attribute
-  ref name=rng-backend/
+  interleave
+ref name=rng-backend/
+optional
+  ref name=rng-rate/
+/optional
+  /interleave
 /element
   /define

@@ -3546,6 +3551,17 @@
 /element
   /define

+  define name=rng-rate
+element name=rate
+  optional
+attribute name=period
+  ref name=positiveInteger/
+/attribute
+  /optional
+  ref name=positiveInteger/
+/element
+  /define
+
   define name=usbmaster
 element name=master
   attribute name=startport
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b6de57c..ccf5200 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7501,6 +7501,17 @@ virDomainRNGDefParseXML(const xmlNodePtr node,

 ctxt-node = node;

+if (virXPathUInt(string(./rate), ctxt, def-rate)  -1) {
+virReportError(VIR_ERR_XML_ERROR, %s, _(invalid RNG rate value));
+goto error;
+}
+
+if (def-rate  0 
+virXPathUInt(string(./rate/@period), ctxt, def-period)  -1) {
+virReportError(VIR_ERR_XML_ERROR, %s, _(invalid RNG period value));
+goto error;
+}
+
 if ((nbackends = virXPathNodeSet(./backend, ctxt, backends))  0)
 goto error;

@@ -13814,6 +13825,12 @@ virDomainRNGDefFormat(virBufferPtr buf,
 const char *backend = virDomainRNGBackendTypeToString(def-backend);

 virBufferAsprintf(buf, rng model='%s'\n, model);
+if (def-rate) {
+virBufferAddLit(buf,   rate);
+if (def-period)
+virBufferAsprintf(buf,  period='%u', def-period);
+virBufferAsprintf(buf, %u/rate\n, def-rate);
+}
 virBufferAsprintf(buf,   backend model='%s', backend);

 switch ((enum virDomainRNGBackend) def-backend) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0828954..4b62b93 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1736,6 +1736,8 @@ enum virDomainRNGBackend {
 struct _virDomainRNGDef {
 int model;
 int backend;
+unsigned int rate;
+unsigned int period;

 union {
 char *file; /* file name for 'random' source */
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1c9bfc9..6fcc093 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4255,6 +4255,15 @@ qemuBuildRNGDeviceArgs(virCommandPtr cmd,

 virBufferAsprintf(buf, virtio-rng-pci,rng=%s, dev-info.alias);

+if (dev-rate  0) {
+/* qemu uses bytes */
+virBufferAsprintf(buf, ,max-bytes=%u, dev-rate / 8);
+if (dev-period)
+virBufferAsprintf(buf, ,period=%u, dev-period);
+else
+virBufferAddLit(buf, ,period=1000);
+}
+
 if