From patchwork Wed May 20 21:05:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11561581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6CA9C739 for ; Wed, 20 May 2020 21:09:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 341F320829 for ; Wed, 20 May 2020 21:09:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="Ms1jlobG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 341F320829 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbVxr-0005oX-4X for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 May 2020 17:09:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbVuP-0002Gi-CX; Wed, 20 May 2020 17:05:49 -0400 Received: from mout.web.de ([212.227.17.11]:51459) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbVuO-0002S2-4a; Wed, 20 May 2020 17:05:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1590008742; bh=tqkhTpmFcfXP/udx2L1FFDKOb54iXy6N2msQCYMji5Y=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=Ms1jlobGBOHIjoUuD2sCRdDMWkdz8UtsEP0LOKhBoIOACAquLgkDK9db3HmFj/8Kw 1wCY9xYbQ/5V++/D40iyesHJAa4eUiX+JOMAhz3lao9d2jIEGXNm5FHkzpo/7vy4fa 94F7z4kfd3NlSn2K3dr2I0E6WTARwkev1YtQDALA= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([88.130.61.105]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MRCnT-1jUBWV3meN-00UWX2; Wed, 20 May 2020 23:05:41 +0200 Date: Wed, 20 May 2020 23:05:39 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v2 1/4] Introduce yank feature Message-ID: <20005a15c708fbda983f9be602c55fc0b1979a18.1590008051.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:YGPfmkpSDnW8lNP4O/ZXcylaYIeQqOBkBTY+EERF6pj/7GGo5d3 zAD8nu/K4eSW4U3p+aMYi2AKxhbY9BgTk98SSAVdR2tqbgilxoLKx77fGQUQO3ZiNgYzI33 mPOAUzp48e6z1xmaVbqPz8qdzsQD/ztzwFlvhwXLm+d7ByBnldL02cvDzhUslawoQLCFa0Q roEkQxL/0Oi/as0xRpVXA== X-UI-Out-Filterresults: notjunk:1;V03:K0:ShOSo1su23Q=:LTyuxCXuKUHicytMKr1HX7 xOlBkbhjLRW3GjscR0nLUV6X2Ag5HWQ6xYu/TDsnEsJCyiU3nSQ+RmWuCNL0EJIhWennvlfuA 4adD3FwgU1YDWencb559v+WFJKAo7ac+Uvv4BXwPP03+kmiJu44YIW5GsNjn25M/hqXIRGjXH 3ZOzOVD8HJTK93j0T1nKWSNdv9+FYzLtZk7rUQ044S37Jk3JAeyibOGqhDH28CxGML5aDmWCI 5vWjJM0XESKNdHxusQdBwKrTmScuzttrkNQWfEjFIWq/Ij5vRPfB+7qbACFIfQNp/rbwMbE9R V1KFKTSNzJZynZQTCdE7bHI4qEc/1+Sb2L5dWVreXDBsdrZplbNiE8x9+Ysv/Qm5fCuF+N4aj RsPPPwcVwTaiyEZ3agoK/04MxVEVsjZQHwfzRwcWQZ6kLnlCmBxqCtMOJfVo0a20/6UyxOQLT V6J3wJcN/duR8532XzuGE0Jqq/RLzk29BhIJyig3bHsrGVL+OZjkeX1FKKP5FzA3fuIXIAF2D Tv+Xc8ZtMBFO+DGYm10341DX3QJokPvKm9sFp5BzCeD2Ij+IznBl2J2GQ9P9VLy5vxLN0A3Il 6yAKi903+/G/ZsqbAgXZZhlSVAmr57mo8Bs7v+cs43hmlALosHN75l7tWmA6/P9Gi0cyKZmEl BvK3nGc9tMGm6uWCrRrM/YA7vOEQ8sEFNZSQNPW9QmFyWDO3I2qRHni3Z/CFnuwjertX2oBmT q1FwQWu/M5GB8S3zxvFWb2R4NkjLgYfk6XOLgSvAywa9Y69M2vD4B0c6xreMW+Y0Qe3rWbx6f v0CTWzeaA4uz4xtEZUlVP5bnDwpBsNx7kQJewtN/SsKifO7l2mbvLluJtBcOQJ0TgPTmPulGn AHEeUprC8+LhX34HtrXhyilFJRRUmTj3I2ZrV5Hww1S3uXrYDh8GTNiXhvsTKQgjN9QfOVaio sYtlr7GPl6+e0+58fBs6J44ploRQjJhvr0xwKdYd5i35L1ilDZBi2OgcrgUsmyfkJ3qTT5p7Z itAK3rpULjccKoB7j3NiA7onJSPubRoVUAk2NKUNOXIUuwiDZoPumELmZCFR5+Fysycspbn2x kdNS34dbYNgG0RtELlstkyUvl7t61/6yWfvhLsBIy6/oINYNPOT5fSmMGrhXM6IF8bB8GRJjc 8CtI64pmeZyTJ8CjzhpNI4y8Vkre+1wTu1b24+biEJYEM2VQdj/aKOP9TIijobAWumrZXdapn H/sMGL++pvG/qpTAp Received-SPF: pass client-ip=212.227.17.11; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 16:42:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Kevin Wolf , "Daniel P. =?utf-8?b?QmVycmFuZ8Op?= " , qemu-block , Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- qapi/misc.json | 45 +++++++++++++ softmmu/vl.c | 2 + yank.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++ yank.h | 69 ++++++++++++++++++++ 4 files changed, 290 insertions(+) create mode 100644 yank.c create mode 100644 yank.h -- 2.20.1 diff --git a/qapi/misc.json b/qapi/misc.json index 99b90ac80b..f5228b2502 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1550,3 +1550,48 @@ ## { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' } +## +# @YankInstances: +# +# @instances: List of yank instances. +# +# Yank instances are named after the following schema: +# "blockdev:", "chardev:" and "migration" +# +# Since: 5.1 +## +{ 'struct': 'YankInstances', 'data': {'instances': ['str'] } } + +## +# @yank: +# +# Recover from hanging qemu by yanking the specified instances. +# +# Takes @YankInstances as argument. +# +# Returns: nothing. +# +# Example: +# +# -> { "execute": "yank", "arguments": { "instances": ["blockdev:nbd0"] } } +# <- { "return": {} } +# +# Since: 5.1 +## +{ 'command': 'yank', 'data': 'YankInstances', 'allow-oob': true } + +## +# @query-yank: +# +# Query yank instances. +# +# Returns: @YankInstances +# +# Example: +# +# -> { "execute": "query-yank" } +# <- { "return": { "instances": ["blockdev:nbd0"] } } +# +# Since: 5.1 +## +{ 'command': 'query-yank', 'returns': 'YankInstances', 'allow-oob': true } diff --git a/softmmu/vl.c b/softmmu/vl.c index 32c0047889..5d99749d29 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -112,6 +112,7 @@ #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" #include "qemu/guest-random.h" +#include "yank.h" #define MAX_VIRTIO_CONSOLES 1 @@ -2906,6 +2907,7 @@ void qemu_init(int argc, char **argv, char **envp) precopy_infrastructure_init(); postcopy_infrastructure_init(); monitor_init_globals(); + yank_init(); if (qcrypto_init(&err) < 0) { error_reportf_err(err, "cannot initialize crypto: "); diff --git a/yank.c b/yank.c new file mode 100644 index 0000000000..bfce19185e --- /dev/null +++ b/yank.c @@ -0,0 +1,174 @@ +/* + * QEMU yank feature + * + * Copyright (c) Lukas Straub + * + * 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 "qapi/qapi-commands-misc.h" +#include "io/channel.h" +#include "yank.h" + +struct YankFuncAndParam { + YankFn *func; + void *opaque; + QLIST_ENTRY(YankFuncAndParam) next; +}; + +struct YankInstance { + char *name; + QLIST_HEAD(, YankFuncAndParam) yankfns; + QLIST_ENTRY(YankInstance) next; +}; + +static QemuMutex lock; +static QLIST_HEAD(yankinst_list, YankInstance) head + = QLIST_HEAD_INITIALIZER(head); + +static struct YankInstance *yank_find_instance(char *name) +{ + struct YankInstance *tmp, *instance; + instance = NULL; + QLIST_FOREACH(tmp, &head, next) { + if (!strcmp(tmp->name, name)) { + instance = tmp; + } + } + return instance; +} + +void yank_register_instance(char *instance_name) +{ + struct YankInstance *instance; + + qemu_mutex_lock(&lock); + assert(!yank_find_instance(instance_name)); + + instance = g_slice_new(struct YankInstance); + instance->name = g_strdup(instance_name); + QLIST_INIT(&instance->yankfns); + QLIST_INSERT_HEAD(&head, instance, next); + + qemu_mutex_unlock(&lock); +} + +void yank_unregister_instance(char *instance_name) +{ + struct YankInstance *instance; + + qemu_mutex_lock(&lock); + instance = yank_find_instance(instance_name); + assert(instance); + + assert(QLIST_EMPTY(&instance->yankfns)); + QLIST_REMOVE(instance, next); + g_free(instance->name); + g_slice_free(struct YankInstance, instance); + + qemu_mutex_unlock(&lock); +} + +void yank_register_function(char *instance_name, YankFn *func, void *opaque) +{ + struct YankInstance *instance; + struct YankFuncAndParam *entry; + + qemu_mutex_lock(&lock); + instance = yank_find_instance(instance_name); + assert(instance); + + entry = g_slice_new(struct YankFuncAndParam); + entry->func = func; + entry->opaque = opaque; + + QLIST_INSERT_HEAD(&instance->yankfns, entry, next); + qemu_mutex_unlock(&lock); +} + +void yank_unregister_function(char *instance_name, YankFn *func, void *opaque) +{ + struct YankInstance *instance; + struct YankFuncAndParam *entry; + + qemu_mutex_lock(&lock); + instance = yank_find_instance(instance_name); + assert(instance); + + QLIST_FOREACH(entry, &instance->yankfns, next) { + if (entry->func == func && entry->opaque == opaque) { + QLIST_REMOVE(entry, next); + g_slice_free(struct YankFuncAndParam, entry); + qemu_mutex_unlock(&lock); + 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(strList *instances, Error **errp) +{ + strList *tmp; + struct YankInstance *instance; + struct YankFuncAndParam *entry; + + qemu_mutex_lock(&lock); + tmp = instances; + for (; tmp; tmp = tmp->next) { + instance = yank_find_instance(tmp->value); + if (!instance) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Instance '%s' not found", tmp->value); + qemu_mutex_unlock(&lock); + return; + } + } + tmp = instances; + for (; tmp; tmp = tmp->next) { + instance = yank_find_instance(tmp->value); + assert(instance); + QLIST_FOREACH(entry, &instance->yankfns, next) { + entry->func(entry->opaque); + } + } + qemu_mutex_unlock(&lock); +} + +YankInstances *qmp_query_yank(Error **errp) +{ + struct YankInstance *instance; + YankInstances *ret; + + ret = g_new0(YankInstances, 1); + ret->instances = NULL; + + qemu_mutex_lock(&lock); + QLIST_FOREACH(instance, &head, next) { + strList *entry; + entry = g_new0(strList, 1); + entry->value = g_strdup(instance->name); + entry->next = ret->instances; + ret->instances = entry; + } + qemu_mutex_unlock(&lock); + + return ret; +} + +void yank_init(void) +{ + qemu_mutex_init(&lock); +} diff --git a/yank.h b/yank.h new file mode 100644 index 0000000000..f01b370999 --- /dev/null +++ b/yank.h @@ -0,0 +1,69 @@ + +#ifndef YANK_H +#define 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_name: The globally unique name of the instance. + */ +void yank_register_instance(char *instance_name); + +/** + * 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_name: The name of the instance. + */ +void yank_unregister_instance(char *instance_name); + +/** + * 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. + * + * This function is thread-safe. + * + * @instance_name: The name of the instance + * @func: The yank function + * @opaque: Will be passed to the yank function + */ +void yank_register_function(char *instance_name, YankFn *func, void *opaque); + +/** + * yank_unregister_function: Unregister a yank function + * + * This unregisters a yank function. + * + * This function is thread-safe. + * + * @instance_name: The name of the instance + * @func: func that was passed to yank_register_function + * @opaque: opaque that was passed to yank_register_function + */ +void yank_unregister_function(char *instance_name, YankFn *func, void *opaque); + +/** + * yank_unregister_function: 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); + +void yank_init(void); +#endif From patchwork Wed May 20 21:05:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11561611 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA6A090 for ; Wed, 20 May 2020 21:15:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8129320748 for ; Wed, 20 May 2020 21:15:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="m1cg9iv2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8129320748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:52488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbW45-0002o3-Ft for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 May 2020 17:15:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbVuS-0002Is-1T; Wed, 20 May 2020 17:05:52 -0400 Received: from mout.web.de ([212.227.15.14]:46407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbVuQ-0002SG-MM; Wed, 20 May 2020 17:05:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1590008744; bh=/xFb+uwZk6b6GLotHwOBOfo+Z5J6TuKbIQZ+zdDqQSY=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=m1cg9iv2biN/b7i5k5H1ZaNVymcYmh3qhSeVi9LxLhjbdJ3My4cRmFzJOG1Yh4R2H 9h0fr/2M7L6f/pYYIGrTOLoY7df8hr2n94PvFo7E7LL3FUrzvve4BwxbrZp7kowhae 3DYBRls6eswRgV3yMqMfhcPxh/Wyg0uv0fOL9dK4= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([88.130.61.105]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LmcRH-1j2RwJ202N-00aERs; Wed, 20 May 2020 23:05:44 +0200 Date: Wed, 20 May 2020 23:05:43 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v2 2/4] block/nbd.c: Add yank feature Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:mzWudhdfZSmBzlRnmCnIFlMRj4vwfVepF7bxb0Hzre35Wgs2WjU NGlaUDderD4pRynxQIwa1KWPBF43kacvdFjvhod6aOM9k6Vz3yQsrfBxvGbJR5mlUntA803 fI7xtuQayqJjKZLxECHxr/t56uZaCmYCMdJNB0ue7ge2/4jc+Fuab6AsZtEThVJEmRnZ0ID APZMMXZi32kGS0uymobQw== X-UI-Out-Filterresults: notjunk:1;V03:K0:7B3JV0olYJc=:bfoxVDfTURBl2uJb/mDmTE jqfZ+6L73fc0yB8U8Y0ku4VASCpiHOXObd90Xq4gB2Gxhp0gdfdIHG2ZH8mybh6gEhzeXvmQG cGlarUiEwFHd6bqYLYNf2OP8NInPFPHa2g/HaE4crNHmRPS0USbsmELRa7aCzbpipUhNvzcG8 3JrDWP0UgO4iBS+FW+hT1+h2Vh+uks9Nludw6iSrbeVA+yoKGnkiyCUgKYfvdqLU6h0swX3BV ot4xdceNxdKnXN3p+IQ3ac47eeAvzdFirrWPCZE/Lrp1huzkKdZHqtJSNnJkgSw8zbkDaTx7f bb/BaPy4Aqq34rfCKCTqot9nhCzTNAcFOlx4ZzSKGDrq/mdUstXl5nmdRhcn9q1xQCjP2efFi xptVSb5FWeOkN34ozwHhXnQ9kR2AfR/gVPTNgzRHcQXWCylC5oWBh+gTVm4BbWogzXcQZkrrF YkFVHCaZ+ylhwILcSl0MTqjJRMKHSmfYWxCj2Nfy9861uWb18wSxwtBuZALP4m1wMnH4opdT4 HC2rjkycSBtwovge9wRBV18LG9Dpl/iulcbqPrK/B/JdGvIts39sGi6kcP/0s5OiSSBddk9Lv H3MwJ6Xu7QJXgcSUT23fJmfd0P6tbqun/RKr6OEvhhJw0nupz0RUITK0FH2Lj8ExuaJiES7hd sEH4jWYen65r4OLpflZhnDtmFlx3wRNA7zHOLi56RoB6OVzu/DLgkR7wYIQq5lCzbCpVlWevk iJ0HAuTnlelxCPFfUcjIWMzs76GQwi0c+7Mh+K31g3DoKEp+IYqY6AHintzxVup/s3SP5cudG j8c+f2BMtxznN3w3Xzlu4vuFBxNRohy+mnstpS4q/duWSTO39+yrK8K+oMjBk14oYyI6EBX1l /1cIbszzhdDoxVIl8aBfRTlFhWUnSRQSn1vojQqpYsiUm0VRNLVbQGjAatm1jR6m+THTVwtJw xYLw0bn3Qa+y4ZDyVzJLKWIzCkX3YFAsIHFVSXGR6+b/wWWaUe6aafLZvPgyyEq9hfi5SMbB/ zxohfLTypDZq6SLYFkmT8DnorhjWS1SFXB5s4bC80jnj803GJdHPAF9y2cdHuYXOX7bjOBqTK c218vKSAPhqz1SNzqHEaz+cM+LCxFgrV61S3SIhtaDRo2R79Oi1xQ+gGKk/4wCEjdHOhPxL5z PV03PFrk/IjZJMzYSBWAU8pvAwid6iAJgsysAg6kSU/IQCdfwZjaeElZzxcVt8Uwqgjtx9o1P hRvToQP4mskJMx2Fe Received-SPF: pass client-ip=212.227.15.14; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 16:42:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Kevin Wolf , "Daniel P. =?utf-8?b?QmVycmFuZ8Op?= " , qemu-block , Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Register a yank function which shuts down the socket and sets s->state = NBD_CLIENT_QUIT. This is the same behaviour as if an error occured. Signed-off-by: Lukas Straub --- Makefile.objs | 1 + block/nbd.c | 101 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 37 deletions(-) -- 2.20.1 diff --git a/Makefile.objs b/Makefile.objs index a7c967633a..8e403b81f3 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -18,6 +18,7 @@ block-obj-y += block.o blockjob.o job.o block-obj-y += block/ scsi/ block-obj-y += qemu-io-cmds.o block-obj-$(CONFIG_REPLICATION) += replication.o +block-obj-y += yank.o block-obj-m = block/ diff --git a/block/nbd.c b/block/nbd.c index 2160859f64..3a41749f1b 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" @@ -43,6 +44,8 @@ #include "block/nbd.h" #include "block/block_int.h" +#include "yank.h" + #define EN_OPTSTR ":exportname=" #define MAX_NBD_REQUESTS 16 @@ -84,6 +87,8 @@ typedef struct BDRVNBDState { NBDReply reply; BlockDriverState *bs; + char *yank_name; + /* Connection parameters */ uint32_t reconnect_delay; SocketAddress *saddr; @@ -94,6 +99,7 @@ typedef struct BDRVNBDState { } BDRVNBDState; static int nbd_client_connect(BlockDriverState *bs, Error **errp); +static void nbd_yank(void *opaque); static void nbd_clear_bdrvstate(BDRVNBDState *s) { @@ -106,17 +112,19 @@ static void nbd_clear_bdrvstate(BDRVNBDState *s) s->tlscredsid = NULL; g_free(s->x_dirty_bitmap); s->x_dirty_bitmap = NULL; + g_free(s->yank_name); + s->yank_name = NULL; } static void nbd_channel_error(BDRVNBDState *s, int ret) { if (ret == -EIO) { - if (s->state == NBD_CLIENT_CONNECTED) { + if (atomic_read(&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 (atomic_read(&s->state) == NBD_CLIENT_CONNECTED) { qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); } s->state = NBD_CLIENT_QUIT; @@ -167,7 +175,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 (atomic_read(&s->state) == NBD_CLIENT_CONNECTED) { qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), new_context); } @@ -206,7 +214,7 @@ static void nbd_teardown_connection(BlockDriverState *bs) { BDRVNBDState *s = (BDRVNBDState *)bs->opaque; - if (s->state == NBD_CLIENT_CONNECTED) { + if (atomic_read(&s->state) == NBD_CLIENT_CONNECTED) { /* finish any pending coroutines */ assert(s->ioc); qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); @@ -230,13 +238,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 = atomic_read(&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 atomic_read(&s->state) == NBD_CLIENT_CONNECTING_WAIT; } static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) @@ -274,6 +283,7 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) /* Finalize previous connection if any */ if (s->ioc) { nbd_client_detach_aio_context(s->bs); + yank_unregister_function(s->yank_name, nbd_yank, s->bs); object_unref(OBJECT(s->sioc)); s->sioc = NULL; object_unref(OBJECT(s->ioc)); @@ -305,7 +315,7 @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s) nbd_reconnect_attempt(s); while (nbd_client_connecting(s)) { - if (s->state == NBD_CLIENT_CONNECTING_WAIT && + if (atomic_read(&s->state) == NBD_CLIENT_CONNECTING_WAIT && qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start_time_ns > delay_ns) { s->state = NBD_CLIENT_CONNECTING_NOWAIT; @@ -341,7 +351,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque) int ret = 0; Error *local_err = NULL; - while (s->state != NBD_CLIENT_QUIT) { + while (atomic_read(&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 @@ -356,7 +366,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque) nbd_co_reconnect_loop(s); } - if (s->state != NBD_CLIENT_CONNECTED) { + if (atomic_read(&s->state) != NBD_CLIENT_CONNECTED) { continue; } @@ -411,6 +421,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque) s->connection_co = NULL; if (s->ioc) { nbd_client_detach_aio_context(s->bs); + yank_unregister_function(s->yank_name, nbd_yank, s->bs); object_unref(OBJECT(s->sioc)); s->sioc = NULL; object_unref(OBJECT(s->ioc)); @@ -435,7 +446,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 (atomic_read(&s->state) != NBD_CLIENT_CONNECTED) { rc = -EIO; goto err; } @@ -462,7 +473,7 @@ 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 (rc >= 0 && atomic_read(&s->state) == NBD_CLIENT_CONNECTED) { if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { rc = -EIO; @@ -777,7 +788,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 (atomic_read(&s->state) != NBD_CLIENT_CONNECTED) { error_setg(errp, "Connection closed"); return -EIO; } @@ -936,7 +947,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 (atomic_read(&s->state) != NBD_CLIENT_CONNECTED) { error_setg(&local_err, "Connection closed"); nbd_iter_channel_error(iter, -EIO, &local_err); goto break_loop; @@ -961,7 +972,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) || + atomic_read(&s->state) != NBD_CLIENT_CONNECTED) { goto break_loop; } @@ -1395,6 +1407,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; + + qio_channel_shutdown(QIO_CHANNEL(s->sioc), QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + atomic_set(&s->state, NBD_CLIENT_QUIT); +} + static void nbd_client_close(BlockDriverState *bs) { BDRVNBDState *s = (BDRVNBDState *)bs->opaque; @@ -1407,25 +1428,29 @@ 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) { - QIOChannelSocket *sioc; + BDRVNBDState *s = (BDRVNBDState *)bs->opaque; Error *local_err = NULL; - 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"); + yank_register_function(s->yank_name, nbd_yank, bs); - qio_channel_socket_connect_sync(sioc, saddr, &local_err); + qio_channel_socket_connect_sync(s->sioc, saddr, &local_err); if (local_err) { - object_unref(OBJECT(sioc)); + yank_unregister_function(s->yank_name, nbd_yank, bs); + object_unref(OBJECT(s->sioc)); + s->sioc = NULL; error_propagate(errp, local_err); - return NULL; + return -1; } - qio_channel_set_delay(QIO_CHANNEL(sioc), false); + qio_channel_set_delay(QIO_CHANNEL(s->sioc), false); - return sioc; + return 0; } static int nbd_client_connect(BlockDriverState *bs, Error **errp) @@ -1438,28 +1463,27 @@ static int nbd_client_connect(BlockDriverState *bs, Error **errp) * establish TCP connection, return error if it fails * TODO: Configurable retry-until-timeout behaviour. */ - QIOChannelSocket *sioc = nbd_establish_connection(s->saddr, errp); - - if (!sioc) { + if (nbd_establish_connection(bs, s->saddr, errp) < 0) { return -ECONNREFUSED; } /* NBD handshake */ trace_nbd_client_connect(s->export); - 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(s->yank_name, nbd_yank, bs); + object_unref(OBJECT(s->sioc)); return ret; } if (s->x_dirty_bitmap && !s->info.base_allocation) { @@ -1485,10 +1509,8 @@ static int nbd_client_connect(BlockDriverState *bs, Error **errp) } } - s->sioc = sioc; - if (!s->ioc) { - s->ioc = QIO_CHANNEL(sioc); + s->ioc = QIO_CHANNEL(s->sioc); object_ref(OBJECT(s->ioc)); } @@ -1504,9 +1526,10 @@ static int nbd_client_connect(BlockDriverState *bs, Error **errp) { 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(s->yank_name, nbd_yank, bs); + object_unref(OBJECT(s->sioc)); return ret; } @@ -1913,6 +1936,9 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, qemu_co_mutex_init(&s->send_mutex); qemu_co_queue_init(&s->free_sema); + s->yank_name = g_strconcat("blockdev:", bs->node_name, NULL); + yank_register_instance(s->yank_name); + ret = nbd_client_connect(bs, errp); if (ret < 0) { nbd_clear_bdrvstate(s); @@ -1972,6 +1998,7 @@ static void nbd_close(BlockDriverState *bs) BDRVNBDState *s = bs->opaque; nbd_client_close(bs); + yank_unregister_instance(s->yank_name); nbd_clear_bdrvstate(s); } From patchwork Wed May 20 21:05:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11561579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A848739 for ; Wed, 20 May 2020 21:08:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 31D8720829 for ; Wed, 20 May 2020 21:08:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="RWPpcALT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31D8720829 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbVws-0004Va-8A for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 May 2020 17:08:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbVuV-0002Lp-6R; Wed, 20 May 2020 17:05:55 -0400 Received: from mout.web.de ([212.227.17.11]:44687) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbVuU-0002Se-7K; Wed, 20 May 2020 17:05:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1590008748; bh=sDjR+yB4Sa8Fjus9eFBoA6y68LMtxEpQOMPCGsUwKO4=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=RWPpcALTQ2rbUoui3GrM5Vtt2XrhGw6OC0cKUSRIA1IWgsHntBOQPQxRcRhN4anOS +KbeLr7Ul8ntS3AX0X2QI/KaQEhe84YMQdk3sV6c4mlyhATrhFX+ubHC3c7OUU5UgH 3PGXJBnhVXXeDdV7BoXkMrbP8bmFmPuswHx19rf4= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([88.130.61.105]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MDdyH-1jjWW31eIp-00ArTE; Wed, 20 May 2020 23:05:48 +0200 Date: Wed, 20 May 2020 23:05:47 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v2 3/4] chardev/char-socket.c: Add yank feature Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:DHrEwcV8UvTN1AYvO9yej2jPOHHiEVQkm8UNKmXMdX5YpBuOyxC QEIJ4rDBv0mxmXqIFn3REfGFX0owMfYrJ4PwwY7wcouz2xubB0QK4gNOe2uovnkWiXYHZej FWmcq2uE75wNo5BNcOlBo2Rlmu/ggTo3AhWV90VScaaxvY7AvO5b9/kMhILmzhde3FlB7KM /uXRCpwPnHOYn/kt/drNg== X-UI-Out-Filterresults: notjunk:1;V03:K0:O1KCSz03cNA=:xZpjl4gq2AkDVxZ3/Go0Li czSRpZhhwSBOp4c+8Zd5rw3wSasn5q8eQ+DJlD3X+baWOwncUts8dSCaHZILSQG1HHDG5lBus lPAR0XQDT+2x2Pv6hqkN1ogrH39zlLmArDTPieehn7/MZhlLgBntnAN6WWxwn7Zjh1f4StKM4 0dHF5R8oI7tl/ehq5oqf8hpFDudeQukgoFgY4qr64atizx4m722WgGfvetaX9bDgpSUNWZqDS mgJffGS0js+hCf3TwuEn9Cx0lriEIXbhgJnNHtAIU88/npUoB4pryNcabkX+8eIejA9vvQvu9 KTsHTSYN/oXCU/+C+fYWCNtjuk7cHYs+FYNr3Cc9IfAAOk4Gvj+H5Xpi3tPL0qTJnaB1YfIwZ DLf8PvzugqoSSu2HACHd71Wt3/BkyB9vdAJgn69JwHpSNio4KF+k3k0tLb+HHVcvaUXtcGXmh UEKBufLUhytgYjMTQoQo89vyEOKfqf8IKps8U4+HDg2kJqI7co3U+AkK7gImdjVylNC6IcvDw D/g4R4KislMc/DFLHKuo13YivcpBEkt2nrnacpJhobAQntvwzjSW4/O3cFc8Y8fK5ZPcG1HPi WXmCZvQLrxu8C9VZp72z8hnVhMosYKEsPM+iyumz7kxc0tsZmCIu7Nu63dzwAqZeK1QVJjDo1 /5DIwyhMwgjd86zPQn8V1Ewi+ZXs/lJw5meIfwMMKdFnCLIlHeu4ffLPTrwxdfSm17Q5xZELK hN5cO6ZvpRFaw0htjx0QFVDDgJwiK9olke2bNXe3riJ4FFPew5W1Wd7KCqq147+Si3Wj8AhFm UDYRejWK+AP0j6vlZNpzyrLA5Qgubk+Yu4Pe25bPXAuuM1FhwKilpM9WEcvJOfjsaiz9mm2Nv fqU665foznaz3LH6T4fhCDz3JrxhPm8gC2SVSVYJIABM+YIaT1yMCKeGfkRLJ9VNAWua9GGnf 2zn7WUUWCsze6o6G8yLh5ajiHgJ2nBDng1AvmBI2CrKybl5NwqrJUaNAm2snrxoiaAcA/aC5g ahgm5z3c/5W6rQY2YBWobz4pcj2VOIzYa9ntLRWHxWa8qBcVoF31w/OP51KrD8kDvnPYucsO2 wjFATZjZqE0THhJbaWqORiMfKborIPu/xDXucsF5l3n7Tiuw4y/ryGzwCSb1pgQP4vdqsEnDZ 5CviqN+5KmR31DvogRybENn3ap9GaAB46hr0X2uIVj1uYvSUolL0A6uYr45K0t51zqnVxTFFQ 9xcGNB/ej+UpzEvJL Received-SPF: pass client-ip=212.227.17.11; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 16:42:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Kevin Wolf , "Daniel P. =?utf-8?b?QmVycmFuZ8Op?= " , qemu-block , Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Register a yank function to shutdown the socket on yank. Signed-off-by: Lukas Straub --- chardev/char-socket.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) -- 2.20.1 diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 185fe38dda..d5c6cd2153 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 "yank.h" #include "chardev/char-io.h" @@ -69,6 +70,7 @@ typedef struct { size_t read_msgfds_num; int *write_msgfds; size_t write_msgfds_num; + char *yank_name; SocketAddress *addr; bool is_listen; @@ -409,6 +411,11 @@ 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(s->yank_name, yank_generic_iochannel, + QIO_CHANNEL(s->sioc)); + } object_unref(OBJECT(s->sioc)); s->sioc = NULL; object_unref(OBJECT(s->ioc)); @@ -912,6 +919,8 @@ 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(s->yank_name, yank_generic_iochannel, + QIO_CHANNEL(sioc)); ret = tcp_chr_new_client(chr, sioc); object_unref(OBJECT(sioc)); return ret; @@ -926,6 +935,8 @@ 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(s->yank_name, yank_generic_iochannel, + QIO_CHANNEL(cioc)); tcp_chr_new_client(chr, cioc); } @@ -941,6 +952,8 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp) object_unref(OBJECT(sioc)); return -1; } + yank_register_function(s->yank_name, yank_generic_iochannel, + QIO_CHANNEL(sioc)); tcp_chr_new_client(chr, sioc); object_unref(OBJECT(sioc)); return 0; @@ -956,6 +969,8 @@ 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(s->yank_name, yank_generic_iochannel, + QIO_CHANNEL(sioc)); tcp_chr_new_client(chr, sioc); object_unref(OBJECT(sioc)); } @@ -1066,6 +1081,8 @@ static void char_socket_finalize(Object *obj) object_unref(OBJECT(s->tls_creds)); } g_free(s->tls_authz); + yank_unregister_instance(s->yank_name); + g_free(s->yank_name); qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } @@ -1081,6 +1098,8 @@ 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(s->yank_name, yank_generic_iochannel, + QIO_CHANNEL(sioc)); check_report_connect_error(chr, err); error_free(err); goto cleanup; @@ -1115,6 +1134,8 @@ 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(s->yank_name, 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 @@ -1356,6 +1377,9 @@ static void qmp_chardev_open_socket(Chardev *chr, qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS); } + s->yank_name = g_strconcat("chardev:", chr->label, NULL); + yank_register_instance(s->yank_name); + /* be isn't opened until we get a connection */ *be_opened = false; From patchwork Wed May 20 21:05:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11561613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB7D490 for ; Wed, 20 May 2020 21:15:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B24E220829 for ; Wed, 20 May 2020 21:15:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="jN8JQPuk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B24E220829 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:52526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbW46-0002ou-Ll for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 May 2020 17:15:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbVuY-0002OT-CZ; Wed, 20 May 2020 17:05:58 -0400 Received: from mout.web.de ([212.227.15.3]:45821) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbVuX-0002Sw-AG; Wed, 20 May 2020 17:05:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1590008752; bh=ZT5paGKoMkxQIIK3do9eYhtJlP8tDd8KzO7ihZmKyFg=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=jN8JQPukWhbroWA6Nhx6lWlgaewQxPeY4r5MqilJIrGlITpSm+E9kwMvmFpN7sds5 UDxjZTT8N5H0W9gtbbCOENLrXeF1AXPqK7GB/5chdyelH0x1kMZkJxUPZU3iyls+XX jH/xOUeGzwxzL+bgjY2XH9POmJUA+orvI9zZVMdg= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([88.130.61.105]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MWeGR-1jZfAi40VP-00XweA; Wed, 20 May 2020 23:05:52 +0200 Date: Wed, 20 May 2020 23:05:50 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v2 4/4] migration: Add yank feature Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:OED8SphvAPMlmwdWiFINwLgEeKhUa5E5Vr0SVmxdzdgTzU3dPbQ cFsDGo84lys4jxKwIRC2AzMfb0HAvnHuwy1ATFJnPkwbfK5zNuQn/A9lfc7ICgdBJpvSIf1 acEIvJHEDkYUZeZ4M7m2EtAK+n/6VOHWrAHWo42K9NcWTx7S6YL/J7OUaauOt5ARMeaaCZF cyV6ROAEn2kKPnO9EG/Kg== X-UI-Out-Filterresults: notjunk:1;V03:K0:0iO+pklncoo=:u/XEMv949gD4atgEnMt3J2 3cfAWwqgaKN4FAAT9ACuMh7+RnYOS+n81/cBqD9/GGzOuKHzTaX3nCt8VROWcUS5HdYWfrnUN beB1AQzo9lxyBp6PNh3rImNE8WEjLaMEFaO8uxaPbWbkijK9VCn7bX3KitZLoFmg9i6M+vJAk o0qqQg0Qm86WUOL/54dOUKu8VW3ekHdXrRWdpGLm6v8vwTXZyAfZkOs6eMYUBHRi/e8vIXQ5T eT8EnqWTYZpLCzmDkBG8celKFDiyOY2bZzZnEKcHVk6bbpLrmnMQQlExYnLTr9OnEPjY1Tx9i bdBpBXVgiviwfBg27ITE8sSYldomSfKi9dQY9Tn9yTpp3EK5wDe/v/Yy8OlDGXbIfLZl+Dln0 gkTaiRSlGB10dXf/a51AMjffj5tmMNqrnXsS5anRXhEn3ZYwlLAFkIjVujdtzMoM0de9I9Ho1 zAGawGe17AQZknq3swYBfMm+njnvWc6kiWZi83n6GfgkRtwIGyrU0t9G/g7cLWRPggSQcN+22 HQedScU9ad/QSQTNlZV4I18kNzwBqN4oj8wtup5IpbMvJ9KK8JYM8MljloEdntVMpRT6fn/GU 4BttCmUhYor97Y521TO90f6s7pD2kuuIs7vnjj3QN6MjF2CnwZcQOL+zfUS1qVreBZzzz1tuV Q1vfh1QqKXfvW3lmpeki1lnxEDI4TXC+a4Le0DFCJB+T7xIqTc0rjxkO3BrK1hfSG6cZROXZQ uBQhYUXKg/6fHSWwUaeCluNAQk5UJCwfQQraPCk+rsv4N6lgbyyeDiDouGdi14trSKOXIbzJJ U7UxUZW5P6Nc+IBz82teOIMQwgSW4BJO0eXnfKdRKpnfD5m4A9HPOJ1ygkwUE3LkkhN3DhEOX lc6eTsQZYaPFlCqTmSOkTUESAxbFb3CjgthLDRAxlM+u34QAhDbTKM1HN2rYirMOnMQq/S+Vx svJTABr1fiKrAo54dGJJNraT5RzTHqVuZUfxJsOieA2f8MuJLYX+7EfvINnrXhk5nR2j2KN77 85wtDmqbItOY645AXu2oyM36/WQTtGampOnQ5YTPsVwnhsmEf/sZmIW2wD45LXsqjhyCnbhJO 5ZIetpe7XkRkQxljRCUrRiO419RIXDj05SbkOAFBQhz006ir4I0l4qPTrWiJTY7X1EzBGtU6n 5v/6X9B4az/JdbJOaW/OiHkUeIEUGrl8L73Znx2YzFiEG+7q6SeC2a/s7fwg+8I+berZBjqPl ltPleRJ0DxvEzZEtK Received-SPF: pass client-ip=212.227.15.3; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 16:42:20 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Kevin Wolf , "Daniel P. =?utf-8?b?QmVycmFuZ8Op?= " , qemu-block , Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Register yank functions on sockets to shut them down. Signed-off-by: Lukas Straub --- migration/migration.c | 9 +++++++++ migration/qemu-file-channel.c | 6 ++++++ migration/socket.c | 11 +++++++++++ 3 files changed, 26 insertions(+) -- 2.20.1 diff --git a/migration/migration.c b/migration/migration.c index 187ac0410c..f89fcba198 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -54,6 +54,7 @@ #include "net/announce.h" #include "qemu/queue.h" #include "multifd.h" +#include "yank.h" #define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttling */ @@ -231,6 +232,8 @@ void migration_incoming_state_destroy(void) qapi_free_SocketAddressList(mis->socket_address_list); mis->socket_address_list = NULL; } + + yank_unregister_instance((char *) "migration"); } static void migrate_generate_event(int new_state) @@ -362,6 +365,7 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) const char *p; qapi_event_send_migration(MIGRATION_STATUS_SETUP); + yank_register_instance((char *) "migration"); if (!strcmp(uri, "defer")) { deferred_incoming_migration(errp); } else if (strstart(uri, "tcp:", &p)) { @@ -377,6 +381,7 @@ 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((char *) "migration"); error_setg(errp, "unknown migration protocol: %s", uri); } } @@ -1632,6 +1637,7 @@ static void migrate_fd_cleanup(MigrationState *s) } notifier_list_notify(&migration_state_notifiers, s); block_cleanup_parameters(s); + yank_unregister_instance((char *) "migration"); } static void migrate_fd_cleanup_schedule(MigrationState *s) @@ -2036,6 +2042,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, return; } + yank_register_instance((char *) "migration"); if (strstart(uri, "tcp:", &p)) { tcp_start_outgoing_migration(s, p, &local_err); #ifdef CONFIG_RDMA @@ -2049,6 +2056,7 @@ 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 { + yank_unregister_instance((char *) "migration"); error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, @@ -2058,6 +2066,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } if (local_err) { + yank_unregister_instance((char *) "migration"); migrate_fd_error(s, local_err); error_propagate(errp, local_err); return; diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index d2ce32f4b9..6224bda029 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 "yank.h" static ssize_t channel_writev_buffer(void *opaque, @@ -104,6 +105,11 @@ 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 == 2) { + yank_unregister_function((char *) "migration", yank_generic_iochannel, + QIO_CHANNEL(ioc)); + } object_unref(OBJECT(ioc)); return ret; } diff --git a/migration/socket.c b/migration/socket.c index 97c9efde59..bbca53cc49 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -26,6 +26,7 @@ #include "io/channel-socket.h" #include "io/net-listener.h" #include "trace.h" +#include "yank.h" struct SocketOutgoingArgs { @@ -35,6 +36,8 @@ struct SocketOutgoingArgs { void socket_send_channel_create(QIOTaskFunc f, void *data) { QIOChannelSocket *sioc = qio_channel_socket_new(); + yank_register_function((char *) "migration", yank_generic_iochannel, + QIO_CHANNEL(sioc)); qio_channel_socket_connect_async(sioc, outgoing_args.saddr, f, data, NULL, NULL); } @@ -42,6 +45,8 @@ void socket_send_channel_create(QIOTaskFunc f, void *data) int socket_send_channel_destroy(QIOChannel *send) { /* Remove channel */ + yank_unregister_function((char *) "migration", yank_generic_iochannel, + QIO_CHANNEL(send)); object_unref(OBJECT(send)); if (outgoing_args.saddr) { qapi_free_SocketAddress(outgoing_args.saddr); @@ -101,6 +106,8 @@ static void socket_outgoing_migration(QIOTask *task, Error *err = NULL; if (qio_task_propagate_error(task, &err)) { + yank_unregister_function((char *) "migration", yank_generic_iochannel, + QIO_CHANNEL(sioc)); trace_migration_socket_outgoing_error(error_get_pretty(err)); } else { trace_migration_socket_outgoing_connected(data->hostname); @@ -127,6 +134,8 @@ static void socket_start_outgoing_migration(MigrationState *s, } qio_channel_set_name(QIO_CHANNEL(sioc), "migration-socket-outgoing"); + yank_register_function((char *) "migration", yank_generic_iochannel, + QIO_CHANNEL(sioc)); qio_channel_socket_connect_async(sioc, saddr, socket_outgoing_migration, @@ -163,6 +172,8 @@ static void socket_accept_incoming_migration(QIONetListener *listener, trace_migration_socket_incoming_accepted(); qio_channel_set_name(QIO_CHANNEL(cioc), "migration-socket-incoming"); + yank_register_function((char *) "migration", yank_generic_iochannel, + QIO_CHANNEL(cioc)); migration_channel_process_incoming(QIO_CHANNEL(cioc)); if (migration_has_all_channels()) {