From patchwork Thu Jan 30 12:34:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357869 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 AE3B1139A for ; Thu, 30 Jan 2020 12:36:10 +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 8470B206F0 for ; Thu, 30 Jan 2020 12:36:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GZC188vD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8470B206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix93J-0007Wr-L6 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:36:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54495) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92N-0005ac-CJ for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92L-0004VP-Kk for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:11 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:60657 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92K-0004OK-Ed for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387702; 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=yZ9hXAgel0JCQem0cV9DcJj66tjzrqDTdBjSfttmMJw=; b=GZC188vDxY3MPRFaGthc2Z//sYpTcxHer66GezKvpyeos/E1Rnmr2t9JNBJSFwNIRVtAQk +8A4jTiVrGaB+IDSsapl8UMS2Me5xcxvsYKLU7Jm5Kt74yZOXs7osaRJcqlgkMCgutACVI cXSKKgulahi9VvawowxmcG0AnnxiYMs= 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-209-elGd1-CeOZmyyFN9IxoBhw-1; Thu, 30 Jan 2020 07:34:58 -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 467E5107ACC4; Thu, 30 Jan 2020 12:34:57 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4499C19756; Thu, 30 Jan 2020 12:34:55 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 01/11] usb/dev-storage: remove unused include Date: Thu, 30 Jan 2020 14:34:38 +0200 Message-Id: <20200130123448.21093-2-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: elGd1-CeOZmyyFN9IxoBhw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Philippe Mathieu-Daudé --- hw/usb/dev-storage.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index 90da008df1..5629213d55 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -19,7 +19,6 @@ #include "hw/scsi/scsi.h" #include "ui/console.h" #include "migration/vmstate.h" -#include "monitor/monitor.h" #include "sysemu/sysemu.h" #include "sysemu/block-backend.h" #include "qapi/visitor.h" From patchwork Thu Jan 30 12:34:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357867 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 850BF92A for ; Thu, 30 Jan 2020 12:36:03 +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 5C088206F0 for ; Thu, 30 Jan 2020 12:36:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VjpNTvRq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C088206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix93C-0007MB-IK for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:36:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54497) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92N-0005ae-Cf for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92M-0004XC-AW for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:11 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:25141 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92M-0004R1-6s for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xIB5EKz/PP52nepCG9ZIBf61jVupUOv7U1wULQeWDdA=; b=VjpNTvRqy1+hgfumobsWF69BdzaXotxit/DkzYGEtuM/1A3GzIm6eBt6bQUoZRVRSylzxV TdIS8pbKNbB866g+PgqwbiCTMvQHnLUoxPCqSh3IDXIlBgxlZb2xubidYxxj9w+bpFncYO k8wihcXlaBA6cWbicIr81PXOOiYOdOc= 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-15-yUKiICx_MR2KgsZ-giPTQg-1; Thu, 30 Jan 2020 07:35:00 -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 A12FB100550E; Thu, 30 Jan 2020 12:34:59 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0A6E167A3; Thu, 30 Jan 2020 12:34:57 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 02/11] monitor/hmp: uninline add_init_drive Date: Thu, 30 Jan 2020 14:34:39 +0200 Message-Id: <20200130123448.21093-3-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: yUKiICx_MR2KgsZ-giPTQg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This is only used by hmp_drive_add. The code is just a bit shorter this way. No functional changes Signed-off-by: Maxim Levitsky Reviewed-by: Markus Armbruster --- device-hotplug.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/device-hotplug.c b/device-hotplug.c index f01d53774b..554e4d98db 100644 --- a/device-hotplug.c +++ b/device-hotplug.c @@ -34,42 +34,35 @@ #include "monitor/monitor.h" #include "block/block_int.h" -static DriveInfo *add_init_drive(const char *optstr) + +void hmp_drive_add(Monitor *mon, const QDict *qdict) { Error *err = NULL; DriveInfo *dinfo; QemuOpts *opts; MachineClass *mc; + const char *optstr = qdict_get_str(qdict, "opts"); + bool node = qdict_get_try_bool(qdict, "node", false); + + if (node) { + hmp_drive_add_node(mon, optstr); + return; + } opts = drive_def(optstr); if (!opts) - return NULL; + return; mc = MACHINE_GET_CLASS(current_machine); dinfo = drive_new(opts, mc->block_default_type, &err); if (err) { error_report_err(err); qemu_opts_del(opts); - return NULL; - } - - return dinfo; -} - -void hmp_drive_add(Monitor *mon, const QDict *qdict) -{ - DriveInfo *dinfo = NULL; - const char *opts = qdict_get_str(qdict, "opts"); - bool node = qdict_get_try_bool(qdict, "node", false); - - if (node) { - hmp_drive_add_node(mon, opts); - return; + goto err; } - dinfo = add_init_drive(opts); if (!dinfo) { - goto err; + return; } switch (dinfo->type) { From patchwork Thu Jan 30 12:34:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357881 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 EF31692A for ; Thu, 30 Jan 2020 12:37:38 +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 C58B8206D3 for ; Thu, 30 Jan 2020 12:37:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UActzBrP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C58B8206D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix94j-0002Y7-V0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:37:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54545) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92O-0005bG-QA for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92N-0004Zq-EF for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:12 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:55183 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92N-0004Rx-9i for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mDDYN1526RpxoYeW85lvREBRRxEe2IGN9z2m/v1Qfbk=; b=UActzBrPCox55rYSTpS4abVPy+3RqRC2JsuQeQw0EE5+wlYDikgwwQ2QAbyqaMX73NdCUs 4u6GqAVMNkx1CK2ixXC12Z7Aou104sh8iDl8G3THzdYkVXiMNKCWYKV8K7w1lJDZEOgXUK y6o+iB6rtIaT4MUnX3cyiVhjQugDRNs= 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-97-romJZpZMOJyvZRLSqcNIZw-1; Thu, 30 Jan 2020 07:35:03 -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 12148107ACC4; Thu, 30 Jan 2020 12:35:02 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06D2E19756; Thu, 30 Jan 2020 12:34:59 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 03/11] monitor/hmp: rename device-hotplug.c to block/monitor/block-hmp-cmds.c Date: Thu, 30 Jan 2020 14:34:40 +0200 Message-Id: <20200130123448.21093-4-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: romJZpZMOJyvZRLSqcNIZw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" These days device-hotplug.c only contains the hmp_drive_add In the next patch, rest of hmp_drive* functions will be moved there. Also add block-hmp-cmds.h to contain prototypes of these functions License for block-hmp-cmds.h since it contains the code moved from sysemu.h which lacks license and thus according to LICENSE is under GPLv2+ Signed-off-by: Maxim Levitsky Reviewed-by: Markus Armbruster --- MAINTAINERS | 1 + Makefile.objs | 2 +- block/Makefile.objs | 1 + block/monitor/Makefile.objs | 1 + .../monitor/block-hmp-cmds.c | 3 ++- include/block/block-hmp-cmds.h | 16 ++++++++++++++++ include/sysemu/sysemu.h | 3 --- monitor/misc.c | 1 + 8 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 block/monitor/Makefile.objs rename device-hotplug.c => block/monitor/block-hmp-cmds.c (97%) create mode 100644 include/block/block-hmp-cmds.h diff --git a/MAINTAINERS b/MAINTAINERS index efd3f3875f..068051d053 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1884,6 +1884,7 @@ Block QAPI, monitor, command line M: Markus Armbruster S: Supported F: blockdev.c +F: blockdev-hmp-cmds.c F: block/qapi.c F: qapi/block*.json F: qapi/transaction.json diff --git a/Makefile.objs b/Makefile.objs index f2da7241fc..dc3fd58b24 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -39,7 +39,7 @@ common-obj-y += dump/ common-obj-y += job-qmp.o common-obj-y += monitor/ common-obj-y += net/ -common-obj-y += qdev-monitor.o device-hotplug.o +common-obj-y += qdev-monitor.o common-obj-$(CONFIG_WIN32) += os-win32.o common-obj-$(CONFIG_POSIX) += os-posix.o diff --git a/block/Makefile.objs b/block/Makefile.objs index 330529b0b7..3f65544a6b 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -44,6 +44,7 @@ block-obj-y += crypto.o block-obj-y += aio_task.o block-obj-y += backup-top.o block-obj-y += filter-compress.o +common-obj-y += monitor/ common-obj-y += stream.o diff --git a/block/monitor/Makefile.objs b/block/monitor/Makefile.objs new file mode 100644 index 0000000000..0a74f9a8b5 --- /dev/null +++ b/block/monitor/Makefile.objs @@ -0,0 +1 @@ +common-obj-y += block-hmp-cmds.o diff --git a/device-hotplug.c b/block/monitor/block-hmp-cmds.c similarity index 97% rename from device-hotplug.c rename to block/monitor/block-hmp-cmds.c index 554e4d98db..bcf35b4b44 100644 --- a/device-hotplug.c +++ b/block/monitor/block-hmp-cmds.c @@ -1,5 +1,5 @@ /* - * QEMU device hotplug helpers + * Blockdev HMP commands * * Copyright (c) 2004 Fabrice Bellard * @@ -33,6 +33,7 @@ #include "sysemu/sysemu.h" #include "monitor/monitor.h" #include "block/block_int.h" +#include "block/block-hmp-cmds.h" void hmp_drive_add(Monitor *mon, const QDict *qdict) diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h new file mode 100644 index 0000000000..0db8a889a1 --- /dev/null +++ b/include/block/block-hmp-cmds.h @@ -0,0 +1,16 @@ +/* + * HMP commands related to the block layer + * + * Copyright (c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2. + * or (at your option) any later version. + * See the COPYING file in the top-level directory. + */ + +#ifndef BLOCK_HMP_COMMANDS_H +#define BLOCK_HMP_COMMANDS_H + +void hmp_drive_add(Monitor *mon, const QDict *qdict); + +#endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 80c57fdc4e..c48635666d 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -68,9 +68,6 @@ extern int nb_option_roms; extern const char *prom_envs[MAX_PROM_ENVS]; extern unsigned int nb_prom_envs; -/* generic hotplug */ -void hmp_drive_add(Monitor *mon, const QDict *qdict); - /* pcie aer error injection */ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); diff --git a/monitor/misc.c b/monitor/misc.c index 4752150a67..b8f3cce19e 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -66,6 +66,7 @@ #include "qemu/option.h" #include "qemu/thread.h" #include "block/qapi.h" +#include "block/block-hmp-cmds.h" #include "qapi/qapi-commands-char.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-misc.h" From patchwork Thu Jan 30 12:34:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357885 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 EFA8092A for ; Thu, 30 Jan 2020 12:39:12 +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 C557D206D3 for ; Thu, 30 Jan 2020 12:39:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IDHvo7fR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C557D206D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix96G-0005iF-09 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:39:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54610) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92R-0005hm-Qt for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92P-0004g1-UO for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:15 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56769 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92P-0004eH-PM for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=knbpuyRkOPg8DkA8kyMD1BICuHwMzoLuCDq9Dzmmdmk=; b=IDHvo7fRQSHyHwK+HFj3L2pR3/J7bPcEajz9NcohbBYB9CdE/ARvYjqdrugcxRFd2kmO+6 NVw3z9ZQ9e9TU2E7+ZeK5WAAt/B75oHNLvW68w5x0L3KgKKyrJfmdysUR5S2zfaWw+UfrY +Gnkb20O9vnBhLt2seDi2p1hWemVu+k= 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-402-BPFEXSZnMWK3d6C-kdhI2A-1; Thu, 30 Jan 2020 07:35:05 -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 696B118FF660; Thu, 30 Jan 2020 12:35:04 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6766419756; Thu, 30 Jan 2020 12:35:02 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 04/11] monitor/hmp: move hmp_drive_del and hmp_commit to block-hmp-cmds.c Date: Thu, 30 Jan 2020 14:34:41 +0200 Message-Id: <20200130123448.21093-5-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: BPFEXSZnMWK3d6C-kdhI2A-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 108 ++++++++++++++++++++++++++++++++- blockdev.c | 95 ----------------------------- include/block/block-hmp-cmds.h | 4 ++ include/sysemu/blockdev.h | 4 -- 4 files changed, 110 insertions(+), 101 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index bcf35b4b44..ad727a6b08 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -1,7 +1,15 @@ /* * Blockdev HMP commands * - * Copyright (c) 2004 Fabrice Bellard + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright (c) 2003-2008 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,6 +34,7 @@ #include "hw/boards.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" +#include "qapi/qapi-commands-block.h" #include "qapi/qmp/qdict.h" #include "qapi/error.h" #include "qemu/config-file.h" @@ -35,7 +44,6 @@ #include "block/block_int.h" #include "block/block-hmp-cmds.h" - void hmp_drive_add(Monitor *mon, const QDict *qdict) { Error *err = NULL; @@ -83,3 +91,99 @@ err: blk_unref(blk); } } + +void hmp_drive_del(Monitor *mon, const QDict *qdict) +{ + const char *id = qdict_get_str(qdict, "id"); + BlockBackend *blk; + BlockDriverState *bs; + AioContext *aio_context; + Error *local_err = NULL; + + bs = bdrv_find_node(id); + if (bs) { + qmp_blockdev_del(id, &local_err); + if (local_err) { + error_report_err(local_err); + } + return; + } + + blk = blk_by_name(id); + if (!blk) { + error_report("Device '%s' not found", id); + return; + } + + if (!blk_legacy_dinfo(blk)) { + error_report("Deleting device added with blockdev-add" + " is not supported"); + return; + } + + aio_context = blk_get_aio_context(blk); + aio_context_acquire(aio_context); + + bs = blk_bs(blk); + if (bs) { + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { + error_report_err(local_err); + aio_context_release(aio_context); + return; + } + + blk_remove_bs(blk); + } + + /* Make the BlockBackend and the attached BlockDriverState anonymous */ + monitor_remove_blk(blk); + + /* + * If this BlockBackend has a device attached to it, its refcount will be + * decremented when the device is removed; otherwise we have to do so here. + */ + if (blk_get_attached_dev(blk)) { + /* Further I/O must not pause the guest */ + blk_set_on_error(blk, BLOCKDEV_ON_ERROR_REPORT, + BLOCKDEV_ON_ERROR_REPORT); + } else { + blk_unref(blk); + } + + aio_context_release(aio_context); +} + +void hmp_commit(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + BlockBackend *blk; + int ret; + + if (!strcmp(device, "all")) { + ret = blk_commit_all(); + } else { + BlockDriverState *bs; + AioContext *aio_context; + + blk = blk_by_name(device); + if (!blk) { + error_report("Device '%s' not found", device); + return; + } + if (!blk_is_available(blk)) { + error_report("Device '%s' has no medium", device); + return; + } + + bs = blk_bs(blk); + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + ret = bdrv_commit(bs); + + aio_context_release(aio_context); + } + if (ret < 0) { + error_report("'commit' error for '%s': %s", device, strerror(-ret)); + } +} diff --git a/blockdev.c b/blockdev.c index 4cd9a58d36..f2c5ea8a87 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1074,41 +1074,6 @@ static BlockBackend *qmp_get_blk(const char *blk_name, const char *qdev_id, return blk; } -void hmp_commit(Monitor *mon, const QDict *qdict) -{ - const char *device = qdict_get_str(qdict, "device"); - BlockBackend *blk; - int ret; - - if (!strcmp(device, "all")) { - ret = blk_commit_all(); - } else { - BlockDriverState *bs; - AioContext *aio_context; - - blk = blk_by_name(device); - if (!blk) { - error_report("Device '%s' not found", device); - return; - } - if (!blk_is_available(blk)) { - error_report("Device '%s' has no medium", device); - return; - } - - bs = blk_bs(blk); - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - ret = bdrv_commit(bs); - - aio_context_release(aio_context); - } - if (ret < 0) { - error_report("'commit' error for '%s': %s", device, strerror(-ret)); - } -} - static void blockdev_do_action(TransactionAction *action, Error **errp) { TransactionActionList list; @@ -3259,66 +3224,6 @@ BlockDirtyBitmapSha256 *qmp_x_debug_block_dirty_bitmap_sha256(const char *node, return ret; } -void hmp_drive_del(Monitor *mon, const QDict *qdict) -{ - const char *id = qdict_get_str(qdict, "id"); - BlockBackend *blk; - BlockDriverState *bs; - AioContext *aio_context; - Error *local_err = NULL; - - bs = bdrv_find_node(id); - if (bs) { - qmp_blockdev_del(id, &local_err); - if (local_err) { - error_report_err(local_err); - } - return; - } - - blk = blk_by_name(id); - if (!blk) { - error_report("Device '%s' not found", id); - return; - } - - if (!blk_legacy_dinfo(blk)) { - error_report("Deleting device added with blockdev-add" - " is not supported"); - return; - } - - aio_context = blk_get_aio_context(blk); - aio_context_acquire(aio_context); - - bs = blk_bs(blk); - if (bs) { - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { - error_report_err(local_err); - aio_context_release(aio_context); - return; - } - - blk_remove_bs(blk); - } - - /* Make the BlockBackend and the attached BlockDriverState anonymous */ - monitor_remove_blk(blk); - - /* If this BlockBackend has a device attached to it, its refcount will be - * decremented when the device is removed; otherwise we have to do so here. - */ - if (blk_get_attached_dev(blk)) { - /* Further I/O must not pause the guest */ - blk_set_on_error(blk, BLOCKDEV_ON_ERROR_REPORT, - BLOCKDEV_ON_ERROR_REPORT); - } else { - blk_unref(blk); - } - - aio_context_release(aio_context); -} - void qmp_block_resize(bool has_device, const char *device, bool has_node_name, const char *node_name, int64_t size, Error **errp) diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h index 0db8a889a1..30b0f56415 100644 --- a/include/block/block-hmp-cmds.h +++ b/include/block/block-hmp-cmds.h @@ -1,6 +1,7 @@ /* * HMP commands related to the block layer * + * Copyright (c) 2003-2008 Fabrice Bellard * Copyright (c) 2020 Red Hat, Inc. * * This work is licensed under the terms of the GNU GPL, version 2. @@ -13,4 +14,7 @@ void hmp_drive_add(Monitor *mon, const QDict *qdict); +void hmp_commit(Monitor *mon, const QDict *qdict); +void hmp_drive_del(Monitor *mon, const QDict *qdict); + #endif diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index d34c4920dc..a86d99b3d8 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -57,8 +57,4 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file, DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type, Error **errp); -/* device-hotplug */ - -void hmp_commit(Monitor *mon, const QDict *qdict); -void hmp_drive_del(Monitor *mon, const QDict *qdict); #endif From patchwork Thu Jan 30 12:34:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357873 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 E8B30139A for ; Thu, 30 Jan 2020 12:36:15 +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 BF62D20702 for ; Thu, 30 Jan 2020 12:36:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OEsC/QBc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF62D20702 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix93O-0007is-SO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:36:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54616) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92S-0005iq-9A for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92Q-0004gu-H2 for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:16 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:46588 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92Q-0004gP-Br for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387714; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qtl7o3371u3Lmk8R0/nKZWtQGrm8CVYqtZpNGcR+6RA=; b=OEsC/QBc1twzVZ+YxlnIAcFaJkT9vp0sMi1dxwJAynYjVvMkZ3Wzpi5j0qHnN/v2DuEkDv g3D+er6EyulAONZgybgJ25oi4+g53kCKvFSliKsxUXTAvEi2XouQj2aitUgBJWuv46k7FQ frwMlE2V+dYBzwi1Hx9GfgM5+o9KSjI= 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-291-OxdTBgk4O5ujvTU5jJgb4w-1; Thu, 30 Jan 2020 07:35:11 -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 CCAA7DB60; Thu, 30 Jan 2020 12:35:10 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id C28FD19756; Thu, 30 Jan 2020 12:35:04 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 05/11] monitor/hmp: move hmp_drive_mirror and hmp_drive_backup to block-hmp-cmds.c Moved code was added after 2012-01-13, thus under GPLv2+ Date: Thu, 30 Jan 2020 14:34:42 +0200 Message-Id: <20200130123448.21093-6-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: OxdTBgk4O5ujvTU5jJgb4w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 60 ++++++++++++++++++++++++++++++++++ include/block/block-hmp-cmds.h | 12 +++++-- include/monitor/hmp.h | 2 -- monitor/hmp-cmds.c | 58 -------------------------------- 4 files changed, 69 insertions(+), 63 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index ad727a6b08..d6dd5d97f7 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -37,10 +37,12 @@ #include "qapi/qapi-commands-block.h" #include "qapi/qmp/qdict.h" #include "qapi/error.h" +#include "qapi/qmp/qerror.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "sysemu/sysemu.h" #include "monitor/monitor.h" +#include "monitor/hmp.h" #include "block/block_int.h" #include "block/block-hmp-cmds.h" @@ -187,3 +189,61 @@ void hmp_commit(Monitor *mon, const QDict *qdict) error_report("'commit' error for '%s': %s", device, strerror(-ret)); } } + +void hmp_drive_mirror(Monitor *mon, const QDict *qdict) +{ + const char *filename = qdict_get_str(qdict, "target"); + const char *format = qdict_get_try_str(qdict, "format"); + bool reuse = qdict_get_try_bool(qdict, "reuse", false); + bool full = qdict_get_try_bool(qdict, "full", false); + Error *err = NULL; + DriveMirror mirror = { + .device = (char *)qdict_get_str(qdict, "device"), + .target = (char *)filename, + .has_format = !!format, + .format = (char *)format, + .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, + .has_mode = true, + .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, + .unmap = true, + }; + + if (!filename) { + error_setg(&err, QERR_MISSING_PARAMETER, "target"); + hmp_handle_error(mon, err); + return; + } + qmp_drive_mirror(&mirror, &err); + hmp_handle_error(mon, err); +} + +void hmp_drive_backup(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *filename = qdict_get_str(qdict, "target"); + const char *format = qdict_get_try_str(qdict, "format"); + bool reuse = qdict_get_try_bool(qdict, "reuse", false); + bool full = qdict_get_try_bool(qdict, "full", false); + bool compress = qdict_get_try_bool(qdict, "compress", false); + Error *err = NULL; + DriveBackup backup = { + .device = (char *)device, + .target = (char *)filename, + .has_format = !!format, + .format = (char *)format, + .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, + .has_mode = true, + .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, + .has_compress = !!compress, + .compress = compress, + }; + + if (!filename) { + error_setg(&err, QERR_MISSING_PARAMETER, "target"); + hmp_handle_error(mon, err); + return; + } + + qmp_drive_backup(&backup, &err); + hmp_handle_error(mon, err); +} diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h index 30b0f56415..a64b737b3a 100644 --- a/include/block/block-hmp-cmds.h +++ b/include/block/block-hmp-cmds.h @@ -3,10 +3,13 @@ * * Copyright (c) 2003-2008 Fabrice Bellard * Copyright (c) 2020 Red Hat, Inc. + * Copyright IBM, Corp. 2011 * - * This work is licensed under the terms of the GNU GPL, version 2. - * or (at your option) any later version. - * See the COPYING file in the top-level directory. + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. */ #ifndef BLOCK_HMP_COMMANDS_H @@ -17,4 +20,7 @@ void hmp_drive_add(Monitor *mon, const QDict *qdict); void hmp_commit(Monitor *mon, const QDict *qdict); void hmp_drive_del(Monitor *mon, const QDict *qdict); +void hmp_drive_mirror(Monitor *mon, const QDict *qdict); +void hmp_drive_backup(Monitor *mon, const QDict *qdict); + #endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 3d329853b2..c1b363ee57 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -64,8 +64,6 @@ void hmp_block_resize(Monitor *mon, const QDict *qdict); void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict); void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict); void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict); -void hmp_drive_mirror(Monitor *mon, const QDict *qdict); -void hmp_drive_backup(Monitor *mon, const QDict *qdict); void hmp_loadvm(Monitor *mon, const QDict *qdict); void hmp_savevm(Monitor *mon, const QDict *qdict); void hmp_delvm(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index d0e0af893a..a70bcb1d16 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1337,64 +1337,6 @@ void hmp_block_resize(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } -void hmp_drive_mirror(Monitor *mon, const QDict *qdict) -{ - const char *filename = qdict_get_str(qdict, "target"); - const char *format = qdict_get_try_str(qdict, "format"); - bool reuse = qdict_get_try_bool(qdict, "reuse", false); - bool full = qdict_get_try_bool(qdict, "full", false); - Error *err = NULL; - DriveMirror mirror = { - .device = (char *)qdict_get_str(qdict, "device"), - .target = (char *)filename, - .has_format = !!format, - .format = (char *)format, - .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, - .has_mode = true, - .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, - .unmap = true, - }; - - if (!filename) { - error_setg(&err, QERR_MISSING_PARAMETER, "target"); - hmp_handle_error(mon, err); - return; - } - qmp_drive_mirror(&mirror, &err); - hmp_handle_error(mon, err); -} - -void hmp_drive_backup(Monitor *mon, const QDict *qdict) -{ - const char *device = qdict_get_str(qdict, "device"); - const char *filename = qdict_get_str(qdict, "target"); - const char *format = qdict_get_try_str(qdict, "format"); - bool reuse = qdict_get_try_bool(qdict, "reuse", false); - bool full = qdict_get_try_bool(qdict, "full", false); - bool compress = qdict_get_try_bool(qdict, "compress", false); - Error *err = NULL; - DriveBackup backup = { - .device = (char *)device, - .target = (char *)filename, - .has_format = !!format, - .format = (char *)format, - .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, - .has_mode = true, - .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS, - .has_compress = !!compress, - .compress = compress, - }; - - if (!filename) { - error_setg(&err, QERR_MISSING_PARAMETER, "target"); - hmp_handle_error(mon, err); - return; - } - - qmp_drive_backup(&backup, &err); - hmp_handle_error(mon, err); -} - void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); From patchwork Thu Jan 30 12:34:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357887 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 469921800 for ; Thu, 30 Jan 2020 12:39:13 +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 1BA36206D3 for ; Thu, 30 Jan 2020 12:39:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PCAqpI0K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1BA36206D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix96G-0005io-Aa for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:39:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54695) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92W-0005xu-Pv for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92V-0004o3-3z for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:20 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:25259 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92U-0004nU-WC for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EP96nc4+jZv7gcbZ9+98UgVX3lg0fmtpP2kk0L0diwc=; b=PCAqpI0KwrraL6shSpGRh0MWSQnHfplQuEyqlbeMJIJ9MoRzLp7nplH3cNEn4bdaFbx+sP b4pK1Etba4I4IshhQ29t+0DmTkeKZ9Y7+d3ajY2P0MAmuGw3hxeEqytHG2jkMaj8rCuuc3 AmGZIVhb7eQyOi7vSDyWna7JVgqqxNY= 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-286-O_RqVOmwO4uH1myoPepXtw-1; Thu, 30 Jan 2020 07:35:16 -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 96F0DDB61; Thu, 30 Jan 2020 12:35:15 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DAE1167A3; Thu, 30 Jan 2020 12:35:10 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 06/11] monitor/hmp: move hmp_block_job* to block-hmp-cmds.c Date: Thu, 30 Jan 2020 14:34:43 +0200 Message-Id: <20200130123448.21093-7-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: O_RqVOmwO4uH1myoPepXtw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 52 ++++++++++++++++++++++++++++++++++ include/block/block-hmp-cmds.h | 6 ++++ include/monitor/hmp.h | 5 ---- monitor/hmp-cmds.c | 52 ---------------------------------- 4 files changed, 58 insertions(+), 57 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index d6dd5d97f7..8e8288c2f1 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -247,3 +247,55 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict) qmp_drive_backup(&backup, &err); hmp_handle_error(mon, err); } + +void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) +{ + Error *error = NULL; + const char *device = qdict_get_str(qdict, "device"); + int64_t value = qdict_get_int(qdict, "speed"); + + qmp_block_job_set_speed(device, value, &error); + + hmp_handle_error(mon, error); +} + +void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) +{ + Error *error = NULL; + const char *device = qdict_get_str(qdict, "device"); + bool force = qdict_get_try_bool(qdict, "force", false); + + qmp_block_job_cancel(device, true, force, &error); + + hmp_handle_error(mon, error); +} + +void hmp_block_job_pause(Monitor *mon, const QDict *qdict) +{ + Error *error = NULL; + const char *device = qdict_get_str(qdict, "device"); + + qmp_block_job_pause(device, &error); + + hmp_handle_error(mon, error); +} + +void hmp_block_job_resume(Monitor *mon, const QDict *qdict) +{ + Error *error = NULL; + const char *device = qdict_get_str(qdict, "device"); + + qmp_block_job_resume(device, &error); + + hmp_handle_error(mon, error); +} + +void hmp_block_job_complete(Monitor *mon, const QDict *qdict) +{ + Error *error = NULL; + const char *device = qdict_get_str(qdict, "device"); + + qmp_block_job_complete(device, &error); + + hmp_handle_error(mon, error); +} diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h index a64b737b3a..fcdf1eec48 100644 --- a/include/block/block-hmp-cmds.h +++ b/include/block/block-hmp-cmds.h @@ -23,4 +23,10 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict); void hmp_drive_mirror(Monitor *mon, const QDict *qdict); void hmp_drive_backup(Monitor *mon, const QDict *qdict); +void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict); +void hmp_block_job_cancel(Monitor *mon, const QDict *qdict); +void hmp_block_job_pause(Monitor *mon, const QDict *qdict); +void hmp_block_job_resume(Monitor *mon, const QDict *qdict); +void hmp_block_job_complete(Monitor *mon, const QDict *qdict); + #endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index c1b363ee57..592ce0ccfe 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -87,11 +87,6 @@ void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mon, const QDict *qdict); void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict); void hmp_block_stream(Monitor *mon, const QDict *qdict); -void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict); -void hmp_block_job_cancel(Monitor *mon, const QDict *qdict); -void hmp_block_job_pause(Monitor *mon, const QDict *qdict); -void hmp_block_job_resume(Monitor *mon, const QDict *qdict); -void hmp_block_job_complete(Monitor *mon, const QDict *qdict); void hmp_migrate(Monitor *mon, const QDict *qdict); void hmp_device_add(Monitor *mon, const QDict *qdict); void hmp_device_del(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index a70bcb1d16..996ce96430 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1975,58 +1975,6 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, error); } -void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) -{ - Error *error = NULL; - const char *device = qdict_get_str(qdict, "device"); - int64_t value = qdict_get_int(qdict, "speed"); - - qmp_block_job_set_speed(device, value, &error); - - hmp_handle_error(mon, error); -} - -void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) -{ - Error *error = NULL; - const char *device = qdict_get_str(qdict, "device"); - bool force = qdict_get_try_bool(qdict, "force", false); - - qmp_block_job_cancel(device, true, force, &error); - - hmp_handle_error(mon, error); -} - -void hmp_block_job_pause(Monitor *mon, const QDict *qdict) -{ - Error *error = NULL; - const char *device = qdict_get_str(qdict, "device"); - - qmp_block_job_pause(device, &error); - - hmp_handle_error(mon, error); -} - -void hmp_block_job_resume(Monitor *mon, const QDict *qdict) -{ - Error *error = NULL; - const char *device = qdict_get_str(qdict, "device"); - - qmp_block_job_resume(device, &error); - - hmp_handle_error(mon, error); -} - -void hmp_block_job_complete(Monitor *mon, const QDict *qdict) -{ - Error *error = NULL; - const char *device = qdict_get_str(qdict, "device"); - - qmp_block_job_complete(device, &error); - - hmp_handle_error(mon, error); -} - typedef struct HMPMigrationStatus { QEMUTimer *timer; From patchwork Thu Jan 30 12:34:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357875 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 64FBE92A for ; Thu, 30 Jan 2020 12:36:18 +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 3BC0E2082E for ; Thu, 30 Jan 2020 12:36:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="clRlKecB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BC0E2082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix93R-0007q0-8X for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:36:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54740) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92Z-00064g-8I for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92X-0004sm-Iw for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:23 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:51989 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92X-0004qs-Cx for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oX8Ifkue+FMGOOZe9ZcjsoR3TDSis1w0DjfgJB/CBnE=; b=clRlKecBMmUH5d1B5A8pDePVplCUmDFg2BpjGz/BVbd/Opkb/ARpSxWCzanHz1QYQOTS7m Mn7uXtqwzWNfbK5XpycDHKplGrpo/g+CnfffjdIePGR0cOqxY9v+voZBtddIwRI4nWNLBB nB735+7JjqgLMCk243jOwwxa/nmoobk= 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-155-S5i-uCFOM6CCsLnTEUGj5g-1; Thu, 30 Jan 2020 07:35:19 -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 003CB18FF660; Thu, 30 Jan 2020 12:35:18 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0D9819486; Thu, 30 Jan 2020 12:35:15 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 07/11] monitor/hmp: move hmp_snapshot_* to block-hmp-cmds.c hmp_snapshot_blkdev is from GPLv2 version of the hmp-cmds.c thus have to change the licence to GPLv2 Date: Thu, 30 Jan 2020 14:34:44 +0200 Message-Id: <20200130123448.21093-8-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: S5i-uCFOM6CCsLnTEUGj5g-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 56 ++++++++++++++++++++++++++++++++-- include/block/block-hmp-cmds.h | 4 +++ include/monitor/hmp.h | 3 -- monitor/hmp-cmds.c | 47 ---------------------------- 4 files changed, 58 insertions(+), 52 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 8e8288c2f1..b83687196f 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -1,10 +1,13 @@ /* * Blockdev HMP commands * + * Authors: + * Anthony Liguori + * * Copyright (c) 2003-2008 Fabrice Bellard * - * This work is licensed under the terms of the GNU GPL, version 2 or - * later. See the COPYING file in the top-level directory. + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. * * This file incorporates work covered by the following copyright and * permission notice: @@ -299,3 +302,52 @@ void hmp_block_job_complete(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, error); } + +void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *filename = qdict_get_try_str(qdict, "snapshot-file"); + const char *format = qdict_get_try_str(qdict, "format"); + bool reuse = qdict_get_try_bool(qdict, "reuse", false); + enum NewImageMode mode; + Error *err = NULL; + + if (!filename) { + /* + * In the future, if 'snapshot-file' is not specified, the snapshot + * will be taken internally. Today it's actually required. + */ + error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); + hmp_handle_error(mon, err); + return; + } + + mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; + qmp_blockdev_snapshot_sync(true, device, false, NULL, + filename, false, NULL, + !!format, format, + true, mode, &err); + hmp_handle_error(mon, err); +} + +void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *name = qdict_get_str(qdict, "name"); + Error *err = NULL; + + qmp_blockdev_snapshot_internal_sync(device, name, &err); + hmp_handle_error(mon, err); +} + +void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *name = qdict_get_str(qdict, "name"); + const char *id = qdict_get_try_str(qdict, "id"); + Error *err = NULL; + + qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id, + true, name, &err); + hmp_handle_error(mon, err); +} diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h index fcdf1eec48..cc81779c7c 100644 --- a/include/block/block-hmp-cmds.h +++ b/include/block/block-hmp-cmds.h @@ -29,4 +29,8 @@ void hmp_block_job_pause(Monitor *mon, const QDict *qdict); void hmp_block_job_resume(Monitor *mon, const QDict *qdict); void hmp_block_job_complete(Monitor *mon, const QDict *qdict); +void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict); +void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict); +void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict); + #endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 592ce0ccfe..6d34e29bb6 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -61,9 +61,6 @@ void hmp_set_link(Monitor *mon, const QDict *qdict); void hmp_block_passwd(Monitor *mon, const QDict *qdict); void hmp_balloon(Monitor *mon, const QDict *qdict); void hmp_block_resize(Monitor *mon, const QDict *qdict); -void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict); -void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict); -void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict); void hmp_loadvm(Monitor *mon, const QDict *qdict); void hmp_savevm(Monitor *mon, const QDict *qdict); void hmp_delvm(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 996ce96430..46b46b6dd7 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1337,53 +1337,6 @@ void hmp_block_resize(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } -void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) -{ - const char *device = qdict_get_str(qdict, "device"); - const char *filename = qdict_get_try_str(qdict, "snapshot-file"); - const char *format = qdict_get_try_str(qdict, "format"); - bool reuse = qdict_get_try_bool(qdict, "reuse", false); - enum NewImageMode mode; - Error *err = NULL; - - if (!filename) { - /* In the future, if 'snapshot-file' is not specified, the snapshot - will be taken internally. Today it's actually required. */ - error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); - hmp_handle_error(mon, err); - return; - } - - mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; - qmp_blockdev_snapshot_sync(true, device, false, NULL, - filename, false, NULL, - !!format, format, - true, mode, &err); - hmp_handle_error(mon, err); -} - -void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) -{ - const char *device = qdict_get_str(qdict, "device"); - const char *name = qdict_get_str(qdict, "name"); - Error *err = NULL; - - qmp_blockdev_snapshot_internal_sync(device, name, &err); - hmp_handle_error(mon, err); -} - -void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) -{ - const char *device = qdict_get_str(qdict, "device"); - const char *name = qdict_get_str(qdict, "name"); - const char *id = qdict_get_try_str(qdict, "id"); - Error *err = NULL; - - qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id, - true, name, &err); - hmp_handle_error(mon, err); -} - void hmp_loadvm(Monitor *mon, const QDict *qdict) { int saved_vm_running = runstate_is_running(); From patchwork Thu Jan 30 12:34:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357891 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 6561092A for ; Thu, 30 Jan 2020 12:40: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 391AB206F0 for ; Thu, 30 Jan 2020 12:40:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KNOfvVpb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 391AB206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix97p-0007j7-Cp for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:40:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54823) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92d-0006ET-GT for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92b-00051Y-O9 for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:27 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:33231 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92b-00050v-KQ for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ckn606U+Kpv7bQGSm37+vFUJ9QCt8MR0RolDlUILtz8=; b=KNOfvVpbxSFArQytGSdZ7quCgGQFHFBTrNmoRHnBuZS8BzypxhbZSIddbS++GAfyNluQxL j5TlAxo4LXsmo/ijKspQTZ10CheKt18FBjPmtCq7Mm4XjTtnrtCb38i5gXMSRFf51g/oyp yKTU3Fwys+IrFhXVUhi939jgWQCNKEw= 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-99-_VL6IbTYO-u1oYEF0174iA-1; Thu, 30 Jan 2020 07:35:21 -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 60469800D4C; Thu, 30 Jan 2020 12:35:20 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B10A166A9; Thu, 30 Jan 2020 12:35:18 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 08/11] monitor/hmp: move hmp_nbd_server* to block-hmp-cmds.c Date: Thu, 30 Jan 2020 14:34:45 +0200 Message-Id: <20200130123448.21093-9-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: _VL6IbTYO-u1oYEF0174iA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 89 ++++++++++++++++++++++++++++++++++ include/block/block-hmp-cmds.h | 5 ++ include/monitor/hmp.h | 4 -- monitor/hmp-cmds.c | 87 --------------------------------- 4 files changed, 94 insertions(+), 91 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index b83687196f..d72e2164fe 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -43,9 +43,11 @@ #include "qapi/qmp/qerror.h" #include "qemu/config-file.h" #include "qemu/option.h" +#include "qemu/sockets.h" #include "sysemu/sysemu.h" #include "monitor/monitor.h" #include "monitor/hmp.h" +#include "block/nbd.h" #include "block/block_int.h" #include "block/block-hmp-cmds.h" @@ -351,3 +353,90 @@ void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) true, name, &err); hmp_handle_error(mon, err); } + +void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) +{ + const char *uri = qdict_get_str(qdict, "uri"); + bool writable = qdict_get_try_bool(qdict, "writable", false); + bool all = qdict_get_try_bool(qdict, "all", false); + Error *local_err = NULL; + BlockInfoList *block_list, *info; + SocketAddress *addr; + + if (writable && !all) { + error_setg(&local_err, "-w only valid together with -a"); + goto exit; + } + + /* First check if the address is valid and start the server. */ + addr = socket_parse(uri, &local_err); + if (local_err != NULL) { + goto exit; + } + + nbd_server_start(addr, NULL, NULL, &local_err); + qapi_free_SocketAddress(addr); + if (local_err != NULL) { + goto exit; + } + + if (!all) { + return; + } + + /* + * Then try adding all block devices. If one fails, close all and + * exit. + */ + block_list = qmp_query_block(NULL); + + for (info = block_list; info; info = info->next) { + if (!info->value->has_inserted) { + continue; + } + + qmp_nbd_server_add(info->value->device, false, NULL, + true, writable, false, NULL, &local_err); + + if (local_err != NULL) { + qmp_nbd_server_stop(NULL); + break; + } + } + + qapi_free_BlockInfoList(block_list); + +exit: + hmp_handle_error(mon, local_err); +} + +void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *name = qdict_get_try_str(qdict, "name"); + bool writable = qdict_get_try_bool(qdict, "writable", false); + Error *local_err = NULL; + + qmp_nbd_server_add(device, !!name, name, true, writable, + false, NULL, &local_err); + hmp_handle_error(mon, local_err); +} + +void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) +{ + const char *name = qdict_get_str(qdict, "name"); + bool force = qdict_get_try_bool(qdict, "force", false); + Error *err = NULL; + + /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */ + qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err); + hmp_handle_error(mon, err); +} + +void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + + qmp_nbd_server_stop(&err); + hmp_handle_error(mon, err); +} diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h index cc81779c7c..50ff802598 100644 --- a/include/block/block-hmp-cmds.h +++ b/include/block/block-hmp-cmds.h @@ -33,4 +33,9 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict); void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict); void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict); +void hmp_nbd_server_start(Monitor *mon, const QDict *qdict); +void hmp_nbd_server_add(Monitor *mon, const QDict *qdict); +void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict); +void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict); + #endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 6d34e29bb6..736a969131 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -94,10 +94,6 @@ void hmp_getfd(Monitor *mon, const QDict *qdict); void hmp_closefd(Monitor *mon, const QDict *qdict); void hmp_sendkey(Monitor *mon, const QDict *qdict); void hmp_screendump(Monitor *mon, const QDict *qdict); -void hmp_nbd_server_start(Monitor *mon, const QDict *qdict); -void hmp_nbd_server_add(Monitor *mon, const QDict *qdict); -void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict); -void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict); void hmp_chardev_add(Monitor *mon, const QDict *qdict); void hmp_chardev_change(Monitor *mon, const QDict *qdict); void hmp_chardev_remove(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 46b46b6dd7..67d2ca8a4c 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -45,7 +45,6 @@ #include "qapi/string-output-visitor.h" #include "qom/object_interfaces.h" #include "ui/console.h" -#include "block/nbd.h" #include "block/qapi.h" #include "qemu-io.h" #include "qemu/cutils.h" @@ -2154,92 +2153,6 @@ void hmp_screendump(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } -void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) -{ - const char *uri = qdict_get_str(qdict, "uri"); - bool writable = qdict_get_try_bool(qdict, "writable", false); - bool all = qdict_get_try_bool(qdict, "all", false); - Error *local_err = NULL; - BlockInfoList *block_list, *info; - SocketAddress *addr; - - if (writable && !all) { - error_setg(&local_err, "-w only valid together with -a"); - goto exit; - } - - /* First check if the address is valid and start the server. */ - addr = socket_parse(uri, &local_err); - if (local_err != NULL) { - goto exit; - } - - nbd_server_start(addr, NULL, NULL, &local_err); - qapi_free_SocketAddress(addr); - if (local_err != NULL) { - goto exit; - } - - if (!all) { - return; - } - - /* Then try adding all block devices. If one fails, close all and - * exit. - */ - block_list = qmp_query_block(NULL); - - for (info = block_list; info; info = info->next) { - if (!info->value->has_inserted) { - continue; - } - - qmp_nbd_server_add(info->value->device, false, NULL, - true, writable, false, NULL, &local_err); - - if (local_err != NULL) { - qmp_nbd_server_stop(NULL); - break; - } - } - - qapi_free_BlockInfoList(block_list); - -exit: - hmp_handle_error(mon, local_err); -} - -void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) -{ - const char *device = qdict_get_str(qdict, "device"); - const char *name = qdict_get_try_str(qdict, "name"); - bool writable = qdict_get_try_bool(qdict, "writable", false); - Error *local_err = NULL; - - qmp_nbd_server_add(device, !!name, name, true, writable, - false, NULL, &local_err); - hmp_handle_error(mon, local_err); -} - -void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) -{ - const char *name = qdict_get_str(qdict, "name"); - bool force = qdict_get_try_bool(qdict, "force", false); - Error *err = NULL; - - /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */ - qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err); - hmp_handle_error(mon, err); -} - -void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) -{ - Error *err = NULL; - - qmp_nbd_server_stop(&err); - hmp_handle_error(mon, err); -} - void hmp_chardev_add(Monitor *mon, const QDict *qdict) { const char *args = qdict_get_str(qdict, "args"); From patchwork Thu Jan 30 12:34:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357883 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 C41BE92A for ; Thu, 30 Jan 2020 12:38:15 +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 8A540206F0 for ; Thu, 30 Jan 2020 12:38:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BTphY3z9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A540206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix95K-0003tM-KZ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:38:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54868) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92g-0006Ml-QA for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92e-00055x-95 for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:30 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:59251 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92e-000552-4t for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UvYNkohCd3m/eEBdExljAj3+OmHolEEu7gFb5aHvbsY=; b=BTphY3z9cPEDwrSe2mOd9Rc9QYlaNxVgrzn/ja1XO8ZrcJyWlkeg038vICfYnQJhzjhB7M ph1/OIpKFAov1cBJAuJ0C1HzihZKDzhlqXHNigtTrbfYkPjuxPAAspKQaOYDQUdWYpGojO T5IL03drBT4/hQ3hdDF9sTI3Bs9xy1c= 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-156-0OwxYeHcMX2o8Zk4U0s7fA-1; Thu, 30 Jan 2020 07:35:23 -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 EAFCD801E67; Thu, 30 Jan 2020 12:35:22 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA697166A9; Thu, 30 Jan 2020 12:35:20 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 09/11] monitor/hmp: move remaining hmp_block* functions to block-hmp-cmds.c Date: Thu, 30 Jan 2020 14:34:46 +0200 Message-Id: <20200130123448.21093-10-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 0OwxYeHcMX2o8Zk4U0s7fA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 140 +++++++++++++++++++++++++++++++++ include/block/block-hmp-cmds.h | 9 +++ include/monitor/hmp.h | 6 -- monitor/hmp-cmds.c | 137 -------------------------------- 4 files changed, 149 insertions(+), 143 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index d72e2164fe..15bc565527 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -50,6 +50,7 @@ #include "block/nbd.h" #include "block/block_int.h" #include "block/block-hmp-cmds.h" +#include "qemu-io.h" void hmp_drive_add(Monitor *mon, const QDict *qdict) { @@ -440,3 +441,142 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) qmp_nbd_server_stop(&err); hmp_handle_error(mon, err); } + +void hmp_block_resize(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + int64_t size = qdict_get_int(qdict, "size"); + Error *err = NULL; + + qmp_block_resize(true, device, false, NULL, size, &err); + hmp_handle_error(mon, err); +} + +void hmp_block_stream(Monitor *mon, const QDict *qdict) +{ + Error *error = NULL; + const char *device = qdict_get_str(qdict, "device"); + const char *base = qdict_get_try_str(qdict, "base"); + int64_t speed = qdict_get_try_int(qdict, "speed", 0); + + qmp_block_stream(true, device, device, base != NULL, base, false, NULL, + false, NULL, qdict_haskey(qdict, "speed"), speed, true, + BLOCKDEV_ON_ERROR_REPORT, false, false, false, false, + &error); + + hmp_handle_error(mon, error); +} + +void hmp_block_passwd(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "device"); + const char *password = qdict_get_str(qdict, "password"); + Error *err = NULL; + + qmp_block_passwd(true, device, false, NULL, password, &err); + hmp_handle_error(mon, err); +} + +void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + char *device = (char *) qdict_get_str(qdict, "device"); + BlockIOThrottle throttle = { + .bps = qdict_get_int(qdict, "bps"), + .bps_rd = qdict_get_int(qdict, "bps_rd"), + .bps_wr = qdict_get_int(qdict, "bps_wr"), + .iops = qdict_get_int(qdict, "iops"), + .iops_rd = qdict_get_int(qdict, "iops_rd"), + .iops_wr = qdict_get_int(qdict, "iops_wr"), + }; + + /* + * qmp_block_set_io_throttle has separate parameters for the + * (deprecated) block device name and the qdev ID but the HMP + * version has only one, so we must decide which one to pass. + */ + if (blk_by_name(device)) { + throttle.has_device = true; + throttle.device = device; + } else { + throttle.has_id = true; + throttle.id = device; + } + + qmp_block_set_io_throttle(&throttle, &err); + hmp_handle_error(mon, err); +} + +void hmp_eject(Monitor *mon, const QDict *qdict) +{ + bool force = qdict_get_try_bool(qdict, "force", false); + const char *device = qdict_get_str(qdict, "device"); + Error *err = NULL; + + qmp_eject(true, device, false, NULL, true, force, &err); + hmp_handle_error(mon, err); +} + +void hmp_qemu_io(Monitor *mon, const QDict *qdict) +{ + BlockBackend *blk; + BlockBackend *local_blk = NULL; + bool qdev = qdict_get_try_bool(qdict, "qdev", false); + const char *device = qdict_get_str(qdict, "device"); + const char *command = qdict_get_str(qdict, "command"); + Error *err = NULL; + int ret; + + if (qdev) { + blk = blk_by_qdev_id(device, &err); + if (!blk) { + goto fail; + } + } else { + blk = blk_by_name(device); + if (!blk) { + BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err); + if (bs) { + blk = local_blk = blk_new(bdrv_get_aio_context(bs), + 0, BLK_PERM_ALL); + ret = blk_insert_bs(blk, bs, &err); + if (ret < 0) { + goto fail; + } + } else { + goto fail; + } + } + } + + /* + * Notably absent: Proper permission management. This is sad, but it seems + * almost impossible to achieve without changing the semantics and thereby + * limiting the use cases of the qemu-io HMP command. + * + * In an ideal world we would unconditionally create a new BlockBackend for + * qemuio_command(), but we have commands like 'reopen' and want them to + * take effect on the exact BlockBackend whose name the user passed instead + * of just on a temporary copy of it. + * + * Another problem is that deleting the temporary BlockBackend involves + * draining all requests on it first, but some qemu-iotests cases want to + * issue multiple aio_read/write requests and expect them to complete in + * the background while the monitor has already returned. + * + * This is also what prevents us from saving the original permissions and + * restoring them later: We can't revoke permissions until all requests + * have completed, and we don't know when that is nor can we really let + * anything else run before we have revoken them to avoid race conditions. + * + * What happens now is that command() in qemu-io-cmds.c can extend the + * permissions if necessary for the qemu-io command. And they simply stay + * extended, possibly resulting in a read-only guest device keeping write + * permissions. Ugly, but it appears to be the lesser evil. + */ + qemuio_command(blk, command); + +fail: + blk_unref(local_blk); + hmp_handle_error(mon, err); +} diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h index 50ff802598..c2d18fba06 100644 --- a/include/block/block-hmp-cmds.h +++ b/include/block/block-hmp-cmds.h @@ -38,4 +38,13 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict); void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict); void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict); +void hmp_block_resize(Monitor *mon, const QDict *qdict); +void hmp_block_stream(Monitor *mon, const QDict *qdict); +void hmp_block_passwd(Monitor *mon, const QDict *qdict); +void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict); +void hmp_eject(Monitor *mon, const QDict *qdict); + +void hmp_qemu_io(Monitor *mon, const QDict *qdict); + + #endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 736a969131..47a7cad734 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -58,9 +58,7 @@ void hmp_cont(Monitor *mon, const QDict *qdict); void hmp_system_wakeup(Monitor *mon, const QDict *qdict); void hmp_nmi(Monitor *mon, const QDict *qdict); void hmp_set_link(Monitor *mon, const QDict *qdict); -void hmp_block_passwd(Monitor *mon, const QDict *qdict); void hmp_balloon(Monitor *mon, const QDict *qdict); -void hmp_block_resize(Monitor *mon, const QDict *qdict); void hmp_loadvm(Monitor *mon, const QDict *qdict); void hmp_savevm(Monitor *mon, const QDict *qdict); void hmp_delvm(Monitor *mon, const QDict *qdict); @@ -80,10 +78,7 @@ void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict); void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict); void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); -void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mon, const QDict *qdict); -void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict); -void hmp_block_stream(Monitor *mon, const QDict *qdict); void hmp_migrate(Monitor *mon, const QDict *qdict); void hmp_device_add(Monitor *mon, const QDict *qdict); void hmp_device_del(Monitor *mon, const QDict *qdict); @@ -98,7 +93,6 @@ void hmp_chardev_add(Monitor *mon, const QDict *qdict); void hmp_chardev_change(Monitor *mon, const QDict *qdict); void hmp_chardev_remove(Monitor *mon, const QDict *qdict); void hmp_chardev_send_break(Monitor *mon, const QDict *qdict); -void hmp_qemu_io(Monitor *mon, const QDict *qdict); void hmp_cpu_add(Monitor *mon, const QDict *qdict); void hmp_object_add(Monitor *mon, const QDict *qdict); void hmp_object_del(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 67d2ca8a4c..c224e0f338 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -46,7 +46,6 @@ #include "qom/object_interfaces.h" #include "ui/console.h" #include "block/qapi.h" -#include "qemu-io.h" #include "qemu/cutils.h" #include "qemu/error-report.h" #include "exec/ramlist.h" @@ -1307,16 +1306,6 @@ void hmp_set_link(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } -void hmp_block_passwd(Monitor *mon, const QDict *qdict) -{ - const char *device = qdict_get_str(qdict, "device"); - const char *password = qdict_get_str(qdict, "password"); - Error *err = NULL; - - qmp_block_passwd(true, device, false, NULL, password, &err); - hmp_handle_error(mon, err); -} - void hmp_balloon(Monitor *mon, const QDict *qdict) { int64_t value = qdict_get_int(qdict, "value"); @@ -1326,16 +1315,6 @@ void hmp_balloon(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } -void hmp_block_resize(Monitor *mon, const QDict *qdict) -{ - const char *device = qdict_get_str(qdict, "device"); - int64_t size = qdict_get_int(qdict, "size"); - Error *err = NULL; - - qmp_block_resize(true, device, false, NULL, size, &err); - hmp_handle_error(mon, err); -} - void hmp_loadvm(Monitor *mon, const QDict *qdict) { int saved_vm_running = runstate_is_running(); @@ -1818,15 +1797,6 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } -void hmp_eject(Monitor *mon, const QDict *qdict) -{ - bool force = qdict_get_try_bool(qdict, "force", false); - const char *device = qdict_get_str(qdict, "device"); - Error *err = NULL; - - qmp_eject(true, device, false, NULL, true, force, &err); - hmp_handle_error(mon, err); -} #ifdef CONFIG_VNC static void hmp_change_read_arg(void *opaque, const char *password, @@ -1884,49 +1854,6 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } -void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) -{ - Error *err = NULL; - char *device = (char *) qdict_get_str(qdict, "device"); - BlockIOThrottle throttle = { - .bps = qdict_get_int(qdict, "bps"), - .bps_rd = qdict_get_int(qdict, "bps_rd"), - .bps_wr = qdict_get_int(qdict, "bps_wr"), - .iops = qdict_get_int(qdict, "iops"), - .iops_rd = qdict_get_int(qdict, "iops_rd"), - .iops_wr = qdict_get_int(qdict, "iops_wr"), - }; - - /* qmp_block_set_io_throttle has separate parameters for the - * (deprecated) block device name and the qdev ID but the HMP - * version has only one, so we must decide which one to pass. */ - if (blk_by_name(device)) { - throttle.has_device = true; - throttle.device = device; - } else { - throttle.has_id = true; - throttle.id = device; - } - - qmp_block_set_io_throttle(&throttle, &err); - hmp_handle_error(mon, err); -} - -void hmp_block_stream(Monitor *mon, const QDict *qdict) -{ - Error *error = NULL; - const char *device = qdict_get_str(qdict, "device"); - const char *base = qdict_get_try_str(qdict, "base"); - int64_t speed = qdict_get_try_int(qdict, "speed", 0); - - qmp_block_stream(true, device, device, base != NULL, base, false, NULL, - false, NULL, qdict_haskey(qdict, "speed"), speed, true, - BLOCKDEV_ON_ERROR_REPORT, false, false, false, false, - &error); - - hmp_handle_error(mon, error); -} - typedef struct HMPMigrationStatus { QEMUTimer *timer; @@ -2219,70 +2146,6 @@ void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, local_err); } -void hmp_qemu_io(Monitor *mon, const QDict *qdict) -{ - BlockBackend *blk; - BlockBackend *local_blk = NULL; - bool qdev = qdict_get_try_bool(qdict, "qdev", false); - const char* device = qdict_get_str(qdict, "device"); - const char* command = qdict_get_str(qdict, "command"); - Error *err = NULL; - int ret; - - if (qdev) { - blk = blk_by_qdev_id(device, &err); - if (!blk) { - goto fail; - } - } else { - blk = blk_by_name(device); - if (!blk) { - BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err); - if (bs) { - blk = local_blk = blk_new(bdrv_get_aio_context(bs), - 0, BLK_PERM_ALL); - ret = blk_insert_bs(blk, bs, &err); - if (ret < 0) { - goto fail; - } - } else { - goto fail; - } - } - } - - /* - * Notably absent: Proper permission management. This is sad, but it seems - * almost impossible to achieve without changing the semantics and thereby - * limiting the use cases of the qemu-io HMP command. - * - * In an ideal world we would unconditionally create a new BlockBackend for - * qemuio_command(), but we have commands like 'reopen' and want them to - * take effect on the exact BlockBackend whose name the user passed instead - * of just on a temporary copy of it. - * - * Another problem is that deleting the temporary BlockBackend involves - * draining all requests on it first, but some qemu-iotests cases want to - * issue multiple aio_read/write requests and expect them to complete in - * the background while the monitor has already returned. - * - * This is also what prevents us from saving the original permissions and - * restoring them later: We can't revoke permissions until all requests - * have completed, and we don't know when that is nor can we really let - * anything else run before we have revoken them to avoid race conditions. - * - * What happens now is that command() in qemu-io-cmds.c can extend the - * permissions if necessary for the qemu-io command. And they simply stay - * extended, possibly resulting in a read-only guest device keeping write - * permissions. Ugly, but it appears to be the lesser evil. - */ - qemuio_command(blk, command); - -fail: - blk_unref(local_blk); - hmp_handle_error(mon, err); -} - void hmp_object_del(Monitor *mon, const QDict *qdict) { const char *id = qdict_get_str(qdict, "id"); From patchwork Thu Jan 30 12:34:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357895 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 DDF281398 for ; Thu, 30 Jan 2020 12:42:34 +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 A37CF206D3 for ; Thu, 30 Jan 2020 12:42:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iea/g5Nw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A37CF206D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix99V-0001FQ-So for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:42:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54899) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92i-0006Qu-A4 for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92e-00056p-VZ for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:32 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:49655 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92e-00056B-Oo for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KZk7mUTmx/TdJ8Tt1UrBaFVXbOvi1epHNGECn9S6ES0=; b=iea/g5NwzUUU3jrsbP43QrmFqO/dYkdx5lrQiGd0IkIqcwhx8k9ov2Oyv+ZIg+tWR1ZyWn K/ZfxJz8JcK599SFBRry/npDEFw5LcWkvh+3Yab/eLds9rxmlpcQ1VZ9EM9Pea2CR5/jjP 4q3ZYxhlI9CS3HyowzhDjz2lWelOQhw= 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-248-dQj-Ztt-Ma2ScoFD75jWBg-1; Thu, 30 Jan 2020 07:35:26 -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 82C5718FF663; Thu, 30 Jan 2020 12:35:25 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50FF6167A3; Thu, 30 Jan 2020 12:35:23 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 10/11] monitor/hmp: move hmp_info_block* to block-hmp-cmds.c Date: Thu, 30 Jan 2020 14:34:47 +0200 Message-Id: <20200130123448.21093-11-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: dQj-Ztt-Ma2ScoFD75jWBg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 390 +++++++++++++++++++++++++++++++++ include/block/block-hmp-cmds.h | 4 + include/monitor/hmp.h | 4 - monitor/hmp-cmds.c | 388 -------------------------------- 4 files changed, 394 insertions(+), 392 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 15bc565527..2ee96f3258 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -44,10 +44,12 @@ #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/sockets.h" +#include "qemu/cutils.h" #include "sysemu/sysemu.h" #include "monitor/monitor.h" #include "monitor/hmp.h" #include "block/nbd.h" +#include "block/qapi.h" #include "block/block_int.h" #include "block/block-hmp-cmds.h" #include "qemu-io.h" @@ -580,3 +582,391 @@ fail: blk_unref(local_blk); hmp_handle_error(mon, err); } + +static void print_block_info(Monitor *mon, BlockInfo *info, + BlockDeviceInfo *inserted, bool verbose) +{ + ImageInfo *image_info; + + assert(!info || !info->has_inserted || info->inserted == inserted); + + if (info && *info->device) { + monitor_printf(mon, "%s", info->device); + if (inserted && inserted->has_node_name) { + monitor_printf(mon, " (%s)", inserted->node_name); + } + } else { + assert(info || inserted); + monitor_printf(mon, "%s", + inserted && inserted->has_node_name ? inserted->node_name + : info && info->has_qdev ? info->qdev + : ""); + } + + if (inserted) { + monitor_printf(mon, ": %s (%s%s%s)\n", + inserted->file, + inserted->drv, + inserted->ro ? ", read-only" : "", + inserted->encrypted ? ", encrypted" : ""); + } else { + monitor_printf(mon, ": [not inserted]\n"); + } + + if (info) { + if (info->has_qdev) { + monitor_printf(mon, " Attached to: %s\n", info->qdev); + } + if (info->has_io_status && + info->io_status != BLOCK_DEVICE_IO_STATUS_OK) { + monitor_printf(mon, " I/O status: %s\n", + BlockDeviceIoStatus_str(info->io_status)); + } + + if (info->removable) { + monitor_printf(mon, " Removable device: %slocked, tray %s\n", + info->locked ? "" : "not ", + info->tray_open ? "open" : "closed"); + } + } + + + if (!inserted) { + return; + } + + monitor_printf(mon, " Cache mode: %s%s%s\n", + inserted->cache->writeback ? "writeback" : "writethrough", + inserted->cache->direct ? ", direct" : "", + inserted->cache->no_flush ? ", ignore flushes" : ""); + + if (inserted->has_backing_file) { + monitor_printf(mon, + " Backing file: %s " + "(chain depth: %" PRId64 ")\n", + inserted->backing_file, + inserted->backing_file_depth); + } + + if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { + monitor_printf(mon, " Detect zeroes: %s\n", + BlockdevDetectZeroesOptions_str(inserted->detect_zeroes)); + } + + if (inserted->bps || inserted->bps_rd || inserted->bps_wr || + inserted->iops || inserted->iops_rd || inserted->iops_wr) + { + monitor_printf(mon, " I/O throttling: bps=%" PRId64 + " bps_rd=%" PRId64 " bps_wr=%" PRId64 + " bps_max=%" PRId64 + " bps_rd_max=%" PRId64 + " bps_wr_max=%" PRId64 + " iops=%" PRId64 " iops_rd=%" PRId64 + " iops_wr=%" PRId64 + " iops_max=%" PRId64 + " iops_rd_max=%" PRId64 + " iops_wr_max=%" PRId64 + " iops_size=%" PRId64 + " group=%s\n", + inserted->bps, + inserted->bps_rd, + inserted->bps_wr, + inserted->bps_max, + inserted->bps_rd_max, + inserted->bps_wr_max, + inserted->iops, + inserted->iops_rd, + inserted->iops_wr, + inserted->iops_max, + inserted->iops_rd_max, + inserted->iops_wr_max, + inserted->iops_size, + inserted->group); + } + + if (verbose) { + monitor_printf(mon, "\nImages:\n"); + image_info = inserted->image; + while (1) { + bdrv_image_info_dump(image_info); + if (image_info->has_backing_image) { + image_info = image_info->backing_image; + } else { + break; + } + } + } +} + +void hmp_info_block(Monitor *mon, const QDict *qdict) +{ + BlockInfoList *block_list, *info; + BlockDeviceInfoList *blockdev_list, *blockdev; + const char *device = qdict_get_try_str(qdict, "device"); + bool verbose = qdict_get_try_bool(qdict, "verbose", false); + bool nodes = qdict_get_try_bool(qdict, "nodes", false); + bool printed = false; + + /* Print BlockBackend information */ + if (!nodes) { + block_list = qmp_query_block(NULL); + } else { + block_list = NULL; + } + + for (info = block_list; info; info = info->next) { + if (device && strcmp(device, info->value->device)) { + continue; + } + + if (info != block_list) { + monitor_printf(mon, "\n"); + } + + print_block_info(mon, info->value, info->value->has_inserted + ? info->value->inserted : NULL, + verbose); + printed = true; + } + + qapi_free_BlockInfoList(block_list); + + if ((!device && !nodes) || printed) { + return; + } + + /* Print node information */ + blockdev_list = qmp_query_named_block_nodes(NULL); + for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { + assert(blockdev->value->has_node_name); + if (device && strcmp(device, blockdev->value->node_name)) { + continue; + } + + if (blockdev != blockdev_list) { + monitor_printf(mon, "\n"); + } + + print_block_info(mon, NULL, blockdev->value, verbose); + } + qapi_free_BlockDeviceInfoList(blockdev_list); +} + +void hmp_info_blockstats(Monitor *mon, const QDict *qdict) +{ + BlockStatsList *stats_list, *stats; + + stats_list = qmp_query_blockstats(false, false, NULL); + + for (stats = stats_list; stats; stats = stats->next) { + if (!stats->value->has_device) { + continue; + } + + monitor_printf(mon, "%s:", stats->value->device); + monitor_printf(mon, " rd_bytes=%" PRId64 + " wr_bytes=%" PRId64 + " rd_operations=%" PRId64 + " wr_operations=%" PRId64 + " flush_operations=%" PRId64 + " wr_total_time_ns=%" PRId64 + " rd_total_time_ns=%" PRId64 + " flush_total_time_ns=%" PRId64 + " rd_merged=%" PRId64 + " wr_merged=%" PRId64 + " idle_time_ns=%" PRId64 + "\n", + stats->value->stats->rd_bytes, + stats->value->stats->wr_bytes, + stats->value->stats->rd_operations, + stats->value->stats->wr_operations, + stats->value->stats->flush_operations, + stats->value->stats->wr_total_time_ns, + stats->value->stats->rd_total_time_ns, + stats->value->stats->flush_total_time_ns, + stats->value->stats->rd_merged, + stats->value->stats->wr_merged, + stats->value->stats->idle_time_ns); + } + + qapi_free_BlockStatsList(stats_list); +} + +void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) +{ + BlockJobInfoList *list; + Error *err = NULL; + + list = qmp_query_block_jobs(&err); + assert(!err); + + if (!list) { + monitor_printf(mon, "No active jobs\n"); + return; + } + + while (list) { + if (strcmp(list->value->type, "stream") == 0) { + monitor_printf(mon, "Streaming device %s: Completed %" PRId64 + " of %" PRId64 " bytes, speed limit %" PRId64 + " bytes/s\n", + list->value->device, + list->value->offset, + list->value->len, + list->value->speed); + } else { + monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 + " of %" PRId64 " bytes, speed limit %" PRId64 + " bytes/s\n", + list->value->type, + list->value->device, + list->value->offset, + list->value->len, + list->value->speed); + } + list = list->next; + } + + qapi_free_BlockJobInfoList(list); +} + +void hmp_info_snapshots(Monitor *mon, const QDict *qdict) +{ + BlockDriverState *bs, *bs1; + BdrvNextIterator it1; + QEMUSnapshotInfo *sn_tab, *sn; + bool no_snapshot = true; + int nb_sns, i; + int total; + int *global_snapshots; + AioContext *aio_context; + + typedef struct SnapshotEntry { + QEMUSnapshotInfo sn; + QTAILQ_ENTRY(SnapshotEntry) next; + } SnapshotEntry; + + typedef struct ImageEntry { + const char *imagename; + QTAILQ_ENTRY(ImageEntry) next; + QTAILQ_HEAD(, SnapshotEntry) snapshots; + } ImageEntry; + + QTAILQ_HEAD(, ImageEntry) image_list = + QTAILQ_HEAD_INITIALIZER(image_list); + + ImageEntry *image_entry, *next_ie; + SnapshotEntry *snapshot_entry; + + bs = bdrv_all_find_vmstate_bs(); + if (!bs) { + monitor_printf(mon, "No available block device supports snapshots\n"); + return; + } + aio_context = bdrv_get_aio_context(bs); + + aio_context_acquire(aio_context); + nb_sns = bdrv_snapshot_list(bs, &sn_tab); + aio_context_release(aio_context); + + if (nb_sns < 0) { + monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns); + return; + } + + for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) { + int bs1_nb_sns = 0; + ImageEntry *ie; + SnapshotEntry *se; + AioContext *ctx = bdrv_get_aio_context(bs1); + + aio_context_acquire(ctx); + if (bdrv_can_snapshot(bs1)) { + sn = NULL; + bs1_nb_sns = bdrv_snapshot_list(bs1, &sn); + if (bs1_nb_sns > 0) { + no_snapshot = false; + ie = g_new0(ImageEntry, 1); + ie->imagename = bdrv_get_device_name(bs1); + QTAILQ_INIT(&ie->snapshots); + QTAILQ_INSERT_TAIL(&image_list, ie, next); + for (i = 0; i < bs1_nb_sns; i++) { + se = g_new0(SnapshotEntry, 1); + se->sn = sn[i]; + QTAILQ_INSERT_TAIL(&ie->snapshots, se, next); + } + } + g_free(sn); + } + aio_context_release(ctx); + } + + if (no_snapshot) { + monitor_printf(mon, "There is no snapshot available.\n"); + return; + } + + global_snapshots = g_new0(int, nb_sns); + total = 0; + for (i = 0; i < nb_sns; i++) { + SnapshotEntry *next_sn; + if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) { + global_snapshots[total] = i; + total++; + QTAILQ_FOREACH(image_entry, &image_list, next) { + QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, + next, next_sn) { + if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) { + QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry, + next); + g_free(snapshot_entry); + } + } + } + } + } + monitor_printf(mon, "List of snapshots present on all disks:\n"); + + if (total > 0) { + bdrv_snapshot_dump(NULL); + monitor_printf(mon, "\n"); + for (i = 0; i < total; i++) { + sn = &sn_tab[global_snapshots[i]]; + /* + * The ID is not guaranteed to be the same on all images, so + * overwrite it. + */ + pstrcpy(sn->id_str, sizeof(sn->id_str), "--"); + bdrv_snapshot_dump(sn); + monitor_printf(mon, "\n"); + } + } else { + monitor_printf(mon, "None\n"); + } + + QTAILQ_FOREACH(image_entry, &image_list, next) { + if (QTAILQ_EMPTY(&image_entry->snapshots)) { + continue; + } + monitor_printf(mon, + "\nList of partial (non-loadable) snapshots on '%s':\n", + image_entry->imagename); + bdrv_snapshot_dump(NULL); + monitor_printf(mon, "\n"); + QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) { + bdrv_snapshot_dump(&snapshot_entry->sn); + monitor_printf(mon, "\n"); + } + } + + QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) { + SnapshotEntry *next_sn; + QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next, + next_sn) { + g_free(snapshot_entry); + } + g_free(image_entry); + } + g_free(sn_tab); + g_free(global_snapshots); +} diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h index c2d18fba06..3412e108ca 100644 --- a/include/block/block-hmp-cmds.h +++ b/include/block/block-hmp-cmds.h @@ -46,5 +46,9 @@ void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_qemu_io(Monitor *mon, const QDict *qdict); +void hmp_info_block(Monitor *mon, const QDict *qdict); +void hmp_info_blockstats(Monitor *mon, const QDict *qdict); +void hmp_info_block_jobs(Monitor *mon, const QDict *qdict); +void hmp_info_snapshots(Monitor *mon, const QDict *qdict); #endif diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 47a7cad734..e33ca5a911 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -30,8 +30,6 @@ void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict); void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict); void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict); void hmp_info_cpus(Monitor *mon, const QDict *qdict); -void hmp_info_block(Monitor *mon, const QDict *qdict); -void hmp_info_blockstats(Monitor *mon, const QDict *qdict); void hmp_info_vnc(Monitor *mon, const QDict *qdict); void hmp_info_spice(Monitor *mon, const QDict *qdict); void hmp_info_balloon(Monitor *mon, const QDict *qdict); @@ -39,7 +37,6 @@ void hmp_info_irq(Monitor *mon, const QDict *qdict); void hmp_info_pic(Monitor *mon, const QDict *qdict); void hmp_info_rdma(Monitor *mon, const QDict *qdict); void hmp_info_pci(Monitor *mon, const QDict *qdict); -void hmp_info_block_jobs(Monitor *mon, const QDict *qdict); void hmp_info_tpm(Monitor *mon, const QDict *qdict); void hmp_info_iothreads(Monitor *mon, const QDict *qdict); void hmp_quit(Monitor *mon, const QDict *qdict); @@ -62,7 +59,6 @@ void hmp_balloon(Monitor *mon, const QDict *qdict); void hmp_loadvm(Monitor *mon, const QDict *qdict); void hmp_savevm(Monitor *mon, const QDict *qdict); void hmp_delvm(Monitor *mon, const QDict *qdict); -void hmp_info_snapshots(Monitor *mon, const QDict *qdict); void hmp_migrate_cancel(Monitor *mon, const QDict *qdict); void hmp_migrate_continue(Monitor *mon, const QDict *qdict); void hmp_migrate_incoming(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index c224e0f338..1ddfe2fceb 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -45,7 +45,6 @@ #include "qapi/string-output-visitor.h" #include "qom/object_interfaces.h" #include "ui/console.h" -#include "block/qapi.h" #include "qemu/cutils.h" #include "qemu/error-report.h" #include "exec/ramlist.h" @@ -465,213 +464,6 @@ void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) qmp_query_migrate_cache_size(NULL) >> 10); } -static void print_block_info(Monitor *mon, BlockInfo *info, - BlockDeviceInfo *inserted, bool verbose) -{ - ImageInfo *image_info; - - assert(!info || !info->has_inserted || info->inserted == inserted); - - if (info && *info->device) { - monitor_printf(mon, "%s", info->device); - if (inserted && inserted->has_node_name) { - monitor_printf(mon, " (%s)", inserted->node_name); - } - } else { - assert(info || inserted); - monitor_printf(mon, "%s", - inserted && inserted->has_node_name ? inserted->node_name - : info && info->has_qdev ? info->qdev - : ""); - } - - if (inserted) { - monitor_printf(mon, ": %s (%s%s%s)\n", - inserted->file, - inserted->drv, - inserted->ro ? ", read-only" : "", - inserted->encrypted ? ", encrypted" : ""); - } else { - monitor_printf(mon, ": [not inserted]\n"); - } - - if (info) { - if (info->has_qdev) { - monitor_printf(mon, " Attached to: %s\n", info->qdev); - } - if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) { - monitor_printf(mon, " I/O status: %s\n", - BlockDeviceIoStatus_str(info->io_status)); - } - - if (info->removable) { - monitor_printf(mon, " Removable device: %slocked, tray %s\n", - info->locked ? "" : "not ", - info->tray_open ? "open" : "closed"); - } - } - - - if (!inserted) { - return; - } - - monitor_printf(mon, " Cache mode: %s%s%s\n", - inserted->cache->writeback ? "writeback" : "writethrough", - inserted->cache->direct ? ", direct" : "", - inserted->cache->no_flush ? ", ignore flushes" : ""); - - if (inserted->has_backing_file) { - monitor_printf(mon, - " Backing file: %s " - "(chain depth: %" PRId64 ")\n", - inserted->backing_file, - inserted->backing_file_depth); - } - - if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { - monitor_printf(mon, " Detect zeroes: %s\n", - BlockdevDetectZeroesOptions_str(inserted->detect_zeroes)); - } - - if (inserted->bps || inserted->bps_rd || inserted->bps_wr || - inserted->iops || inserted->iops_rd || inserted->iops_wr) - { - monitor_printf(mon, " I/O throttling: bps=%" PRId64 - " bps_rd=%" PRId64 " bps_wr=%" PRId64 - " bps_max=%" PRId64 - " bps_rd_max=%" PRId64 - " bps_wr_max=%" PRId64 - " iops=%" PRId64 " iops_rd=%" PRId64 - " iops_wr=%" PRId64 - " iops_max=%" PRId64 - " iops_rd_max=%" PRId64 - " iops_wr_max=%" PRId64 - " iops_size=%" PRId64 - " group=%s\n", - inserted->bps, - inserted->bps_rd, - inserted->bps_wr, - inserted->bps_max, - inserted->bps_rd_max, - inserted->bps_wr_max, - inserted->iops, - inserted->iops_rd, - inserted->iops_wr, - inserted->iops_max, - inserted->iops_rd_max, - inserted->iops_wr_max, - inserted->iops_size, - inserted->group); - } - - if (verbose) { - monitor_printf(mon, "\nImages:\n"); - image_info = inserted->image; - while (1) { - bdrv_image_info_dump(image_info); - if (image_info->has_backing_image) { - image_info = image_info->backing_image; - } else { - break; - } - } - } -} - -void hmp_info_block(Monitor *mon, const QDict *qdict) -{ - BlockInfoList *block_list, *info; - BlockDeviceInfoList *blockdev_list, *blockdev; - const char *device = qdict_get_try_str(qdict, "device"); - bool verbose = qdict_get_try_bool(qdict, "verbose", false); - bool nodes = qdict_get_try_bool(qdict, "nodes", false); - bool printed = false; - - /* Print BlockBackend information */ - if (!nodes) { - block_list = qmp_query_block(NULL); - } else { - block_list = NULL; - } - - for (info = block_list; info; info = info->next) { - if (device && strcmp(device, info->value->device)) { - continue; - } - - if (info != block_list) { - monitor_printf(mon, "\n"); - } - - print_block_info(mon, info->value, info->value->has_inserted - ? info->value->inserted : NULL, - verbose); - printed = true; - } - - qapi_free_BlockInfoList(block_list); - - if ((!device && !nodes) || printed) { - return; - } - - /* Print node information */ - blockdev_list = qmp_query_named_block_nodes(NULL); - for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { - assert(blockdev->value->has_node_name); - if (device && strcmp(device, blockdev->value->node_name)) { - continue; - } - - if (blockdev != blockdev_list) { - monitor_printf(mon, "\n"); - } - - print_block_info(mon, NULL, blockdev->value, verbose); - } - qapi_free_BlockDeviceInfoList(blockdev_list); -} - -void hmp_info_blockstats(Monitor *mon, const QDict *qdict) -{ - BlockStatsList *stats_list, *stats; - - stats_list = qmp_query_blockstats(false, false, NULL); - - for (stats = stats_list; stats; stats = stats->next) { - if (!stats->value->has_device) { - continue; - } - - monitor_printf(mon, "%s:", stats->value->device); - monitor_printf(mon, " rd_bytes=%" PRId64 - " wr_bytes=%" PRId64 - " rd_operations=%" PRId64 - " wr_operations=%" PRId64 - " flush_operations=%" PRId64 - " wr_total_time_ns=%" PRId64 - " rd_total_time_ns=%" PRId64 - " flush_total_time_ns=%" PRId64 - " rd_merged=%" PRId64 - " wr_merged=%" PRId64 - " idle_time_ns=%" PRId64 - "\n", - stats->value->stats->rd_bytes, - stats->value->stats->wr_bytes, - stats->value->stats->rd_operations, - stats->value->stats->wr_operations, - stats->value->stats->flush_operations, - stats->value->stats->wr_total_time_ns, - stats->value->stats->rd_total_time_ns, - stats->value->stats->flush_total_time_ns, - stats->value->stats->rd_merged, - stats->value->stats->wr_merged, - stats->value->stats->idle_time_ns); - } - - qapi_free_BlockStatsList(stats_list); -} #ifdef CONFIG_VNC /* Helper for hmp_info_vnc_clients, _servers */ @@ -1051,44 +843,6 @@ void hmp_info_pci(Monitor *mon, const QDict *qdict) qapi_free_PciInfoList(info_list); } -void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) -{ - BlockJobInfoList *list; - Error *err = NULL; - - list = qmp_query_block_jobs(&err); - assert(!err); - - if (!list) { - monitor_printf(mon, "No active jobs\n"); - return; - } - - while (list) { - if (strcmp(list->value->type, "stream") == 0) { - monitor_printf(mon, "Streaming device %s: Completed %" PRId64 - " of %" PRId64 " bytes, speed limit %" PRId64 - " bytes/s\n", - list->value->device, - list->value->offset, - list->value->len, - list->value->speed); - } else { - monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 - " of %" PRId64 " bytes, speed limit %" PRId64 - " bytes/s\n", - list->value->type, - list->value->device, - list->value->offset, - list->value->len, - list->value->speed); - } - list = list->next; - } - - qapi_free_BlockJobInfoList(list); -} - void hmp_info_tpm(Monitor *mon, const QDict *qdict) { TPMInfoList *info_list, *info; @@ -1351,148 +1105,6 @@ void hmp_delvm(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } -void hmp_info_snapshots(Monitor *mon, const QDict *qdict) -{ - BlockDriverState *bs, *bs1; - BdrvNextIterator it1; - QEMUSnapshotInfo *sn_tab, *sn; - bool no_snapshot = true; - int nb_sns, i; - int total; - int *global_snapshots; - AioContext *aio_context; - - typedef struct SnapshotEntry { - QEMUSnapshotInfo sn; - QTAILQ_ENTRY(SnapshotEntry) next; - } SnapshotEntry; - - typedef struct ImageEntry { - const char *imagename; - QTAILQ_ENTRY(ImageEntry) next; - QTAILQ_HEAD(, SnapshotEntry) snapshots; - } ImageEntry; - - QTAILQ_HEAD(, ImageEntry) image_list = - QTAILQ_HEAD_INITIALIZER(image_list); - - ImageEntry *image_entry, *next_ie; - SnapshotEntry *snapshot_entry; - - bs = bdrv_all_find_vmstate_bs(); - if (!bs) { - monitor_printf(mon, "No available block device supports snapshots\n"); - return; - } - aio_context = bdrv_get_aio_context(bs); - - aio_context_acquire(aio_context); - nb_sns = bdrv_snapshot_list(bs, &sn_tab); - aio_context_release(aio_context); - - if (nb_sns < 0) { - monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns); - return; - } - - for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) { - int bs1_nb_sns = 0; - ImageEntry *ie; - SnapshotEntry *se; - AioContext *ctx = bdrv_get_aio_context(bs1); - - aio_context_acquire(ctx); - if (bdrv_can_snapshot(bs1)) { - sn = NULL; - bs1_nb_sns = bdrv_snapshot_list(bs1, &sn); - if (bs1_nb_sns > 0) { - no_snapshot = false; - ie = g_new0(ImageEntry, 1); - ie->imagename = bdrv_get_device_name(bs1); - QTAILQ_INIT(&ie->snapshots); - QTAILQ_INSERT_TAIL(&image_list, ie, next); - for (i = 0; i < bs1_nb_sns; i++) { - se = g_new0(SnapshotEntry, 1); - se->sn = sn[i]; - QTAILQ_INSERT_TAIL(&ie->snapshots, se, next); - } - } - g_free(sn); - } - aio_context_release(ctx); - } - - if (no_snapshot) { - monitor_printf(mon, "There is no snapshot available.\n"); - return; - } - - global_snapshots = g_new0(int, nb_sns); - total = 0; - for (i = 0; i < nb_sns; i++) { - SnapshotEntry *next_sn; - if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) { - global_snapshots[total] = i; - total++; - QTAILQ_FOREACH(image_entry, &image_list, next) { - QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, - next, next_sn) { - if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) { - QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry, - next); - g_free(snapshot_entry); - } - } - } - } - } - - monitor_printf(mon, "List of snapshots present on all disks:\n"); - - if (total > 0) { - bdrv_snapshot_dump(NULL); - monitor_printf(mon, "\n"); - for (i = 0; i < total; i++) { - sn = &sn_tab[global_snapshots[i]]; - /* The ID is not guaranteed to be the same on all images, so - * overwrite it. - */ - pstrcpy(sn->id_str, sizeof(sn->id_str), "--"); - bdrv_snapshot_dump(sn); - monitor_printf(mon, "\n"); - } - } else { - monitor_printf(mon, "None\n"); - } - - QTAILQ_FOREACH(image_entry, &image_list, next) { - if (QTAILQ_EMPTY(&image_entry->snapshots)) { - continue; - } - monitor_printf(mon, - "\nList of partial (non-loadable) snapshots on '%s':\n", - image_entry->imagename); - bdrv_snapshot_dump(NULL); - monitor_printf(mon, "\n"); - QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) { - bdrv_snapshot_dump(&snapshot_entry->sn); - monitor_printf(mon, "\n"); - } - } - - QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) { - SnapshotEntry *next_sn; - QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next, - next_sn) { - g_free(snapshot_entry); - } - g_free(image_entry); - } - g_free(sn_tab); - g_free(global_snapshots); - -} - void hmp_announce_self(Monitor *mon, const QDict *qdict) { const char *interfaces_str = qdict_get_try_str(qdict, "interfaces"); From patchwork Thu Jan 30 12:34:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11357893 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 BB48992A for ; Thu, 30 Jan 2020 12:41:02 +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 91E79206D3 for ; Thu, 30 Jan 2020 12:41:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W36c5Ov3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 91E79206D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60109 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix981-00083y-Nv for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jan 2020 07:41:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54911) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ix92i-0006SC-PG for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ix92h-0005Cb-HF for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:32 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:37008 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ix92h-0005Bx-C8 for qemu-devel@nongnu.org; Thu, 30 Jan 2020 07:35:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580387731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fJUPOHmntB9ho2HtJMwQbVXRTaucc5wHz3u9jhdGrNU=; b=W36c5Ov3tVP1n3N9snKwx9nc/X2510XoK7Cg28gk9w4a3uLWjkPNqvqmCh9Ns0sIWTHAJW gJJTkc34rvjRVvR2cXYrPGXyjqyJ8kbhflAoCwdcCWJG3rcHs5WM1QlLMKvvRYh1T/5095 WQMTqmX7aG94+wprpR8AyBQXIAnFvP0= 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-74-lCUfIltONj-A3tZDaS4lwg-1; Thu, 30 Jan 2020 07:35:28 -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 DDA84800D53; Thu, 30 Jan 2020 12:35:27 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCEAD166A9; Thu, 30 Jan 2020 12:35:25 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v4 11/11] monitor/hmp: Move hmp_drive_add_node to block-hmp-cmds.c Date: Thu, 30 Jan 2020 14:34:48 +0200 Message-Id: <20200130123448.21093-12-mlevitsk@redhat.com> In-Reply-To: <20200130123448.21093-1-mlevitsk@redhat.com> References: <20200130123448.21093-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: lCUfIltONj-A3tZDaS4lwg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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 , Maxim Levitsky , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Gerd Hoffmann , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 30 ++++++++++++++++++++++++ blockdev.c | 42 +++++++--------------------------- include/block/block_int.h | 5 ++-- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 2ee96f3258..67098e3d51 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -54,6 +54,36 @@ #include "block/block-hmp-cmds.h" #include "qemu-io.h" +static void hmp_drive_add_node(Monitor *mon, const char *optstr) +{ + QemuOpts *opts; + QDict *qdict; + Error *local_err = NULL; + + opts = qemu_opts_parse_noisily(&qemu_drive_opts, optstr, false); + if (!opts) { + return; + } + + qdict = qemu_opts_to_qdict(opts, NULL); + + if (!qdict_get_try_str(qdict, "node-name")) { + qobject_unref(qdict); + error_report("'node-name' needs to be specified"); + goto out; + } + + BlockDriverState *bs = bds_tree_init(qdict, &local_err); + if (!bs) { + error_report_err(local_err); + goto out; + } + + bdrv_set_monitor_owned(bs); +out: + qemu_opts_del(opts); +} + void hmp_drive_add(Monitor *mon, const QDict *qdict) { Error *err = NULL; diff --git a/blockdev.c b/blockdev.c index f2c5ea8a87..d422ac4fe3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -64,7 +64,7 @@ #include "qemu/main-loop.h" #include "qemu/throttle-options.h" -static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states = +QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states = QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states); static int do_open_tray(const char *blk_name, const char *qdev_id, @@ -75,6 +75,11 @@ static void blockdev_insert_medium(bool has_device, const char *device, bool has_id, const char *id, const char *node_name, Error **errp); +void bdrv_set_monitor_owned(BlockDriverState *bs) +{ + QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list); +} + static const char *const if_name[IF_COUNT] = { [IF_NONE] = "none", [IF_IDE] = "ide", @@ -652,7 +657,7 @@ err_no_opts: } /* Takes the ownership of bs_opts */ -static BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp) +BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp) { int bdrv_flags = 0; @@ -4232,37 +4237,6 @@ out: aio_context_release(aio_context); } -void hmp_drive_add_node(Monitor *mon, const char *optstr) -{ - QemuOpts *opts; - QDict *qdict; - Error *local_err = NULL; - - opts = qemu_opts_parse_noisily(&qemu_drive_opts, optstr, false); - if (!opts) { - return; - } - - qdict = qemu_opts_to_qdict(opts, NULL); - - if (!qdict_get_try_str(qdict, "node-name")) { - qobject_unref(qdict); - error_report("'node-name' needs to be specified"); - goto out; - } - - BlockDriverState *bs = bds_tree_init(qdict, &local_err); - if (!bs) { - error_report_err(local_err); - goto out; - } - - QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list); - -out: - qemu_opts_del(opts); -} - void qmp_blockdev_add(BlockdevOptions *options, Error **errp) { BlockDriverState *bs; @@ -4292,7 +4266,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp) goto fail; } - QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list); + bdrv_set_monitor_owned(bs); fail: visit_free(v); diff --git a/include/block/block_int.h b/include/block/block_int.h index dd033d0b37..10df257a61 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1217,8 +1217,6 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque, JobTxn *txn, Error **errp); -void hmp_drive_add_node(Monitor *mon, const char *optstr); - BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, const BdrvChildRole *child_role, @@ -1320,4 +1318,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, uint64_t src_offset, int refresh_total_sectors(BlockDriverState *bs, int64_t hint); +void bdrv_set_monitor_owned(BlockDriverState *bs); +BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp); + #endif /* BLOCK_INT_H */