From 9e50d53b1a93ca10489dceb3a1540e2a16000649 Mon Sep 17 00:00:00 2001 From: Jonas Pfefferle Date: Fri, 19 Aug 2022 12:58:54 +0200 Subject: [PATCH] bdev: add compare fall-back separate md support If the bdev does not natively support compare we use the fall-back which performs a read instead of a compare operation. We then compare the results of the read with the buffer provided by the user. In case the bdev has metadata, there are two options: 1) md is interleaved -> the md will be part of the data buffer allocated for the read and compared accordingly 2) md is separate -> currently we do not compare the metadata but just ignore it. This patch fixes 2) by comparing the md buffer after the read is done. Signed-off-by: Jonas Pfefferle Change-Id: I1018b8c02540bffcba69408eb283bdc8f06bb747 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14132 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Aleksey Marchuk Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/bdev/bdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 1fec0bb1c..6458789d1 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -4557,6 +4557,7 @@ static void bdev_compare_do_read_done(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg) { struct spdk_bdev_io *parent_io = cb_arg; + struct spdk_bdev *bdev = parent_io->bdev; uint8_t *read_buf = bdev_io->u.bdev.iovs[0].iov_base; int i, rc = 0; @@ -4577,6 +4578,12 @@ bdev_compare_do_read_done(struct spdk_bdev_io *bdev_io, bool success, void *cb_a read_buf += parent_io->u.bdev.iovs[i].iov_len; } + if (rc == 0 && parent_io->u.bdev.md_buf && spdk_bdev_is_md_separate(bdev)) { + rc = memcmp(bdev_io->u.bdev.md_buf, + parent_io->u.bdev.md_buf, + spdk_bdev_get_md_size(bdev)); + } + spdk_bdev_free_io(bdev_io); if (rc == 0) {