Re: [PATCH v7 04/25] RDMA/rtrs: core: lib functions shared between client and server modules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 16, 2020 at 01:58:54PM +0100, Jack Wang wrote:
> From: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx>
>
> This is a set of library functions existing as a rtrs-core module,
> used by client and server modules.
>
> Mainly these functions wrap IB and RDMA calls and provide a bit higher
> abstraction for implementing of RTRS protocol on client or server
> sides.
>
> Signed-off-by: Danil Kipnis <danil.kipnis@xxxxxxxxxxxxxxx>
> Signed-off-by: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx>
> ---
>  drivers/infiniband/ulp/rtrs/rtrs.c | 597 +++++++++++++++++++++++++++++
>  1 file changed, 597 insertions(+)
>  create mode 100644 drivers/infiniband/ulp/rtrs/rtrs.c
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs.c b/drivers/infiniband/ulp/rtrs/rtrs.c
> new file mode 100644
> index 000000000000..7b84d76e2a67
> --- /dev/null
> +++ b/drivers/infiniband/ulp/rtrs/rtrs.c
> @@ -0,0 +1,597 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * RDMA Transport Layer
> + *
> + * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
> + *
> + * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
> + *
> + * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
> + */
> +#undef pr_fmt
> +#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt
> +
> +#include <linux/module.h>
> +#include <linux/inet.h>
> +
> +#include "rtrs-pri.h"
> +#include "rtrs-log.h"
> +
> +MODULE_DESCRIPTION("RDMA Transport Core");
> +MODULE_LICENSE("GPL");
> +
> +struct rtrs_iu *rtrs_iu_alloc(u32 queue_size, size_t size, gfp_t gfp_mask,
> +			      struct ib_device *dma_dev,
> +			      enum dma_data_direction dir,
> +			      void (*done)(struct ib_cq *cq, struct ib_wc *wc))
> +{
> +	struct rtrs_iu *ius, *iu;
> +	int i;
> +
> +	WARN_ON(!queue_size);
> +	ius = kcalloc(queue_size, sizeof(*ius), gfp_mask);
> +	if (unlikely(!ius))
> +		return NULL;

Let's do not add useless WARN_ON() and unlikely to every error path.

> +	for (i = 0; i < queue_size; i++) {
> +		iu = &ius[i];
> +		iu->buf = kzalloc(size, gfp_mask);
> +		if (unlikely(!iu->buf))
> +			goto err;
> +
> +		iu->dma_addr = ib_dma_map_single(dma_dev, iu->buf, size, dir);
> +		if (unlikely(ib_dma_mapping_error(dma_dev, iu->dma_addr)))
> +			goto err;
> +
> +		iu->cqe.done  = done;
> +		iu->size      = size;
> +		iu->direction = dir;
> +	}
> +	return ius;
> +err:
> +	rtrs_iu_free(ius, dir, dma_dev, i);
> +	return NULL;
> +}
> +EXPORT_SYMBOL_GPL(rtrs_iu_alloc);
> +
> +void rtrs_iu_free(struct rtrs_iu *ius, enum dma_data_direction dir,
> +		   struct ib_device *ibdev, u32 queue_size)
> +{
> +	struct rtrs_iu *iu;
> +	int i;
> +
> +	if (!ius)
> +		return;
> +
> +	for (i = 0; i < queue_size; i++) {
> +		iu = &ius[i];
> +		ib_dma_unmap_single(ibdev, iu->dma_addr, iu->size, dir);
> +		kfree(iu->buf);
> +	}
> +	kfree(ius);
> +}
> +EXPORT_SYMBOL_GPL(rtrs_iu_free);
> +
> +int rtrs_iu_post_recv(struct rtrs_con *con, struct rtrs_iu *iu)
> +{
> +	struct rtrs_sess *sess = con->sess;
> +	struct ib_recv_wr wr;
> +	struct ib_sge list;
> +
> +	list.addr   = iu->dma_addr;
> +	list.length = iu->size;
> +	list.lkey   = sess->dev->ib_pd->local_dma_lkey;
> +
> +	if (WARN_ON(list.length == 0)) {
> +		rtrs_wrn(con->sess,
> +			  "Posting receive work request failed, sg list is empty\n");

Both WARN_ON and warning message?

Thanks



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux