* top-level directory.
*/
-#include "iov.h"
+#include "qemu/iov.h"
#include "qdev.h"
#include "virtio.h"
#include "virtio-rng.h"
/* Only one vq - guest puts buffer(s) on it when it needs entropy */
VirtQueue *vq;
- /* Config data for the device -- currently only chardev */
VirtIORNGConf *conf;
RngBackend *rng;
return false;
}
-static size_t get_request_size(VirtQueue *vq)
+static size_t get_request_size(VirtQueue *vq, unsigned quota)
{
unsigned int in, out;
- virtqueue_get_avail_bytes(vq, &in, &out);
+ virtqueue_get_avail_bytes(vq, &in, &out, quota, 0);
return in;
}
static void virtio_rng_process(VirtIORNG *vrng)
{
size_t size;
+ unsigned quota;
if (!is_guest_ready(vrng)) {
return;
}
- size = get_request_size(vrng->vq);
+ if (vrng->quota_remaining < 0) {
+ quota = 0;
+ } else {
+ quota = MIN((uint64_t)vrng->quota_remaining, (uint64_t)UINT32_MAX);
+ }
+ size = get_request_size(vrng->vq, quota);
size = MIN(vrng->quota_remaining, size);
if (size) {
rng_backend_request_entropy(vrng->rng, size, chr_read, vrng);
virtio_load(&vrng->vdev, f);
/* We may have an element ready but couldn't process it due to a quota
- limit. Make sure to try again after live migration when the quota may
- have been reset.
- */
+ * limit. Make sure to try again after live migration when the quota may
+ * have been reset.
+ */
virtio_rng_process(vrng);
return 0;
vrng->qdev = dev;
vrng->conf = conf;
+ assert(vrng->conf->max_bytes <= INT64_MAX);
vrng->quota_remaining = vrng->conf->max_bytes;
- g_assert_cmpint(vrng->conf->max_bytes, <=, INT64_MAX);
-
vrng->rate_limit_timer = qemu_new_timer_ms(vm_clock,
check_rate_limit, vrng);