Skip to content

Instantly share code, notes, and snippets.

@XanClic
Created March 4, 2022 14:29
Show Gist options
  • Save XanClic/f096d83614393c8f2aba98f6b493ad3c to your computer and use it in GitHub Desktop.
Save XanClic/f096d83614393c8f2aba98f6b493ad3c to your computer and use it in GitHub Desktop.
diff --git a/block/amend.c b/block/amend.c
index 329bca53dc..f696a006e3 100644
--- a/block/amend.c
+++ b/block/amend.c
@@ -62,20 +62,22 @@ static int blockdev_amend_pre_run(BlockdevAmendJob *s, Error **errp)
return 0;
}
-static void blockdev_amend_clean(Job *job)
+static void blockdev_amend_free(Job *job)
{
BlockdevAmendJob *s = container_of(job, BlockdevAmendJob, common);
if (s->bs->drv->bdrv_amend_clean) {
s->bs->drv->bdrv_amend_clean(s->bs);
}
+
+ bdrv_unref(s->bs);
}
static const JobDriver blockdev_amend_job_driver = {
.instance_size = sizeof(BlockdevAmendJob),
.job_type = JOB_TYPE_AMEND,
.run = blockdev_amend_run,
- .clean = blockdev_amend_clean,
+ .free = blockdev_amend_free,
};
void qmp_x_blockdev_amend(const char *job_id,
@@ -129,11 +131,13 @@ void qmp_x_blockdev_amend(const char *job_id,
return;
}
+ bdrv_ref(bs);
s->bs = bs,
s->opts = QAPI_CLONE(BlockdevAmendOptions, options),
s->force = has_force ? force : false;
if (blockdev_amend_pre_run(s, errp)) {
+ job_early_fail(&s->common);
return;
}
diff --git a/tests/qemu-iotests/296 b/tests/qemu-iotests/296
index 099a3eeaa5..e0b058fc04 100755
--- a/tests/qemu-iotests/296
+++ b/tests/qemu-iotests/296
@@ -174,8 +174,11 @@ class EncryptionSetupTestCase(iotests.QMPTestCase):
}
result = vm.qmp('x-blockdev-amend', **args)
- assert result['return'] == {}
- vm.run_job('job0')
+ iotests.log(result)
+ # Run the job only if it was created
+ event = ('JOB_STATUS_CHANGE', {'data': {'id': 'job0'}})
+ if vm.events_wait([event], timeout=False) is not None:
+ vm.run_job('job0')
# test that when the image opened by two qemu processes,
# neither of them can update the encryption keys
diff --git a/tests/qemu-iotests/296.out b/tests/qemu-iotests/296.out
index 42205cc981..609826eaa0 100644
--- a/tests/qemu-iotests/296.out
+++ b/tests/qemu-iotests/296.out
@@ -1,11 +1,9 @@
-{"execute": "job-dismiss", "arguments": {"id": "job0"}}
{"return": {}}
-Job failed: Failed to get shared "consistent read" lock
{"execute": "job-dismiss", "arguments": {"id": "job0"}}
{"return": {}}
-Job failed: Failed to get shared "consistent read" lock
-{"execute": "job-dismiss", "arguments": {"id": "job0"}}
+{"error": {"class": "GenericError", "desc": "Failed to get shared \"consistent read\" lock"}}
+{"error": {"class": "GenericError", "desc": "Failed to get shared \"consistent read\" lock"}}
{"return": {}}
{"execute": "job-dismiss", "arguments": {"id": "job0"}}
{"return": {}}
@@ -13,14 +11,9 @@ qemu-img: Failed to get shared "consistent read" lock
Is another process using the image [TEST_DIR/test.img]?
.
-Job failed: Block node is read-only
-{"execute": "job-dismiss", "arguments": {"id": "job0"}}
-{"return": {}}
-Job failed: Failed to get shared "consistent read" lock
-{"execute": "job-dismiss", "arguments": {"id": "job0"}}
-{"return": {}}
-Job failed: Failed to get shared "consistent read" lock
-{"execute": "job-dismiss", "arguments": {"id": "job0"}}
+{"error": {"class": "GenericError", "desc": "Block node is read-only"}}
+{"error": {"class": "GenericError", "desc": "Failed to get shared \"consistent read\" lock"}}
+{"error": {"class": "GenericError", "desc": "Failed to get shared \"consistent read\" lock"}}
{"return": {}}
{"execute": "job-dismiss", "arguments": {"id": "job0"}}
{"return": {}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment