* [PATCH rdma-next] RDMA/core: Add rdma_dev_to_netns()
@ 2020-10-07 9:03 Ka-Cheong Poon
2020-10-07 11:14 ` Leon Romanovsky
0 siblings, 1 reply; 2+ messages in thread
From: Ka-Cheong Poon @ 2020-10-07 9:03 UTC (permalink / raw)
To: linux-rdma
This function returns the namespace of a struct ib_device if the RDMA
subsystem is in exclusive network namespace mode. If the subsystem is
in shared namespace mode, this function returns NULL.
Signed-off-by: Ka-Cheong Poon <ka-cheong.poon@oracle.com>
---
drivers/infiniband/core/device.c | 16 ++++++++++++++++
include/rdma/ib_verbs.h | 1 +
2 files changed, 17 insertions(+)
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index c36b4d2b61e0..a3dd95bf3050 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -144,6 +144,22 @@ bool rdma_dev_access_netns(const struct ib_device *dev, const struct net *net)
}
EXPORT_SYMBOL(rdma_dev_access_netns);
+/**
+ * rdma_dev_to_netns() - Return the net namespace of a given device if the
+ * RDMA subsystem is in exclusive network namespace
+ * mode. If it is in shared namespace mode, this
+ * function returns NULL. Caller can use it to
+ * differentiate the two modes of the RDMA subsystem.
+ *
+ * @device: Pointer to rdma device to get the namespace
+ */
+struct net *rdma_dev_to_netns(const struct ib_device *device)
+{
+ return ib_devices_shared_netns ? NULL :
+ read_pnet(&device->coredev.rdma_net);
+}
+EXPORT_SYMBOL(rdma_dev_to_netns);
+
/*
* xarray has this behavior where it won't iterate over NULL values stored in
* allocated arrays. So we need our own iterator to see all values stored in
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index c0b2fa7e9b95..aeced1a3324f 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -4715,6 +4715,7 @@ static inline struct ib_device *rdma_device_to_ibdev(struct device *device)
bool rdma_dev_access_netns(const struct ib_device *device,
const struct net *net);
+struct net *rdma_dev_to_netns(const struct ib_device *device);
#define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
#define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)
--
2.18.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH rdma-next] RDMA/core: Add rdma_dev_to_netns()
2020-10-07 9:03 [PATCH rdma-next] RDMA/core: Add rdma_dev_to_netns() Ka-Cheong Poon
@ 2020-10-07 11:14 ` Leon Romanovsky
0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2020-10-07 11:14 UTC (permalink / raw)
To: Ka-Cheong Poon; +Cc: linux-rdma
On Wed, Oct 07, 2020 at 02:03:55AM -0700, Ka-Cheong Poon wrote:
> This function returns the namespace of a struct ib_device if the RDMA
> subsystem is in exclusive network namespace mode. If the subsystem is
> in shared namespace mode, this function returns NULL.
>
> Signed-off-by: Ka-Cheong Poon <ka-cheong.poon@oracle.com>
> ---
> drivers/infiniband/core/device.c | 16 ++++++++++++++++
> include/rdma/ib_verbs.h | 1 +
> 2 files changed, 17 insertions(+)
We don't merge functions without users.
Thanks
>
> diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
> index c36b4d2b61e0..a3dd95bf3050 100644
> --- a/drivers/infiniband/core/device.c
> +++ b/drivers/infiniband/core/device.c
> @@ -144,6 +144,22 @@ bool rdma_dev_access_netns(const struct ib_device *dev, const struct net *net)
> }
> EXPORT_SYMBOL(rdma_dev_access_netns);
>
> +/**
> + * rdma_dev_to_netns() - Return the net namespace of a given device if the
> + * RDMA subsystem is in exclusive network namespace
> + * mode. If it is in shared namespace mode, this
> + * function returns NULL. Caller can use it to
> + * differentiate the two modes of the RDMA subsystem.
> + *
> + * @device: Pointer to rdma device to get the namespace
> + */
> +struct net *rdma_dev_to_netns(const struct ib_device *device)
> +{
> + return ib_devices_shared_netns ? NULL :
> + read_pnet(&device->coredev.rdma_net);
> +}
> +EXPORT_SYMBOL(rdma_dev_to_netns);
> +
> /*
> * xarray has this behavior where it won't iterate over NULL values stored in
> * allocated arrays. So we need our own iterator to see all values stored in
> diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> index c0b2fa7e9b95..aeced1a3324f 100644
> --- a/include/rdma/ib_verbs.h
> +++ b/include/rdma/ib_verbs.h
> @@ -4715,6 +4715,7 @@ static inline struct ib_device *rdma_device_to_ibdev(struct device *device)
>
> bool rdma_dev_access_netns(const struct ib_device *device,
> const struct net *net);
> +struct net *rdma_dev_to_netns(const struct ib_device *device);
>
> #define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
> #define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)
> --
> 2.18.4
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-07 11:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 9:03 [PATCH rdma-next] RDMA/core: Add rdma_dev_to_netns() Ka-Cheong Poon
2020-10-07 11:14 ` Leon Romanovsky
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.