From: Jens Axboe <axboe@kernel.dk>
To: Keith Busch <kbusch@meta.com>, io-uring@vger.kernel.org
Cc: Keith Busch <kbusch@kernel.org>
Subject: Re: [PATCH] liburing: add test for metadata
Date: Fri, 7 Nov 2025 17:27:27 -0700 [thread overview]
Message-ID: <bffc5ed3-6b17-4119-af4c-1fdb51ea1b97@kernel.dk> (raw)
In-Reply-To: <20251107042953.3393507-1-kbusch@meta.com>
On 11/6/25 9:29 PM, Keith Busch wrote:
> +int main(int argc, char *argv[])
> +{
> + int fd, ret, offset, intervals, metabuffer_size, metabuffer_tx_size;
> + void *orig_data_buf, *orig_pi_buf, *data_buf;
> + struct io_uring_sqe *sqe;
> + struct io_uring_cqe *cqe;
> + struct io_uring ring;
> +
> + if (argc < 2) {
> + fprintf(stderr, "Usage: %s <dev>\n", argv[0]);
> + return T_EXIT_FAIL;
> + }
This should be a T_EXIT_SKIP.
> + fd = open(argv[1], O_RDWR | O_DIRECT);
> + if (fd < 0) {
> + perror("Failed to open device with O_DIRECT");
> + return T_EXIT_FAIL;
> + }
> +
> + ret = init_capabilities(fd);
> + if (ret < 0)
> + return T_EXIT_FAIL;
> + if (lba_size == 0 || metadata_size == 0)
> + return T_EXIT_SKIP;
> +
> + intervals = DATA_SIZE / lba_size;
> + metabuffer_tx_size = intervals * metadata_size;
> + metabuffer_size = metabuffer_tx_size * 2;
> +
> + if (posix_memalign(&orig_data_buf, pagesize, DATA_SIZE)) {
> + perror("posix_memalign failed for data buffer");
> + ret = T_EXIT_FAIL;
> + goto close;
> + }
> +
> + if (posix_memalign(&orig_pi_buf, pagesize, metabuffer_size)) {
> + perror("posix_memalign failed for metadata buffer");
> + ret = T_EXIT_FAIL;
> + goto free;
> + }
> +
> + ret = io_uring_queue_init(8, &ring, 0);
> + if (ret < 0) {
> + perror("io_uring_queue_init failed");
> + goto cleanup;
> + }
> +
> + data_buf = orig_data_buf;
> + for (offset = 0; offset < 512; offset++) {
> + void *pi_buf = (char *)orig_pi_buf + offset * 4;
> + struct io_uring_attr_pi pi_attr = {
> + .addr = (__u64)pi_buf,
> + .seed = offset,
> + .len = metabuffer_tx_size,
> + };
> +
> + if (reftag_enabled)
> + pi_attr.flags = IO_INTEGRITY_CHK_REFTAG;
> +
> + init_data(data_buf, offset);
> + init_metadata(pi_buf, intervals, offset);
> +
> + sqe = io_uring_get_sqe(&ring);
> + if (!sqe) {
> + fprintf(stderr, "Failed to get SQE\n");
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + io_uring_prep_write(sqe, fd, data_buf, DATA_SIZE, offset * lba_size * 8);
> + io_uring_sqe_set_data(sqe, (void *)1L);
> +
> + sqe->attr_type_mask = IORING_RW_ATTR_FLAG_PI;
> + sqe->attr_ptr = (__u64)&pi_attr;
> +
> + ret = io_uring_submit(&ring);
> + if (ret < 1) {
> + perror("io_uring_submit failed (WRITE)");
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + ret = io_uring_wait_cqe(&ring, &cqe);
> + if (ret < 0) {
> + perror("io_uring_wait_cqe failed (WRITE)");
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + if (cqe->res < 0) {
> + fprintf(stderr, "write failed at offset %d: %s\n",
> + offset, strerror(-cqe->res));
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + io_uring_cqe_seen(&ring, cqe);
> +
> + memset(data_buf, 0, DATA_SIZE);
> + memset(pi_buf, 0, metabuffer_tx_size);
> +
> + sqe = io_uring_get_sqe(&ring);
> + if (!sqe) {
> + fprintf(stderr, "failed to get SQE\n");
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + io_uring_prep_read(sqe, fd, data_buf, DATA_SIZE, offset * lba_size * 8);
> + io_uring_sqe_set_data(sqe, (void *)2L);
> +
> + sqe->attr_type_mask = IORING_RW_ATTR_FLAG_PI;
> + sqe->attr_ptr = (__u64)&pi_attr;
> +
> + ret = io_uring_submit(&ring);
> + if (ret < 1) {
> + perror("io_uring_submit failed (read)");
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + ret = io_uring_wait_cqe(&ring, &cqe);
> + if (ret < 0) {
> + fprintf(stderr, "io_uring_wait_cqe failed (read): %s\n", strerror(-ret));
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + if (cqe->res < 0) {
> + fprintf(stderr, "read failed at offset %d: %s\n",
> + offset, strerror(-cqe->res));
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + ret = check_data(data_buf, offset);
> + if (ret) {
> + fprintf(stderr, "data corruption at offset %d\n",
> + offset);
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + ret = check_metadata(pi_buf, intervals, offset);
> + if (ret) {
> + fprintf(stderr, "metadata corruption at offset %d\n",
> + offset);
> + ret = T_EXIT_FAIL;
> + goto ring_exit;
> + }
> +
> + io_uring_cqe_seen(&ring, cqe);
> + }
> +
> + memset(data_buf, 0, DATA_SIZE);
> +
> + sqe = io_uring_get_sqe(&ring);
> + io_uring_prep_write(sqe, fd, data_buf, DATA_SIZE, 0);
> + io_uring_sqe_set_data(sqe, (void *)1L);
> +
> + sqe = io_uring_get_sqe(&ring);
> + io_uring_prep_write(sqe, fd, data_buf, DATA_SIZE, DATA_SIZE);
> + io_uring_sqe_set_data(sqe, (void *)2L);
> +
> + io_uring_submit(&ring);
> +
> + io_uring_wait_cqe(&ring, &cqe);
> + io_uring_cqe_seen(&ring, cqe);
> + io_uring_wait_cqe(&ring, &cqe);
> + io_uring_cqe_seen(&ring, cqe);
This looks a bit odd - no error checking?
--
Jens Axboe
prev parent reply other threads:[~2025-11-08 0:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-07 4:29 [PATCH] liburing: add test for metadata Keith Busch
2025-11-08 0:27 ` Jens Axboe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bffc5ed3-6b17-4119-af4c-1fdb51ea1b97@kernel.dk \
--to=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=kbusch@kernel.org \
--cc=kbusch@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).