linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Jack Wang <jinpuwang@gmail.com>
Cc: linux-block@vger.kernel.org, linux-rdma@vger.kernel.org,
	axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me,
	bvanassche@acm.org, dledford@redhat.com, jgg@ziepe.ca,
	danil.kipnis@cloud.ionos.com, jinpu.wang@cloud.ionos.com,
	rpenyaev@suse.de, pankaj.gupta@cloud.ionos.com
Subject: Re: [PATCH v9 04/25] RDMA/rtrs: core: lib functions shared between client and server modules
Date: Tue, 3 Mar 2020 11:57:13 +0200	[thread overview]
Message-ID: <20200303095713.GK121803@unreal> (raw)
In-Reply-To: <20200221104721.350-5-jinpuwang@gmail.com>

On Fri, Feb 21, 2020 at 11:47:00AM +0100, Jack Wang wrote:
> From: Jack Wang <jinpu.wang@cloud.ionos.com>
>
> 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@cloud.ionos.com>
> Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com>
> ---
>  drivers/infiniband/ulp/rtrs/rtrs.c | 594 +++++++++++++++++++++++++++++
>  1 file changed, 594 insertions(+)
>  create mode 100644 drivers/infiniband/ulp/rtrs/rtrs.c

<...>

> +
> +static void dev_free(struct kref *ref)
> +{
> +	struct rtrs_rdma_dev_pd *pool;
> +	struct rtrs_ib_dev *dev;
> +
> +	dev = container_of(ref, typeof(*dev), ref);
> +	pool = dev->pool;
> +
> +	mutex_lock(&pool->mutex);
> +	list_del(&dev->entry);
> +	mutex_unlock(&pool->mutex);
> +
> +	if (pool->ops && pool->ops->deinit)
> +		pool->ops->deinit(dev);
> +
> +	ib_dealloc_pd(dev->ib_pd);
> +
> +	if (pool->ops && pool->ops->free)
> +		pool->ops->free(dev);
> +	else
> +		kfree(dev);
> +}
> +
> +int rtrs_ib_dev_put(struct rtrs_ib_dev *dev)
> +{
> +	return kref_put(&dev->ref, dev_free);
> +}
> +EXPORT_SYMBOL(rtrs_ib_dev_put);
> +
> +static int rtrs_ib_dev_get(struct rtrs_ib_dev *dev)
> +{
> +	return kref_get_unless_zero(&dev->ref);
> +}
> +
> +struct rtrs_ib_dev *
> +rtrs_ib_dev_find_or_add(struct ib_device *ib_dev,
> +			 struct rtrs_rdma_dev_pd *pool)
> +{
> +	struct rtrs_ib_dev *dev;
> +
> +	mutex_lock(&pool->mutex);

The scope of this mutex is unclear, you protected everything here with
this mutex, but in dev_free() you guarded list_del() only.

> +	list_for_each_entry(dev, &pool->list, entry) {
> +		if (dev->ib_dev->node_guid == ib_dev->node_guid &&
> +		    rtrs_ib_dev_get(dev))
> +			goto out_unlock;
> +	}
> +	if (pool->ops && pool->ops->alloc)
> +		dev = pool->ops->alloc();
> +	else
> +		dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> +	if (IS_ERR_OR_NULL(dev))
> +		goto out_err;
> +
> +	kref_init(&dev->ref);
> +	dev->pool = pool;
> +	dev->ib_dev = ib_dev;
> +	dev->ib_pd = ib_alloc_pd(ib_dev, pool->pd_flags);
> +	if (IS_ERR(dev->ib_pd))
> +		goto out_free_dev;
> +
> +	if (pool->ops && pool->ops->init && pool->ops->init(dev))
> +		goto out_free_pd;
> +
> +	list_add(&dev->entry, &pool->list);
> +out_unlock:
> +	mutex_unlock(&pool->mutex);
> +	return dev;
> +
> +out_free_pd:
> +	ib_dealloc_pd(dev->ib_pd);
> +out_free_dev:
> +	if (pool->ops && pool->ops->free)
> +		pool->ops->free(dev);
> +	else
> +		kfree(dev);
> +out_err:
> +	mutex_unlock(&pool->mutex);
> +	return NULL;
> +}
> +EXPORT_SYMBOL(rtrs_ib_dev_find_or_add);
> --
> 2.17.1
>

  parent reply	other threads:[~2020-03-03  9:57 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-21 10:46 [PATCH v9 00/25] RTRS (former IBTRS) RDMA Transport Library and RNBD (former IBNBD) RDMA Network Block Device Jack Wang
2020-02-21 10:46 ` [PATCH v9 01/25] sysfs: export sysfs_remove_file_self() Jack Wang
2020-03-01  0:24   ` Bart Van Assche
2020-03-02 14:37     ` Jinpu Wang
2020-02-21 10:46 ` [PATCH v9 02/25] RDMA/rtrs: public interface header to establish RDMA connections Jack Wang
2020-03-01  0:31   ` Bart Van Assche
2020-03-02  8:39     ` Jinpu Wang
2020-03-03  9:40   ` Leon Romanovsky
2020-03-03 14:05     ` Jinpu Wang
2020-03-03 14:16       ` Leon Romanovsky
2020-03-03 14:23         ` Jinpu Wang
2020-02-21 10:46 ` [PATCH v9 03/25] RDMA/rtrs: private headers with rtrs protocol structs and helpers Jack Wang
2020-03-01  0:37   ` Bart Van Assche
2020-03-02  9:21     ` Jinpu Wang
2020-03-03  9:45   ` Leon Romanovsky
2020-03-03 13:52     ` Jinpu Wang
2020-03-03 14:05       ` Jason Gunthorpe
2020-03-03 16:13         ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 04/25] RDMA/rtrs: core: lib functions shared between client and server modules Jack Wang
2020-03-01  0:47   ` Bart Van Assche
2020-03-02  8:40     ` Jinpu Wang
2020-03-03  9:57   ` Leon Romanovsky [this message]
2020-03-04 11:21     ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 05/25] RDMA/rtrs: client: private header with client structs and functions Jack Wang
2020-03-01  0:51   ` Bart Van Assche
2020-03-02 13:49     ` Jinpu Wang
2020-03-02 16:13       ` Bart Van Assche
2020-03-02 16:18         ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 06/25] RDMA/rtrs: client: main functionality Jack Wang
2020-03-01  1:33   ` Bart Van Assche
2020-03-02 13:20     ` Danil Kipnis
2020-03-03 16:04       ` Bart Van Assche
2020-03-04 16:43         ` Jinpu Wang
2020-03-04 16:49           ` Jason Gunthorpe
2020-03-05 11:26             ` Jinpu Wang
2020-03-05 13:27               ` Jason Gunthorpe
2020-03-05 13:37                 ` Jinpu Wang
2020-03-05 13:54                   ` Jason Gunthorpe
2020-03-06 13:33                     ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 07/25] RDMA/rtrs: client: statistics functions Jack Wang
2020-03-03 11:28   ` Leon Romanovsky
2020-03-03 11:46     ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 08/25] RDMA/rtrs: client: sysfs interface functions Jack Wang
2020-02-21 10:47 ` [PATCH v9 09/25] RDMA/rtrs: server: private header with server structs and functions Jack Wang
2020-02-21 10:47 ` [PATCH v9 10/25] RDMA/rtrs: server: main functionality Jack Wang
2020-03-01  1:42   ` Bart Van Assche
2020-03-02 14:39     ` Jinpu Wang
2020-03-03 11:37   ` Leon Romanovsky
2020-03-03 16:41     ` Jinpu Wang
2020-03-03 16:59       ` Leon Romanovsky
2020-03-04 11:03         ` Jinpu Wang
2020-03-05  8:00           ` Leon Romanovsky
     [not found]             ` <CAHg0Huyc=pn1=WSKGLjm+c8AcchyQ8q7JS-0ToQyiBRgpGG=jA@mail.gmail.com>
2020-03-05 12:16               ` Leon Romanovsky
2020-03-05 12:28                 ` Jinpu Wang
2020-03-05 12:35                   ` Leon Romanovsky
2020-03-05 13:02                     ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 11/25] RDMA/rtrs: server: statistics functions Jack Wang
2020-02-21 10:47 ` [PATCH v9 12/25] RDMA/rtrs: server: sysfs interface functions Jack Wang
2020-02-21 10:47 ` [PATCH v9 13/25] RDMA/rtrs: include client and server modules into kernel compilation Jack Wang
2020-02-21 10:47 ` [PATCH v9 14/25] RDMA/rtrs: a bit of documentation Jack Wang
2020-02-21 10:47 ` [PATCH v9 15/25] block/rnbd: private headers with rnbd protocol structs and helpers Jack Wang
2020-03-01  2:12   ` Bart Van Assche
2020-03-02 16:37     ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 16/25] block/rnbd: client: private header with client structs and functions Jack Wang
2020-03-01  2:26   ` Bart Van Assche
2020-03-02 14:59     ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 17/25] block/rnbd: client: main functionality Jack Wang
2020-03-01  2:46   ` Bart Van Assche
2020-03-02 14:58     ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 18/25] block/rnbd: client: sysfs interface functions Jack Wang
2020-02-21 10:47 ` [PATCH v9 19/25] block/rnbd: server: private header with server structs and functions Jack Wang
2020-03-01  2:47   ` Bart Van Assche
2020-03-02 10:07     ` Danil Kipnis
2020-02-21 10:47 ` [PATCH v9 20/25] block/rnbd: server: main functionality Jack Wang
2020-03-01  2:58   ` Bart Van Assche
2020-03-02  9:58     ` Danil Kipnis
2020-03-03  5:57       ` Bart Van Assche
2020-02-21 10:47 ` [PATCH v9 21/25] block/rnbd: server: functionality for IO submission to file or block dev Jack Wang
2020-03-01  3:09   ` Bart Van Assche
2020-03-02 10:06     ` Danil Kipnis
2020-03-03 16:20       ` Jinpu Wang
2020-03-03 16:28         ` Bart Van Assche
2020-03-03 16:43           ` Jinpu Wang
2020-02-21 10:47 ` [PATCH v9 22/25] block/rnbd: server: sysfs interface functions Jack Wang
2020-02-21 10:47 ` [PATCH v9 23/25] block/rnbd: include client and server modules into kernel compilation Jack Wang
2020-02-21 10:47 ` [PATCH v9 24/25] block/rnbd: a bit of documentation Jack Wang
2020-02-21 10:47 ` [PATCH v9 25/25] MAINTAINERS: Add maintainers for RNBD/RTRS modules Jack Wang
2020-03-03  9:28 ` [PATCH v9 00/25] RTRS (former IBTRS) RDMA Transport Library and RNBD (former IBNBD) RDMA Network Block Device Leon Romanovsky
2020-03-04 14:06   ` Jinpu Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200303095713.GK121803@unreal \
    --to=leon@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=danil.kipnis@cloud.ionos.com \
    --cc=dledford@redhat.com \
    --cc=hch@infradead.org \
    --cc=jgg@ziepe.ca \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=jinpuwang@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=pankaj.gupta@cloud.ionos.com \
    --cc=rpenyaev@suse.de \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).