From patchwork Mon Apr 4 13:43:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 8741221 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 428A5C0553 for ; Mon, 4 Apr 2016 13:51:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B93420263 for ; Mon, 4 Apr 2016 13:51:25 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id C741E20166 for ; Mon, 4 Apr 2016 13:51:21 +0000 (UTC) Received: from localhost ([::1]:58792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4uX-0003tc-AI for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Apr 2016 09:51:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4oi-00021Z-K3 for qemu-devel@nongnu.org; Mon, 04 Apr 2016 09:45:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1an4og-0000BH-Lm for qemu-devel@nongnu.org; Mon, 04 Apr 2016 09:45:20 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:65131 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1an4og-0000AC-Ap; Mon, 04 Apr 2016 09:45:18 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CRAwCybgJX/5tjdVtdHAGDGoFQpxUBAQEBAQUBgREBkGaCDwENgXKGDQKBMzgUAQEBAQEBAWUnhEIBAQQnUhA/EjwbGYgrAb0HAQEBByCFWIJFjGIFh2UKhV5wQokCjgiBaIdSI4UyjxoeAQFCggEDGYFNaYZpBIE5AQEB X-IPAS-Result: A2CRAwCybgJX/5tjdVtdHAGDGoFQpxUBAQEBAQUBgREBkGaCDwENgXKGDQKBMzgUAQEBAQEBAWUnhEIBAQQnUhA/EjwbGYgrAb0HAQEBByCFWIJFjGIFh2UKhV5wQokCjgiBaIdSI4UyjxoeAQFCggEDGYFNaYZpBIE5AQEB X-IronPort-AV: E=Sophos;i="5.24,440,1454972400"; d="scan'208";a="39334343" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 04 Apr 2016 15:44:37 +0200 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1an4o1-00050w-4t; Mon, 04 Apr 2016 15:44:37 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1an4nj-0003vO-2H; Mon, 04 Apr 2016 16:44:19 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 4 Apr 2016 16:43:55 +0300 Message-Id: X-Mailer: git-send-email 2.8.0.rc3 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 Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v9 05/11] block: allow block jobs in any arbitrary node 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, block jobs can only be owned by root nodes. This patch allows block jobs to be in any arbitrary node, by making the following changes: - Block jobs can now be identified by the node name of their BlockDriverState in addition to the device name. Since both device and node names live in the same namespace there's no ambiguity. - The "device" parameter used by all commands that operate on block jobs can also be a node name now. - The node name is used as a fallback to fill in the BlockJobInfo structure and all BLOCK_JOB_* events if there is no device name for that job. Signed-off-by: Alberto Garcia --- blockdev.c | 18 ++++++++++-------- blockjob.c | 5 +++-- docs/qmp-events.txt | 8 ++++---- qapi/block-core.json | 20 ++++++++++---------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/blockdev.c b/blockdev.c index edbcc19..d1f5dfb 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3685,8 +3685,10 @@ void qmp_blockdev_mirror(const char *device, const char *target, aio_context_release(aio_context); } -/* Get the block job for a given device name and acquire its AioContext */ -static BlockJob *find_block_job(const char *device, AioContext **aio_context, +/* Get the block job for a given device or node name + * and acquire its AioContext */ +static BlockJob *find_block_job(const char *device_or_node, + AioContext **aio_context, Error **errp) { BlockBackend *blk; @@ -3694,18 +3696,18 @@ static BlockJob *find_block_job(const char *device, AioContext **aio_context, *aio_context = NULL; - blk = blk_by_name(device); - if (!blk) { + bs = bdrv_lookup_bs(device_or_node, device_or_node, errp); + if (!bs) { goto notfound; } - *aio_context = blk_get_aio_context(blk); + *aio_context = bdrv_get_aio_context(bs); aio_context_acquire(*aio_context); - if (!blk_is_available(blk)) { + blk = blk_by_name(device_or_node); + if (blk && !blk_is_available(blk)) { goto notfound; } - bs = blk_bs(blk); if (!bs->job) { goto notfound; @@ -3715,7 +3717,7 @@ static BlockJob *find_block_job(const char *device, AioContext **aio_context, notfound: error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE, - "No active block job on device '%s'", device); + "No active block job on node '%s'", device_or_node); if (*aio_context) { aio_context_release(*aio_context); *aio_context = NULL; diff --git a/blockjob.c b/blockjob.c index 3557048..2ab4794 100644 --- a/blockjob.c +++ b/blockjob.c @@ -67,7 +67,8 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, BlockJob *job; if (bs->job) { - error_setg(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs)); + error_setg(errp, "Node '%s' is in use", + bdrv_get_device_or_node_name(bs)); return NULL; } bdrv_ref(bs); @@ -78,7 +79,7 @@ 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->id = g_strdup(bdrv_get_device_or_node_name(bs)); job->bs = bs; job->cb = cb; job->opaque = opaque; diff --git a/docs/qmp-events.txt b/docs/qmp-events.txt index fa7574d..2d238c5 100644 --- a/docs/qmp-events.txt +++ b/docs/qmp-events.txt @@ -92,7 +92,7 @@ Data: - "type": Job type (json-string; "stream" for image streaming "commit" for block commit) -- "device": Device name (json-string) +- "device": Device name, or node name if not present (json-string) - "len": Maximum progress value (json-int) - "offset": Current progress value (json-int) On success this is equal to len. @@ -116,7 +116,7 @@ Data: - "type": Job type (json-string; "stream" for image streaming "commit" for block commit) -- "device": Device name (json-string) +- "device": Device name, or node name if not present (json-string) - "len": Maximum progress value (json-int) - "offset": Current progress value (json-int) On success this is equal to len. @@ -143,7 +143,7 @@ Emitted when a block job encounters an error. Data: -- "device": device name (json-string) +- "device": device name, or node name if not present (json-string) - "operation": I/O operation (json-string, "read" or "write") - "action": action that has been taken, it's one of the following (json-string): "ignore": error has been ignored, the job may fail later @@ -167,7 +167,7 @@ Data: - "type": Job type (json-string; "stream" for image streaming "commit" for block commit) -- "device": Device name (json-string) +- "device": Device name, or node name if not present (json-string) - "len": Maximum progress value (json-int) - "offset": Current progress value (json-int) On success this is equal to len. diff --git a/qapi/block-core.json b/qapi/block-core.json index 1d09079..59107ed 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -713,7 +713,7 @@ # # @type: the job type ('stream' for image streaming) # -# @device: the block device name +# @device: the block device name, or node name if not present # # @len: the maximum progress value # @@ -1456,7 +1456,7 @@ # # Throttling can be disabled by setting the speed to 0. # -# @device: the device name +# @device: the device or node name of the owner of the block job. # # @speed: the maximum speed, in bytes per second, or 0 for unlimited. # Defaults to 0. @@ -1487,7 +1487,7 @@ # operation can be started at a later time to finish copying all data from the # backing file. # -# @device: the device name +# @device: the device or node name of the owner of the block job. # # @force: #optional whether to allow cancellation of a paused job (default # false). Since 1.3. @@ -1513,7 +1513,7 @@ # the operation is actually paused. Cancelling a paused job automatically # resumes it. # -# @device: the device name +# @device: the device or node name of the owner of the block job. # # Returns: Nothing on success # If no background operation is active on this device, DeviceNotActive @@ -1533,7 +1533,7 @@ # # This command also clears the error status of the job. # -# @device: the device name +# @device: the device or node name of the owner of the block job. # # Returns: Nothing on success # If no background operation is active on this device, DeviceNotActive @@ -1559,7 +1559,7 @@ # # A cancelled or paused job cannot be completed. # -# @device: the device name +# @device: the device or node name of the owner of the block job. # # Returns: Nothing on success # If no background operation is active on this device, DeviceNotActive @@ -2404,7 +2404,7 @@ # # @type: job type # -# @device: device name +# @device: device name, or node name if not present # # @len: maximum progress value # @@ -2435,7 +2435,7 @@ # # @type: job type # -# @device: device name +# @device: device name, or node name if not present # # @len: maximum progress value # @@ -2458,7 +2458,7 @@ # # Emitted when a block job encounters an error # -# @device: device name +# @device: device name, or node name if not present # # @operation: I/O operation # @@ -2478,7 +2478,7 @@ # # @type: job type # -# @device: device name +# @device: device name, or node name if not present # # @len: maximum progress value #