* [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum
@ 2013-10-08 9:29 Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 1/3] blockjob: rename BlockJobType to BlockJobDriver Fam Zheng
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Fam Zheng @ 2013-10-08 9:29 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Currently, block job type is hard coded string and could be repeated in
different places in the code base. Introduce a enum type in QAPI to make it
better for maintenance and introspection. The old BlockJobType struct is
renamed to BlockJobDriver and its field "job_type" becomes a BlockJobType enum.
Nothing is changed to the interface.
Fam Zheng (3):
blockjob: rename BlockJobType to BlockJobDriver
qapi: Introduce enum BlockJobType
qapi: make use of new BlockJobType
block/backup.c | 6 +++---
block/commit.c | 6 +++---
block/mirror.c | 6 +++---
block/stream.c | 6 +++---
blockjob.c | 22 +++++++++++-----------
include/block/blockjob.h | 14 +++++++-------
qapi-schema.json | 18 ++++++++++++++++++
7 files changed, 48 insertions(+), 30 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 1/3] blockjob: rename BlockJobType to BlockJobDriver
2013-10-08 9:29 [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum Fam Zheng
@ 2013-10-08 9:29 ` Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 2/3] qapi: Introduce enum BlockJobType Fam Zheng
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Fam Zheng @ 2013-10-08 9:29 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
We will use BlockJobType as the enum type name of block jobs in QAPI,
rename current BlockJobType to BlockJobDriver, which will eventually
become a set of operations, similar to block drivers.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/backup.c | 4 ++--
block/commit.c | 4 ++--
block/mirror.c | 4 ++--
block/stream.c | 4 ++--
blockjob.c | 22 +++++++++++-----------
include/block/blockjob.h | 12 ++++++------
6 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index 04c4b5c..d374472 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -202,7 +202,7 @@ static void backup_iostatus_reset(BlockJob *job)
bdrv_iostatus_reset(s->target);
}
-static const BlockJobType backup_job_type = {
+static const BlockJobDriver backup_job_driver = {
.instance_size = sizeof(BackupBlockJob),
.job_type = "backup",
.set_speed = backup_set_speed,
@@ -370,7 +370,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
return;
}
- BackupBlockJob *job = block_job_create(&backup_job_type, bs, speed,
+ BackupBlockJob *job = block_job_create(&backup_job_driver, bs, speed,
cb, opaque, errp);
if (!job) {
return;
diff --git a/block/commit.c b/block/commit.c
index ac4b7cc..5146138 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -173,7 +173,7 @@ static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp)
ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
}
-static const BlockJobType commit_job_type = {
+static const BlockJobDriver commit_job_driver = {
.instance_size = sizeof(CommitBlockJob),
.job_type = "commit",
.set_speed = commit_set_speed,
@@ -238,7 +238,7 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,
}
- s = block_job_create(&commit_job_type, bs, speed, cb, opaque, errp);
+ s = block_job_create(&commit_job_driver, bs, speed, cb, opaque, errp);
if (!s) {
return;
}
diff --git a/block/mirror.c b/block/mirror.c
index 6e7a274..991cc24 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -525,7 +525,7 @@ static void mirror_complete(BlockJob *job, Error **errp)
block_job_resume(job);
}
-static const BlockJobType mirror_job_type = {
+static const BlockJobDriver mirror_job_driver = {
.instance_size = sizeof(MirrorBlockJob),
.job_type = "mirror",
.set_speed = mirror_set_speed,
@@ -563,7 +563,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
return;
}
- s = block_job_create(&mirror_job_type, bs, speed, cb, opaque, errp);
+ s = block_job_create(&mirror_job_driver, bs, speed, cb, opaque, errp);
if (!s) {
return;
}
diff --git a/block/stream.c b/block/stream.c
index 45837f4..7f412bd 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -203,7 +203,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp)
ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
}
-static const BlockJobType stream_job_type = {
+static const BlockJobDriver stream_job_driver = {
.instance_size = sizeof(StreamBlockJob),
.job_type = "stream",
.set_speed = stream_set_speed,
@@ -224,7 +224,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,
return;
}
- s = block_job_create(&stream_job_type, bs, speed, cb, opaque, errp);
+ s = block_job_create(&stream_job_driver, bs, speed, cb, opaque, errp);
if (!s) {
return;
}
diff --git a/blockjob.c b/blockjob.c
index e7d49b7..6814e69 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -35,7 +35,7 @@
#include "qmp-commands.h"
#include "qemu/timer.h"
-void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
+void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
int64_t speed, BlockDriverCompletionFunc *cb,
void *opaque, Error **errp)
{
@@ -48,8 +48,8 @@ void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
bdrv_ref(bs);
bdrv_set_in_use(bs, 1);
- job = g_malloc0(job_type->instance_size);
- job->job_type = job_type;
+ job = g_malloc0(driver->instance_size);
+ job->driver = driver;
job->bs = bs;
job->cb = cb;
job->opaque = opaque;
@@ -87,11 +87,11 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
{
Error *local_err = NULL;
- if (!job->job_type->set_speed) {
+ if (!job->driver->set_speed) {
error_set(errp, QERR_NOT_SUPPORTED);
return;
}
- job->job_type->set_speed(job, speed, &local_err);
+ job->driver->set_speed(job, speed, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
return;
@@ -102,12 +102,12 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
void block_job_complete(BlockJob *job, Error **errp)
{
- if (job->paused || job->cancelled || !job->job_type->complete) {
+ if (job->paused || job->cancelled || !job->driver->complete) {
error_set(errp, QERR_BLOCK_JOB_NOT_READY, job->bs->device_name);
return;
}
- job->job_type->complete(job, errp);
+ job->driver->complete(job, errp);
}
void block_job_pause(BlockJob *job)
@@ -143,8 +143,8 @@ bool block_job_is_cancelled(BlockJob *job)
void block_job_iostatus_reset(BlockJob *job)
{
job->iostatus = BLOCK_DEVICE_IO_STATUS_OK;
- if (job->job_type->iostatus_reset) {
- job->job_type->iostatus_reset(job);
+ if (job->driver->iostatus_reset) {
+ job->driver->iostatus_reset(job);
}
}
@@ -209,7 +209,7 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns)
BlockJobInfo *block_job_query(BlockJob *job)
{
BlockJobInfo *info = g_new0(BlockJobInfo, 1);
- info->type = g_strdup(job->job_type->job_type);
+ info->type = g_strdup(job->driver->job_type);
info->device = g_strdup(bdrv_get_device_name(job->bs));
info->len = job->len;
info->busy = job->busy;
@@ -236,7 +236,7 @@ QObject *qobject_from_block_job(BlockJob *job)
"'len': %" PRId64 ","
"'offset': %" PRId64 ","
"'speed': %" PRId64 " }",
- job->job_type->job_type,
+ job->driver->job_type,
bdrv_get_device_name(job->bs),
job->len,
job->offset,
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index d530409..99359b5 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -28,11 +28,11 @@
#include "block/block.h"
/**
- * BlockJobType:
+ * BlockJobDriver:
*
- * A class type for block job objects.
+ * A class type for block job driver.
*/
-typedef struct BlockJobType {
+typedef struct BlockJobDriver {
/** Derived BlockJob struct size */
size_t instance_size;
@@ -50,7 +50,7 @@ typedef struct BlockJobType {
* manually.
*/
void (*complete)(BlockJob *job, Error **errp);
-} BlockJobType;
+} BlockJobDriver;
/**
* BlockJob:
@@ -59,7 +59,7 @@ typedef struct BlockJobType {
*/
struct BlockJob {
/** The job type, including the job vtable. */
- const BlockJobType *job_type;
+ const BlockJobDriver *driver;
/** The block device on which the job is operating. */
BlockDriverState *bs;
@@ -128,7 +128,7 @@ struct BlockJob {
* This function is not part of the public job interface; it should be
* called from a wrapper that is specific to the job type.
*/
-void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
+void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
int64_t speed, BlockDriverCompletionFunc *cb,
void *opaque, Error **errp);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/3] qapi: Introduce enum BlockJobType
2013-10-08 9:29 [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 1/3] blockjob: rename BlockJobType to BlockJobDriver Fam Zheng
@ 2013-10-08 9:29 ` Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 3/3] qapi: make use of new BlockJobType Fam Zheng
2013-10-08 12:49 ` [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum Kevin Wolf
3 siblings, 0 replies; 6+ messages in thread
From: Fam Zheng @ 2013-10-08 9:29 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
This will replace the open coded block job type string for mirror,
commit and backup.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
qapi-schema.json | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/qapi-schema.json b/qapi-schema.json
index 145eca8..381ffbf 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1366,6 +1366,24 @@
'data': ['top', 'full', 'none'] }
##
+# @BlockJobType:
+#
+# Type of a block job.
+#
+# @commit: block commit job type, see "block-commit"
+#
+# @stream: block stream job type, see "block-stream"
+#
+# @mirror: drive mirror job type, see "drive-mirror"
+#
+# @backup: drive backup job type, see "drive-backup"
+#
+# Since: 1.7
+##
+{ 'enum': 'BlockJobType',
+ 'data': ['commit', 'stream', 'mirror', 'backup'] }
+
+##
# @BlockJobInfo:
#
# Information about a long-running block device operation.
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 3/3] qapi: make use of new BlockJobType
2013-10-08 9:29 [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 1/3] blockjob: rename BlockJobType to BlockJobDriver Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 2/3] qapi: Introduce enum BlockJobType Fam Zheng
@ 2013-10-08 9:29 ` Fam Zheng
2013-10-08 13:06 ` Eric Blake
2013-10-08 12:49 ` [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum Kevin Wolf
3 siblings, 1 reply; 6+ messages in thread
From: Fam Zheng @ 2013-10-08 9:29 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Switch the string to enum type BlockJobType in BlockJobDriver.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/backup.c | 2 +-
block/commit.c | 2 +-
block/mirror.c | 2 +-
block/stream.c | 2 +-
blockjob.c | 4 ++--
include/block/blockjob.h | 2 +-
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index d374472..cad14c9 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -204,7 +204,7 @@ static void backup_iostatus_reset(BlockJob *job)
static const BlockJobDriver backup_job_driver = {
.instance_size = sizeof(BackupBlockJob),
- .job_type = "backup",
+ .job_type = BLOCK_JOB_TYPE_BACKUP,
.set_speed = backup_set_speed,
.iostatus_reset = backup_iostatus_reset,
};
diff --git a/block/commit.c b/block/commit.c
index 5146138..d4090cb 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -175,7 +175,7 @@ static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp)
static const BlockJobDriver commit_job_driver = {
.instance_size = sizeof(CommitBlockJob),
- .job_type = "commit",
+ .job_type = BLOCK_JOB_TYPE_COMMIT,
.set_speed = commit_set_speed,
};
diff --git a/block/mirror.c b/block/mirror.c
index 991cc24..7b95acf 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -527,7 +527,7 @@ static void mirror_complete(BlockJob *job, Error **errp)
static const BlockJobDriver mirror_job_driver = {
.instance_size = sizeof(MirrorBlockJob),
- .job_type = "mirror",
+ .job_type = BLOCK_JOB_TYPE_MIRROR,
.set_speed = mirror_set_speed,
.iostatus_reset= mirror_iostatus_reset,
.complete = mirror_complete,
diff --git a/block/stream.c b/block/stream.c
index 7f412bd..694fd42 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -205,7 +205,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp)
static const BlockJobDriver stream_job_driver = {
.instance_size = sizeof(StreamBlockJob),
- .job_type = "stream",
+ .job_type = BLOCK_JOB_TYPE_STREAM,
.set_speed = stream_set_speed,
};
diff --git a/blockjob.c b/blockjob.c
index 6814e69..9e5fd5c 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -209,7 +209,7 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns)
BlockJobInfo *block_job_query(BlockJob *job)
{
BlockJobInfo *info = g_new0(BlockJobInfo, 1);
- info->type = g_strdup(job->driver->job_type);
+ info->type = g_strdup(BlockJobType_lookup[job->driver->job_type]);
info->device = g_strdup(bdrv_get_device_name(job->bs));
info->len = job->len;
info->busy = job->busy;
@@ -236,7 +236,7 @@ QObject *qobject_from_block_job(BlockJob *job)
"'len': %" PRId64 ","
"'offset': %" PRId64 ","
"'speed': %" PRId64 " }",
- job->driver->job_type,
+ BlockJobType_lookup[job->driver->job_type],
bdrv_get_device_name(job->bs),
job->len,
job->offset,
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index 99359b5..d76de62 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -37,7 +37,7 @@ typedef struct BlockJobDriver {
size_t instance_size;
/** String describing the operation, part of query-block-jobs QMP API */
- const char *job_type;
+ BlockJobType job_type;
/** Optional callback for job types that support setting a speed limit */
void (*set_speed)(BlockJob *job, int64_t speed, Error **errp);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum
2013-10-08 9:29 [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum Fam Zheng
` (2 preceding siblings ...)
2013-10-08 9:29 ` [Qemu-devel] [PATCH 3/3] qapi: make use of new BlockJobType Fam Zheng
@ 2013-10-08 12:49 ` Kevin Wolf
3 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2013-10-08 12:49 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel, stefanha
Am 08.10.2013 um 11:29 hat Fam Zheng geschrieben:
> Currently, block job type is hard coded string and could be repeated in
> different places in the code base. Introduce a enum type in QAPI to make it
> better for maintenance and introspection. The old BlockJobType struct is
> renamed to BlockJobDriver and its field "job_type" becomes a BlockJobType enum.
>
> Nothing is changed to the interface.
>
> Fam Zheng (3):
> blockjob: rename BlockJobType to BlockJobDriver
> qapi: Introduce enum BlockJobType
> qapi: make use of new BlockJobType
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 3/3] qapi: make use of new BlockJobType
2013-10-08 9:29 ` [Qemu-devel] [PATCH 3/3] qapi: make use of new BlockJobType Fam Zheng
@ 2013-10-08 13:06 ` Eric Blake
0 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2013-10-08 13:06 UTC (permalink / raw)
To: Fam Zheng; +Cc: kwolf, qemu-devel, stefanha
[-- Attachment #1: Type: text/plain, Size: 755 bytes --]
On 10/08/2013 03:29 AM, Fam Zheng wrote:
> Switch the string to enum type BlockJobType in BlockJobDriver.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> +++ b/include/block/blockjob.h
> @@ -37,7 +37,7 @@ typedef struct BlockJobDriver {
> size_t instance_size;
>
> /** String describing the operation, part of query-block-jobs QMP API */
> - const char *job_type;
> + BlockJobType job_type;
Comment looks awkward now that it is not a string in memory; but it is
still a string on the wire, so I can live with it as-is.
Series: Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks for doing this!
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-10-08 13:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-08 9:29 [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 1/3] blockjob: rename BlockJobType to BlockJobDriver Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 2/3] qapi: Introduce enum BlockJobType Fam Zheng
2013-10-08 9:29 ` [Qemu-devel] [PATCH 3/3] qapi: make use of new BlockJobType Fam Zheng
2013-10-08 13:06 ` Eric Blake
2013-10-08 12:49 ` [Qemu-devel] [PATCH 0/3] qapi: introduce BlockJobType enum Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).