From patchwork Thu Apr 27 17:23:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1774574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=GydNz2e2; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q6jKr13Dbz23s0 for ; Fri, 28 Apr 2023 03:25:04 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5M4-000062-RO; Thu, 27 Apr 2023 13:24:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5M2-0008Om-OR; Thu, 27 Apr 2023 13:24:26 -0400 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5Lz-0007qM-7y; Thu, 27 Apr 2023 13:24:26 -0400 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-b9a805fd0dcso1145413276.1; Thu, 27 Apr 2023 10:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616260; x=1685208260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KDeNqO7F4FiGzd0ELVM+fuyUs22M96ueXedU39c3dZc=; b=GydNz2e2jE86YduhEDl6jiQ+nM2oFVq85S9SRUjfqQbt3CWhS4Wk/XTG7xtQaUoYAz gT0ql59UqGTF9WBKEyFKzKLjyFClLuiCDtb6mPcIKSDyZTIzUDxrmxiIalwpeUGA19eg WMUQy2eOboi7JT1GIx/hXAUR5CPWG49qlW/SDvtsyOc83It2ke5HWDRZquU2jZ3vk+np fZ+fsdRYW3XcXRuFZbVhr4x2tsjOY/7fKWZcZvt1kFr1t1y22Vfl1d9+c+9njjxWD34N kAmwqi1DhdvqdQPOdhj8ZsdGDR3VYjSCVFQPn7ZrjmtJJh8BY1ePhYyhWX8YU0DKCjKQ TKdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616260; x=1685208260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KDeNqO7F4FiGzd0ELVM+fuyUs22M96ueXedU39c3dZc=; b=V57MCJon9cSsKGLNaufYnQqdlccvk8FRMplWAI617wN56GlwpSnqWHOmPAlwFnCOfU 8oUqay0AwCGHeAJBa1K0PXUartABdsuKX/isYAibb4OKvbmedFA9XZylk520cxI9Yfcy kEby0+cTtKXXzEmIQmW3BmxlZSsXh8k0y4pW1Q+1p1hcivUZOmPbCFRKiqDWd26fq9TZ ZhLtwSHM6NIFAd4hX0RFhjjCGlQm4w/p+2eaGQPUS5tQZdL1m5sc8h+sadGhQzdqe35I JPPc6sXoAjgEM1qBMW9QeR52K9Gafy/KfjyS4OFP7arZgy2Hh/bFNXk/18EN+eSv1FdD qf8A== X-Gm-Message-State: AC+VfDxzChLoNwudDHkkGVwHmnV7eABkVgcE0KEIJz5DWzQk2rJewvr3 3qAtnvNCfVOo3JzaUhDSnUUpQUMyfny0pxLwz2s= X-Google-Smtp-Source: ACHHUZ5qCy/HDLNP45VCDO1+Wq4e0pw87DGdESxvarY0EV9JnZn0AU6jCUPfcbDNesz7i76XJLsvMQ== X-Received: by 2002:a17:90a:f3c9:b0:246:b60a:290b with SMTP id ha9-20020a17090af3c900b00246b60a290bmr2724510pjb.21.1682616238608; Thu, 27 Apr 2023 10:23:58 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id x12-20020a65538c000000b0050bc03741ffsm11698712pgq.84.2023.04.27.10.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:23:58 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: dlemoal@kernel.org, dmitry.fomichev@wdc.com, Aarushi Mehta , qemu-block@nongnu.org, Kevin Wolf , Stefan Hajnoczi , Julia Suvorova , Hanna Reitz , hare@suse.de, Fam Zheng , Stefano Garzarella , Sam Li Subject: [PATCH v10 3/4] qemu-iotests: test zone append operation Date: Fri, 28 Apr 2023 01:23:38 +0800 Message-Id: <20230427172339.3709-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172339.3709-1-faithilikerun@gmail.com> References: <20230427172339.3709-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b32; envelope-from=faithilikerun@gmail.com; helo=mail-yb1-xb32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The patch tests zone append writes by reporting the zone wp after the completion of the call. "zap -p" option can print the sector offset value after completion, which should be the start sector where the append write begins. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- qemu-io-cmds.c | 75 ++++++++++++++++++++++++++++++ tests/qemu-iotests/tests/zoned | 16 +++++++ tests/qemu-iotests/tests/zoned.out | 16 +++++++ 3 files changed, 107 insertions(+) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index f35ea627d7..3f75d2f5a6 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1874,6 +1874,80 @@ static const cmdinfo_t zone_reset_cmd = { .oneline = "reset a zone write pointer in zone block device", }; +static int do_aio_zone_append(BlockBackend *blk, QEMUIOVector *qiov, + int64_t *offset, int flags, int *total) +{ + int async_ret = NOT_DONE; + + blk_aio_zone_append(blk, offset, qiov, flags, aio_rw_done, &async_ret); + while (async_ret == NOT_DONE) { + main_loop_wait(false); + } + + *total = qiov->size; + return async_ret < 0 ? async_ret : 1; +} + +static int zone_append_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + bool pflag = false; + int flags = 0; + int total = 0; + int64_t offset; + char *buf; + int c, nr_iov; + int pattern = 0xcd; + QEMUIOVector qiov; + + if (optind > argc - 3) { + return -EINVAL; + } + + if ((c = getopt(argc, argv, "p")) != -1) { + pflag = true; + } + + offset = cvtnum(argv[optind]); + if (offset < 0) { + print_cvtnum_err(offset, argv[optind]); + return offset; + } + optind++; + nr_iov = argc - optind; + buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern, + flags & BDRV_REQ_REGISTERED_BUF); + if (buf == NULL) { + return -EINVAL; + } + ret = do_aio_zone_append(blk, &qiov, &offset, flags, &total); + if (ret < 0) { + printf("zone append failed: %s\n", strerror(-ret)); + goto out; + } + + if (pflag) { + printf("After zap done, the append sector is 0x%" PRIx64 "\n", + tosector(offset)); + } + +out: + qemu_io_free(blk, buf, qiov.size, + flags & BDRV_REQ_REGISTERED_BUF); + qemu_iovec_destroy(&qiov); + return ret; +} + +static const cmdinfo_t zone_append_cmd = { + .name = "zone_append", + .altname = "zap", + .cfunc = zone_append_f, + .argmin = 3, + .argmax = 4, + .args = "offset len [len..]", + .oneline = "append write a number of bytes at a specified offset", +}; + static int truncate_f(BlockBackend *blk, int argc, char **argv); static const cmdinfo_t truncate_cmd = { .name = "truncate", @@ -2672,6 +2746,7 @@ static void __attribute((constructor)) init_qemuio_commands(void) qemuio_add_command(&zone_close_cmd); qemuio_add_command(&zone_finish_cmd); qemuio_add_command(&zone_reset_cmd); + qemuio_add_command(&zone_append_cmd); qemuio_add_command(&truncate_cmd); qemuio_add_command(&length_cmd); qemuio_add_command(&info_cmd); diff --git a/tests/qemu-iotests/tests/zoned b/tests/qemu-iotests/tests/zoned index 56f60616b5..3d23ce9cc1 100755 --- a/tests/qemu-iotests/tests/zoned +++ b/tests/qemu-iotests/tests/zoned @@ -82,6 +82,22 @@ echo "(5) resetting the second zone" $QEMU_IO $IMG -c "zrs 268435456 268435456" echo "After resetting a zone:" $QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo +echo "(6) append write" # the physical block size of the device is 4096 +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 0 0x1000 0x2000" +echo "After appending the first zone firstly:" +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 0 0x1000 0x2000" +echo "After appending the first zone secondly:" +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 268435456 0x1000 0x2000" +echo "After appending the second zone firstly:" +$QEMU_IO $IMG -c "zrp 268435456 1" +$QEMU_IO $IMG -c "zap -p 268435456 0x1000 0x2000" +echo "After appending the second zone secondly:" +$QEMU_IO $IMG -c "zrp 268435456 1" # success, all done echo "*** done" diff --git a/tests/qemu-iotests/tests/zoned.out b/tests/qemu-iotests/tests/zoned.out index b2d061da49..fe53ba4744 100644 --- a/tests/qemu-iotests/tests/zoned.out +++ b/tests/qemu-iotests/tests/zoned.out @@ -50,4 +50,20 @@ start: 0x80000, len 0x80000, cap 0x80000, wptr 0x100000, zcond:14, [type: 2] (5) resetting the second zone After resetting a zone: start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80000, zcond:1, [type: 2] + + +(6) append write +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] +After zap done, the append sector is 0x0 +After appending the first zone firstly: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x18, zcond:2, [type: 2] +After zap done, the append sector is 0x18 +After appending the first zone secondly: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x30, zcond:2, [type: 2] +After zap done, the append sector is 0x80000 +After appending the second zone firstly: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80018, zcond:2, [type: 2] +After zap done, the append sector is 0x80018 +After appending the second zone secondly: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80030, zcond:2, [type: 2] *** done