diff options
43 files changed, 886 insertions, 283 deletions
diff --git a/.cirrus.yml b/.cirrus.yml index 3907e036da..bc40a0550d 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -64,23 +64,61 @@ windows_msys2_task: CIRRUS_SHELL: powershell MSYS: winsymlinks:nativestrict MSYSTEM: MINGW64 + MSYS2_URL: https://github.com/msys2/msys2-installer/releases/download/2021-01-05/msys2-base-x86_64-20210105.sfx.exe + MSYS2_FINGERPRINT: 0 + MSYS2_PACKAGES: " + diffutils git grep make pkg-config sed + mingw-w64-x86_64-python + mingw-w64-x86_64-python-sphinx + mingw-w64-x86_64-toolchain + mingw-w64-x86_64-SDL2 + mingw-w64-x86_64-SDL2_image + mingw-w64-x86_64-gtk3 + mingw-w64-x86_64-glib2 + mingw-w64-x86_64-ninja + mingw-w64-x86_64-jemalloc + mingw-w64-x86_64-lzo2 + mingw-w64-x86_64-zstd + mingw-w64-x86_64-libjpeg-turbo + mingw-w64-x86_64-pixman + mingw-w64-x86_64-libgcrypt + mingw-w64-x86_64-libpng + mingw-w64-x86_64-libssh + mingw-w64-x86_64-libxml2 + mingw-w64-x86_64-snappy + mingw-w64-x86_64-libusb + mingw-w64-x86_64-usbredir + mingw-w64-x86_64-libtasn1 + mingw-w64-x86_64-nettle + mingw-w64-x86_64-cyrus-sasl + mingw-w64-x86_64-curl + mingw-w64-x86_64-gnutls + mingw-w64-x86_64-libnfs + " CHERE_INVOKING: 1 - setup_script: - - choco install -y --no-progress 7zip - - Write-Output $env:PATH msys2_cache: folder: C:\tools\archive reupload_on_changes: false - fingerprint_script: cat .cirrus.yml + # These env variables are used to generate fingerprint to trigger the cache procedure + # If wanna to force re-populate msys2, increase MSYS2_FINGERPRINT + fingerprint_script: + - | + echo $env:CIRRUS_TASK_NAME + echo $env:MSYS2_URL + echo $env:MSYS2_FINGERPRINT + echo $env:MSYS2_PACKAGES populate_script: - | - md C:\tools - md C:\tools\archive + md -Force C:\tools\archive\pkg $start_time = Get-Date + bitsadmin /transfer msys_download /dynamic /download /priority FOREGROUND $env:MSYS2_URL C:\tools\archive\base.exe + Write-Output "Download time taken: $((Get-Date).Subtract($start_time))" cd C:\tools - bitsadmin /transfer msys_download /dynamic /download /priority FOREGROUND https://github.com/msys2/msys2-installer/releases/download/2020-09-03/msys2-base-x86_64-20200903.sfx.exe C:\tools\base.exe - Write-Output "Download time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)" - C:\tools\base.exe -y + C:\tools\archive\base.exe -y + del -Force C:\tools\archive\base.exe + Write-Output "Base install time taken: $((Get-Date).Subtract($start_time))" + $start_time = Get-Date + ((Get-Content -path C:\tools\msys64\etc\\post-install\\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path C:\tools\msys64\etc\\post-install\\07-pacman-key.post C:\tools\msys64\usr\bin\bash.exe -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf" C:\tools\msys64\usr\bin\bash.exe -lc "export" @@ -90,52 +128,35 @@ windows_msys2_task: tasklist C:\tools\msys64\usr\bin\bash.exe -lc "mv -f /etc/pacman.conf.pacnew /etc/pacman.conf || true" C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Suu --overwrite=*" - C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -S --needed \ - diffutils git grep make pkg-config sed \ - mingw-w64-x86_64-python \ - mingw-w64-x86_64-toolchain \ - mingw-w64-x86_64-SDL2 \ - mingw-w64-x86_64-SDL2_image \ - mingw-w64-x86_64-gtk3 \ - mingw-w64-x86_64-glib2 \ - mingw-w64-x86_64-ninja \ - mingw-w64-x86_64-jemalloc \ - mingw-w64-x86_64-lzo2 \ - mingw-w64-x86_64-zstd \ - mingw-w64-x86_64-libjpeg-turbo \ - mingw-w64-x86_64-pixman \ - mingw-w64-x86_64-libgcrypt \ - mingw-w64-x86_64-libpng \ - mingw-w64-x86_64-libssh \ - mingw-w64-x86_64-libxml2 \ - mingw-w64-x86_64-snappy \ - mingw-w64-x86_64-libusb \ - mingw-w64-x86_64-usbredir \ - mingw-w64-x86_64-libtasn1 \ - mingw-w64-x86_64-nettle \ - mingw-w64-x86_64-cyrus-sasl \ - mingw-w64-x86_64-curl \ - mingw-w64-x86_64-gnutls \ - mingw-w64-x86_64-libnfs \ - " - bitsadmin /transfer msys_download /dynamic /download /priority FOREGROUND ` - https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz ` - C:\tools\mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz - C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -U /c/tools/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz" - del C:\tools\mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz - C:\tools\msys64\usr\bin\bash.exe -lc "rm -rf /var/cache/pacman/pkg/*" - cd C:\tools\msys64 - echo "Start archive" - cmd /C "7z a -ttar . -so | 7z a -txz -simsys2-x86_64.tar C:\tools\archive\msys2-x86_64.tar.xz" + Write-Output "Core install time taken: $((Get-Date).Subtract($start_time))" + $start_time = Get-Date + + C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -S --needed $env:MSYS2_PACKAGES" + Write-Output "Package install time taken: $((Get-Date).Subtract($start_time))" + $start_time = Get-Date + + del -Force -ErrorAction SilentlyContinue C:\tools\msys64\etc\mtab + del -Force -ErrorAction SilentlyContinue C:\tools\msys64\dev\fd + del -Force -ErrorAction SilentlyContinue C:\tools\msys64\dev\stderr + del -Force -ErrorAction SilentlyContinue C:\tools\msys64\dev\stdin + del -Force -ErrorAction SilentlyContinue C:\tools\msys64\dev\stdout + del -Force -Recurse -ErrorAction SilentlyContinue C:\tools\msys64\var\cache\pacman\pkg + tar cf C:\tools\archive\msys64.tar -C C:\tools\ msys64 + + Write-Output "Package archive time taken: $((Get-Date).Subtract($start_time))" + del -Force -Recurse -ErrorAction SilentlyContinue c:\tools\msys64 install_script: - | + $start_time = Get-Date cd C:\tools - cmd /C "7z x C:\tools\archive\msys2-x86_64.tar.xz -so | 7z x -aoa -simsys2-x86_64.tar -ttar -omsys64" - C:\tools\msys64\usr\bin\bash.exe -lc "export" - + ls C:\tools\archive\msys64.tar + tar xf C:\tools\archive\msys64.tar + Write-Output "Extract msys2 time taken: $((Get-Date).Subtract($start_time))" script: - C:\tools\msys64\usr\bin\bash.exe -lc "mkdir build" - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && ../configure --python=python3" - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && make -j8" + - exit $LastExitCode test_script: - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && make V=1 check" + - exit $LastExitCode diff --git a/MAINTAINERS b/MAINTAINERS index 4be087b88e..cb0656aec3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2732,6 +2732,13 @@ F: util/uuid.c F: include/qemu/uuid.h F: tests/test-uuid.c +Yank feature +M: Lukas Straub <lukasstraub2@web.de> +S: Odd fixes +F: util/yank.c +F: include/qemu/yank.h +F: qapi/yank.json + COLO Framework M: zhanghailiang <zhang.zhanghailiang@huawei.com> S: Maintained @@ -3198,6 +3205,12 @@ S: Maintained F: .cirrus.yml W: https://cirrus-ci.com/github/qemu/qemu +Windows Hosted Continuous Integration +M: Yonggang Luo <luoyonggang@gmail.com> +S: Maintained +F: .cirrus.yml +W: https://cirrus-ci.com/github/qemu/qemu + GitLab Continuous Integration M: Thomas Huth <thuth@redhat.com> M: Philippe Mathieu-Daudé <philmd@redhat.com> diff --git a/block/meson.build b/block/meson.build index d44c92ab04..eeaefe5809 100644 --- a/block/meson.build +++ b/block/meson.build @@ -40,7 +40,7 @@ block_ss.add(files( 'vmdk.c', 'vpc.c', 'write-threshold.c', -), zstd, zlib) +), zstd, zlib, gnutls) softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('blkreplay.c')) diff --git a/block/nbd.c b/block/nbd.c index 242a258f3a..42e10c7c93 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -35,6 +35,7 @@ #include "qemu/option.h" #include "qemu/cutils.h" #include "qemu/main-loop.h" +#include "qemu/atomic.h" #include "qapi/qapi-visit-sockets.h" #include "qapi/qmp/qstring.h" @@ -44,6 +45,8 @@ #include "block/nbd.h" #include "block/block_int.h" +#include "qemu/yank.h" + #define EN_OPTSTR ":exportname=" #define MAX_NBD_REQUESTS 16 @@ -141,14 +144,13 @@ typedef struct BDRVNBDState { NBDConnectThread *connect_thread; } BDRVNBDState; -static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr, - Error **errp); -static QIOChannelSocket *nbd_co_establish_connection(BlockDriverState *bs, - Error **errp); +static int nbd_establish_connection(BlockDriverState *bs, SocketAddress *saddr, + Error **errp); +static int nbd_co_establish_connection(BlockDriverState *bs, Error **errp); static void nbd_co_establish_connection_cancel(BlockDriverState *bs, bool detach); -static int nbd_client_handshake(BlockDriverState *bs, QIOChannelSocket *sioc, - Error **errp); +static int nbd_client_handshake(BlockDriverState *bs, Error **errp); +static void nbd_yank(void *opaque); static void nbd_clear_bdrvstate(BDRVNBDState *s) { @@ -166,12 +168,12 @@ static void nbd_clear_bdrvstate(BDRVNBDState *s) static void nbd_channel_error(BDRVNBDState *s, int ret) { if (ret == -EIO) { - if (s->state == NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) { s->state = s->reconnect_delay ? NBD_CLIENT_CONNECTING_WAIT : NBD_CLIENT_CONNECTING_NOWAIT; } } else { - if (s->state == NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) { qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); } s->state = NBD_CLIENT_QUIT; @@ -203,7 +205,7 @@ static void reconnect_delay_timer_cb(void *opaque) { BDRVNBDState *s = opaque; - if (s->state == NBD_CLIENT_CONNECTING_WAIT) { + if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT) { s->state = NBD_CLIENT_CONNECTING_NOWAIT; while (qemu_co_enter_next(&s->free_sema, NULL)) { /* Resume all queued requests */ @@ -215,7 +217,7 @@ static void reconnect_delay_timer_cb(void *opaque) static void reconnect_delay_timer_init(BDRVNBDState *s, uint64_t expire_time_ns) { - if (s->state != NBD_CLIENT_CONNECTING_WAIT) { + if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTING_WAIT) { return; } @@ -260,7 +262,7 @@ static void nbd_client_attach_aio_context(BlockDriverState *bs, * s->connection_co is either yielded from nbd_receive_reply or from * nbd_co_reconnect_loop() */ - if (s->state == NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) { qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), new_context); } @@ -286,7 +288,7 @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs) reconnect_delay_timer_del(s); - if (s->state == NBD_CLIENT_CONNECTING_WAIT) { + if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT) { s->state = NBD_CLIENT_CONNECTING_NOWAIT; qemu_co_queue_restart_all(&s->free_sema); } @@ -337,13 +339,14 @@ static void nbd_teardown_connection(BlockDriverState *bs) static bool nbd_client_connecting(BDRVNBDState *s) { - return s->state == NBD_CLIENT_CONNECTING_WAIT || - s->state == NBD_CLIENT_CONNECTING_NOWAIT; + NBDClientState state = qatomic_load_acquire(&s->state); + return state == NBD_CLIENT_CONNECTING_WAIT || + state == NBD_CLIENT_CONNECTING_NOWAIT; } static bool nbd_client_connecting_wait(BDRVNBDState *s) { - return s->state == NBD_CLIENT_CONNECTING_WAIT; + return qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT; } static void connect_bh(void *opaque) @@ -423,12 +426,12 @@ static void *connect_thread_func(void *opaque) return NULL; } -static QIOChannelSocket *coroutine_fn +static int coroutine_fn nbd_co_establish_connection(BlockDriverState *bs, Error **errp) { + int ret; QemuThread thread; BDRVNBDState *s = bs->opaque; - QIOChannelSocket *res; NBDConnectThread *thr = s->connect_thread; qemu_mutex_lock(&thr->mutex); @@ -445,10 +448,12 @@ nbd_co_establish_connection(BlockDriverState *bs, Error **errp) case CONNECT_THREAD_SUCCESS: /* Previous attempt finally succeeded in background */ thr->state = CONNECT_THREAD_NONE; - res = thr->sioc; + s->sioc = thr->sioc; thr->sioc = NULL; + yank_register_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), + nbd_yank, bs); qemu_mutex_unlock(&thr->mutex); - return res; + return 0; case CONNECT_THREAD_RUNNING: /* Already running, will wait */ break; @@ -480,8 +485,13 @@ nbd_co_establish_connection(BlockDriverState *bs, Error **errp) thr->state = CONNECT_THREAD_NONE; error_propagate(errp, thr->err); thr->err = NULL; - res = thr->sioc; + s->sioc = thr->sioc; thr->sioc = NULL; + if (s->sioc) { + yank_register_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), + nbd_yank, bs); + } + ret = (s->sioc ? 0 : -1); break; case CONNECT_THREAD_RUNNING: case CONNECT_THREAD_RUNNING_DETACHED: @@ -490,7 +500,7 @@ nbd_co_establish_connection(BlockDriverState *bs, Error **errp) * failed. Still connect thread is executing in background, and its * result may be used for next connection attempt. */ - res = NULL; + ret = -1; error_setg(errp, "Connection attempt cancelled by other operation"); break; @@ -507,7 +517,7 @@ nbd_co_establish_connection(BlockDriverState *bs, Error **errp) qemu_mutex_unlock(&thr->mutex); - return res; + return ret; } /* @@ -560,7 +570,6 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) { int ret; Error *local_err = NULL; - QIOChannelSocket *sioc; if (!nbd_client_connecting(s)) { return; @@ -593,21 +602,22 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) /* Finalize previous connection if any */ if (s->ioc) { qio_channel_detach_aio_context(QIO_CHANNEL(s->ioc)); + yank_unregister_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), + nbd_yank, s->bs); object_unref(OBJECT(s->sioc)); s->sioc = NULL; object_unref(OBJECT(s->ioc)); s->ioc = NULL; } - sioc = nbd_co_establish_connection(s->bs, &local_err); - if (!sioc) { + if (nbd_co_establish_connection(s->bs, &local_err) < 0) { ret = -ECONNREFUSED; goto out; } bdrv_dec_in_flight(s->bs); - ret = nbd_client_handshake(s->bs, sioc, &local_err); + ret = nbd_client_handshake(s->bs, &local_err); if (s->drained) { s->wait_drained_end = true; @@ -639,7 +649,7 @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s) uint64_t timeout = 1 * NANOSECONDS_PER_SECOND; uint64_t max_timeout = 16 * NANOSECONDS_PER_SECOND; - if (s->state == NBD_CLIENT_CONNECTING_WAIT) { + if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT) { reconnect_delay_timer_init(s, qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + s->reconnect_delay * NANOSECONDS_PER_SECOND); } @@ -682,7 +692,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque) int ret = 0; Error *local_err = NULL; - while (s->state != NBD_CLIENT_QUIT) { + while (qatomic_load_acquire(&s->state) != NBD_CLIENT_QUIT) { /* * The NBD client can only really be considered idle when it has * yielded from qio_channel_readv_all_eof(), waiting for data. This is @@ -697,7 +707,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque) nbd_co_reconnect_loop(s); } - if (s->state != NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) { continue; } @@ -752,6 +762,8 @@ static coroutine_fn void nbd_connection_entry(void *opaque) s->connection_co = NULL; if (s->ioc) { qio_channel_detach_aio_context(QIO_CHANNEL(s->ioc)); + yank_unregister_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), + nbd_yank, s->bs); object_unref(OBJECT(s->sioc)); s->sioc = NULL; object_unref(OBJECT(s->ioc)); @@ -776,7 +788,7 @@ static int nbd_co_send_request(BlockDriverState *bs, qemu_co_queue_wait(&s->free_sema, &s->send_mutex); } - if (s->state != NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) { rc = -EIO; goto err; } @@ -803,7 +815,8 @@ static int nbd_co_send_request(BlockDriverState *bs, if (qiov) { qio_channel_set_cork(s->ioc, true); rc = nbd_send_request(s->ioc, request); - if (rc >= 0 && s->state == NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED && + rc >= 0) { if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { rc = -EIO; @@ -1128,7 +1141,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( s->requests[i].receiving = true; qemu_coroutine_yield(); s->requests[i].receiving = false; - if (s->state != NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) { error_setg(errp, "Connection closed"); return -EIO; } @@ -1287,7 +1300,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s, NBDReply local_reply; NBDStructuredReplyChunk *chunk; Error *local_err = NULL; - if (s->state != NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) { error_setg(&local_err, "Connection closed"); nbd_iter_channel_error(iter, -EIO, &local_err); goto break_loop; @@ -1312,7 +1325,8 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s, } /* Do not execute the body of NBD_FOREACH_REPLY_CHUNK for simple reply. */ - if (nbd_reply_is_simple(reply) || s->state != NBD_CLIENT_CONNECTED) { + if (nbd_reply_is_simple(reply) || + qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) { goto break_loop; } @@ -1744,6 +1758,15 @@ static int nbd_client_reopen_prepare(BDRVReopenState *state, return 0; } +static void nbd_yank(void *opaque) +{ + BlockDriverState *bs = opaque; + BDRVNBDState *s = (BDRVNBDState *)bs->opaque; + + qatomic_store_release(&s->state, NBD_CLIENT_QUIT); + qio_channel_shutdown(QIO_CHANNEL(s->sioc), QIO_CHANNEL_SHUTDOWN_BOTH, NULL); +} + static void nbd_client_close(BlockDriverState *bs) { BDRVNBDState *s = (BDRVNBDState *)bs->opaque; @@ -1756,52 +1779,53 @@ static void nbd_client_close(BlockDriverState *bs) nbd_teardown_connection(bs); } -static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr, - Error **errp) +static int nbd_establish_connection(BlockDriverState *bs, + SocketAddress *saddr, + Error **errp) { ERRP_GUARD(); - QIOChannelSocket *sioc; + BDRVNBDState *s = (BDRVNBDState *)bs->opaque; - sioc = qio_channel_socket_new(); - qio_channel_set_name(QIO_CHANNEL(sioc), "nbd-client"); + s->sioc = qio_channel_socket_new(); + qio_channel_set_name(QIO_CHANNEL(s->sioc), "nbd-client"); - qio_channel_socket_connect_sync(sioc, saddr, errp); + qio_channel_socket_connect_sync(s->sioc, saddr, errp); if (*errp) { - object_unref(OBJECT(sioc)); - return NULL; + object_unref(OBJECT(s->sioc)); + s->sioc = NULL; + return -1; } - qio_channel_set_delay(QIO_CHANNEL(sioc), false); + yank_register_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), nbd_yank, bs); + qio_channel_set_delay(QIO_CHANNEL(s->sioc), false); - return sioc; + return 0; } -/* nbd_client_handshake takes ownership on sioc. On failure it is unref'ed. */ -static int nbd_client_handshake(BlockDriverState *bs, QIOChannelSocket *sioc, - Error **errp) +/* nbd_client_handshake takes ownership on s->sioc. On failure it's unref'ed. */ +static int nbd_client_handshake(BlockDriverState *bs, Error **errp) { BDRVNBDState *s = (BDRVNBDState *)bs->opaque; AioContext *aio_context = bdrv_get_aio_context(bs); int ret; trace_nbd_client_handshake(s->export); - - s->sioc = sioc; - - qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); - qio_channel_attach_aio_context(QIO_CHANNEL(sioc), aio_context); + qio_channel_set_blocking(QIO_CHANNEL(s->sioc), false, NULL); + qio_channel_attach_aio_context(QIO_CHANNEL(s->sioc), aio_context); s->info.request_sizes = true; s->info.structured_reply = true; s->info.base_allocation = true; s->info.x_dirty_bitmap = g_strdup(s->x_dirty_bitmap); s->info.name = g_strdup(s->export ?: ""); - ret = nbd_receive_negotiate(aio_context, QIO_CHANNEL(sioc), s->tlscreds, + ret = nbd_receive_negotiate(aio_context, QIO_CHANNEL(s->sioc), s->tlscreds, s->hostname, &s->ioc, &s->info, errp); g_free(s->info.x_dirty_bitmap); g_free(s->info.name); if (ret < 0) { - object_unref(OBJECT(sioc)); + yank_unregister_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), + nbd_yank, bs); + object_unref(OBJECT(s->sioc)); s->sioc = NULL; return ret; } @@ -1834,7 +1858,7 @@ static int nbd_client_handshake(BlockDriverState *bs, QIOChannelSocket *sioc, } if (!s->ioc) { - s->ioc = QIO_CHANNEL(sioc); + s->ioc = QIO_CHANNEL(s->sioc); object_ref(OBJECT(s->ioc)); } @@ -1850,9 +1874,11 @@ static int nbd_client_handshake(BlockDriverState *bs, QIOChannelSocket *sioc, { NBDRequest request = { .type = NBD_CMD_DISC }; - nbd_send_request(s->ioc ?: QIO_CHANNEL(sioc), &request); + nbd_send_request(s->ioc ?: QIO_CHANNEL(s->sioc), &request); - object_unref(OBJECT(sioc)); + yank_unregister_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), + nbd_yank, bs); + object_unref(OBJECT(s->sioc)); s->sioc = NULL; return ret; @@ -2244,7 +2270,6 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, { int ret; BDRVNBDState *s = (BDRVNBDState *)bs->opaque; - QIOChannelSocket *sioc; ret = nbd_process_options(bs, options, errp); if (ret < 0) { @@ -2255,17 +2280,22 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, qemu_co_mutex_init(&s->send_mutex); qemu_co_queue_init(&s->free_sema); + if (!yank_register_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name), errp)) { + return -EEXIST; + } + /* * establish TCP connection, return error if it fails * TODO: Configurable retry-until-timeout behaviour. */ - sioc = nbd_establish_connection(s->saddr, errp); - if (!sioc) { + if (nbd_establish_connection(bs, s->saddr, errp) < 0) { + yank_unregister_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name)); return -ECONNREFUSED; } - ret = nbd_client_handshake(bs, sioc, errp); + ret = nbd_client_handshake(bs, errp); if (ret < 0) { + yank_unregister_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name)); nbd_clear_bdrvstate(s); return ret; } @@ -2325,6 +2355,7 @@ static void nbd_close(BlockDriverState *bs) BDRVNBDState *s = bs->opaque; nbd_client_close(bs); + yank_unregister_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name)); nbd_clear_bdrvstate(s); } diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 213a4c8dd0..8a707d766c 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -34,6 +34,7 @@ #include "qapi/error.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-visit-sockets.h" +#include "qemu/yank.h" #include "chardev/char-io.h" #include "qom/object.h" @@ -70,6 +71,7 @@ struct SocketChardev { size_t read_msgfds_num; int *write_msgfds; size_t write_msgfds_num; + bool registered_yank; SocketAddress *addr; bool is_listen; @@ -415,6 +417,12 @@ static void tcp_chr_free_connection(Chardev *chr) tcp_set_msgfds(chr, NULL, 0); remove_fd_in_watch(chr); + if (s->state == TCP_CHARDEV_STATE_CONNECTING + || s->state == TCP_CHARDEV_STATE_CONNECTED) { + yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label), + yank_generic_iochannel, + QIO_CHANNEL(s->sioc)); + } object_unref(OBJECT(s->sioc)); s->sioc = NULL; object_unref(OBJECT(s->ioc)); @@ -932,6 +940,9 @@ static int tcp_chr_add_client(Chardev *chr, int fd) } tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING); tcp_chr_set_client_ioc_name(chr, sioc); + yank_register_function(CHARDEV_YANK_INSTANCE(chr->label), + yank_generic_iochannel, + QIO_CHANNEL(sioc)); ret = tcp_chr_new_client(chr, sioc); object_unref(OBJECT(sioc)); return ret; @@ -946,6 +957,9 @@ static void tcp_chr_accept(QIONetListener *listener, tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING); tcp_chr_set_client_ioc_name(chr, cioc); + yank_register_function(CHARDEV_YANK_INSTANCE(chr->label), + yank_generic_iochannel, + QIO_CHANNEL(cioc)); tcp_chr_new_client(chr, cioc); } @@ -961,6 +975,9 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp) object_unref(OBJECT(sioc)); return -1; } + yank_register_function(CHARDEV_YANK_INSTANCE(chr->label), + yank_generic_iochannel, + QIO_CHANNEL(sioc)); tcp_chr_new_client(chr, sioc); object_unref(OBJECT(sioc)); return 0; @@ -976,6 +993,9 @@ static void tcp_chr_accept_server_sync(Chardev *chr) tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING); sioc = qio_net_listener_wait_client(s->listener); tcp_chr_set_client_ioc_name(chr, sioc); + yank_register_function(CHARDEV_YANK_INSTANCE(chr->label), + yank_generic_iochannel, + QIO_CHANNEL(sioc)); tcp_chr_new_client(chr, sioc); object_unref(OBJECT(sioc)); } @@ -1086,6 +1106,9 @@ static void char_socket_finalize(Object *obj) object_unref(OBJECT(s->tls_creds)); } g_free(s->tls_authz); + if (s->registered_yank) { + yank_unregister_instance(CHARDEV_YANK_INSTANCE(chr->label)); + } qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } @@ -1101,6 +1124,9 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque) if (qio_task_propagate_error(task, &err)) { tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED); + yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label), + yank_generic_iochannel, + QIO_CHANNEL(sioc)); check_report_connect_error(chr, err); goto cleanup; } @@ -1134,6 +1160,9 @@ static void tcp_chr_connect_client_async(Chardev *chr) tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING); sioc = qio_channel_socket_new(); tcp_chr_set_client_ioc_name(chr, sioc); + yank_register_function(CHARDEV_YANK_INSTANCE(chr->label), + yank_generic_iochannel, + QIO_CHANNEL(sioc)); /* * Normally code would use the qio_channel_socket_connect_async * method which uses a QIOTask + qio_task_set_error internally @@ -1376,6 +1405,11 @@ static void qmp_chardev_open_socket(Chardev *chr, qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS); } + if (!yank_register_instance(CHARDEV_YANK_INSTANCE(chr->label), errp)) { + return; + } + s->registered_yank = true; + /* be isn't opened until we get a connection */ *be_opened = false; diff --git a/configure b/configure index 5860bdb77b..155dda124c 100755 --- a/configure +++ b/configure @@ -89,6 +89,10 @@ printf " '%s'" "$0" "$@" >> config.log echo >> config.log echo "#" >> config.log +quote_sh() { + printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&'," +} + print_error() { (echo echo "ERROR: $1" @@ -414,8 +418,7 @@ cfi="false" cfi_debug="false" seccomp="auto" glusterfs="auto" -gtk="$default_feature" -gtk_gl="no" +gtk="auto" tls_priority="NORMAL" gnutls="$default_feature" nettle="$default_feature" @@ -773,7 +776,6 @@ Darwin) QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS" QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS" fi - cocoa="enabled" audio_drv_list="coreaudio try-sdl" audio_possible_drivers="coreaudio sdl" QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS" @@ -1149,9 +1151,7 @@ for opt do ;; --disable-cocoa) cocoa="disabled" ;; - --enable-cocoa) - cocoa="enabled" ; - audio_drv_list="coreaudio $(echo $audio_drv_list | sed s,coreaudio,,g)" + --enable-cocoa) cocoa="enabled" ;; --disable-system) softmmu="no" ;; @@ -1380,9 +1380,9 @@ for opt do --enable-uuid|--disable-uuid) echo "$0: $opt is obsolete, UUID support is always built" >&2 ;; - --disable-gtk) gtk="no" + --disable-gtk) gtk="disabled" ;; - --enable-gtk) gtk="yes" + --enable-gtk) gtk="enabled" ;; --tls-priority=*) tls_priority="$optarg" ;; @@ -2325,20 +2325,6 @@ if test -z "$want_tools"; then fi ########################################## -# cocoa implies not SDL or GTK -# (the cocoa UI code currently assumes it is always the active UI -# and doesn't interact well with other UI frontend code) -if test "$cocoa" = "enabled"; then - if test "$sdl" = "enabled"; then - error_exit "Cocoa and SDL UIs cannot both be enabled at once" - fi - if test "$gtk" = "yes"; then - error_exit "Cocoa and GTK UIs cannot both be enabled at once" - fi - gtk=no - sdl=disabled -fi - # Some versions of Mac OS X incorrectly define SIZE_MAX cat > $TMPC << EOF #include <stdint.h> @@ -2763,39 +2749,6 @@ EOF fi ########################################## -# X11 probe -if $pkg_config --exists "x11"; then - have_x11=yes - x11_cflags=$($pkg_config --cflags x11) - x11_libs=$($pkg_config --libs x11) -fi - -########################################## -# GTK probe - -if test "$gtk" != "no"; then - gtkpackage="gtk+-3.0" - gtkx11package="gtk+-x11-3.0" - gtkversion="3.22.0" - if $pkg_config --exists "$gtkpackage >= $gtkversion"; then - gtk_cflags=$($pkg_config --cflags $gtkpackage) - gtk_libs=$($pkg_config --libs $gtkpackage) - gtk_version=$($pkg_config --modversion $gtkpackage) - if $pkg_config --exists "$gtkx11package >= $gtkversion"; then - need_x11=yes - gtk_cflags="$gtk_cflags $x11_cflags" - gtk_libs="$gtk_libs $x11_libs" - fi - gtk="yes" - elif test "$gtk" = "yes"; then - feature_not_found "gtk" "Install gtk3-devel" - else - gtk="no" - fi -fi - - -########################################## # GNUTLS probe if test "$gnutls" != "no"; then @@ -3628,9 +3581,6 @@ if test "$opengl" != "no" ; then opengl_cflags="$($pkg_config --cflags $opengl_pkgs)" opengl_libs="$($pkg_config --libs $opengl_pkgs)" opengl=yes - if test "$gtk" = "yes" && $pkg_config --exists "$gtkpackage >= 3.16"; then - gtk_gl="yes" - fi else if test "$opengl" = "yes" ; then feature_not_found "opengl" "Please install opengl (mesa) devel pkgs: $opengl_pkgs" @@ -3654,16 +3604,6 @@ EOF fi fi -if test "$opengl" = "yes" && test "$have_x11" = "yes"; then - for target in $target_list; do - case $target in - lm32-softmmu) # milkymist-tmu2 requires X11 and OpenGL - need_x11=yes - ;; - esac - done -fi - ########################################## # libxml2 probe if test "$libxml2" != "no" ; then @@ -5687,11 +5627,6 @@ fi if test "$module_upgrades" = "yes"; then echo "CONFIG_MODULE_UPGRADES=y" >> $config_host_mak fi -if test "$have_x11" = "yes" && test "$need_x11" = "yes"; then - echo "CONFIG_X11=y" >> $config_host_mak - echo "X11_CFLAGS=$x11_cflags" >> $config_host_mak - echo "X11_LIBS=$x11_libs" >> $config_host_mak -fi if test "$pipe2" = "yes" ; then echo "CONFIG_PIPE2=y" >> $config_host_mak fi @@ -5779,14 +5714,6 @@ fi if test "$bswap_h" = "yes" ; then echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak fi -if test "$gtk" = "yes" ; then - echo "CONFIG_GTK=y" >> $config_host_mak - echo "GTK_CFLAGS=$gtk_cflags" >> $config_host_mak - echo "GTK_LIBS=$gtk_libs" >> $config_host_mak - if test "$gtk_gl" = "yes" ; then - echo "CONFIG_GTK_GL=y" >> $config_host_mak - fi -fi if test "$gio" = "yes" ; then echo "CONFIG_GIO=y" >> $config_host_mak echo "GIO_CFLAGS=$gio_cflags" >> $config_host_mak @@ -6520,7 +6447,7 @@ NINJA=$ninja $meson setup \ -Dmalloc=$malloc -Dmalloc_trim=$malloc_trim -Dsparse=$sparse \ -Dkvm=$kvm -Dhax=$hax -Dwhpx=$whpx -Dhvf=$hvf \ -Dxen=$xen -Dxen_pci_passthrough=$xen_pci_passthrough -Dtcg=$tcg \ - -Dcocoa=$cocoa -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \ + -Dcocoa=$cocoa -Dgtk=$gtk -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \ -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \ -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f -Dvirtiofsd=$virtiofsd \ -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt -Dbrlapi=$brlapi \ @@ -6596,7 +6523,7 @@ preserve_env WINDRES printf "exec" >>config.status for i in "$0" "$@"; do - test "$i" = --skip-meson || printf " '%s'" "$i" >>config.status + test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status done echo ' "$@"' >>config.status chmod +x config.status diff --git a/docs/devel/rcu.txt b/docs/devel/rcu.txt index cdf002edd8..2e6cc607a1 100644 --- a/docs/devel/rcu.txt +++ b/docs/devel/rcu.txt @@ -392,7 +392,7 @@ Instead, we store the size of the array with the array itself: /* Removal phase. */ old_array = global_array; - qatomic_rcu_set(&new_array->data, new_array); + qatomic_rcu_set(&global_array, new_array); synchronize_rcu(); /* Reclamation phase. */ diff --git a/fsdev/meson.build b/fsdev/meson.build index 7dd1cc9bfb..65455a179e 100644 --- a/fsdev/meson.build +++ b/fsdev/meson.build @@ -8,7 +8,7 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( ), if_false: files('qemu-fsdev-dummy.c')) softmmu_ss.add_all(when: 'CONFIG_LINUX', if_true: fsdev_ss) -have_virtfs_proxy_helper = have_tools and libattr.found() and libcap_ng.found() and 'CONFIG_VIRTFS' in config_host +have_virtfs_proxy_helper = have_tools and libattr.found() and libcap_ng.found() and have_virtfs if have_virtfs_proxy_helper executable('virtfs-proxy-helper', files('virtfs-proxy-helper.c', '9p-marshal.c', '9p-iov-marshal.c'), diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events index 9a4a60ca63..0e0aa9847d 100644 --- a/hw/scsi/trace-events +++ b/hw/scsi/trace-events @@ -294,6 +294,15 @@ lsi_awoken(void) "Woken by SIGP" lsi_reg_read(const char *name, int offset, uint8_t ret) "Read reg %s 0x%x = 0x%02x" lsi_reg_write(const char *name, int offset, uint8_t val) "Write reg %s 0x%x = 0x%02x" +# virtio-scsi.c +virtio_scsi_cmd_req(int lun, uint32_t tag, uint8_t cmd) "virtio_scsi_cmd_req lun=%u tag=0x%x cmd=0x%x" +virtio_scsi_cmd_resp(int lun, uint32_t tag, int response, uint8_t status) "virtio_scsi_cmd_resp lun=%u tag=0x%x response=%d status=0x%x" +virtio_scsi_tmf_req(int lun, uint32_t tag, int subtype) "virtio_scsi_tmf_req lun=%u tag=0x%x subtype=%d" +virtio_scsi_tmf_resp(int lun, uint32_t tag, int response) "virtio_scsi_tmf_resp lun=%u tag=0x%x response=%d" +virtio_scsi_an_req(int lun, uint32_t event_requested) "virtio_scsi_an_req lun=%u event_requested=0x%x" +virtio_scsi_an_resp(int lun, int response) "virtio_scsi_an_resp lun=%u response=%d" +virtio_scsi_event(int lun, int event, int reason) "virtio_scsi_event lun=%u event=%d reason=%d" + # scsi-disk.c scsi_disk_check_condition(uint32_t tag, uint8_t key, uint8_t asc, uint8_t ascq) "Command complete tag=0x%x sense=%d/%d/%d" scsi_disk_read_complete(uint32_t tag, size_t size) "Data ready tag=0x%x len=%zd" diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 3db9a8aae9..9690bc63c8 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -27,6 +27,7 @@ #include "scsi/constants.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#include "trace.h" static inline int virtio_scsi_get_lun(uint8_t *lun) { @@ -239,7 +240,11 @@ static void virtio_scsi_cancel_notify(Notifier *notifier, void *data) notifier); if (--n->tmf_req->remaining == 0) { - virtio_scsi_complete_req(n->tmf_req); + VirtIOSCSIReq *req = n->tmf_req; + + trace_virtio_scsi_tmf_resp(virtio_scsi_get_lun(req->req.tmf.lun), + req->req.tmf.tag, req->resp.tmf.response); + virtio_scsi_complete_req(req); } g_free(n); } @@ -273,6 +278,9 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) req->req.tmf.subtype = virtio_tswap32(VIRTIO_DEVICE(s), req->req.tmf.subtype); + trace_virtio_scsi_tmf_req(virtio_scsi_get_lun(req->req.tmf.lun), + req->req.tmf.tag, req->req.tmf.subtype); + switch (req->req.tmf.subtype) { case VIRTIO_SCSI_T_TMF_ABORT_TASK: case VIRTIO_SCSI_T_TMF_QUERY_TASK: @@ -429,11 +437,23 @@ static void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req) virtio_scsi_bad_req(req); return; } else { + req->req.an.event_requested = + virtio_tswap32(VIRTIO_DEVICE(s), req->req.an.event_requested); + trace_virtio_scsi_an_req(virtio_scsi_get_lun(req->req.an.lun), + req->req.an.event_requested); req->resp.an.event_actual = 0; req->resp.an.response = VIRTIO_SCSI_S_OK; } } if (r == 0) { + if (type == VIRTIO_SCSI_T_TMF) + trace_virtio_scsi_tmf_resp(virtio_scsi_get_lun(req->req.tmf.lun), + req->req.tmf.tag, + req->resp.tmf.response); + else if (type == VIRTIO_SCSI_T_AN_QUERY || + type == VIRTIO_SCSI_T_AN_SUBSCRIBE) + trace_virtio_scsi_an_resp(virtio_scsi_get_lun(req->req.an.lun), + req->resp.an.response); virtio_scsi_complete_req(req); } else { assert(r == -EINPROGRESS); @@ -469,6 +489,10 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req) { + trace_virtio_scsi_cmd_resp(virtio_scsi_get_lun(req->req.cmd.lun), + req->req.cmd.tag, + req->resp.cmd.response, + req->resp.cmd.status); /* Sense data is not in req->resp and is copied separately * in virtio_scsi_command_complete. */ @@ -566,6 +590,8 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) return -EINVAL; } } + trace_virtio_scsi_cmd_req(virtio_scsi_get_lun(req->req.cmd.lun), + req->req.cmd.tag, req->req.cmd.cdb[0]); d = virtio_scsi_device_get(s, req->req.cmd.lun); if (!d) { @@ -767,6 +793,8 @@ void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev, } evt->lun[3] = dev->lun & 0xFF; } + trace_virtio_scsi_event(virtio_scsi_get_lun(evt->lun), event, reason); + virtio_scsi_complete_req(req); } diff --git a/include/io/channel.h b/include/io/channel.h index 4d6fe45f63..ab9ea77959 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -92,7 +92,8 @@ struct QIOChannel { * provide additional optional features. * * Consult the corresponding public API docs for a description - * of the semantics of each callback + * of the semantics of each callback. io_shutdown in particular + * must be thread-safe, terminate quickly and must not block. */ struct QIOChannelClass { ObjectClass parent; @@ -510,6 +511,8 @@ int qio_channel_close(QIOChannel *ioc, * QIO_CHANNEL_FEATURE_SHUTDOWN prior to calling * this method. * + * This function is thread-safe, terminates quickly and does not block. + * * Returns: 0 on success, -1 on error */ int qio_channel_shutdown(QIOChannel *ioc, diff --git a/include/qemu/yank.h b/include/qemu/yank.h new file mode 100644 index 0000000000..5b93c70cbf --- /dev/null +++ b/include/qemu/yank.h @@ -0,0 +1,97 @@ +/* + * QEMU yank feature + * + * Copyright (c) Lukas Straub <lukasstraub2@web.de> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef YANK_H +#define YANK_H + +#include "qapi/qapi-types-yank.h" + +typedef void (YankFn)(void *opaque); + +/** + * yank_register_instance: Register a new instance. + * + * This registers a new instance for yanking. Must be called before any yank + * function is registered for this instance. + * + * This function is thread-safe. + * + * @instance: The instance. + * @errp: Error object. + * + * Returns true on success or false if an error occured. + */ +bool yank_register_instance(const YankInstance *instance, Error **errp); + +/** + * yank_unregister_instance: Unregister a instance. + * + * This unregisters a instance. Must be called only after every yank function + * of the instance has been unregistered. + * + * This function is thread-safe. + * + * @instance: The instance. + */ +void yank_unregister_instance(const YankInstance *instance); + +/** + * yank_register_function: Register a yank function + * + * This registers a yank function. All limitations of qmp oob commands apply + * to the yank function as well. See docs/devel/qapi-code-gen.txt under + * "An OOB-capable command handler must satisfy the following conditions". + * + * This function is thread-safe. + * + * @instance: The instance. + * @func: The yank function. + * @opaque: Will be passed to the yank function. + */ +void yank_register_function(const YankInstance *instance, + YankFn *func, + void *opaque); + +/** + * yank_unregister_function: Unregister a yank function + * + * This unregisters a yank function. + * + * This function is thread-safe. + * + * @instance: The instance. + * @func: func that was passed to yank_register_function. + * @opaque: opaque that was passed to yank_register_function. + */ +void yank_unregister_function(const YankInstance *instance, + YankFn *func, + void *opaque); + +/** + * yank_generic_iochannel: Generic yank function for iochannel + * + * This is a generic yank function which will call qio_channel_shutdown on the + * provided QIOChannel. + * + * @opaque: QIOChannel to shutdown + */ +void yank_generic_iochannel(void *opaque); + +#define BLOCKDEV_YANK_INSTANCE(the_node_name) (&(YankInstance) { \ + .type = YANK_INSTANCE_TYPE_BLOCK_NODE, \ + .u.block_node.node_name = (the_node_name) }) + +#define CHARDEV_YANK_INSTANCE(the_id) (&(YankInstance) { \ + .type = YANK_INSTANCE_TYPE_CHARDEV, \ + .u.chardev.id = (the_id) }) + +#define MIGRATION_YANK_INSTANCE (&(YankInstance) { \ + .type = YANK_INSTANCE_TYPE_MIGRATION }) + +#endif diff --git a/include/sysemu/whpx.h b/include/sysemu/whpx.h index 9346fd92e9..8ca1c1c4ac 100644 --- a/include/sysemu/whpx.h +++ b/include/sysemu/whpx.h @@ -15,28 +15,8 @@ #ifdef CONFIG_WHPX -#include "whp-dispatch.h" - -struct whpx_state { - uint64_t mem_quota; - WHV_PARTITION_HANDLE partition; - bool kernel_irqchip_allowed; - bool kernel_irqchip_required; - bool apic_in_platform; -}; - -struct whpx_lapic_state { - struct { - uint32_t data; - uint32_t padding[3]; - } fields[256]; -}; - -extern struct whpx_state whpx_global; int whpx_enabled(void); - -void whpx_apic_get(DeviceState *s); -#define whpx_apic_in_platform() (whpx_global.apic_in_platform) +bool whpx_apic_in_platform(void); #else /* CONFIG_WHPX */ diff --git a/io/channel-tls.c b/io/channel-tls.c index 388f019977..2ae1b92fc0 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -23,6 +23,7 @@ #include "qemu/module.h" #include "io/channel-tls.h" #include "trace.h" +#include "qemu/atomic.h" static ssize_t qio_channel_tls_write_handler(const char *buf, @@ -277,7 +278,8 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc, return QIO_CHANNEL_ERR_BLOCK; } } else if (errno == ECONNABORTED && - (tioc->shutdown & QIO_CHANNEL_SHUTDOWN_READ)) { + (qatomic_load_acquire(&tioc->shutdown) & + QIO_CHANNEL_SHUTDOWN_READ)) { return 0; } @@ -361,7 +363,7 @@ static int qio_channel_tls_shutdown(QIOChannel *ioc, { QIOChannelTLS *tioc = QIO_CHANNEL_TLS(ioc); - tioc->shutdown |= how; + qatomic_or(&tioc->shutdown, how); return qio_channel_shutdown(tioc->master, how, errp); } diff --git a/io/meson.build b/io/meson.build index bcd8b1e737..bbcd3c53a4 100644 --- a/io/meson.build +++ b/io/meson.build @@ -12,4 +12,4 @@ io_ss.add(files( 'dns-resolver.c', 'net-listener.c', 'task.c', -)) +), gnutls) diff --git a/meson.build b/meson.build index 0ce993a404..3d889857a0 100644 --- a/meson.build +++ b/meson.build @@ -169,7 +169,6 @@ version_res = [] coref = [] iokit = [] emulator_link_args = [] -cocoa = not_found hvf = not_found if targetos == 'windows' socket = cc.find_library('ws2_32') @@ -182,7 +181,6 @@ if targetos == 'windows' elif targetos == 'darwin' coref = dependency('appleframeworks', modules: 'CoreFoundation') iokit = dependency('appleframeworks', modules: 'IOKit') - cocoa = dependency('appleframeworks', modules: 'Cocoa', required: get_option('cocoa')) elif targetos == 'sunos' socket = [cc.find_library('socket'), cc.find_library('nsl'), @@ -256,9 +254,6 @@ if not have_xen_pci_passthrough and get_option('xen_pci_passthrough').enabled() error('Xen PCI passthrough requested but Xen not enabled') endif endif -if not cocoa.found() and get_option('cocoa').enabled() - error('Cocoa not available on this platform') -endif ################ # Dependencies # @@ -362,6 +357,14 @@ if not get_option('attr').disabled() endif endif +cocoa = dependency('appleframeworks', modules: 'Cocoa', required: get_option('cocoa')) +if cocoa.found() and get_option('sdl').enabled() + error('Cocoa and SDL cannot be enabled at the same time') +endif +if cocoa.found() and get_option('gtk').enabled() + error('Cocoa and GTK+ cannot be enabled at the same time') +endif + seccomp = not_found if not get_option('seccomp').auto() or have_system or have_tools seccomp = dependency('libseccomp', version: '>=2.3.0', @@ -647,7 +650,7 @@ if not get_option('brlapi').auto() or have_system endif sdl = not_found -if have_system +if not get_option('sdl').auto() or (have_system and not cocoa.found()) sdl = dependency('sdl2', required: get_option('sdl'), static: enable_static) sdl_image = not_found endif @@ -776,20 +779,32 @@ if 'CONFIG_OPENGL' in config_host opengl = declare_dependency(compile_args: config_host['OPENGL_CFLAGS'].split(), link_args: config_host['OPENGL_LIBS'].split()) endif + gtk = not_found -if 'CONFIG_GTK' in config_host - gtk = declare_dependency(compile_args: config_host['GTK_CFLAGS'].split(), - link_args: config_host['GTK_LIBS'].split()) +gtkx11 = not_found +if not get_option('gtk').auto() or (have_system and not cocoa.found()) + gtk = dependency('gtk+-3.0', version: '>=3.22.0', + method: 'pkg-config', + required: get_option('gtk'), + static: enable_static) + if gtk.found() + gtkx11 = dependency('gtk+-x11-3.0', version: '>=3.22.0', + method: 'pkg-config', + required: false, + static: enable_static) + gtk = declare_dependency(dependencies: [gtk, gtkx11]) + endif endif + vte = not_found if 'CONFIG_VTE' in config_host vte = declare_dependency(compile_args: config_host['VTE_CFLAGS'].split(), link_args: config_host['VTE_LIBS'].split()) endif x11 = not_found -if 'CONFIG_X11' in config_host - x11 = declare_dependency(compile_args: config_host['X11_CFLAGS'].split(), - link_args: config_host['X11_LIBS'].split()) +if gtkx11.found() or 'lm32-softmmu' in target_dirs + x11 = dependency('x11', method: 'pkg-config', required: gtkx11.found(), + static: enable_static) endif vnc = not_found png = not_found @@ -1062,6 +1077,7 @@ if glusterfs.found() config_host_data.set('CONFIG_GLUSTERFS_FTRUNCATE_HAS_STAT', glusterfs_ftruncate_has_stat) config_host_data.set('CONFIG_GLUSTERFS_IOCB_HAS_STAT', glusterfs_iocb_has_stat) endif +config_host_data.set('CONFIG_GTK', gtk.found()) config_host_data.set('CONFIG_LIBATTR', have_old_libattr) config_host_data.set('CONFIG_LIBCAP_NG', libcap_ng.found()) config_host_data.set('CONFIG_LIBISCSI', libiscsi.found()) @@ -1085,6 +1101,7 @@ config_host_data.set('CONFIG_STATX', has_statx) config_host_data.set('CONFIG_ZSTD', zstd.found()) config_host_data.set('CONFIG_FUSE', fuse.found()) config_host_data.set('CONFIG_FUSE_LSEEK', fuse_lseek.found()) +config_host_data.set('CONFIG_X11', x11.found()) config_host_data.set('CONFIG_CFI', get_option('cfi')) config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version())) config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0]) @@ -1171,7 +1188,7 @@ host_kconfig = \ ('CONFIG_SPICE' in config_host ? ['CONFIG_SPICE=y'] : []) + \ ('CONFIG_IVSHMEM' in config_host ? ['CONFIG_IVSHMEM=y'] : []) + \ ('CONFIG_OPENGL' in config_host ? ['CONFIG_OPENGL=y'] : []) + \ - ('CONFIG_X11' in config_host ? ['CONFIG_X11=y'] : []) + \ + (x11.found() ? ['CONFIG_X11=y'] : []) + \ ('CONFIG_VHOST_USER' in config_host ? ['CONFIG_VHOST_USER=y'] : []) + \ ('CONFIG_VHOST_VDPA' in config_host ? ['CONFIG_VHOST_VDPA=y'] : []) + \ ('CONFIG_VHOST_KERNEL' in config_host ? ['CONFIG_VHOST_KERNEL=y'] : []) + \ @@ -1815,7 +1832,7 @@ blockdev_ss.add(files( 'blockdev-nbd.c', 'iothread.c', 'job-qmp.c', -)) +), gnutls) # os-posix.c contains POSIX-specific functions used by qemu-storage-daemon, # os-win32.c does not @@ -1971,6 +1988,7 @@ qmp = declare_dependency(link_whole: [libqmp]) libchardev = static_library('chardev', chardev_ss.sources() + genh, name_suffix: 'fa', + dependencies: [gnutls], build_by_default: false) chardev = declare_dependency(link_whole: libchardev) @@ -2189,7 +2207,7 @@ if have_tools qemu_io = executable('qemu-io', files('qemu-io.c'), dependencies: [block, qemuutil], install: true) qemu_nbd = executable('qemu-nbd', files('qemu-nbd.c'), - dependencies: [blockdev, qemuutil], install: true) + dependencies: [blockdev, qemuutil, gnutls], install: true) subdir('storage-daemon') subdir('contrib/rdmacm-mux') @@ -2229,7 +2247,7 @@ subdir('tools') subdir('pc-bios') subdir('docs') subdir('tests') -if 'CONFIG_GTK' in config_host +if gtk.found() subdir('po') endif @@ -2246,7 +2264,7 @@ if host_machine.system() == 'windows' if build_docs nsis_cmd += '-DCONFIG_DOCUMENTATION=y' endif - if 'CONFIG_GTK' in config_host + if gtk.found() nsis_cmd += '-DCONFIG_GTK=y' endif @@ -2331,14 +2349,13 @@ summary_info += {'profiler': config_host.has_key('CONFIG_PROFILER')} summary_info += {'link-time optimization (LTO)': get_option('b_lto')} summary_info += {'static build': config_host.has_key('CONFIG_STATIC')} if targetos == 'darwin' - summary_info += {'Cocoa support': config_host.has_key('CONFIG_COCOA')} + summary_info += {'Cocoa support': cocoa.found()} endif # TODO: add back version summary_info += {'SDL support': sdl.found()} summary_info += {'SDL image support': sdl_image.found()} # TODO: add back version -summary_info += {'GTK support': config_host.has_key('CONFIG_GTK')} -summary_info += {'GTK GL support': config_host.has_key('CONFIG_GTK_GL')} +summary_info += {'GTK support': gtk.found()} summary_info += {'pixman': pixman.found()} # TODO: add back version summary_info += {'VTE support': config_host.has_key('CONFIG_VTE')} diff --git a/meson_options.txt b/meson_options.txt index 7948a8255c..72a3ca22d6 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -74,6 +74,8 @@ option('lzo', type : 'feature', value : 'auto', description: 'lzo compression support') option('rbd', type : 'feature', value : 'auto', description: 'Ceph block device driver') +option('gtk', type : 'feature', value : 'auto', + description: 'GTK+ user interface') option('sdl', type : 'feature', value : 'auto', description: 'SDL user interface') option('sdl_image', type : 'feature', value : 'auto', diff --git a/migration/channel.c b/migration/channel.c index 8a783baa0b..35fe234e9c 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -18,6 +18,8 @@ #include "trace.h" #include "qapi/error.h" #include "io/channel-tls.h" +#include "io/channel-socket.h" +#include "qemu/yank.h" /** * @migration_channel_process_incoming - Create new incoming migration channel @@ -35,6 +37,11 @@ void migration_channel_process_incoming(QIOChannel *ioc) trace_migration_set_incoming_channel( ioc, object_get_typename(OBJECT(ioc))); + if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET)) { + yank_register_function(MIGRATION_YANK_INSTANCE, yank_generic_iochannel, + QIO_CHANNEL(ioc)); + } + if (s->parameters.tls_creds && *s->parameters.tls_creds && !object_dynamic_cast(OBJECT(ioc), @@ -67,6 +74,12 @@ void migration_channel_connect(MigrationState *s, ioc, object_get_typename(OBJECT(ioc)), hostname, error); if (!error) { + if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET)) { + yank_register_function(MIGRATION_YANK_INSTANCE, + yank_generic_iochannel, + QIO_CHANNEL(ioc)); + } + if (s->parameters.tls_creds && *s->parameters.tls_creds && !object_dynamic_cast(OBJECT(ioc), diff --git a/migration/migration.c b/migration/migration.c index a5da718baa..d5136419bf 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -57,6 +57,7 @@ #include "net/announce.h" #include "qemu/queue.h" #include "multifd.h" +#include "qemu/yank.h" #ifdef CONFIG_VFIO #include "hw/vfio/vfio-common.h" @@ -255,6 +256,8 @@ void migration_incoming_state_destroy(void) qapi_free_SocketAddressList(mis->socket_address_list); mis->socket_address_list = NULL; } + + yank_unregister_instance(MIGRATION_YANK_INSTANCE); } static void migrate_generate_event(int new_state) @@ -416,6 +419,10 @@ static void qemu_start_incoming_migration(const char *uri, Error **errp) { const char *p = NULL; + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { + return; + } + qapi_event_send_migration(MIGRATION_STATUS_SETUP); if (strstart(uri, "tcp:", &p) || strstart(uri, "unix:", NULL) || @@ -430,6 +437,7 @@ static void qemu_start_incoming_migration(const char *uri, Error **errp) } else if (strstart(uri, "fd:", &p)) { fd_start_incoming_migration(p, errp); } else { + yank_unregister_instance(MIGRATION_YANK_INSTANCE); error_setg(errp, "unknown migration protocol: %s", uri); } } @@ -1731,6 +1739,7 @@ static void migrate_fd_cleanup(MigrationState *s) } notifier_list_notify(&migration_state_notifiers, s); block_cleanup_parameters(s); + yank_unregister_instance(MIGRATION_YANK_INSTANCE); } static void migrate_fd_cleanup_schedule(MigrationState *s) @@ -2005,6 +2014,7 @@ void qmp_migrate_recover(const char *uri, Error **errp) * only re-setup the migration stream and poke existing migration * to continue using that newly established channel. */ + yank_unregister_instance(MIGRATION_YANK_INSTANCE); qemu_start_incoming_migration(uri, errp); } @@ -2148,6 +2158,12 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, return; } + if (!(has_resume && resume)) { + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { + return; + } + } + if (strstart(uri, "tcp:", &p) || strstart(uri, "unix:", NULL) || strstart(uri, "vsock:", NULL)) { @@ -2161,6 +2177,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } else if (strstart(uri, "fd:", &p)) { fd_start_outgoing_migration(s, p, &local_err); } else { + if (!(has_resume && resume)) { + yank_unregister_instance(MIGRATION_YANK_INSTANCE); + } error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, @@ -2170,6 +2189,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } if (local_err) { + if (!(has_resume && resume)) { + yank_unregister_instance(MIGRATION_YANK_INSTANCE); + } migrate_fd_error(s, local_err); error_propagate(errp, local_err); return; diff --git a/migration/multifd.c b/migration/multifd.c index 45c690aa11..1a1e589064 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -25,6 +25,9 @@ #include "trace.h" #include "multifd.h" +#include "qemu/yank.h" +#include "io/channel-socket.h" + /* Multiple fd's */ #define MULTIFD_MAGIC 0x11223344U @@ -974,6 +977,13 @@ int multifd_load_cleanup(Error **errp) for (i = 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p = &multifd_recv_state->params[i]; + if (object_dynamic_cast(OBJECT(p->c), TYPE_QIO_CHANNEL_SOCKET) + && OBJECT(p->c)->ref == 1) { + yank_unregister_function(MIGRATION_YANK_INSTANCE, + yank_generic_iochannel, + QIO_CHANNEL(p->c)); + } + object_unref(OBJECT(p->c)); p->c = NULL; qemu_mutex_destroy(&p->mutex); diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index d2ce32f4b9..afc3a7f642 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -27,6 +27,7 @@ #include "qemu-file.h" #include "io/channel-socket.h" #include "qemu/iov.h" +#include "qemu/yank.h" static ssize_t channel_writev_buffer(void *opaque, @@ -104,6 +105,12 @@ static int channel_close(void *opaque, Error **errp) int ret; QIOChannel *ioc = QIO_CHANNEL(opaque); ret = qio_channel_close(ioc, errp); + if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) + && OBJECT(ioc)->ref == 1) { + yank_unregister_function(MIGRATION_YANK_INSTANCE, + yank_generic_iochannel, + QIO_CHANNEL(ioc)); + } object_unref(OBJECT(ioc)); return ret; } diff --git a/migration/savevm.c b/migration/savevm.c index 27e842812e..4f3b69ecfc 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -62,6 +62,7 @@ #include "migration/colo.h" #include "qemu/bitmap.h" #include "net/announce.h" +#include "qemu/yank.h" const unsigned int postcopy_ram_discard_version; @@ -3006,6 +3007,10 @@ int load_snapshot(const char *name, Error **errp) qemu_system_reset(SHUTDOWN_CAUSE_NONE); mis->from_src_file = f; + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { + ret = -EINVAL; + goto err_drain; + } aio_context_acquire(aio_context); ret = qemu_loadvm_state(f); migration_incoming_state_destroy(); diff --git a/qapi/meson.build b/qapi/meson.build index 0e98146f1f..ab68e7900e 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -47,6 +47,7 @@ qapi_all_modules = [ 'trace', 'transaction', 'ui', + 'yank', ] qapi_storage_daemon_modules = [ diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 0b444b76d2..3441c9a9ae 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -86,6 +86,7 @@ { 'include': 'machine.json' } { 'include': 'machine-target.json' } { 'include': 'replay.json' } +{ 'include': 'yank.json' } { 'include': 'misc.json' } { 'include': 'misc-target.json' } { 'include': 'audio.json' } diff --git a/qapi/yank.json b/qapi/yank.json new file mode 100644 index 0000000000..167a775594 --- /dev/null +++ b/qapi/yank.json @@ -0,0 +1,119 @@ +# -*- Mode: Python -*- +# vim: filetype=python +# + +## +# = Yank feature +## + +## +# @YankInstanceType: +# +# An enumeration of yank instance types. See @YankInstance for more +# information. +# +# Since: 6.0 +## +{ 'enum': 'YankInstanceType', + 'data': [ 'block-node', 'chardev', 'migration' ] } + +## +# @YankInstanceBlockNode: +# +# Specifies which block graph node to yank. See @YankInstance for more +# information. +# +# @node-name: the name of the block graph node +# +# Since: 6.0 +## +{ 'struct': 'YankInstanceBlockNode', + 'data': { 'node-name': 'str' } } + +## +# @YankInstanceChardev: +# +# Specifies which character device to yank. See @YankInstance for more +# information. +# +# @id: the chardev's ID +# +# Since: 6.0 +## +{ 'struct': 'YankInstanceChardev', + 'data': { 'id': 'str' } } + +## +# @YankInstance: +# +# A yank instance can be yanked with the @yank qmp command to recover from a +# hanging QEMU. +# +# Currently implemented yank instances: +# - nbd block device: +# Yanking it will shut down the connection to the nbd server without +# attempting to reconnect. +# - socket chardev: +# Yanking it will shut down the connected socket. +# - migration: +# Yanking it will shut down all migration connections. Unlike +# @migrate_cancel, it will not notify the migration process, so migration +# will go into @failed state, instead of @cancelled state. @yank should be +# used to recover from hangs. +# +# Since: 6.0 +## +{ 'union': 'YankInstance', + 'base': { 'type': 'YankInstanceType' }, + 'discriminator': 'type', + 'data': { + 'block-node': 'YankInstanceBlockNode', + 'chardev': 'YankInstanceChardev' } } + +## +# @yank: +# +# Try to recover from hanging QEMU by yanking the specified instances. See +# @YankInstance for more information. +# +# Takes a list of @YankInstance as argument. +# +# Returns: - Nothing on success +# - @DeviceNotFound error, if any of the YankInstances doesn't exist +# +# Example: +# +# -> { "execute": "yank", +# "arguments": { +# "instances": [ +# { "type": "block-node", +# "node-name": "nbd0" } +# ] } } +# <- { "return": {} } +# +# Since: 6.0 +## +{ 'command': 'yank', + 'data': { 'instances': ['YankInstance'] }, + 'allow-oob': true } + +## +# @query-yank: +# +# Query yank instances. See @YankInstance for more information. +# +# Returns: list of @YankInstance +# +# Example: +# +# -> { "execute": "query-yank" } +# <- { "return": [ +# { "type": "block-node", +# "node-name": "nbd0" } +# ] } +# +# Since: 6.0 +## +{ 'command': 'query-yank', + 'returns': ['YankInstance'], + 'allow-oob': true } diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index e0bfa7b5a4..4d2a9f6c43 100644 --- a/scripts/qemu-gdb.py +++ b/scripts/qemu-gdb.py @@ -40,6 +40,7 @@ timers.TimersCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() +coroutine.CoroutineBt() # Default to silently passing through SIGUSR1, because QEMU sends it # to itself a lot. diff --git a/scripts/qemugdb/coroutine.py b/scripts/qemugdb/coroutine.py index db61389022..7db46d4b68 100644 --- a/scripts/qemugdb/coroutine.py +++ b/scripts/qemugdb/coroutine.py @@ -70,6 +70,11 @@ def bt_jmpbuf(jmpbuf): regs = get_jmpbuf_regs(jmpbuf) old = dict() + # remember current stack frame and select the topmost + # so that register modifications don't wreck it + selected_frame = gdb.selected_frame() + gdb.newest_frame().select() + for i in regs: old[i] = gdb.parse_and_eval('(uint64_t)$%s' % i) @@ -81,8 +86,13 @@ def bt_jmpbuf(jmpbuf): for i in regs: gdb.execute('set $%s = %s' % (i, old[i])) + selected_frame.select() + +def co_cast(co): + return co.cast(gdb.lookup_type('CoroutineUContext').pointer()) + def coroutine_to_jmpbuf(co): - coroutine_pointer = co.cast(gdb.lookup_type('CoroutineUContext').pointer()) + coroutine_pointer = co_cast(co) return coroutine_pointer['env']['__jmpbuf'] @@ -100,6 +110,29 @@ class CoroutineCommand(gdb.Command): bt_jmpbuf(coroutine_to_jmpbuf(gdb.parse_and_eval(argv[0]))) +class CoroutineBt(gdb.Command): + '''Display backtrace including coroutine switches''' + def __init__(self): + gdb.Command.__init__(self, 'qemu bt', gdb.COMMAND_STACK, + gdb.COMPLETE_NONE) + + def invoke(self, arg, from_tty): + + gdb.execute("bt") + + if gdb.parse_and_eval("qemu_in_coroutine()") == False: + return + + co_ptr = gdb.parse_and_eval("qemu_coroutine_self()") + + while True: + co = co_cast(co_ptr) + co_ptr = co["base"]["caller"] + if co_ptr == 0: + break + gdb.write("Coroutine at " + str(co_ptr) + ":\n") + bt_jmpbuf(coroutine_to_jmpbuf(co_ptr)) + class CoroutineSPFunction(gdb.Function): def __init__(self): gdb.Function.__init__(self, 'qemu_coroutine_sp') diff --git a/storage-daemon/meson.build b/storage-daemon/meson.build index c5adce81c3..68852f3d25 100644 --- a/storage-daemon/meson.build +++ b/storage-daemon/meson.build @@ -1,6 +1,6 @@ qsd_ss = ss.source_set() qsd_ss.add(files('qemu-storage-daemon.c')) -qsd_ss.add(blockdev, chardev, qmp, qom, qemuutil) +qsd_ss.add(blockdev, chardev, qmp, qom, qemuutil, gnutls) subdir('qapi') diff --git a/target/i386/cpu.h b/target/i386/cpu.h index af130512e2..d23a5b340a 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1807,7 +1807,7 @@ void cpu_sync_bndcs_hflags(CPUX86State *env); /* this function must always be used to load data in the segment cache: it synchronizes the hflags with the segment cache values */ static inline void cpu_x86_load_seg_cache(CPUX86State *env, - int seg_reg, unsigned int selector, + X86Seg seg_reg, unsigned int selector, target_ulong base, unsigned int limit, unsigned int flags) @@ -1896,7 +1896,7 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector, /* cpu-exec.c */ /* the following helpers are only usable in user mode simulation as they can trigger unexpected exceptions */ -void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector); +void cpu_x86_load_seg(CPUX86State *s, X86Seg seg_reg, int selector); void cpu_x86_fsave(CPUX86State *s, target_ulong ptr, int data32); void cpu_x86_frstor(CPUX86State *s, target_ulong ptr, int data32); void cpu_x86_fxsave(CPUX86State *s, target_ulong ptr); diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c index 4a3de5f69d..41e265fc67 100644 --- a/target/i386/gdbstub.c +++ b/target/i386/gdbstub.c @@ -232,7 +232,7 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) return 0; } -static int x86_cpu_gdb_load_seg(X86CPU *cpu, int sreg, uint8_t *mem_buf) +static int x86_cpu_gdb_load_seg(X86CPU *cpu, X86Seg sreg, uint8_t *mem_buf) { CPUX86State *env = &cpu->env; uint16_t selector = ldl_p(mem_buf); diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c index 5f2ee6aa7e..180d47f0e9 100644 --- a/target/i386/tcg/seg_helper.c +++ b/target/i386/tcg/seg_helper.c @@ -176,8 +176,8 @@ static inline void get_ss_esp_from_tss(CPUX86State *env, uint32_t *ss_ptr, } } -static void tss_load_seg(CPUX86State *env, int seg_reg, int selector, int cpl, - uintptr_t retaddr) +static void tss_load_seg(CPUX86State *env, X86Seg seg_reg, int selector, + int cpl, uintptr_t retaddr) { uint32_t e1, e2; int rpl, dpl; @@ -2098,7 +2098,7 @@ void helper_iret_real(CPUX86State *env, int shift) env->hflags2 &= ~HF2_NMI_MASK; } -static inline void validate_seg(CPUX86State *env, int seg_reg, int cpl) +static inline void validate_seg(CPUX86State *env, X86Seg seg_reg, int cpl) { int dpl; uint32_t e2; @@ -2623,7 +2623,7 @@ void helper_verw(CPUX86State *env, target_ulong selector1) } #if defined(CONFIG_USER_ONLY) -void cpu_x86_load_seg(CPUX86State *env, int seg_reg, int selector) +void cpu_x86_load_seg(CPUX86State *env, X86Seg seg_reg, int selector) { if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) { int dpl = (env->eflags & VM_MASK) ? 3 : 0; diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 11db2f3c8d..6a4c31f933 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2287,13 +2287,13 @@ static void gen_cmovcc1(CPUX86State *env, DisasContext *s, MemOp ot, int b, } } -static inline void gen_op_movl_T0_seg(DisasContext *s, int seg_reg) +static inline void gen_op_movl_T0_seg(DisasContext *s, X86Seg seg_reg) { tcg_gen_ld32u_tl(s->T0, cpu_env, offsetof(CPUX86State,segs[seg_reg].selector)); } -static inline void gen_op_movl_seg_T0_vm(DisasContext *s, int seg_reg) +static inline void gen_op_movl_seg_T0_vm(DisasContext *s, X86Seg seg_reg) { tcg_gen_ext16u_tl(s->T0, s->T0); tcg_gen_st32_tl(s->T0, cpu_env, @@ -2303,7 +2303,7 @@ static inline void gen_op_movl_seg_T0_vm(DisasContext *s, int seg_reg) /* move T0 to seg_reg and compute if the CPU state may change. Never call this function with seg_reg == R_CS */ -static void gen_movl_seg_T0(DisasContext *s, int seg_reg) +static void gen_movl_seg_T0(DisasContext *s, X86Seg seg_reg) { if (s->pe && !s->vm86) { tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 3b824fc9d7..985ceba8f8 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -26,13 +26,10 @@ #include "qapi/qapi-types-common.h" #include "qapi/qapi-visit-common.h" #include "migration/blocker.h" -#include "whp-dispatch.h" #include <winerror.h> #include "whpx-cpus.h" - -#include <WinHvPlatform.h> -#include <WinHvEmulation.h> +#include "whpx-internal.h" #define HYPERV_APIC_BUS_FREQUENCY (200000000ULL) @@ -1869,6 +1866,10 @@ int whpx_enabled(void) return whpx_allowed; } +bool whpx_apic_in_platform(void) { + return whpx_global.apic_in_platform; +} + static void whpx_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); diff --git a/target/i386/whpx/whpx-apic.c b/target/i386/whpx/whpx-apic.c index b127a3cb8a..bba36f3ec9 100644 --- a/target/i386/whpx/whpx-apic.c +++ b/target/i386/whpx/whpx-apic.c @@ -18,7 +18,14 @@ #include "hw/pci/msi.h" #include "sysemu/hw_accel.h" #include "sysemu/whpx.h" -#include "whp-dispatch.h" +#include "whpx-internal.h" + +struct whpx_lapic_state { + struct { + uint32_t data; + uint32_t padding[3]; + } fields[256]; +}; static void whpx_put_apic_state(APICCommonState *s, struct whpx_lapic_state *kapic) diff --git a/target/i386/whpx/whpx-cpus.c b/target/i386/whpx/whpx-cpus.c index d9bd5a2d36..f7e69881a3 100644 --- a/target/i386/whpx/whpx-cpus.c +++ b/target/i386/whpx/whpx-cpus.c @@ -15,11 +15,9 @@ #include "qemu/guest-random.h" #include "sysemu/whpx.h" +#include "whpx-internal.h" #include "whpx-cpus.h" -#include <WinHvPlatform.h> -#include <WinHvEmulation.h> - static void *whpx_cpu_thread_fn(void *arg) { CPUState *cpu = arg; diff --git a/target/i386/whpx/whp-dispatch.h b/target/i386/whpx/whpx-internal.h index cef5d848bd..908ababf6d 100644 --- a/target/i386/whpx/whp-dispatch.h +++ b/target/i386/whpx/whpx-internal.h @@ -1,10 +1,21 @@ -#ifndef WHP_DISPATCH_H -#define WHP_DISPATCH_H +#ifndef WHP_INTERNAL_H +#define WHP_INTERNAL_H #include <windows.h> #include <WinHvPlatform.h> #include <WinHvEmulation.h> +struct whpx_state { + uint64_t mem_quota; + WHV_PARTITION_HANDLE partition; + bool kernel_irqchip_allowed; + bool kernel_irqchip_required; + bool apic_in_platform; +}; + +extern struct whpx_state whpx_global; +void whpx_apic_get(DeviceState *s); + #define WHV_E_UNKNOWN_CAPABILITY 0x80370300L #define LIST_WINHVPLATFORM_FUNCTIONS(X) \ @@ -72,4 +83,4 @@ typedef enum WHPFunctionList { WINHV_PLATFORM_FNS_SUPPLEMENTAL } WHPFunctionList; -#endif /* WHP_DISPATCH_H */ +#endif /* WHP_INTERNAL_H */ diff --git a/tests/meson.build b/tests/meson.build index 1fa068f27b..29ebaba48d 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -159,11 +159,11 @@ if have_block 'CONFIG_POSIX' in config_host tests += { 'test-crypto-tlscredsx509': ['crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c', - tasn1, crypto], + tasn1, crypto, gnutls], 'test-crypto-tlssession': ['crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c', 'crypto-tls-psk-helpers.c', - tasn1, crypto], + tasn1, crypto, gnutls], 'test-io-channel-tls': ['io-channel-helpers.c', 'crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c', - tasn1, io, crypto]} + tasn1, io, crypto, gnutls]} endif if 'CONFIG_AUTH_PAM' in config_host tests += {'test-authz-pam': [authz]} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 0b5467f084..16d04625b8 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -201,7 +201,9 @@ qos_test_ss.add( 'virtio-serial-test.c', 'vmxnet3-test.c', ) -qos_test_ss.add(when: 'CONFIG_VIRTFS', if_true: files('virtio-9p-test.c')) +if have_virtfs + qos_test_ss.add(files('virtio-9p-test.c')) +endif qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-test.c')) tpmemu_files = ['tpm-emu.c', 'tpm-util.c', 'tpm-tests.c'] diff --git a/tests/test-char.c b/tests/test-char.c index 06102977b6..469d25989c 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -937,6 +937,7 @@ static void char_socket_client_dupid_test(gconstpointer opaque) g_assert_nonnull(opts); chr1 = qemu_chr_new_from_opts(opts, NULL, &error_abort); g_assert_nonnull(chr1); + qemu_chr_wait_connected(chr1, &error_abort); chr2 = qemu_chr_new_from_opts(opts, NULL, &local_err); g_assert_null(chr2); diff --git a/ui/gtk.c b/ui/gtk.c index a752aa22be..e8474456df 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -396,7 +396,7 @@ static void gd_update_full_redraw(VirtualConsole *vc) int ww, wh; ww = gdk_window_get_width(gtk_widget_get_window(area)); wh = gdk_window_get_height(gtk_widget_get_window(area)); -#if defined(CONFIG_GTK_GL) +#if defined(CONFIG_OPENGL) if (vc->gfx.gls && gtk_use_gl_area) { gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area)); return; @@ -625,7 +625,7 @@ static const DisplayChangeListenerOps dcl_ops = { /** DisplayState Callbacks (opengl version) **/ -#if defined(CONFIG_GTK_GL) +#if defined(CONFIG_OPENGL) static const DisplayChangeListenerOps dcl_gl_area_ops = { .dpy_name = "gtk-egl", @@ -644,7 +644,7 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = { .dpy_gl_update = gd_gl_area_scanout_flush, }; -#endif /* CONFIG_GTK_GL */ +#endif /* CONFIG_OPENGL */ static const DisplayChangeListenerOps dcl_egl_ops = { .dpy_name = "gtk-egl", @@ -725,7 +725,7 @@ static void gd_set_ui_info(VirtualConsole *vc, gint width, gint height) dpy_set_ui_info(vc->gfx.dcl.con, &info); } -#if defined(CONFIG_GTK_GL) +#if defined(CONFIG_OPENGL) static gboolean gd_render_event(GtkGLArea *area, GdkGLContext *context, void *opaque) @@ -1865,7 +1865,7 @@ static void gd_connect_vc_gfx_signals(VirtualConsole *vc) { g_signal_connect(vc->gfx.drawing_area, "draw", G_CALLBACK(gd_draw_event), vc); -#if defined(CONFIG_GTK_GL) +#if defined(CONFIG_OPENGL) if (gtk_use_gl_area) { /* wire up GtkGlArea events */ g_signal_connect(vc->gfx.drawing_area, "render", @@ -1992,12 +1992,12 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, #if defined(CONFIG_OPENGL) if (display_opengl) { -#if defined(CONFIG_GTK_GL) +#if defined(CONFIG_OPENGL) if (gtk_use_gl_area) { vc->gfx.drawing_area = gtk_gl_area_new(); vc->gfx.dcl.ops = &dcl_gl_area_ops; } else -#endif /* CONFIG_GTK_GL */ +#endif /* CONFIG_OPENGL */ { vc->gfx.drawing_area = gtk_drawing_area_new(); /* @@ -2314,7 +2314,7 @@ static void early_gtk_display_init(DisplayOptions *opts) assert(opts->type == DISPLAY_TYPE_GTK); if (opts->has_gl && opts->gl != DISPLAYGL_MODE_OFF) { #if defined(CONFIG_OPENGL) -#if defined(CONFIG_GTK_GL) && defined(GDK_WINDOWING_WAYLAND) +#if defined(GDK_WINDOWING_WAYLAND) if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) { gtk_use_gl_area = true; gtk_gl_area_init(); diff --git a/ui/meson.build b/ui/meson.build index 013258a01c..634fabab0d 100644 --- a/ui/meson.build +++ b/ui/meson.build @@ -29,7 +29,7 @@ vnc_ss.add(files( 'vnc-ws.c', 'vnc-jobs.c', )) -vnc_ss.add(zlib, png, jpeg) +vnc_ss.add(zlib, png, jpeg, gnutls) vnc_ss.add(when: sasl, if_true: files('vnc-auth-sasl.c')) softmmu_ss.add_all(when: vnc, if_true: vnc_ss) softmmu_ss.add(when: vnc, if_false: files('vnc-stubs.c')) @@ -57,14 +57,13 @@ if config_host.has_key('CONFIG_OPENGL_DMABUF') ui_modules += {'egl-headless' : egl_headless_ss} endif -if config_host.has_key('CONFIG_GTK') +if gtk.found() softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('win32-kbd-hook.c')) gtk_ss = ss.source_set() gtk_ss.add(gtk, vte, pixman, files('gtk.c')) - gtk_ss.add(when: [x11, 'CONFIG_X11'], if_true: files('x_keymap.c')) - gtk_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('gtk-egl.c')) - gtk_ss.add(when: [opengl, 'CONFIG_GTK_GL'], if_true: files('gtk-gl-area.c')) + gtk_ss.add(when: x11, if_true: files('x_keymap.c')) + gtk_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('gtk-egl.c', 'gtk-gl-area.c')) ui_modules += {'gtk' : gtk_ss} endif @@ -78,7 +77,7 @@ if sdl.found() 'sdl2.c', )) sdl_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('sdl2-gl.c')) - sdl_ss.add(when: [x11, 'CONFIG_X11'], if_true: files('x_keymap.c')) + sdl_ss.add(when: x11, if_true: files('x_keymap.c')) ui_modules += {'sdl' : sdl_ss} endif diff --git a/util/meson.build b/util/meson.build index a3dfc0f966..540a605b78 100644 --- a/util/meson.build +++ b/util/meson.build @@ -50,6 +50,7 @@ endif if have_system util_ss.add(when: 'CONFIG_GIO', if_true: [files('dbus.c'), gio]) + util_ss.add(files('yank.c')) endif if have_block diff --git a/util/yank.c b/util/yank.c new file mode 100644 index 0000000000..fc08f65209 --- /dev/null +++ b/util/yank.c @@ -0,0 +1,207 @@ +/* + * QEMU yank feature + * + * Copyright (c) Lukas Straub <lukasstraub2@web.de> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/thread.h" +#include "qemu/queue.h" +#include "qemu/lockable.h" +#include "qapi/qapi-commands-yank.h" +#include "qapi/qapi-visit-yank.h" +#include "qapi/clone-visitor.h" +#include "io/channel.h" +#include "qemu/yank.h" + +struct YankFuncAndParam { + YankFn *func; + void *opaque; + QLIST_ENTRY(YankFuncAndParam) next; +}; + +struct YankInstanceEntry { + YankInstance *instance; + QLIST_HEAD(, YankFuncAndParam) yankfns; + QLIST_ENTRY(YankInstanceEntry) next; +}; + +typedef struct YankFuncAndParam YankFuncAndParam; +typedef struct YankInstanceEntry YankInstanceEntry; + +/* + * This lock protects the yank_instance_list below. Because it's taken by + * OOB-capable commands, it must be "fast", i.e. it may only be held for a + * bounded, short time. See docs/devel/qapi-code-gen.txt for additional + * information. + */ +static QemuMutex yank_lock; + +static QLIST_HEAD(, YankInstanceEntry) yank_instance_list + = QLIST_HEAD_INITIALIZER(yank_instance_list); + +static bool yank_instance_equal(const YankInstance *a, const YankInstance *b) +{ + if (a->type != b->type) { + return false; + } + + switch (a->type) { + case YANK_INSTANCE_TYPE_BLOCK_NODE: + return g_str_equal(a->u.block_node.node_name, + b->u.block_node.node_name); + + case YANK_INSTANCE_TYPE_CHARDEV: + return g_str_equal(a->u.chardev.id, b->u.chardev.id); + + case YANK_INSTANCE_TYPE_MIGRATION: + return true; + + default: + abort(); + } +} + +static YankInstanceEntry *yank_find_entry(const YankInstance *instance) +{ + YankInstanceEntry *entry; + + QLIST_FOREACH(entry, &yank_instance_list, next) { + if (yank_instance_equal(entry->instance, instance)) { + return entry; + } + } + return NULL; +} + +bool yank_register_instance(const YankInstance *instance, Error **errp) +{ + YankInstanceEntry *entry; + + QEMU_LOCK_GUARD(&yank_lock); + + if (yank_find_entry(instance)) { + error_setg(errp, "duplicate yank instance"); + return false; + } + + entry = g_new0(YankInstanceEntry, 1); + entry->instance = QAPI_CLONE(YankInstance, instance); + QLIST_INIT(&entry->yankfns); + QLIST_INSERT_HEAD(&yank_instance_list, entry, next); + + return true; +} + +void yank_unregister_instance(const YankInstance *instance) +{ + YankInstanceEntry *entry; + + QEMU_LOCK_GUARD(&yank_lock); + entry = yank_find_entry(instance); + assert(entry); + + assert(QLIST_EMPTY(&entry->yankfns)); + QLIST_REMOVE(entry, next); + qapi_free_YankInstance(entry->instance); + g_free(entry); +} + +void yank_register_function(const YankInstance *instance, + YankFn *func, + void *opaque) +{ + YankInstanceEntry *entry; + YankFuncAndParam *func_entry; + + QEMU_LOCK_GUARD(&yank_lock); + entry = yank_find_entry(instance); + assert(entry); + + func_entry = g_new0(YankFuncAndParam, 1); + func_entry->func = func; + func_entry->opaque = opaque; + + QLIST_INSERT_HEAD(&entry->yankfns, func_entry, next); +} + +void yank_unregister_function(const YankInstance *instance, + YankFn *func, + void *opaque) +{ + YankInstanceEntry *entry; + YankFuncAndParam *func_entry; + + QEMU_LOCK_GUARD(&yank_lock); + entry = yank_find_entry(instance); + assert(entry); + + QLIST_FOREACH(func_entry, &entry->yankfns, next) { + if (func_entry->func == func && func_entry->opaque == opaque) { + QLIST_REMOVE(func_entry, next); + g_free(func_entry); + return; + } + } + + abort(); +} + +void yank_generic_iochannel(void *opaque) +{ + QIOChannel *ioc = QIO_CHANNEL(opaque); + + qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); +} + +void qmp_yank(YankInstanceList *instances, + Error **errp) +{ + YankInstanceList *tail; + YankInstanceEntry *entry; + YankFuncAndParam *func_entry; + + QEMU_LOCK_GUARD(&yank_lock); + for (tail = instances; tail; tail = tail->next) { + entry = yank_find_entry(tail->value); + if (!entry) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Instance not found"); + return; + } + } + for (tail = instances; tail; tail = tail->next) { + entry = yank_find_entry(tail->value); + assert(entry); + QLIST_FOREACH(func_entry, &entry->yankfns, next) { + func_entry->func(func_entry->opaque); + } + } +} + +YankInstanceList *qmp_query_yank(Error **errp) +{ + YankInstanceEntry *entry; + YankInstanceList *ret; + + ret = NULL; + + QEMU_LOCK_GUARD(&yank_lock); + QLIST_FOREACH(entry, &yank_instance_list, next) { + YankInstanceList *new_entry; + new_entry = g_new0(YankInstanceList, 1); + new_entry->value = QAPI_CLONE(YankInstance, entry->instance); + new_entry->next = ret; + ret = new_entry; + } + + return ret; +} + +static void __attribute__((__constructor__)) yank_init(void) +{ + qemu_mutex_init(&yank_lock); +} |