aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blockdev-nbd.c9
-rw-r--r--monitor/hmp-cmds.c4
-rw-r--r--qapi/block.json9
-rwxr-xr-xtests/qemu-iotests/2232
-rw-r--r--tests/qemu-iotests/223.out6
5 files changed, 21 insertions, 9 deletions
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 8c20baa4a4..de2f2ff713 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -144,6 +144,7 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
}
void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
+ bool has_description, const char *description,
bool has_writable, bool writable,
bool has_bitmap, const char *bitmap, Error **errp)
{
@@ -167,6 +168,11 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
return;
}
+ if (has_description && strlen(description) > NBD_MAX_STRING_SIZE) {
+ error_setg(errp, "description '%s' too long", description);
+ return;
+ }
+
if (nbd_export_find(name)) {
error_setg(errp, "NBD server already has export named '%s'", name);
return;
@@ -195,7 +201,8 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
writable = false;
}
- exp = nbd_export_new(bs, 0, len, name, NULL, bitmap, !writable, !writable,
+ exp = nbd_export_new(bs, 0, len, name, description, bitmap,
+ !writable, !writable,
NULL, false, on_eject_blk, errp);
if (!exp) {
goto out;
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index d0e0af893a..558fe06b8f 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -2351,7 +2351,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
continue;
}
- qmp_nbd_server_add(info->value->device, false, NULL,
+ qmp_nbd_server_add(info->value->device, false, NULL, false, NULL,
true, writable, false, NULL, &local_err);
if (local_err != NULL) {
@@ -2373,7 +2373,7 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
bool writable = qdict_get_try_bool(qdict, "writable", false);
Error *local_err = NULL;
- qmp_nbd_server_add(device, !!name, name, true, writable,
+ qmp_nbd_server_add(device, !!name, name, false, NULL, true, writable,
false, NULL, &local_err);
hmp_handle_error(mon, local_err);
}
diff --git a/qapi/block.json b/qapi/block.json
index 145c268bb6..7898104dae 100644
--- a/qapi/block.json
+++ b/qapi/block.json
@@ -250,9 +250,12 @@
# @name: Export name. If unspecified, the @device parameter is used as the
# export name. (Since 2.12)
#
+# @description: Free-form description of the export, up to 4096 bytes.
+# (Since 5.0)
+#
# @writable: Whether clients should be able to write to the device via the
# NBD connection (default false).
-
+#
# @bitmap: Also export the dirty bitmap reachable from @device, so the
# NBD client can use NBD_OPT_SET_META_CONTEXT with
# "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0)
@@ -263,8 +266,8 @@
# Since: 1.3.0
##
{ 'command': 'nbd-server-add',
- 'data': {'device': 'str', '*name': 'str', '*writable': 'bool',
- '*bitmap': 'str' } }
+ 'data': {'device': 'str', '*name': 'str', '*description': 'str',
+ '*writable': 'bool', '*bitmap': 'str' } }
##
# @NbdServerRemoveMode:
diff --git a/tests/qemu-iotests/223 b/tests/qemu-iotests/223
index ea69cd4b8b..56fbc5fb09 100755
--- a/tests/qemu-iotests/223
+++ b/tests/qemu-iotests/223
@@ -153,7 +153,7 @@ _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
"bitmap":"b3"}}' "error" # Missing bitmap
_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
"arguments":{"device":"n", "name":"n2", "writable":true,
- "bitmap":"b2"}}' "return"
+ "description":"some text", "bitmap":"b2"}}' "return"
$QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd"
echo
diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out
index f175598802..80c0cf6509 100644
--- a/tests/qemu-iotests/223.out
+++ b/tests/qemu-iotests/223.out
@@ -50,7 +50,7 @@ exports available: 0
{"error": {"class": "GenericError", "desc": "Enabled bitmap 'b2' incompatible with readonly export"}}
{"execute":"nbd-server-add", "arguments":{"device":"n", "name":"n2", "bitmap":"b3"}}
{"error": {"class": "GenericError", "desc": "Bitmap 'b3' is not found"}}
-{"execute":"nbd-server-add", "arguments":{"device":"n", "name":"n2", "writable":true, "bitmap":"b2"}}
+{"execute":"nbd-server-add", "arguments":{"device":"n", "name":"n2", "writable":true, "description":"some text", "bitmap":"b2"}}
{"return": {}}
exports available: 2
export: 'n'
@@ -63,6 +63,7 @@ exports available: 2
base:allocation
qemu:dirty-bitmap:b
export: 'n2'
+ description: some text
size: 4194304
flags: 0xced ( flush fua trim zeroes df cache fast-zero )
min block: 1
@@ -130,7 +131,7 @@ exports available: 0
{"error": {"class": "GenericError", "desc": "Enabled bitmap 'b2' incompatible with readonly export"}}
{"execute":"nbd-server-add", "arguments":{"device":"n", "name":"n2", "bitmap":"b3"}}
{"error": {"class": "GenericError", "desc": "Bitmap 'b3' is not found"}}
-{"execute":"nbd-server-add", "arguments":{"device":"n", "name":"n2", "writable":true, "bitmap":"b2"}}
+{"execute":"nbd-server-add", "arguments":{"device":"n", "name":"n2", "writable":true, "description":"some text", "bitmap":"b2"}}
{"return": {}}
exports available: 2
export: 'n'
@@ -143,6 +144,7 @@ exports available: 2
base:allocation
qemu:dirty-bitmap:b
export: 'n2'
+ description: some text
size: 4194304
flags: 0xced ( flush fua trim zeroes df cache fast-zero )
min block: 1