aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2022-06-29 21:35:27 +0530
committerRichard Henderson <richard.henderson@linaro.org>2022-06-29 21:35:27 +0530
commitf96d4e0f60073963a5c64844271ecfee8dd87abc (patch)
tree49045d2cf087e41acff10fa0df0ea44a8429b0c6 /util
parent2a8835cb45371a1f05c9c5899741d66685290f28 (diff)
parent1b8f777673985af366de099ad4e41d334b36fb12 (diff)
Merge tag 'pull-block-2022-06-14-v2' of https://gitlab.com/vsementsov/qemu into staging
Block jobs & NBD patches v2: - add arguments to QEMUMachine constructor in test, to make it work on arm in gitlab pipeline - use bdrv_inc_in_flight() / bdrv_dec_in_flight() instead of direct manipulation with bs->in_flight - add new options for copy-before-write filter - new trace points for NBD - prefer unsigned type for some 'in_flight' fields # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCgAdFiEEi5wmzbL9FHyIDoahVh8kwfGfefsFAmK8BqkACgkQVh8kwfGf # efuiMw/+P9FFLfGFSjVP+LYeT0Ah6kN1ypCMQzIk3Qq/J6qgMZhtRqpQoZOfIFQL # U9fGmEtQZ7gvEMD/nJToL6uOYlnQfPxDcA6GrRwWWE3rcFiPK4J0q2LlnPLn4QaU # W/qag5l/QnZfLlj/iV6neWOEvqdnvY1L8IS+T8xV6N0iBYlwgMC/6FGshQwehzcV # T5F1qPGB0vjFDjf92LFPEsvsFFHjHIVPwOyJMvF64QtSk57utikq/la9PI/yA9AH # Ll4mNQuZKx6rSI5wE6b21jc8iOUvaoHdPSEDQZfNILSdgGdiKvFwE51y+baGnIAD # TpjxfG59q0jyGxMjQVxMRSFaxAC4+Mqi82diSPv4xbiUdsE4byJH0oENn4z7+wAv # EvjuU9yx4FfHHltoUNwfn2pv00o/ELdZIoBNmW36rPxSGZMvfVfRtuBL7XWNUFbW # Fr4BwsjC4KfIxb16QTBGhXVv6grxdlwoU9N23npdi0YpW1ftZzXGDa85+gINQ807 # eK/gP/OtYPwIql0bgmLiuaRNzC9psmQOO6vQbdvd/e4BEVWkxiez37+e+zFMStmL # OAL8rS6jckUoxVZjCYFEWg97XOobLUIhQxt9Fwh2omMDGKTwv861ghUAivxSWs93 # IRNxfwqNPxnpDDXjnK1ayZgU08IL98AUYVKcPN1y8JvEhB4Hr1k= # =ndKk # -----END PGP SIGNATURE----- # gpg: Signature made Wed 29 Jun 2022 01:30:41 PM +0530 # gpg: using RSA key 8B9C26CDB2FD147C880E86A1561F24C1F19F79FB # gpg: Good signature from "Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>" [unknown] # gpg: aka "Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 8B9C 26CD B2FD 147C 880E 86A1 561F 24C1 F19F 79FB * tag 'pull-block-2022-06-14-v2' of https://gitlab.com/vsementsov/qemu: block: use 'unsigned' for in_flight field on driver state nbd: trace long NBD operations iotests: copy-before-write: add cases for cbw-timeout option block/copy-before-write: implement cbw-timeout option block/block-copy: block_copy(): add timeout_ns parameter util: add qemu-co-timeout iotests: add copy-before-write: on-cbw-error tests block/copy-before-write: add on-cbw-error open parameter block/copy-before-write: refactor option parsing Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'util')
-rw-r--r--util/meson.build1
-rw-r--r--util/qemu-co-timeout.c89
2 files changed, 90 insertions, 0 deletions
diff --git a/util/meson.build b/util/meson.build
index 4939b0b91c..8cce8f8968 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -85,6 +85,7 @@ if have_block
util_ss.add(files('block-helpers.c'))
util_ss.add(files('qemu-coroutine-sleep.c'))
util_ss.add(files('qemu-co-shared-resource.c'))
+ util_ss.add(files('qemu-co-timeout.c'))
util_ss.add(files('thread-pool.c', 'qemu-timer.c'))
util_ss.add(files('readline.c'))
util_ss.add(files('throttle.c'))
diff --git a/util/qemu-co-timeout.c b/util/qemu-co-timeout.c
new file mode 100644
index 0000000000..00cd335649
--- /dev/null
+++ b/util/qemu-co-timeout.c
@@ -0,0 +1,89 @@
+/*
+ * Helper functionality for distributing a fixed total amount of
+ * an abstract resource among multiple coroutines.
+ *
+ * Copyright (c) 2022 Virtuozzo International GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/coroutine.h"
+#include "block/aio.h"
+
+typedef struct QemuCoTimeoutState {
+ CoroutineEntry *entry;
+ void *opaque;
+ QemuCoSleep sleep_state;
+ bool marker;
+ CleanupFunc *clean;
+} QemuCoTimeoutState;
+
+static void coroutine_fn qemu_co_timeout_entry(void *opaque)
+{
+ QemuCoTimeoutState *s = opaque;
+
+ s->entry(s->opaque);
+
+ if (s->marker) {
+ assert(!s->sleep_state.to_wake);
+ /* .marker set by qemu_co_timeout, it have been failed */
+ if (s->clean) {
+ s->clean(s->opaque);
+ }
+ g_free(s);
+ } else {
+ s->marker = true;
+ qemu_co_sleep_wake(&s->sleep_state);
+ }
+}
+
+int coroutine_fn qemu_co_timeout(CoroutineEntry *entry, void *opaque,
+ uint64_t timeout_ns, CleanupFunc clean)
+{
+ QemuCoTimeoutState *s;
+ Coroutine *co;
+
+ if (timeout_ns == 0) {
+ entry(opaque);
+ return 0;
+ }
+
+ s = g_new(QemuCoTimeoutState, 1);
+ *s = (QemuCoTimeoutState) {
+ .entry = entry,
+ .opaque = opaque,
+ .clean = clean
+ };
+
+ co = qemu_coroutine_create(qemu_co_timeout_entry, s);
+
+ aio_co_enter(qemu_get_current_aio_context(), co);
+ qemu_co_sleep_ns_wakeable(&s->sleep_state, QEMU_CLOCK_REALTIME, timeout_ns);
+
+ if (s->marker) {
+ /* .marker set by qemu_co_timeout_entry, success */
+ g_free(s);
+ return 0;
+ }
+
+ /* Don't free s, as we can't cancel qemu_co_timeout_entry execution */
+ s->marker = true;
+ return -ETIMEDOUT;
+}