From nobody Wed Nov 5 12:54:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@amazon.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536107529143482.99622264584264; Tue, 4 Sep 2018 17:32:09 -0700 (PDT) Received: from localhost ([::1]:53172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxLjm-0002lB-Fj for importer@patchew.org; Tue, 04 Sep 2018 20:32:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxLio-0002SV-Tp for qemu-devel@nongnu.org; Tue, 04 Sep 2018 20:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxLik-0001Au-CT for qemu-devel@nongnu.org; Tue, 04 Sep 2018 20:31:02 -0400 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:63992) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxLib-0000Qi-D8; Tue, 04 Sep 2018 20:30:49 -0400 Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1a-807d4a99.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 05 Sep 2018 00:25:56 +0000 Received: from ue4a4719f239757c4d2ec.ant.amazon.com (iad7-ws-svc-lb50-vlan2.amazon.com [10.0.93.210]) by email-inbound-relay-1a-807d4a99.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w850P78i030768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 5 Sep 2018 00:25:07 GMT Received: from ue4a4719f239757c4d2ec.ant.amazon.com (localhost [127.0.0.1]) by ue4a4719f239757c4d2ec.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w850P7wL009904; Tue, 4 Sep 2018 17:25:07 -0700 Received: (from marcolso@localhost) by ue4a4719f239757c4d2ec.ant.amazon.com (8.15.2/8.15.2/Submit) id w850P68Z009903; Tue, 4 Sep 2018 17:25:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1536107449; x=1567643449; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=OFtlJfF1jhdU9ncooQXHw1RRA27U8mGdMeQdJOyH528=; b=NDZ54WfeA1sogyRAQ1KNQ4YFtJ3PPCw/RozDQsNYdW6AyCbJuN3MQVwU 3TzwKl14MTL6mjz18+gc/Yxw9PwfbIfuJVx1hnVbASgoVHRfHb7cAzv8C l1SXWCNKd1d6RdHmhtsZA6VmY4QMGYox8SMbMg9+YXzDzT9apJ1i9QHYy o=; X-IronPort-AV: E=Sophos;i="5.53,331,1531785600"; d="scan'208";a="756964520" To: qemu-devel@nongnu.org Date: Tue, 4 Sep 2018 17:24:49 -0700 Message-Id: <1536107089-9829-1-git-send-email-marcolso@amazon.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535087186-9643-1-git-send-email-marcolso@amazon.com> References: <1535087186-9643-1-git-send-email-marcolso@amazon.com> Precedence: Bulk X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 207.171.184.25 Subject: [Qemu-devel] [PATCH v2] blkdebug: Add support for latency rules X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Marc Olson via Qemu-devel Reply-To: Marc Olson Cc: Kevin Wolf , qemu-block@nongnu.org, Marc Olson , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sometimes storage devices can be slow to respond, due to media errors, firm= ware issues, SSD garbage collection, etc. This patch adds a new rule type to blkdebug that allows injection of latency to I/O operations. Similar to err= or injection rules, latency rules can be specified with or without an offset, = and can also apply upon state transitions. Signed-off-by: Marc Olson --- v2: - Change so that delay rules are executed before error rules - Add QMP support - Add tests --- block/blkdebug.c | 119 +++++++++++++++++++++++++++++++++++------= ---- docs/devel/blkdebug.txt | 30 +++++++++--- qapi/block-core.json | 39 +++++++++++++-- tests/qemu-iotests/071 | 63 ++++++++++++++++++++++++ tests/qemu-iotests/071.out | 31 ++++++++++++ 5 files changed, 244 insertions(+), 38 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 0759452..1785fe3 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -65,6 +65,7 @@ typedef struct BlkdebugSuspendedReq { =20 enum { ACTION_INJECT_ERROR, + ACTION_DELAY, ACTION_SET_STATE, ACTION_SUSPEND, }; @@ -73,14 +74,17 @@ typedef struct BlkdebugRule { BlkdebugEvent event; int action; int state; + int once; + int64_t offset; union { struct { int error; int immediately; - int once; - int64_t offset; } inject; struct { + int64_t latency; + } delay; + struct { int new_state; } set_state; struct { @@ -123,6 +127,33 @@ static QemuOptsList inject_error_opts =3D { }, }; =20 +static QemuOptsList delay_opts =3D { + .name =3D "delay", + .head =3D QTAILQ_HEAD_INITIALIZER(delay_opts.head), + .desc =3D { + { + .name =3D "event", + }, + { + .name =3D "state", + .type =3D QEMU_OPT_NUMBER, + }, + { + .name =3D "latency", + .type =3D QEMU_OPT_NUMBER, + }, + { + .name =3D "sector", + .type =3D QEMU_OPT_NUMBER, + }, + { + .name =3D "once", + .type =3D QEMU_OPT_BOOL, + }, + { /* end of list */ } + }, +}; + static QemuOptsList set_state_opts =3D { .name =3D "set-state", .head =3D QTAILQ_HEAD_INITIALIZER(set_state_opts.head), @@ -145,6 +176,7 @@ static QemuOptsList set_state_opts =3D { =20 static QemuOptsList *config_groups[] =3D { &inject_error_opts, + &delay_opts, &set_state_opts, NULL }; @@ -182,16 +214,21 @@ static int add_rule(void *opaque, QemuOpts *opts, Err= or **errp) .state =3D qemu_opt_get_number(opts, "state", 0), }; =20 + rule->once =3D qemu_opt_get_bool(opts, "once", 0); + sector =3D qemu_opt_get_number(opts, "sector", -1); + rule->offset =3D sector =3D=3D -1 ? -1 : sector * BDRV_SECTOR_SIZE; + /* Parse action-specific options */ switch (d->action) { case ACTION_INJECT_ERROR: rule->options.inject.error =3D qemu_opt_get_number(opts, "errno", = EIO); - rule->options.inject.once =3D qemu_opt_get_bool(opts, "once", 0); rule->options.inject.immediately =3D qemu_opt_get_bool(opts, "immediately", 0); - sector =3D qemu_opt_get_number(opts, "sector", -1); - rule->options.inject.offset =3D - sector =3D=3D -1 ? -1 : sector * BDRV_SECTOR_SIZE; + break; + + case ACTION_DELAY: + rule->options.delay.latency =3D + qemu_opt_get_number(opts, "latency", 100) * SCALE_US; break; =20 case ACTION_SET_STATE: @@ -264,6 +301,14 @@ static int read_config(BDRVBlkdebugState *s, const cha= r *filename, goto fail; } =20 + d.action =3D ACTION_DELAY; + qemu_opts_foreach(&delay_opts, add_rule, &d, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto fail; + } + d.action =3D ACTION_SET_STATE; qemu_opts_foreach(&set_state_opts, add_rule, &d, &local_err); if (local_err) { @@ -275,6 +320,7 @@ static int read_config(BDRVBlkdebugState *s, const char= *filename, ret =3D 0; fail: qemu_opts_reset(&inject_error_opts); + qemu_opts_reset(&delay_opts); qemu_opts_reset(&set_state_opts); if (f) { fclose(f); @@ -473,39 +519,61 @@ out: static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t byte= s) { BDRVBlkdebugState *s =3D bs->opaque; - BlkdebugRule *rule =3D NULL; + BlkdebugRule *rule =3D NULL, *delay_rule =3D NULL, *error_rule =3D NUL= L; + int64_t latency; int error; bool immediately; + int ret =3D 0; =20 QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) { - uint64_t inject_offset =3D rule->options.inject.offset; - - if (inject_offset =3D=3D -1 || - (bytes && inject_offset >=3D offset && - inject_offset < offset + bytes)) + if (rule->offset =3D=3D -1 || + (bytes && rule->offset >=3D offset && + rule->offset < offset + bytes)) { - break; + if (!error_rule && rule->action =3D=3D ACTION_INJECT_ERROR) { + error_rule =3D rule; + } else if (!delay_rule && rule->action =3D=3D ACTION_DELAY) { + delay_rule =3D rule; + } + + if (error_rule && delay_rule) { + break; + } } } =20 - if (!rule || !rule->options.inject.error) { - return 0; - } + if (delay_rule) { + latency =3D delay_rule->options.delay.latency; =20 - immediately =3D rule->options.inject.immediately; - error =3D rule->options.inject.error; + if (delay_rule->once) { + QSIMPLEQ_REMOVE(&s->active_rules, delay_rule, BlkdebugRule, ac= tive_next); + remove_rule(delay_rule); + } =20 - if (rule->options.inject.once) { - QSIMPLEQ_REMOVE(&s->active_rules, rule, BlkdebugRule, active_next); - remove_rule(rule); + if (latency !=3D 0) { + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, latency); + } } =20 - if (!immediately) { - aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_sel= f()); - qemu_coroutine_yield(); + if (error_rule) { + error =3D error_rule->options.inject.error; + immediately =3D error_rule->options.inject.immediately; + + if (error_rule->once) { + QSIMPLEQ_REMOVE(&s->active_rules, error_rule, BlkdebugRule, ac= tive_next); + remove_rule(error_rule); + } + + if (error && !immediately) { + aio_co_schedule(qemu_get_current_aio_context(), + qemu_coroutine_self()); + qemu_coroutine_yield(); + } + + ret =3D -error; } =20 - return -error; + return ret; } =20 static int coroutine_fn @@ -694,6 +762,7 @@ static bool process_rule(BlockDriverState *bs, struct B= lkdebugRule *rule, /* Take the action */ switch (rule->action) { case ACTION_INJECT_ERROR: + case ACTION_DELAY: if (!injected) { QSIMPLEQ_INIT(&s->active_rules); injected =3D true; diff --git a/docs/devel/blkdebug.txt b/docs/devel/blkdebug.txt index 43d8e8f..1befcf8 100644 --- a/docs/devel/blkdebug.txt +++ b/docs/devel/blkdebug.txt @@ -24,7 +24,7 @@ This way, all error paths can be tested to make sure they= are correct. Rules ----- The blkdebug block driver takes a list of "rules" that tell the error inje= ction -engine when to fail an I/O request. +engine when to fail (inject-error) or add latency to (delay) an I/O reques= t. =20 Each I/O request is evaluated against the rules. If a rule matches the re= quest then its "action" is executed. @@ -33,17 +33,25 @@ Rules can be placed in a configuration file; the config= uration file follows the same .ini-like format used by QEMU's -readconfig option, and each section of the file represents a rule. =20 -The following configuration file defines a single rule: +The following configuration file defines multiple rules: =20 $ cat blkdebug.conf [inject-error] event =3D "read_aio" errno =3D "28" =20 -This rule fails all aio read requests with ENOSPC (28). Note that the err= no -value depends on the host. On Linux, see + [delay] + event =3D "read_aio" + sector =3D "2048" + latency =3D "500000" + +The error rule fails all aio read requests with ENOSPC (28). Note that the +errno value depends on the host. On Linux, see /usr/include/asm-generic/errno-base.h for errno values. =20 +The delay rule adds 500 ms of latency to a read I/O request containing sec= tor +2048. + Invoke QEMU as follows: =20 $ qemu-system-x86_64 @@ -60,21 +68,27 @@ Rules support the following attributes: rule to match. See the "State transitions" section for informat= ion on states. =20 - errno - the numeric errno value to return when a request matches this ru= le. - The errno values depend on the host since the numeric values are= not - standarized in the POSIX specification. - sector - (optional) a sector number that the request must overlap in ord= er to match this rule =20 once - (optional, default "off") only execute this action on the first matching request =20 +Error injection rules support the following attributes: + + errno - the numeric errno value to return when a request matches this ru= le. + The errno values depend on the host since the numeric values are= not + standarized in the POSIX specification. + immediately - (optional, default "off") return a NULL BlockAIOCB pointer and fail without an errno instead. This exercises the code path where BlockAIOCB fails and the caller's BlockCompletionFunc is not invoked. =20 +Delay rules support the following attribute: + + latency - the delay to add to an I/O request, in microseconds. + Events ------ Block drivers provide information about the type of I/O request they are a= bout diff --git a/qapi/block-core.json b/qapi/block-core.json index 4c7a37a..819e3f9 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2941,11 +2941,11 @@ 'refblock_alloc_write_blocks', 'refblock_alloc_write_table', 'refblock_alloc_switch_table', 'cluster_alloc', 'cluster_alloc_bytes', 'cluster_free', 'flush_to_os', - 'flush_to_disk', 'pwritev_rmw_head', 'pwritev_rmw_after_head', - 'pwritev_rmw_tail', 'pwritev_rmw_after_tail', 'pwritev', - 'pwritev_zero', 'pwritev_done', 'empty_image_prepare', - 'l1_shrink_write_table', 'l1_shrink_free_l2_clusters', - 'cor_write'] } + 'flush_to_disk', 'preadv', 'pwritev_rmw_head', + 'pwritev_rmw_after_head', 'pwritev_rmw_tail', + 'pwritev_rmw_after_tail', 'pwritev', 'pwritev_zero', 'pwritev_= done', + 'empty_image_prepare', 'l1_shrink_write_table', + 'l1_shrink_free_l2_clusters', 'cor_write'] } =20 ## # @BlkdebugInjectErrorOptions: @@ -2980,6 +2980,34 @@ '*immediately': 'bool' } } =20 ## +# @BlkdebugDelayOptions: +# +# Describes a single latency injection for blkdebug. +# +# @event: trigger event +# +# @state: the state identifier blkdebug needs to be in to +# actually trigger the event; defaults to "any" +# +# @latency: The delay to add to an I/O, in microseconds. +# +# @sector: specifies the sector index which has to be affected +# in order to actually trigger the event; defaults to "any +# sector" +# +# @once: disables further events after this one has been +# triggered; defaults to false +# +# Since: 3.0 +## +{ 'struct': 'BlkdebugDelayOptions', + 'data': { 'event': 'BlkdebugEvent', + '*state': 'int', + '*latency': 'int', + '*sector': 'int', + '*once': 'bool' } } + +## # @BlkdebugSetStateOptions: # # Describes a single state-change event for blkdebug. @@ -3049,6 +3077,7 @@ '*opt-write-zero': 'int32', '*max-write-zero': 'int32', '*opt-discard': 'int32', '*max-discard': 'int32', '*inject-error': ['BlkdebugInjectErrorOptions'], + '*delay': ['BlkdebugDelayOptions'], '*set-state': ['BlkdebugSetStateOptions'] } } =20 ## diff --git a/tests/qemu-iotests/071 b/tests/qemu-iotests/071 index 48b4955..3d0610c 100755 --- a/tests/qemu-iotests/071 +++ b/tests/qemu-iotests/071 @@ -100,6 +100,69 @@ $QEMU_IO -c "open -o driver=3D$IMGFMT,file.driver=3Dbl= kdebug,file.inject-error.event -c 'read -P 42 0x38000 512' =20 echo +echo "=3D=3D=3D Testing blkdebug latency through filename =3D=3D=3D" +echo + +$QEMU_IO -c "open -o file.driver=3Dblkdebug,file.delay.event=3Dwrite_aio,f= ile.delay.latency=3D10000 $TEST_IMG" \ + -c 'aio_write -P 42 0x28000 512' \ + -c 'aio_read -P 42 0x38000 512' \ + | _filter_qemu_io + +echo +echo "=3D=3D=3D Testing blkdebug latency through file blockref =3D=3D=3D" +echo + +$QEMU_IO -c "open -o driver=3D$IMGFMT,file.driver=3Dblkdebug,file.delay.ev= ent=3Dwrite_aio,file.delay.latency=3D10000,file.image.filename=3D$TEST_IMG"= \ + -c 'aio_write -P 42 0x28000 512' \ + -c 'aio_read -P 42 0x38000 512' \ + | _filter_qemu_io + +# Using QMP is synchronous by default, so even though we would +# expect reordering due to using the aio_* commands, they are +# not. The purpose of this test is to verify that the driver +# can be setup via QMP, and IO can complete. See the qemu-io +# test above to prove delay functionality +echo +echo "=3D=3D=3D Testing blkdebug on existing block device =3D=3D=3D" +echo + +run_qemu <