From nobody Thu Mar 28 17:05:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610530882; cv=none; d=zohomail.com; s=zohoarc; b=ZDQbvJThEl53+BI+EI4dXLCIk6lLQss5fnTy/R3Yy57wwUI1t3+SFBCFinam7fTWKVxWrw0CVtQpaii9/LgjjZm4Q7UHvU1U5jlbtZPD1o3TSVgiDlbhw3Cpot8N1zPbh8yGnA0wWUxAWTqHd4OSHW3WyJtErNTdC8otycS/Gow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610530882; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dogi5DWyEYa+fVoL1HzL7xVRIrOzAf9cdLWePyL4XsY=; b=PIDhHojJd9U6QplJiGOc7NHgC1y6qPRKSNGnQ7yJMm0upliCjFJSMe9NMzEJEkowDoaRVbaGQb0iz5H27hInYtKCqZ/tQmmJrg3o5jtmXfzSxrCzwV6IThpzf4Ga2/9xLOhxXmebXxApHe9wXUTSBfvOaSEoSwcXRvEhE6KRmq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610530882111425.17672126363345; Wed, 13 Jan 2021 01:41:22 -0800 (PST) Received: from localhost ([::1]:47608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzceW-0000Sn-Py for importer@patchew.org; Wed, 13 Jan 2021 04:41:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzcUo-0005pu-SF for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:29837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kzcUk-0002xn-Ml for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-574-FsN-gXJIOFWlwb418jX1Lw-1; Wed, 13 Jan 2021 04:31:11 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2C53DF8B2; Wed, 13 Jan 2021 09:31:09 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02F4660BF1; Wed, 13 Jan 2021 09:31:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8384811385EE; Wed, 13 Jan 2021 10:31:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610530274; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dogi5DWyEYa+fVoL1HzL7xVRIrOzAf9cdLWePyL4XsY=; b=g6QCn4eRgcJWK6VE7e6u3MOII4KlAT0NBdH0rwfz8jYHgB5VCXTtjNk4jIkm2a2SPOoZMi jm+xSdyPUnHOkyEAjC1A52Iha+Rjk4Ywi3f2KHDKsGWtA0+WCP1hI0q0CNhnwD4ASKq4Sh pj+kvHOtENvGwI4mkcwcnflUKH8lKdo= X-MC-Unique: FsN-gXJIOFWlwb418jX1Lw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 1/7] Introduce yank feature Date: Wed, 13 Jan 2021 10:30:55 +0100 Message-Id: <20210113093101.550964-2-armbru@redhat.com> In-Reply-To: <20210113093101.550964-1-armbru@redhat.com> References: <20210113093101.550964-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, lukasstraub2@web.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Lukas Straub The yank feature allows to recover from hanging qemu by "yanking" at various parts. Other qemu systems can register themselves and multiple yank functions. Then all yank functions for selected instances can be called by the 'yank' out-of-band qmp command. Available instances can be queried by a 'query-yank' oob command. Signed-off-by: Lukas Straub Acked-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Message-Id: <69934ceacfd33a7dfe53db145ecc630ad39ee47c.1609167865.git.lukass= traub2@web.de> Acked-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Markus Armbruster --- qapi/qapi-schema.json | 1 + qapi/yank.json | 119 ++++++++++++++++++++++++ include/qemu/yank.h | 97 ++++++++++++++++++++ util/yank.c | 207 ++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 7 ++ qapi/meson.build | 1 + util/meson.build | 1 + 7 files changed, 433 insertions(+) create mode 100644 qapi/yank.json create mode 100644 include/qemu/yank.h create mode 100644 util/yank.c 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=3Dpython +# + +## +# =3D 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 migrati= on +# 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 ex= ist +# +# 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/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 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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 ya= nk + * 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 funct= ion + * 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 app= ly + * 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 =3D YANK_INSTANCE_TYPE_BLOCK_NODE, \ + .u.block_node.node_name =3D (the_node_name) }) + +#define CHARDEV_YANK_INSTANCE(the_id) (&(YankInstance) { \ + .type =3D YANK_INSTANCE_TYPE_CHARDEV, \ + .u.chardev.id =3D (the_id) }) + +#define MIGRATION_YANK_INSTANCE (&(YankInstance) { \ + .type =3D YANK_INSTANCE_TYPE_MIGRATION }) + +#endif 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 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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 + =3D QLIST_HEAD_INITIALIZER(yank_instance_list); + +static bool yank_instance_equal(const YankInstance *a, const YankInstance = *b) +{ + if (a->type !=3D 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 =3D g_new0(YankInstanceEntry, 1); + entry->instance =3D 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 =3D 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 =3D yank_find_entry(instance); + assert(entry); + + func_entry =3D g_new0(YankFuncAndParam, 1); + func_entry->func =3D func; + func_entry->opaque =3D 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 =3D yank_find_entry(instance); + assert(entry); + + QLIST_FOREACH(func_entry, &entry->yankfns, next) { + if (func_entry->func =3D=3D func && func_entry->opaque =3D=3D opaq= ue) { + QLIST_REMOVE(func_entry, next); + g_free(func_entry); + return; + } + } + + abort(); +} + +void yank_generic_iochannel(void *opaque) +{ + QIOChannel *ioc =3D 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 =3D instances; tail; tail =3D tail->next) { + entry =3D yank_find_entry(tail->value); + if (!entry) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Instance not fo= und"); + return; + } + } + for (tail =3D instances; tail; tail =3D tail->next) { + entry =3D 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 =3D NULL; + + QEMU_LOCK_GUARD(&yank_lock); + QLIST_FOREACH(entry, &yank_instance_list, next) { + YankInstanceList *new_entry; + new_entry =3D g_new0(YankInstanceList, 1); + new_entry->value =3D QAPI_CLONE(YankInstance, entry->instance); + new_entry->next =3D ret; + ret =3D new_entry; + } + + return ret; +} + +static void __attribute__((__constructor__)) yank_init(void) +{ + qemu_mutex_init(&yank_lock); +} diff --git a/MAINTAINERS b/MAINTAINERS index 4be087b88e..ddbf0fc1e3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2732,6 +2732,13 @@ F: util/uuid.c F: include/qemu/uuid.h F: tests/test-uuid.c =20 +Yank feature +M: Lukas Straub +S: Odd fixes +F: util/yank.c +F: include/qemu/yank.h +F: qapi/yank.json + COLO Framework M: zhanghailiang S: Maintained 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 =3D [ 'trace', 'transaction', 'ui', + 'yank', ] =20 qapi_storage_daemon_modules =3D [ 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 =20 if have_system util_ss.add(when: 'CONFIG_GIO', if_true: [files('dbus.c'), gio]) + util_ss.add(files('yank.c')) endif =20 if have_block --=20 2.26.2 From nobody Thu Mar 28 17:05:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610530746; cv=none; d=zohomail.com; s=zohoarc; b=BQVeBbIkiAhSYNozbrtzKVbkCIqJ5QcEMl5/maIPEU595fk5kOxsdbpefMZY8npyWYc175wG6m9XraIJdpMXA/RkE5/wh3/g+R0HbcXpQmw8Pxc+nCclLjHZfE/tPDOguQRL1gBK5dX3Ip/HyYr599bR8FD4RtEjUMr6tFWetEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610530746; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VH0r/GZLW+747oKc/EuvS2rYYWlkaxPrcllC6yXz0X4=; b=SG2ub9dx+kmMLtp/ns1TG2PPaXofD3CMt7Fm+51Oh2eC6AFChmO7I32LwIO/jDBloPQw9+/ohX8Z+HeeBSjjg+M1mqhui7Eh3NiHCkzJ5ydJg7s7QcUgiaCcuEsORAK/fTQnm7KHegk9MZBx+MK67yHiQq4yR96DNUvK2oqRTdE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610530746758136.47640001459172; Wed, 13 Jan 2021 01:39:06 -0800 (PST) Received: from localhost ([::1]:39428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzccL-0005VP-9L for importer@patchew.org; Wed, 13 Jan 2021 04:39:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzcUn-0005na-TF for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kzcUi-0002wm-Vr for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-263-En7s5G6cOzGqFOslTUhcww-1; Wed, 13 Jan 2021 04:31:09 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BB7C1005D44; Wed, 13 Jan 2021 09:31:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 079456A916; Wed, 13 Jan 2021 09:31:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 877A311385FD; Wed, 13 Jan 2021 10:31:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610530271; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VH0r/GZLW+747oKc/EuvS2rYYWlkaxPrcllC6yXz0X4=; b=L0W+E5jZXJ0JmBbXD9d81rAAg3xRBwkiBU2PWsMq34DEuh4SEDs5hTjCWfX9CXxrP77G7U sv34NyhYxMib8yJH/dwz+ULPMLlo7tj7EWD6wRVOY59/kV0BxbUz6cfJf1nCc5VWaLc2S6 FSpmdZI/K2cTpXIoVaShQV4RaKZ5dIc= X-MC-Unique: En7s5G6cOzGqFOslTUhcww-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 2/7] block/nbd.c: Add yank feature Date: Wed, 13 Jan 2021 10:30:56 +0100 Message-Id: <20210113093101.550964-3-armbru@redhat.com> In-Reply-To: <20210113093101.550964-1-armbru@redhat.com> References: <20210113093101.550964-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, lukasstraub2@web.de, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Lukas Straub Register a yank function which shuts down the socket and sets s->state =3D NBD_CLIENT_QUIT. This is the same behaviour as if an error occured. Signed-off-by: Lukas Straub Acked-by: Stefan Hajnoczi Reviewed-by: Eric Blake Message-Id: Signed-off-by: Markus Armbruster --- block/nbd.c | 153 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 92 insertions(+), 61 deletions(-) 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" =20 #include "qapi/qapi-visit-sockets.h" #include "qapi/qmp/qstring.h" @@ -44,6 +45,8 @@ #include "block/nbd.h" #include "block/block_int.h" =20 +#include "qemu/yank.h" + #define EN_OPTSTR ":exportname=3D" #define MAX_NBD_REQUESTS 16 =20 @@ -141,14 +144,13 @@ typedef struct BDRVNBDState { NBDConnectThread *connect_thread; } BDRVNBDState; =20 -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 *s= addr, + 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 *si= oc, - Error **errp); +static int nbd_client_handshake(BlockDriverState *bs, Error **errp); +static void nbd_yank(void *opaque); =20 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 =3D=3D -EIO) { - if (s->state =3D=3D NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTED) { s->state =3D s->reconnect_delay ? NBD_CLIENT_CONNECTING_WAIT : NBD_CLIENT_CONNECTING_NOWAIT; } } else { - if (s->state =3D=3D NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTED) { qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); } s->state =3D NBD_CLIENT_QUIT; @@ -203,7 +205,7 @@ static void reconnect_delay_timer_cb(void *opaque) { BDRVNBDState *s =3D opaque; =20 - if (s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT) { + if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WAIT)= { s->state =3D 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) =20 static void reconnect_delay_timer_init(BDRVNBDState *s, uint64_t expire_ti= me_ns) { - if (s->state !=3D NBD_CLIENT_CONNECTING_WAIT) { + if (qatomic_load_acquire(&s->state) !=3D NBD_CLIENT_CONNECTING_WAIT) { return; } =20 @@ -260,7 +262,7 @@ static void nbd_client_attach_aio_context(BlockDriverSt= ate *bs, * s->connection_co is either yielded from nbd_receive_reply or from * nbd_co_reconnect_loop() */ - if (s->state =3D=3D NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTED) { qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), new_context); } =20 @@ -286,7 +288,7 @@ static void coroutine_fn nbd_client_co_drain_begin(Bloc= kDriverState *bs) =20 reconnect_delay_timer_del(s); =20 - if (s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT) { + if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WAIT)= { s->state =3D NBD_CLIENT_CONNECTING_NOWAIT; qemu_co_queue_restart_all(&s->free_sema); } @@ -337,13 +339,14 @@ static void nbd_teardown_connection(BlockDriverState = *bs) =20 static bool nbd_client_connecting(BDRVNBDState *s) { - return s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT || - s->state =3D=3D NBD_CLIENT_CONNECTING_NOWAIT; + NBDClientState state =3D qatomic_load_acquire(&s->state); + return state =3D=3D NBD_CLIENT_CONNECTING_WAIT || + state =3D=3D NBD_CLIENT_CONNECTING_NOWAIT; } =20 static bool nbd_client_connecting_wait(BDRVNBDState *s) { - return s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT; + return qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WA= IT; } =20 static void connect_bh(void *opaque) @@ -423,12 +426,12 @@ static void *connect_thread_func(void *opaque) return NULL; } =20 -static QIOChannelSocket *coroutine_fn +static int coroutine_fn nbd_co_establish_connection(BlockDriverState *bs, Error **errp) { + int ret; QemuThread thread; BDRVNBDState *s =3D bs->opaque; - QIOChannelSocket *res; NBDConnectThread *thr =3D s->connect_thread; =20 qemu_mutex_lock(&thr->mutex); @@ -445,10 +448,12 @@ nbd_co_establish_connection(BlockDriverState *bs, Err= or **errp) case CONNECT_THREAD_SUCCESS: /* Previous attempt finally succeeded in background */ thr->state =3D CONNECT_THREAD_NONE; - res =3D thr->sioc; + s->sioc =3D thr->sioc; thr->sioc =3D 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, Erro= r **errp) thr->state =3D CONNECT_THREAD_NONE; error_propagate(errp, thr->err); thr->err =3D NULL; - res =3D thr->sioc; + s->sioc =3D thr->sioc; thr->sioc =3D NULL; + if (s->sioc) { + yank_register_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), + nbd_yank, bs); + } + ret =3D (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 =3D NULL; + ret =3D -1; error_setg(errp, "Connection attempt cancelled by other operation"= ); break; =20 @@ -507,7 +517,7 @@ nbd_co_establish_connection(BlockDriverState *bs, Error= **errp) =20 qemu_mutex_unlock(&thr->mutex); =20 - return res; + return ret; } =20 /* @@ -560,7 +570,6 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDS= tate *s) { int ret; Error *local_err =3D NULL; - QIOChannelSocket *sioc; =20 if (!nbd_client_connecting(s)) { return; @@ -593,21 +602,22 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNB= DState *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 =3D NULL; object_unref(OBJECT(s->ioc)); s->ioc =3D NULL; } =20 - sioc =3D nbd_co_establish_connection(s->bs, &local_err); - if (!sioc) { + if (nbd_co_establish_connection(s->bs, &local_err) < 0) { ret =3D -ECONNREFUSED; goto out; } =20 bdrv_dec_in_flight(s->bs); =20 - ret =3D nbd_client_handshake(s->bs, sioc, &local_err); + ret =3D nbd_client_handshake(s->bs, &local_err); =20 if (s->drained) { s->wait_drained_end =3D true; @@ -639,7 +649,7 @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDS= tate *s) uint64_t timeout =3D 1 * NANOSECONDS_PER_SECOND; uint64_t max_timeout =3D 16 * NANOSECONDS_PER_SECOND; =20 - if (s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT) { + if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTING_WAIT)= { reconnect_delay_timer_init(s, qemu_clock_get_ns(QEMU_CLOCK_REALTIM= E) + s->reconnect_delay * NANOSECONDS_PER_SE= COND); } @@ -682,7 +692,7 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) int ret =3D 0; Error *local_err =3D NULL; =20 - while (s->state !=3D NBD_CLIENT_QUIT) { + while (qatomic_load_acquire(&s->state) !=3D 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. Thi= s is @@ -697,7 +707,7 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) nbd_co_reconnect_loop(s); } =20 - if (s->state !=3D NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) !=3D NBD_CLIENT_CONNECTED) { continue; } =20 @@ -752,6 +762,8 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) s->connection_co =3D 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 =3D 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); } =20 - if (s->state !=3D NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) !=3D NBD_CLIENT_CONNECTED) { rc =3D -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 =3D nbd_send_request(s->ioc, request); - if (rc >=3D 0 && s->state =3D=3D NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) =3D=3D NBD_CLIENT_CONNECTED && + rc >=3D 0) { if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { rc =3D -EIO; @@ -1128,7 +1141,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( s->requests[i].receiving =3D true; qemu_coroutine_yield(); s->requests[i].receiving =3D false; - if (s->state !=3D NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) !=3D 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 =3D NULL; - if (s->state !=3D NBD_CLIENT_CONNECTED) { + if (qatomic_load_acquire(&s->state) !=3D 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, } =20 /* Do not execute the body of NBD_FOREACH_REPLY_CHUNK for simple reply= . */ - if (nbd_reply_is_simple(reply) || s->state !=3D NBD_CLIENT_CONNECTED) { + if (nbd_reply_is_simple(reply) || + qatomic_load_acquire(&s->state) !=3D NBD_CLIENT_CONNECTED) { goto break_loop; } =20 @@ -1744,6 +1758,15 @@ static int nbd_client_reopen_prepare(BDRVReopenState= *state, return 0; } =20 +static void nbd_yank(void *opaque) +{ + BlockDriverState *bs =3D opaque; + BDRVNBDState *s =3D (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 =3D (BDRVNBDState *)bs->opaque; @@ -1756,52 +1779,53 @@ static void nbd_client_close(BlockDriverState *bs) nbd_teardown_connection(bs); } =20 -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 =3D (BDRVNBDState *)bs->opaque; =20 - sioc =3D qio_channel_socket_new(); - qio_channel_set_name(QIO_CHANNEL(sioc), "nbd-client"); + s->sioc =3D qio_channel_socket_new(); + qio_channel_set_name(QIO_CHANNEL(s->sioc), "nbd-client"); =20 - 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 =3D NULL; + return -1; } =20 - 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); =20 - return sioc; + return 0; } =20 -/* nbd_client_handshake takes ownership on sioc. On failure it is unref'ed= . */ -static int nbd_client_handshake(BlockDriverState *bs, QIOChannelSocket *si= oc, - 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 =3D (BDRVNBDState *)bs->opaque; AioContext *aio_context =3D bdrv_get_aio_context(bs); int ret; =20 trace_nbd_client_handshake(s->export); - - s->sioc =3D 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); =20 s->info.request_sizes =3D true; s->info.structured_reply =3D true; s->info.base_allocation =3D true; s->info.x_dirty_bitmap =3D g_strdup(s->x_dirty_bitmap); s->info.name =3D g_strdup(s->export ?: ""); - ret =3D nbd_receive_negotiate(aio_context, QIO_CHANNEL(sioc), s->tlscr= eds, + ret =3D nbd_receive_negotiate(aio_context, QIO_CHANNEL(s->sioc), s->tl= screds, 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 =3D NULL; return ret; } @@ -1834,7 +1858,7 @@ static int nbd_client_handshake(BlockDriverState *bs,= QIOChannelSocket *sioc, } =20 if (!s->ioc) { - s->ioc =3D QIO_CHANNEL(sioc); + s->ioc =3D QIO_CHANNEL(s->sioc); object_ref(OBJECT(s->ioc)); } =20 @@ -1850,9 +1874,11 @@ static int nbd_client_handshake(BlockDriverState *bs= , QIOChannelSocket *sioc, { NBDRequest request =3D { .type =3D NBD_CMD_DISC }; =20 - nbd_send_request(s->ioc ?: QIO_CHANNEL(sioc), &request); + nbd_send_request(s->ioc ?: QIO_CHANNEL(s->sioc), &request); =20 - object_unref(OBJECT(sioc)); + yank_unregister_function(BLOCKDEV_YANK_INSTANCE(bs->node_name), + nbd_yank, bs); + object_unref(OBJECT(s->sioc)); s->sioc =3D NULL; =20 return ret; @@ -2244,7 +2270,6 @@ static int nbd_open(BlockDriverState *bs, QDict *opti= ons, int flags, { int ret; BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - QIOChannelSocket *sioc; =20 ret =3D nbd_process_options(bs, options, errp); if (ret < 0) { @@ -2255,17 +2280,22 @@ static int nbd_open(BlockDriverState *bs, QDict *op= tions, int flags, qemu_co_mutex_init(&s->send_mutex); qemu_co_queue_init(&s->free_sema); =20 + if (!yank_register_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name), err= p)) { + return -EEXIST; + } + /* * establish TCP connection, return error if it fails * TODO: Configurable retry-until-timeout behaviour. */ - sioc =3D 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; } =20 - ret =3D nbd_client_handshake(bs, sioc, errp); + ret =3D 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 =3D bs->opaque; =20 nbd_client_close(bs); + yank_unregister_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name)); nbd_clear_bdrvstate(s); } =20 --=20 2.26.2 From nobody Thu Mar 28 17:05:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610530558; cv=none; d=zohomail.com; s=zohoarc; b=l6MjLo/m1aOIeNPqHqKGKhNBkrQn6/1BTioa8l8j8GNVjLoJ9T8EKrgcWiGkMAwZW1UcD9Ca1az21RMqUWm1XgZEXI/+ZcU0CLMS/HHBqnjYNX3LxMnUI0fEZfpqMTvvJGLik0m6pwUUqDX8fhqdc1QIGeOQgeMHfBjrI0/y1Hg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610530558; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dNoqFKciYpD2Rf40H647CpXZfveEzCJUnYLa1QVvBnY=; b=ABenMh7bDroKVTTawLDI/L0HjYVC8MW9pgVTOv5j45+EuBmWL5Uibd73pNiYOCAZtZX506iPmv2UHwlfnFq0GREpGQdgf6aJ8RO0yZ0JQYfHUPeL8zyRPYwXzUuJVMJeGl4KJWzpoNQCZt4w7ZCIAwJ+SOy9Q6pBHRyS82VNau8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161053055813233.94332447191675; Wed, 13 Jan 2021 01:35:58 -0800 (PST) Received: from localhost ([::1]:33182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzcZJ-0002lS-0V for importer@patchew.org; Wed, 13 Jan 2021 04:35:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzcUp-0005qk-5r for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kzcUn-0002yx-93 for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-433-NcLqVPx8NBSCB93BlhHSbw-1; Wed, 13 Jan 2021 04:31:12 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 586C21005D44; Wed, 13 Jan 2021 09:31:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D44270484; Wed, 13 Jan 2021 09:31:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8B9841138613; Wed, 13 Jan 2021 10:31:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610530276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dNoqFKciYpD2Rf40H647CpXZfveEzCJUnYLa1QVvBnY=; b=QMGyNdA8AVUEaJLPeAy+ny5FRYyv4VbwHY/0NBamfGccU8j9jP0S9n8d8hNPFSaWzLn0j6 wvA2PxUPcOjZQ/K6CPuIJWeVp172sDEhn4cGotktwWy5Nk7alQf8ymXPYaUB/zpcilh6/p ViB8jfmXPdMD3UH7Z3Jfd7IMR7OeNYc= X-MC-Unique: NcLqVPx8NBSCB93BlhHSbw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 3/7] chardev/char-socket.c: Add yank feature Date: Wed, 13 Jan 2021 10:30:57 +0100 Message-Id: <20210113093101.550964-4-armbru@redhat.com> In-Reply-To: <20210113093101.550964-1-armbru@redhat.com> References: <20210113093101.550964-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, lukasstraub2@web.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Lukas Straub Register a yank function to shutdown the socket on yank. Signed-off-by: Lukas Straub Acked-by: Stefan Hajnoczi Message-Id: <1f4eeed1d066c6cbb8d05ffa9585f6e87b34aac6.1609167865.git.lukass= traub2@web.de> Acked-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Markus Armbruster --- chardev/char-socket.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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" =20 #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; =20 SocketAddress *addr; bool is_listen; @@ -415,6 +417,12 @@ static void tcp_chr_free_connection(Chardev *chr) =20 tcp_set_msgfds(chr, NULL, 0); remove_fd_in_watch(chr); + if (s->state =3D=3D TCP_CHARDEV_STATE_CONNECTING + || s->state =3D=3D 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 =3D 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 =3D tcp_chr_new_client(chr, sioc); object_unref(OBJECT(sioc)); return ret; @@ -946,6 +957,9 @@ static void tcp_chr_accept(QIONetListener *listener, =20 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); } =20 @@ -961,6 +975,9 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Er= ror **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 =3D 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)); + } =20 qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } @@ -1101,6 +1124,9 @@ static void qemu_chr_socket_connected(QIOTask *task, = void *opaque) =20 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 =3D 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); } =20 + if (!yank_register_instance(CHARDEV_YANK_INSTANCE(chr->label), errp)) { + return; + } + s->registered_yank =3D true; + /* be isn't opened until we get a connection */ *be_opened =3D false; =20 --=20 2.26.2 From nobody Thu Mar 28 17:05:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610530401; cv=none; d=zohomail.com; s=zohoarc; b=mqn99KiUmVaN2h57L/DiBIsNrx+4T8hdufFmqXcyD4/3dkppRnPleESMw+0juK/jzS9KEqe8nlz/zA38K3g7RDaQv2JmfpZlP0Bn6qElWddNJLdvUXHbdpv939tgU2SayRmLM1qVM5EzghTkw4QuSI9KyR1OhtdLX30rlFmE0aA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610530401; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=U+mhYbQMvbCArKcO6oUbSAe+a6SOuQxc5n96c2USsKo=; b=DXOd2XZVtsVtnC3TX7ksOwrTcDKY/nhve+O1bdB4lymb92E0QKMg37MkIht9vGWEEn8C1ObJG3NKMQQhAc7gM6dlR4cDPIGl8mj9cZpQU+d0Y4r0ZJuzNUl/R5Y4iiqXHC70Y658R1wK7ZHqCRJB3TCE5vvbnDTgbzjqQnCMfwQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610530401022382.5006743439509; Wed, 13 Jan 2021 01:33:21 -0800 (PST) Received: from localhost ([::1]:52706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzcWk-0007Vs-AM for importer@patchew.org; Wed, 13 Jan 2021 04:33:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzcUm-0005mF-UU for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kzcUh-0002w7-5j for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:16 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-231-V8RSYQyONaOe4lBUV_DyEg-1; Wed, 13 Jan 2021 04:31:08 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9CFD800050; Wed, 13 Jan 2021 09:31:06 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1637560938; Wed, 13 Jan 2021 09:31:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8F8881138617; Wed, 13 Jan 2021 10:31:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610530270; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U+mhYbQMvbCArKcO6oUbSAe+a6SOuQxc5n96c2USsKo=; b=VBb9J4QWtUYRS7OWJenxFj+EPRYSQDZL3Eeiu56lQGixBQzcIUkl4er2al0y0MiP8g310I WPr4OVy609gg/zOZPXTO6Altaep+Z18Ztuc2lgRHC+lMaa5fkuAC1K2USPV6FoCc09t1ye 5TBE3vUdRj6yFCMvXEMKbwS9ijouakw= X-MC-Unique: V8RSYQyONaOe4lBUV_DyEg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 4/7] migration: Add yank feature Date: Wed, 13 Jan 2021 10:30:58 +0100 Message-Id: <20210113093101.550964-5-armbru@redhat.com> In-Reply-To: <20210113093101.550964-1-armbru@redhat.com> References: <20210113093101.550964-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, lukasstraub2@web.de, "Dr . David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Lukas Straub Register yank functions on sockets to shut them down. Signed-off-by: Lukas Straub Acked-by: Stefan Hajnoczi Acked-by: Dr. David Alan Gilbert Message-Id: <484c6a14cc2506bebedd5a237259b91363ff8f88.1609167865.git.lukass= traub2@web.de> Signed-off-by: Markus Armbruster --- migration/channel.c | 13 +++++++++++++ migration/migration.c | 22 ++++++++++++++++++++++ migration/multifd.c | 10 ++++++++++ migration/qemu-file-channel.c | 7 +++++++ migration/savevm.c | 5 +++++ 5 files changed, 57 insertions(+) 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" =20 /** * @migration_channel_process_incoming - Create new incoming migration cha= nnel @@ -35,6 +37,11 @@ void migration_channel_process_incoming(QIOChannel *ioc) trace_migration_set_incoming_channel( ioc, object_get_typename(OBJECT(ioc))); =20 + if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET)) { + yank_register_function(MIGRATION_YANK_INSTANCE, yank_generic_iocha= nnel, + 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); =20 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" =20 #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 =3D NULL; } + + yank_unregister_instance(MIGRATION_YANK_INSTANCE); } =20 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 =3D NULL; =20 + 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 *u= ri, 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); } =20 static void migrate_fd_cleanup_schedule(MigrationState *s) @@ -2005,6 +2014,7 @@ void qmp_migrate_recover(const char *uri, Error **err= p) * 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); } =20 @@ -2148,6 +2158,12 @@ void qmp_migrate(const char *uri, bool has_blk, bool= blk, return; } =20 + 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, } =20 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" =20 +#include "qemu/yank.h" +#include "io/channel-socket.h" + /* Multiple fd's */ =20 #define MULTIFD_MAGIC 0x11223344U @@ -974,6 +977,13 @@ int multifd_load_cleanup(Error **errp) for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 + if (object_dynamic_cast(OBJECT(p->c), TYPE_QIO_CHANNEL_SOCKET) + && OBJECT(p->c)->ref =3D=3D 1) { + yank_unregister_function(MIGRATION_YANK_INSTANCE, + yank_generic_iochannel, + QIO_CHANNEL(p->c)); + } + object_unref(OBJECT(p->c)); p->c =3D 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" =20 =20 static ssize_t channel_writev_buffer(void *opaque, @@ -104,6 +105,12 @@ static int channel_close(void *opaque, Error **errp) int ret; QIOChannel *ioc =3D QIO_CHANNEL(opaque); ret =3D qio_channel_close(ioc, errp); + if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) + && OBJECT(ioc)->ref =3D=3D 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" =20 const unsigned int postcopy_ram_discard_version; =20 @@ -3006,6 +3007,10 @@ int load_snapshot(const char *name, Error **errp) qemu_system_reset(SHUTDOWN_CAUSE_NONE); mis->from_src_file =3D f; =20 + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { + ret =3D -EINVAL; + goto err_drain; + } aio_context_acquire(aio_context); ret =3D qemu_loadvm_state(f); migration_incoming_state_destroy(); --=20 2.26.2 From nobody Thu Mar 28 17:05:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610530397; cv=none; d=zohomail.com; s=zohoarc; b=BWqcufpYyaSP2C7zn8QGQ5jSHCI8B040EBr6velnCSG5hGpMFkNmLm/10t8Y2MJveUua1PyE/R2BofQ/QQhsDfM2UmMi1WDVQ71uPBO7ftMkZECnsSAJkYCXjaJ4Jt9PVvSARJ+oT3h37gnAxU7LV4xcB+Y+wXzIZSwUiO6DIZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610530397; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZKde8W3EpFqNiZbJkhG/VYyyMlyPl64FhJ8VI+Q8VaY=; b=cxHEfzxQsT31FKUW65cz255g/M2olI1gB7RivnZ/KsQtxZnAznSv3hto8p2OOfpci/X5uvHezCZOiIQqAL2S1q7jxrVEpz+USS/1c58KZdvh6dfvFjcsPZcB9hh4u1zSw+NGa0deLRVLURWwFD2VCi2cOV6fc8HDdOg4PNi+fMY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610530397185106.91787794858237; Wed, 13 Jan 2021 01:33:17 -0800 (PST) Received: from localhost ([::1]:52682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzcWg-0007VJ-JF for importer@patchew.org; Wed, 13 Jan 2021 04:33:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzcUm-0005lC-5r for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kzcUj-0002wx-NC for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-377-iW7rXPx5OGmMvARSdIqlAQ-1; Wed, 13 Jan 2021 04:31:10 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D735DF8B0; Wed, 13 Jan 2021 09:31:09 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D27681F04F; Wed, 13 Jan 2021 09:31:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 92BEF11385A7; Wed, 13 Jan 2021 10:31:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610530272; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZKde8W3EpFqNiZbJkhG/VYyyMlyPl64FhJ8VI+Q8VaY=; b=gah5PQXeU78z9RQhaLJylaij9VT7vXYb+09u7ovX8Cg3o/W0XPFQXpMrE06libCJHNbAa0 4WCbmMJvUgI+LWlgj3AMKiZR9ozEo3H0QAeksMptyI6CXGFLua8OrALn/geYbkXresqsWJ BcWT0Pcp2xvokgJJ5NqlWpsPimOMnqo= X-MC-Unique: iW7rXPx5OGmMvARSdIqlAQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 5/7] io/channel-tls.c: make qio_channel_tls_shutdown thread-safe Date: Wed, 13 Jan 2021 10:30:59 +0100 Message-Id: <20210113093101.550964-6-armbru@redhat.com> In-Reply-To: <20210113093101.550964-1-armbru@redhat.com> References: <20210113093101.550964-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, lukasstraub2@web.de, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Lukas Straub Make qio_channel_tls_shutdown thread-safe by using atomics when accessing tioc->shutdown. Signed-off-by: Lukas Straub Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <5bd8733f583f3558b32250fd0eb576b7aa756485.1609167865.git.lukass= traub2@web.de> Signed-off-by: Markus Armbruster --- io/channel-tls.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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" =20 =20 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 =3D=3D ECONNABORTED && - (tioc->shutdown & QIO_CHANNEL_SHUTDOWN_READ)) { + (qatomic_load_acquire(&tioc->shutdown) & + QIO_CHANNEL_SHUTDOWN_READ)) { return 0; } =20 @@ -361,7 +363,7 @@ static int qio_channel_tls_shutdown(QIOChannel *ioc, { QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(ioc); =20 - tioc->shutdown |=3D how; + qatomic_or(&tioc->shutdown, how); =20 return qio_channel_shutdown(tioc->master, how, errp); } --=20 2.26.2 From nobody Thu Mar 28 17:05:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610530401; cv=none; d=zohomail.com; s=zohoarc; b=IZOJDdfzwhERSShZn1DcyWhbvoEbuNdi0rbNTfxvZc/lSVVW8XG4Vh0UeSxxJtmAp/mht1Bqm/n1eULfzagiWhjBHO/stMIdLWwYNqN+5YDNweVPuJGQb1Djbki0XaG245G4kMZ3B5vPt+quNmcWBbLBKhn0eaB17jcQEstculc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610530401; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IwhUUFzbg9bxLgP6Y/HDhmKvFlmJO9629jp0xXZpajA=; b=lnqb3UlD4Kd9kzlDUY478nhH/cfFcOvg8KzA/EO2gYRvB/UG2LJMwJsqvJnH4REypQWCBQwNeYlhqhkDo6gfXoE11CUiPqSw/IdplxQYnHAX38CvCXhSqUyLlQw8jsr5J99QqUUwMo8CrBvBilWtWBPxC5luw7WFn0F9oIlAT18= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610530401129941.0381514771929; Wed, 13 Jan 2021 01:33:21 -0800 (PST) Received: from localhost ([::1]:52662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzcWk-0007Uo-Bm for importer@patchew.org; Wed, 13 Jan 2021 04:33:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzcUl-0005ko-Qd for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25383) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kzcUj-0002wu-EA for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-572-5JF5nUnsPZ6o6LFW6UOPqg-1; Wed, 13 Jan 2021 04:31:10 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A550C802B49; Wed, 13 Jan 2021 09:31:09 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D28D660C0F; Wed, 13 Jan 2021 09:31:04 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 980CE11385CB; Wed, 13 Jan 2021 10:31:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610530272; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IwhUUFzbg9bxLgP6Y/HDhmKvFlmJO9629jp0xXZpajA=; b=Rs645PrU011HYbthzSy8Ugg4zZ/aU8jzveEMa2mnLxdm2lQASY1wFlePsftljfL20rALhM aRsBWoyXLyk7Cs0VSNy8tZaIWgWfCZehIZJyOlqSWnBug5opBq1RGztU/Msq2PQkmDws/i g0T9w0EaLJFTkQL54CzLGVolS3X/Y8A= X-MC-Unique: 5JF5nUnsPZ6o6LFW6UOPqg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 6/7] io: Document qmp oob suitability of qio_channel_shutdown and io_shutdown Date: Wed, 13 Jan 2021 10:31:00 +0100 Message-Id: <20210113093101.550964-7-armbru@redhat.com> In-Reply-To: <20210113093101.550964-1-armbru@redhat.com> References: <20210113093101.550964-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, lukasstraub2@web.de, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Lukas Straub Migration and yank code assume that qio_channel_shutdown is thread -safe and can be called from qmp oob handler. Document this after checking the code. Signed-off-by: Lukas Straub Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <32b8c27e256da043f0f00db05bd7ab8fbc506070.1609167865.git.lukass= traub2@web.de> Signed-off-by: Markus Armbruster --- include/io/channel.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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, --=20 2.26.2 From nobody Thu Mar 28 17:05:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610530553; cv=none; d=zohomail.com; s=zohoarc; b=fLyN/Fx/WRg/W1uA/O6ZNx2NXaJNL2XYept4wvu1gxTrFdkTc97YXRdu5m7df5qEXyxHKQqrK97Sy0iUgeny3T4yHcerwX62/KgnKzwXouW/vtwcTV2o/gpqdz83KDgVsRCSnOnZRN0RrHCg27PdWYZkKKc4t7HC1MU6XS50Rco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610530553; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h75iak/bbCWrSRfC26SSu6eLIUokCgUIkNAwELbATaE=; b=QXWY5BNgwUSmTzQMxtYTkvZAMIY941MkgpyN7RTQ/YGqUb42FrT1jtTBXW/dbefsCx3O3CtxaMvTAEcgSB1FunIPFrgb3vP1aj7StT1+PZ09LvLIc69FgpfCPitcRIyqN75VIl/TSRAmMQ9oyR40+TfHzeXifXA85BW4xt/q4mI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610530553504426.3300483063384; Wed, 13 Jan 2021 01:35:53 -0800 (PST) Received: from localhost ([::1]:33002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzcZE-0002gB-3t for importer@patchew.org; Wed, 13 Jan 2021 04:35:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzcUq-0005tN-8p for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50101) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kzcUk-0002xe-CD for qemu-devel@nongnu.org; Wed, 13 Jan 2021 04:31:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-PbiSRMNoO4mWY0y3fmePdw-1; Wed, 13 Jan 2021 04:31:09 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52233DF8A5; Wed, 13 Jan 2021 09:31:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EE0E1002393; Wed, 13 Jan 2021 09:31:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9B92411385D4; Wed, 13 Jan 2021 10:31:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610530273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h75iak/bbCWrSRfC26SSu6eLIUokCgUIkNAwELbATaE=; b=bC5FJe2Oo6oZgaF1PWFIqia27n4Lrr56EydH4QUIN895jLsKMnhfNOeRQGEP6zCWVDaO4m 2ZkixZBOcHNA5weenqa7JSxqHZsD7wqo86D9ReKXS2jP9L6oojeAi+8HrCwf+SlJ3ZuSHG j3iPSjP9ICQhWbaseLJfDglPDUGS8tI= X-MC-Unique: PbiSRMNoO4mWY0y3fmePdw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 7/7] tests/test-char.c: Wait for the chardev to connect in char_socket_client_dupid_test Date: Wed, 13 Jan 2021 10:31:01 +0100 Message-Id: <20210113093101.550964-8-armbru@redhat.com> In-Reply-To: <20210113093101.550964-1-armbru@redhat.com> References: <20210113093101.550964-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, lukasstraub2@web.de, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Lukas Straub A connecting chardev object has an additional reference by the connecting thread, so if the chardev is still connecting by the end of the test, then the chardev object won't be freed. This in turn means that the yank instance won't be unregistered and when running the next test-case yank_register_instance will abort, because the yank instance is already/still registered. Signed-off-by: Lukas Straub Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <1445e97a5800e3f2ba024ad52b500a0315701632.1609167865.git.lukass= traub2@web.de> Signed-off-by: Markus Armbruster --- tests/test-char.c | 1 + 1 file changed, 1 insertion(+) 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 =3D qemu_chr_new_from_opts(opts, NULL, &error_abort); g_assert_nonnull(chr1); + qemu_chr_wait_connected(chr1, &error_abort); =20 chr2 =3D qemu_chr_new_from_opts(opts, NULL, &local_err); g_assert_null(chr2); --=20 2.26.2