From patchwork Mon May 11 11:14:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11540247 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 A4EAB15AB for ; Mon, 11 May 2020 11:18:25 +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 7B1EA20722 for ; Mon, 11 May 2020 11:18:25 +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="Ls5hh1hN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B1EA20722 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]:59688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jY6S0-0002yu-DJ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 11 May 2020 07:18:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jY6OT-0000Nb-FK; Mon, 11 May 2020 07:14:45 -0400 Received: from mout.web.de ([212.227.17.11]:45173) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jY6OS-0006pG-Er; Mon, 11 May 2020 07:14:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1589195679; bh=69isl/oloXKqCgT1lMh7Rv9glCgzyS4DtmEifV3kP2Y=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=Ls5hh1hNeY5R9PSRPcu0l8xb9iP8cgvDfwuYZvKhzmNCphsc7EhdeNzPh+ZWkJdPq dCSB3itY0opts2furo1sGH4TKfZcTZ5FKyqe3sf8UNJePEkPDXIJErsD5+Y5ajV6GS 9JCYXCkygiweynZ0ncWoGRc+3+1JFqEdPwGiOCNg= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([89.247.255.192]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1N7gXQ-1j40SL0KZe-014gPR; Mon, 11 May 2020 13:14:39 +0200 Date: Mon, 11 May 2020 13:14:37 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH 1/5] Introduce yank feature Message-ID: <99931d0c9ab23eb641bd612e154f007348afa690.1589193717.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:MJUelbv6jUA0wE0LZky0xBVwVS9C3aZj3VVV3jOfm7HZnRG5Mm0 QY4q73Ow6G9i6DBZaNmccKdFCL1AX30vLnN6xSvjqoz+5KKVGTaW3EnBk7InpRL+7DXpsV7 vkK3cI+w8qTBbaAiavTEpyhT0IIx7R2OAA2LPBtZxfh4qS+gBnZ4Cq3BvXLi/R8KyHKOM1q tBB6JTCxGYekgDGRQnAFg== X-UI-Out-Filterresults: notjunk:1;V03:K0:zVbW5lOgWBg=:0lyFw7JO3+DbF/yjYHeZDj SVyQQI0VVcepf5xP72yT5xqOJoKSQUtL0KbNIEaVgm5LqI2Srzhit0q/Fg5RA0dV0T/GTK4Dc ds1ePzZWf1lcXlCkY1R+Fgi7KpZksphPoLvDIGK1Dkng6JGlxyBSkYMpS7PF7iBZgyLi2phw+ DVOr6PfmZql8DqngKZBpWM/dBEQ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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/11 07:14:43 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 yank functions which will be called by the 'yank' out-of-band qmp command. Signed-off-by: Lukas Straub --- qapi/misc.json | 15 ++++++++++ softmmu/vl.c | 2 ++ yank.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ yank.h | 12 ++++++++ 4 files changed, 104 insertions(+) create mode 100644 yank.c create mode 100644 yank.h diff --git a/qapi/misc.json b/qapi/misc.json index 99b90ac80b..de1ee494ae 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1550,3 +1550,18 @@ ## { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' } +## +# @yank: +# +# Recover from hanging qemu by calling yank functions. +# +# Returns: nothing. +# +# Example: +# +# -> { "execute": "yank" } +# <- { "return": {} } +# +# Since: 5.1 +## +{ 'command': 'yank', '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..cefbfd8ab5 --- /dev/null +++ b/yank.c @@ -0,0 +1,75 @@ +/* + * 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 "yank.h" + +struct YankFuncAndParam { + YankFn *func; + void *opaque; + QLIST_ENTRY(YankFuncAndParam) next; +}; + +static QemuMutex lock; +static QLIST_HEAD(qlisthead, YankFuncAndParam) head + = QLIST_HEAD_INITIALIZER(head); + +void yank_register_function(YankFn *func, void *opaque) +{ + struct YankFuncAndParam *tmp = g_malloc(sizeof(struct YankFuncAndParam)); + tmp->func = func; + tmp->opaque = opaque; + + qemu_mutex_lock(&lock); + QLIST_INSERT_HEAD(&head, tmp, next); + qemu_mutex_unlock(&lock); +} + +void yank_unregister_function(YankFn *func, void *opaque) +{ + qemu_mutex_lock(&lock); + + struct YankFuncAndParam *tmp; + QLIST_FOREACH(tmp, &head, next) { + if (tmp->func == func && tmp->opaque == opaque) { + QLIST_REMOVE(tmp, next); + g_free(tmp); + qemu_mutex_unlock(&lock); + return; + } + } + + abort(); +} + +void yank_call_functions(void) +{ + qemu_mutex_lock(&lock); + + struct YankFuncAndParam *tmp; + QLIST_FOREACH(tmp, &head, next) { + tmp->func(tmp->opaque); + } + + qemu_mutex_unlock(&lock); +} + +void qmp_yank(Error **errp) +{ + yank_call_functions(); +} + +void yank_init(void) +{ + qemu_mutex_init(&lock); + QLIST_INIT(&head); +} diff --git a/yank.h b/yank.h new file mode 100644 index 0000000000..7376224219 --- /dev/null +++ b/yank.h @@ -0,0 +1,12 @@ + +#ifndef YANK_H +#define YANK_H + +typedef void (YankFn) (void *opaque); + +void yank_register_function(YankFn *func, void *opaque); +void yank_unregister_function(YankFn *func, void *opaque); +void yank_call_functions(void); +void yank_init(void); +void qmp_yank(Error **errp); +#endif