mirror of
https://github.com/mii443/qemu.git
synced 2025-12-03 11:08:25 +00:00
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>
This commit is contained in:
12
qemu-nbd.c
12
qemu-nbd.c
@@ -100,6 +100,7 @@ static void usage(const char *name)
|
||||
"\n"
|
||||
"Exposing part of the image:\n"
|
||||
" -o, --offset=OFFSET offset into the image\n"
|
||||
" -A, --allocation-depth expose the allocation depth\n"
|
||||
" -B, --bitmap=NAME expose a persistent dirty bitmap\n"
|
||||
"\n"
|
||||
"General purpose options:\n"
|
||||
@@ -524,7 +525,7 @@ int main(int argc, char **argv)
|
||||
char *device = NULL;
|
||||
QemuOpts *sn_opts = NULL;
|
||||
const char *sn_id_or_name = NULL;
|
||||
const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:B:L";
|
||||
const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L";
|
||||
struct option lopt[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
@@ -533,6 +534,7 @@ int main(int argc, char **argv)
|
||||
{ "socket", required_argument, NULL, 'k' },
|
||||
{ "offset", required_argument, NULL, 'o' },
|
||||
{ "read-only", no_argument, NULL, 'r' },
|
||||
{ "allocation-depth", no_argument, NULL, 'A' },
|
||||
{ "bitmap", required_argument, NULL, 'B' },
|
||||
{ "connect", required_argument, NULL, 'c' },
|
||||
{ "disconnect", no_argument, NULL, 'd' },
|
||||
@@ -575,6 +577,7 @@ int main(int argc, char **argv)
|
||||
const char *export_name = NULL; /* defaults to "" later for server mode */
|
||||
const char *export_description = NULL;
|
||||
strList *bitmaps = NULL;
|
||||
bool alloc_depth = false;
|
||||
const char *tlscredsid = NULL;
|
||||
bool imageOpts = false;
|
||||
bool writethrough = true;
|
||||
@@ -689,6 +692,9 @@ int main(int argc, char **argv)
|
||||
readonly = true;
|
||||
flags &= ~BDRV_O_RDWR;
|
||||
break;
|
||||
case 'A':
|
||||
alloc_depth = true;
|
||||
break;
|
||||
case 'B':
|
||||
QAPI_LIST_PREPEND(bitmaps, g_strdup(optarg));
|
||||
break;
|
||||
@@ -787,7 +793,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
if (export_name || export_description || dev_offset ||
|
||||
device || disconnect || fmt || sn_id_or_name || bitmaps ||
|
||||
seen_aio || seen_discard || seen_cache) {
|
||||
alloc_depth || seen_aio || seen_discard || seen_cache) {
|
||||
error_report("List mode is incompatible with per-device settings");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -1073,6 +1079,8 @@ int main(int argc, char **argv)
|
||||
.description = g_strdup(export_description),
|
||||
.has_bitmaps = !!bitmaps,
|
||||
.bitmaps = bitmaps,
|
||||
.has_allocation_depth = alloc_depth,
|
||||
.allocation_depth = alloc_depth,
|
||||
},
|
||||
};
|
||||
blk_exp_add(export_opts, &error_fatal);
|
||||
|
||||
Reference in New Issue
Block a user