[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 25/37] block/export: Add BLOCK_EXPORT_DELETED event
From: |
Kevin Wolf |
Subject: |
[PULL 25/37] block/export: Add BLOCK_EXPORT_DELETED event |
Date: |
Fri, 2 Oct 2020 16:43:33 +0200 |
Clients may want to know when an export has finally disappeard
(block-export-del returns earlier than that in the general case), so add
a QAPI event for it.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200924152717.287415-22-kwolf@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qapi/block-export.json | 12 ++++++++++++
block/export/export.c | 2 ++
tests/qemu-iotests/140 | 9 ++++++++-
tests/qemu-iotests/140.out | 2 +-
tests/qemu-iotests/223.out | 4 ++++
5 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/qapi/block-export.json b/qapi/block-export.json
index 3d22527c84..76e014c406 100644
--- a/qapi/block-export.json
+++ b/qapi/block-export.json
@@ -233,3 +233,15 @@
##
{ 'command': 'block-export-del',
'data': { 'id': 'str', '*mode': 'BlockExportRemoveMode' } }
+
+##
+# @BLOCK_EXPORT_DELETED:
+#
+# Emitted when a block export is removed and its id can be reused.
+#
+# @id: Block export id.
+#
+# Since: 5.2
+##
+{ 'event': 'BLOCK_EXPORT_DELETED',
+ 'data': { 'id': 'str' } }
diff --git a/block/export/export.c b/block/export/export.c
index d186beffe9..87940d5c40 100644
--- a/block/export/export.c
+++ b/block/export/export.c
@@ -19,6 +19,7 @@
#include "block/nbd.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-block-export.h"
+#include "qapi/qapi-events-block-export.h"
#include "qemu/id.h"
static const BlockExportDriver *blk_exp_drivers[] = {
@@ -113,6 +114,7 @@ static void blk_exp_delete_bh(void *opaque)
assert(exp->refcount == 0);
QLIST_REMOVE(exp, next);
exp->drv->delete(exp);
+ qapi_event_send_block_export_deleted(exp->id);
g_free(exp->id);
g_free(exp);
diff --git a/tests/qemu-iotests/140 b/tests/qemu-iotests/140
index 8d2ce5d9e3..309b177e77 100755
--- a/tests/qemu-iotests/140
+++ b/tests/qemu-iotests/140
@@ -81,10 +81,17 @@ $QEMU_IO_PROG -f raw -r -c 'read -P 42 0 64k' \
"nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \
| _filter_qemu_io | _filter_nbd
+# The order of 'return' and the BLOCK_EXPORT_DELETED event is undefined. Just
+# wait until we've twice seen one of them. Filter the 'return' line out so that
+# the output is defined.
_send_qemu_cmd $QEMU_HANDLE \
"{ 'execute': 'eject',
'arguments': { 'device': 'drv' }}" \
- 'return'
+ 'return\|BLOCK_EXPORT_DELETED' |
+ grep -v 'return'
+
+_send_qemu_cmd $QEMU_HANDLE '' 'return\|BLOCK_EXPORT_DELETED' |
+ grep -v 'return'
$QEMU_IO_PROG -f raw -r -c close \
"nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \
diff --git a/tests/qemu-iotests/140.out b/tests/qemu-iotests/140.out
index 86b985da75..62d9c3ab3c 100644
--- a/tests/qemu-iotests/140.out
+++ b/tests/qemu-iotests/140.out
@@ -11,7 +11,7 @@ wrote 65536/65536 bytes at offset 0
read 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
{ 'execute': 'eject', 'arguments': { 'device': 'drv' }}
-{"return": {}}
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event":
"BLOCK_EXPORT_DELETED", "data": {"id": "drv"}}
qemu-io: can't open device nbd+unix:///drv?socket=SOCK_DIR/nbd: Requested
export not available
server reported: export 'drv' not present
{ 'execute': 'quit' }
diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out
index 31ce9e6fe0..f6eac23f04 100644
--- a/tests/qemu-iotests/223.out
+++ b/tests/qemu-iotests/223.out
@@ -102,8 +102,10 @@ read 2097152/2097152 bytes at offset 2097152
{"execute":"nbd-server-remove", "arguments":{"name":"n"}}
{"return": {}}
{"execute":"nbd-server-remove", "arguments":{"name":"n2"}}
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event":
"BLOCK_EXPORT_DELETED", "data": {"id": "n"}}
{"return": {}}
{"execute":"nbd-server-remove", "arguments":{"name":"n2"}}
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event":
"BLOCK_EXPORT_DELETED", "data": {"id": "n2"}}
{"error": {"class": "GenericError", "desc": "Export 'n2' is not found"}}
{"execute":"nbd-server-stop"}
{"return": {}}
@@ -183,8 +185,10 @@ read 2097152/2097152 bytes at offset 2097152
{"execute":"nbd-server-remove", "arguments":{"name":"n"}}
{"return": {}}
{"execute":"nbd-server-remove", "arguments":{"name":"n2"}}
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event":
"BLOCK_EXPORT_DELETED", "data": {"id": "n"}}
{"return": {}}
{"execute":"nbd-server-remove", "arguments":{"name":"n2"}}
+{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event":
"BLOCK_EXPORT_DELETED", "data": {"id": "n2"}}
{"error": {"class": "GenericError", "desc": "Export 'n2' is not found"}}
{"execute":"nbd-server-stop"}
{"return": {}}
--
2.25.4
- [PULL 14/37] nbd: Remove NBDExport.close callback, (continued)
- [PULL 14/37] nbd: Remove NBDExport.close callback, Kevin Wolf, 2020/10/02
- [PULL 17/37] block/export: Move refcount from NBDExport to BlockExport, Kevin Wolf, 2020/10/02
- [PULL 15/37] qemu-nbd: Use blk_exp_add() to create the export, Kevin Wolf, 2020/10/02
- [PULL 18/37] block/export: Move AioContext from NBDExport to BlockExport, Kevin Wolf, 2020/10/02
- [PULL 19/37] block/export: Add node-name to BlockExportOptions, Kevin Wolf, 2020/10/02
- [PULL 21/37] block/export: Add blk_exp_close_all(_type), Kevin Wolf, 2020/10/02
- [PULL 20/37] block/export: Allocate BlockExport in blk_exp_add(), Kevin Wolf, 2020/10/02
- [PULL 22/37] block/export: Add 'id' option to block-export-add, Kevin Wolf, 2020/10/02
- [PULL 24/37] block/export: Add block-export-del, Kevin Wolf, 2020/10/02
- [PULL 23/37] block/export: Move strong user reference to block_exports, Kevin Wolf, 2020/10/02
- [PULL 25/37] block/export: Add BLOCK_EXPORT_DELETED event,
Kevin Wolf <=
- [PULL 26/37] block/export: Move blk to BlockExport, Kevin Wolf, 2020/10/02
- [PULL 30/37] nbd: Merge nbd_export_new() and nbd_export_create(), Kevin Wolf, 2020/10/02
- [PULL 29/37] block/export: Move writable to BlockExportOptions, Kevin Wolf, 2020/10/02
- [PULL 28/37] block/export: Add query-block-exports, Kevin Wolf, 2020/10/02
- [PULL 31/37] nbd: Deprecate nbd-server-add/remove, Kevin Wolf, 2020/10/02
- [PULL 27/37] block/export: Create BlockBackend in blk_exp_add(), Kevin Wolf, 2020/10/02
- [PULL 33/37] iotests: Introduce qemu_nbd_list_log(), Kevin Wolf, 2020/10/02
- [PULL 36/37] qemu-storage-daemon: Fix help line for --export, Kevin Wolf, 2020/10/02
- [PULL 32/37] iotests: Factor out qemu_tool_pipe_and_status(), Kevin Wolf, 2020/10/02
- [PULL 37/37] qcow2: Use L1E_SIZE in qcow2_write_l1_entry(), Kevin Wolf, 2020/10/02