Skip to content

Commit 3c605f4

Browse files
committed
commit: Add top-node/base-node options
The block-commit QMP command required specifying the top and base nodes of the commit jobs using the file name of that node. While this works in simple cases (local files with absolute paths), the file names generated for more complicated setups can be hard to predict. The block-commit command has more problems than just this, so we want to replace it altogether in the long run, but libvirt needs a reliable way to address nodes now. So we don't want to wait for a new, cleaner command, but just add the minimal thing needed right now. This adds two new options top-node and base-node to the command, which allow specifying node names instead. They are mutually exclusive with the old options. Signed-off-by: Kevin Wolf <[email protected]>
1 parent 66da04d commit 3c605f4

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

blockdev.c

+30-2
Original file line numberDiff line numberDiff line change
@@ -3214,7 +3214,9 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device,
32143214
}
32153215

32163216
void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
3217+
bool has_base_node, const char *base_node,
32173218
bool has_base, const char *base,
3219+
bool has_top_node, const char *top_node,
32183220
bool has_top, const char *top,
32193221
bool has_backing_file, const char *backing_file,
32203222
bool has_speed, int64_t speed,
@@ -3275,7 +3277,20 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
32753277
/* default top_bs is the active layer */
32763278
top_bs = bs;
32773279

3278-
if (has_top && top) {
3280+
if (has_top_node && has_top) {
3281+
error_setg(errp, "'top-node' and 'top' are mutually exclusive");
3282+
goto out;
3283+
} else if (has_top_node) {
3284+
top_bs = bdrv_lookup_bs(NULL, top_node, errp);
3285+
if (top_bs == NULL) {
3286+
goto out;
3287+
}
3288+
if (!bdrv_chain_contains(bs, top_bs)) {
3289+
error_setg(errp, "'%s' is not in this backing file chain",
3290+
top_node);
3291+
goto out;
3292+
}
3293+
} else if (has_top && top) {
32793294
if (strcmp(bs->filename, top) != 0) {
32803295
top_bs = bdrv_find_backing_image(bs, top);
32813296
}
@@ -3288,7 +3303,20 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
32883303

32893304
assert(bdrv_get_aio_context(top_bs) == aio_context);
32903305

3291-
if (has_base && base) {
3306+
if (has_base_node && has_base) {
3307+
error_setg(errp, "'base-node' and 'base' are mutually exclusive");
3308+
goto out;
3309+
} else if (has_base_node) {
3310+
base_bs = bdrv_lookup_bs(NULL, base_node, errp);
3311+
if (base_bs == NULL) {
3312+
goto out;
3313+
}
3314+
if (!bdrv_chain_contains(top_bs, base_bs)) {
3315+
error_setg(errp, "'%s' is not in this backing file chain",
3316+
base_node);
3317+
goto out;
3318+
}
3319+
} else if (has_base && base) {
32923320
base_bs = bdrv_find_backing_image(top_bs, base);
32933321
} else {
32943322
base_bs = bdrv_find_base(top_bs);

qapi/block-core.json

+18-6
Original file line numberDiff line numberDiff line change
@@ -1457,12 +1457,23 @@
14571457
#
14581458
# @device: the device name or node-name of a root node
14591459
#
1460-
# @base: The file name of the backing image to write data into.
1461-
# If not specified, this is the deepest backing image.
1460+
# @base-node: The node name of the backing image to write data into.
1461+
# If not specified, this is the deepest backing image.
1462+
# (since: 3.1)
14621463
#
1463-
# @top: The file name of the backing image within the image chain,
1464-
# which contains the topmost data to be committed down. If
1465-
# not specified, this is the active layer.
1464+
# @base: Same as @base-node, except that it is a file name rather than a node
1465+
# name. This must be the exact filename string that was used to open the
1466+
# node; other strings, even if addressing the same file, are not
1467+
# accepted (deprecated, use @base-node instead)
1468+
#
1469+
# @top-node: The node name of the backing image within the image chain
1470+
# which contains the topmost data to be committed down. If
1471+
# not specified, this is the active layer. (since: 3.1)
1472+
#
1473+
# @top: Same as @top-node, except that it is a file name rather than a node
1474+
# name. This must be the exact filename string that was used to open the
1475+
# node; other strings, even if addressing the same file, are not
1476+
# accepted (deprecated, use @base-node instead)
14661477
#
14671478
# @backing-file: The backing file string to write into the overlay
14681479
# image of 'top'. If 'top' is the active layer,
@@ -1528,7 +1539,8 @@
15281539
#
15291540
##
15301541
{ 'command': 'block-commit',
1531-
'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', '*top': 'str',
1542+
'data': { '*job-id': 'str', 'device': 'str', '*base-node': 'str',
1543+
'*base': 'str', '*top-node': 'str', '*top': 'str',
15321544
'*backing-file': 'str', '*speed': 'int',
15331545
'*filter-node-name': 'str',
15341546
'*auto-finalize': 'bool', '*auto-dismiss': 'bool' } }

0 commit comments

Comments
 (0)