bdev: allow NULL md_buf for md-related APIs
It is a nicer API to allow users to use an md-related API such as spdk_bdev_read_blocks_with_md passing md_buf as NULL to mean "don't read metadata". This avoids the need for an if-statement in the users code to check if the md buffer is NULL before deciding which API needs to be called. This basically requires two changes: 1) only check if the metadata is separate for the bdev if the md_buf != NULL 2) do not fail if the buffer is specified but the md buffer is not (we only need to fail the case where the md buffer is specified but the data buffer is not) Note that spdk_bdev_readv/writev_blocks_ext was already allowing the metadata buffer to be NULL, but change those functions too to match the others on how we check if the data buffer isn't allocated. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: I764cf49b9f573fccb19e73876a376fd231cc3580 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13612 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
ee3ec3f7c2
commit
f3dd8f7e0d
@ -4132,12 +4132,6 @@ bdev_io_valid_blocks(struct spdk_bdev *bdev, uint64_t offset_blocks, uint64_t nu
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_bdev_io_check_md_buf(const struct iovec *iovs, const void *md_buf)
|
||||
{
|
||||
return _is_buf_allocated(iovs) == (md_buf != NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
bdev_read_blocks_with_md(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, void *buf,
|
||||
void *md_buf, uint64_t offset_blocks, uint64_t num_blocks,
|
||||
@ -4205,11 +4199,11 @@ spdk_bdev_read_blocks_with_md(struct spdk_bdev_desc *desc, struct spdk_io_channe
|
||||
.iov_base = buf,
|
||||
};
|
||||
|
||||
if (!spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
if (md_buf && !spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!_bdev_io_check_md_buf(&iov, md_buf)) {
|
||||
if (md_buf && !_is_buf_allocated(&iov)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -4285,11 +4279,11 @@ spdk_bdev_readv_blocks_with_md(struct spdk_bdev_desc *desc, struct spdk_io_chann
|
||||
uint64_t offset_blocks, uint64_t num_blocks,
|
||||
spdk_bdev_io_completion_cb cb, void *cb_arg)
|
||||
{
|
||||
if (!spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
if (md_buf && !spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!_bdev_io_check_md_buf(iov, md_buf)) {
|
||||
if (md_buf && !_is_buf_allocated(iov)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -4332,7 +4326,7 @@ spdk_bdev_readv_blocks_ext(struct spdk_bdev_desc *desc, struct spdk_io_channel *
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (md && !_bdev_io_check_md_buf(iov, md)) {
|
||||
if (md && !_is_buf_allocated(iov)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -4412,11 +4406,11 @@ spdk_bdev_write_blocks_with_md(struct spdk_bdev_desc *desc, struct spdk_io_chann
|
||||
.iov_base = buf,
|
||||
};
|
||||
|
||||
if (!spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
if (md_buf && !spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!_bdev_io_check_md_buf(&iov, md_buf)) {
|
||||
if (md_buf && !_is_buf_allocated(&iov)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -4497,11 +4491,11 @@ spdk_bdev_writev_blocks_with_md(struct spdk_bdev_desc *desc, struct spdk_io_chan
|
||||
uint64_t offset_blocks, uint64_t num_blocks,
|
||||
spdk_bdev_io_completion_cb cb, void *cb_arg)
|
||||
{
|
||||
if (!spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
if (md_buf && !spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!_bdev_io_check_md_buf(iov, md_buf)) {
|
||||
if (md_buf && !_is_buf_allocated(iov)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -4529,7 +4523,7 @@ spdk_bdev_writev_blocks_ext(struct spdk_bdev_desc *desc, struct spdk_io_channel
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (md && !_bdev_io_check_md_buf(iov, md)) {
|
||||
if (md && !_is_buf_allocated(iov)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -4646,11 +4640,11 @@ spdk_bdev_comparev_blocks_with_md(struct spdk_bdev_desc *desc, struct spdk_io_ch
|
||||
uint64_t offset_blocks, uint64_t num_blocks,
|
||||
spdk_bdev_io_completion_cb cb, void *cb_arg)
|
||||
{
|
||||
if (!spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
if (md_buf && !spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!_bdev_io_check_md_buf(iov, md_buf)) {
|
||||
if (md_buf && !_is_buf_allocated(iov)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -4716,11 +4710,11 @@ spdk_bdev_compare_blocks_with_md(struct spdk_bdev_desc *desc, struct spdk_io_cha
|
||||
.iov_base = buf,
|
||||
};
|
||||
|
||||
if (!spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
if (md_buf && !spdk_bdev_is_md_separate(spdk_bdev_desc_get_bdev(desc))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!_bdev_io_check_md_buf(&iov, md_buf)) {
|
||||
if (md_buf && !_is_buf_allocated(&iov)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user