From patchwork Mon Jun 27 00:19:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1648524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=EDtSjqC0; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWT310d8Jz9sGt for ; Mon, 27 Jun 2022 10:23:08 +1000 (AEST) Received: from localhost ([::1]:53966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5cWw-0003MF-Le for incoming@patchwork.ozlabs.org; Sun, 26 Jun 2022 20:23:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5cTk-0007Nq-3Z; Sun, 26 Jun 2022 20:19:48 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:43942) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5cTg-0000b5-Rm; Sun, 26 Jun 2022 20:19:47 -0400 Received: by mail-pj1-x102e.google.com with SMTP id dw10-20020a17090b094a00b001ed00a16eb4so7855188pjb.2; Sun, 26 Jun 2022 17:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Sl1KHg62VRe4mTaNOmkTdlZXTww6q+Ij1RaqgrCOyHQ=; b=EDtSjqC0AuANIyUN7HjzDpjB4V+5XYxSbUzkb8DqUgP4zWnljcdr0nxzD47qfDiSsL wuofdVMnshmndwj5v0BzUVaNtBxlfFQXLOgV65sOmwCHSvA9OcEXTcEVZAnD6NradGSO numr8wdGOrv0Rv8Hop8oyJLY6qa9Ofv8DO9a1T+pxSvFYov/Sm6CsRzt9NCeG3bJXnPr Ss78Z3K/mjdOsUYRxQuGWRUyp4p+8OiWYi6KnXB+0vw3LSqtSu55ByPsBNZBL7Yhk57s 0nZKMHAyi8lGtbBdctNqWPt9a3t7uRYWFDrbcQXD2Ir88inv1ZUObGVYF1O01CV1nj7S 7sZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Sl1KHg62VRe4mTaNOmkTdlZXTww6q+Ij1RaqgrCOyHQ=; b=J0OwZT09PmXYnmAjNyhEtyLByh+oapsXVZ39azhbSQMr0hPLJSVDUQe61C63tJ0oS1 JSk5DczLQjWGvxoARKAwjkXQcXLAmzZscYK33k/fzKDUFL3knXEaaJXzFYj6/308+edT f7leLP3Rrb2ymxkqgy3vuaB1YFI4wmGH00QDM1U4O74O6E1x6QMZ+CWqdSBwNW5N6giy p1pWEe1ZuwojPdzkv75dl6RHLwJl3t71Sz35zcgFWZhjXiVKbte6JhgVgAN7W7Et1GPU 5rYavWmW7rRyiVGJ1iFFCWbz5yPcKsmh8UOt2TezjLiXGfkgeNODThmfXSNaFc4FV0bK /dDw== X-Gm-Message-State: AJIora+Psch35axhH1TBMiYxCKW+D9DUeD+GxZufFOHHC/B7BuWS7D+s pos1pJrFVj8ZHa4HU/IR1yDHJ0L2SvfUFA== X-Google-Smtp-Source: AGRyM1vzu5dz3vo+8+6ktSKPu6cUSq7ci10oWEAtL/15cs4c/Ct81K8sC5wyFYCyVp7MEUOLW60AEQ== X-Received: by 2002:a17:902:c948:b0:16a:58f4:c142 with SMTP id i8-20020a170902c94800b0016a58f4c142mr12038497pla.103.1656289182885; Sun, 26 Jun 2022 17:19:42 -0700 (PDT) Received: from fedora.. ([106.84.130.34]) by smtp.gmail.com with ESMTPSA id e11-20020a6558cb000000b00408b89e4282sm5715294pgu.47.2022.06.26.17.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jun 2022 17:19:42 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Hanna Reitz , dmitry.fomichev@wdc.com, Kevin Wolf , Fam Zheng , Stefan Hajnoczi , damien.lemoal@opensource.wdc.com, qemu-block@nongnu.org, Sam Li Subject: [RFC v3 1/5] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls. Date: Mon, 27 Jun 2022 08:19:13 +0800 Message-Id: <20220627001917.9417-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220627001917.9417-1-faithilikerun@gmail.com> References: <20220627001917.9417-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, 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" By adding zone management operations in BlockDriver, storage controller emulation can use the new block layer APIs including zone_report and zone_mgmt(open, close, finish, reset). --- block/block-backend.c | 56 ++++++++ block/coroutines.h | 5 + block/file-posix.c | 238 +++++++++++++++++++++++++++++++ include/block/block-common.h | 43 +++++- include/block/block_int-common.h | 20 +++ 5 files changed, 361 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index e0e1aff4b1..786f964d02 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1810,6 +1810,62 @@ int blk_flush(BlockBackend *blk) return ret; } +/* + * Return zone_report from BlockDriver. Offset can be any number within + * the zone size. No alignment for offset and len. + */ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + int64_t len, int64_t *nr_zones, + BlockZoneDescriptor *zones) +{ + int ret; + BlockDriverState *bs; + IO_CODE(); + + blk_inc_in_flight(blk); /* increase before waiting */ + blk_wait_while_drained(blk); + bs = blk_bs(blk); + + ret = blk_check_byte_request(blk, offset, len); + if (ret < 0) { + return ret; + } + + bdrv_inc_in_flight(bs); + ret = bdrv_co_zone_report(blk->root->bs, offset, len, + nr_zones, zones); + bdrv_dec_in_flight(bs); + blk_dec_in_flight(blk); + return ret; +} + +/* + * Return zone_mgmt from BlockDriver. + * Offset is the start of a zone and len is aligned to zones. + */ +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, enum zone_op op, + int64_t offset, int64_t len) +{ + int ret; + BlockDriverState *bs; + IO_CODE(); + + blk_inc_in_flight(blk); + blk_wait_while_drained(blk); + bs = blk_bs(blk); + + ret = blk_check_byte_request(blk, offset, len); + if (ret < 0) { + return ret; + } + + bdrv_inc_in_flight(bs); + ret = bdrv_co_zone_mgmt(blk->root->bs, op, offset, len); + bdrv_dec_in_flight(bs); + blk_dec_in_flight(blk); + return ret; +} + void blk_drain(BlockBackend *blk) { BlockDriverState *bs = blk_bs(blk); diff --git a/block/coroutines.h b/block/coroutines.h index 830ecaa733..a114d7bc30 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -80,6 +80,11 @@ int coroutine_fn blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); int coroutine_fn blk_co_do_flush(BlockBackend *blk); +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + int64_t len, int64_t *nr_zones, + BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, enum zone_op op, + int64_t offset, int64_t len); /* diff --git a/block/file-posix.c b/block/file-posix.c index 48cd096624..1b8b0d351f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -216,6 +217,11 @@ typedef struct RawPosixAIOData { PreallocMode prealloc; Error **errp; } truncate; + struct { + int64_t *nr_zones; + BlockZoneDescriptor *zones; + } zone_report; + zone_op op; }; } RawPosixAIOData; @@ -1801,6 +1807,135 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, } #endif +/* + * parse_zone - Fill a zone descriptor + */ +static inline void parse_zone(struct BlockZoneDescriptor *zone, + struct blk_zone *blkz) { + zone->start = blkz->start; + zone->length = blkz->len; + zone->cap = blkz->capacity; + zone->wp = blkz->wp - blkz->start; + zone->type = blkz->type; + zone->cond = blkz->cond; +} + +static int handle_aiocb_zone_report(void *opaque) { + RawPosixAIOData *aiocb = opaque; + int fd = aiocb->aio_fildes; + int64_t *nr_zones = aiocb->zone_report.nr_zones; + BlockZoneDescriptor *zones = aiocb->zone_report.zones; + int64_t offset = aiocb->aio_offset; + int64_t len = aiocb->aio_nbytes; + + struct blk_zone *blkz; + int64_t rep_size, nrz; + int ret, n = 0, i = 0; + + nrz = *nr_zones; + if (len == -1) { + return -errno; + } + rep_size = sizeof(struct blk_zone_report) + nrz * sizeof(struct blk_zone); + g_autofree struct blk_zone_report *rep = g_new(struct blk_zone_report, nrz); + offset = offset / 512; /* get the unit of the start sector: sector size is 512 bytes. */ + printf("start to report zone with offset: 0x%lx\n", offset); + + blkz = (struct blk_zone *)(rep + 1); + while (n < nrz) { + memset(rep, 0, rep_size); + rep->sector = offset; + rep->nr_zones = nrz; + + ret = ioctl(fd, BLKREPORTZONE, rep); + if (ret != 0) { + ret = -errno; + error_report("%d: ioctl BLKREPORTZONE at %ld failed %d", + fd, offset, errno); + return ret; + } + + if (!rep->nr_zones) { + break; + } + + for (i = 0; i < rep->nr_zones; i++, n++) { + parse_zone(&zones[n], &blkz[i]); + /* The next report should start after the last zone reported */ + offset = blkz[i].start + blkz[i].len; + } + } + + *nr_zones = n; + return 0; +} + +static int handle_aiocb_zone_mgmt(void *opaque) { + RawPosixAIOData *aiocb = opaque; + int fd = aiocb->aio_fildes; + int64_t offset = aiocb->aio_offset; + int64_t len = aiocb->aio_nbytes; + zone_op op = aiocb->op; + + struct blk_zone_range range; + const char *ioctl_name; + unsigned long ioctl_op; + int64_t zone_size; + int64_t zone_size_mask; + int ret; + + ret = ioctl(fd, BLKGETZONESZ, &zone_size); + if (ret) { + return -1; + } + + zone_size_mask = zone_size - 1; + if (offset & zone_size_mask) { + error_report("offset is not the start of a zone"); + return -1; + } + + if (len & zone_size_mask) { + error_report("len is not aligned to zones"); + return -1; + } + + switch (op) { + case zone_open: + ioctl_name = "BLKOPENZONE"; + ioctl_op = BLKOPENZONE; + break; + case zone_close: + ioctl_name = "BLKCLOSEZONE"; + ioctl_op = BLKCLOSEZONE; + break; + case zone_finish: + ioctl_name = "BLKFINISHZONE"; + ioctl_op = BLKFINISHZONE; + break; + case zone_reset: + ioctl_name = "BLKRESETZONE"; + ioctl_op = BLKRESETZONE; + break; + default: + error_report("Invalid zone operation 0x%x", op); + errno = -EINVAL; + return -1; + } + + /* Execute the operation */ + range.sector = offset; + range.nr_sectors = len; + ret = ioctl(fd, ioctl_op, &range); + if (ret != 0) { + error_report("ioctl %s failed %d", + ioctl_name, errno); + return -1; + } + + return 0; +} + static int handle_aiocb_copy_range(void *opaque) { RawPosixAIOData *aiocb = opaque; @@ -2973,6 +3108,58 @@ static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) } } +/* + * zone report - Get a zone block device's information in the form + * of an array of zone descriptors. + * + * @param bs: passing zone block device file descriptor + * @param zones: an array of zone descriptors to hold zone + * information on reply + * @param offset: offset can be any byte within the zone size. + * @param len: (not sure yet. + * @return 0 on success, -1 on failure + */ +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, + int64_t len, int64_t *nr_zones, + BlockZoneDescriptor *zones) { + BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_IOCTL, + .aio_offset = offset, + .aio_nbytes = len, + .zone_report = { + .nr_zones = nr_zones, + .zones = zones, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_zone_report, &acb); +} + +/* + * zone management operations - Execute an operation on a zone + */ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, zone_op op, + int64_t offset, int64_t len) { + BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_IOCTL, + .aio_offset = offset, + .aio_nbytes = len, + .op = op, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_zone_mgmt, &acb); +} + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes, bool blkdev) @@ -3324,6 +3511,9 @@ BlockDriver bdrv_file = { .bdrv_abort_perm_update = raw_abort_perm_update, .create_opts = &raw_create_opts, .mutable_opts = mutable_opts, + + .bdrv_co_zone_report = raw_co_zone_report, + .bdrv_co_zone_mgmt = raw_co_zone_mgmt, }; /***********************************************/ @@ -3703,6 +3893,53 @@ static BlockDriver bdrv_host_device = { #endif }; +static BlockDriver bdrv_zoned_host_device = { + .format_name = "zoned_host_device", + .protocol_name = "zoned_host_device", + .instance_size = sizeof(BDRVRawState), + .bdrv_needs_filename = true, + .bdrv_probe_device = hdev_probe_device, + .bdrv_parse_filename = hdev_parse_filename, + .bdrv_file_open = hdev_open, + .bdrv_close = raw_close, + .bdrv_reopen_prepare = raw_reopen_prepare, + .bdrv_reopen_commit = raw_reopen_commit, + .bdrv_reopen_abort = raw_reopen_abort, + .bdrv_co_create_opts = bdrv_co_create_opts_simple, + .create_opts = &bdrv_create_opts_simple, + .mutable_opts = mutable_opts, + .bdrv_co_invalidate_cache = raw_co_invalidate_cache, + .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes, + + .bdrv_co_preadv = raw_co_preadv, + .bdrv_co_pwritev = raw_co_pwritev, + .bdrv_co_flush_to_disk = raw_co_flush_to_disk, + .bdrv_co_pdiscard = hdev_co_pdiscard, + .bdrv_co_copy_range_from = raw_co_copy_range_from, + .bdrv_co_copy_range_to = raw_co_copy_range_to, + .bdrv_refresh_limits = raw_refresh_limits, + .bdrv_io_plug = raw_aio_plug, + .bdrv_io_unplug = raw_aio_unplug, + .bdrv_attach_aio_context = raw_aio_attach_aio_context, + + .bdrv_co_truncate = raw_co_truncate, + .bdrv_getlength = raw_getlength, + .bdrv_get_info = raw_get_info, + .bdrv_get_allocated_file_size + = raw_get_allocated_file_size, + .bdrv_get_specific_stats = hdev_get_specific_stats, + .bdrv_check_perm = raw_check_perm, + .bdrv_set_perm = raw_set_perm, + .bdrv_abort_perm_update = raw_abort_perm_update, + .bdrv_probe_blocksizes = hdev_probe_blocksizes, + .bdrv_probe_geometry = hdev_probe_geometry, + .bdrv_co_ioctl = hdev_co_ioctl, + + /* zone management operations */ + .bdrv_co_zone_report = raw_co_zone_report, + .bdrv_co_zone_mgmt = raw_co_zone_mgmt, +}; + #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) static void cdrom_parse_filename(const char *filename, QDict *options, Error **errp) @@ -3964,6 +4201,7 @@ static void bdrv_file_init(void) #if defined(HAVE_HOST_BLOCK_DEVICE) bdrv_register(&bdrv_host_device); #ifdef __linux__ + bdrv_register(&bdrv_zoned_host_device); bdrv_register(&bdrv_host_cdrom); #endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) diff --git a/include/block/block-common.h b/include/block/block-common.h index fdb7306e78..78cddeeda5 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -23,7 +23,6 @@ */ #ifndef BLOCK_COMMON_H #define BLOCK_COMMON_H - #include "block/aio.h" #include "block/aio-wait.h" #include "qemu/iov.h" @@ -49,6 +48,48 @@ typedef struct BlockDriver BlockDriver; typedef struct BdrvChild BdrvChild; typedef struct BdrvChildClass BdrvChildClass; +typedef enum zone_op { + zone_open, + zone_close, + zone_finish, + zone_reset, +} zone_op; + +typedef enum zone_model { + BLK_Z_HM, + BLK_Z_HA, +} zone_model; + +typedef enum BlkZoneCondition { + BLK_ZS_NOT_WP = 0x0, + BLK_ZS_EMPTY = 0x1, + BLK_ZS_IOPEN = 0x2, + BLK_ZS_EOPEN = 0x3, + BLK_ZS_CLOSED = 0x4, + BLK_ZS_RDONLY = 0xD, + BLK_ZS_FULL = 0xE, + BLK_ZS_OFFLINE = 0xF, +} BlkZoneCondition; + +typedef enum BlkZoneType { + BLK_ZT_CONV = 0x1, + BLK_ZT_SWR = 0x2, + BLK_ZT_SWP = 0x3, +} BlkZoneType; + +/* + * Zone descriptor data structure. + * Provide information on a zone with all position and size values in bytes. + */ +typedef struct BlockZoneDescriptor { + uint64_t start; + uint64_t length; + uint64_t cap; + uint64_t wp; + BlkZoneType type; + BlkZoneCondition cond; +} BlockZoneDescriptor; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 8947abab76..b9ea9db6dc 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -94,6 +94,20 @@ typedef struct BdrvTrackedRequest { struct BdrvTrackedRequest *waiting_for; } BdrvTrackedRequest; +/** + * Zone device information data structure. + * Provide information on a device. + */ +typedef struct zbd_dev { + uint32_t zone_size; + zone_model model; + uint32_t block_size; + uint32_t write_granularity; + uint32_t nr_zones; + struct BlockZoneDescriptor *zones; /* array of zones */ + uint32_t max_nr_open_zones; /* maximum number of explicitly open zones */ + uint32_t max_nr_active_zones; +} zbd_dev; struct BlockDriver { /* @@ -691,6 +705,12 @@ struct BlockDriver { QEMUIOVector *qiov, int64_t pos); + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, + int64_t offset, int64_t len, int64_t *nr_zones, + BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, enum zone_op op, + int64_t offset, int64_t len); + /* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs); void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); From patchwork Mon Jun 27 00:19:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1648523 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=K60n/ISh; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWT104C0xz9sGt for ; Mon, 27 Jun 2022 10:21:24 +1000 (AEST) Received: from localhost ([::1]:50160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5cVG-0000hY-EU for incoming@patchwork.ozlabs.org; Sun, 26 Jun 2022 20:21:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5cTn-0007S8-83; Sun, 26 Jun 2022 20:19:51 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:45589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5cTl-0000bY-EN; Sun, 26 Jun 2022 20:19:50 -0400 Received: by mail-pg1-x536.google.com with SMTP id 184so7572928pga.12; Sun, 26 Jun 2022 17:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RjF8k+hpX9AH/ezNK0riUGjUD2YIMsd6gzdiqYDfMl4=; b=K60n/ISh5jnq1nVfSZAJaHifkSb6dh6g/51QWzYFpkRO1l3XogY8aWlXLnuZseCkSI ImiEALIcBdTGUtZ5QfK0/FashQyztba8Ol5N07zHcJZDgVhCoVD28ChjV1docIOlqaO8 pBCHmBqu9Bd92A2UOB3qnDqDWjmuqwXZ0wU0v8pPekt0QzGEefi3JAUGfHNc/1TzcEuy x/lOLsj4JRi/tzXLE2vw8+lxvEMFCNdG+bm/DUARALgA80I99yGofDLXyRG4H8d4FMn+ ZMTj+EIh/ke1i5PwP+ypwz+d9QUk0whcjDf8UMTd794K843Fyr7mWlKmyeqH5NDmCG9R A0/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RjF8k+hpX9AH/ezNK0riUGjUD2YIMsd6gzdiqYDfMl4=; b=Wm1P4mEcfQeiH7Z9tPRJsYHZRb96sktdAc/hJOGvSRYVRvsyLzLbMfHtzQUWzH1Yro AUXsjkmPz0vCvgmctPljYietY6/OlTlcWL4HeIWKpj8vfYBzhgfRTSa6XMD1DnQUQJi5 cHZ7t/nsqpRVtYao8RrZ2wbEIt08b+AJ8m39WCsaf7feKK1IlGm7okOlXh4Mecx2e0jS BMTpxi0HSyvYJOfK8uGbZN1Eb0s63m+KNWT50vM/oQU9At6waVHC5PYKvCuvj6ub7XRy 8ttcBpEMKuJLUskDNg11XRF1exw2jA99z3Og0adS2aHdCYM8m6Sw1rQ4oW3eY61azuRR tP1A== X-Gm-Message-State: AJIora/TlNI8jfGU23C3vf8WqXr/LvyTwwD0EIWW3SUfYJb4Mcpt9LId 8mw+wOd3+IIZZ4/m1pL3SMm9YPK3lFWvNw== X-Google-Smtp-Source: AGRyM1u+diJWiow1AS132ZiauRTjF4RNyschmMIWDqqg8AuteNWo5t3MqaI48rLW78zSwwslITsw6w== X-Received: by 2002:a63:3d85:0:b0:40c:f690:d759 with SMTP id k127-20020a633d85000000b0040cf690d759mr10005791pga.343.1656289186665; Sun, 26 Jun 2022 17:19:46 -0700 (PDT) Received: from fedora.. ([106.84.130.34]) by smtp.gmail.com with ESMTPSA id e11-20020a6558cb000000b00408b89e4282sm5715294pgu.47.2022.06.26.17.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jun 2022 17:19:46 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Hanna Reitz , dmitry.fomichev@wdc.com, Kevin Wolf , Fam Zheng , Stefan Hajnoczi , damien.lemoal@opensource.wdc.com, qemu-block@nongnu.org, Sam Li Subject: [RFC v3 2/5] qemu-io: add zoned block device operations. Date: Mon, 27 Jun 2022 08:19:14 +0800 Message-Id: <20220627001917.9417-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220627001917.9417-1-faithilikerun@gmail.com> References: <20220627001917.9417-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x536.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" --- block/io.c | 21 +++++++ include/block/block-io.h | 13 +++++ qemu-io-cmds.c | 121 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) diff --git a/block/io.c b/block/io.c index 789e6373d5..656a1b7271 100644 --- a/block/io.c +++ b/block/io.c @@ -3258,6 +3258,27 @@ out: return co.ret; } +int bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + int64_t len, int64_t *nr_zones, + BlockZoneDescriptor *zones) +{ + if (!bs->drv->bdrv_co_zone_report) { + return -ENOTSUP; + } + + return bs->drv->bdrv_co_zone_report(bs, offset, len, nr_zones, zones); +} + +int bdrv_co_zone_mgmt(BlockDriverState *bs, enum zone_op op, + int64_t offset, int64_t len) +{ + if (!bs->drv->bdrv_co_zone_mgmt) { + return -ENOTSUP; + } + + return bs->drv->bdrv_co_zone_mgmt(bs, op, offset, len); +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/include/block/block-io.h b/include/block/block-io.h index 62c84f0519..c85c174579 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -80,6 +80,13 @@ int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); /* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +/* Report zone information of zone block device. */ +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + int64_t len, int64_t *nr_zones, + BlockZoneDescriptor *zones); +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, zone_op op, + int64_t offset, int64_t len); + int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, @@ -290,6 +297,12 @@ bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int generated_co_wrapper bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); +int generated_co_wrapper blk_zone_report(BlockBackend *blk, int64_t offset, + int64_t len, int64_t *nr_zones, + BlockZoneDescriptor *zones); +int generated_co_wrapper blk_zone_mgmt(BlockBackend *blk, enum zone_op op, + int64_t offset, int64_t len); + /** * bdrv_parent_drained_begin_single: * diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 2f0d8ac25a..3f2592b9f5 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1706,6 +1706,122 @@ static const cmdinfo_t flush_cmd = { .oneline = "flush all in-core file state to disk", }; +static int zone_report_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len, nr_zones; + int i = 0; + + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ++optind; + nr_zones = cvtnum(argv[optind]); + + g_autofree BlockZoneDescriptor *zones = g_new(BlockZoneDescriptor, nr_zones); + ret = blk_zone_report(blk, offset, len, &nr_zones, zones); + while (i < nr_zones) { + fprintf(stdout, "start: 0x%lx, len 0x%lx, cap 0x%lx, wptr 0x%lx, " + "zcond:%u, [type: %u]\n", + zones[i].start, zones[i].length, zones[i].cap, zones[i].wp, + zones[i].cond, zones[i].type); + ++i; + } + return ret; +} + +static const cmdinfo_t zone_report_cmd = { + .name = "zone_report", + .altname = "f", + .cfunc = zone_report_f, + .argmin = 3, + .argmax = 3, + .args = "offset [offset..] len [len..] number [num..]", + .oneline = "report a number of zones", +}; + +static int zone_open_f(BlockBackend *blk, int argc, char **argv) +{ + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + return blk_zone_mgmt(blk, zone_open, offset, len); +} + +static const cmdinfo_t zone_open_cmd = { + .name = "zone_open", + .altname = "f", + .cfunc = zone_open_f, + .argmin = 2, + .argmax = 2, + .args = "offset [offset..] len [len..]", + .oneline = "explicit open a range of zones in zone block device", +}; + +static int zone_close_f(BlockBackend *blk, int argc, char **argv) +{ + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + return blk_zone_mgmt(blk, zone_close, offset, len); +} + +static const cmdinfo_t zone_close_cmd = { + .name = "zone_close", + .altname = "f", + .cfunc = zone_close_f, + .argmin = 2, + .argmax = 2, + .args = "offset [offset..] len [len..]", + .oneline = "close a range of zones in zone block device", +}; + +static int zone_finish_f(BlockBackend *blk, int argc, char **argv) +{ + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + return blk_zone_mgmt(blk, zone_finish, offset, len); +} + +static const cmdinfo_t zone_finish_cmd = { + .name = "zone_finish", + .altname = "f", + .cfunc = zone_finish_f, + .argmin = 2, + .argmax = 2, + .args = "offset [offset..] len [len..]", + .oneline = "finish a range of zones in zone block device", +}; + +static int zone_reset_f(BlockBackend *blk, int argc, char **argv) +{ + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + return blk_zone_mgmt(blk, zone_reset, offset, len); +} + +static const cmdinfo_t zone_reset_cmd = { + .name = "zone_reset", + .altname = "f", + .cfunc = zone_reset_f, + .argmin = 2, + .argmax = 2, + .args = "offset [offset..] len [len..]", + .oneline = "reset a zone write pointer in zone block device", +}; + + static int truncate_f(BlockBackend *blk, int argc, char **argv); static const cmdinfo_t truncate_cmd = { .name = "truncate", @@ -2498,6 +2614,11 @@ static void __attribute((constructor)) init_qemuio_commands(void) qemuio_add_command(&aio_write_cmd); qemuio_add_command(&aio_flush_cmd); qemuio_add_command(&flush_cmd); + qemuio_add_command(&zone_report_cmd); + qemuio_add_command(&zone_open_cmd); + qemuio_add_command(&zone_close_cmd); + qemuio_add_command(&zone_finish_cmd); + qemuio_add_command(&zone_reset_cmd); qemuio_add_command(&truncate_cmd); qemuio_add_command(&length_cmd); qemuio_add_command(&info_cmd); From patchwork Mon Jun 27 00:19:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1648526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=hd0frErw; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWT6t1Xytz9sGt for ; Mon, 27 Jun 2022 10:26:28 +1000 (AEST) Received: from localhost ([::1]:59116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5ca9-0006te-Hx for incoming@patchwork.ozlabs.org; Sun, 26 Jun 2022 20:26:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5cTp-0007WF-Sv; Sun, 26 Jun 2022 20:19:53 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:35600) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5cTo-0000bq-2X; Sun, 26 Jun 2022 20:19:53 -0400 Received: by mail-pl1-x630.google.com with SMTP id o18so6761679plg.2; Sun, 26 Jun 2022 17:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uCBSV1a3T0RavDWr47mBjoBHGiE4VvB7HcyvwccMHIE=; b=hd0frErwRGQz3O1CS7pf2b+VjSz5VNEsPY5IY5tww4JXsRYnuReC5Dxw8K8ceyMPu5 wPaZ6uaC+rpSxId183rpRX7cCO8Qs1KJMxvMFFJ50MfM3NYdHdrZrdG1Y4sNFvr/D2M8 At+LsWQGsHaGlfHInwbLYlIzP2yLYdBGxMOWov7dRj2CW0v4Px1SJY6DuPtic8hRvmEn XlFCFkco9rt2tD/pfDLrDEaqmZ07LYq/bMQpzUknhlPNKkQht5H1Ufb/XngWmNUyJws/ bB7yoyUwZynzpCVr47z7CP3CxGN44XF0n1ag/xYCiFRCgpWf+CRyaKmVkvDRwBE6yHZf TU5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uCBSV1a3T0RavDWr47mBjoBHGiE4VvB7HcyvwccMHIE=; b=fYM8rZC7HSEFkKXI06gisK3AWYfBeGZviVv5U0qcUKNrX4gFBp1Iw08oPlpE+ILrs6 g289v/5/BKPfLe2OaQjqFS1JaNihWq+WVWyEq/OtTHj7XzGc4Uan1UXKHYVpQ1hrPckz p4NPhGZvpZ1nEGZqLHP4aAAQIV8+o9xo+ovCmaTrnjhZgkmbN4BF3Ok/3K2irZBE1uUO IW2/quVjFd/iTYNy4E8NsL0EneXFOssjDTgkR98K5upMZrHlcDhRf+mrZU4uPSlYvo8e RhxrLs6pReOK5pSpGYP9tqD81hc2DAHS34BhB6wwgO0bXIQXIYun2WKFYAigLGYk2xZi 2Plg== X-Gm-Message-State: AJIora+pVrXjfS+p5/ZwLSN08JWCJD/9kjmQU+v7KpS9N5xx0ei2S2KF TfLhgo+IZi7KK3rXua6BJJ9QY7PVoqqfqQ== X-Google-Smtp-Source: AGRyM1vcDzXMhXJ7a2GAhUp1MlyZqh6RjcmIQX/zzJh5b/AKLRDyMAZ9vsQfOeKysdZNL1WUNQoxrg== X-Received: by 2002:a17:90a:6396:b0:1ec:f52d:90db with SMTP id f22-20020a17090a639600b001ecf52d90dbmr12747532pjj.52.1656289190224; Sun, 26 Jun 2022 17:19:50 -0700 (PDT) Received: from fedora.. ([106.84.130.34]) by smtp.gmail.com with ESMTPSA id e11-20020a6558cb000000b00408b89e4282sm5715294pgu.47.2022.06.26.17.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jun 2022 17:19:49 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Hanna Reitz , dmitry.fomichev@wdc.com, Kevin Wolf , Fam Zheng , Stefan Hajnoczi , damien.lemoal@opensource.wdc.com, qemu-block@nongnu.org, Sam Li Subject: [RFC v3 3/5] file-posix: introduce get_sysfs_long_val for zoned device information. Date: Mon, 27 Jun 2022 08:19:15 +0800 Message-Id: <20220627001917.9417-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220627001917.9417-1-faithilikerun@gmail.com> References: <20220627001917.9417-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x630.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" Use sysfs attribute files to get the zoned device information in case that ioctl() commands of zone management interface won't work. It can return long type of value like chunk_sectors, zoned_append_max_bytes, max_open_zones, max_active_zones. Reviewed-by: Hannes Reinecke --- block/file-posix.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 1b8b0d351f..73c2cdfbca 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1216,15 +1216,19 @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st) #endif } -static int hdev_get_max_segments(int fd, struct stat *st) -{ +/* + * Get zoned device information (chunk_sectors, zoned_append_max_bytes, + * max_open_zones, max_active_zones) through sysfs attribute files. + */ +static long get_sysfs_long_val(int fd, struct stat *st, + const char *attribute) { #ifdef CONFIG_LINUX char buf[32]; const char *end; char *sysfspath = NULL; int ret; int sysfd = -1; - long max_segments; + long val; if (S_ISCHR(st->st_mode)) { if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) == 0) { @@ -1237,8 +1241,9 @@ static int hdev_get_max_segments(int fd, struct stat *st) return -ENOTSUP; } - sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments", - major(st->st_rdev), minor(st->st_rdev)); + sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st->st_rdev), minor(st->st_rdev), + attribute); sysfd = open(sysfspath, O_RDONLY); if (sysfd == -1) { ret = -errno; @@ -1256,9 +1261,9 @@ static int hdev_get_max_segments(int fd, struct stat *st) } buf[ret] = 0; /* The file is ended with '\n', pass 'end' to accept that. */ - ret = qemu_strtol(buf, &end, 10, &max_segments); + ret = qemu_strtol(buf, &end, 10, &val); if (ret == 0 && end && *end == '\n') { - ret = max_segments; + ret = val; } out: @@ -1272,6 +1277,15 @@ out: #endif } +static int hdev_get_max_segments(int fd, struct stat *st) { + int ret; + ret = get_sysfs_long_val(fd, st, "max_segments"); + if (ret < 0) { + return -1; + } + return ret; +} + static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s = bs->opaque; @@ -1872,6 +1886,7 @@ static int handle_aiocb_zone_report(void *opaque) { static int handle_aiocb_zone_mgmt(void *opaque) { RawPosixAIOData *aiocb = opaque; + BlockDriverState *s = aiocb->bs; int fd = aiocb->aio_fildes; int64_t offset = aiocb->aio_offset; int64_t len = aiocb->aio_nbytes; @@ -1884,11 +1899,9 @@ static int handle_aiocb_zone_mgmt(void *opaque) { int64_t zone_size_mask; int ret; - ret = ioctl(fd, BLKGETZONESZ, &zone_size); - if (ret) { - return -1; - } - + g_autofree struct stat *file = g_new(struct stat, 1); + stat(s->filename, file); + zone_size = get_sysfs_long_val(fd, file, "chunk_sectors"); zone_size_mask = zone_size - 1; if (offset & zone_size_mask) { error_report("offset is not the start of a zone"); From patchwork Mon Jun 27 00:19:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1648522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=qPATO2Sk; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWT0P11mBz9sGt for ; Mon, 27 Jun 2022 10:20:53 +1000 (AEST) Received: from localhost ([::1]:47948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5cUl-0007dP-02 for incoming@patchwork.ozlabs.org; Sun, 26 Jun 2022 20:20:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5cTu-0007aF-K7; Sun, 26 Jun 2022 20:20:00 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:32983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5cTt-0000cC-25; Sun, 26 Jun 2022 20:19:58 -0400 Received: by mail-pj1-x102a.google.com with SMTP id i8-20020a17090aee8800b001ecc929d14dso9145995pjz.0; Sun, 26 Jun 2022 17:19:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DhnRgF9lt7hzXqkLaTIFS4codVu1vrUHflYtD4rxjHs=; b=qPATO2SkgnvroTVv/bkyU1lfey30y9qzTs6pfM2osDxLNlUFdF/aukQ9+KiiiA0rLW gr7VfpYQE9VzBXdK0kZ4wNt5j/ydErxy8YKHrl7A8vNqqu2LajuYdjUj+BPEu2cS5ZP+ T3P8DTZceJTVbCypLx+LVl1gKzsoxT3+LssEdKOr9TPbizffcOhQ0ip5EGfO3fktdled oqUM2NxIEm5b5k8x3TwMivCnJ+OWj3zs8+h2A0vYA1kYStiMiNTbs7+LOHnDj2Wfbn2h RJz7CxFsKIhxQqGvqbNHjqQaCU1o3ueASW8NMbk3VXVm3oMGb6kBXKlr4an/hZVM9gbX VpjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DhnRgF9lt7hzXqkLaTIFS4codVu1vrUHflYtD4rxjHs=; b=MZqoxMNih4tjGrootu8nDcsus7yn/J5eQuA/3IuE7fU9k4MkJF1mmfs6s5mCehLjD+ D6S2D3H9REMInowi6EezpgZmjiRTRd4iocU6fxKTU9zZm+YxGZA7CpqJckV293f0tC0z di32SDKtXxCHrMD8vREJd+UojI0QTYvn6ll4MA7U+iM4uJW6Hpc3aMRef7l4jfAmyEq8 q/tSnwtUcZv8O0EIcntGupOytkSQyEB3keCDAyV17OW3SeVePdkKNaaOkxWrtTm/ahoq FGvfKxwg0jScY0wg3VwXO7OOW43Sdyq+N3U0KtVImgFz9ztPGDfiMy6wyj10qm7qi9Yf +SfQ== X-Gm-Message-State: AJIora/ZrFaBYbm/tXsCvmszGIfKwbyeBrzCPBkPzqleexOUlVGkgiRz xSOxmYyldrVrP78s5QyMlTcOL+dYgS7m/g== X-Google-Smtp-Source: AGRyM1t3yfUwLJJnbeZ1PeoDUf/dtLrpAyLFfUn2BhbldTKbtr2nB37TcPpu8TCyF/DebWihqQxUrA== X-Received: by 2002:a17:90b:17d2:b0:1ec:be52:56e2 with SMTP id me18-20020a17090b17d200b001ecbe5256e2mr17009057pjb.207.1656289194375; Sun, 26 Jun 2022 17:19:54 -0700 (PDT) Received: from fedora.. ([106.84.130.34]) by smtp.gmail.com with ESMTPSA id e11-20020a6558cb000000b00408b89e4282sm5715294pgu.47.2022.06.26.17.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jun 2022 17:19:54 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Hanna Reitz , dmitry.fomichev@wdc.com, Kevin Wolf , Fam Zheng , Stefan Hajnoczi , damien.lemoal@opensource.wdc.com, qemu-block@nongnu.org, Sam Li Subject: [RFC v3 4/5] file-posix: introduce get_sysfs_str_val for device zoned model. Date: Mon, 27 Jun 2022 08:19:16 +0800 Message-Id: <20220627001917.9417-5-faithilikerun@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220627001917.9417-1-faithilikerun@gmail.com> References: <20220627001917.9417-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x102a.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" --- block/file-posix.c | 60 ++++++++++++++++++++++++++++++++++++ include/block/block-common.h | 4 +-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 73c2cdfbca..74c0245e0f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1277,6 +1277,66 @@ out: #endif } +/* + * Convert the zoned attribute file in sysfs to internal value. + */ +static zone_model get_sysfs_str_val(int fd, struct stat *st) { +#ifdef CONFIG_LINUX + char buf[32]; + char *sysfspath = NULL; + int ret; + int sysfd = -1; + + if (S_ISCHR(st->st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) == 0) { + return ret; + } + return -ENOTSUP; + } + + if (!S_ISBLK(st->st_mode)) { + return -ENOTSUP; + } + + sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/zoned", + major(st->st_rdev), minor(st->st_rdev)); + sysfd = open(sysfspath, O_RDONLY); + if (sysfd == -1) { + ret = -errno; + goto out; + } + do { + ret = read(sysfd, buf, sizeof(buf) - 1); + } while (ret == -1 && errno == EINTR); + if (ret < 0) { + ret = -errno; + goto out; + } else if (ret == 0) { + ret = -EIO; + goto out; + } + buf[ret] = 0; + + /* The file is ended with '\n' */ + if (strcmp(buf, "host-managed\n") == 0) { + return BLK_Z_HM; + } else if (strcmp(buf, "host-aware\n") == 0) { + return BLK_Z_HA; + } else { + return -ENOTSUP; + } + +out: + if (sysfd != -1) { + close(sysfd); + } + g_free(sysfspath); + return ret; +#else + return -ENOTSUP; +#endif +} + static int hdev_get_max_segments(int fd, struct stat *st) { int ret; ret = get_sysfs_long_val(fd, st, "max_segments"); diff --git a/include/block/block-common.h b/include/block/block-common.h index 78cddeeda5..35e00afe8e 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -56,8 +56,8 @@ typedef enum zone_op { } zone_op; typedef enum zone_model { - BLK_Z_HM, - BLK_Z_HA, + BLK_Z_HM = 0x1, + BLK_Z_HA = 0x2, } zone_model; typedef enum BlkZoneCondition { From patchwork Mon Jun 27 00:19:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1648525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=aWXAjIFR; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWT450mhZz9sGt for ; Mon, 27 Jun 2022 10:24:05 +1000 (AEST) Received: from localhost ([::1]:56116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5cXq-0004pK-Vg for incoming@patchwork.ozlabs.org; Sun, 26 Jun 2022 20:24:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5cTx-0007cC-23; Sun, 26 Jun 2022 20:20:01 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:38407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5cTv-0000cT-JI; Sun, 26 Jun 2022 20:20:00 -0400 Received: by mail-pg1-x529.google.com with SMTP id e63so7606141pgc.5; Sun, 26 Jun 2022 17:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aQauG1xPWeXI+3hfKGKaEx5Uo9MpNuqh+ACmDAc1ZzE=; b=aWXAjIFRFoUn1lu8WZWdcitgCH70rSMTKMWc5IsK+JeYA02NIgA8xYNCYJmmzucPrV JPKWXNlWXa67SlnQ8jL0CzfqxELvsZtcvb57pDLqn0d9vU5qfvV76toaAJm3IDiXDZ7W BDfqvUnEP9PqgZmiwf+TJISXkMGHuhgEciYNiGHk+ZmirDQt/0tn8nOP1Ziu33G8MsqQ df72ZTs91teS4nJIUTm+qCSQtPlzT8WH1JUFL6kCbVBBshwacxjArI5TtA8Dt7U5Nav+ lV/ZR1fc95B2/S7j/8oXyKAH5glc1juY+c7J0SQ30r0aNErKNZwR1dNC24bkthzfSUJl H4uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aQauG1xPWeXI+3hfKGKaEx5Uo9MpNuqh+ACmDAc1ZzE=; b=35qSKQ20d/spti7xnycZq2BBR4nc1yl2u246ggbk41xMB9uo8nnCHZE8sXmS7N0c0N cD9r0LwKnoM9y1h5gwCL9PI8Mddyc5y+2Gtt9BBiHz61XQU5J1TcCtrqDk0QTXZ0YPtb 9DNaaL2fpa94ZPGNluQyXJ1vBvOYAEaoknRqx59g+cC2RO/l1CXyU/ZOygZngRTPaXBq cQwcO5CUskiIKXPbBqhid2vVouuWXjMRUUN7pGBKmNbqWK3o9KZQ/A7N+1pg9aIm/zE4 JyJ5rAMrN9CNWz1JtpGDXVTl9WppM02UaPQTGP1omlKARjec0eunv4PrP7ZRJKTziEPU t6Fg== X-Gm-Message-State: AJIora/gkI6qYCKqxW71cINCHyRHl+mgug6NiGmB8wISg7ZM2o4GEINW cYCkiwOxKqabeqos7H6Ec2kBHkGul8fxWQ== X-Google-Smtp-Source: AGRyM1ug3HIg7eEB+p9y1Swwh5+5wajVhKElOIz86ty7UaREXqjw5gmd3YxxE6YK68d3IHEMbU0GPA== X-Received: by 2002:a63:454c:0:b0:40d:ffa7:9dc4 with SMTP id u12-20020a63454c000000b0040dffa79dc4mr1596506pgk.500.1656289197881; Sun, 26 Jun 2022 17:19:57 -0700 (PDT) Received: from fedora.. ([106.84.130.34]) by smtp.gmail.com with ESMTPSA id e11-20020a6558cb000000b00408b89e4282sm5715294pgu.47.2022.06.26.17.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jun 2022 17:19:57 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Hanna Reitz , dmitry.fomichev@wdc.com, Kevin Wolf , Fam Zheng , Stefan Hajnoczi , damien.lemoal@opensource.wdc.com, qemu-block@nongnu.org, Sam Li Subject: [RFC v3 5/5] qemu-iotests: add zone operation tests. Date: Mon, 27 Jun 2022 08:19:17 +0800 Message-Id: <20220627001917.9417-6-faithilikerun@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220627001917.9417-1-faithilikerun@gmail.com> References: <20220627001917.9417-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x529.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" --- tests/qemu-iotests/tests/zoned.sh | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 tests/qemu-iotests/tests/zoned.sh Reviewed-by: Hannes Reinecke diff --git a/tests/qemu-iotests/tests/zoned.sh b/tests/qemu-iotests/tests/zoned.sh new file mode 100755 index 0000000000..262c0b5427 --- /dev/null +++ b/tests/qemu-iotests/tests/zoned.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# +# Test zone management operations. +# + +QEMU_IO="build/qemu-io" +IMG="--image-opts driver=zoned_host_device,filename=/dev/nullb0" +QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT + +echo "Testing a null_blk device" +echo "Simple cases: if the operations work" +sudo modprobe null_blk nr_devices=1 zoned=1 +# hidden issues: +# 1. memory allocation error of "unaligned tcache chunk detected" when the nr_zone=1 in zone report +# 2. qemu-io: after report 10 zones, the program failed at double free error and exited. +echo "report the first zone" +sudo $QEMU_IO $IMG -c "zone_report 0 0 1" +echo "report: the first 10 zones" +sudo $QEMU_IO $IMG -c "zone_report 0 0 10" + +echo "open the first zone" +sudo $QEMU_IO $IMG -c "zone_open 0 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zone_report 0 0 1" +echo "open the last zone" +sudo $QEMU_IO $IMG -c "zone_open 0x3e70000000 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zone_report 0x3e70000000 0 2" + +echo "close the first zone" +sudo $QEMU_IO $IMG -c "zone_close 0 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zone_report 0 0 1" +echo "close the last zone" +sudo $QEMU_IO $IMG -c "zone_close 0x3e70000000 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zone_report 0x3e70000000 0 2" + + +echo "reset the second zone" +sudo $QEMU_IO $IMG -c "zone_reset 0x80000 0x80000" +echo "After resetting a zone:" +sudo $QEMU_IO $IMG -c "zone_report 0x80000 0 5" + +# success, all done +sudo rmmod null_blk +echo "*** done" +#rm -f $seq.full +status=0