diff mbox

[RFC,2/2] rng-egd: introduce a parameter to set buffer size

Message ID 1386598213-8156-3-git-send-email-akong@redhat.com
State New
Headers show

Commit Message

Amos Kong Dec. 9, 2013, 2:10 p.m. UTC
This patch makes the buffer size configurable, the max
buffer size is 65536.

 -object rng-egd,chardev=chr0,id=rng0,buf_size=1024

Signed-off-by: Amos Kong <akong@redhat.com>
---
 backends/rng-egd.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Comments

Eric Blake Dec. 10, 2013, 4:58 p.m. UTC | #1
On 12/09/2013 07:10 AM, Amos Kong wrote:
> This patch makes the buffer size configurable, the max
> buffer size is 65536.
> 
>  -object rng-egd,chardev=chr0,id=rng0,buf_size=1024
> 
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
>  backends/rng-egd.c | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)

> @@ -281,6 +298,7 @@ static void rng_egd_init(Object *obj)
>      object_property_add_str(obj, "chardev",
>                              rng_egd_get_chardev, rng_egd_set_chardev,
>                              NULL);
> +    object_property_add_str(obj, "buf_size", NULL, rng_egd_set_buf_size, NULL);
>  }

Will libvirt ever need to set this property?  And is it easily
discoverable whether qemu supports or lacks this property?
Amos Kong Dec. 12, 2013, 2:55 a.m. UTC | #2
On Tue, Dec 10, 2013 at 09:58:19AM -0700, Eric Blake wrote:
> On 12/09/2013 07:10 AM, Amos Kong wrote:

Hi Eric,

> > This patch makes the buffer size configurable, the max
> > buffer size is 65536.
> > 
> >  -object rng-egd,chardev=chr0,id=rng0,buf_size=1024
> > 
> > Signed-off-by: Amos Kong <akong@redhat.com>
> > ---
> >  backends/rng-egd.c | 24 +++++++++++++++++++++---
> >  1 file changed, 21 insertions(+), 3 deletions(-)
> 
> > @@ -281,6 +298,7 @@ static void rng_egd_init(Object *obj)
> >      object_property_add_str(obj, "chardev",
> >                              rng_egd_get_chardev, rng_egd_set_chardev,
> >                              NULL);
> > +    object_property_add_str(obj, "buf_size", NULL, rng_egd_set_buf_size, NULL);
> >  }
> 
> Will libvirt ever need to set this property?  And is it easily
> discoverable whether qemu supports or lacks this property?

This is ajust a RFC patch, we might fix the performance with other
method. If it won't cost too much memory for buf, we can remove
this parameter.

In this patch, we have a default buffer size.
 
> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
diff mbox

Patch

diff --git a/backends/rng-egd.c b/backends/rng-egd.c
index d317c61..4e5ba18 100644
--- a/backends/rng-egd.c
+++ b/backends/rng-egd.c
@@ -18,7 +18,7 @@ 
 #define TYPE_RNG_EGD "rng-egd"
 #define RNG_EGD(obj) OBJECT_CHECK(RngEgd, (obj), TYPE_RNG_EGD)
 
-#define BUFFER_SIZE 65536
+#define MAX_BUFFER_SIZE 65536
 
 typedef struct RngEgd
 {
@@ -31,6 +31,7 @@  typedef struct RngEgd
     GSList *requests;
     void *opaque;
     size_t req_size;
+    uint32_t buf_size;
 } RngEgd;
 
 typedef struct RngRequest
@@ -154,9 +155,16 @@  static void rng_egd_request_entropy(RngBackend *b, size_t size,
     }
 
     int total_size = get_total_buf_size(s);
+    int buf_size;
 
-    while (total_size < BUFFER_SIZE)  {
-        int add_size = MIN(BUFFER_SIZE - total_size, 255);
+    if (s->buf_size != 0) {
+        buf_size = MIN(s->buf_size, MAX_BUFFER_SIZE);
+    } else {
+        buf_size = MAX_BUFFER_SIZE;
+    }
+
+    while (total_size < buf_size)  {
+        int add_size = MIN(buf_size - total_size, 255);
         total_size += add_size;
         rng_egd_append_request(b, add_size, receive_entropy, opaque);
     }
@@ -253,6 +261,15 @@  static void rng_egd_opened(RngBackend *b, Error **errp)
                           NULL, s);
 }
 
+static void rng_egd_set_buf_size(Object *obj, const char *value, Error **errp)
+{
+    RngBackend *b = RNG_BACKEND(obj);
+    RngEgd *s = RNG_EGD(b);
+
+    s->buf_size = atoi(value);
+    assert(s->buf_size > 0);
+}
+
 static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
 {
     RngBackend *b = RNG_BACKEND(obj);
@@ -281,6 +298,7 @@  static void rng_egd_init(Object *obj)
     object_property_add_str(obj, "chardev",
                             rng_egd_get_chardev, rng_egd_set_chardev,
                             NULL);
+    object_property_add_str(obj, "buf_size", NULL, rng_egd_set_buf_size, NULL);
 }
 
 static void rng_egd_finalize(Object *obj)