From patchwork Wed Jun 22 12:24:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9192711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0400C601C0 for ; Wed, 22 Jun 2016 12:53:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E79EE283E9 for ; Wed, 22 Jun 2016 12:53:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC42728402; Wed, 22 Jun 2016 12:53:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 264B0283E9 for ; Wed, 22 Jun 2016 12:53:29 +0000 (UTC) Received: from localhost ([::1]:58039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFheq-0005wd-8J for patchwork-qemu-devel@patchwork.kernel.org; Wed, 22 Jun 2016 08:53:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFhEG-0003aQ-AU for qemu-devel@nongnu.org; Wed, 22 Jun 2016 08:26:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFhE9-0001wy-A7 for qemu-devel@nongnu.org; Wed, 22 Jun 2016 08:26:00 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:10832 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFhE8-0001w7-PS; Wed, 22 Jun 2016 08:25:53 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CkAgCmgmpX/5tjdVteHQGDIIFTjSqYLgEBAQEBAQUBgQ8BkTGCD4F6hhcCgSw4FAEBAQEBAQFlJ4RNAgQnUhA/EjwbGYg0AcMKAQEBByeFX4JHjGkFiAaFcnBCiVOOLYlGhV2PfB42gggcF4E4a4ktBIFAAQEB X-IPAS-Result: A2CkAgCmgmpX/5tjdVteHQGDIIFTjSqYLgEBAQEBAQUBgQ8BkTGCD4F6hhcCgSw4FAEBAQEBAQFlJ4RNAgQnUhA/EjwbGYg0AcMKAQEBByeFX4JHjGkFiAaFcnBCiVOOLYlGhV2PfB42gggcF4E4a4ktBIFAAQEB X-IronPort-AV: E=Sophos;i="5.26,509,1459807200"; d="scan'208";a="76201808" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 22 Jun 2016 14:25:48 +0200 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim) id 1bFhE4-0004kT-4h; Wed, 22 Jun 2016 14:25:48 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bFhDo-0007FG-CK; Wed, 22 Jun 2016 15:25:32 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Wed, 22 Jun 2016 15:24:59 +0300 Message-Id: <6034f1747fb838368a057df8463084b6a2326fe4.1466598035.git.berto@igalia.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.51.32.191 Subject: [Qemu-devel] [PATCH v2 02/15] blockjob: Decouple the ID from the device name in the BlockJob struct X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Jeff Cody , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Block jobs are identified by the name of the BlockBackend of the BDS where the job was started. We want block jobs to have unique, arbitrary identifiers that are not tied to a block device, so this patch decouples the ID from the device name in the BlockJob structure. The ID is generated automatically for the moment, in later patches we'll allow the user to set it. Signed-off-by: Alberto Garcia --- block/mirror.c | 3 ++- blockjob.c | 18 +++++++++++------- include/block/blockjob.h | 12 ++++++++---- include/qapi/qmp/qerror.h | 3 --- include/qemu/id.h | 1 + util/id.c | 1 + 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index a04ed9c..bcb1999 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -755,7 +755,8 @@ static void mirror_complete(BlockJob *job, Error **errp) target = blk_bs(s->target); if (!s->synced) { - error_setg(errp, QERR_BLOCK_JOB_NOT_READY, job->id); + error_setg(errp, "The active block job '%s' cannot be completed", + job->id); return; } diff --git a/blockjob.c b/blockjob.c index 90c4e26..8bcb5ea 100644 --- a/blockjob.c +++ b/blockjob.c @@ -33,6 +33,7 @@ #include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" #include "qemu/coroutine.h" +#include "qemu/id.h" #include "qmp-commands.h" #include "qemu/timer.h" #include "qapi-event.h" @@ -125,7 +126,8 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); job->driver = driver; - job->id = g_strdup(bdrv_get_device_name(bs)); + job->device = g_strdup(bdrv_get_device_name(bs)); + job->id = id_generate(ID_JOB); job->blk = blk; job->cb = cb; job->opaque = opaque; @@ -168,6 +170,7 @@ void block_job_unref(BlockJob *job) block_job_detach_aio_context, job); blk_unref(job->blk); error_free(job->blocker); + g_free(job->device); g_free(job->id); QLIST_REMOVE(job, job_list); g_free(job); @@ -289,7 +292,8 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) void block_job_complete(BlockJob *job, Error **errp) { if (job->pause_count || job->cancelled || !job->driver->complete) { - error_setg(errp, QERR_BLOCK_JOB_NOT_READY, job->id); + error_setg(errp, "The active block job '%s' cannot be completed", + job->id); return; } @@ -464,7 +468,7 @@ BlockJobInfo *block_job_query(BlockJob *job) { BlockJobInfo *info = g_new0(BlockJobInfo, 1); info->type = g_strdup(BlockJobType_lookup[job->driver->job_type]); - info->device = g_strdup(job->id); + info->device = g_strdup(job->device); info->len = job->len; info->busy = job->busy; info->paused = job->pause_count > 0; @@ -486,7 +490,7 @@ static void block_job_iostatus_set_err(BlockJob *job, int error) void block_job_event_cancelled(BlockJob *job) { qapi_event_send_block_job_cancelled(job->driver->job_type, - job->id, + job->device, job->len, job->offset, job->speed, @@ -496,7 +500,7 @@ void block_job_event_cancelled(BlockJob *job) void block_job_event_completed(BlockJob *job, const char *msg) { qapi_event_send_block_job_completed(job->driver->job_type, - job->id, + job->device, job->len, job->offset, job->speed, @@ -510,7 +514,7 @@ void block_job_event_ready(BlockJob *job) job->ready = true; qapi_event_send_block_job_ready(job->driver->job_type, - job->id, + job->device, job->len, job->offset, job->speed, &error_abort); @@ -538,7 +542,7 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, default: abort(); } - qapi_event_send_block_job_error(job->id, + qapi_event_send_block_job_error(job->device, is_read ? IO_OPERATION_TYPE_READ : IO_OPERATION_TYPE_WRITE, action, &error_abort); diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 7dc720c..856486a 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -106,14 +106,18 @@ struct BlockJob { BlockBackend *blk; /** - * The ID of the block job. Currently the BlockBackend name of the BDS - * owning the job at the time when the job is started. - * - * TODO Decouple block job IDs from BlockBackend names + * The ID of the block job. */ char *id; /** + * BlockBackend name of the BDS owning the job at the time when + * the job is started. For compatibility with clients that don't + * support the ID field. + */ + char *device; + + /** * The coroutine that executes the job. If not NULL, it is * reentered when busy is false and the job is cancelled. */ diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h index d08652a..6586c9f 100644 --- a/include/qapi/qmp/qerror.h +++ b/include/qapi/qmp/qerror.h @@ -19,9 +19,6 @@ #define QERR_BASE_NOT_FOUND \ "Base '%s' not found" -#define QERR_BLOCK_JOB_NOT_READY \ - "The active block job for device '%s' cannot be completed" - #define QERR_BUS_NO_HOTPLUG \ "Bus '%s' does not support hotplugging" diff --git a/include/qemu/id.h b/include/qemu/id.h index 7d90335..c6c73ca 100644 --- a/include/qemu/id.h +++ b/include/qemu/id.h @@ -4,6 +4,7 @@ typedef enum IdSubSystems { ID_QDEV, ID_BLOCK, + ID_JOB, ID_MAX /* last element, used as array size */ } IdSubSystems; diff --git a/util/id.c b/util/id.c index 6141352..eb5478b 100644 --- a/util/id.c +++ b/util/id.c @@ -34,6 +34,7 @@ bool id_wellformed(const char *id) static const char *const id_subsys_str[ID_MAX] = { [ID_QDEV] = "qdev", [ID_BLOCK] = "block", + [ID_JOB] = "job", }; /*