Created
March 4, 2022 14:35
-
-
Save XanClic/cb30312568f0e7b9f2b4b41ebd31bc5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/block/crypto.c b/block/crypto.c | |
index d9895c3543..70b2f07351 100644 | |
--- a/block/crypto.c | |
+++ b/block/crypto.c | |
@@ -781,10 +781,16 @@ static int | |
block_crypto_amend_prepare(BlockDriverState *bs, Error **errp) | |
{ | |
BlockCrypto *crypto = bs->opaque; | |
+ int ret; | |
/* apply for exclusive read/write permissions to the underlying file */ | |
crypto->updating_keys = true; | |
- return bdrv_child_refresh_perms(bs, bs->file, errp); | |
+ ret = bdrv_child_refresh_perms(bs, bs->file, errp); | |
+ if (ret < 0) { | |
+ /* Well, in this case we will not be updating any keys */ | |
+ crypto->updating_keys = false; | |
+ } | |
+ return ret; | |
} | |
static void | |
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