From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659555; cv=none; d=zohomail.com; s=zohoarc; b=aY0SxKqWGn2u6Vgxtz/MlhlVm4dA/o9bpX1OINwoUgw0yjPHTLR7gnxETkN6c3e1fHF0FmoEX/fXUEyfPssjIltHIGeWRZrC2O5SqVHSnVfMrKk5jWzoOcg5gEXIdacLCmrqACupZIeS+m60a4iD0W8yK1MnBX6dEHyadW463jc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659555; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yZ9hXAgel0JCQem0cV9DcJj66tjzrqDTdBjSfttmMJw=; b=YkUh0BkMzJn4D56bexNm2e9zj5Z2ntd4bkNToAMFpe/8FEUm3gY8vnWSvCJB2uCdas10NBz1KgZCVkZi9kaMJHwJZBDONXahRdaMhjJCwqNAs3LDYtVSFfV6nb9TBPcw5AXikEOfYHUAcm/4rjH+HZC/BN/MnybbaSnbDJSlXmY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583659555587486.96837670142304; Sun, 8 Mar 2020 01:25:55 -0800 (PST) Received: from localhost ([::1]:56256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsC2-00049c-2m for importer@patchew.org; Sun, 08 Mar 2020 05:25:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55816) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsB5-0002by-Nx for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:24:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsB3-0008PH-HS for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:24:55 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:49326 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 1jAsB3-0008Oj-Ec for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:24:53 -0400 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-426-kif1jvKhPRumLhx98vGoEg-1; Sun, 08 Mar 2020 05:24:50 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B20A08017CC; Sun, 8 Mar 2020 09:24:49 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8651B10027B8; Sun, 8 Mar 2020 09:24:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659492; 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=PoHxHaWmZwcCDdeVYvJDGSFELFH/QkLomTtGXRFDRzhiEl1NtbdD6vo4VvLoLQk1wfzxAK 42xP1nLaEn/3p1KzToZsZLHsKAAVmzN0S6WwEDVK1iD3zCreh6Zq6i/GeeIZugtLa3ZiRm fnsLL93ijFvWH8505zNpXRyVo1iTx4k= X-MC-Unique: kif1jvKhPRumLhx98vGoEg-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 01/11] usb/dev-storage: remove unused include Date: Sun, 8 Mar 2020 11:24:30 +0200 Message-Id: <20200308092440.23564-2-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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" --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659556; cv=none; d=zohomail.com; s=zohoarc; b=I9/OCaf1wKfLY4rMjb104uEyyMeLnhjIcMaDp6zlfoOq6rPg3a1JRX0GZphg5dhD44G7uBmlArLyr5JTGR5/7lbrcVlNfEX1Ziw/rf1znoKv+1OtpFgHc1XcQ9xIHT+P8gPEzgJkCde+JDj7X9KqJb5FHMfrkw58arCELAFkhTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659556; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=qNpcWxMNhKSHAyHJ/6I9p7T+0h3KsCJucmDPFGTxZrA=; b=doZZsRdCDUnwN7E9Q2ojzMxA7LVLO+htwRXFqkOk/xkeGu60+imO4ZUpih0lhkoj8kJiG1ki6fr324PHBN1GCNhN5p/3mo8g6ng+7F+xcwP/bK/ZNiKcCwnnWcYr6x9yBy2u617aBm9DU/7/QQbwIFXHVhfs04elv2X2Ztdo74Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158365955609334.8009839044837; Sun, 8 Mar 2020 01:25:56 -0800 (PST) Received: from localhost ([::1]:56258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsC3-0004Bo-2V for importer@patchew.org; Sun, 08 Mar 2020 05:25:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55839) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsB6-0002cH-QY for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:24:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsB5-0008QA-S7 for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:24:56 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:37204 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 1jAsB5-0008Pt-Oa for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:24:55 -0400 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-245-HV0oCh05PoGtAUariO1roQ-1; Sun, 08 Mar 2020 05:24:53 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FF0B477; Sun, 8 Mar 2020 09:24:52 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20F5A101D486; Sun, 8 Mar 2020 09:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659495; 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=qNpcWxMNhKSHAyHJ/6I9p7T+0h3KsCJucmDPFGTxZrA=; b=Y6fp7QCCaf8E1d/lDnT19ziC9d10uvwCbNfsKVroBquCMw0NvYrAG/SQI/77iDWvLO4wYB MWA1ywS1zcq/FCU6wG0oD/SCel9hKYmo9qvkptN9bmlSH4oKvTyCbdEzyDRVGnFmDI/vyP JkA4soJiyx6S8nsd95ozp/U/LSbpooc= X-MC-Unique: HV0oCh05PoGtAUariO1roQ-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 02/11] monitor/hmp: inline add_init_drive Date: Sun, 8 Mar 2020 11:24:31 +0200 Message-Id: <20200308092440.23564-3-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This function 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" =20 -static DriveInfo *add_init_drive(const char *optstr) + +void hmp_drive_add(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; DriveInfo *dinfo; QemuOpts *opts; MachineClass *mc; + const char *optstr =3D qdict_get_str(qdict, "opts"); + bool node =3D qdict_get_try_bool(qdict, "node", false); + + if (node) { + hmp_drive_add_node(mon, optstr); + return; + } =20 opts =3D drive_def(optstr); if (!opts) - return NULL; + return; =20 mc =3D MACHINE_GET_CLASS(current_machine); dinfo =3D 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 =3D NULL; - const char *opts =3D qdict_get_str(qdict, "opts"); - bool node =3D qdict_get_try_bool(qdict, "node", false); - - if (node) { - hmp_drive_add_node(mon, opts); - return; + goto err; } =20 - dinfo =3D add_init_drive(opts); if (!dinfo) { - goto err; + return; } =20 switch (dinfo->type) { --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659637; cv=none; d=zohomail.com; s=zohoarc; b=liqqKq/AJmHcqElPAOulTxBq8N0+6yRNdpqBklnCEfxMWT8xY4UNt3DLAdT/ASmoKVY2uNTfuaN+gjC5+/04jwPjDCutZ5dzQpvocGCXPMVakkd8NG1RUY2RwiaA/uqkutVX6wNvmNSiaR0Yhq5yF6gnVCy4mYDt1iRvEcN+pEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659637; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=xRtG3JhmvyvgF+sHtipO5m+XE6oaJdutYEaSju2JbUk=; b=RKgA483D3N8oqdAZIi9+34rCJOitXEeFbs54ShTu3xkpO6OAniE4sLr7bwzqNpmhXKleo5uJWRGGhyAY8QvbbdZINQriXfQd2HB0DdNm2BPS9WtWHhn9CDPBGzFyacC1dRkOvfUa+TS0j7jSio2/eW5YC6WchGjFjUAQM/ZD3ME= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158365963736680.2433911474426; Sun, 8 Mar 2020 01:27:17 -0800 (PST) Received: from localhost ([::1]:56284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsDM-0006iP-CT for importer@patchew.org; Sun, 08 Mar 2020 05:27:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55864) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsB9-0002gr-Dr for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsB8-0008RT-54 for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:24:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32887 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 1jAsB8-0008RD-1x for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:24:58 -0400 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-271-Hg4-Qw0xPOq-e9AMt5Cs_Q-1; Sun, 08 Mar 2020 05:24:56 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E0C05107ACCA; Sun, 8 Mar 2020 09:24:54 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id B28C6100E805; Sun, 8 Mar 2020 09:24:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659497; 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=xRtG3JhmvyvgF+sHtipO5m+XE6oaJdutYEaSju2JbUk=; b=HnpOjKGUNbfy9OchrLQFAZSb3Ce6e8uBAxwcDEmYC97qF14mD/ChL1YV1ho3QoaI3gPpE7 vedx2E0aeXK+qzVlNXa+OvFPHgGN6+2KmAa8r5gNw2W0apjYw/nVwmp/DmhO3BhWixXjvl f40l55WTllBBi0FMF3neNpSZXJMFdxs= X-MC-Unique: Hg4-Qw0xPOq-e9AMt5Cs_Q-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 03/11] monitor/hmp: rename device-hotplug.c to block/monitor/block-hmp-cmds.c Date: Sun, 8 Mar 2020 11:24:32 +0200 Message-Id: <20200308092440.23564-4-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =3D> block/monitor/block-hmp-cmds.c (97%) create mode 100644 include/block/block-hmp-cmds.h diff --git a/MAINTAINERS b/MAINTAINERS index 36d0c6887a..d881ba7d9c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1920,6 +1920,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 e288663d89..40d3a1696c 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -48,7 +48,7 @@ common-obj-y +=3D dump/ common-obj-y +=3D job-qmp.o common-obj-y +=3D monitor/ common-obj-y +=3D net/ -common-obj-y +=3D qdev-monitor.o device-hotplug.o +common-obj-y +=3D qdev-monitor.o common-obj-$(CONFIG_WIN32) +=3D os-win32.o common-obj-$(CONFIG_POSIX) +=3D os-posix.o =20 diff --git a/block/Makefile.objs b/block/Makefile.objs index cb36ae2503..3635b6b4c1 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -45,6 +45,7 @@ block-obj-y +=3D crypto.o block-obj-y +=3D aio_task.o block-obj-y +=3D backup-top.o block-obj-y +=3D filter-compress.o +common-obj-y +=3D monitor/ =20 block-obj-y +=3D stream.o =20 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 +=3D 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" =20 =20 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 479d90bcea..ef81302e1a 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -63,9 +63,6 @@ extern int nb_option_roms; extern const char *prom_envs[MAX_PROM_ENVS]; extern unsigned int nb_prom_envs; =20 -/* 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); =20 diff --git a/monitor/misc.c b/monitor/misc.c index 1748ab3911..c3bc34c099 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-control.h" #include "qapi/qapi-commands-migration.h" --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659648; cv=none; d=zohomail.com; s=zohoarc; b=hP2p9OGLyWX7+uhCtCc/UpQ8EyJpbeoyYsJAc5lBqmzoFTXOmUTPeXN0ebI7pa21AUqvnc0dV3xlwPsIBX+Eij5pmV+zKL0W39EQ6s+i8+CDKv9IAbESme9zVpI/EfZQ4g3arUppzHIFpjXwI38IBmhmhOlD4skeS4kUoYvaJlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659648; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=VXOm4dxyZeY2loK8tmgTiOIqav1bwD89UCAMkJSB0fs=; b=iS+a4W6Ku+ElxMEL3fwHA9o2U4YD392XEPAvIJ5DnCSMBZ1F6kon4m5WFTmOLUsFSjZh7sAj2ppYkiMDzeY72/dPfEWSa0IMYbJqLsSCsrK9xn4Xg18YOzdvJC0IzDRIQqPkuuCNMmrAOXHmCV9WuPVj9LZ1rWgDBiXESWGZJ3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158365964895827.431831946081275; Sun, 8 Mar 2020 01:27:28 -0800 (PST) Received: from localhost ([::1]:56286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsDX-00074X-TF for importer@patchew.org; Sun, 08 Mar 2020 05:27:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55912) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsBE-0002v5-D0 for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsBC-0008T5-IG for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:04 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:40376 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 1jAsBC-0008So-Eu for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:02 -0400 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-49-YElPQ9qJNbqqMtiB8h57Ow-1; Sun, 08 Mar 2020 05:24:58 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B2C8100550E; Sun, 8 Mar 2020 09:24:57 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E0A9100E805; Sun, 8 Mar 2020 09:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659502; 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=VXOm4dxyZeY2loK8tmgTiOIqav1bwD89UCAMkJSB0fs=; b=L7V/fWasWiTVCuaYvGjA0zRNCRQfKng4pbzy0kvwdhqsiSOwy0kUP4K+kmAZ/4RE63dvVU mqNk2KHhn+Oc0IVnlnOr7t3ioheHvrdBl0ENtAAxT0jWGi8knbm4YIoYiKpf641RE3/J1H bdvldvfqqJOQhvaoXNk8C3kWcKj7gxc= X-MC-Unique: YElPQ9qJNbqqMtiB8h57Ow-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 04/11] monitor/hmp: move hmp_drive_del and hmp_commit to block-hmp-cmds.c Date: Sun, 8 Mar 2020 11:24:33 +0200 Message-Id: <20200308092440.23564-5-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 108 ++++++++++++++++++++++++++++++++- blockdev.c | 96 +---------------------------- include/block/block-hmp-cmds.h | 4 ++ include/sysemu/blockdev.h | 4 -- 4 files changed, 111 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"), t= o 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" =20 - void hmp_drive_add(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; @@ -83,3 +91,99 @@ err: blk_unref(blk); } } + +void hmp_drive_del(Monitor *mon, const QDict *qdict) +{ + const char *id =3D qdict_get_str(qdict, "id"); + BlockBackend *blk; + BlockDriverState *bs; + AioContext *aio_context; + Error *local_err =3D NULL; + + bs =3D bdrv_find_node(id); + if (bs) { + qmp_blockdev_del(id, &local_err); + if (local_err) { + error_report_err(local_err); + } + return; + } + + blk =3D 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 =3D blk_get_aio_context(blk); + aio_context_acquire(aio_context); + + bs =3D 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 =3D qdict_get_str(qdict, "device"); + BlockBackend *blk; + int ret; + + if (!strcmp(device, "all")) { + ret =3D blk_commit_all(); + } else { + BlockDriverState *bs; + AioContext *aio_context; + + blk =3D 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 =3D blk_bs(blk); + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + ret =3D 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 3e44fa766b..b38c247cdc 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1039,41 +1039,6 @@ static BlockDriverState *qmp_get_root_bs(const char = *name, Error **errp) return bs; } =20 -void hmp_commit(Monitor *mon, const QDict *qdict) -{ - const char *device =3D qdict_get_str(qdict, "device"); - BlockBackend *blk; - int ret; - - if (!strcmp(device, "all")) { - ret =3D blk_commit_all(); - } else { - BlockDriverState *bs; - AioContext *aio_context; - - blk =3D 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 =3D blk_bs(blk); - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - ret =3D 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; @@ -2747,66 +2712,6 @@ BlockDirtyBitmapSha256 *qmp_x_debug_block_dirty_bitm= ap_sha256(const char *node, return ret; } =20 -void hmp_drive_del(Monitor *mon, const QDict *qdict) -{ - const char *id =3D qdict_get_str(qdict, "id"); - BlockBackend *blk; - BlockDriverState *bs; - AioContext *aio_context; - Error *local_err =3D NULL; - - bs =3D bdrv_find_node(id); - if (bs) { - qmp_blockdev_del(id, &local_err); - if (local_err) { - error_report_err(local_err); - } - return; - } - - blk =3D 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 =3D blk_get_aio_context(blk); - aio_context_acquire(aio_context); - - bs =3D 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) @@ -3814,6 +3719,7 @@ out: aio_context_release(aio_context); } =20 + void hmp_drive_add_node(Monitor *mon, const char *optstr) { QemuOpts *opts; 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 @@ =20 void hmp_drive_add(Monitor *mon, const QDict *qdict); =20 +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, c= onst char *file, DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type, Error **errp); =20 -/* device-hotplug */ - -void hmp_commit(Monitor *mon, const QDict *qdict); -void hmp_drive_del(Monitor *mon, const QDict *qdict); #endif --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659773; cv=none; d=zohomail.com; s=zohoarc; b=I1P3ijYqTQJ7mUEJSsUEWvNne7591w1DqpGLjRMS4u6ce6HffZpAXwAKgljk9CJMOY5ZEt+FzPZbVkUW9nLGeWShjF6tP7Ez4UlWTK4awUlsKZ+Sr1FaBBB+6cSPb3ek6UJ3yySTI2Lb5Sf4CB9q6ya+NVhNesSPFABZbx62TvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659773; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=iXlSQ/j7X2kHmQ8HTyeR2DcHxysn8tmLEnB/n69mbOg=; b=JIoxlqHFev0dh33jthzf4tuSUj0plSB1UJGTeOWYITmcGXhc9qXcj5zFhNkYnYNDumnYXPthlOBBgBDdj3hxctJsg1UuJ9fOgYopHMinzx+7pHINPh912xKNdd5LeoGt6dnCEncU1oO89IWjVLMrDaC1Ak4+Lh/3rmjj0UO+1gA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583659773922541.9081744821826; Sun, 8 Mar 2020 01:29:33 -0800 (PST) Received: from localhost ([::1]:56316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsFY-00028d-UX for importer@patchew.org; Sun, 08 Mar 2020 05:29:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55946) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsBF-0002zP-WF for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsBE-0008Tz-5y for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34244 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 1jAsBE-0008Th-1s for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:04 -0400 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-148-JMyEAWunN_ikir_hEv4akg-1; Sun, 08 Mar 2020 05:25:01 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 152F6800D50; Sun, 8 Mar 2020 09:25:00 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE074101D486; Sun, 8 Mar 2020 09:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659503; 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=iXlSQ/j7X2kHmQ8HTyeR2DcHxysn8tmLEnB/n69mbOg=; b=YouYYoyDldg+BD/HvTw6AfJYiH4vm7gs9p8NHzRrAyJMEW/3ojrTqX70OCnUBbGbLGraF+ j12glaCxsQnHA7TddYM+P1+nfKDJRrxkNR5Lyu/CE5ieIFd4mrEa5QCjJLIA3oa+LgxZD8 UcZ78LDS05KBUdsIesLBmK5w47qM/Dg= X-MC-Unique: JMyEAWunN_ikir_hEv4akg-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 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: Sun, 8 Mar 2020 11:24:34 +0200 Message-Id: <20200308092440.23564-6-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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" =20 @@ -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 =3D qdict_get_str(qdict, "target"); + const char *format =3D qdict_get_try_str(qdict, "format"); + bool reuse =3D qdict_get_try_bool(qdict, "reuse", false); + bool full =3D qdict_get_try_bool(qdict, "full", false); + Error *err =3D NULL; + DriveMirror mirror =3D { + .device =3D (char *)qdict_get_str(qdict, "device"), + .target =3D (char *)filename, + .has_format =3D !!format, + .format =3D (char *)format, + .sync =3D full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, + .has_mode =3D true, + .mode =3D reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUT= E_PATHS, + .unmap =3D 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 =3D qdict_get_str(qdict, "device"); + const char *filename =3D qdict_get_str(qdict, "target"); + const char *format =3D qdict_get_try_str(qdict, "format"); + bool reuse =3D qdict_get_try_bool(qdict, "reuse", false); + bool full =3D qdict_get_try_bool(qdict, "full", false); + bool compress =3D qdict_get_try_bool(qdict, "compress", false); + Error *err =3D NULL; + DriveBackup backup =3D { + .device =3D (char *)device, + .target =3D (char *)filename, + .has_format =3D !!format, + .format =3D (char *)format, + .sync =3D full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, + .has_mode =3D true, + .mode =3D reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUT= E_PATHS, + .has_compress =3D !!compress, + .compress =3D 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. */ =20 #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); =20 +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 fb4c2fd2a8..06f0cb4bb9 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1342,64 +1342,6 @@ void hmp_block_resize(Monitor *mon, const QDict *qdi= ct) hmp_handle_error(mon, err); } =20 -void hmp_drive_mirror(Monitor *mon, const QDict *qdict) -{ - const char *filename =3D qdict_get_str(qdict, "target"); - const char *format =3D qdict_get_try_str(qdict, "format"); - bool reuse =3D qdict_get_try_bool(qdict, "reuse", false); - bool full =3D qdict_get_try_bool(qdict, "full", false); - Error *err =3D NULL; - DriveMirror mirror =3D { - .device =3D (char *)qdict_get_str(qdict, "device"), - .target =3D (char *)filename, - .has_format =3D !!format, - .format =3D (char *)format, - .sync =3D full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, - .has_mode =3D true, - .mode =3D reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUT= E_PATHS, - .unmap =3D 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 =3D qdict_get_str(qdict, "device"); - const char *filename =3D qdict_get_str(qdict, "target"); - const char *format =3D qdict_get_try_str(qdict, "format"); - bool reuse =3D qdict_get_try_bool(qdict, "reuse", false); - bool full =3D qdict_get_try_bool(qdict, "full", false); - bool compress =3D qdict_get_try_bool(qdict, "compress", false); - Error *err =3D NULL; - DriveBackup backup =3D { - .device =3D (char *)device, - .target =3D (char *)filename, - .has_format =3D !!format, - .format =3D (char *)format, - .sync =3D full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP, - .has_mode =3D true, - .mode =3D reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUT= E_PATHS, - .has_compress =3D !!compress, - .compress =3D 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 =3D qdict_get_str(qdict, "device"); --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659637; cv=none; d=zohomail.com; s=zohoarc; b=c63V+nIpjKJX4c/Yra9Zeeki3itdwHnnKEmgIzk5/7c1FcZfZHARosT+m2wnA/+rFbWn6FIBT3VaIMSbwGQDSaPA4Du0fWtShB/D6JnF39TQmwikcep0PG183VKnL9UqKfmCNC+l9LOTNC04asZMRDSjiPK1ilDDiDDz2Xm5AO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659637; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=XCOT55DYUU3zNVmW4vf52e3l56ujZOajfaV/B+RZOME=; b=Z4E7wOBXVTz1ibhcIwrek5PPIGp2l7jjsRVx4cJAs5PZPtC2iz3VpHVAHVHWQF5K/W9ft91Imw9qaYqngcvw6EwOumOJ/455L7rMjh7GJjoIqk9oC7dY3Wr/7qSkmJHHQywBdGMj8c21NGAdx/vSA80kNX2sVnIYlg0KLzEMJmo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583659637511405.31395904521753; Sun, 8 Mar 2020 01:27:17 -0800 (PST) Received: from localhost ([::1]:56282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsDL-0006gu-W5 for importer@patchew.org; Sun, 08 Mar 2020 05:27:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55966) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsBH-000330-By for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsBF-0008VU-Ut for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:07 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:42207 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 1jAsBF-0008V6-RW for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:05 -0400 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-338-HoTsfH3dPcqemnbYncQTbQ-1; Sun, 08 Mar 2020 05:25:03 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ACC568017CC; Sun, 8 Mar 2020 09:25:02 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78D5D100E805; Sun, 8 Mar 2020 09:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659505; 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=XCOT55DYUU3zNVmW4vf52e3l56ujZOajfaV/B+RZOME=; b=OZUEDe/eZdSMjqZXIwnZ1c407BJEYf6B410G2IJqd4PYQKMB9GtR8EXSsCnrl52PsqiJi0 chbsrTLq9Xpg+OA3fq6QQLiKbkT72B4ROkQSRw3qf2NoIdWayzkwKblBBiErVfWtwlMSAr u1yt70loZwICSILs3DJNfUMIum/S7w8= X-MC-Unique: HoTsfH3dPcqemnbYncQTbQ-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 06/11] monitor/hmp: move hmp_block_job* to block-hmp-cmds.c Date: Sun, 8 Mar 2020 11:24:35 +0200 Message-Id: <20200308092440.23564-7-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =3D NULL; + const char *device =3D qdict_get_str(qdict, "device"); + int64_t value =3D 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 =3D NULL; + const char *device =3D qdict_get_str(qdict, "device"); + bool force =3D 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 =3D NULL; + const char *device =3D 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 =3D NULL; + const char *device =3D 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 =3D NULL; + const char *device =3D 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); =20 +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 06f0cb4bb9..ac90a9e0c6 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1997,58 +1997,6 @@ void hmp_block_stream(Monitor *mon, const QDict *qdi= ct) hmp_handle_error(mon, error); } =20 -void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) -{ - Error *error =3D NULL; - const char *device =3D qdict_get_str(qdict, "device"); - int64_t value =3D 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 =3D NULL; - const char *device =3D qdict_get_str(qdict, "device"); - bool force =3D 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 =3D NULL; - const char *device =3D 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 =3D NULL; - const char *device =3D 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 =3D NULL; - const char *device =3D qdict_get_str(qdict, "device"); - - qmp_block_job_complete(device, &error); - - hmp_handle_error(mon, error); -} - typedef struct HMPMigrationStatus { QEMUTimer *timer; --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659745; cv=none; d=zohomail.com; s=zohoarc; b=bPS1nogJ3w6Z/EQeAmXElB831SSYIvcf5rK1RPV94VXD/iGkmRsNh2XfibEn6GxCUH/z8avOjsX+loiwA75VsJcKqmLOgQ8pUBlNz+L5pW2LwFumQ5AmK6xJmb2kOB6NM2jtZTwgXTTIHzCKFodl5PGKAgqJZQy5rsWMF56fb3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659745; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=99y7vF6wkCV/UtdwMXgwZEQJ0z2dhLG3C4JW1s+J4lw=; b=II21Os1zHq417BgTMjoHloHUIxhrB+qklt8H6vLTFPHtXcnn40mfwsVe2SwBUlkISKuiSoMzJlCMYQbgwjx7lG43zNrtV8lR4GfqYSzNB3KDSkvdU8JHdGQEYzx+9ttcu3wug+fyvtc+Cz85NTYR259VM+oF6kFTyMIny3MwAcM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583659745132294.3996819364463; Sun, 8 Mar 2020 01:29:05 -0800 (PST) Received: from localhost ([::1]:56314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsF6-0001Ci-4k for importer@patchew.org; Sun, 08 Mar 2020 05:29:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56008) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsBN-0003I4-Gg for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsBM-00007I-1j for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:13 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:31477 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 1jAsBL-00006t-Tn for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:11 -0400 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-201-7KowSpKnPxmZo0Ved6md3Q-1; Sun, 08 Mar 2020 05:25:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E836107ACC7; Sun, 8 Mar 2020 09:25:08 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16C43100E805; Sun, 8 Mar 2020 09:25:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659511; 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=99y7vF6wkCV/UtdwMXgwZEQJ0z2dhLG3C4JW1s+J4lw=; b=Bomw2QdrF/zdRPjIsjSBRkVZ0yeHfadCcsQmyZANvrWTsG/a2ghMNZJqpx1UvkOUqKRTe2 F6yuf44lQ9H+toyqKsbqxMOhds28Q9O4LYlZSKrHFLaWkfm5JYQ+5Lrd/mrILDd+r8lICy bod8Pzzu0MJmqXBUCGK6fi/HKj9pFwc= X-MC-Unique: 7KowSpKnPxmZo0Ved6md3Q-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 07/11] monitor/hmp: move hmp_snapshot_* to block-hmp-cmds.c Date: Sun, 8 Mar 2020 11:24:36 +0200 Message-Id: <20200308092440.23564-8-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" hmp_snapshot_blkdev is from GPLv2 version of the hmp-cmds.c thus have to change the licence to GPLv2 Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 58 ++++++++++++++++++++++++++++++++-- include/block/block-hmp-cmds.h | 4 +++ include/monitor/hmp.h | 3 -- monitor/hmp-cmds.c | 47 --------------------------- 4 files changed, 60 insertions(+), 52 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 8e8288c2f1..0131be8ecf 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -1,10 +1,15 @@ /* * 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. + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. * * This file incorporates work covered by the following copyright and * permission notice: @@ -299,3 +304,52 @@ void hmp_block_job_complete(Monitor *mon, const QDict = *qdict) =20 hmp_handle_error(mon, error); } + +void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) +{ + const char *device =3D qdict_get_str(qdict, "device"); + const char *filename =3D qdict_get_try_str(qdict, "snapshot-file"); + const char *format =3D qdict_get_try_str(qdict, "format"); + bool reuse =3D qdict_get_try_bool(qdict, "reuse", false); + enum NewImageMode mode; + Error *err =3D 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 =3D reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PAT= HS; + 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 =3D qdict_get_str(qdict, "device"); + const char *name =3D qdict_get_str(qdict, "name"); + Error *err =3D 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 =3D qdict_get_str(qdict, "device"); + const char *name =3D qdict_get_str(qdict, "name"); + const char *id =3D qdict_get_try_str(qdict, "id"); + Error *err =3D 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); =20 +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 ac90a9e0c6..74e6e5b7ef 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1342,53 +1342,6 @@ void hmp_block_resize(Monitor *mon, const QDict *qdi= ct) hmp_handle_error(mon, err); } =20 -void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) -{ - const char *device =3D qdict_get_str(qdict, "device"); - const char *filename =3D qdict_get_try_str(qdict, "snapshot-file"); - const char *format =3D qdict_get_try_str(qdict, "format"); - bool reuse =3D qdict_get_try_bool(qdict, "reuse", false); - enum NewImageMode mode; - Error *err =3D 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 =3D reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PAT= HS; - 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 =3D qdict_get_str(qdict, "device"); - const char *name =3D qdict_get_str(qdict, "name"); - Error *err =3D 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 =3D qdict_get_str(qdict, "device"); - const char *name =3D qdict_get_str(qdict, "name"); - const char *id =3D qdict_get_try_str(qdict, "id"); - Error *err =3D 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 =3D runstate_is_running(); --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659744; cv=none; d=zohomail.com; s=zohoarc; b=Qx+jtvs+iLEtQFK3F9nlDlwX+rjAv4+wIQHkO7796A9bVynikfn3pYaqbECueroAwTVivTIPTvHlepsrPdIiSq+/3GClnnVEeXFjuzJMYV159AF/73bCcqdM4IwKzn+tdYgVOuf1LqtvRfqC/Rv1aumq4Chcnv4Ea87YATyxZl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659744; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=i2KZ2EuzS5sNogU5k+ULwuoXfTpVR5aWEpP+uAiP5pQ=; b=cHMXdLUX/67dTJx27Z9m/8UkDkmDMH1tNa6vM9yysb+KWnH2T3nE+wn67UD/O8s6ZBVpp/j66YewBJlCYpioIzywKSAXYHWCthrfJJY/wjmPeYeXc0PKcMJwMtezVO9HRfm/JgQzd40UWnvp8TktQVa+PvXCuzF2EUAJmjOeY9A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583659744968939.4412955559263; Sun, 8 Mar 2020 01:29:04 -0800 (PST) Received: from localhost ([::1]:56312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsF5-0001CD-Tp for importer@patchew.org; Sun, 08 Mar 2020 05:29:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56055) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsBR-0003PT-0j for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsBP-0000B9-5N for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:16 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:47730 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 1jAsBP-0000AZ-0W for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:15 -0400 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-251-8G1HEppVOiGXjw-XCZSamQ-1; Sun, 08 Mar 2020 05:25:12 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3E9C418A72A2; Sun, 8 Mar 2020 09:25:11 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A731100E805; Sun, 8 Mar 2020 09:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659514; 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=i2KZ2EuzS5sNogU5k+ULwuoXfTpVR5aWEpP+uAiP5pQ=; b=LgXKyF1NmCCiQxw7UijExQkrtznmMt/4+v4Cx0sap3IG+Ur52beLlFqZKcVwD5o7UOBmF2 ebp5nts48p5O8G+XcMS9/8BD5UrdR+wlRv4ezD+V8fRm0xbyxLQ5Plh5cztFNg/PctKqbT ZZ8vcId6A6JtP4HE/nh51lmjonQSz/s= X-MC-Unique: 8G1HEppVOiGXjw-XCZSamQ-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 08/11] monitor/hmp: move hmp_nbd_server* to block-hmp-cmds.c Date: Sun, 8 Mar 2020 11:24:37 +0200 Message-Id: <20200308092440.23564-9-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 101 +++++++++++++++++++++++++++++++++ include/block/block-hmp-cmds.h | 5 ++ include/monitor/hmp.h | 4 -- monitor/hmp-cmds.c | 100 -------------------------------- 4 files changed, 106 insertions(+), 104 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 0131be8ecf..188374abbc 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -45,9 +45,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" =20 @@ -353,3 +355,102 @@ 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 =3D qdict_get_str(qdict, "uri"); + bool writable =3D qdict_get_try_bool(qdict, "writable", false); + bool all =3D qdict_get_try_bool(qdict, "all", false); + Error *local_err =3D NULL; + BlockInfoList *block_list, *info; + SocketAddress *addr; + BlockExportNbd export; + + 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 =3D socket_parse(uri, &local_err); + if (local_err !=3D NULL) { + goto exit; + } + + nbd_server_start(addr, NULL, NULL, &local_err); + qapi_free_SocketAddress(addr); + if (local_err !=3D NULL) { + goto exit; + } + + if (!all) { + return; + } + + /* Then try adding all block devices. If one fails, close all and + * exit. + */ + block_list =3D qmp_query_block(NULL); + + for (info =3D block_list; info; info =3D info->next) { + if (!info->value->has_inserted) { + continue; + } + + export =3D (BlockExportNbd) { + .device =3D info->value->device, + .has_writable =3D true, + .writable =3D writable, + }; + + qmp_nbd_server_add(&export, &local_err); + + if (local_err !=3D 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 =3D qdict_get_str(qdict, "device"); + const char *name =3D qdict_get_try_str(qdict, "name"); + bool writable =3D qdict_get_try_bool(qdict, "writable", false); + Error *local_err =3D NULL; + + BlockExportNbd export =3D { + .device =3D (char *) device, + .has_name =3D !!name, + .name =3D (char *) name, + .has_writable =3D true, + .writable =3D writable, + }; + + qmp_nbd_server_add(&export, &local_err); + hmp_handle_error(mon, local_err); +} + +void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) +{ + const char *name =3D qdict_get_str(qdict, "name"); + bool force =3D qdict_get_try_bool(qdict, "force", false); + Error *err =3D 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 =3D 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); =20 +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 74e6e5b7ef..978a6c9b36 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -47,7 +47,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" @@ -2176,105 +2175,6 @@ void hmp_screendump(Monitor *mon, const QDict *qdic= t) hmp_handle_error(mon, err); } =20 -void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) -{ - const char *uri =3D qdict_get_str(qdict, "uri"); - bool writable =3D qdict_get_try_bool(qdict, "writable", false); - bool all =3D qdict_get_try_bool(qdict, "all", false); - Error *local_err =3D NULL; - BlockInfoList *block_list, *info; - SocketAddress *addr; - BlockExportNbd export; - - 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 =3D socket_parse(uri, &local_err); - if (local_err !=3D NULL) { - goto exit; - } - - nbd_server_start(addr, NULL, NULL, &local_err); - qapi_free_SocketAddress(addr); - if (local_err !=3D NULL) { - goto exit; - } - - if (!all) { - return; - } - - /* Then try adding all block devices. If one fails, close all and - * exit. - */ - block_list =3D qmp_query_block(NULL); - - for (info =3D block_list; info; info =3D info->next) { - if (!info->value->has_inserted) { - continue; - } - - export =3D (BlockExportNbd) { - .device =3D info->value->device, - .has_writable =3D true, - .writable =3D writable, - }; - - qmp_nbd_server_add(&export, &local_err); - - if (local_err !=3D 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 =3D qdict_get_str(qdict, "device"); - const char *name =3D qdict_get_try_str(qdict, "name"); - bool writable =3D qdict_get_try_bool(qdict, "writable", false); - Error *local_err =3D NULL; - - BlockExportNbd export =3D { - .device =3D (char *) device, - .has_name =3D !!name, - .name =3D (char *) name, - .has_writable =3D true, - .writable =3D writable, - }; - - qmp_nbd_server_add(&export, &local_err); - hmp_handle_error(mon, local_err); -} - -void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) -{ - const char *name =3D qdict_get_str(qdict, "name"); - bool force =3D qdict_get_try_bool(qdict, "force", false); - Error *err =3D 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 =3D NULL; - - qmp_nbd_server_stop(&err); - hmp_handle_error(mon, err); -} - void hmp_chardev_add(Monitor *mon, const QDict *qdict) { const char *args =3D qdict_get_str(qdict, "args"); --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659831; cv=none; d=zohomail.com; s=zohoarc; b=M5WmXIEfxxVt8LzDSFEdmvRyT1Xt0A+Lwrz3fweBUPZbFgUzNvV5CmJnbfuvbtmv0l2YiJpMA3Dao+jt8DCFcdKuwOIeiXyV6mz6cyP8tGebvWIDCJsZCRp4+lskKeui36YF7eRYwYKH69dvBxQpmQBUUCcbxk33C/oL4xtM7iw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659831; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=VRzrGYrU0uQ83yWnZjPo1jMoKASMgrj12IVnQYxdBHA=; b=AM5YCZP7r0y6wi9x/bxSmQtDZi3ng9rZIyioiQJpU/AtBW2PqhxT6EYsgSscItOcKPT+hS+vWlPVQ9vgyiLSpa+DxXItBcGLqWs7v6krv8jvRe7Iiy5mTLiLTIVkuTOXFQnaDVcMdoryd8kEmWDfbxMGIpFbICtSNWTFu2qoLZ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583659831231690.1960968091997; Sun, 8 Mar 2020 01:30:31 -0800 (PST) Received: from localhost ([::1]:56345 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsGU-0003p2-6T for importer@patchew.org; Sun, 08 Mar 2020 05:30:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56106) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsBV-0003Y2-KA for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsBT-0000E2-Ax for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:47156 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 1jAsBT-0000Di-5Z for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:19 -0400 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-256-vPk3KQvwMeaFQazH1FPU7A-1; Sun, 08 Mar 2020 05:25:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0AFA8801E53; Sun, 8 Mar 2020 09:25:14 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DB1C100E805; Sun, 8 Mar 2020 09:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659518; 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=VRzrGYrU0uQ83yWnZjPo1jMoKASMgrj12IVnQYxdBHA=; b=LrXYoHQDog39PjmR+Fyr9TWrB19GVjyUn6KKWxNG/pVyZox3vsd7urFclItdI5uO+GNiCW eT0PMix+EAQjiStGoC/0PrBHkDxAylG/Ld0jdAV0b6omWSEM0eZc5gpFaFoy0RX8UKjzWM ocOwQTRXCxlNrwzVuWjr8G115IJH/9s= X-MC-Unique: vPk3KQvwMeaFQazH1FPU7A-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 09/11] monitor/hmp: move remaining hmp_block* functions to block-hmp-cmds.c Date: Sun, 8 Mar 2020 11:24:38 +0200 Message-Id: <20200308092440.23564-10-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 188374abbc..5beb7df2f7 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -52,6 +52,7 @@ #include "block/nbd.h" #include "block/block_int.h" #include "block/block-hmp-cmds.h" +#include "qemu-io.h" =20 void hmp_drive_add(Monitor *mon, const QDict *qdict) { @@ -454,3 +455,142 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *q= dict) qmp_nbd_server_stop(&err); hmp_handle_error(mon, err); } + +void hmp_block_resize(Monitor *mon, const QDict *qdict) +{ + const char *device =3D qdict_get_str(qdict, "device"); + int64_t size =3D qdict_get_int(qdict, "size"); + Error *err =3D 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 =3D NULL; + const char *device =3D qdict_get_str(qdict, "device"); + const char *base =3D qdict_get_try_str(qdict, "base"); + int64_t speed =3D qdict_get_try_int(qdict, "speed", 0); + + qmp_block_stream(true, device, device, base !=3D NULL, base, false, NU= LL, + false, NULL, qdict_haskey(qdict, "speed"), speed, tru= e, + 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 =3D qdict_get_str(qdict, "device"); + const char *password =3D qdict_get_str(qdict, "password"); + Error *err =3D 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 =3D NULL; + char *device =3D (char *) qdict_get_str(qdict, "device"); + BlockIOThrottle throttle =3D { + .bps =3D qdict_get_int(qdict, "bps"), + .bps_rd =3D qdict_get_int(qdict, "bps_rd"), + .bps_wr =3D qdict_get_int(qdict, "bps_wr"), + .iops =3D qdict_get_int(qdict, "iops"), + .iops_rd =3D qdict_get_int(qdict, "iops_rd"), + .iops_wr =3D 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 =3D true; + throttle.device =3D device; + } else { + throttle.has_id =3D true; + throttle.id =3D device; + } + + qmp_block_set_io_throttle(&throttle, &err); + hmp_handle_error(mon, err); +} + +void hmp_eject(Monitor *mon, const QDict *qdict) +{ + bool force =3D qdict_get_try_bool(qdict, "force", false); + const char *device =3D qdict_get_str(qdict, "device"); + Error *err =3D 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 =3D NULL; + bool qdev =3D qdict_get_try_bool(qdict, "qdev", false); + const char *device =3D qdict_get_str(qdict, "device"); + const char *command =3D qdict_get_str(qdict, "command"); + Error *err =3D NULL; + int ret; + + if (qdev) { + blk =3D blk_by_qdev_id(device, &err); + if (!blk) { + goto fail; + } + } else { + blk =3D blk_by_name(device); + if (!blk) { + BlockDriverState *bs =3D bdrv_lookup_bs(NULL, device, &err); + if (bs) { + blk =3D local_blk =3D blk_new(bdrv_get_aio_context(bs), + 0, BLK_PERM_ALL); + ret =3D blk_insert_bs(blk, bs, &err); + if (ret < 0) { + goto fail; + } + } else { + goto fail; + } + } + } + + /* + * Notably absent: Proper permission management. This is sad, but it s= eems + * almost impossible to achieve without changing the semantics and the= reby + * limiting the use cases of the qemu-io HMP command. + * + * In an ideal world we would unconditionally create a new BlockBacken= d for + * qemuio_command(), but we have commands like 'reopen' and want them = to + * take effect on the exact BlockBackend whose name the user passed in= stead + * 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 conditi= ons. + * + * 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 s= tay + * extended, possibly resulting in a read-only guest device keeping wr= ite + * 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); =20 +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 QDic= t *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 978a6c9b36..99aa31aefa 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -48,7 +48,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" @@ -1312,16 +1311,6 @@ void hmp_set_link(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } =20 -void hmp_block_passwd(Monitor *mon, const QDict *qdict) -{ - const char *device =3D qdict_get_str(qdict, "device"); - const char *password =3D qdict_get_str(qdict, "password"); - Error *err =3D 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 =3D qdict_get_int(qdict, "value"); @@ -1331,16 +1320,6 @@ void hmp_balloon(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } =20 -void hmp_block_resize(Monitor *mon, const QDict *qdict) -{ - const char *device =3D qdict_get_str(qdict, "device"); - int64_t size =3D qdict_get_int(qdict, "size"); - Error *err =3D 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 =3D runstate_is_running(); @@ -1840,15 +1819,6 @@ void hmp_expire_password(Monitor *mon, const QDict *= qdict) hmp_handle_error(mon, err); } =20 -void hmp_eject(Monitor *mon, const QDict *qdict) -{ - bool force =3D qdict_get_try_bool(qdict, "force", false); - const char *device =3D qdict_get_str(qdict, "device"); - Error *err =3D NULL; - - qmp_eject(true, device, false, NULL, true, force, &err); - hmp_handle_error(mon, err); -} =20 #ifdef CONFIG_VNC static void hmp_change_read_arg(void *opaque, const char *password, @@ -1906,49 +1876,6 @@ void hmp_change(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } =20 -void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) -{ - Error *err =3D NULL; - char *device =3D (char *) qdict_get_str(qdict, "device"); - BlockIOThrottle throttle =3D { - .bps =3D qdict_get_int(qdict, "bps"), - .bps_rd =3D qdict_get_int(qdict, "bps_rd"), - .bps_wr =3D qdict_get_int(qdict, "bps_wr"), - .iops =3D qdict_get_int(qdict, "iops"), - .iops_rd =3D qdict_get_int(qdict, "iops_rd"), - .iops_wr =3D 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 =3D true; - throttle.device =3D device; - } else { - throttle.has_id =3D true; - throttle.id =3D device; - } - - qmp_block_set_io_throttle(&throttle, &err); - hmp_handle_error(mon, err); -} - -void hmp_block_stream(Monitor *mon, const QDict *qdict) -{ - Error *error =3D NULL; - const char *device =3D qdict_get_str(qdict, "device"); - const char *base =3D qdict_get_try_str(qdict, "base"); - int64_t speed =3D qdict_get_try_int(qdict, "speed", 0); - - qmp_block_stream(true, device, device, base !=3D NULL, base, false, NU= LL, - false, NULL, qdict_haskey(qdict, "speed"), speed, tru= e, - BLOCKDEV_ON_ERROR_REPORT, false, false, false, false, - &error); - - hmp_handle_error(mon, error); -} - typedef struct HMPMigrationStatus { QEMUTimer *timer; @@ -2241,70 +2168,6 @@ void hmp_chardev_send_break(Monitor *mon, const QDic= t *qdict) hmp_handle_error(mon, local_err); } =20 -void hmp_qemu_io(Monitor *mon, const QDict *qdict) -{ - BlockBackend *blk; - BlockBackend *local_blk =3D NULL; - bool qdev =3D qdict_get_try_bool(qdict, "qdev", false); - const char* device =3D qdict_get_str(qdict, "device"); - const char* command =3D qdict_get_str(qdict, "command"); - Error *err =3D NULL; - int ret; - - if (qdev) { - blk =3D blk_by_qdev_id(device, &err); - if (!blk) { - goto fail; - } - } else { - blk =3D blk_by_name(device); - if (!blk) { - BlockDriverState *bs =3D bdrv_lookup_bs(NULL, device, &err); - if (bs) { - blk =3D local_blk =3D blk_new(bdrv_get_aio_context(bs), - 0, BLK_PERM_ALL); - ret =3D blk_insert_bs(blk, bs, &err); - if (ret < 0) { - goto fail; - } - } else { - goto fail; - } - } - } - - /* - * Notably absent: Proper permission management. This is sad, but it s= eems - * almost impossible to achieve without changing the semantics and the= reby - * limiting the use cases of the qemu-io HMP command. - * - * In an ideal world we would unconditionally create a new BlockBacken= d for - * qemuio_command(), but we have commands like 'reopen' and want them = to - * take effect on the exact BlockBackend whose name the user passed in= stead - * 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 conditi= ons. - * - * 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 s= tay - * extended, possibly resulting in a read-only guest device keeping wr= ite - * 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 =3D qdict_get_str(qdict, "id"); --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659831; cv=none; d=zohomail.com; s=zohoarc; b=fRN6horGAqF3gkvmEfAki+14YHflWYR+q597Ivj1WMVvTT1tioXAwEaVJ8ZZoyq0hKlLCb2OCNF4327+XWDEIRW/QunhAnIaIkqEc3m82qVjhPitahHoKJngL02neMOWNmBVqbHk5VikFFgCGm/b0KPpjJQKWF5FoPDav+KDlrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659831; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=8+yO139i+hn7PfOJhB1m/WxK+oxaY6buL5siIDKC+HE=; b=i1vOr2eCfRb+p6e+MaRI6JSsta+RI7Cts73V1uSLrwwKUWpC397pK59JZf/zP1NQHZeTuawaQMkRm/GU+kXRr2iIcdVWd9TL6Rrk67y4bGdHOnwY40KgdsI38sjVphGfZEKXqxWogOq6033BumvDYk5/RMFgvKYoV3gvVeQ51dI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583659831744990.4086174310202; Sun, 8 Mar 2020 01:30:31 -0800 (PST) Received: from localhost ([::1]:56350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsGU-0003pu-NA for importer@patchew.org; Sun, 08 Mar 2020 05:30:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56140) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsBY-0003fC-GX for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsBV-0000Ej-8d for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:28176 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 1jAsBV-0000EX-3L for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:21 -0400 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-365-naY0NY3NNCujlk567qHVRA-1; Sun, 08 Mar 2020 05:25:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D086A108443A; Sun, 8 Mar 2020 09:25:16 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CD3B10027B8; Sun, 8 Mar 2020 09:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659520; 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=8+yO139i+hn7PfOJhB1m/WxK+oxaY6buL5siIDKC+HE=; b=BXuqkajNS1o0dMhuJPSPZ7Tlx6ShEs95Db6ZTkTwO2mp0O6Xkoxk8GPBMR7yk4t3z+7Wzo iNM8ry29bx3CjLjnOw0OuhfuQMgUnUBcYMLYJCuqgm0wU5Jg4HKkPykAUia3W8xsP+3RMI n4IVNuUqrSkzmJZ2bv0h6+LcdfIj5nc= X-MC-Unique: naY0NY3NNCujlk567qHVRA-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 10/11] monitor/hmp: move hmp_info_block* to block-hmp-cmds.c Date: Sun, 8 Mar 2020 11:24:39 +0200 Message-Id: <20200308092440.23564-11-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 389 +++++++++++++++++++++++++++++++++ include/block/block-hmp-cmds.h | 4 + include/monitor/hmp.h | 4 - monitor/hmp-cmds.c | 388 -------------------------------- 4 files changed, 393 insertions(+), 392 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 5beb7df2f7..aebf1dce0d 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -46,10 +46,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" @@ -594,3 +596,390 @@ 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 =3D=3D 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->nod= e_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 !=3D BLOCK_DEVICE_IO_ST= ATUS_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" : "writethroug= h", + 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 !=3D 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=3D%" PRId64 + " bps_rd=3D%" PRId64 " bps_wr=3D%" PRId64 + " bps_max=3D%" PRId64 + " bps_rd_max=3D%" PRId64 + " bps_wr_max=3D%" PRId64 + " iops=3D%" PRId64 " iops_rd=3D%" PRId64 + " iops_wr=3D%" PRId64 + " iops_max=3D%" PRId64 + " iops_rd_max=3D%" PRId64 + " iops_wr_max=3D%" PRId64 + " iops_size=3D%" PRId64 + " group=3D%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 =3D inserted->image; + while (1) { + bdrv_image_info_dump(image_info); + if (image_info->has_backing_image) { + image_info =3D 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 =3D qdict_get_try_str(qdict, "device"); + bool verbose =3D qdict_get_try_bool(qdict, "verbose", false); + bool nodes =3D qdict_get_try_bool(qdict, "nodes", false); + bool printed =3D false; + + /* Print BlockBackend information */ + if (!nodes) { + block_list =3D qmp_query_block(NULL); + } else { + block_list =3D NULL; + } + + for (info =3D block_list; info; info =3D info->next) { + if (device && strcmp(device, info->value->device)) { + continue; + } + + if (info !=3D block_list) { + monitor_printf(mon, "\n"); + } + + print_block_info(mon, info->value, info->value->has_inserted + ? info->value->inserted : NULL, + verbose); + printed =3D true; + } + + qapi_free_BlockInfoList(block_list); + + if ((!device && !nodes) || printed) { + return; + } + + /* Print node information */ + blockdev_list =3D qmp_query_named_block_nodes(false, false, NULL); + for (blockdev =3D blockdev_list; blockdev; blockdev =3D blockdev->next= ) { + assert(blockdev->value->has_node_name); + if (device && strcmp(device, blockdev->value->node_name)) { + continue; + } + + if (blockdev !=3D 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 =3D qmp_query_blockstats(false, false, NULL); + + for (stats =3D stats_list; stats; stats =3D stats->next) { + if (!stats->value->has_device) { + continue; + } + + monitor_printf(mon, "%s:", stats->value->device); + monitor_printf(mon, " rd_bytes=3D%" PRId64 + " wr_bytes=3D%" PRId64 + " rd_operations=3D%" PRId64 + " wr_operations=3D%" PRId64 + " flush_operations=3D%" PRId64 + " wr_total_time_ns=3D%" PRId64 + " rd_total_time_ns=3D%" PRId64 + " flush_total_time_ns=3D%" PRId64 + " rd_merged=3D%" PRId64 + " wr_merged=3D%" PRId64 + " idle_time_ns=3D%" 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 =3D NULL; + + list =3D 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") =3D=3D 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 =3D 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 =3D 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 =3D + QTAILQ_HEAD_INITIALIZER(image_list); + + ImageEntry *image_entry, *next_ie; + SnapshotEntry *snapshot_entry; + + bs =3D bdrv_all_find_vmstate_bs(); + if (!bs) { + monitor_printf(mon, "No available block device supports snapshots\= n"); + return; + } + aio_context =3D bdrv_get_aio_context(bs); + + aio_context_acquire(aio_context); + nb_sns =3D 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 =3D bdrv_first(&it1); bs1; bs1 =3D bdrv_next(&it1)) { + int bs1_nb_sns =3D 0; + ImageEntry *ie; + SnapshotEntry *se; + AioContext *ctx =3D bdrv_get_aio_context(bs1); + + aio_context_acquire(ctx); + if (bdrv_can_snapshot(bs1)) { + sn =3D NULL; + bs1_nb_sns =3D bdrv_snapshot_list(bs1, &sn); + if (bs1_nb_sns > 0) { + no_snapshot =3D false; + ie =3D g_new0(ImageEntry, 1); + ie->imagename =3D bdrv_get_device_name(bs1); + QTAILQ_INIT(&ie->snapshots); + QTAILQ_INSERT_TAIL(&image_list, ie, next); + for (i =3D 0; i < bs1_nb_sns; i++) { + se =3D g_new0(SnapshotEntry, 1); + se->sn =3D 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 =3D g_new0(int, nb_sns); + total =3D 0; + for (i =3D 0; i < nb_sns; i++) { + SnapshotEntry *next_sn; + if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) =3D=3D 0) { + global_snapshots[total] =3D i; + total++; + QTAILQ_FOREACH(image_entry, &image_list, next) { + QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshot= s, + next, next_sn) { + if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) { + QTAILQ_REMOVE(&image_entry->snapshots, snapshot_en= try, + 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 =3D 0; i < total; i++) { + sn =3D &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); =20 void hmp_qemu_io(Monitor *mon, const QDict *qdict); =20 +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); =20 #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 QD= ict *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 99aa31aefa..dc790f1801 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -47,7 +47,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" @@ -470,213 +469,6 @@ void hmp_info_migrate_cache_size(Monitor *mon, const = QDict *qdict) qmp_query_migrate_cache_size(NULL) >> 10); } =20 -static void print_block_info(Monitor *mon, BlockInfo *info, - BlockDeviceInfo *inserted, bool verbose) -{ - ImageInfo *image_info; - - assert(!info || !info->has_inserted || info->inserted =3D=3D 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->nod= e_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 !=3D BLOCK_DEVICE_IO_ST= ATUS_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" : "writethroug= h", - 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 !=3D 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=3D%" PRId64 - " bps_rd=3D%" PRId64 " bps_wr=3D%" PRId64 - " bps_max=3D%" PRId64 - " bps_rd_max=3D%" PRId64 - " bps_wr_max=3D%" PRId64 - " iops=3D%" PRId64 " iops_rd=3D%" PRId64 - " iops_wr=3D%" PRId64 - " iops_max=3D%" PRId64 - " iops_rd_max=3D%" PRId64 - " iops_wr_max=3D%" PRId64 - " iops_size=3D%" PRId64 - " group=3D%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 =3D inserted->image; - while (1) { - bdrv_image_info_dump(image_info); - if (image_info->has_backing_image) { - image_info =3D 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 =3D qdict_get_try_str(qdict, "device"); - bool verbose =3D qdict_get_try_bool(qdict, "verbose", false); - bool nodes =3D qdict_get_try_bool(qdict, "nodes", false); - bool printed =3D false; - - /* Print BlockBackend information */ - if (!nodes) { - block_list =3D qmp_query_block(NULL); - } else { - block_list =3D NULL; - } - - for (info =3D block_list; info; info =3D info->next) { - if (device && strcmp(device, info->value->device)) { - continue; - } - - if (info !=3D block_list) { - monitor_printf(mon, "\n"); - } - - print_block_info(mon, info->value, info->value->has_inserted - ? info->value->inserted : NULL, - verbose); - printed =3D true; - } - - qapi_free_BlockInfoList(block_list); - - if ((!device && !nodes) || printed) { - return; - } - - /* Print node information */ - blockdev_list =3D qmp_query_named_block_nodes(false, false, NULL); - for (blockdev =3D blockdev_list; blockdev; blockdev =3D blockdev->next= ) { - assert(blockdev->value->has_node_name); - if (device && strcmp(device, blockdev->value->node_name)) { - continue; - } - - if (blockdev !=3D 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 =3D qmp_query_blockstats(false, false, NULL); - - for (stats =3D stats_list; stats; stats =3D stats->next) { - if (!stats->value->has_device) { - continue; - } - - monitor_printf(mon, "%s:", stats->value->device); - monitor_printf(mon, " rd_bytes=3D%" PRId64 - " wr_bytes=3D%" PRId64 - " rd_operations=3D%" PRId64 - " wr_operations=3D%" PRId64 - " flush_operations=3D%" PRId64 - " wr_total_time_ns=3D%" PRId64 - " rd_total_time_ns=3D%" PRId64 - " flush_total_time_ns=3D%" PRId64 - " rd_merged=3D%" PRId64 - " wr_merged=3D%" PRId64 - " idle_time_ns=3D%" 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); -} =20 #ifdef CONFIG_VNC /* Helper for hmp_info_vnc_clients, _servers */ @@ -1056,44 +848,6 @@ void hmp_info_pci(Monitor *mon, const QDict *qdict) qapi_free_PciInfoList(info_list); } =20 -void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) -{ - BlockJobInfoList *list; - Error *err =3D NULL; - - list =3D 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") =3D=3D 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 =3D list->next; - } - - qapi_free_BlockJobInfoList(list); -} - void hmp_info_tpm(Monitor *mon, const QDict *qdict) { TPMInfoList *info_list, *info; @@ -1356,148 +1110,6 @@ void hmp_delvm(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } =20 -void hmp_info_snapshots(Monitor *mon, const QDict *qdict) -{ - BlockDriverState *bs, *bs1; - BdrvNextIterator it1; - QEMUSnapshotInfo *sn_tab, *sn; - bool no_snapshot =3D 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 =3D - QTAILQ_HEAD_INITIALIZER(image_list); - - ImageEntry *image_entry, *next_ie; - SnapshotEntry *snapshot_entry; - - bs =3D bdrv_all_find_vmstate_bs(); - if (!bs) { - monitor_printf(mon, "No available block device supports snapshots\= n"); - return; - } - aio_context =3D bdrv_get_aio_context(bs); - - aio_context_acquire(aio_context); - nb_sns =3D 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 =3D bdrv_first(&it1); bs1; bs1 =3D bdrv_next(&it1)) { - int bs1_nb_sns =3D 0; - ImageEntry *ie; - SnapshotEntry *se; - AioContext *ctx =3D bdrv_get_aio_context(bs1); - - aio_context_acquire(ctx); - if (bdrv_can_snapshot(bs1)) { - sn =3D NULL; - bs1_nb_sns =3D bdrv_snapshot_list(bs1, &sn); - if (bs1_nb_sns > 0) { - no_snapshot =3D false; - ie =3D g_new0(ImageEntry, 1); - ie->imagename =3D bdrv_get_device_name(bs1); - QTAILQ_INIT(&ie->snapshots); - QTAILQ_INSERT_TAIL(&image_list, ie, next); - for (i =3D 0; i < bs1_nb_sns; i++) { - se =3D g_new0(SnapshotEntry, 1); - se->sn =3D 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 =3D g_new0(int, nb_sns); - total =3D 0; - for (i =3D 0; i < nb_sns; i++) { - SnapshotEntry *next_sn; - if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) =3D=3D 0) { - global_snapshots[total] =3D i; - total++; - QTAILQ_FOREACH(image_entry, &image_list, next) { - QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshot= s, - next, next_sn) { - if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) { - QTAILQ_REMOVE(&image_entry->snapshots, snapshot_en= try, - 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 =3D 0; i < total; i++) { - sn =3D &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 =3D qdict_get_try_str(qdict, "interfaces"); --=20 2.17.2 From nobody Thu Nov 13 23:19:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583659948; cv=none; d=zohomail.com; s=zohoarc; b=XKnYHhPy9UfsnmQ8moGakhpBgM4+hUuvTXyJkaOFiGShdfygLPmH4EEPnOhXLroWOc11Nt93eIvI4fgz5MykfMpebLuwSfqJ1NYUNZH9BG1dwQxv24Bfw6JN/edR3W4W0Cp2PIah75G9IIewHQg96Y1lbZvuIkRj7Zz8C7qWfdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583659948; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=5ICFbxacI83VgTIlkhxD7c4tDRUEMLoHCXrDPHn0udY=; b=ZN2oLnTbhLukm91hE3lAOKC9zBUDqDSanvCjKdfs3Lg5UUUKxpZjbNv+sE1qBTl+G8WExCYZEIeBDrf8/CITkpq2hivGtLHCSCTLdCaRQK3oRliV9mqGN3k3xF+dYEKTC4jEKgJa2uCrzibpVcKgss91GGR9CAxkaluQeQUdRdg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583659948102119.28447634701297; Sun, 8 Mar 2020 01:32:28 -0800 (PST) Received: from localhost ([::1]:56378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsIL-0005Pu-CE for importer@patchew.org; Sun, 08 Mar 2020 05:32:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56136) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAsBY-0003du-8E for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAsBW-0000Ff-RV for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:24 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:24120 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 1jAsBW-0000FS-OI for qemu-devel@nongnu.org; Sun, 08 Mar 2020 05:25:22 -0400 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-411-gAa3995UPjiwbhbVg_fZUQ-1; Sun, 08 Mar 2020 05:25:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C6D88010F1; Sun, 8 Mar 2020 09:25:19 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DC69101D486; Sun, 8 Mar 2020 09:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583659522; 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=5ICFbxacI83VgTIlkhxD7c4tDRUEMLoHCXrDPHn0udY=; b=HqFyHif6jINzJRMggsZa7Vc0az5YA3nPqAkPhZwU/PyBGO34jMOj2Qw/FSL9/O9zouVu8d iUxGs8rUFEEFPseBMDroi/N9YtCwQSPr4S+5KKvdKIy/VFUBeUiArO72VXac1dtiY23JJz HjkoZYz77MgWTHE6VlNMlRkY5UEzEB4= X-MC-Unique: gAa3995UPjiwbhbVg_fZUQ-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v5 11/11] monitor/hmp: Move hmp_drive_add_node to block-hmp-cmds.c Date: Sun, 8 Mar 2020 11:24:40 +0200 Message-Id: <20200308092440.23564-12-mlevitsk@redhat.com> In-Reply-To: <20200308092440.23564-1-mlevitsk@redhat.com> References: <20200308092440.23564-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky Reviewed-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 30 ++++++++++++++++++++++++ blockdev.c | 43 +++++++--------------------------- include/block/block_int.h | 5 ++-- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index aebf1dce0d..c3a6368dfc 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -56,6 +56,36 @@ #include "block/block-hmp-cmds.h" #include "qemu-io.h" =20 +static void hmp_drive_add_node(Monitor *mon, const char *optstr) +{ + QemuOpts *opts; + QDict *qdict; + Error *local_err =3D NULL; + + opts =3D qemu_opts_parse_noisily(&qemu_drive_opts, optstr, false); + if (!opts) { + return; + } + + qdict =3D 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 =3D 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 =3D NULL; diff --git a/blockdev.c b/blockdev.c index b38c247cdc..257cb37682 100644 --- a/blockdev.c +++ b/blockdev.c @@ -64,9 +64,14 @@ #include "qemu/main-loop.h" #include "qemu/throttle-options.h" =20 -static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =3D +QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =3D QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states); =20 +void bdrv_set_monitor_owned(BlockDriverState *bs) +{ + QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list); +} + static const char *const if_name[IF_COUNT] =3D { [IF_NONE] =3D "none", [IF_IDE] =3D "ide", @@ -640,7 +645,7 @@ err_no_opts: } =20 /* 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 =3D 0; =20 @@ -3719,38 +3724,6 @@ out: aio_context_release(aio_context); } =20 - -void hmp_drive_add_node(Monitor *mon, const char *optstr) -{ - QemuOpts *opts; - QDict *qdict; - Error *local_err =3D NULL; - - opts =3D qemu_opts_parse_noisily(&qemu_drive_opts, optstr, false); - if (!opts) { - return; - } - - qdict =3D 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 =3D 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; @@ -3780,7 +3753,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error= **errp) goto fail; } =20 - QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list); + bdrv_set_monitor_owned(bs); =20 fail: visit_free(v); diff --git a/include/block/block_int.h b/include/block/block_int.h index f422c0bff0..3f70a98b2d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1216,8 +1216,6 @@ BlockJob *backup_job_create(const char *job_id, Block= DriverState *bs, BlockCompletionFunc *cb, void *opaque, JobTxn *txn, Error **errp); =20 -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, @@ -1322,4 +1320,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src= , uint64_t src_offset, =20 int refresh_total_sectors(BlockDriverState *bs, int64_t hint); =20 +void bdrv_set_monitor_owned(BlockDriverState *bs); +BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp); + #endif /* BLOCK_INT_H */ --=20 2.17.2