Re: [RFC WIP 2/2] rdma_rxe: use netlink messages to add/delete links

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

 



On Fri, Sep 14, 2018 at 11:43:55AM -0700, Steve Wise wrote:
> Signed-off-by: Steve Wise <swise@xxxxxxxxxxxxxxxxxxxxx>
>  drivers/infiniband/sw/rxe/rxe.c       | 61 +++++++++++++++++++++++++++++++++++
>  drivers/infiniband/sw/rxe/rxe_net.c   |  3 +-
>  drivers/infiniband/sw/rxe/rxe_net.h   |  2 +-
>  drivers/infiniband/sw/rxe/rxe_sysfs.c |  6 ++--
>  drivers/infiniband/sw/rxe/rxe_verbs.c |  1 -
>  5 files changed, 67 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/infiniband/sw/rxe/rxe.c b/drivers/infiniband/sw/rxe/rxe.c
> index 10999fa69281..83f52954c300 100644
> +++ b/drivers/infiniband/sw/rxe/rxe.c
> @@ -31,6 +31,7 @@
>   * SOFTWARE.
>   */
>  
> +#include <rdma/rdma_netlink.h>
>  #include <net/addrconf.h>
>  #include "rxe.h"
>  #include "rxe_loc.h"
> @@ -340,6 +341,64 @@ void rxe_remove(struct rxe_dev *rxe)
>  	rxe_dev_put(rxe);
>  }
>  
> +static int rxe_newlink(char *ibdev_name, char *ndev_name)

const char *ndev_name

> +{
> +	struct net_device *ndev = NULL;
> +	struct rxe_dev *rxe;
> +	int err = 0;
> +
> +	ndev = dev_get_by_name(&init_net, ndev_name);
> +	if (!ndev) {
> +		pr_err("interface %s not found\n", ndev_name);
> +		err = -ENODEV;
> +		goto err;
> +	}
> +
> +	if (net_to_rxe(ndev)) {
> +		pr_err("already configured on %s\n", ndev_name);
> +		err = -EEXIST;
> +		goto err;
> +	}
> +
> +	rxe = rxe_net_add(ibdev_name, ndev);
> +	if (!rxe) {
> +		pr_err("failed to add %s\n", ndev_name);
> +		err = -EINVAL;
> +		goto err;
> +	}
> +
> +	if (netif_running(ndev) && netif_carrier_ok(ndev))
> +		rxe_port_up(rxe);
> +	else
> +		rxe_port_down(rxe);
> +	pr_info("added %s to %s\n", rxe->ib_dev.name, ndev->name);
> +err:
> +	if (ndev)
> +		dev_put(ndev);
> +	return err;
> +}
> +
> +static int rxe_dellink(char *ibdev_name)
> +{
> +	struct rxe_dev *rxe;
> +
> +	rxe = get_rxe_by_name(ibdev_name);
> +	if (!rxe) {
> +		pr_err("not configured on %s\n", ibdev_name);
> +		return -ENODEV;
> +	}
> +
> +	list_del(&rxe->list);
> +	rxe_remove(rxe);
> +	return 0;
> +}
> +
> +static struct rdma_link_ops rxe_link_ops = {
> +	.type = "rxe",
> +	.newlink = rxe_newlink,
> +	.dellink = rxe_dellink,
> +};
> +
>  static int __init rxe_module_init(void)
>  {
>  	int err;
> @@ -355,12 +414,14 @@ static int __init rxe_module_init(void)
>  	if (err)
>  		return err;
>  
> +	rdma_link_register(&rxe_link_ops);
>  	pr_info("loaded\n");
>  	return 0;
>  }
>  
>  static void __exit rxe_module_exit(void)
>  {
> +	rdma_link_unregister(&rxe_link_ops);
>  	rxe_remove_all();
>  	rxe_net_exit();
>  	rxe_cache_exit();
> diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c
> index 8094cbaa54a9..0c520999c8d4 100644
> +++ b/drivers/infiniband/sw/rxe/rxe_net.c
> @@ -565,7 +565,7 @@ enum rdma_link_layer rxe_link_layer(struct rxe_dev *rxe, unsigned int port_num)
>  	return IB_LINK_LAYER_ETHERNET;
>  }
>  
> -struct rxe_dev *rxe_net_add(struct net_device *ndev)
> +struct rxe_dev *rxe_net_add(char *ibdev_name, struct net_device *ndev)
>  {
>  	int err;
>  	struct rxe_dev *rxe = NULL;
> @@ -575,6 +575,7 @@ struct rxe_dev *rxe_net_add(struct net_device *ndev)
>  		return NULL;
>  
>  	rxe->ndev = ndev;
> +	strlcpy(rxe->ib_dev.name, ibdev_name, IB_DEVICE_NAME_MAX);

I'm trying to delete these, don't add new ones :)

The name needs to be passed to register. Maybe check that it doesn't
have % in it in the core code too.

>  	err = rxe_add(rxe, ndev->mtu);
>  	if (err) {
> diff --git a/drivers/infiniband/sw/rxe/rxe_net.h b/drivers/infiniband/sw/rxe/rxe_net.h
> index 106c586dbb26..5e646039d393 100644
> +++ b/drivers/infiniband/sw/rxe/rxe_net.h
> @@ -43,7 +43,7 @@ struct rxe_recv_sockets {
>  	struct socket *sk6;
>  };
>  
> -struct rxe_dev *rxe_net_add(struct net_device *ndev);
> +struct rxe_dev *rxe_net_add(char *ibdev_name, struct net_device *ndev);
>  
>  int rxe_net_init(void);
>  void rxe_net_exit(void);
> diff --git a/drivers/infiniband/sw/rxe/rxe_sysfs.c b/drivers/infiniband/sw/rxe/rxe_sysfs.c
> index d5ed7571128f..1f82019ff8f3 100644
> +++ b/drivers/infiniband/sw/rxe/rxe_sysfs.c
> @@ -97,7 +97,7 @@ static int rxe_param_set_add(const char *val, const struct kernel_param *kp)
>  		goto err;
>  	}
>  
> -	rxe = rxe_net_add(ndev);
> +	rxe = rxe_net_add(NULL, ndev);

Doesn't this crash?

Jason



[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