From patchwork Tue Jul 24 11:04:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 172873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 92CD42C008F for ; Tue, 24 Jul 2012 22:39:57 +1000 (EST) Received: from localhost ([::1]:41626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SteP5-0006yu-Nr for incoming@patchwork.ozlabs.org; Tue, 24 Jul 2012 08:39:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Stcw5-0007eL-Mf for qemu-devel@nongnu.org; Tue, 24 Jul 2012 07:05:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Stcw4-0005nc-3g for qemu-devel@nongnu.org; Tue, 24 Jul 2012 07:05:53 -0400 Received: from mail-yw0-f45.google.com ([209.85.213.45]:36778) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Stcw3-00058R-UL for qemu-devel@nongnu.org; Tue, 24 Jul 2012 07:05:52 -0400 Received: by mail-yw0-f45.google.com with SMTP id p34so6575216yhp.4 for ; Tue, 24 Jul 2012 04:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=ofKFrQKzqOl1iHCim0EY0WnvDPk0XyNmv7mg1ntZ3uE=; b=RWzRFpcHDDkMOXbA2WE/wAg06wvzIyEM708UXq/vNph63KK4+zZ646ld26McAFtl/J M2SS8hum7xjcclgj9UhkfRAc1jdDf41DpI8OIC95WM9lhkOCr0mfkLDsZQ3ON5FN8R+N pF0ca5kcIqYZpqdOJBteMf7YWv5Mropxx/eTt0Mxz1dqJF1z5EbwWdNqLiPI+fPpiNb3 CSqHTcSYh47A+Tngh7CJjZjNrdfZUsHkNarf6Y8JInknqVOfU6Opz6bZcapUmrjhd1IW RfIIThitNE+hdSeZhhmcilgpHuwUFMxEb+e5F06vxy4sJrUFdpDM5XZZr1jnxpUDFa9f vGDg== Received: by 10.43.124.201 with SMTP id gp9mr14444314icc.47.1343127951443; Tue, 24 Jul 2012 04:05:51 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-189-113.ip51.fastwebnet.it. [93.34.189.113]) by mx.google.com with ESMTPS id if4sm1752561igc.10.2012.07.24.04.05.48 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 24 Jul 2012 04:05:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 24 Jul 2012 13:04:03 +0200 Message-Id: <1343127865-16608-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343127865-16608-1-git-send-email-pbonzini@redhat.com> References: <1343127865-16608-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.45 Cc: kwolf@redhat.com, jcody@redhat.com, eblake@redhat.com, stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 25/47] block: add block-job-complete X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org While streaming can be dropped as soon as it progressed through the whole image, mirroring needs to be completed manually for two reasons: 1) so that management knows exactly when the VM switches to the target; 2) because for other use cases such as replication, we may leave the operation running for the whole life of the virtual machine. Add a new block job command that manually completes background operations. Signed-off-by: Paolo Bonzini --- blockdev.c | 13 +++++++++++++ blockjob.c | 10 ++++++++++ blockjob.h | 15 +++++++++++++++ hmp-commands.hx | 17 ++++++++++++++++- hmp.c | 10 ++++++++++ hmp.h | 1 + qapi-schema.json | 27 +++++++++++++++++++++++++++ qerror.c | 4 ++++ qerror.h | 3 +++ qmp-commands.hx | 5 +++++ trace-events | 1 + 11 files changed, 105 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 49ade14..7544afc 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1200,6 +1200,19 @@ void qmp_block_job_resume(const char *device, Error **errp) block_job_resume(job); } +void qmp_block_job_complete(const char *device, Error **errp) +{ + BlockJob *job = find_block_job(device); + + if (!job) { + error_set(errp, QERR_BLOCK_JOB_NOT_ACTIVE, device); + return; + } + + trace_qmp_block_job_complete(job); + block_job_complete(job, errp); +} + static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs) { BlockJobInfoList **prev = opaque; diff --git a/blockjob.c b/blockjob.c index 651ee8d..e5b5e63 100644 --- a/blockjob.c +++ b/blockjob.c @@ -99,6 +99,16 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) job->speed = speed; } +void block_job_complete(BlockJob *job, Error **errp) +{ + if (job->paused || job->cancelled || !job->job_type->complete) { + error_set(errp, QERR_BLOCK_JOB_NOT_READY, job->bs->device_name); + return; + } + + job->job_type->complete(job, errp); +} + void block_job_pause(BlockJob *job) { job->paused = true; diff --git a/blockjob.h b/blockjob.h index 5e03b5d..61fdafb 100644 --- a/blockjob.h +++ b/blockjob.h @@ -47,6 +47,12 @@ typedef struct BlockJobType { * of BlockJobInfo. */ void (*query)(BlockJob *job, BlockJobInfo *info); + + /** + * Optional callback for job types whose completion must be triggered + * manually. + */ + void (*complete)(BlockJob *job, Error **errp); } BlockJobType; /** @@ -170,6 +176,15 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp); void block_job_cancel(BlockJob *job); /** + * block_job_complete: + * @job: The job to be completed. + * @errp: Error object. + * + * Synchronously complete the specified job. + */ +void block_job_complete(BlockJob *job, Error **errp); + +/** * block_job_is_cancelled: * @job: The job being queried. * diff --git a/hmp-commands.hx b/hmp-commands.hx index 3c60626..7a72122 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -109,7 +109,22 @@ ETEXI STEXI @item block_job_cancel @findex block_job_cancel -Stop an active block streaming operation. +Stop an active background block operation (streaming, mirroring). +ETEXI + + { + .name = "block_job_complete", + .args_type = "device:B", + .params = "device", + .help = "stop an active background block operation", + .mhandler.cmd = hmp_block_job_complete, + }, + +STEXI +@item block_job_complete +@findex block_job_complete +Manually trigger completion of an active background block operation. +For mirroring, this will switch the device to the destination path. ETEXI { diff --git a/hmp.c b/hmp.c index 5d4e6ac..206e920 100644 --- a/hmp.c +++ b/hmp.c @@ -893,6 +893,16 @@ void hmp_block_job_resume(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &error); } +void hmp_block_job_complete(Monitor *mon, const QDict *qdict) +{ + Error *error = NULL; + const char *device = qdict_get_str(qdict, "device"); + + qmp_block_job_complete(device, &error); + + hmp_handle_error(mon, &error); +} + typedef struct MigrationStatus { QEMUTimer *timer; diff --git a/hmp.h b/hmp.h index 39a71c4..24e551e 100644 --- a/hmp.h +++ b/hmp.h @@ -61,6 +61,7 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict); void hmp_block_job_cancel(Monitor *mon, const QDict *qdict); void hmp_block_job_pause(Monitor *mon, const QDict *qdict); void hmp_block_job_resume(Monitor *mon, const QDict *qdict); +void hmp_block_job_complete(Monitor *mon, const QDict *qdict); void hmp_migrate(Monitor *mon, const QDict *qdict); void hmp_device_del(Monitor *mon, const QDict *qdict); void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict); diff --git a/qapi-schema.json b/qapi-schema.json index 2697220..e081ddf 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1792,6 +1792,33 @@ { 'command': 'block-job-resume', 'data': { 'device': 'str' } } ## +# @block-job-complete: +# +# Manually trigger completion of an active background block operation. This +# is supported for drive mirroring, where it also switches the device to +# write to the target path only. +# +# This command completes an active background block operation synchronously. +# The ordering of this command's return with the BLOCK_JOB_COMPLETED event +# is not defined. Note that if an I/O error occurs during the processing of +# this command: 1) the command itself will fail; 2) the error will be processed +# according to the rerror/werror arguments that were specified when starting +# the operation. +# +# A cancelled or paused job cannot be completed. +# +# @device: the device name +# +# Returns: Nothing on success +# If no background operation is active on this device, BlockJobNotActive +# If the operation cannot be completed manually (either in general, or +# not at the time the command is invoked), BlockJobNotReady +# +# Since: 1.2 +## +{ 'command': 'block-job-complete', 'data': { 'device': 'str' } } + +## # @ObjectTypeInfo: # # This structure describes a search result from @qom-list-types diff --git a/qerror.c b/qerror.c index 72183ec..60303a4 100644 --- a/qerror.c +++ b/qerror.c @@ -68,6 +68,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "The block job for device '%(name)' is currently paused", }, { + .error_fmt = QERR_BLOCK_JOB_NOT_READY, + .desc = "The active block job for device '%(name)' cannot be completed", + }, + { .error_fmt = QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, .desc = "Block format '%(format)' used by device '%(name)' does not support feature '%(feature)'", }, diff --git a/qerror.h b/qerror.h index d1baea0..c15e933 100644 --- a/qerror.h +++ b/qerror.h @@ -70,6 +70,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_BLOCK_JOB_PAUSED \ "{ 'class': 'BlockJobPaused', 'data': { 'name': %s } }" +#define QERR_BLOCK_JOB_NOT_READY \ + "{ 'class': 'BlockJobNotReady', 'data': { 'name': %s } }" + #define QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED \ "{ 'class': 'BlockFormatFeatureNotSupported', 'data': { 'format': %s, 'name': %s, 'feature': %s } }" diff --git a/qmp-commands.hx b/qmp-commands.hx index 7026a4a..56f953d 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -744,6 +744,11 @@ EQMP .mhandler.cmd_new = qmp_marshal_input_block_job_resume, }, { + .name = "block-job-complete", + .args_type = "device:B", + .mhandler.cmd_new = qmp_marshal_input_block_job_complete, + }, + { .name = "transaction", .args_type = "actions:q", .mhandler.cmd_new = qmp_marshal_input_transaction, diff --git a/trace-events b/trace-events index 416b723..58dfe6c 100644 --- a/trace-events +++ b/trace-events @@ -79,6 +79,7 @@ stream_start(void *bs, void *base, void *s, void *co, void *opaque) "bs %p base qmp_block_job_cancel(void *job) "job %p" qmp_block_job_pause(void *job) "job %p" qmp_block_job_resume(void *job) "job %p" +qmp_block_job_complete(void *job) "job %p" block_stream_cb(void *bs, void *job, int ret) "bs %p job %p ret %d" qmp_block_stream(void *bs, void *job) "bs %p job %p"