rng: use simpleq instead of gslist

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJW3q6rAAoJEB6aO1+FQIO2SUEP/0nisgkxbzEQGkhNsZHMDkix
 XvyVfdwoTZrITr/JvHCuponQF6MicLxw3zxoo3llgmniHZIqlLs0gGneZlHALQVf
 Pr3hYlmyue6Sq/6U22pI2eOHzo6kBrj9P1hUIstYWNLYyL5i4L7K0L3dlsqv6GUW
 DKfEHw7+rEKCVfFvoT0NubWG2XvjlGOs+56ndKdz8z6u5mf3GH9uPhfP9POMu/xU
 LAVGJT7Zn0MRhQhFW8qx2XIH51QRGArba9Xv8ZezCosMgf2lMCz+mdezWtsgaapb
 Pavl4605zykwmqlLYcJGq4UG7NgP4DuiRaKppbD8fBjaQTvhfHwVRFg37AJt4fn/
 vgDjxZ1a1GsTZkfY0kJ2ui2hg72iRNgZMQKhBnlDZXFTMKmFjHrTAxbF+VEicmLU
 BnxTLcDU+oPKL8CUxFJO+A3WJypikH4OST8q/FdpJVHcenrusKrOpBvnsvufkCD4
 IqoMnYrwJ64YLWr2rxm5yNeuxPKWIbEFXY/3RTSyqL/A+90KaX+GtKNqrs8HI2AE
 F2nxF6QzcBJODxK0M9k9/SV3zi+1NvnVNa7LsH5krFD2WGGA9swyIaPegTOqXsYP
 H93+EGtTJ6AxtfWVx7T7r+jaASqPJODAsFo6mVCSsNOsSs7KbqyCcj52oD53jWS6
 YpKkkaKWIjy7WEMxVxKI
 =CXFm
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/amit-virtio-rng/tags/rng-for-2.6-2' into staging

rng: use simpleq instead of gslist

# gpg: Signature made Tue 08 Mar 2016 10:51:23 GMT using RSA key ID 854083B6
# gpg: Good signature from "Amit Shah <amit@amitshah.net>"
# gpg:                 aka "Amit Shah <amit@kernel.org>"
# gpg:                 aka "Amit Shah <amitshah@gmx.net>"

* remotes/amit-virtio-rng/tags/rng-for-2.6-2:
  rng: switch request queue to QSIMPLEQ

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2016-03-09 00:21:17 +00:00
commit 5763795f93
4 changed files with 19 additions and 16 deletions

View File

@ -49,11 +49,10 @@ static void rng_egd_request_entropy(RngBackend *b, RngRequest *req)
static int rng_egd_chr_can_read(void *opaque) static int rng_egd_chr_can_read(void *opaque)
{ {
RngEgd *s = RNG_EGD(opaque); RngEgd *s = RNG_EGD(opaque);
GSList *i; RngRequest *req;
int size = 0; int size = 0;
for (i = s->parent.requests; i; i = i->next) { QSIMPLEQ_FOREACH(req, &s->parent.requests, next) {
RngRequest *req = i->data;
size += req->size - req->offset; size += req->size - req->offset;
} }
@ -65,8 +64,8 @@ static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)
RngEgd *s = RNG_EGD(opaque); RngEgd *s = RNG_EGD(opaque);
size_t buf_offset = 0; size_t buf_offset = 0;
while (size > 0 && s->parent.requests) { while (size > 0 && !QSIMPLEQ_EMPTY(&s->parent.requests)) {
RngRequest *req = s->parent.requests->data; RngRequest *req = QSIMPLEQ_FIRST(&s->parent.requests);
int len = MIN(size, req->size - req->offset); int len = MIN(size, req->size - req->offset);
memcpy(req->data + req->offset, buf + buf_offset, len); memcpy(req->data + req->offset, buf + buf_offset, len);

View File

@ -35,8 +35,8 @@ static void entropy_available(void *opaque)
{ {
RndRandom *s = RNG_RANDOM(opaque); RndRandom *s = RNG_RANDOM(opaque);
while (s->parent.requests != NULL) { while (!QSIMPLEQ_EMPTY(&s->parent.requests)) {
RngRequest *req = s->parent.requests->data; RngRequest *req = QSIMPLEQ_FIRST(&s->parent.requests);
ssize_t len; ssize_t len;
len = read(s->fd, req->data, req->size); len = read(s->fd, req->data, req->size);
@ -58,7 +58,7 @@ static void rng_random_request_entropy(RngBackend *b, RngRequest *req)
{ {
RndRandom *s = RNG_RANDOM(b); RndRandom *s = RNG_RANDOM(b);
if (s->parent.requests == NULL) { if (QSIMPLEQ_EMPTY(&s->parent.requests)) {
/* If there are no pending requests yet, we need to /* If there are no pending requests yet, we need to
* install our fd handler. */ * install our fd handler. */
qemu_set_fd_handler(s->fd, entropy_available, NULL, s); qemu_set_fd_handler(s->fd, entropy_available, NULL, s);

View File

@ -33,7 +33,7 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,
k->request_entropy(s, req); k->request_entropy(s, req);
s->requests = g_slist_append(s->requests, req); QSIMPLEQ_INSERT_TAIL(&s->requests, req, next);
} }
} }
@ -83,24 +83,27 @@ static void rng_backend_free_request(RngRequest *req)
static void rng_backend_free_requests(RngBackend *s) static void rng_backend_free_requests(RngBackend *s)
{ {
GSList *i; RngRequest *req, *next;
for (i = s->requests; i; i = i->next) { QSIMPLEQ_FOREACH_SAFE(req, &s->requests, next, next) {
rng_backend_free_request(i->data); rng_backend_free_request(req);
} }
g_slist_free(s->requests); QSIMPLEQ_INIT(&s->requests);
s->requests = NULL;
} }
void rng_backend_finalize_request(RngBackend *s, RngRequest *req) void rng_backend_finalize_request(RngBackend *s, RngRequest *req)
{ {
s->requests = g_slist_remove(s->requests, req); QSIMPLEQ_REMOVE(&s->requests, req, RngRequest, next);
rng_backend_free_request(req); rng_backend_free_request(req);
} }
static void rng_backend_init(Object *obj) static void rng_backend_init(Object *obj)
{ {
RngBackend *s = RNG_BACKEND(obj);
QSIMPLEQ_INIT(&s->requests);
object_property_add_bool(obj, "opened", object_property_add_bool(obj, "opened",
rng_backend_prop_get_opened, rng_backend_prop_get_opened,
rng_backend_prop_set_opened, rng_backend_prop_set_opened,

View File

@ -39,6 +39,7 @@ struct RngRequest
void *opaque; void *opaque;
size_t offset; size_t offset;
size_t size; size_t size;
QSIMPLEQ_ENTRY(RngRequest) next;
}; };
struct RngBackendClass struct RngBackendClass
@ -56,7 +57,7 @@ struct RngBackend
/*< protected >*/ /*< protected >*/
bool opened; bool opened;
GSList *requests; QSIMPLEQ_HEAD(requests, RngRequest) requests;
}; };