Message ID | 20170809160405.25142-14-leon@kernel.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
On 8/9/2017 12:03 PM, Leon Romanovsky wrote: > From: Leon Romanovsky <leonro@mellanox.com> > > The coming nldev needs to iterate over all IB devices in the system > and in order to not expose the ib_devices list outside the devices.c, > it is necessary to provide function iterator. > > Current version is written explicitly for nldev callback to avoid > over-engineering at this stage, but it can be easily extended for > other types. > > Signed-off-by: Leon Romanovsky <leonro@mellanox.com> > Reviewed-by: Steve Wise <swise@opengridcomputing.com> > --- > drivers/infiniband/core/core_priv.h | 8 ++++++++ > drivers/infiniband/core/device.c | 25 +++++++++++++++++++++++++ > 2 files changed, 33 insertions(+) > > diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h > index e759c27113cd..0c175590cf92 100644 > --- a/drivers/infiniband/core/core_priv.h > +++ b/drivers/infiniband/core/core_priv.h > @@ -102,6 +102,14 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter, > roce_netdev_callback cb, > void *cookie); > > +typedef int (*nldev_callback)(struct ib_device *device, > + struct sk_buff *skb, > + struct netlink_callback *cb, > + unsigned int idx); > + > +int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb, > + struct netlink_callback *cb); > + > enum ib_cache_gid_default_mode { > IB_CACHE_GID_DEFAULT_MODE_SET, > IB_CACHE_GID_DEFAULT_MODE_DELETE > diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c > index a1d5798fa4d7..54143476a020 100644 > --- a/drivers/infiniband/core/device.c > +++ b/drivers/infiniband/core/device.c > @@ -892,6 +892,31 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter, > up_read(&lists_rwsem); > } > > +/** > + * ib_enum_all_devs - enumerate all ib_devices > + * @cb: Callback to call for each found ib_device > + * > + * Enumerates all ib_devices and calls callback() on each device. > + */ > +int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb, > + struct netlink_callback *cb) > +{ > + struct ib_device *dev; > + unsigned int idx = 0; > + int ret = 0; > + > + down_read(&lists_rwsem); > + list_for_each_entry(dev, &device_list, core_list) { > + ret = nldev_cb(dev, skb, cb, idx); This clearly enumerates more than just ib devs, should the signature not be rdma_enum_all_devs? > + if (ret) > + break; > + idx++; > + } > + > + up_read(&lists_rwsem); > + return ret; > +} > + > /** > * ib_query_pkey - Get P_Key table entry > * @device:Device to query >
On Wed, Aug 09, 2017 at 01:09:00PM -0400, Doug Ledford wrote: > On 8/9/2017 12:03 PM, Leon Romanovsky wrote: > > From: Leon Romanovsky <leonro@mellanox.com> > > > > The coming nldev needs to iterate over all IB devices in the system > > and in order to not expose the ib_devices list outside the devices.c, > > it is necessary to provide function iterator. > > > > Current version is written explicitly for nldev callback to avoid > > over-engineering at this stage, but it can be easily extended for > > other types. > > > > Signed-off-by: Leon Romanovsky <leonro@mellanox.com> > > Reviewed-by: Steve Wise <swise@opengridcomputing.com> > > --- > > drivers/infiniband/core/core_priv.h | 8 ++++++++ > > drivers/infiniband/core/device.c | 25 +++++++++++++++++++++++++ > > 2 files changed, 33 insertions(+) > > > > diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h > > index e759c27113cd..0c175590cf92 100644 > > --- a/drivers/infiniband/core/core_priv.h > > +++ b/drivers/infiniband/core/core_priv.h > > @@ -102,6 +102,14 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter, > > roce_netdev_callback cb, > > void *cookie); > > > > +typedef int (*nldev_callback)(struct ib_device *device, > > + struct sk_buff *skb, > > + struct netlink_callback *cb, > > + unsigned int idx); > > + > > +int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb, > > + struct netlink_callback *cb); > > + > > enum ib_cache_gid_default_mode { > > IB_CACHE_GID_DEFAULT_MODE_SET, > > IB_CACHE_GID_DEFAULT_MODE_DELETE > > diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c > > index a1d5798fa4d7..54143476a020 100644 > > --- a/drivers/infiniband/core/device.c > > +++ b/drivers/infiniband/core/device.c > > @@ -892,6 +892,31 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter, > > up_read(&lists_rwsem); > > } > > > > +/** > > + * ib_enum_all_devs - enumerate all ib_devices > > + * @cb: Callback to call for each found ib_device > > + * > > + * Enumerates all ib_devices and calls callback() on each device. > > + */ > > +int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb, > > + struct netlink_callback *cb) > > +{ > > + struct ib_device *dev; > > + unsigned int idx = 0; > > + int ret = 0; > > + > > + down_read(&lists_rwsem); > > + list_for_each_entry(dev, &device_list, core_list) { > > + ret = nldev_cb(dev, skb, cb, idx); > > This clearly enumerates more than just ib devs, should the signature not > be rdma_enum_all_devs? It enumerates "struct ib_device"s, so I prefer to leave it as is for now. > > > + if (ret) > > + break; > > + idx++; > > + } > > + > > + up_read(&lists_rwsem); > > + return ret; > > +} > > + > > /** > > * ib_query_pkey - Get P_Key table entry > > * @device:Device to query > > > > > -- > Doug Ledford <dledford@redhat.com> > GPG Key ID: B826A3330E572FDD > Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD >
diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index e759c27113cd..0c175590cf92 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -102,6 +102,14 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter, roce_netdev_callback cb, void *cookie); +typedef int (*nldev_callback)(struct ib_device *device, + struct sk_buff *skb, + struct netlink_callback *cb, + unsigned int idx); + +int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb, + struct netlink_callback *cb); + enum ib_cache_gid_default_mode { IB_CACHE_GID_DEFAULT_MODE_SET, IB_CACHE_GID_DEFAULT_MODE_DELETE diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index a1d5798fa4d7..54143476a020 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -892,6 +892,31 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter, up_read(&lists_rwsem); } +/** + * ib_enum_all_devs - enumerate all ib_devices + * @cb: Callback to call for each found ib_device + * + * Enumerates all ib_devices and calls callback() on each device. + */ +int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb, + struct netlink_callback *cb) +{ + struct ib_device *dev; + unsigned int idx = 0; + int ret = 0; + + down_read(&lists_rwsem); + list_for_each_entry(dev, &device_list, core_list) { + ret = nldev_cb(dev, skb, cb, idx); + if (ret) + break; + idx++; + } + + up_read(&lists_rwsem); + return ret; +} + /** * ib_query_pkey - Get P_Key table entry * @device:Device to query