From nobody Wed May 14 17:17:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526642970219487.20821871877604; Fri, 18 May 2018 04:29:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6068F30C4D27; Fri, 18 May 2018 11:29:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33178600C9; Fri, 18 May 2018 11:29:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E0E6D4CAAD; Fri, 18 May 2018 11:29:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4IBTKe7016043 for ; Fri, 18 May 2018 07:29:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 47AA32026E03; Fri, 18 May 2018 11:29:20 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id E161B2026DFD for ; Fri, 18 May 2018 11:29:19 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 18 May 2018 13:28:56 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/15] qemu: monitor: Add implementation for blockdev-add and blockdev-del X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 18 May 2018 11:29:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor.c | 37 +++++++++++++++++++++++++++++ src/qemu/qemu_monitor.h | 7 ++++++ src/qemu/qemu_monitor_json.c | 55 ++++++++++++++++++++++++++++++++++++++++= ++++ src/qemu/qemu_monitor_json.h | 9 ++++++++ 4 files changed, 108 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index f21bf7000d..fb9583e405 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4412,3 +4412,40 @@ qemuMonitorSetWatchdogAction(qemuMonitorPtr mon, return qemuMonitorJSONSetWatchdogAction(mon, action); } + + +/** + * qemuMonitorBlockdevAdd: + * @mon: monitor object + * @props: JSON object describing the blockdev to add + * + * Adds a new block device (BDS) to qemu. Note that @props is always consu= med + * by this function and should not be accessed after calling this function. + */ +int +qemuMonitorBlockdevAdd(qemuMonitorPtr mon, + virJSONValuePtr props) +{ + VIR_DEBUG("props=3D%p (node-name=3D%s)", props, + NULLSTR(virJSONValueObjectGetString(props, "node-name"))); + + QEMU_CHECK_MONITOR_JSON_GOTO(mon, error); + + return qemuMonitorJSONBlockdevAdd(mon, props); + + error: + virJSONValueFree(props); + return -1; +} + + +int +qemuMonitorBlockdevDel(qemuMonitorPtr mon, + const char *nodename) +{ + VIR_DEBUG("nodename=3D%s", nodename); + + QEMU_CHECK_MONITOR_JSON(mon); + + return qemuMonitorJSONBlockdevDel(mon, nodename); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 6cba37c281..52ad843029 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1142,4 +1142,11 @@ virJSONValuePtr qemuMonitorQueryNamedBlockNodes(qemu= MonitorPtr mon); int qemuMonitorSetWatchdogAction(qemuMonitorPtr mon, const char *action); + +int qemuMonitorBlockdevAdd(qemuMonitorPtr mon, + virJSONValuePtr props); + +int qemuMonitorBlockdevDel(qemuMonitorPtr mon, + const char *nodename); + #endif /* QEMU_MONITOR_H */ diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 0b0fb7feba..61554a7ebc 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7889,3 +7889,58 @@ qemuMonitorJSONSetWatchdogAction(qemuMonitorPtr mon, virJSONValueFree(reply); return ret; } + + +int +qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon, + virJSONValuePtr props) +{ + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + int ret =3D -1; + + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("blockdev-add", + props, false))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + + +int +qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon, + const char *nodename) +{ + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + int ret =3D -1; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("blockdev-del", + "s:node-name", nodename, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 8461932cac..22bcc1e8ef 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -537,4 +537,13 @@ virJSONValuePtr qemuMonitorJSONQueryNamedBlockNodes(qe= muMonitorPtr mon) int qemuMonitorJSONSetWatchdogAction(qemuMonitorPtr mon, const char *action) ATTRIBUTE_NONNULL(1); + +int qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon, + virJSONValuePtr props) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon, + const char *nodename) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + #endif /* QEMU_MONITOR_JSON_H */ --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list