Re: [PATCHv2 1/2] blktests: test direct io offsets

Chaitanya Kulkarni
2025-11-19T23:48:51Z

On 11/19/25 11:54, Keith Busch wrote:
> +static void test_invalid_dma_vector_length()
> +{
> + const int vecs = 4;
> +
> + bool should_fail = dma_alignment > 1;
> + struct iovec iov[vecs];
> + int ret;
> +
> + iov[0].iov_base = out_buf;
> + iov[0].iov_len = max_bytes * 2 - max_bytes / 2;
> +
> + iov[1].iov_base = out_buf + max_bytes * 4;
> + iov[1].iov_len = logical_block_size * 2 - (dma_alignment + 1);
> +
> + iov[2].iov_base = out_buf + max_bytes * 8;
> + iov[2].iov_len = logical_block_size * 2 + (dma_alignment + 1);
> +
> + iov[3].iov_base = out_buf + max_bytes * 12;
> + iov[3].iov_len = max_bytes - max_bytes / 2;
> +
> + ret = pwritev(test_fd, iov, vecs, 0);
> + if (ret < 0) {
> + if (should_fail)
> + return;
> + err(errno, "%s: failed to write buf", __func__);
> + }
> +
> + if (should_fail)
> + err(ENOTSUP, "%s: write buf unexpectedly succeeded with invalid DMA offset addressret:%d",
> + __func__, ret);
> +
> + iov[0].iov_base = in_buf;
> + iov[0].iov_len = max_bytes * 2 - max_bytes / 2;
> +
> + iov[1].iov_base = in_buf + max_bytes * 4;
> + iov[1].iov_len = logical_block_size * 2 - (dma_alignment + 1);
> +
> + iov[2].iov_base = in_buf + max_bytes * 8;
> + iov[2].iov_len = logical_block_size * 2 + (dma_alignment + 1);
> +
> + iov[3].iov_base = in_buf + max_bytes * 12;
> + iov[3].iov_len = max_bytes - max_bytes / 2;
> +
> + ret = pwritev(test_fd, iov, vecs, 0);
> + if (ret < 0)
> + err(errno, "%s: failed to read buf", __func__);
> +

is pwritev correct above or it should be preadv () ?

> + compare(out_buf, in_buf, iov[0].iov_len);
> + compare(out_buf + max_bytes * 4, in_buf + max_bytes * 4, iov[1].iov_len);
> + compare(out_buf + max_bytes * 8, in_buf + max_bytes * 8, iov[2].iov_len);
> + compare(out_buf + max_bytes * 12, in_buf + max_bytes * 12, iov[3].iov_len);
> +}
> +

-ck