*/
#include "qemu/osdep.h"
-#include "qemu-common.h"
#include "block/block.h"
#include "block/blockjob_int.h"
#include "block/block_int.h"
void block_job_free(Job *job)
{
BlockJob *bjob = container_of(job, BlockJob, job);
- BlockDriverState *bs = blk_bs(bjob->blk);
- bs->job = NULL;
block_job_remove_all_bdrv(bjob);
blk_unref(bjob->blk);
error_free(bjob->blocker);
job->nodes = NULL;
}
+bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs)
+{
+ GSList *el;
+
+ for (el = job->nodes; el; el = el->next) {
+ BdrvChild *c = el->data;
+ if (c->bs == bs) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
uint64_t perm, uint64_t shared_perm, Error **errp)
{
BdrvChild *c;
bdrv_ref(bs);
- c = bdrv_root_attach_child(bs, name, &child_job, perm, shared_perm,
- job, errp);
+ if (job->job.aio_context != qemu_get_aio_context()) {
+ aio_context_release(job->job.aio_context);
+ }
+ c = bdrv_root_attach_child(bs, name, &child_job, job->job.aio_context,
+ perm, shared_perm, job, errp);
+ if (job->job.aio_context != qemu_get_aio_context()) {
+ aio_context_acquire(job->job.aio_context);
+ }
if (c == NULL) {
return -EPERM;
}
BlockJob *job;
int ret;
- if (bs->job) {
- error_setg(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
- return NULL;
- }
-
if (job_id == NULL && !(flags & JOB_INTERNAL)) {
job_id = bdrv_get_device_name(bs);
}
- blk = blk_new(perm, shared_perm);
+ blk = blk_new(bdrv_get_aio_context(bs), perm, shared_perm);
ret = blk_insert_bs(blk, bs, errp);
if (ret < 0) {
blk_unref(blk);
error_setg(&job->blocker, "block device is in use by block job: %s",
job_type_str(&job->job));
block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort);
- bs->job = job;
bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker);