From nobody Sun Nov 9 22:38:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551980761246577.9187151689417; Thu, 7 Mar 2019 09:46:01 -0800 (PST) Received: from localhost ([127.0.0.1]:56302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1x5f-0006qC-TO for importer@patchew.org; Thu, 07 Mar 2019 12:45:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqV-0002r6-DR for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqS-0007pz-3U for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:15 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:33356) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqR-0007oy-Nl for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:12 -0500 Received: by mail-wm1-x329.google.com with SMTP id c13so7231159wmb.0 for ; Thu, 07 Mar 2019 09:30:11 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=p7WyB4FGFEbHxG6zKaVRMhCl6DOMfwNsjOYCApmR5Ao=; b=PbxfdQSEk+VWFkHGQe7SPYnszAQwalFQu/dQaZcAaMO3M6ux41Dxs+7eRD8a4AaOV6 3PtjTswRoTxOM5E6OIy6s42aEEZXZzioGTs4+RnBkYQoUWaGM4r0tn/HjenzVxUVtQg2 eZX6irGfgAlNhiwxMG3DTP1OQd1dHVh7fl1uC7zbMoo0QSSY9OO3nrkwV78s4GjkG0wV JVgi0i8ISN2WQfb8+GydsjvyPRaQTwXVivR7VtKMh5dEY9MXen7lB0RiApnjn0AAPC7V RfiLjckLj18Sj0MeyHZBpUETYoxs/H5ouk/AmkXcE///hTXuPwC76lWA+nt+8L5t90ax u8XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=p7WyB4FGFEbHxG6zKaVRMhCl6DOMfwNsjOYCApmR5Ao=; b=JUGPKjUQ3EJeeYxDD4m6eiKVNO3ccjTmvqLPZGY7WKlpjsqV222J5RJPrbGd8a/GGz qenZu6tzm74fI2+9XvMOnVuS/GBjlJ9SFVZruWjnSYwnuPCofXhc3GSoWN+Yy5VqS0Cl Lno3AGYm2lzJIHUfV2G6fFbzoh7Uqe9zTm4+IlMz22U5Nf/TUhBeJV54B5sN6LRK18uS yRhi7dU+8Wal2xI5A99UlOnYLP6X7YJhgnwnJfwE3/K9VG7MGIRAOgFZHwTuqq7lp10m 1aleyxYQG/sAR3+luDcioikuufhPu3DSDoSQBvKCFvGEx0Pu9deSGyfuDlVRefVk0T25 oTmw== X-Gm-Message-State: APjAAAUUu3l2NhwjSkDJ+7kOWanC5n4Bw7qC1BvktGI1rkt0CzY+YZRB bgNq5PtsOX6JH0EVGXWJ36ec52LZ X-Google-Smtp-Source: APXvYqwNDbzfwFM1iI/oenJlH/AqBvsIW11rplr+FB2KwTb4BWdJmGbBPrUuTaSbHGXT5NkEp7tmKg== X-Received: by 2002:a7b:c932:: with SMTP id h18mr6070037wml.12.1551979809873; Thu, 07 Mar 2019 09:30:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:11 +0100 Message-Id: <1551979804-6060-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::329 Subject: [Qemu-devel] [PULL 04/57] tests/libqos: embed allocators instead of malloc-ing them separately X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, lviver@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qgraph will embed these objects instead of allocating them in a separate object. Expose a new API "generic_alloc_init" and "generic_alloc_destroy" for that, and rename the existing API with s/init/new/ and s/uninit/free/. Signed-off-by: Paolo Bonzini --- tests/ahci-test.c | 6 ++-- tests/e1000e-test.c | 22 +++++++------- tests/ide-test.c | 17 +++++------ tests/libqos/libqos-pc.c | 3 +- tests/libqos/libqos-spapr.c | 3 +- tests/libqos/libqos.c | 13 ++++---- tests/libqos/libqos.h | 11 ++++--- tests/libqos/malloc-generic.c | 21 ++----------- tests/libqos/malloc-generic.h | 7 ++--- tests/libqos/malloc-pc.c | 18 ++--------- tests/libqos/malloc-pc.h | 4 +-- tests/libqos/malloc-spapr.c | 19 ++---------- tests/libqos/malloc-spapr.h | 4 +-- tests/libqos/malloc.c | 42 ++++---------------------- tests/libqos/malloc.h | 21 +++++++++---- tests/rtas-test.c | 2 +- tests/vhost-user-test.c | 10 +++---- tests/virtio-9p-test.c | 12 ++++---- tests/virtio-blk-test.c | 69 ++++++++++++++++++++++-----------------= ---- tests/virtio-net-test.c | 10 +++---- tests/virtio-scsi-test.c | 14 ++++----- 21 files changed, 124 insertions(+), 204 deletions(-) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 5dd380e..9f07e6f 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -162,7 +162,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list = ap) s =3D g_new0(AHCIQState, 1); s->parent =3D qtest_pc_vboot(cli, ap); global_qtest =3D s->parent->qts; - alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT); + alloc_set_flags(&s->parent->alloc, ALLOC_LEAK_ASSERT); =20 /* Verify that we have an AHCI device present. */ s->dev =3D get_ahci_device(s->parent->qts, &s->fingerprint); @@ -1039,7 +1039,7 @@ static void test_dma_fragmented(void) generate_pattern(tx, bufsize, AHCI_SECTOR_SIZE); =20 /* Create a DMA buffer in guest memory, and write our pattern to it. */ - ptr =3D guest_alloc(ahci->parent->alloc, bufsize); + ptr =3D guest_alloc(&ahci->parent->alloc, bufsize); g_assert(ptr); bufwrite(ptr, tx, bufsize); =20 @@ -1059,7 +1059,7 @@ static void test_dma_fragmented(void) =20 /* Read back the guest's receive buffer into local memory */ bufread(ptr, rx, bufsize); - guest_free(ahci->parent->alloc, ptr); + guest_free(&ahci->parent->alloc, ptr); =20 g_assert_cmphex(memcmp(tx, rx, bufsize), =3D=3D, 0); =20 diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c index 5525589..17a12b8 100644 --- a/tests/e1000e-test.c +++ b/tests/e1000e-test.c @@ -94,7 +94,7 @@ typedef struct e1000e_device { } e1000e_device; =20 static int test_sockets[2]; -static QGuestAllocator *test_alloc; +static QGuestAllocator test_alloc; static QPCIBus *test_bus; =20 static void e1000e_pci_foreach_callback(QPCIDevice *dev, int devfn, void *= data) @@ -165,7 +165,7 @@ static void e1000e_device_init(QPCIBus *bus, e1000e_dev= ice *d) val | E1000E_CTRL_EXT_DRV_LOAD | E1000E_CTRL_EXT_TXLSFLOW); =20 /* Allocate and setup TX ring */ - d->tx_ring =3D guest_alloc(test_alloc, E1000E_RING_LEN); + d->tx_ring =3D guest_alloc(&test_alloc, E1000E_RING_LEN); g_assert(d->tx_ring !=3D 0); =20 e1000e_macreg_write(d, E1000E_TDBAL, (uint32_t) d->tx_ring); @@ -178,7 +178,7 @@ static void e1000e_device_init(QPCIBus *bus, e1000e_dev= ice *d) e1000e_macreg_write(d, E1000E_TCTL, E1000E_TCTL_EN); =20 /* Allocate and setup RX ring */ - d->rx_ring =3D guest_alloc(test_alloc, E1000E_RING_LEN); + d->rx_ring =3D guest_alloc(&test_alloc, E1000E_RING_LEN); g_assert(d->rx_ring !=3D 0); =20 e1000e_macreg_write(d, E1000E_RDBAL, (uint32_t)d->rx_ring); @@ -268,7 +268,7 @@ static void e1000e_send_verify(e1000e_device *d) uint32_t recv_len; =20 /* Prepare test data buffer */ - uint64_t data =3D guest_alloc(test_alloc, data_len); + uint64_t data =3D guest_alloc(&test_alloc, data_len); memwrite(data, "TEST", 5); =20 /* Prepare TX descriptor */ @@ -296,7 +296,7 @@ static void e1000e_send_verify(e1000e_device *d) g_assert_cmpstr(buffer, =3D=3D , "TEST"); =20 /* Free test data buffer */ - guest_free(test_alloc, data); + guest_free(&test_alloc, data); } =20 static void e1000e_receive_verify(e1000e_device *d) @@ -348,7 +348,7 @@ static void e1000e_receive_verify(e1000e_device *d) g_assert_cmpint(ret, =3D=3D , sizeof(test) + sizeof(len)); =20 /* Prepare test data buffer */ - uint64_t data =3D guest_alloc(test_alloc, data_len); + uint64_t data =3D guest_alloc(&test_alloc, data_len); =20 /* Prepare RX descriptor */ memset(&descr, 0, sizeof(descr)); @@ -369,7 +369,7 @@ static void e1000e_receive_verify(e1000e_device *d) g_assert_cmpstr(buffer, =3D=3D , "TEST"); =20 /* Free test data buffer */ - guest_free(test_alloc, data); + guest_free(&test_alloc, data); } =20 static void e1000e_device_clear(QPCIBus *bus, e1000e_device *d) @@ -392,10 +392,8 @@ static void data_test_init(e1000e_device *d) qtest_start(cmdline); g_free(cmdline); =20 - test_alloc =3D pc_alloc_init(global_qtest); - g_assert_nonnull(test_alloc); - - test_bus =3D qpci_new_pc(global_qtest, test_alloc); + pc_alloc_init(&test_alloc, global_qtest, 0); + test_bus =3D qpci_new_pc(global_qtest, &test_alloc); g_assert_nonnull(test_bus); =20 e1000e_device_init(test_bus, d); @@ -405,7 +403,7 @@ static void data_test_clear(e1000e_device *d) { e1000e_device_clear(test_bus, d); close(test_sockets[0]); - pc_alloc_uninit(test_alloc); + alloc_destroy(&test_alloc); g_free(d->pci_dev); qpci_free_pc(test_bus); qtest_end(); diff --git a/tests/ide-test.c b/tests/ide-test.c index 46898d9..d863a99 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -120,7 +120,7 @@ enum { #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), =3D= =3D, 0) =20 static QPCIBus *pcibus =3D NULL; -static QGuestAllocator *guest_malloc; +static QGuestAllocator guest_malloc; =20 static char tmp_path[] =3D "/tmp/qtest.XXXXXX"; static char debug_path[] =3D "/tmp/qtest-blkdebug.XXXXXX"; @@ -135,7 +135,7 @@ static void ide_test_start(const char *cmdline_fmt, ...) va_end(ap); =20 qtest_start(cmdline); - guest_malloc =3D pc_alloc_init(global_qtest); + pc_alloc_init(&guest_malloc, global_qtest, 0); =20 g_free(cmdline); } @@ -146,8 +146,7 @@ static void ide_test_quit(void) qpci_free_pc(pcibus); pcibus =3D NULL; } - pc_alloc_uninit(guest_malloc); - guest_malloc =3D NULL; + alloc_destroy(&guest_malloc); qtest_end(); } =20 @@ -246,7 +245,7 @@ static int send_dma_request(int cmd, uint64_t sector, i= nt nb_sectors, =20 /* Setup PRDT */ len =3D sizeof(*prdt) * prdt_entries; - guest_prdt =3D guest_alloc(guest_malloc, len); + guest_prdt =3D guest_alloc(&guest_malloc, len); memwrite(guest_prdt, prdt, len); qpci_io_writel(dev, bmdma_bar, bmreg_prdt, guest_prdt); =20 @@ -311,7 +310,7 @@ static void test_bmdma_simple_rw(void) uint8_t *buf; uint8_t *cmpbuf; size_t len =3D 512; - uintptr_t guest_buf =3D guest_alloc(guest_malloc, len); + uintptr_t guest_buf =3D guest_alloc(&guest_malloc, len); =20 PrdtEntry prdt[] =3D { { @@ -381,7 +380,7 @@ static void test_bmdma_trim(void) const uint64_t bad_range =3D trim_range_le(TEST_IMAGE_SIZE / 512 - 1, = 2); size_t len =3D 512; uint8_t *buf; - uintptr_t guest_buf =3D guest_alloc(guest_malloc, len); + uintptr_t guest_buf =3D guest_alloc(&guest_malloc, len); =20 PrdtEntry prdt[] =3D { { @@ -625,7 +624,7 @@ static void make_dirty(uint8_t device) =20 dev =3D get_pci_device(&bmdma_bar, &ide_bar); =20 - guest_buf =3D guest_alloc(guest_malloc, len); + guest_buf =3D guest_alloc(&guest_malloc, len); buf =3D g_malloc(len); memset(buf, rand() % 255 + 1, len); g_assert(guest_buf); @@ -986,7 +985,7 @@ static void test_cdrom_dma(void) "-device ide-cd,drive=3Dsr0,bus=3Dide.0", tmp_path); qtest_irq_intercept_in(global_qtest, "ioapic"); =20 - guest_buf =3D guest_alloc(guest_malloc, len); + guest_buf =3D guest_alloc(&guest_malloc, len); prdt[0].addr =3D cpu_to_le32(guest_buf); prdt[0].size =3D cpu_to_le32(len | PRDT_EOT); =20 diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c index 293f9b6..d04abc5 100644 --- a/tests/libqos/libqos-pc.c +++ b/tests/libqos/libqos-pc.c @@ -4,8 +4,7 @@ #include "libqos/pci-pc.h" =20 static QOSOps qos_ops =3D { - .init_allocator =3D pc_alloc_init_flags, - .uninit_allocator =3D pc_alloc_uninit, + .alloc_init =3D pc_alloc_init, .qpci_new =3D qpci_new_pc, .qpci_free =3D qpci_free_pc, .shutdown =3D qtest_pc_shutdown, diff --git a/tests/libqos/libqos-spapr.c b/tests/libqos/libqos-spapr.c index 64addfe..8766d54 100644 --- a/tests/libqos/libqos-spapr.c +++ b/tests/libqos/libqos-spapr.c @@ -4,8 +4,7 @@ #include "libqos/pci-spapr.h" =20 static QOSOps qos_ops =3D { - .init_allocator =3D spapr_alloc_init_flags, - .uninit_allocator =3D spapr_alloc_uninit, + .alloc_init =3D spapr_alloc_init, .qpci_new =3D qpci_new_spapr, .qpci_free =3D qpci_free_spapr, .shutdown =3D qtest_spapr_shutdown, diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 6c91371..636a111 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -24,8 +24,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fm= t, va_list ap) qs->qts =3D qtest_init(cmdline); qs->ops =3D ops; if (ops) { - qs->alloc =3D ops->init_allocator(qs->qts, ALLOC_NO_FLAGS); - qs->pcibus =3D ops->qpci_new(qs->qts, qs->alloc); + ops->alloc_init(&qs->alloc, qs->qts, ALLOC_NO_FLAGS); + qs->pcibus =3D ops->qpci_new(qs->qts, &qs->alloc); } =20 g_free(cmdline); @@ -58,11 +58,8 @@ void qtest_common_shutdown(QOSState *qs) qs->ops->qpci_free(qs->pcibus); qs->pcibus =3D NULL; } - if (qs->alloc && qs->ops->uninit_allocator) { - qs->ops->uninit_allocator(qs->alloc); - qs->alloc =3D NULL; - } } + alloc_destroy(&qs->alloc); qtest_quit(qs->qts); g_free(qs); } @@ -116,7 +113,7 @@ void migrate(QOSState *from, QOSState *to, const char *= uri) =20 /* If we were running, we can wait for an event. */ if (running) { - migrate_allocator(from->alloc, to->alloc); + migrate_allocator(&from->alloc, &to->alloc); set_context(to); qtest_qmp_eventwait(to->qts, "RESUME"); return; @@ -146,7 +143,7 @@ void migrate(QOSState *from, QOSState *to, const char *= uri) g_assert_not_reached(); } =20 - migrate_allocator(from->alloc, to->alloc); + migrate_allocator(&from->alloc, &to->alloc); set_context(to); } =20 diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h index 1af6035..149b0be 100644 --- a/tests/libqos/libqos.h +++ b/tests/libqos/libqos.h @@ -3,13 +3,12 @@ =20 #include "libqtest.h" #include "libqos/pci.h" -#include "libqos/malloc-pc.h" +#include "libqos/malloc.h" =20 typedef struct QOSState QOSState; =20 typedef struct QOSOps { - QGuestAllocator *(*init_allocator)(QTestState *qts, QAllocOpts); - void (*uninit_allocator)(QGuestAllocator *); + void (*alloc_init)(QGuestAllocator *, QTestState *, QAllocOpts); QPCIBus *(*qpci_new)(QTestState *qts, QGuestAllocator *alloc); void (*qpci_free)(QPCIBus *bus); void (*shutdown)(QOSState *); @@ -17,7 +16,7 @@ typedef struct QOSOps { =20 struct QOSState { QTestState *qts; - QGuestAllocator *alloc; + QGuestAllocator alloc; QPCIBus *pcibus; QOSOps *ops; }; @@ -36,12 +35,12 @@ void generate_pattern(void *buffer, size_t len, size_t = cycle_len); =20 static inline uint64_t qmalloc(QOSState *q, size_t bytes) { - return guest_alloc(q->alloc, bytes); + return guest_alloc(&q->alloc, bytes); } =20 static inline void qfree(QOSState *q, uint64_t addr) { - guest_free(q->alloc, addr); + guest_free(&q->alloc, addr); } =20 #endif diff --git a/tests/libqos/malloc-generic.c b/tests/libqos/malloc-generic.c index 33ce90b..766a308 100644 --- a/tests/libqos/malloc-generic.c +++ b/tests/libqos/malloc-generic.c @@ -15,25 +15,10 @@ * Mostly for valgrind happiness, but it does offer * a chokepoint for debugging guest memory leaks, too. */ -void generic_alloc_uninit(QGuestAllocator *allocator) +void generic_alloc_init(QGuestAllocator *s, uint64_t base_addr, + uint64_t size, uint32_t page_size) { - alloc_uninit(allocator); -} - -QGuestAllocator *generic_alloc_init_flags(uint64_t base_addr, uint64_t siz= e, - uint32_t page_size, QAllocOpts fla= gs) -{ - QGuestAllocator *s; uint64_t start =3D base_addr + (1 << 20); /* Start at 1MB */ =20 - s =3D alloc_init_flags(flags, start, start + size); - alloc_set_page_size(s, page_size); - - return s; -} - -inline QGuestAllocator *generic_alloc_init(uint64_t base_addr, uint64_t si= ze, - uint32_t page_= size) -{ - return generic_alloc_init_flags(base_addr, size, page_size, ALLOC_NO_F= LAGS); + alloc_init(s, 0, start, start + size, page_size); } diff --git a/tests/libqos/malloc-generic.h b/tests/libqos/malloc-generic.h index 90104ec..40ea058 100644 --- a/tests/libqos/malloc-generic.h +++ b/tests/libqos/malloc-generic.h @@ -12,10 +12,7 @@ =20 #include "libqos/malloc.h" =20 -QGuestAllocator *generic_alloc_init(uint64_t base_addr, uint64_t size, - uint32_t page_= size); -QGuestAllocator *generic_alloc_init_flags(uint64_t base_addr, uint64_t siz= e, - uint32_t page_size, QAllocOpts fla= gs); -void generic_alloc_uninit(QGuestAllocator *allocator); +void generic_alloc_init(QGuestAllocator *s, uint64_t base_addr, uint64_t s= ize, + uint32_t page_size); =20 #endif diff --git a/tests/libqos/malloc-pc.c b/tests/libqos/malloc-pc.c index b83cb8f..9aff807 100644 --- a/tests/libqos/malloc-pc.c +++ b/tests/libqos/malloc-pc.c @@ -24,28 +24,14 @@ * Mostly for valgrind happiness, but it does offer * a chokepoint for debugging guest memory leaks, too. */ -void pc_alloc_uninit(QGuestAllocator *allocator) +void pc_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags) { - alloc_uninit(allocator); -} - -QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags) -{ - QGuestAllocator *s; uint64_t ram_size; QFWCFG *fw_cfg =3D pc_fw_cfg_init(qts); =20 ram_size =3D qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE); - s =3D alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000)); - alloc_set_page_size(s, PAGE_SIZE); + alloc_init(s, flags, 1 << 20, MIN(ram_size, 0xE0000000), PAGE_SIZE); =20 /* clean-up */ g_free(fw_cfg); - - return s; -} - -inline QGuestAllocator *pc_alloc_init(QTestState *qts) -{ - return pc_alloc_init_flags(qts, ALLOC_NO_FLAGS); } diff --git a/tests/libqos/malloc-pc.h b/tests/libqos/malloc-pc.h index 10f3da6..21e75ae 100644 --- a/tests/libqos/malloc-pc.h +++ b/tests/libqos/malloc-pc.h @@ -15,8 +15,6 @@ =20 #include "libqos/malloc.h" =20 -QGuestAllocator *pc_alloc_init(QTestState *qts); -QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags); -void pc_alloc_uninit(QGuestAllocator *allocator); +void pc_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags); =20 #endif diff --git a/tests/libqos/malloc-spapr.c b/tests/libqos/malloc-spapr.c index 1c359ce..2a6b7e3 100644 --- a/tests/libqos/malloc-spapr.c +++ b/tests/libqos/malloc-spapr.c @@ -17,22 +17,7 @@ */ #define SPAPR_MIN_SIZE 0x10000000 =20 -void spapr_alloc_uninit(QGuestAllocator *allocator) +void spapr_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flag= s) { - alloc_uninit(allocator); -} - -QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags) -{ - QGuestAllocator *s; - - s =3D alloc_init_flags(flags, 1 << 20, SPAPR_MIN_SIZE); - alloc_set_page_size(s, PAGE_SIZE); - - return s; -} - -QGuestAllocator *spapr_alloc_init(void) -{ - return spapr_alloc_init_flags(NULL, ALLOC_NO_FLAGS); + alloc_init(s, flags, 1 << 20, SPAPR_MIN_SIZE, PAGE_SIZE); } diff --git a/tests/libqos/malloc-spapr.h b/tests/libqos/malloc-spapr.h index 52a9346..e5fe9bf 100644 --- a/tests/libqos/malloc-spapr.h +++ b/tests/libqos/malloc-spapr.h @@ -10,8 +10,6 @@ =20 #include "libqos/malloc.h" =20 -QGuestAllocator *spapr_alloc_init(void); -QGuestAllocator *spapr_alloc_init_flags(QTestState *qts, QAllocOpts flags); -void spapr_alloc_uninit(QGuestAllocator *allocator); +void spapr_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flag= s); =20 #endif diff --git a/tests/libqos/malloc.c b/tests/libqos/malloc.c index f7bae47..615422a 100644 --- a/tests/libqos/malloc.c +++ b/tests/libqos/malloc.c @@ -15,24 +15,12 @@ #include "qemu-common.h" #include "qemu/host-utils.h" =20 -typedef QTAILQ_HEAD(MemList, MemBlock) MemList; - typedef struct MemBlock { QTAILQ_ENTRY(MemBlock) MLIST_ENTNAME; uint64_t size; uint64_t addr; } MemBlock; =20 -struct QGuestAllocator { - QAllocOpts opts; - uint64_t start; - uint64_t end; - uint32_t page_size; - - MemList *used; - MemList *free; -}; - #define DEFAULT_PAGE_SIZE 4096 =20 static void mlist_delete(MemList *list, MemBlock *node) @@ -225,7 +213,7 @@ static void mlist_free(QGuestAllocator *s, uint64_t add= r) * Mostly for valgrind happiness, but it does offer * a chokepoint for debugging guest memory leaks, too. */ -void alloc_uninit(QGuestAllocator *allocator) +void alloc_destroy(QGuestAllocator *allocator) { MemBlock *node; MemBlock *tmp; @@ -261,7 +249,6 @@ void alloc_uninit(QGuestAllocator *allocator) =20 g_free(allocator->used); g_free(allocator->free); - g_free(allocator); } =20 uint64_t guest_alloc(QGuestAllocator *allocator, size_t size) @@ -297,11 +284,13 @@ void guest_free(QGuestAllocator *allocator, uint64_t = addr) } } =20 -QGuestAllocator *alloc_init(uint64_t start, uint64_t end) +void alloc_init(QGuestAllocator *s, QAllocOpts opts, + uint64_t start, uint64_t end, + size_t page_size) { - QGuestAllocator *s =3D g_malloc0(sizeof(*s)); MemBlock *node; =20 + s->opts =3D opts; s->start =3D start; s->end =3D end; =20 @@ -313,26 +302,7 @@ QGuestAllocator *alloc_init(uint64_t start, uint64_t e= nd) node =3D mlist_new(s->start, s->end - s->start); QTAILQ_INSERT_HEAD(s->free, node, MLIST_ENTNAME); =20 - s->page_size =3D DEFAULT_PAGE_SIZE; - - return s; -} - -QGuestAllocator *alloc_init_flags(QAllocOpts opts, - uint64_t start, uint64_t end) -{ - QGuestAllocator *s =3D alloc_init(start, end); - s->opts =3D opts; - return s; -} - -void alloc_set_page_size(QGuestAllocator *allocator, size_t page_size) -{ - /* Can't alter the page_size for an allocator in-use */ - g_assert(QTAILQ_EMPTY(allocator->used)); - - g_assert(is_power_of_2(page_size)); - allocator->page_size =3D page_size; + s->page_size =3D page_size; } =20 void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts) diff --git a/tests/libqos/malloc.h b/tests/libqos/malloc.h index 828fdda..4d1a2e2 100644 --- a/tests/libqos/malloc.h +++ b/tests/libqos/malloc.h @@ -23,19 +23,28 @@ typedef enum { ALLOC_PARANOID =3D 0x04 } QAllocOpts; =20 -typedef struct QGuestAllocator QGuestAllocator; +typedef QTAILQ_HEAD(MemList, MemBlock) MemList; =20 -void alloc_uninit(QGuestAllocator *allocator); +typedef struct QGuestAllocator { + QAllocOpts opts; + uint64_t start; + uint64_t end; + uint32_t page_size; + + MemList *used; + MemList *free; +} QGuestAllocator; =20 /* Always returns page aligned values */ uint64_t guest_alloc(QGuestAllocator *allocator, size_t size); void guest_free(QGuestAllocator *allocator, uint64_t addr); void migrate_allocator(QGuestAllocator *src, QGuestAllocator *dst); =20 -QGuestAllocator *alloc_init(uint64_t start, uint64_t end); -QGuestAllocator *alloc_init_flags(QAllocOpts flags, - uint64_t start, uint64_t end); -void alloc_set_page_size(QGuestAllocator *allocator, size_t page_size); void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts); =20 +void alloc_init(QGuestAllocator *alloc, QAllocOpts flags, + uint64_t start, uint64_t end, + size_t page_size); +void alloc_destroy(QGuestAllocator *allocator); + #endif diff --git a/tests/rtas-test.c b/tests/rtas-test.c index 009bda6..ee88867 100644 --- a/tests/rtas-test.c +++ b/tests/rtas-test.c @@ -17,7 +17,7 @@ static void test_rtas_get_time_of_day(void) global_qtest =3D qs->qts; =20 t1 =3D time(NULL); - ret =3D qrtas_get_time_of_day(qs->qts, qs->alloc, &tm, &ns); + ret =3D qrtas_get_time_of_day(qs->qts, &qs->alloc, &tm, &ns); g_assert_cmpint(ret, =3D=3D, 0); t2 =3D mktimegm(&tm); g_assert(t2 - t1 < 5); /* 5 sec max to run the test */ diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 611d3a7..b1414e2 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -158,7 +158,7 @@ typedef struct TestServer { bool test_fail; int test_flags; int queues; - QGuestAllocator *alloc; + QGuestAllocator alloc; } TestServer; =20 static TestServer *test_server_new(const gchar *name); @@ -206,10 +206,10 @@ static void init_virtio_dev(QTestState *qts, TestServ= er *s, uint32_t features_ma qvirtio_pci_device_enable(s->dev); qvirtio_start_device(&s->dev->vdev); =20 - s->alloc =3D pc_alloc_init(qts); + pc_alloc_init(&s->alloc, qts, 0); =20 for (i =3D 0; i < s->queues * 2; i++) { - s->vq[i] =3D qvirtqueue_setup(&s->dev->vdev, s->alloc, i); + s->vq[i] =3D qvirtqueue_setup(&s->dev->vdev, &s->alloc, i); } =20 features =3D qvirtio_get_features(&s->dev->vdev); @@ -224,9 +224,9 @@ static void uninit_virtio_dev(TestServer *s) int i; =20 for (i =3D 0; i < s->queues * 2; i++) { - qvirtqueue_cleanup(s->dev->vdev.bus, s->vq[i], s->alloc); + qvirtqueue_cleanup(s->dev->vdev.bus, s->vq[i], &s->alloc); } - pc_alloc_uninit(s->alloc); + alloc_destroy(&s->alloc); =20 qvirtio_pci_device_free(s->dev); } diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index d275c74..8fd74f6 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -67,7 +67,7 @@ static QVirtIO9P *qvirtio_9p_pci_start(void) qvirtio_pci_device_enable(dev); qvirtio_start_device(v9p->dev); =20 - v9p->vq =3D qvirtqueue_setup(v9p->dev, v9p->qs->alloc, 0); + v9p->vq =3D qvirtqueue_setup(v9p->dev, &v9p->qs->alloc, 0); =20 qvirtio_set_driver_ok(v9p->dev); =20 @@ -76,7 +76,7 @@ static QVirtIO9P *qvirtio_9p_pci_start(void) =20 static void qvirtio_9p_pci_stop(QVirtIO9P *v9p) { - qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, v9p->qs->alloc); + qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, &v9p->qs->alloc); qvirtio_pci_device_disable(container_of(v9p->dev, QVirtioPCIDevice, vd= ev)); qvirtio_pci_device_free((QVirtioPCIDevice *)v9p->dev); qvirtio_9p_stop(v9p); @@ -222,7 +222,7 @@ static P9Req *v9fs_req_init(QVirtIO9P *v9p, uint32_t si= ze, uint8_t id, =20 req->v9p =3D v9p; req->t_size =3D total_size; - req->t_msg =3D guest_alloc(v9p->qs->alloc, req->t_size); + req->t_msg =3D guest_alloc(&v9p->qs->alloc, req->t_size); v9fs_memwrite(req, &hdr, 7); req->tag =3D tag; return req; @@ -232,7 +232,7 @@ static void v9fs_req_send(P9Req *req) { QVirtIO9P *v9p =3D req->v9p; =20 - req->r_msg =3D guest_alloc(v9p->qs->alloc, P9_MAX_SIZE); + req->r_msg =3D guest_alloc(&v9p->qs->alloc, P9_MAX_SIZE); req->free_head =3D qvirtqueue_add(v9p->vq, req->t_msg, req->t_size, fa= lse, true); qvirtqueue_add(v9p->vq, req->r_msg, P9_MAX_SIZE, true, false); @@ -290,8 +290,8 @@ static void v9fs_req_free(P9Req *req) { QVirtIO9P *v9p =3D req->v9p; =20 - guest_free(v9p->qs->alloc, req->t_msg); - guest_free(v9p->qs->alloc, req->r_msg); + guest_free(&v9p->qs->alloc, req->t_msg); + guest_free(&v9p->qs->alloc, req->r_msg); g_free(req); } =20 diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 0680bd0..b449970 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -15,6 +15,7 @@ #include "libqos/virtio.h" #include "libqos/virtio-pci.h" #include "libqos/virtio-mmio.h" +#include "libqos/malloc.h" #include "libqos/malloc-generic.h" #include "qapi/qmp/qdict.h" #include "qemu/bswap.h" @@ -403,12 +404,12 @@ static void pci_basic(void) qs =3D pci_test_start(); dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT); =20 - vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); + vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); =20 - test_basic(&dev->vdev, qs->alloc, &vqpci->vq); + test_basic(&dev->vdev, &qs->alloc, &vqpci->vq); =20 /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); qtest_shutdown(qs); @@ -442,7 +443,7 @@ static void pci_indirect(void) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&dev->vdev, features); =20 - vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); + vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); qvirtio_set_driver_ok(&dev->vdev); =20 /* Write request */ @@ -452,11 +453,11 @@ static void pci_indirect(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); =20 g_free(req.data); =20 - indirect =3D qvring_indirect_desc_setup(&dev->vdev, qs->alloc, 2); + indirect =3D qvring_indirect_desc_setup(&dev->vdev, &qs->alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 528, false); qvring_indirect_desc_add(indirect, req_addr + 528, 1, true); free_head =3D qvirtqueue_add_indirect(&vqpci->vq, indirect); @@ -468,7 +469,7 @@ static void pci_indirect(void) g_assert_cmpint(status, =3D=3D, 0); =20 g_free(indirect); - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); =20 /* Read request */ req.type =3D VIRTIO_BLK_T_IN; @@ -477,11 +478,11 @@ static void pci_indirect(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); =20 g_free(req.data); =20 - indirect =3D qvring_indirect_desc_setup(&dev->vdev, qs->alloc, 2); + indirect =3D qvring_indirect_desc_setup(&dev->vdev, &qs->alloc, 2); qvring_indirect_desc_add(indirect, req_addr, 16, false); qvring_indirect_desc_add(indirect, req_addr + 16, 513, true); free_head =3D qvirtqueue_add_indirect(&vqpci->vq, indirect); @@ -498,10 +499,10 @@ static void pci_indirect(void) g_free(data); =20 g_free(indirect); - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); =20 /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); qtest_shutdown(qs); @@ -556,7 +557,7 @@ static void pci_msix(void) dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT); qpci_msix_enable(dev->pdev); =20 - qvirtio_pci_set_msix_configuration_vector(dev, qs->alloc, 0); + qvirtio_pci_set_msix_configuration_vector(dev, &qs->alloc, 0); =20 capacity =3D qvirtio_config_readq(&dev->vdev, 0); g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); @@ -568,8 +569,8 @@ static void pci_msix(void) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&dev->vdev, features); =20 - vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); - qvirtqueue_pci_msix_setup(dev, vqpci, qs->alloc, 1); + vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); + qvirtqueue_pci_msix_setup(dev, vqpci, &qs->alloc, 1); =20 qvirtio_set_driver_ok(&dev->vdev); =20 @@ -589,7 +590,7 @@ static void pci_msix(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); =20 g_free(req.data); =20 @@ -604,7 +605,7 @@ static void pci_msix(void) status =3D readb(req_addr + 528); g_assert_cmpint(status, =3D=3D, 0); =20 - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); =20 /* Read request */ req.type =3D VIRTIO_BLK_T_IN; @@ -612,7 +613,7 @@ static void pci_msix(void) req.sector =3D 0; req.data =3D g_malloc0(512); =20 - req_addr =3D virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); =20 g_free(req.data); =20 @@ -634,10 +635,10 @@ static void pci_msix(void) g_assert_cmpstr(data, =3D=3D, "TEST"); g_free(data); =20 - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); =20 /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); @@ -664,7 +665,7 @@ static void pci_idx(void) dev =3D virtio_blk_pci_init(qs->pcibus, PCI_SLOT); qpci_msix_enable(dev->pdev); =20 - qvirtio_pci_set_msix_configuration_vector(dev, qs->alloc, 0); + qvirtio_pci_set_msix_configuration_vector(dev, &qs->alloc, 0); =20 capacity =3D qvirtio_config_readq(&dev->vdev, 0); g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); @@ -676,8 +677,8 @@ static void pci_idx(void) (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&dev->vdev, features); =20 - vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); - qvirtqueue_pci_msix_setup(dev, vqpci, qs->alloc, 1); + vqpci =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); + qvirtqueue_pci_msix_setup(dev, vqpci, &qs->alloc, 1); =20 qvirtio_set_driver_ok(&dev->vdev); =20 @@ -688,7 +689,7 @@ static void pci_idx(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); =20 g_free(req.data); =20 @@ -707,7 +708,7 @@ static void pci_idx(void) req.data =3D g_malloc0(512); strcpy(req.data, "TEST"); =20 - req_addr =3D virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); =20 g_free(req.data); =20 @@ -725,7 +726,7 @@ static void pci_idx(void) QVIRTIO_BLK_TIMEOUT_US); g_assert_cmpint(status, =3D=3D, 0); =20 - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); =20 /* Read request */ req.type =3D VIRTIO_BLK_T_IN; @@ -733,7 +734,7 @@ static void pci_idx(void) req.sector =3D 1; req.data =3D g_malloc0(512); =20 - req_addr =3D virtio_blk_request(qs->alloc, &dev->vdev, &req, 512); + req_addr =3D virtio_blk_request(&qs->alloc, &dev->vdev, &req, 512); =20 g_free(req.data); =20 @@ -757,10 +758,10 @@ static void pci_idx(void) g_assert_cmpstr(data, =3D=3D, "TEST"); g_free(data); =20 - guest_free(qs->alloc, req_addr); + guest_free(&qs->alloc, req_addr); =20 /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, &qs->alloc); qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); qvirtio_pci_device_free(dev); @@ -820,7 +821,7 @@ static void mmio_basic(void) { QVirtioMMIODevice *dev; QVirtQueue *vq; - QGuestAllocator *alloc; + QGuestAllocator alloc; int n_size =3D TEST_IMAGE_SIZE / 2; uint64_t capacity; =20 @@ -832,10 +833,10 @@ static void mmio_basic(void) =20 qvirtio_start_device(&dev->vdev); =20 - alloc =3D generic_alloc_init(MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_S= IZE); - vq =3D qvirtqueue_setup(&dev->vdev, alloc, 0); + generic_alloc_init(&alloc, MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZ= E); + vq =3D qvirtqueue_setup(&dev->vdev, &alloc, 0); =20 - test_basic(&dev->vdev, alloc, vq); + test_basic(&dev->vdev, &alloc, vq); =20 qmp_discard_response("{ 'execute': 'block_resize', " " 'arguments': { 'device': 'drive0', " @@ -847,9 +848,9 @@ static void mmio_basic(void) g_assert_cmpint(capacity, =3D=3D, n_size / 512); =20 /* End test */ - qvirtqueue_cleanup(dev->vdev.bus, vq, alloc); + qvirtqueue_cleanup(dev->vdev.bus, vq, &alloc); g_free(dev); - generic_alloc_uninit(alloc); + alloc_destroy(&alloc); test_end(); } =20 diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index d4a32a4..653148e 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -228,16 +228,16 @@ static void pci_basic(gconstpointer data) "virtio-net-pci,netdev=3Dhs0", sv[1]); dev =3D virtio_net_pci_init(qs->pcibus, PCI_SLOT); =20 - rx =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0); - tx =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 1); + rx =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 0); + tx =3D (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, &qs->alloc, 1); =20 driver_init(&dev->vdev); - func(&dev->vdev, qs->alloc, &rx->vq, &tx->vq, sv[0]); + func(&dev->vdev, &qs->alloc, &rx->vq, &tx->vq, sv[0]); =20 /* End test */ close(sv[0]); - qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, qs->alloc); - qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, &qs->alloc); + qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, &qs->alloc); qvirtio_pci_device_disable(dev); g_free(dev->pdev); g_free(dev); diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 961925c..9298aa8 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -62,7 +62,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs) int i; =20 for (i =3D 0; i < vs->num_queues + 2; i++) { - qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], vs->qs->alloc); + qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], &vs->qs->alloc); } qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vde= v)); qvirtio_pci_device_free((QVirtioPCIDevice *)vs->dev); @@ -75,7 +75,7 @@ static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_= t alloc_size, { uint64_t addr; =20 - addr =3D guest_alloc(vs->qs->alloc, alloc_size); + addr =3D guest_alloc(&vs->qs->alloc, alloc_size); if (data) { memwrite(addr, data, alloc_size); } @@ -133,10 +133,10 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs= , const uint8_t *cdb, memread(resp_addr, resp_out, sizeof(*resp_out)); } =20 - guest_free(vs->qs->alloc, req_addr); - guest_free(vs->qs->alloc, resp_addr); - guest_free(vs->qs->alloc, data_in_addr); - guest_free(vs->qs->alloc, data_out_addr); + guest_free(&vs->qs->alloc, req_addr); + guest_free(&vs->qs->alloc, resp_addr); + guest_free(&vs->qs->alloc, data_in_addr); + guest_free(&vs->qs->alloc, data_out_addr); return response; } =20 @@ -166,7 +166,7 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) g_assert_cmpint(vs->num_queues, <, MAX_NUM_QUEUES); =20 for (i =3D 0; i < vs->num_queues + 2; i++) { - vs->vq[i] =3D qvirtqueue_setup(vs->dev, vs->qs->alloc, i); + vs->vq[i] =3D qvirtqueue_setup(vs->dev, &vs->qs->alloc, i); } =20 /* Clear the POWER ON OCCURRED unit attention */ --=20 1.8.3.1