summaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorEric Blake2020-10-27 06:05:55 +0100
committerEric Blake2020-10-30 21:22:00 +0100
commitdbc7b01492371e4a54b92d2b6d968f9b863cc794 (patch)
tree24812091f95b86d03192a23bec70e21d9a5b74eb /block
parentnbd: Add new qemu:allocation-depth metadata context (diff)
downloadqemu-dbc7b01492371e4a54b92d2b6d968f9b863cc794.tar.gz
qemu-dbc7b01492371e4a54b92d2b6d968f9b863cc794.tar.xz
qemu-dbc7b01492371e4a54b92d2b6d968f9b863cc794.zip
nbd: Add 'qemu-nbd -A' to expose allocation depth
Allow the server to expose an additional metacontext to be requested by savvy clients. qemu-nbd adds a new option -A to expose the qemu:allocation-depth metacontext through NBD_CMD_BLOCK_STATUS; this can also be set via QMP when using block-export-add. qemu as client is hacked into viewing the key aspects of this new context by abusing the already-experimental x-dirty-bitmap option to collapse all depths greater than 2, which results in a tri-state value visible in the output of 'qemu-img map --output=json' (yes, that means x-dirty-bitmap is now a bit of a misnomer, but I didn't feel like renaming it as it would introduce a needless break of back-compat, even though we make no compat guarantees with x- members): unallocated (depth 0) => "zero":false, "data":true local (depth 1) => "zero":false, "data":false backing (depth 2+) => "zero":true, "data":true libnbd as client is probably a nicer way to get at the information without having to decipher such hacks in qemu as client. ;) Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <20201027050556.269064-11-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Diffstat (limited to 'block')
-rw-r--r--block/nbd.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/block/nbd.c b/block/nbd.c
index 4548046cd7..42536702b6 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -135,6 +135,7 @@ typedef struct BDRVNBDState {
QCryptoTLSCreds *tlscreds;
const char *hostname;
char *x_dirty_bitmap;
+ bool alloc_depth;
bool wait_connect;
NBDConnectThread *connect_thread;
@@ -961,6 +962,16 @@ static int nbd_parse_blockstatus_payload(BDRVNBDState *s,
trace_nbd_parse_blockstatus_compliance("extent length too large");
}
+ /*
+ * HACK: if we are using x-dirty-bitmaps to access
+ * qemu:allocation-depth, treat all depths > 2 the same as 2,
+ * since nbd_client_co_block_status is only expecting the low two
+ * bits to be set.
+ */
+ if (s->alloc_depth && extent->flags > 2) {
+ extent->flags = 2;
+ }
+
return 0;
}
@@ -1795,11 +1806,16 @@ static int nbd_client_handshake(BlockDriverState *bs, QIOChannelSocket *sioc,
s->sioc = NULL;
return ret;
}
- if (s->x_dirty_bitmap && !s->info.base_allocation) {
- error_setg(errp, "requested x-dirty-bitmap %s not found",
- s->x_dirty_bitmap);
- ret = -EINVAL;
- goto fail;
+ if (s->x_dirty_bitmap) {
+ if (!s->info.base_allocation) {
+ error_setg(errp, "requested x-dirty-bitmap %s not found",
+ s->x_dirty_bitmap);
+ ret = -EINVAL;
+ goto fail;
+ }
+ if (strcmp(s->x_dirty_bitmap, "qemu:allocation-depth") == 0) {
+ s->alloc_depth = true;
+ }
}
if (s->info.flags & NBD_FLAG_READ_ONLY) {
ret = bdrv_apply_auto_read_only(bs, "NBD export is read-only", errp);