From patchwork Tue Jul 5 15:50:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 644943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rkWSb50jpz9sBg for ; Wed, 6 Jul 2016 03:43:11 +1000 (AEST) Received: from localhost ([::1]:56683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKUNI-0000oR-E4 for incoming@patchwork.ozlabs.org; Tue, 05 Jul 2016 13:43:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKSdB-0000oe-8P for qemu-devel@nongnu.org; Tue, 05 Jul 2016 11:51:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKSd9-0006WR-4J for qemu-devel@nongnu.org; Tue, 05 Jul 2016 11:51:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42569) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKSd6-0006UM-Ae; Tue, 05 Jul 2016 11:51:20 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D354A3F724; Tue, 5 Jul 2016 15:51:19 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u65Fp6fL006758; Tue, 5 Jul 2016 11:51:18 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 5 Jul 2016 17:50:19 +0200 Message-Id: <1467733852-27097-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1467733852-27097-1-git-send-email-kwolf@redhat.com> References: <1467733852-27097-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 05 Jul 2016 15:51:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/43] blkdebug: Set request_alignment during .bdrv_refresh_limits() 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Blake We want to eventually stick request_alignment alongside other BlockLimits, but first, we must ensure it is populated at the same time as all other limits, rather than being a special case that is set only when a block is first opened. Note that when the user does not provide "align", then we were defaulting to bs->request_alignment - but at this stage in the initialization, that was always 512. We were also rejecting an explicit "align":0 from the user; this patch now allows that, as an explicit request for the default alignment (which may not always be 512 in the future). qemu-iotests 77 is particularly sensitive to the fact that we can specify an artificial alignment override in blkdebug, and that override must continue to work even when limits are refreshed on an already open device. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/blkdebug.c | 19 +++++++++++++++---- qapi/block-core.json | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 20d25bd..54b6870 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -37,6 +37,7 @@ typedef struct BDRVBlkdebugState { int state; int new_state; + int align; QLIST_HEAD(, BlkdebugRule) rules[BLKDBG__MAX]; QSIMPLEQ_HEAD(, BlkdebugRule) active_rules; @@ -382,10 +383,10 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, } /* Set request alignment */ - align = qemu_opt_get_size(opts, "align", bs->request_alignment); - if (align > 0 && align < INT_MAX && !(align & (align - 1))) { - bs->request_alignment = align; - } else { + align = qemu_opt_get_size(opts, "align", 0); + if (align < INT_MAX && is_power_of_2(align)) { + s->align = align; + } else if (align) { error_setg(errp, "Invalid alignment"); ret = -EINVAL; goto fail_unref; @@ -720,6 +721,15 @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) bs->full_open_options = opts; } +static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp) +{ + BDRVBlkdebugState *s = bs->opaque; + + if (s->align) { + bs->request_alignment = s->align; + } +} + static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp) { @@ -738,6 +748,7 @@ static BlockDriver bdrv_blkdebug = { .bdrv_getlength = blkdebug_getlength, .bdrv_truncate = blkdebug_truncate, .bdrv_refresh_filename = blkdebug_refresh_filename, + .bdrv_refresh_limits = blkdebug_refresh_limits, .bdrv_aio_readv = blkdebug_aio_readv, .bdrv_aio_writev = blkdebug_aio_writev, diff --git a/qapi/block-core.json b/qapi/block-core.json index 98a20d2..ac8f5f6 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1961,7 +1961,8 @@ # # @config: #optional filename of the configuration file # -# @align: #optional required alignment for requests in bytes +# @align: #optional required alignment for requests in bytes, +# must be power of 2, or 0 for default # # @inject-error: #optional array of error injection descriptions #