app/pdump: use EAL hotplug instead of ethdev attach
authorAndrew Rybchenko <arybchenko@solarflare.com>
Wed, 11 Jul 2018 14:14:08 +0000 (15:14 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Sun, 5 Aug 2018 22:52:16 +0000 (00:52 +0200)
rte_eth_dev_attach() is to be deprecated.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
app/pdump/main.c

index 6bcf8c4..ac22871 100644 (file)
@@ -38,8 +38,9 @@
 #define PDUMP_MSIZE_ARG "mbuf-size"
 #define PDUMP_NUM_MBUFS_ARG "total-num-mbufs"
 
-#define VDEV_PCAP "net_pcap_%s_%d,tx_pcap=%s"
-#define VDEV_IFACE "net_pcap_%s_%d,tx_iface=%s"
+#define VDEV_NAME_FMT "net_pcap_%s_%d"
+#define VDEV_PCAP_ARGS_FMT "tx_pcap=%s"
+#define VDEV_IFACE_ARGS_FMT "tx_iface=%s"
 #define TX_STREAM_SIZE 64
 
 #define MP_NAME "pdump_pool_%d"
@@ -570,6 +571,7 @@ create_mp_ring_vdev(void)
        uint16_t portid;
        struct pdump_tuples *pt = NULL;
        struct rte_mempool *mbuf_pool = NULL;
+       char vdev_name[SIZE];
        char vdev_args[SIZE];
        char ring_name[SIZE];
        char mempool_name[SIZE];
@@ -619,17 +621,28 @@ create_mp_ring_vdev(void)
                        }
 
                        /* create vdevs */
+                       snprintf(vdev_name, sizeof(vdev_name),
+                                VDEV_NAME_FMT, RX_STR, i);
                        (pt->rx_vdev_stream_type == IFACE) ?
-                       snprintf(vdev_args, SIZE, VDEV_IFACE, RX_STR, i,
-                       pt->rx_dev) :
-                       snprintf(vdev_args, SIZE, VDEV_PCAP, RX_STR, i,
-                       pt->rx_dev);
-                       if (rte_eth_dev_attach(vdev_args, &portid) < 0) {
+                       snprintf(vdev_args, sizeof(vdev_args),
+                                VDEV_IFACE_ARGS_FMT, pt->rx_dev) :
+                       snprintf(vdev_args, sizeof(vdev_args),
+                                VDEV_PCAP_ARGS_FMT, pt->rx_dev);
+                       if (rte_eal_hotplug_add("vdev", vdev_name,
+                                               vdev_args) < 0) {
                                cleanup_rings();
                                rte_exit(EXIT_FAILURE,
                                        "vdev creation failed:%s:%d\n",
                                        __func__, __LINE__);
                        }
+                       if (rte_eth_dev_get_port_by_name(vdev_name,
+                                                        &portid) != 0) {
+                               rte_eal_hotplug_remove("vdev", vdev_name);
+                               cleanup_rings();
+                               rte_exit(EXIT_FAILURE,
+                                       "cannot find added vdev %s:%s:%d\n",
+                                       vdev_name, __func__, __LINE__);
+                       }
                        pt->rx_vdev_id = portid;
 
                        /* configure vdev */
@@ -638,18 +651,29 @@ create_mp_ring_vdev(void)
                        if (pt->single_pdump_dev)
                                pt->tx_vdev_id = portid;
                        else {
-                               (pt->tx_vdev_stream_type == IFACE) ?
-                               snprintf(vdev_args, SIZE, VDEV_IFACE, TX_STR, i,
-                               pt->tx_dev) :
-                               snprintf(vdev_args, SIZE, VDEV_PCAP, TX_STR, i,
-                               pt->tx_dev);
-                               if (rte_eth_dev_attach(vdev_args,
-                                                       &portid) < 0) {
+                               snprintf(vdev_name, sizeof(vdev_name),
+                                        VDEV_NAME_FMT, TX_STR, i);
+                               (pt->rx_vdev_stream_type == IFACE) ?
+                               snprintf(vdev_args, sizeof(vdev_args),
+                                        VDEV_IFACE_ARGS_FMT, pt->tx_dev) :
+                               snprintf(vdev_args, sizeof(vdev_args),
+                                        VDEV_PCAP_ARGS_FMT, pt->tx_dev);
+                               if (rte_eal_hotplug_add("vdev", vdev_name,
+                                                       vdev_args) < 0) {
                                        cleanup_rings();
                                        rte_exit(EXIT_FAILURE,
                                                "vdev creation failed:"
                                                "%s:%d\n", __func__, __LINE__);
                                }
+                               if (rte_eth_dev_get_port_by_name(vdev_name,
+                                               &portid) != 0) {
+                                       rte_eal_hotplug_remove("vdev",
+                                                              vdev_name);
+                                       cleanup_rings();
+                                       rte_exit(EXIT_FAILURE,
+                                               "cannot find added vdev %s:%s:%d\n",
+                                               vdev_name, __func__, __LINE__);
+                               }
                                pt->tx_vdev_id = portid;
 
                                /* configure vdev */
@@ -667,17 +691,28 @@ create_mp_ring_vdev(void)
                                        rte_strerror(rte_errno));
                        }
 
+                       snprintf(vdev_name, sizeof(vdev_name),
+                                VDEV_NAME_FMT, RX_STR, i);
                        (pt->rx_vdev_stream_type == IFACE) ?
-                       snprintf(vdev_args, SIZE, VDEV_IFACE, RX_STR, i,
-                               pt->rx_dev) :
-                       snprintf(vdev_args, SIZE, VDEV_PCAP, RX_STR, i,
-                               pt->rx_dev);
-                       if (rte_eth_dev_attach(vdev_args, &portid) < 0) {
+                       snprintf(vdev_args, sizeof(vdev_args),
+                                VDEV_IFACE_ARGS_FMT, pt->rx_dev) :
+                       snprintf(vdev_args, sizeof(vdev_args),
+                                VDEV_PCAP_ARGS_FMT, pt->rx_dev);
+                       if (rte_eal_hotplug_add("vdev", vdev_name,
+                                               vdev_args) < 0) {
                                cleanup_rings();
                                rte_exit(EXIT_FAILURE,
                                        "vdev creation failed:%s:%d\n",
                                        __func__, __LINE__);
                        }
+                       if (rte_eth_dev_get_port_by_name(vdev_name,
+                                                        &portid) != 0) {
+                               rte_eal_hotplug_remove("vdev", vdev_name);
+                               cleanup_rings();
+                               rte_exit(EXIT_FAILURE,
+                                       "cannot find added vdev %s:%s:%d\n",
+                                       vdev_name, __func__, __LINE__);
+                       }
                        pt->rx_vdev_id = portid;
                        /* configure vdev */
                        configure_vdev(pt->rx_vdev_id);
@@ -693,16 +728,27 @@ create_mp_ring_vdev(void)
                                        rte_strerror(rte_errno));
                        }
 
+                       snprintf(vdev_name, sizeof(vdev_name),
+                                VDEV_NAME_FMT, TX_STR, i);
                        (pt->tx_vdev_stream_type == IFACE) ?
-                       snprintf(vdev_args, SIZE, VDEV_IFACE, TX_STR, i,
-                               pt->tx_dev) :
-                       snprintf(vdev_args, SIZE, VDEV_PCAP, TX_STR, i,
-                               pt->tx_dev);
-                       if (rte_eth_dev_attach(vdev_args, &portid) < 0) {
+                       snprintf(vdev_args, sizeof(vdev_args),
+                                VDEV_IFACE_ARGS_FMT, pt->tx_dev) :
+                       snprintf(vdev_args, sizeof(vdev_args),
+                                VDEV_PCAP_ARGS_FMT, pt->tx_dev);
+                       if (rte_eal_hotplug_add("vdev", vdev_name,
+                                               vdev_args) < 0) {
                                cleanup_rings();
                                rte_exit(EXIT_FAILURE,
                                        "vdev creation failed\n");
                        }
+                       if (rte_eth_dev_get_port_by_name(vdev_name,
+                                                        &portid) != 0) {
+                               rte_eal_hotplug_remove("vdev", vdev_name);
+                               cleanup_rings();
+                               rte_exit(EXIT_FAILURE,
+                                       "cannot find added vdev %s:%s:%d\n",
+                                       vdev_name, __func__, __LINE__);
+                       }
                        pt->tx_vdev_id = portid;
 
                        /* configure vdev */