From patchwork Fri Aug 24 05:06:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10574819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1331112E for ; Fri, 24 Aug 2018 05:11:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 880AC2C1BC for ; Fri, 24 Aug 2018 05:11:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BD6B2C43C; Fri, 24 Aug 2018 05:11:23 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 B86912C1BC for ; Fri, 24 Aug 2018 05:11:22 +0000 (UTC) Received: from localhost ([::1]:39915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ft4NV-0003FW-77 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 24 Aug 2018 01:11:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ft4Mm-0002Ag-TQ for qemu-devel@nongnu.org; Fri, 24 Aug 2018 01:10:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ft4Mj-00034a-Mq for qemu-devel@nongnu.org; Fri, 24 Aug 2018 01:10:36 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:52671) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1ft4Mj-00033I-Ay; Fri, 24 Aug 2018 01:10:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1535087433; x=1566623433; h=from:to:cc:subject:date:message-id; bh=e/F1lgJZaHa/B/MpJpRN8lTTFpVxKN5A9RS3MFzz8I4=; b=PeXcFlyY8l+xwx2EyExO2CaPL1hx6nJHBoTvOsYsYyA+1Zr06IicYSQa NGGfRw+aWk7fmO5zSizyiZ5/b/waOL0grzwGUA2pTxyv0viK3V3ne1trV 0LaQXEQgpGXzhNmjcB3tjQRGzpVAkBWIHXYLcz5lsAx/BL5YEoFvbnO3G o=; X-IronPort-AV: E=Sophos;i="5.53,281,1531785600"; d="scan'208";a="627973700" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2b-81e76b79.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Aug 2018 05:07:29 +0000 Received: from ue4a4719f239757c4d2ec.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2b-81e76b79.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w7O56gT0038941 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 24 Aug 2018 05:06:44 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 w7O56e9I009693; Thu, 23 Aug 2018 22:06:41 -0700 Received: (from marcolso@localhost) by ue4a4719f239757c4d2ec.ant.amazon.com (8.15.2/8.15.2/Submit) id w7O56emv009690; Thu, 23 Aug 2018 22:06:40 -0700 To: Date: Thu, 23 Aug 2018 22:06:25 -0700 Message-Id: <1535087186-9643-1-git-send-email-marcolso@amazon.com> X-Mailer: git-send-email 2.7.4 Precedence: Bulk X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 207.171.184.29 Subject: [Qemu-devel] [PATCH] 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: , X-Patchwork-Original-From: Marc Olson via Qemu-devel From: "Denis V. Lunev\" via" Reply-To: Marc Olson Cc: Kevin Wolf , Marc Olson , qemu-devel@nongnu.org, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Allow rules to be created to inject latency into I/O operations. Signed-off-by: Marc Olson --- block/blkdebug.c | 101 ++++++++++++++++++++++++++++++++++++++---------- docs/devel/blkdebug.txt | 30 ++++++++++---- 2 files changed, 103 insertions(+), 28 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index e216699..762e438 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -65,6 +65,7 @@ typedef struct BlkdebugSuspendedReq { 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 = { }, }; +static QemuOptsList delay_opts = { + .name = "delay", + .head = QTAILQ_HEAD_INITIALIZER(delay_opts.head), + .desc = { + { + .name = "event", + }, + { + .name = "state", + .type = QEMU_OPT_NUMBER, + }, + { + .name = "latency", + .type = QEMU_OPT_NUMBER, + }, + { + .name = "sector", + .type = QEMU_OPT_NUMBER, + }, + { + .name = "once", + .type = QEMU_OPT_BOOL, + }, + { /* end of list */ } + }, +}; + static QemuOptsList set_state_opts = { .name = "set-state", .head = QTAILQ_HEAD_INITIALIZER(set_state_opts.head), @@ -145,6 +176,7 @@ static QemuOptsList set_state_opts = { static QemuOptsList *config_groups[] = { &inject_error_opts, + &delay_opts, &set_state_opts, NULL }; @@ -182,16 +214,21 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp) .state = qemu_opt_get_number(opts, "state", 0), }; + rule->once = qemu_opt_get_bool(opts, "once", 0); + sector = qemu_opt_get_number(opts, "sector", -1); + rule->offset = sector == -1 ? -1 : sector * BDRV_SECTOR_SIZE; + /* Parse action-specific options */ switch (d->action) { case ACTION_INJECT_ERROR: rule->options.inject.error = qemu_opt_get_number(opts, "errno", EIO); - rule->options.inject.once = qemu_opt_get_bool(opts, "once", 0); rule->options.inject.immediately = qemu_opt_get_bool(opts, "immediately", 0); - sector = qemu_opt_get_number(opts, "sector", -1); - rule->options.inject.offset = - sector == -1 ? -1 : sector * BDRV_SECTOR_SIZE; + break; + + case ACTION_DELAY: + rule->options.delay.latency = + qemu_opt_get_number(opts, "latency", 100) * SCALE_US; break; case ACTION_SET_STATE: @@ -264,6 +301,14 @@ static int read_config(BDRVBlkdebugState *s, const char *filename, goto fail; } + d.action = ACTION_DELAY; + qemu_opts_foreach(&delay_opts, add_rule, &d, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret = -EINVAL; + goto fail; + } + d.action = 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 = 0; fail: qemu_opts_reset(&inject_error_opts); + qemu_opts_reset(&delay_opts); qemu_opts_reset(&set_state_opts); if (f) { fclose(f); @@ -475,36 +521,50 @@ static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes) BlkdebugRule *rule = NULL; int error; bool immediately; + int ret = 0; QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) { - uint64_t inject_offset = rule->options.inject.offset; - - if (inject_offset == -1 || - (bytes && inject_offset >= offset && - inject_offset < offset + bytes)) + if (rule->offset == -1 || + (bytes && rule->offset >= offset && + rule->offset < offset + bytes)) { break; } } - if (!rule || !rule->options.inject.error) { + if (!rule || + (rule->action == ACTION_INJECT_ERROR && !rule->options.inject.error) || + (rule->action == ACTION_DELAY && !rule->options.delay.latency)) { return 0; } - immediately = rule->options.inject.immediately; - error = rule->options.inject.error; - - if (rule->options.inject.once) { + if (rule->once) { QSIMPLEQ_REMOVE(&s->active_rules, rule, BlkdebugRule, active_next); remove_rule(rule); } - if (!immediately) { - aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_self()); - qemu_coroutine_yield(); + switch (rule->action) { + case ACTION_INJECT_ERROR: + immediately = rule->options.inject.immediately; + error = rule->options.inject.error; + + if (!immediately) { + aio_co_schedule(qemu_get_current_aio_context(), + qemu_coroutine_self()); + qemu_coroutine_yield(); + } + + ret = -error; + break; + + case ACTION_DELAY: + if (rule->options.delay.latency) { + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, rule->options.delay.latency); + } + break; } - return -error; + return ret; } static int coroutine_fn @@ -691,6 +751,7 @@ static bool process_rule(BlockDriverState *bs, struct BlkdebugRule *rule, /* Take the action */ switch (rule->action) { case ACTION_INJECT_ERROR: + case ACTION_DELAY: if (!injected) { QSIMPLEQ_INIT(&s->active_rules); injected = 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 injection -engine when to fail an I/O request. +engine when to fail (inject-error) or add latency to (delay) an I/O request. Each I/O request is evaluated against the rules. If a rule matches the request then its "action" is executed. @@ -33,17 +33,25 @@ Rules can be placed in a configuration file; the configuration file follows the same .ini-like format used by QEMU's -readconfig option, and each section of the file represents a rule. -The following configuration file defines a single rule: +The following configuration file defines multiple rules: $ cat blkdebug.conf [inject-error] event = "read_aio" errno = "28" -This rule fails all aio read requests with ENOSPC (28). Note that the errno -value depends on the host. On Linux, see + [delay] + event = "read_aio" + sector = "2048" + latency = "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. +The delay rule adds 500 ms of latency to a read I/O request containing sector +2048. + Invoke QEMU as follows: $ qemu-system-x86_64 @@ -60,21 +68,27 @@ Rules support the following attributes: rule to match. See the "State transitions" section for information on states. - errno - the numeric errno value to return when a request matches this rule. - 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 order to match this rule once - (optional, default "off") only execute this action on the first matching request +Error injection rules support the following attributes: + + errno - the numeric errno value to return when a request matches this rule. + 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. +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 about