From patchwork Tue Jul 12 02:13:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655164 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=VA/FOMFe; 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 4Lhktp5f4wz9s07 for ; Tue, 12 Jul 2022 12:18:10 +1000 (AEST) Received: from localhost ([::1]:44594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5TT-0005K4-KY for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:18:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5PU-0000qc-Jn; Mon, 11 Jul 2022 22:14:01 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:40473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5PS-0007xo-AQ; Mon, 11 Jul 2022 22:14:00 -0400 Received: by mail-pf1-x42c.google.com with SMTP id y141so6286573pfb.7; Mon, 11 Jul 2022 19:13:57 -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=/tZHFm+mPHr7tsG3wFfR5uJwssz9W71PC8P9nLV3z3Q=; b=VA/FOMFeE620hc6wR1TB7E/CWaS/rr+ljLIuO0+M9X3aIwfdM5qd+ecM0PCtX2iqfU 8o0bpZvQqIqrNSGqLSIsu0R8NL3IbTukw8nvQjVrk9O1+z4SMTeE1C6KdgZkn4DD/icN VDjcv5gMeBTWJCMirAyhDpIqS/ewOqoKNflr/vwY9YXGZe3HvBD4nRwy4r8zBJm6HsYJ ZIJQwEgluP9vlYHIiXjnw1G51lTKsdLpvmj53Le+eepCyhOR3/aCgUnKsNK8Klm2ZfpU Zbh3AKLNTAX09PsdOGNSRjOzvxksSQEA7RgYPqtKvL3xvjT+BUBBWi4Q/hXSxm+Lyc2M FhNg== 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=/tZHFm+mPHr7tsG3wFfR5uJwssz9W71PC8P9nLV3z3Q=; b=DVSX+xYbm8erDoxyfLr0rmyDnrmHMaVCjTS8nE7lP5bXLemJyVh4iM1uqSKBfYtZFQ HbEB5zZg4WU5ghpDV+Csn2wiyHwamhHU/uIksL92cm30+UJWNxG/AURDobPXs/ZhSUeL jRskic8DLLQ3U+opMPExF82i2ODsvl8MvgxXZzwSTt7aUPAE18XfHIFLTD8oCoXib5aY GvXg8iiFHxnW2Jy9Df8Ym78E60JVwvpAu4rTAb7jAxHtt5bjRKL6S5EBh9DYIH5/U1V/ cKT8HTa4eobXV/nieNpBX1AUoa6HBdfE9g8nSwcLaiJIB4P2FJ+e8LuNNXXW1EUioMuw xqiw== X-Gm-Message-State: AJIora+ENMIl4SkFJ7gqvqCXuEIRx+Zm3wMCo3EcrNbSRRuM1Ol4z3E0 1R9xIoJNWIKMnAl0ATwjPwqa8Q7zJEqeo65F X-Google-Smtp-Source: AGRyM1vIhOeun0Iw5ym/ZA6Z1MwohjFQCjdAPAMl5jFIG5Mu4nJcDLPiM+4z9okJfH4T0poacXkbMw== X-Received: by 2002:a65:6e41:0:b0:412:4c1f:9936 with SMTP id be1-20020a656e41000000b004124c1f9936mr18952035pgb.455.1657592035971; Mon, 11 Jul 2022 19:13:55 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:13:55 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 1/9] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls. Date: Tue, 12 Jul 2022 10:13:37 +0800 Message-Id: <20220712021345.8530-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x42c.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). Signed-off-by: Sam Li --- block/block-backend.c | 41 ++++++ block/coroutines.h | 5 + block/file-posix.c | 236 +++++++++++++++++++++++++++++++ include/block/block-common.h | 43 +++++- include/block/block_int-common.h | 20 +++ 5 files changed, 344 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index f425b00793..0a05247ae4 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1806,6 +1806,47 @@ int blk_flush(BlockBackend *blk) return ret; } +/* + * Send a zone_report command. + * offset can be any number within the zone size. No alignment for offset. + * nr_zones represents IN maximum and OUT actual. + */ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + int64_t *nr_zones, + BlockZoneDescriptor *zones) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); /* increase before waiting */ + blk_wait_while_drained(blk); + ret = bdrv_co_zone_report(blk->root->bs, offset, nr_zones, zones); + blk_dec_in_flight(blk); + return ret; +} + +/* + * Send a zone_management command. + * 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; + IO_CODE(); + + blk_inc_in_flight(blk); + blk_wait_while_drained(blk); + ret = blk_check_byte_request(blk, offset, len); + if (ret < 0) { + return ret; + } + + ret = bdrv_co_zone_mgmt(blk->root->bs, op, offset, len); + 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..19aa96cc56 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 *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..e7523ae2ed 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,13 @@ typedef struct RawPosixAIOData { PreallocMode prealloc; Error **errp; } truncate; + struct { + int64_t *nr_zones; + BlockZoneDescriptor *zones; + } zone_report; + struct { + zone_op op; + } zone_mgmt; }; } RawPosixAIOData; @@ -1801,6 +1809,130 @@ 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; + + struct blk_zone *blkz; + int64_t rep_size, nrz; + int ret, n = 0, i = 0; + + nrz = *nr_zones; + 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); + 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->zone_mgmt.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; + + g_autofree struct stat *file = NULL; + 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"); + return -EINVAL; + } + + if (len & zone_size_mask) { + error_report("len is not aligned to zones"); + return -EINVAL; + } + + 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); + return -EINVAL; + } + + /* 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 -errno; + } + + return 0; +} + static int handle_aiocb_copy_range(void *opaque) { RawPosixAIOData *aiocb = opaque; @@ -2973,6 +3105,59 @@ 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 *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, + .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, + .zone_mgmt = { + .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 +3509,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 +3891,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 +4199,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..6037871089 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 *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 Tue Jul 12 02:13:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655163 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=lqySzhBI; 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 4Lhktf5LYGz9s07 for ; Tue, 12 Jul 2022 12:18:02 +1000 (AEST) Received: from localhost ([::1]:44358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5TM-0005AD-JS for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:18:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5PX-0000rz-JJ; Mon, 11 Jul 2022 22:14:04 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:47088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5PV-0007yH-Kt; Mon, 11 Jul 2022 22:14:03 -0400 Received: by mail-pj1-x1030.google.com with SMTP id t5-20020a17090a6a0500b001ef965b262eso6573811pjj.5; Mon, 11 Jul 2022 19:14:00 -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=C4nHElRN8Z9bhFfHXmoqX/Uwi2blG90mk7XLJXN33h8=; b=lqySzhBIOCCmXpIIGuYmcMeF+HoNCvJmja2hzTyLnRkW1iddiLfQNhcmQiJlgLlEZZ Q8kKn0EdFrqgKFA0j9iQKzAisDz+gGNYRQaVmzcfEzerht8nimAbwHF32EKP4b5mswo0 ziIaaLzFSuCkAsmZUaFQQALDKNQcDfEpFVfdQ1Y85Js9SYNxkGF1UaMAbaBhex4DVuu2 iyiKhxMwVOgehPiMTnxi2jN/TbW6g5F5JEgXi316iHel4AuM1WF0m73ALDz4F0KTehoM uzG7Tsrj91eCSOzlMF8A8nWFT73SYMuniEK3UCPoC8WHn2DDxaQh12p1+hNHyvn4FEjY ydDg== 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=C4nHElRN8Z9bhFfHXmoqX/Uwi2blG90mk7XLJXN33h8=; b=GCn/DyblO5ljDz9MVwp6Z8PkCV8ppHg7WkeMdKPghzVYLzJyb9KGMzYIEdJ9iRJJih 78Lix6XwspqomYZuTSbHbj4AEpyfKa1iIw3c7VFAC2g1D5mLyK5CYTRd1634nKQfU81k fjdqWuvX+bmgp61YiBMM+W15Sg/ZKkFKn9YkHPtpF+tzuqYvxyos8TPy2o1N9fexi1RW REeyMSdxC4g0HhAsFLpqZat5vifIPkmJTksE/6Wz2N0GNJFiDW8sh632Ih/8Li72OSrz 3g+sLayU+33Z6t/wZDHhX/B0NRewb/uADX1J3j1OiyUI0500MjYddRMfncyDdaGmtxpZ tl8A== X-Gm-Message-State: AJIora/JOzTyxbqCJyhgRxz/ycEm0LTVGP1Ki99Zb6ge9j5L+JgloyMw t+kT+7Mahcr6SAq5J4lE3v7yF8e++8cmu/1u X-Google-Smtp-Source: AGRyM1vXEcMDGd99KyRoTf7kE6lY0l68tD20MU6moBy7YTCQ2EUi4R6L83SqAxCnLKauavILnIWfvg== X-Received: by 2002:a17:90b:3b51:b0:1f0:5ebc:ac9 with SMTP id ot17-20020a17090b3b5100b001f05ebc0ac9mr893960pjb.229.1657592039759; Mon, 11 Jul 2022 19:13:59 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:13:59 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 2/9] qemu-io: add zoned block device operations. Date: Tue, 12 Jul 2022 10:13:38 +0800 Message-Id: <20220712021345.8530-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1030.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" Add zoned storage commands of the device: zone_open(zo), zone_close(zc), zone_reset(zs), zone_report(zp), zone_finish(zf). For example, it can be called by: ./build/qemu-io --image-opts driver=zoned_host_device, filename=/dev/nullb0 -c "zone_report 0 0 1" Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke --- block/io.c | 57 ++++++++++++++++ include/block/block-io.h | 13 ++++ qemu-io-cmds.c | 143 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) diff --git a/block/io.c b/block/io.c index 1e9bf09a49..a760be0131 100644 --- a/block/io.c +++ b/block/io.c @@ -3243,6 +3243,63 @@ out: return co.ret; } +int bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + int64_t *nr_zones, + BlockZoneDescriptor *zones) +{ + BlockDriver *drv = bs->drv; + CoroutineIOCompletion co = { + .coroutine = qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || (!drv->bdrv_co_zone_report)) { + co.ret = -ENOTSUP; + goto out; + } + + if (drv->bdrv_co_zone_report) { + co.ret = drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); + } else { + co.ret = -ENOTSUP; + goto out; + qemu_coroutine_yield(); + } + +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int bdrv_co_zone_mgmt(BlockDriverState *bs, enum zone_op op, + int64_t offset, int64_t len) +{ + BlockDriver *drv = bs->drv; + CoroutineIOCompletion co = { + .coroutine = qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || (!drv->bdrv_co_zone_mgmt)) { + co.ret = -ENOTSUP; + goto out; + } + + if (drv->bdrv_co_zone_mgmt) { + co.ret = drv->bdrv_co_zone_mgmt(bs, op, offset, len); + } else { + co.ret = -ENOTSUP; + goto out; + qemu_coroutine_yield(); + } + +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + 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 053a27141a..a0ae140452 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 *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, @@ -289,6 +296,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 *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..a88fa322d2 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1706,6 +1706,144 @@ 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, nr_zones; + + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + nr_zones = cvtnum(argv[optind]); + + g_autofree BlockZoneDescriptor *zones = NULL; + zones = g_new(BlockZoneDescriptor, nr_zones); + ret = blk_zone_report(blk, offset, &nr_zones, zones); + if (ret < 0) { + printf("zone report failed: %s\n", strerror(-ret)); + } else { + for (int i = 0; i < nr_zones; ++i) { + printf("start: 0x%" PRIx64 ", len 0x%" PRIx64 ", " + "cap"" 0x%" PRIx64 ",wptr 0x%" PRIx64 ", " + "zcond:%u, [type: %u]\n", + zones[i].start, zones[i].length, zones[i].cap, zones[i].wp, + zones[i].cond, zones[i].type); + } + } + return ret; +} + +static const cmdinfo_t zone_report_cmd = { + .name = "zone_report", + .altname = "zp", + .cfunc = zone_report_f, + .argmin = 2, + .argmax = 2, + .args = "offset number", + .oneline = "report zone information", +}; + +static int zone_open_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ret = blk_zone_mgmt(blk, zone_open, offset, len); + if (ret < 0) { + printf("zone open failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_open_cmd = { + .name = "zone_open", + .altname = "zo", + .cfunc = zone_open_f, + .argmin = 2, + .argmax = 2, + .args = "offset len", + .oneline = "explicit open a range of zones in zone block device", +}; + +static int zone_close_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ret = blk_zone_mgmt(blk, zone_close, offset, len); + if (ret < 0) { + printf("zone close failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_close_cmd = { + .name = "zone_close", + .altname = "zc", + .cfunc = zone_close_f, + .argmin = 2, + .argmax = 2, + .args = "offset len", + .oneline = "close a range of zones in zone block device", +}; + +static int zone_finish_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ret = blk_zone_mgmt(blk, zone_finish, offset, len); + if (ret < 0) { + printf("zone finish failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_finish_cmd = { + .name = "zone_finish", + .altname = "zf", + .cfunc = zone_finish_f, + .argmin = 2, + .argmax = 2, + .args = "offset len", + .oneline = "finish a range of zones in zone block device", +}; + +static int zone_reset_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ret = blk_zone_mgmt(blk, zone_reset, offset, len); + if (ret < 0) { + printf("zone reset failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_reset_cmd = { + .name = "zone_reset", + .altname = "zrs", + .cfunc = zone_reset_f, + .argmin = 2, + .argmax = 2, + .args = "offset 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 +2636,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 Tue Jul 12 02:13:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655161 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=dZDnoBis; 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 4Lhkqn6kd5z9s07 for ; Tue, 12 Jul 2022 12:15:33 +1000 (AEST) Received: from localhost ([::1]:39182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5Qx-0001TW-Pv for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:15:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5Pb-0000uk-0k; Mon, 11 Jul 2022 22:14:07 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:40715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5PZ-0007yv-DO; Mon, 11 Jul 2022 22:14:06 -0400 Received: by mail-pj1-x1033.google.com with SMTP id g16-20020a17090a7d1000b001ea9f820449so10041968pjl.5; Mon, 11 Jul 2022 19:14:04 -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=X6UnQvN3OLOVsFUsNq31Hyp6m/tlEpJBxogdQyEOF0s=; b=dZDnoBisiFSaZtf2sKxaKEoW0fFNoDs0TnEhE+ZumeFGt3Y3ROSimO9YxoWRqf6Jn+ v4X6lkyB8wEOzSuW48XqFiUSSqOvvJJAYt3k7khNakzyRlmEXbI/GnnD3f5q/Z3hBwbU 95KuSG7C4qwGiYkXtCiSM3PaV4Iy8zu0O52X7czfhLHHP/kNeD/FQIPX6irJFSJVytQE Qwijpy5OYMe2mOPKVuqYcCTj+rhuKkEBubQbxmK6Su4TuYz8dwRrkLuxBSYGqnB2ORCD cSUrwxKZ9+YmG7WYsdulRm353ozJDLDxusdehQzDeWMBvnCV2l0sMZpir9Tifynwy6vh 0JGg== 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=X6UnQvN3OLOVsFUsNq31Hyp6m/tlEpJBxogdQyEOF0s=; b=awZ8onYRApvHs8zUQ3OPKEOWNyIOIzRnUvviIM5Ch5aet41+YgSurNzWMxVgUKOV2A J85WHmdrJQwU6lwECHb7JY5XYTg3VXicd152VfdrynamOGW+umfeHwjDmuP4lu0/L8t0 cgx3+0RYHoODgIEc7emJqo7U1JtxZw2D+Y926ezn/+NjKAsp0bUanfBzkp+3QyGVMh1+ 7x0jtvpOSmHZEGOIJq5C67o/ZxaGSNrlDgj1bq/BbQpBc04OkjI+IrBzkRmUEglPEFV9 iInChLhwm0Q9H5XPFEzCNNc9SnsixQc+onw6Dxg36BfaMi/9mdoLoQT36KGd0LodVn17 xBtQ== X-Gm-Message-State: AJIora/rFly/qeiDlp4rRyCe19xovOA6wiK12StvDssgt9EIx6hiV8nI r2Hs/BVEkGuGYs5OZaKX26E/Et+qLD1nHim8 X-Google-Smtp-Source: AGRyM1tmhv8Z/292CrWuxRK8pJ5PGO1yww1pegunr3sJ390+7fBG3++dhWHndRvQV1bT8L89WDNMeA== X-Received: by 2002:a17:90b:4c0f:b0:1f0:3dba:bdb0 with SMTP id na15-20020a17090b4c0f00b001f03dbabdb0mr1580379pjb.6.1657592043601; Mon, 11 Jul 2022 19:14:03 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:14:03 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 3/9] file-posix: introduce get_sysfs_long_val for a block queue of sysfs attribute Date: Tue, 12 Jul 2022 10:13:39 +0800 Message-Id: <20220712021345.8530-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1033.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. Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke --- block/file-posix.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index e7523ae2ed..3161d39ea4 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1218,15 +1218,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) { @@ -1239,8 +1243,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; @@ -1258,9 +1263,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: @@ -1274,6 +1279,10 @@ out: #endif } +static int hdev_get_max_segments(int fd, struct stat *st) { + return get_sysfs_long_val(fd, st, "max_segments"); +} + static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s = bs->opaque; @@ -1883,10 +1892,17 @@ static int handle_aiocb_zone_mgmt(void *opaque) { int64_t zone_size_mask; int ret; - g_autofree struct stat *file = NULL; - file = g_new(struct stat, 1); - stat(s->filename, file); - zone_size = get_sysfs_long_val(fd, file, "chunk_sectors"); + struct stat file; + if (fstat(fd, &file) < 0) { + return -errno; + } + mod = get_sysfs_str_val(fd, &file); + if (mod != BLK_Z_HM) { + ret = -ENOTSUP; + return ret; + } + + 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 Tue Jul 12 02:13:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655167 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=akr+G9tM; 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 4Lhkwx5SKcz9s07 for ; Tue, 12 Jul 2022 12:20:00 +1000 (AEST) Received: from localhost ([::1]:47502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5VE-0007PO-Sh for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:19:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5Pe-0000vq-RF; Mon, 11 Jul 2022 22:14:12 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:35769) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5Pd-0007zK-Aa; Mon, 11 Jul 2022 22:14:10 -0400 Received: by mail-pl1-x62f.google.com with SMTP id g13so1089565plh.2; Mon, 11 Jul 2022 19:14:08 -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=hPoBlU6VEZ9/MBaZgZCAm+WFSPnS8MEgQJKdwtPiJww=; b=akr+G9tMYn2cOi2u8YgHSwuPWbYg0ShqDnlaX8j5o+zy+SJEtERJg9EqUqPA/19IZw AV1POeYqmCUQvsgr5yE541hb7Qp0JRaQFIvx8UKqcqeTBEiT1p4w6k3O4AO2lUGA7WXR dcsTakqvgFAG3yxpN8Lp0R5nXLKux8TepBUWhTcqYeLrHbn+A5Klwc0qsBdAVADUsUpe 94oACk3yV4XFT7/7X63MfZ7moWoyA7xyGQkg2tT3QY17lxoI1MblJ/aB3vnviUnLJ+Fj 7D8M814MV+bFdKph6Ix/gLOHkxbL8939K+WIk6R8zfM9oKvjZSbjP7pp1EYZggoAtigr hyUQ== 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=hPoBlU6VEZ9/MBaZgZCAm+WFSPnS8MEgQJKdwtPiJww=; b=bw/2rOEPRkWOM+yeYBAAeCkinKcde1DFzDwgDz8WBhj6anid6FPXQOfi1FhMcGWAah 6r2e54YnHMEEBpQ8dWIgIYFbzmVOW0v39JcVrz1AU+dRus2nmmZCPio47fOFnrP/Nrem 2RELE3Hx0D7YBgOEJQLlvWp1Iny87FSqQ16rgNc9TV6OetLE/GBQxX3t6lFNLq1/r4VU yCwKPrb0iExHw5FaZB1//3WUf+3t9o9+uVDA5AmbZe2fBZlPzeAAA3l/uAA83aV9zgwl vU2aZoGHiw0/ahREQL/PzRKcF9Pq5AF9AE8WRANB2RJ89pzPXd9U1xVH8izXFGlCmJaY DY4g== X-Gm-Message-State: AJIora+pyEyRXLHFq932VXV5DzJ4XVfXchttcMqvq9qi7VgxD70e4GZa bSrLSnWNxeYp6l9F0/SDdZ+240dEzWcK7jka X-Google-Smtp-Source: AGRyM1s6hYKYIg4JStjdBFTWXYTK5HeavaV2pUjmY0PdeO9rKBfkl9thep2yc1yGEiKO2CMa8QqD3g== X-Received: by 2002:a17:90b:4c48:b0:1ef:c839:c68c with SMTP id np8-20020a17090b4c4800b001efc839c68cmr1503260pjb.233.1657592047381; Mon, 11 Jul 2022 19:14:07 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:14:07 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 4/9] file-posix: introduce get_sysfs_str_val for device zoned model. Date: Tue, 12 Jul 2022 10:13:40 +0800 Message-Id: <20220712021345.8530-5-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x62f.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" Signed-off-by: Sam Li --- 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 3161d39ea4..42708012ff 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1279,6 +1279,65 @@ 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, offset; + 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; + } + offset = 0; + do { + ret = read(sysfd, buf + offset, sizeof(buf) - 1 + offset); + if (ret > 0) { + offset += ret; + } + } while (ret == -1); + /* The file is ended with '\n' */ + if (buf[ret - 1] == '\n') { + buf[ret - 1] = '\0'; + } + + if (strcmp(buf, "host-managed") == 0) { + return BLK_Z_HM; + } else if (strcmp(buf, "host-aware") == 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) { return get_sysfs_long_val(fd, st, "max_segments"); } @@ -1885,6 +1944,7 @@ static int handle_aiocb_zone_mgmt(void *opaque) { int64_t len = aiocb->aio_nbytes; zone_op op = aiocb->zone_mgmt.op; + zone_model mod; struct blk_zone_range range; const char *ioctl_name; unsigned long ioctl_op; 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 Tue Jul 12 02:13:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655168 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=LtIVi7p9; 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 4LhkzN5qsJz9s07 for ; Tue, 12 Jul 2022 12:22:08 +1000 (AEST) Received: from localhost ([::1]:53068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5XK-00030r-H7 for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:22:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5Pk-0000y8-O6; Mon, 11 Jul 2022 22:14:18 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:44988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5Pi-0007xZ-0d; Mon, 11 Jul 2022 22:14:16 -0400 Received: by mail-pg1-x529.google.com with SMTP id bf13so6294562pgb.11; Mon, 11 Jul 2022 19:14:11 -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=QDjrm0H7uHOnTUuOuooiPn3aOFoherhF8zUE9XmuL88=; b=LtIVi7p94WuIQ52U/gPGAa/TFO96Do0KvQOu0d5mWOpAXq0gZyGY/aGAgwsl4NF4Bg e7z39ceIYc9hDXYjnz9v8IQX37hNIzgswuSb+9YmXtfnVvzxqFKZhnbKcW6X8kaMyIXP jUsiEfZEhB/1HktnX5Cc5AoG94m3+PjvXZireg+GsGzXKGFgnNn91/KyhgxWnSt2oGmL BRfGr+ikOHIXk8mxbjjRqzfo0JWfD0LJK3EmBlsPfZMdA13c6XmGXWCEWnvxIjDnSgNp TKsoEbGCgbgFtySCHSOcxiL2rGMFW4UNxyvS0B6uuV0CflGzmZ73dqKPBXIcOZ1++TIR fgeg== 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=QDjrm0H7uHOnTUuOuooiPn3aOFoherhF8zUE9XmuL88=; b=0TbsPVvYz3nT+42gNwi5XGLN4TkmTFX4Lw/5qekBIleOWg3thwyOs3315bQjvD4wls qndCgdrCWi8f9NU5o6sA7JKeqhlvfpcxPb646lmER1Qvntw1a7sLTJaM3CGGeuUW4/il wh2dLUxlkbmTlKu+vm4skDwyWKH1oWDIDpBw06qUO8PUiIGS2vgGWuAlIXnsvuCZ0iMx 8VGPuBZplM0RXuvEKHAR2zosVVF/GhUQygVTFdHOBxJRokhTT5QXlszulxSBYW/vfHWG XZviTvoMPEkhPWPfkzq5/xaYqRBtdIIxlSjkH5WGvBD1N9nLaezSEnOu8fTXzksZJQ0C yycg== X-Gm-Message-State: AJIora9A7c5J7CpgUR3571uMT2ugzXQBr0xZTy2ym0f10NveDs8H9ixu 3RFseMVbtZjGSxBpMAsZxFOvx5L+S0K4y7fL X-Google-Smtp-Source: AGRyM1tpksMFeuWGmUdWJl0St15+/XCB5D+MYNUqTr66K1+3g9SPzqZl8HICOBMAyGaT/7E8CiSbvg== X-Received: by 2002:a63:ea55:0:b0:412:290c:9694 with SMTP id l21-20020a63ea55000000b00412290c9694mr18762569pgk.39.1657592051149; Mon, 11 Jul 2022 19:14:11 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:14:10 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 5/9] qemu-iotests: test new zone operations. Date: Tue, 12 Jul 2022 10:13:41 +0800 Message-Id: <20220712021345.8530-6-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-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" We have added new block layer APIs of zoned block devices. Test it with: (1) Create a null_blk device, run each zone operation on it and see whether reporting right zone information. Signed-off-by: Sam Li --- tests/qemu-iotests/tests/zoned.sh | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 tests/qemu-iotests/tests/zoned.sh diff --git a/tests/qemu-iotests/tests/zoned.sh b/tests/qemu-iotests/tests/zoned.sh new file mode 100755 index 0000000000..e14a3a420e --- /dev/null +++ b/tests/qemu-iotests/tests/zoned.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# +# Test zone management operations. +# + +seq="$(basename $0)" +echo "QA output created by $seq" +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + sudo rmmod null_blk +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.qemu + +# This test only runs on Linux hosts with raw image files. +_supported_fmt raw +_supported_proto file +_supported_os Linux + +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 "zr 0 0 1" +echo "report: the first 10 zones" +sudo $QEMU_IO $IMG -c "zr 0 0 10" + +echo "open the first zone" +sudo $QEMU_IO $IMG -c "zo 0 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zr 0 0 1" +echo "open the last zone" +sudo $QEMU_IO $IMG -c "zo 0x3e70000000 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zr 0x3e70000000 0 2" + +echo "close the first zone" +sudo $QEMU_IO $IMG -c "zc 0 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zr 0 0 1" +echo "close the last zone" +sudo $QEMU_IO $IMG -c "zc 0x3e70000000 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zr 0x3e70000000 0 2" + + +echo "reset the second zone" +sudo $QEMU_IO $IMG -c "zrs 0x80000 0x80000" +echo "After resetting a zone:" +sudo $QEMU_IO $IMG -c "zr 0x80000 0 5" + +# success, all done +echo "*** done" +rm -f $seq.full +status=0 From patchwork Tue Jul 12 02:13:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655170 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=XRhGZDgB; 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 4Lhl3g08xMz9s07 for ; Tue, 12 Jul 2022 12:25:49 +1000 (AEST) Received: from localhost ([::1]:59816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5as-0007im-CR for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:25:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5Pm-0000zJ-JU; Mon, 11 Jul 2022 22:14:19 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:34712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5Pk-00080v-Qf; Mon, 11 Jul 2022 22:14:17 -0400 Received: by mail-pj1-x1033.google.com with SMTP id cp18-20020a17090afb9200b001ef79e8484aso337254pjb.1; Mon, 11 Jul 2022 19:14:16 -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=LnocqEql15XybyUUiK+n2EXh+6pjpEpQkwpJSSpKAPU=; b=XRhGZDgBPhnhAzRjNDBae5fkpAjJb6vJ5z4XpQcB6XRJqotPuqPnlLM/lR+8I7hi1P i9xnUuDMUoGK3MgNH1oLM17gPGEL1FuqeTHreI10qclqwy7XY7YTInv68iOWQzFp1Kvk hbYdJkHAUTuUYJNdr1jqsjmnKDhRXwU+Db+xJtm2J/TTp/rReYH+oIlW/1fG0/hpXDqp XgmOmG0dElk+QH7dVzSP2auEubhBAPHMHqYo6TbqTqtty4kq44Yq3Rt5q+nNbGp8gMpC zN7XBYSYUmfbQ/4K3XBVdfSOTsPgvGVILxdhxTmCFrrU9cZRBR+sF4uO+Y0CvRtqtBQW 7WFg== 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=LnocqEql15XybyUUiK+n2EXh+6pjpEpQkwpJSSpKAPU=; b=BCdaME4cIYgU8gXUj11Wk3eysWXajj3HakwlBeudRO3nYV8sg+x3LMeH5ei7PXMnKT PUPdH3ewurBydnem63lXFdcM3xZka/JU+RNxGij8uzMA/oXhsjBiRndT9OvhEoFVlBrr GtEFhSHezsb0zs4eDgADtTpNYfBAV8sG5SrXprniORhOIzfjdldZKzh1aas8HJOx1NFd YzD0t49OsBGscUApKTsnYClVITtMsmhIbf42FKQPbd7QbCAtpXgBzuv3qGjI1vloMJpr i+jwHkxio24swXto0sNLSHwmTDsu3oUUnvp17TrRkCyvYs7dxdmLlz7sHN+xXa2owlUy HGWw== X-Gm-Message-State: AJIora8wDoXm1B85Q4sywXG6ihIfwWS/OSeoJ+PqE2/GcCHeYqaMXmGJ FA/xnNifKwrY7EVteV2rdSg+m/zyYWjTpacL X-Google-Smtp-Source: AGRyM1vOfYUanDs0Afa2uc6bhlCk1hVuetmcGs2zBaZQJxsIpkDhhOhhGbfiBruKFhQJA+nqnTH86w== X-Received: by 2002:a17:90b:1a84:b0:1ef:dc5c:3088 with SMTP id ng4-20020a17090b1a8400b001efdc5c3088mr1492997pjb.245.1657592055131; Mon, 11 Jul 2022 19:14:15 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:14:14 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 6/9] raw-format: add zone operations Date: Tue, 12 Jul 2022 10:13:42 +0800 Message-Id: <20220712021345.8530-7-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1033.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" Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- block/raw-format.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index 69fd650eaf..96bdb6c1e2 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -314,6 +314,17 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs, return bdrv_co_pdiscard(bs->file, offset, bytes); } +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, + int64_t *nr_zones, + BlockZoneDescriptor *zones) { + return bdrv_co_zone_report(bs->file->bs, offset, nr_zones, zones); +} + +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, zone_op op, + int64_t offset, int64_t len) { + return bdrv_co_zone_mgmt(bs->file->bs, op, offset, len); +} + static int64_t raw_getlength(BlockDriverState *bs) { int64_t len; @@ -614,6 +625,8 @@ BlockDriver bdrv_raw = { .bdrv_co_pwritev = &raw_co_pwritev, .bdrv_co_pwrite_zeroes = &raw_co_pwrite_zeroes, .bdrv_co_pdiscard = &raw_co_pdiscard, + .bdrv_co_zone_report = &raw_co_zone_report, + .bdrv_co_zone_mgmt = &raw_co_zone_mgmt, .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, From patchwork Tue Jul 12 02:13:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655169 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=CYTOJjfp; 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 4Lhl004pFWz9s07 for ; Tue, 12 Jul 2022 12:22:40 +1000 (AEST) Received: from localhost ([::1]:54424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5Xq-0003wT-B9 for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:22:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5Ps-0001Eb-6t; Mon, 11 Jul 2022 22:14:24 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:41835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5Pq-00081Y-Js; Mon, 11 Jul 2022 22:14:23 -0400 Received: by mail-pf1-x42f.google.com with SMTP id l124so6279679pfl.8; Mon, 11 Jul 2022 19:14:20 -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=IEva+i6vtaMTudz/mittdmHp6URnOdrUbp0T/SibzHA=; b=CYTOJjfpmG9gtJfRTGEdQEFjcg+w96hONXOsrHy/K085BIf3crJYJYlGbKOnGd9HDi k8DnWTFciS0z8nAYL8fBh9e0eY2U9LblnG01KC1kLrt90Jvvs/YKIczP1bdb/uq9SaQf 5tfouWC8HYZl1WLR02VsM8jaW++ScxQa8tDSU6YEjv5HCkZun1uDkGMf/em0cAzg00Kc BtROKwXLi/064kEZbtqBoRyJAPbJG9s1ZN722pTVt0xsIFl9N6niT6JGUct7wOSnRIKv 3TBqk7+TAVRXLHYhNx6UmlNyZkcFZGpGpSdriHv8189bWzcrmxi6OwndtpWF5ATM95I1 1LSA== 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=IEva+i6vtaMTudz/mittdmHp6URnOdrUbp0T/SibzHA=; b=u1cjQyieLoSt6A6cS52wcl03dlBIZTvu6UirNVB4zCOmvmfK9j+hEHxp6NiDcXUOGa Z82azMQU2XGapMb0NFtQ1eB7Hkwe5V2cKqVZwPo6lFVf2S2NQNmHS5EO9gPHvMjXQ6fW kaDs/8GT/DehrgmqaoqFDxMLDJpf7T1mNVZFy35cNebq9WpfsxdKwnXYkcEb94PYMWCf mnxGXXiqnFnf97YYRQSqBvgHFwaVEM5TBD7Mvl9CImv+FopkLvWbQ4H3yy45WFGmTLlz qXguhLZcSFOSWxWNO+Zd9xHxJADL3BGZi3AnVyEIpLAOC0NXwublp8W4MLQbM8LH+0SO P00Q== X-Gm-Message-State: AJIora+BDWstKIf/vgyVrEYb0Cz5UPApyZoq0BbvOeYJ03QLybUikQx4 1vwOhTAb5V6SUpgj1kkY8v4Erpy5+uaKtOdT X-Google-Smtp-Source: AGRyM1uWSbJUr57dQ2oCfNBlO3V6xjqxw21SUPB0egDsX6K5vQgIGZoodq83LmF2oHpmg/m8T1G2cA== X-Received: by 2002:a63:1f5f:0:b0:412:9ace:9fd6 with SMTP id q31-20020a631f5f000000b004129ace9fd6mr18854208pgm.199.1657592058836; Mon, 11 Jul 2022 19:14:18 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:14:18 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 7/9] config: add check to block layer Date: Tue, 12 Jul 2022 10:13:43 +0800 Message-Id: <20220712021345.8530-8-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x42f.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" Putting zoned/non-zoned BlockDrivers on top of each other is not allowed. Signed-off-by: Sam Li --- block.c | 7 +++++++ block/file-posix.c | 2 ++ include/block/block_int-common.h | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/block.c b/block.c index 2c00dddd80..0e24582c7d 100644 --- a/block.c +++ b/block.c @@ -7945,6 +7945,13 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, return; } + if (parent_bs->drv->is_zoned != child_bs->drv->is_zoned) { + error_setg(errp, "Cannot add a %s child to a %s parent", + child_bs->drv->is_zoned ? "zoned" : "non-zoned", + parent_bs->drv->is_zoned ? "zoned" : "non-zoned"); + return; + } + if (!QLIST_EMPTY(&child_bs->parents)) { error_setg(errp, "The node %s already has a parent", child_bs->node_name); diff --git a/block/file-posix.c b/block/file-posix.c index 42708012ff..e9ad1d8e1e 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3924,6 +3924,7 @@ static BlockDriver bdrv_host_device = { .format_name = "host_device", .protocol_name = "host_device", .instance_size = sizeof(BDRVRawState), + .is_zoned = false, .bdrv_needs_filename = true, .bdrv_probe_device = hdev_probe_device, .bdrv_parse_filename = hdev_parse_filename, @@ -3971,6 +3972,7 @@ static BlockDriver bdrv_zoned_host_device = { .format_name = "zoned_host_device", .protocol_name = "zoned_host_device", .instance_size = sizeof(BDRVRawState), + .is_zoned = true, .bdrv_needs_filename = true, .bdrv_probe_device = hdev_probe_device, .bdrv_parse_filename = hdev_parse_filename, diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 6037871089..29f1ec9184 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -141,6 +141,11 @@ struct BlockDriver { */ bool is_format; + /* + * Set to true if the BlockDriver is a zoned block driver. + */ + bool is_zoned; + /* * Drivers not implementing bdrv_parse_filename nor bdrv_open should have * this field set to true, except ones that are defined only by their From patchwork Tue Jul 12 02:13:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655171 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=Vi8BnugV; 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 4Lhl7L0zqGz9s07 for ; Tue, 12 Jul 2022 12:29:02 +1000 (AEST) Received: from localhost ([::1]:38782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5dz-0004Qj-DH for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:28:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5Pu-0001KI-BI; Mon, 11 Jul 2022 22:14:26 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:46740) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5Ps-000824-Eg; Mon, 11 Jul 2022 22:14:25 -0400 Received: by mail-pf1-x42c.google.com with SMTP id a15so6255170pfv.13; Mon, 11 Jul 2022 19:14:23 -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=A0ag3gAZoGkVBeV73+KkTy7HnO0SGfyVP1akGZ5l3w0=; b=Vi8BnugVqzUywBqlu1jwi2KIENaoyfO85IAeER+hVm99TJfIhdmqNzza6qTDH0e4t+ Q2e8yjCu5ogZfn940FuxBUzoBgqVCQx36/8dBIeRoAfgRAjkhaZfDYWHwg+eG8rrS7bb F1VOR6axG12d6l6HCoWX3lDcI4bmPbjTnQ2ad3OV53g3DR8rj6M3U8+CVNGYY0QnfysD z8jHLx5sErq7efmSl3l3tM/UGGq/Zm5a+X8d4X2ryCv8UCCVqqbF3GhcDqjKViIOMeDA G1RZztibsELIyIFRYKHWKE89JHHgAeqor9XtvPUWGeuOLJU9nTB27RLepk4lFYMau9f/ wAsA== 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=A0ag3gAZoGkVBeV73+KkTy7HnO0SGfyVP1akGZ5l3w0=; b=Nwm2lsj9cdU99NjTZL9qYRep2ngg4T56jesCUHmZ0SCuHaDKtNLShBPIMvoWzctWZz iX1FDdWTkH7LUhk8wyEBkzmKklDgLBZ28Y0me7v+LV/C6jzjzxl1UPxEALHVEwJDook0 d254sFM9ZjBBzcFUX50vu/KE9JFBHeYSaq6BsaLgE0UWP2bKREYwEafyGV9MvD3+3bER 1tri7CDxXaZOLmgoqmqb9htHDqyXOjdF7h6C11255OVZ8H1+9Z2T4l5cvhoqOPPbeNFB sdNA8H2pXeW6czCFGBiAYiYe2M+HLVDH1qYwLJ+f7JpOPAmkmDV0vtuET2EKtvYkMcH/ IaxQ== X-Gm-Message-State: AJIora/4B7yU0LlB4omhOXUm+3+VPY3XPfK1jjtv/O3x5sETHOHzWoxF J8lPNBllC6fTwqH7/qDrzAJgN5HxBH/0lBtK X-Google-Smtp-Source: AGRyM1sN5t1+mweD9QOFJII5qtmfKYSKxC+KGQOlwAsMPxtwBW2aRmz3h4qAZ5EmZCibTC67lynEmg== X-Received: by 2002:a63:5f4e:0:b0:417:ba9d:c513 with SMTP id t75-20020a635f4e000000b00417ba9dc513mr2329952pgb.434.1657592062587; Mon, 11 Jul 2022 19:14:22 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:14:22 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 8/9] include: add support for zoned block devices Date: Tue, 12 Jul 2022 10:13:44 +0800 Message-Id: <20220712021345.8530-9-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x42c.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" This is the virtio_blk.h header file from Dmitry's "virtio-blk: add support for zoned block devices" patch. It introduces virtio_blk_zoned_characteristics struct from Dmitry's virtio-blk zoned storage spec. Signed-off-by: Dmitry Fomichev Signed-off-by: Sam Li --- include/standard-headers/linux/virtio_blk.h | 157 ++++++++++++++++++-- 1 file changed, 141 insertions(+), 16 deletions(-) diff --git a/include/standard-headers/linux/virtio_blk.h b/include/standard-headers/linux/virtio_blk.h index 2dcc90826a..f07fbe1b9b 100644 --- a/include/standard-headers/linux/virtio_blk.h +++ b/include/standard-headers/linux/virtio_blk.h @@ -25,10 +25,10 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include "standard-headers/linux/types.h" -#include "standard-headers/linux/virtio_ids.h" -#include "standard-headers/linux/virtio_config.h" -#include "standard-headers/linux/virtio_types.h" +#include +#include +#include +#include /* Feature bits */ #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ @@ -40,6 +40,7 @@ #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */ #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ +#define VIRTIO_BLK_F_ZONED 17 /* Zoned block device */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -47,8 +48,10 @@ #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ #define VIRTIO_BLK_F_FLUSH 9 /* Flush command supported */ #define VIRTIO_BLK_F_CONFIG_WCE 11 /* Writeback mode available in config */ +#ifndef __KERNEL__ /* Old (deprecated) name for VIRTIO_BLK_F_FLUSH. */ #define VIRTIO_BLK_F_WCE VIRTIO_BLK_F_FLUSH +#endif #endif /* !VIRTIO_BLK_NO_LEGACY */ #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ @@ -63,8 +66,8 @@ struct virtio_blk_config { /* geometry of the device (if VIRTIO_BLK_F_GEOMETRY) */ struct virtio_blk_geometry { __virtio16 cylinders; - uint8_t heads; - uint8_t sectors; + __u8 heads; + __u8 sectors; } geometry; /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ @@ -72,17 +75,17 @@ struct virtio_blk_config { /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */ /* exponent for physical block per logical block. */ - uint8_t physical_block_exp; + __u8 physical_block_exp; /* alignment offset in logical blocks. */ - uint8_t alignment_offset; + __u8 alignment_offset; /* minimum I/O size without performance penalty in logical blocks. */ __virtio16 min_io_size; /* optimal sustained I/O size in logical blocks. */ __virtio32 opt_io_size; /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */ - uint8_t wce; - uint8_t unused; + __u8 wce; + __u8 unused; /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */ __virtio16 num_queues; @@ -116,10 +119,24 @@ struct virtio_blk_config { * Set if a VIRTIO_BLK_T_WRITE_ZEROES request may result in the * deallocation of one or more of the sectors. */ - uint8_t write_zeroes_may_unmap; + __u8 write_zeroes_may_unmap; - uint8_t unused1[3]; -} QEMU_PACKED; + __u8 unused1[3]; + + /* Secure erase fields that are defined in the virtio spec */ + __u8 sec_erase[12]; + + /* Zoned block device characteristics (if VIRTIO_BLK_F_ZONED) */ + struct virtio_blk_zoned_characteristics { + __virtio32 zone_sectors; + __virtio32 max_open_zones; + __virtio32 max_active_zones; + __virtio32 max_append_sectors; + __virtio32 write_granularity; + __u8 model; + __u8 unused2[3]; + } zoned; +} __attribute__((packed)); /* * Command types @@ -153,6 +170,24 @@ struct virtio_blk_config { /* Write zeroes command */ #define VIRTIO_BLK_T_WRITE_ZEROES 13 +/* Zone append command */ +#define VIRTIO_BLK_T_ZONE_APPEND 15 + +/* Report zones command */ +#define VIRTIO_BLK_T_ZONE_REPORT 16 + +/* Open zone command */ +#define VIRTIO_BLK_T_ZONE_OPEN 18 + +/* Close zone command */ +#define VIRTIO_BLK_T_ZONE_CLOSE 20 + +/* Finish zone command */ +#define VIRTIO_BLK_T_ZONE_FINISH 22 + +/* Reset zone command */ +#define VIRTIO_BLK_T_ZONE_RESET 24 + #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 @@ -172,17 +207,100 @@ struct virtio_blk_outhdr { __virtio64 sector; }; +/* + * Supported zoned device models. + */ + +/* Host-managed zoned device */ +#define VIRTIO_BLK_Z_HM 1 +/* Host-aware zoned device */ +#define VIRTIO_BLK_Z_HA 2 + +/* ZBD Management Out ALL flag */ +#define VIRTIO_BLK_ZONED_FLAG_ALL (1 << 0) + +/* + * Request header for zoned devices. + * The first three fields are identical in layout to + * struct virtio_blk_outhdr. + */ +struct virtio_blk_zoned_outhdr { + /* VIRTIO_BLK_T* */ + __virtio32 type; + /* io priority. */ + __virtio32 ioprio; + /* Sector (ie. 512 byte offset) */ + __virtio64 sector; + /* Zoned request flags */ + __virtio32 flags; +}; + +/* + * Zone descriptor. A part of VIRTIO_BLK_T_ZONE_REPORT command reply. + */ +struct virtio_blk_zone_descriptor { + /* Zone capacity */ + __virtio64 z_cap; + /* The starting sector of the zone */ + __virtio64 z_start; + /* Zone write pointer position in sectors */ + __virtio64 z_wp; + /* Zone type */ + __u8 z_type; + /* Zone state */ + __u8 z_state; + __u8 reserved[38]; +}; + +struct virtio_blk_zone_report { + __virtio64 nr_zones; + __u8 reserved[56]; + struct virtio_blk_zone_descriptor zones[]; +}; + +/* + * Supported zone types. + */ + +/* Conventional zone */ +#define VIRTIO_BLK_ZT_CONV 1 +/* Sequential Write Required zone */ +#define VIRTIO_BLK_ZT_SWR 2 +/* Sequential Write Preferred zone */ +#define VIRTIO_BLK_ZT_SWP 3 + +/* + * Zone states that are available for zones of all types. + */ + +/* Not a write pointer (conventional zones only) */ +#define VIRTIO_BLK_ZS_NOT_WP 0 +/* Empty */ +#define VIRTIO_BLK_ZS_EMPTY 1 +/* Implicitly Open */ +#define VIRTIO_BLK_ZS_IOPEN 2 +/* Explicitly Open */ +#define VIRTIO_BLK_ZS_EOPEN 3 +/* Closed */ +#define VIRTIO_BLK_ZS_CLOSED 4 +/* Read-Only */ +#define VIRTIO_BLK_ZS_RDONLY 13 +/* Full */ +#define VIRTIO_BLK_ZS_FULL 14 +/* Offline */ +#define VIRTIO_BLK_ZS_OFFLINE 15 + /* Unmap this range (only valid for write zeroes command) */ #define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001 /* Discard/write zeroes range for each request. */ struct virtio_blk_discard_write_zeroes { /* discard/write zeroes start sector */ - uint64_t sector; + __le64 sector; /* number of discard/write zeroes sectors */ - uint32_t num_sectors; + __le32 num_sectors; /* flags for this range */ - uint32_t flags; + __le32 flags; }; #ifndef VIRTIO_BLK_NO_LEGACY @@ -198,4 +316,11 @@ struct virtio_scsi_inhdr { #define VIRTIO_BLK_S_OK 0 #define VIRTIO_BLK_S_IOERR 1 #define VIRTIO_BLK_S_UNSUPP 2 + +/* Error codes that are specific to zoned block devices */ +#define VIRTIO_BLK_S_ZONE_INVALID_CMD 3 +#define VIRTIO_BLK_S_ZONE_UNALIGNED_WP 4 +#define VIRTIO_BLK_S_ZONE_OPEN_RESOURCE 5 +#define VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE 6 + #endif /* _LINUX_VIRTIO_BLK_H */ From patchwork Tue Jul 12 02:13:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 1655172 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=gK84npHS; 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 4LhlBl4D1Gz9s07 for ; Tue, 12 Jul 2022 12:31:58 +1000 (AEST) Received: from localhost ([::1]:42428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB5go-00071L-ON for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2022 22:31:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB5Px-0001Xx-TV; Mon, 11 Jul 2022 22:14:30 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:34617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB5Pw-00082f-BD; Mon, 11 Jul 2022 22:14:29 -0400 Received: by mail-pf1-x435.google.com with SMTP id 70so6299454pfx.1; Mon, 11 Jul 2022 19:14:27 -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=yOIRhO0nQgWE0JR20Yhde7NElMEsFtb20MMGKy3mdQk=; b=gK84npHSRlMExJA6Sqg1fVZqjS9a2kt/VAlHat0oLc3wmmNRV12Ya8Pj3y3xuOujN0 8+uOgVsmgdnQ1/Gte+5xyFoeZHvp1tMlUf+PyOmkc4EkBzSyoBTCmmL+TXLS5tNHkH37 6A4g5hlBmMU3d64er7wW6AsCnMVmk7lFrrDcz+XmEbEOrg+BDLrqbqIv+Ynl6UrkIdmp L9IlSvtB7/vkAiZE6v33hiPmYw4bWqy1lCcJ50fzbHVZlR1d2UnmOeZlp1eG5SeKF75y ZNyv8ngXm5AovGWNPxClZej+yNuJZ6+uBNi56CKPUw4Amuhl3X8VKWy3P7Vaa6YCUdfi sAFw== 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=yOIRhO0nQgWE0JR20Yhde7NElMEsFtb20MMGKy3mdQk=; b=ZLllEInffjVXTpouVlMqWT1b+U7xCWVQyA0GZ/pSbZB+C7yJ1Ff/zurKJ3pm1voY9B NLRSqlln3nR6rxy8a2k3I/bZciAgxFxoWkZ1S4FuC4RSEPR2MXRpYn9Lshg5S8fLRvbU lLosmqcgZWQfQhnEkGkrQsSk1RNWM3YkHcQ00m8tBXJFXo81I94c6QlZd//y0Ff4NBiQ pZWBq5CT07GT/wR1eJJfXHligI9PhUqg4r5rswCxpUu5rEIAA5Nf6mkNolEJUu/BdgTp eKYuTweaQQMRtG+53JaAEyoyRDtMxJGK/kg2HvhWRYZzNzkrq/eqviQxMAZ8EMR+YXHE vP5A== X-Gm-Message-State: AJIora+x3L/VQWjlHHUBgPUqpDJnuFa//unkI4fEJO3yvVM2rKKIsBP6 BbLk2Lf23YiC4pb1gzMF/vS5RAJ2NwQSPyQd X-Google-Smtp-Source: AGRyM1t9rr+mgx+ZPWdbLlMW0dC0RrulsdFHYJML2ZlHPOqYhHYs1J/eqPQ/6qQEIDhpFKPDO5igxA== X-Received: by 2002:a05:6a00:114c:b0:528:2c7a:630e with SMTP id b12-20020a056a00114c00b005282c7a630emr21442113pfm.86.1657592066463; Mon, 11 Jul 2022 19:14:26 -0700 (PDT) Received: from roots.. ([106.84.131.214]) by smtp.gmail.com with ESMTPSA id k22-20020aa79736000000b00528f9597fb3sm5430251pfg.197.2022.07.11.19.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 19:14:26 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, Markus Armbruster , dmitry.fomichev@wdc.com, Stefan Hajnoczi , Hanna Reitz , qemu-block@nongnu.org, Eric Blake , Kevin Wolf , Fam Zheng , hare@suse.de, Sam Li Subject: [RFC v4 9/9] qapi: add support for zoned host device Date: Tue, 12 Jul 2022 10:13:45 +0800 Message-Id: <20220712021345.8530-10-faithilikerun@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712021345.8530-1-faithilikerun@gmail.com> References: <20220712021345.8530-1-faithilikerun@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x435.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 | 8 +++++++- qapi/block-core.json | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index e9ad1d8e1e..4e0aa02acf 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3737,6 +3737,12 @@ static void hdev_parse_filename(const char *filename, QDict *options, bdrv_parse_filename_strip_prefix(filename, "host_device:", options); } +static void zoned_host_device_parse_filename(const char *filename, QDict *options, + Error **errp) +{ + bdrv_parse_filename_strip_prefix(filename, "zoned_host_device:", options); +} + static bool hdev_is_sg(BlockDriverState *bs) { @@ -3975,7 +3981,7 @@ static BlockDriver bdrv_zoned_host_device = { .is_zoned = true, .bdrv_needs_filename = true, .bdrv_probe_device = hdev_probe_device, - .bdrv_parse_filename = hdev_parse_filename, + .bdrv_parse_filename = zoned_host_device_parse_filename, .bdrv_file_open = hdev_open, .bdrv_close = raw_close, .bdrv_reopen_prepare = raw_reopen_prepare, diff --git a/qapi/block-core.json b/qapi/block-core.json index 2173e7734a..ab05c2ef99 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2955,7 +2955,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'HAVE_HOST_BLOCK_DEVICE' } ] } ## # @BlockdevOptionsFile: @@ -4329,7 +4330,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'HAVE_HOST_BLOCK_DEVICE' } } } ##