From patchwork Mon Oct 10 02:33:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1687896 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=20210112 header.b=UXq/9yoz; 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 4Mm3000Q3yz23jr for ; Mon, 10 Oct 2022 13:34:22 +1100 (AEDT) Received: from localhost ([::1]:44358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohicV-0001Ht-Gf for incoming@patchwork.ozlabs.org; Sun, 09 Oct 2022 22:34:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohibf-0001Gi-Tj; Sun, 09 Oct 2022 22:33:29 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:45042) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohibd-0007ox-Sm; Sun, 09 Oct 2022 22:33:27 -0400 Received: by mail-pf1-x431.google.com with SMTP id i3so82184pfc.11; Sun, 09 Oct 2022 19:33:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=yvfxl0IgBZCvmM66WK3Orr+3oPbgHzm5QrwL9hvAxyA=; b=UXq/9yozZNGYg3Tw1gElEcWvFQ2jKX3nzIrfUyLXD075PzONVsSxyJcpi7XNF5hnis DceBQ/7wBbkjueMc23YnZQhZybnJp8VfTKM/t0wPJE8+39XOzKghIWATuSsp9komY4BW dNnyuXxVAMbufdN6BBRee9V87rpYljvDhy5mNDjq9wfKfneuJrKyoOvCpyOE52QLjnOb tJZZbQ+4NBtK6Vjx1LdC+8F7sBDquGRp52lrrH13TAQUTMzh4gLOkfpI9SHc+vjoVEsE VXa73C0wzsIPuH8NdhGox3V43xWj9o1eIo0EigA8o2aHhIU4eyfPrnBUluWO6XTAh/ZD mrpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=yvfxl0IgBZCvmM66WK3Orr+3oPbgHzm5QrwL9hvAxyA=; b=YRMu6BPuABQTVtrZ3NxIq3+6c90QcvNH7hWkEtTLHbn2+ocHmBSx74fpuTWBIgiB0e XTR7rcSXe/3oA7O0Zc+jY/dIITXD3tqnvVA8TjoltyQ7mWbAM5uh2nYj+91ifKU+8PLZ 9L/kYNz9hgNrIVkpRuh0uQ02V9sicP3vpn9LkT/60x3YXdFBIi6x04sHJtTnU90Xn0YS EX1kSQPdDtHuUWy45f/pkD+YwWGHqzOvn5OW+VhAnws0a8V/wqNVXd1S6Na/sF2ix7kg hH5gkdF/igW/HUMlrmqjYp/RNNugqPaIU1FJSUdGuIHH7ho5aPiqvCDzWRBZ6DZHRMsM Hw2w== X-Gm-Message-State: ACrzQf1DvSwow1WSuWcEktxKzyUYdL/LlYlQlG84aRsWrExj2TxWbjmd +GogP9uxXOPy4wpdNE4pnBgGdM4wxT3qh7xJeLI= X-Google-Smtp-Source: AMsMyM6lWvqJYge9lvyCRqW4pw1VtvQ4JJAoKGQKMi+DHPgz9Fmhi3HT3aMQGyXvycak7NTQLjCdng== X-Received: by 2002:a63:1b0e:0:b0:44b:97e8:1020 with SMTP id b14-20020a631b0e000000b0044b97e81020mr14597522pgb.519.1665369203272; Sun, 09 Oct 2022 19:33:23 -0700 (PDT) Received: from roots.. ([112.44.203.212]) by smtp.gmail.com with ESMTPSA id j64-20020a625543000000b00537b1aa9191sm5743995pfb.178.2022.10.09.19.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Oct 2022 19:33:23 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Hanna Reitz , Kevin Wolf , dmitry.fomichev@wdc.com, hare@suse.de, Fam Zheng , damien.lemoal@opensource.wdc.com, qemu-block@nongnu.org, Sam Li Subject: [PATCH v3 1/3] file-posix:add the tracking of the zones write pointers Date: Mon, 10 Oct 2022 10:33:04 +0800 Message-Id: <20221010023306.43610-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221010023306.43610-1-faithilikerun@gmail.com> References: <20221010023306.43610-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x431.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 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" Since Linux doesn't have a user API to issue zone append operations to zoned devices from user space, the file-posix driver is modified to add zone append emulation using regular writes. To do this, the file-posix driver tracks the wp location of all zones of the device. It uses an array of uint64_t. The most significant bit of each wp location indicates if the zone type is conventional zones. The zones wp can be changed due to the following operations issued: - zone reset: change the wp to the start offset of that zone - zone finish: change to the end location of that zone - write to a zone - zone append Signed-off-by: Sam Li --- block/file-posix.c | 158 +++++++++++++++++++++++++++++++ include/block/block-common.h | 14 +++ include/block/block_int-common.h | 5 + 3 files changed, 177 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index a9d347292e..17c0b58158 100755 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -206,6 +206,7 @@ typedef struct RawPosixAIOData { struct { struct iovec *iov; int niov; + int64_t *append_sector; } io; struct { uint64_t cmd; @@ -226,6 +227,7 @@ typedef struct RawPosixAIOData { struct { unsigned long zone_op; const char *zone_op_name; + bool all; } zone_mgmt; }; } RawPosixAIOData; @@ -1331,6 +1333,67 @@ static int hdev_get_max_segments(int fd, struct stat *st) { #endif } +#if defined(CONFIG_BLKZONED) +static int get_zones_wp(int64_t offset, int fd, BlockZoneWps *wps, + unsigned int nrz) { + struct blk_zone *blkz; + int64_t rep_size; + int64_t sector = offset >> BDRV_SECTOR_BITS; + int ret, n = 0, i = 0; + rep_size = sizeof(struct blk_zone_report) + nrz * sizeof(struct blk_zone); + g_autofree struct blk_zone_report *rep = NULL; + + rep = g_malloc(rep_size); + blkz = (struct blk_zone *)(rep + 1); + while (n < nrz) { + memset(rep, 0, rep_size); + rep->sector = sector; + rep->nr_zones = nrz - n; + + do { + ret = ioctl(fd, BLKREPORTZONE, rep); + } while (ret != 0 && errno == EINTR); + if (ret != 0) { + error_report("%d: ioctl BLKREPORTZONE at %" PRId64 " failed %d", + fd, offset, errno); + return -errno; + } + + if (!rep->nr_zones) { + break; + } + + for (i = 0; i < rep->nr_zones; i++, n++) { + /* + * The wp tracking cares only about sequential writes required and + * sequential write preferred zones so that the wp can advance to + * the right location. + * Use the most significant bit of the wp location to indicate the + * zone type: 0 for SWR/SWP zones and 1 for conventional zones. + */ + if (!(blkz[i].type != BLK_ZONE_TYPE_CONVENTIONAL)) { + wps->wp[i] += 1ULL << 63; + } else { + wps->wp[i] = blkz[i].wp << BDRV_SECTOR_BITS; + } + } + sector = blkz[i-1].start + blkz[i-1].len; + } + + return 0; +} + +static void update_zones_wp(int64_t offset, int fd, BlockZoneWps *wps, + unsigned int nrz) { + qemu_mutex_lock(&wps->lock); + if (get_zones_wp(offset, fd, wps, nrz) < 0) { + error_report("report zone wp failed"); + return; + } + qemu_mutex_unlock(&wps->lock); +} +#endif + static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s = bs->opaque; @@ -1414,6 +1477,19 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) error_report("Invalid device capacity %" PRId64 " bytes ", bs->bl.capacity); return; } + + ret = get_sysfs_long_val(&st, "physical_block_size"); + if (ret >= 0) { + bs->bl.write_granularity = ret; + } + + bs->bl.wps = g_malloc(sizeof(BlockZoneWps) + sizeof(int64_t) * ret); + if (get_zones_wp(0, s->fd, bs->bl.wps, ret) < 0){ + error_report("report wps failed"); + g_free(bs->bl.wps); + return; + } + qemu_mutex_init(&bs->bl.wps->lock); } } @@ -1651,6 +1727,20 @@ static int handle_aiocb_rw(void *opaque) ssize_t nbytes; char *buf; + /* + * The offset of regular writes, append writes is the wp location + * of that zone. + */ + if (aiocb->aio_type & QEMU_AIO_WRITE) { + if (aiocb->bs->bl.zone_size > 0) { + BlockZoneWps *wps = aiocb->bs->bl.wps; + qemu_mutex_lock(&wps->lock); + aiocb->aio_offset = wps->wp[aiocb->aio_offset / + aiocb->bs->bl.zone_size]; + qemu_mutex_unlock(&wps->lock); + } + } + if (!(aiocb->aio_type & QEMU_AIO_MISALIGNED)) { /* * If there is just a single buffer, and it is properly aligned @@ -1725,6 +1815,24 @@ static int handle_aiocb_rw(void *opaque) out: if (nbytes == aiocb->aio_nbytes) { +#if defined(CONFIG_BLKZONED) + if (aiocb->aio_type & QEMU_AIO_WRITE) { + BlockZoneWps *wps = aiocb->bs->bl.wps; + int index = aiocb->aio_offset / aiocb->bs->bl.zone_size; + if (wps) { + qemu_mutex_lock(&wps->lock); + if (!BDRV_ZT_IS_CONV(wps->wp[index])) { + uint64_t wend_offset = + aiocb->aio_offset + aiocb->aio_nbytes; + /* Advance the wp if needed */ + if (wend_offset > wps->wp[index]){ + wps->wp[index] = wend_offset; + } + } + qemu_mutex_unlock(&wps->lock); + } + } +#endif return 0; } else if (nbytes >= 0 && nbytes < aiocb->aio_nbytes) { if (aiocb->aio_type & QEMU_AIO_WRITE) { @@ -1736,6 +1844,12 @@ out: } } else { assert(nbytes < 0); +#if defined(CONFIG_BLKZONED) + if (aiocb->aio_type & QEMU_AIO_WRITE) { + update_zones_wp(0, aiocb->aio_fildes, aiocb->bs->bl.wps, + aiocb->bs->bl.nr_zones); + } +#endif return nbytes; } } @@ -2022,12 +2136,17 @@ static int handle_aiocb_zone_report(void *opaque) { #if defined(CONFIG_BLKZONED) static int handle_aiocb_zone_mgmt(void *opaque) { RawPosixAIOData *aiocb = opaque; + BlockDriverState *bs = aiocb->bs; int fd = aiocb->aio_fildes; int64_t sector = aiocb->aio_offset / 512; int64_t nr_sectors = aiocb->aio_nbytes / 512; + uint64_t wend_offset; struct blk_zone_range range; int ret; + BlockZoneWps *wps = bs->bl.wps; + int index = aiocb->aio_offset / bs->bl.zone_size; + /* Execute the operation */ range.sector = sector; range.nr_sectors = nr_sectors; @@ -2035,11 +2154,41 @@ static int handle_aiocb_zone_mgmt(void *opaque) { ret = ioctl(fd, aiocb->zone_mgmt.zone_op, &range); } while (ret != 0 && errno == EINTR); if (ret != 0) { + update_zones_wp(0, aiocb->aio_fildes, aiocb->bs->bl.wps, + aiocb->bs->bl.nr_zones); ret = -errno; error_report("ioctl %s failed %d", aiocb->zone_mgmt.zone_op_name, ret); return ret; } + + qemu_mutex_lock(&wps->lock); + if (!BDRV_ZT_IS_CONV(wps->wp[index])) { + /* + * The zoned device allows the last zone smaller that the zone size. + */ + if (aiocb->aio_nbytes < bs->bl.zone_size) { + wend_offset = aiocb->aio_offset + aiocb->aio_nbytes; + } else { + wend_offset = aiocb->aio_offset + bs->bl.zone_size; + } + + if (aiocb->aio_offset != wps->wp[index] && + aiocb->zone_mgmt.zone_op == BLKRESETZONE) { + if (aiocb->zone_mgmt.all) { + for (int i = 0; i < bs->bl.nr_zones; ++i) { + wps->wp[i] = i * bs->bl.zone_size; + } + } else { + wps->wp[index] = aiocb->aio_offset; + } + } else if (aiocb->aio_offset != wps->wp[index] && + aiocb->zone_mgmt.zone_op == BLKFINISHZONE) { + wps->wp[index] = wend_offset; + } + } + qemu_mutex_unlock(&wps->lock); + return ret; } #endif @@ -2480,6 +2629,12 @@ static void raw_close(BlockDriverState *bs) BDRVRawState *s = bs->opaque; if (s->fd >= 0) { +#if defined(CONFIG_BLKZONED) + if (bs->bl.wps) { + qemu_mutex_destroy(&bs->bl.wps->lock); + g_free(bs->bl.wps); + } +#endif qemu_close(s->fd); s->fd = -1; } @@ -3278,6 +3433,7 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, int64_t zone_size, zone_size_mask; const char *zone_op_name; unsigned long zone_op; + bool is_all = false; zone_size = bs->bl.zone_size; zone_size_mask = zone_size - 1; @@ -3314,6 +3470,7 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, case BLK_ZO_RESET_ALL: zone_op_name = "BLKRESETZONE"; zone_op = BLKRESETZONE; + is_all = true; break; default: g_assert_not_reached(); @@ -3328,6 +3485,7 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, .zone_mgmt = { .zone_op = zone_op, .zone_op_name = zone_op_name, + .all = is_all, }, }; diff --git a/include/block/block-common.h b/include/block/block-common.h index 882de6825e..b8b2dba64a 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -93,6 +93,14 @@ typedef struct BlockZoneDescriptor { BlockZoneCondition cond; } BlockZoneDescriptor; +/* + * Track write pointers of a zone in bytes. + */ +typedef struct BlockZoneWps { + QemuMutex lock; + uint64_t wp[]; +} BlockZoneWps; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; @@ -206,6 +214,12 @@ typedef enum { #define BDRV_SECTOR_BITS 9 #define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS) +/* + * Get the first most significant bit of wp. If it is zero, then + * the zone type is SWR. + */ +#define BDRV_ZT_IS_CONV(wp) (wp & (1ULL << 63)) + #define BDRV_REQUEST_MAX_SECTORS MIN_CONST(SIZE_MAX >> BDRV_SECTOR_BITS, \ INT_MAX >> BDRV_SECTOR_BITS) #define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 37dddc603c..59c2d1316d 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -857,6 +857,11 @@ typedef struct BlockLimits { /* device capacity expressed in bytes */ int64_t capacity; + + /* array of write pointers' location of each zone in the zoned device. */ + BlockZoneWps *wps; + + int64_t write_granularity; } BlockLimits; typedef struct BdrvOpBlocker BdrvOpBlocker; From patchwork Mon Oct 10 02:33:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1687897 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=20210112 header.b=J0Tv6zCU; 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 4Mm30P471Nz23jn for ; Mon, 10 Oct 2022 13:34:45 +1100 (AEDT) Received: from localhost ([::1]:59686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohict-0002Gf-7U for incoming@patchwork.ozlabs.org; Sun, 09 Oct 2022 22:34:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohibl-0001HZ-D1; Sun, 09 Oct 2022 22:33:35 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:41490) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohibj-0007pM-5n; Sun, 09 Oct 2022 22:33:33 -0400 Received: by mail-pj1-x102e.google.com with SMTP id q10-20020a17090a304a00b0020b1d5f6975so8126959pjl.0; Sun, 09 Oct 2022 19:33:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=LDdnwZ8LlAo9NIDS/xnjTRz5pB5SfY/ZhaHzYJkeBAk=; b=J0Tv6zCUvGPb2lYBY8nM6zO8bRWR3GmCx11nRDwq5gWmYOCt/SBxOuQBLiwCTa+9Tq YTr7N6DEr4UvtIWAt3Kae9heUmf04YkfoGFBx1zcDw6qm4i1Y4pIWd1ik03fFtH/lqDG LrcQO+96VSGGDCZMgNqMsn+MGBPn/P0akM1cMTuuBr80TGMpCdFPduBRfz7OqoNt+zIl LsxzEEFqLLSnV5+dk1IldzDY/4T6tMIV3tVgfMpPqqUBI8XFhIk+PEK+f9OljLsZ/CF6 +cUPIUfHONo03SX4owvbspaaI9seJtS72hiy/iIHSmGbsREIhDh3ET/flOdO/0WUzB6k eiVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=LDdnwZ8LlAo9NIDS/xnjTRz5pB5SfY/ZhaHzYJkeBAk=; b=NKdEnOWzm4LtWVfzhbk6AFCxB8YV+iY3Uc+UKv1gH0fdOjSarkmkzMVwJV+/+cELHl gLwBAZVN+wFyY/7myJsZwujJNBjGgNuMs2QQJ+UC7PS3jzMkTy1R8/AVnC2lIoT17Z1j 0LhlXXNaYzY2rWO+JS11Z3OHBK8O5KCVBnyFEDb+035t8BRsep5Cq72pntROFv3H6J0g zSGL8i1aU5t9aBVuTxPw98xG8vKdDlxMYL2kb4jUy4lbq1tYE1HQ8FfWJhrvFyiJLY1n yEywHEstuVqmb08U92WUoqFvEMievSXmh6lOqUYacxRLNzHa33+VP9Q9PD2iEHbPg2HL FsWw== X-Gm-Message-State: ACrzQf36KV9TbitbCrFC3NTRBZze9elTN0e5lQ392kdP5bbDR99O6ff/ TjJQr/QlseQSVcrCCI8GzcwQ6J+2cfebRJptZVc= X-Google-Smtp-Source: AMsMyM5MF02heJewJ1p9KHlkFTVZWHAtGKjVKBTnWBXrZTvMMBG3At5/WMCq0rvFMjXm5oMKUNg6QQ== X-Received: by 2002:a17:90b:1d4d:b0:20a:794a:f6e7 with SMTP id ok13-20020a17090b1d4d00b0020a794af6e7mr29568285pjb.151.1665369209216; Sun, 09 Oct 2022 19:33:29 -0700 (PDT) Received: from roots.. ([112.44.203.212]) by smtp.gmail.com with ESMTPSA id j64-20020a625543000000b00537b1aa9191sm5743995pfb.178.2022.10.09.19.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Oct 2022 19:33:28 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Hanna Reitz , Kevin Wolf , dmitry.fomichev@wdc.com, hare@suse.de, Fam Zheng , damien.lemoal@opensource.wdc.com, qemu-block@nongnu.org, Sam Li Subject: [PATCH v3 2/3] block: introduce zone append write for zoned devices Date: Mon, 10 Oct 2022 10:33:05 +0800 Message-Id: <20221010023306.43610-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221010023306.43610-1-faithilikerun@gmail.com> References: <20221010023306.43610-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x102e.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 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" A zone append command is a write operation that specifies the first logical block of a zone as the write position. When writing to a zoned block device using zone append, the byte offset of writes is pointing to the write pointer of that zone. Upon completion the device will respond with the position the data has been written in the zone. Signed-off-by: Sam Li --- block/block-backend.c | 64 +++++++++++++++++++++++++++++++ block/file-posix.c | 64 ++++++++++++++++++++++++++++--- block/io.c | 21 ++++++++++ block/raw-format.c | 7 ++++ include/block/block-io.h | 3 ++ include/block/block_int-common.h | 3 ++ include/block/raw-aio.h | 4 +- include/sysemu/block-backend-io.h | 9 +++++ 8 files changed, 168 insertions(+), 7 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index ddc569e3ac..bfdb719bc8 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1439,6 +1439,9 @@ typedef struct BlkRwCo { struct { BlockZoneOp op; } zone_mgmt; + struct { + int64_t *append_sector; + } zone_append; }; } BlkRwCo; @@ -1869,6 +1872,46 @@ BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op, return &acb->common; } +static void coroutine_fn blk_aio_zone_append_entry(void *opaque) { + BlkAioEmAIOCB *acb = opaque; + BlkRwCo *rwco = &acb->rwco; + + rwco->ret = blk_co_zone_append(rwco->blk, rwco->zone_append.append_sector, + rwco->iobuf, rwco->flags); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, BdrvRequestFlags flags, + BlockCompletionFunc *cb, void *opaque) { + BlkAioEmAIOCB *acb; + Coroutine *co; + IO_CODE(); + + blk_inc_in_flight(blk); + acb = blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo) { + .blk = blk, + .ret = NOT_DONE, + .flags = flags, + .iobuf = qiov, + .zone_append = { + .append_sector = offset, + }, + }; + acb->has_returned = false; + + co = qemu_coroutine_create(blk_aio_zone_append_entry, acb); + bdrv_coroutine_enter(blk_bs(blk), co); + acb->has_returned = true; + if (acb->rwco.ret != NOT_DONE) { + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); + } + + return &acb->common; +} + /* * Send a zone_report command. * offset is a byte offset from the start of the device. No alignment @@ -1921,6 +1964,27 @@ int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, return ret; } +/* + * Send a zone_append command. + */ +int coroutine_fn blk_co_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, BdrvRequestFlags flags) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); + blk_wait_while_drained(blk); + if (!blk_is_available(blk)) { + blk_dec_in_flight(blk); + return -ENOMEDIUM; + } + + ret = bdrv_co_zone_append(blk_bs(blk), offset, qiov, flags); + blk_dec_in_flight(blk); + return ret; +} + void blk_drain(BlockBackend *blk) { BlockDriverState *bs = blk_bs(blk); diff --git a/block/file-posix.c b/block/file-posix.c index 17c0b58158..08ab164df4 100755 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1657,7 +1657,7 @@ static ssize_t handle_aiocb_rw_vector(RawPosixAIOData *aiocb) ssize_t len; do { - if (aiocb->aio_type & QEMU_AIO_WRITE) + if (aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) len = qemu_pwritev(aiocb->aio_fildes, aiocb->io.iov, aiocb->io.niov, @@ -1687,7 +1687,7 @@ static ssize_t handle_aiocb_rw_linear(RawPosixAIOData *aiocb, char *buf) ssize_t len; while (offset < aiocb->aio_nbytes) { - if (aiocb->aio_type & QEMU_AIO_WRITE) { + if (aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) { len = pwrite(aiocb->aio_fildes, (const char *)buf + offset, aiocb->aio_nbytes - offset, @@ -1731,7 +1731,7 @@ static int handle_aiocb_rw(void *opaque) * The offset of regular writes, append writes is the wp location * of that zone. */ - if (aiocb->aio_type & QEMU_AIO_WRITE) { + if (aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) { if (aiocb->bs->bl.zone_size > 0) { BlockZoneWps *wps = aiocb->bs->bl.wps; qemu_mutex_lock(&wps->lock); @@ -1794,7 +1794,7 @@ static int handle_aiocb_rw(void *opaque) } nbytes = handle_aiocb_rw_linear(aiocb, buf); - if (!(aiocb->aio_type & QEMU_AIO_WRITE)) { + if (!(aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND))) { char *p = buf; size_t count = aiocb->aio_nbytes, copy; int i; @@ -1816,7 +1816,7 @@ static int handle_aiocb_rw(void *opaque) out: if (nbytes == aiocb->aio_nbytes) { #if defined(CONFIG_BLKZONED) - if (aiocb->aio_type & QEMU_AIO_WRITE) { + if (aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) { BlockZoneWps *wps = aiocb->bs->bl.wps; int index = aiocb->aio_offset / aiocb->bs->bl.zone_size; if (wps) { @@ -1828,6 +1828,11 @@ out: if (wend_offset > wps->wp[index]){ wps->wp[index] = wend_offset; } + + if (aiocb->aio_type & QEMU_AIO_ZONE_APPEND) { + *aiocb->io.append_sector = + wps->wp[index] >> BDRV_SECTOR_BITS; + } } qemu_mutex_unlock(&wps->lock); } @@ -1845,7 +1850,7 @@ out: } else { assert(nbytes < 0); #if defined(CONFIG_BLKZONED) - if (aiocb->aio_type & QEMU_AIO_WRITE) { + if (aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) { update_zones_wp(0, aiocb->aio_fildes, aiocb->bs->bl.wps, aiocb->bs->bl.nr_zones); } @@ -3493,6 +3498,52 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, } #endif +#if defined(CONFIG_BLKZONED) +static int coroutine_fn raw_co_zone_append(BlockDriverState *bs, + int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags) { + BDRVRawState *s = bs->opaque; + int64_t zone_size_mask = bs->bl.zone_size - 1; + int64_t iov_len = 0; + int64_t len = 0; + RawPosixAIOData acb; + + if (*offset & zone_size_mask) { + error_report("sector offset %" PRId64 " is not aligned to zone size " + "%" PRId32 "", *offset / 512, bs->bl.zone_size / 512); + return -EINVAL; + } + + int64_t wg = bs->bl.write_granularity; + int64_t wg_mask = wg - 1; + for (int i = 0; i < qiov->niov; i++) { + iov_len = qiov->iov[i].iov_len; + if (iov_len & wg_mask) { + error_report("len of IOVector[%d] %" PRId64 " is not aligned to block " + "size %" PRId64 "", i, iov_len, wg); + return -EINVAL; + } + len += iov_len; + } + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_ZONE_APPEND, + .aio_offset = *offset, + .aio_nbytes = len, + .io = { + .iov = qiov->iov, + .niov = qiov->niov, + .append_sector = offset, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_rw, &acb); +} +#endif + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes, bool blkdev) @@ -4268,6 +4319,7 @@ static BlockDriver bdrv_zoned_host_device = { /* zone management operations */ .bdrv_co_zone_report = raw_co_zone_report, .bdrv_co_zone_mgmt = raw_co_zone_mgmt, + .bdrv_co_zone_append = raw_co_zone_append, }; #endif diff --git a/block/io.c b/block/io.c index e5aaa64e17..935abf2ed4 100644 --- a/block/io.c +++ b/block/io.c @@ -3230,6 +3230,27 @@ out: return co.ret; } +int coroutine_fn bdrv_co_zone_append(BlockDriverState *bs, int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags) +{ + BlockDriver *drv = bs->drv; + CoroutineIOCompletion co = { + .coroutine = qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_append) { + co.ret = -ENOTSUP; + goto out; + } + co.ret = drv->bdrv_co_zone_append(bs, offset, qiov, flags); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/block/raw-format.c b/block/raw-format.c index b885688434..f132880c85 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -325,6 +325,12 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, return bdrv_co_zone_mgmt(bs->file->bs, op, offset, len); } +static int coroutine_fn raw_co_zone_append(BlockDriverState *bs, int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags) { + return bdrv_co_zone_append(bs->file->bs, offset, qiov, flags); +} + static int64_t raw_getlength(BlockDriverState *bs) { int64_t len; @@ -628,6 +634,7 @@ BlockDriver bdrv_raw = { .bdrv_co_pdiscard = &raw_co_pdiscard, .bdrv_co_zone_report = &raw_co_zone_report, .bdrv_co_zone_mgmt = &raw_co_zone_mgmt, + .bdrv_co_zone_append = &raw_co_zone_append, .bdrv_co_block_status = &raw_co_block_status, .bdrv_co_copy_range_from = &raw_co_copy_range_from, .bdrv_co_copy_range_to = &raw_co_copy_range_to, diff --git a/include/block/block-io.h b/include/block/block-io.h index f0cdf67d33..6a54453578 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -94,6 +94,9 @@ int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, BlockZoneDescriptor *zones); int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, int64_t offset, int64_t len); +int coroutine_fn bdrv_co_zone_append(BlockDriverState *bs, int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags); int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 59c2d1316d..a7e7db5646 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -701,6 +701,9 @@ struct BlockDriver { BlockZoneDescriptor *zones); int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneOp op, int64_t offset, int64_t len); + int coroutine_fn (*bdrv_co_zone_append)(BlockDriverState *bs, + int64_t *offset, QEMUIOVector *qiov, + BdrvRequestFlags flags); /* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs); diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index 3d26929cdd..f13cc1887b 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -31,6 +31,7 @@ #define QEMU_AIO_TRUNCATE 0x0080 #define QEMU_AIO_ZONE_REPORT 0x0100 #define QEMU_AIO_ZONE_MGMT 0x0200 +#define QEMU_AIO_ZONE_APPEND 0x0400 #define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \ @@ -41,7 +42,8 @@ QEMU_AIO_COPY_RANGE | \ QEMU_AIO_TRUNCATE | \ QEMU_AIO_ZONE_REPORT | \ - QEMU_AIO_ZONE_MGMT) + QEMU_AIO_ZONE_MGMT | \ + QEMU_AIO_ZONE_APPEND) /* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000 diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 6835525582..33e35ae5d7 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -51,6 +51,9 @@ BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset, BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op, int64_t offset, int64_t len, BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, BdrvRequestFlags flags, + BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes, BlockCompletionFunc *cb, void *opaque); void blk_aio_cancel_async(BlockAIOCB *acb); @@ -172,6 +175,12 @@ int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, int64_t offset, int64_t len); int generated_co_wrapper blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, int64_t offset, int64_t len); +int coroutine_fn blk_co_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags); +int generated_co_wrapper blk_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags); int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); From patchwork Mon Oct 10 02:33:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1687898 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=20210112 header.b=gdWGVWv6; 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 4Mm32k2pXFz20cX for ; Mon, 10 Oct 2022 13:36:46 +1100 (AEDT) Received: from localhost ([::1]:34284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohiep-0005iV-Rr for incoming@patchwork.ozlabs.org; Sun, 09 Oct 2022 22:36:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohibr-0001KA-Ep; Sun, 09 Oct 2022 22:33:39 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:42632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohibp-0007pk-JN; Sun, 09 Oct 2022 22:33:39 -0400 Received: by mail-pj1-x1029.google.com with SMTP id l1-20020a17090a72c100b0020a6949a66aso9238706pjk.1; Sun, 09 Oct 2022 19:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=sNDpjghhIJzk3ZF5nExh31OS+OUK/eTgV50nYtZkFLA=; b=gdWGVWv6T4Dl4lRUQ7gIoO6qJf4co9GnJMxO1gjA2zIpQ8BxbF584LwmhSDG2HyXIV CWcta5Mz+AjTnEpL8PURltsWr1/Q33GkYfLt1Aabw3tyHaouqZhKl2y579F0tQaOHG1K zAGmJqngBTkx6WAAC98BRm2Ij/4gE7yLPGdSHeaDf0ANwhtPi9vtpFnxkVRgiajH3ebf Ihl73pc68cSlJ4YpU38KbfCFU9xsetyAl1C4QUMZP5LsIYzd1oS3Ki7xEjYllaSqNc+1 Bl6xcZ/+TAsfzH3iQWNMVVzT0LweqLgGUrjYIZZTU3LV1rYdSP3Fn2MEQn4MHOgEzjw9 eWQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=sNDpjghhIJzk3ZF5nExh31OS+OUK/eTgV50nYtZkFLA=; b=pNY5aOZ38VkKqXqtMlVFBh+E87Gx4oUz3wnbaq5dOhRxwxbKf11OCEqp/+hiO3rKet 0QBXInpfeTigGS/6x0XeZVMrY/V3EKsKgR7a6S9dlwd67D6myzUHJtXOY0ibxTyDb7aa jiuLavX7EGbQnVw5dk7zAMuLuwkEeKfMuAYYbXNN+H9wLxPdZPiWVYdhRHHj0hrsnI6S pqx4gP6j4kh6V+yXebQgKIQ7ZTuFRLXS2gxdV4JwiMpBnVcRRap3i+fNK/ywS6WuzYoL 59wadt0ctrb7mJmmBmVH77H82BrePxhMY2i4CxQQiG1wN99qNGPeqw+Z8d3EkUwsUQDQ LdoQ== X-Gm-Message-State: ACrzQf32UHOnEJtbYh3gBNvExFaKpObWOpF2ZE64dPtUfxnX4Aq6kOR+ KeqDwiNFJBdMVgkhfZCkNfbR13EpjKo4TPXWpM4= X-Google-Smtp-Source: AMsMyM4j5T9YSRv81Bf1XwfLTv8IUjnPqN7XP4rlnsyOF6ghgoMHfK+nvixFMMNYysJegI+HPM9Q5A== X-Received: by 2002:a17:903:245:b0:178:e0ba:e507 with SMTP id j5-20020a170903024500b00178e0bae507mr17253654plh.115.1665369214601; Sun, 09 Oct 2022 19:33:34 -0700 (PDT) Received: from roots.. ([112.44.203.212]) by smtp.gmail.com with ESMTPSA id j64-20020a625543000000b00537b1aa9191sm5743995pfb.178.2022.10.09.19.33.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Oct 2022 19:33:34 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Hanna Reitz , Kevin Wolf , dmitry.fomichev@wdc.com, hare@suse.de, Fam Zheng , damien.lemoal@opensource.wdc.com, qemu-block@nongnu.org, Sam Li Subject: [PATCH v3 3/3] qemu-iotests: test zone append operation Date: Mon, 10 Oct 2022 10:33:06 +0800 Message-Id: <20221010023306.43610-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221010023306.43610-1-faithilikerun@gmail.com> References: <20221010023306.43610-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1029.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 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" This tests is mainly a helper to indicate append writes in block layer behaves as expected. Signed-off-by: Sam Li --- qemu-io-cmds.c | 62 ++++++++++++++++++++++++++++++ tests/qemu-iotests/tests/zoned.out | 7 ++++ tests/qemu-iotests/tests/zoned.sh | 9 +++++ 3 files changed, 78 insertions(+) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index e56c8d1c30..6cb86de35b 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1855,6 +1855,67 @@ 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; + int flags = 0; + int total = 0; + int64_t offset; + char *buf; + int nr_iov; + int pattern = 0xcd; + QEMUIOVector qiov; + + if (optind > argc - 2) { + return -EINVAL; + } + optind++; + 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); + 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; + } + + out: + qemu_iovec_destroy(&qiov); + qemu_io_free(buf); + return ret; +} + +static const cmdinfo_t zone_append_cmd = { + .name = "zone_append", + .altname = "zap", + .cfunc = zone_append_f, + .argmin = 3, + .argmax = 3, + .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", @@ -2652,6 +2713,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.out b/tests/qemu-iotests/tests/zoned.out index 0c8f96deb9..b3b139b4ec 100644 --- a/tests/qemu-iotests/tests/zoned.out +++ b/tests/qemu-iotests/tests/zoned.out @@ -50,4 +50,11 @@ 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 +After appending the first zone: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x18, zcond:2, [type: 2] +After appending the second zone: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80018, zcond:2, [type: 2] *** done diff --git a/tests/qemu-iotests/tests/zoned.sh b/tests/qemu-iotests/tests/zoned.sh index fced0194c5..888711eef2 100755 --- a/tests/qemu-iotests/tests/zoned.sh +++ b/tests/qemu-iotests/tests/zoned.sh @@ -79,6 +79,15 @@ echo "(5) resetting the second zone" sudo $QEMU_IO $IMG -c "zrs 268435456 268435456" echo "After resetting a zone:" sudo $QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo +echo "(6) append write" # physical block size of the device is 4096 +sudo $QEMU_IO $IMG -c "zap 0 0x1000 0x2000" +echo "After appending the first zone:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +sudo $QEMU_IO $IMG -c "zap 268435456 0x1000 0x2000" +echo "After appending the second zone:" +sudo $QEMU_IO $IMG -c "zrp 268435456 1" # success, all done echo "*** done"