Commit 0f597ac6 authored by Guoqing Jiang's avatar Guoqing Jiang Committed by Leon Romanovsky
Browse files

RDMA/rtrs-srv: Refactor the handling of failure case in map_cont_bufs



Let's call unmap_cont_bufs when failure happens, and also only update
mrs_num after everything is settled which means we can remove 'mri'.

Acked-by: default avatarMd Haris Iqbal <haris.iqbal@ionos.com>
Signed-off-by: default avatarGuoqing Jiang <guoqing.jiang@linux.dev>
Link: https://lore.kernel.org/r/20221117101945.6317-3-guoqing.jiang@linux.dev


Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
parent d7115727
Loading
Loading
Loading
Loading
+20 −27
Original line number Diff line number Diff line
@@ -561,9 +561,11 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
{
	struct rtrs_srv_sess *srv = srv_path->srv;
	struct rtrs_path *ss = &srv_path->s;
	int i, mri, err, mrs_num;
	int i, err, mrs_num;
	unsigned int chunk_bits;
	int chunks_per_mr = 1;
	struct ib_mr *mr;
	struct sg_table *sgt;

	/*
	 * Here we map queue_depth chunks to MR.  Firstly we have to
@@ -586,16 +588,14 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
	if (!srv_path->mrs)
		return -ENOMEM;

	srv_path->mrs_num = mrs_num;

	for (mri = 0; mri < mrs_num; mri++) {
		struct rtrs_srv_mr *srv_mr = &srv_path->mrs[mri];
		struct sg_table *sgt = &srv_mr->sgt;
	for (srv_path->mrs_num = 0; srv_path->mrs_num < mrs_num;
	     srv_path->mrs_num++) {
		struct rtrs_srv_mr *srv_mr = &srv_path->mrs[srv_path->mrs_num];
		struct scatterlist *s;
		struct ib_mr *mr;
		int nr, nr_sgt, chunks;

		chunks = chunks_per_mr * mri;
		sgt = &srv_mr->sgt;
		chunks = chunks_per_mr * srv_path->mrs_num;
		if (!always_invalidate)
			chunks_per_mr = min_t(int, chunks_per_mr,
					      srv->queue_depth - chunks);
@@ -644,14 +644,13 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)

		ib_update_fast_reg_key(mr, ib_inc_rkey(mr->rkey));
		srv_mr->mr = mr;
	}

	chunk_bits = ilog2(srv->queue_depth - 1) + 1;
	srv_path->mem_bits = (MAX_IMM_PAYL_BITS - chunk_bits);

	return 0;

		continue;
err:
		while (mri--) {
			srv_mr = &srv_path->mrs[mri];
			sgt = &srv_mr->sgt;
			mr = srv_mr->mr;
			rtrs_iu_free(srv_mr->iu, srv_path->s.dev->ib_dev, 1);
dereg_mr:
	ib_dereg_mr(mr);
unmap_sg:
@@ -659,18 +658,12 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
			sgt->nents, DMA_BIDIRECTIONAL);
free_sg:
	sg_free_table(sgt);
		}
		kfree(srv_path->mrs);
err:
	unmap_cont_bufs(srv_path);

	return err;
}

	chunk_bits = ilog2(srv->queue_depth - 1) + 1;
	srv_path->mem_bits = (MAX_IMM_PAYL_BITS - chunk_bits);

	return 0;
}

static void rtrs_srv_hb_err_handler(struct rtrs_con *c)
{
	close_path(to_srv_path(c->path));