[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/14] block: keep a list of block jobs
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 01/14] block: keep a list of block jobs |
Date: |
Wed, 4 May 2016 11:39:12 +0200 |
From: Alberto Garcia <address@hidden>
The current way to obtain the list of existing block jobs is to
iterate over all root nodes and check which ones own a job.
Since we want to be able to support block jobs in other nodes as well,
this patch keeps a list of jobs that is updated every time one is
created or destroyed.
Signed-off-by: Alberto Garcia <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
blockjob.c | 13 +++++++++++++
include/block/blockjob.h | 14 ++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/blockjob.c b/blockjob.c
index 5b840a7..0f1bc77 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -50,6 +50,16 @@ struct BlockJobTxn {
int refcnt;
};
+static QLIST_HEAD(, BlockJob) block_jobs = QLIST_HEAD_INITIALIZER(block_jobs);
+
+BlockJob *block_job_next(BlockJob *job)
+{
+ if (!job) {
+ return QLIST_FIRST(&block_jobs);
+ }
+ return QLIST_NEXT(job, job_list);
+}
+
void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
int64_t speed, BlockCompletionFunc *cb,
void *opaque, Error **errp)
@@ -76,6 +86,8 @@ void *block_job_create(const BlockJobDriver *driver,
BlockDriverState *bs,
job->refcnt = 1;
bs->job = job;
+ QLIST_INSERT_HEAD(&block_jobs, job, job_list);
+
/* Only set speed when necessary to avoid NotSupported error */
if (speed != 0) {
Error *local_err = NULL;
@@ -103,6 +115,7 @@ void block_job_unref(BlockJob *job)
bdrv_unref(job->bs);
error_free(job->blocker);
g_free(job->id);
+ QLIST_REMOVE(job, job_list);
g_free(job);
}
}
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index 073a433..30bb2c6 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -135,6 +135,9 @@ struct BlockJob {
*/
bool deferred_to_main_loop;
+ /** Element of the list of block jobs */
+ QLIST_ENTRY(BlockJob) job_list;
+
/** Status that is published by the query-block-jobs QMP API */
BlockDeviceIoStatus iostatus;
@@ -173,6 +176,17 @@ struct BlockJob {
};
/**
+ * block_job_next:
+ * @job: A block job, or %NULL.
+ *
+ * Get the next element from the list of block jobs after @job, or the
+ * first one if @job is %NULL.
+ *
+ * Returns the requested job, or %NULL if there are no more jobs left.
+ */
+BlockJob *block_job_next(BlockJob *job);
+
+/**
* block_job_create:
* @job_type: The class object for the newly-created job.
* @bs: The block
--
1.8.3.1
- [Qemu-devel] [PATCH 00/14] block jobs: Convert I/O to BlockBackend, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 03/14] block: Default to enabled write cache in blk_new(), Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 04/14] block: Convert block job core to BlockBackend, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 05/14] stream: Use BlockBackend for I/O, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 06/14] mirror: Allow target that already has a BlockBackend, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 01/14] block: keep a list of block jobs,
Kevin Wolf <=
- [Qemu-devel] [PATCH 08/14] backup: Don't leak BackupBlockJob in error path, Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 02/14] block: Cancel jobs first in bdrv_close_all(), Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 11/14] block: Add blk_co_readv/writev(), Kevin Wolf, 2016/05/04
- [Qemu-devel] [PATCH 10/14] backup: Remove bs parameter from backup_do_cow(), Kevin Wolf, 2016/05/04