qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

block: move AioContext, QEMUTimer, main-loop to libqemuutil

AioContext is fairly self contained, the only dependency is QEMUTimer but
that in turn doesn't need anything else. So move them out of block-obj-y
to avoid introducing a dependency from io/ to block-obj-y.

main-loop and its dependency iohandler also need to be moved, because
later in this series io/ will call iohandler_get_aio_context.

[Changed copyright "the QEMU team" to "other QEMU contributors" as
suggested by Daniel Berrange and agreed by Paolo.
--Stefan]

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Message-id: 20170213135235.12274-2-pbonzini@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

authored by

Paolo Bonzini and committed by
Stefan Hajnoczi
c2b38b27 56f9e46b

+114 -64
-4
Makefile.objs
··· 9 9 ####################################################################### 10 10 # block-obj-y is code used by both qemu system emulation and qemu-img 11 11 12 - block-obj-y = async.o thread-pool.o 13 12 block-obj-y += nbd/ 14 13 block-obj-y += block.o blockjob.o 15 - block-obj-y += main-loop.o iohandler.o qemu-timer.o 16 - block-obj-$(CONFIG_POSIX) += aio-posix.o 17 - block-obj-$(CONFIG_WIN32) += aio-win32.o 18 14 block-obj-y += block/ 19 15 block-obj-y += qemu-io-cmds.o 20 16 block-obj-$(CONFIG_REPLICATION) += replication.o
+1 -1
aio-posix.c util/aio-posix.c
··· 19 19 #include "qemu/rcu_queue.h" 20 20 #include "qemu/sockets.h" 21 21 #include "qemu/cutils.h" 22 - #include "trace-root.h" 22 + #include "trace.h" 23 23 #ifdef CONFIG_EPOLL_CREATE1 24 24 #include <sys/epoll.h> 25 25 #endif
aio-win32.c util/aio-win32.c
+2 -1
async.c util/async.c
··· 1 1 /* 2 - * QEMU System Emulator 2 + * Data plane event loop 3 3 * 4 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 + * Copyright (c) 2009-2017 QEMU contributors 5 6 * 6 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 8 * of this software and associated documentation files (the "Software"), to deal
-29
block/io.c
··· 2239 2239 return &acb->common; 2240 2240 } 2241 2241 2242 - void *qemu_aio_get(const AIOCBInfo *aiocb_info, BlockDriverState *bs, 2243 - BlockCompletionFunc *cb, void *opaque) 2244 - { 2245 - BlockAIOCB *acb; 2246 - 2247 - acb = g_malloc(aiocb_info->aiocb_size); 2248 - acb->aiocb_info = aiocb_info; 2249 - acb->bs = bs; 2250 - acb->cb = cb; 2251 - acb->opaque = opaque; 2252 - acb->refcnt = 1; 2253 - return acb; 2254 - } 2255 - 2256 - void qemu_aio_ref(void *p) 2257 - { 2258 - BlockAIOCB *acb = p; 2259 - acb->refcnt++; 2260 - } 2261 - 2262 - void qemu_aio_unref(void *p) 2263 - { 2264 - BlockAIOCB *acb = p; 2265 - assert(acb->refcnt > 0); 2266 - if (--acb->refcnt == 0) { 2267 - g_free(acb); 2268 - } 2269 - } 2270 - 2271 2242 /**************************************************************/ 2272 2243 /* Coroutine block device emulation */ 2273 2244
iohandler.c util/iohandler.c
main-loop.c util/main-loop.c
qemu-timer.c util/qemu-timer.c
+1
stubs/Makefile.objs
··· 16 16 stub-obj-y += iothread.o 17 17 stub-obj-y += iothread-lock.o 18 18 stub-obj-y += is-daemonized.o 19 + stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o 19 20 stub-obj-y += machine-init-done.o 20 21 stub-obj-y += migr-blocker.o 21 22 stub-obj-y += monitor.o
+32
stubs/linux-aio.c
··· 1 + /* 2 + * Linux native AIO support. 3 + * 4 + * Copyright (C) 2009 IBM, Corp. 5 + * Copyright (C) 2009 Red Hat, Inc. 6 + * 7 + * This work is licensed under the terms of the GNU GPL, version 2 or later. 8 + * See the COPYING file in the top-level directory. 9 + */ 10 + #include "qemu/osdep.h" 11 + #include "block/aio.h" 12 + #include "block/raw-aio.h" 13 + 14 + void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context) 15 + { 16 + abort(); 17 + } 18 + 19 + void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context) 20 + { 21 + abort(); 22 + } 23 + 24 + LinuxAioState *laio_init(void) 25 + { 26 + abort(); 27 + } 28 + 29 + void laio_cleanup(LinuxAioState *s) 30 + { 31 + abort(); 32 + }
-11
stubs/set-fd-handler.c
··· 9 9 { 10 10 abort(); 11 11 } 12 - 13 - void aio_set_fd_handler(AioContext *ctx, 14 - int fd, 15 - bool is_external, 16 - IOHandler *io_read, 17 - IOHandler *io_write, 18 - AioPollFn *io_poll, 19 - void *opaque) 20 - { 21 - abort(); 22 - }
+6 -5
tests/Makefile.include
··· 45 45 check-unit-y += tests/test-iov$(EXESUF) 46 46 gcov-files-test-iov-y = util/iov.c 47 47 check-unit-y += tests/test-aio$(EXESUF) 48 + gcov-files-test-aio-y = util/async.c util/qemu-timer.o 49 + gcov-files-test-aio-$(CONFIG_WIN32) += util/aio-win32.c 50 + gcov-files-test-aio-$(CONFIG_POSIX) += util/aio-posix.c 48 51 check-unit-y += tests/test-throttle$(EXESUF) 49 52 gcov-files-test-aio-$(CONFIG_WIN32) = aio-win32.c 50 53 gcov-files-test-aio-$(CONFIG_POSIX) = aio-posix.c ··· 517 520 tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y) 518 521 tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y) 519 522 520 - tests/test-char$(EXESUF): tests/test-char.o qemu-timer.o \ 521 - $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y) $(chardev-obj-y) 523 + tests/test-char$(EXESUF): tests/test-char.o $(test-util-obj-y) $(qtest-obj-y) $(test-io-obj-y) $(chardev-obj-y) 522 524 tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y) 523 525 tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) 524 526 tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y) ··· 551 553 migration/vmstate.o migration/qemu-file.o \ 552 554 migration/qemu-file-channel.o migration/qjson.o \ 553 555 $(test-io-obj-y) 554 - tests/test-timed-average$(EXESUF): tests/test-timed-average.o qemu-timer.o \ 555 - $(test-util-obj-y) 556 + tests/test-timed-average$(EXESUF): tests/test-timed-average.o $(test-util-obj-y) 556 557 tests/test-base64$(EXESUF): tests/test-base64.o \ 557 558 libqemuutil.a libqemustub.a 558 559 tests/ptimer-test$(EXESUF): tests/ptimer-test.o tests/ptimer-test-stubs.o hw/core/ptimer.o libqemustub.a ··· 712 713 tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) 713 714 tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o 714 715 tests/postcopy-test$(EXESUF): tests/postcopy-test.o 715 - tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-timer.o \ 716 + tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y) \ 716 717 $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) \ 717 718 $(chardev-obj-y) 718 719 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
+1 -1
thread-pool.c util/thread-pool.c
··· 19 19 #include "qemu/queue.h" 20 20 #include "qemu/thread.h" 21 21 #include "qemu/coroutine.h" 22 - #include "trace-root.h" 22 + #include "trace.h" 23 23 #include "block/thread-pool.h" 24 24 #include "qemu/main-loop.h" 25 25
-11
trace-events
··· 25 25 # 26 26 # The <format-string> should be a sprintf()-compatible format string. 27 27 28 - # aio-posix.c 29 - run_poll_handlers_begin(void *ctx, int64_t max_ns) "ctx %p max_ns %"PRId64 30 - run_poll_handlers_end(void *ctx, bool progress) "ctx %p progress %d" 31 - poll_shrink(void *ctx, int64_t old, int64_t new) "ctx %p old %"PRId64" new %"PRId64 32 - poll_grow(void *ctx, int64_t old, int64_t new) "ctx %p old %"PRId64" new %"PRId64 33 - 34 - # thread-pool.c 35 - thread_pool_submit(void *pool, void *req, void *opaque) "pool %p req %p opaque %p" 36 - thread_pool_complete(void *pool, void *req, void *opaque, int ret) "pool %p req %p opaque %p ret %d" 37 - thread_pool_cancel(void *req, void *opaque) "req %p opaque %p" 38 - 39 28 # ioport.c 40 29 cpu_in(unsigned int addr, char size, unsigned int val) "addr %#x(%c) value %u" 41 30 cpu_out(unsigned int addr, char size, unsigned int val) "addr %#x(%c) value %u"
+5 -1
util/Makefile.objs
··· 1 1 util-obj-y = osdep.o cutils.o unicode.o qemu-timer-common.o 2 2 util-obj-y += bufferiszero.o 3 3 util-obj-y += lockcnt.o 4 + util-obj-y += aiocb.o async.o thread-pool.o qemu-timer.o 5 + util-obj-y += main-loop.o iohandler.o 6 + util-obj-$(CONFIG_POSIX) += aio-posix.o 4 7 util-obj-$(CONFIG_POSIX) += compatfd.o 5 8 util-obj-$(CONFIG_POSIX) += event_notifier-posix.o 6 9 util-obj-$(CONFIG_POSIX) += mmap-alloc.o 7 10 util-obj-$(CONFIG_POSIX) += oslib-posix.o 8 11 util-obj-$(CONFIG_POSIX) += qemu-openpty.o 9 12 util-obj-$(CONFIG_POSIX) += qemu-thread-posix.o 13 + util-obj-$(CONFIG_POSIX) += memfd.o 14 + util-obj-$(CONFIG_WIN32) += aio-win32.o 10 15 util-obj-$(CONFIG_WIN32) += event_notifier-win32.o 11 - util-obj-$(CONFIG_POSIX) += memfd.o 12 16 util-obj-$(CONFIG_WIN32) += oslib-win32.o 13 17 util-obj-$(CONFIG_WIN32) += qemu-thread-win32.o 14 18 util-obj-y += envlist.o path.o module.o
+55
util/aiocb.c
··· 1 + /* 2 + * BlockAIOCB allocation 3 + * 4 + * Copyright (c) 2003-2017 Fabrice Bellard and other QEMU contributors 5 + * 6 + * Permission is hereby granted, free of charge, to any person obtaining a copy 7 + * of this software and associated documentation files (the "Software"), to deal 8 + * in the Software without restriction, including without limitation the rights 9 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 + * copies of the Software, and to permit persons to whom the Software is 11 + * furnished to do so, subject to the following conditions: 12 + * 13 + * The above copyright notice and this permission notice shall be included in 14 + * all copies or substantial portions of the Software. 15 + * 16 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 + * THE SOFTWARE. 23 + */ 24 + 25 + #include "qemu/osdep.h" 26 + #include "block/aio.h" 27 + 28 + void *qemu_aio_get(const AIOCBInfo *aiocb_info, BlockDriverState *bs, 29 + BlockCompletionFunc *cb, void *opaque) 30 + { 31 + BlockAIOCB *acb; 32 + 33 + acb = g_malloc(aiocb_info->aiocb_size); 34 + acb->aiocb_info = aiocb_info; 35 + acb->bs = bs; 36 + acb->cb = cb; 37 + acb->opaque = opaque; 38 + acb->refcnt = 1; 39 + return acb; 40 + } 41 + 42 + void qemu_aio_ref(void *p) 43 + { 44 + BlockAIOCB *acb = p; 45 + acb->refcnt++; 46 + } 47 + 48 + void qemu_aio_unref(void *p) 49 + { 50 + BlockAIOCB *acb = p; 51 + assert(acb->refcnt > 0); 52 + if (--acb->refcnt == 0) { 53 + g_free(acb); 54 + } 55 + }
+11
util/trace-events
··· 1 1 # See docs/tracing.txt for syntax documentation. 2 2 3 + # util/aio-posix.c 4 + run_poll_handlers_begin(void *ctx, int64_t max_ns) "ctx %p max_ns %"PRId64 5 + run_poll_handlers_end(void *ctx, bool progress) "ctx %p progress %d" 6 + poll_shrink(void *ctx, int64_t old, int64_t new) "ctx %p old %"PRId64" new %"PRId64 7 + poll_grow(void *ctx, int64_t old, int64_t new) "ctx %p old %"PRId64" new %"PRId64 8 + 9 + # util/thread-pool.c 10 + thread_pool_submit(void *pool, void *req, void *opaque) "pool %p req %p opaque %p" 11 + thread_pool_complete(void *pool, void *req, void *opaque, int ret) "pool %p req %p opaque %p ret %d" 12 + thread_pool_cancel(void *req, void *opaque) "req %p opaque %p" 13 + 3 14 # util/buffer.c 4 15 buffer_resize(const char *buf, size_t olen, size_t len) "%s: old %zd, new %zd" 5 16 buffer_move_empty(const char *buf, size_t len, const char *from) "%s: %zd bytes from %s"