Commit 676041ea authored by Yankun Li's avatar Yankun Li Committed by Tomasz Zawadzki
Browse files

lib/bdev: Fix the bdev io resource leak



When the return code is no zero, if the return value of bdev_write
_blocks_with_md is NOMEM, queue it. In other cases, bdev_io
representing the write_zeros should be released by callback function.

Change-Id: I9dc73d924efff14f7bc84c3dec6915755cc09419
Signed-off-by: default avatarYankun Li <yankun@staff.sina.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26117


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarChangpeng Liu <changpeliu@tencent.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Reviewed-by: default avatarGangCao <gang.cao@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
parent 8ee24758
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ static void bdev_io_push_bounce_data(struct spdk_bdev_io *bdev_io);
static void _bdev_io_get_accel_buf(struct spdk_bdev_io *bdev_io);

static void bdev_write_zero_buffer_done(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg);
static int bdev_write_zero_buffer(struct spdk_bdev_io *bdev_io);
static void bdev_write_zero_buffer(void *bdev_io);

static void bdev_enable_qos_msg(struct spdk_bdev_channel_iter *i, struct spdk_bdev *bdev,
				struct spdk_io_channel *ch, void *_ctx);
@@ -6724,7 +6724,8 @@ spdk_bdev_write_zeroes_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channe

	assert(_bdev_get_block_size_with_md(bdev) <= ZERO_BUFFER_SIZE);

	return bdev_write_zero_buffer(bdev_io);
	bdev_write_zero_buffer(bdev_io);
	return 0;
}

int
@@ -9716,11 +9717,13 @@ spdk_bdev_module_list_find(const char *name)
	return bdev_module;
}

static int
bdev_write_zero_buffer(struct spdk_bdev_io *bdev_io)
static void
bdev_write_zero_buffer(void *ctx)
{
	struct spdk_bdev_io *bdev_io = ctx;
	uint64_t num_blocks;
	void *md_buf = NULL;
	int rc;

	num_blocks = bdev_io->u.bdev.num_blocks;

@@ -9729,11 +9732,22 @@ bdev_write_zero_buffer(struct spdk_bdev_io *bdev_io)
			 spdk_bdev_get_block_size(bdev_io->bdev) * num_blocks;
	}

	return bdev_write_blocks_with_md(bdev_io->internal.desc,
	rc = bdev_write_blocks_with_md(bdev_io->internal.desc,
				       spdk_io_channel_from_ctx(bdev_io->internal.ch),
				       g_bdev_mgr.zero_buffer, md_buf,
				       bdev_io->u.bdev.offset_blocks, num_blocks,
				       bdev_write_zero_buffer_done, bdev_io);
	if (spdk_likely(rc == 0)) {
		return;
	} else {
		if (spdk_unlikely(rc == -ENOMEM)) {
			bdev_queue_io_wait_with_cb(bdev_io, bdev_write_zero_buffer);
			return;
		}

		bdev_io->internal.status = SPDK_BDEV_IO_STATUS_FAILED;
		bdev_io->internal.cb(bdev_io, false, bdev_io->internal.caller_ctx);
	}
}

static void