From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by dpdk.org (Postfix) with ESMTP id 5B5638DAE for ; Wed, 25 Apr 2018 17:56:52 +0200 (CEST) Received: by mail-pg0-f65.google.com with SMTP id j11so13635431pgf.2 for ; Wed, 25 Apr 2018 08:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xO05wdM8SHMakUlgjWc97MY2a3agwRJ31KmUJT0ZHqw=; b=nDce5pAUXFSPi5KGPgJRCw6oUkLJNikFmTJrFiUA/YBo4yaAE0VRnLwGJODAkJBy6d DOMCWJoBCyZeHxnrixu81PEdc9nNWYCEjusMHv+fdar/eY7qR5pNEsntXXKJJ4Tkcju/ RE8YLocdFuWUITAvLlUgSG3gs5MW9YhIsG9htqCwpceBxdVGgteuJEeq+sClND7Xvlcn bmxk4ToMhkxW8xvoT//IV+NTOD67SMpPpQpq190w0tlmaOsORTtt+fpQKfIxnqg342BL mK1dX4Blcd/NbBRP/Za2Q62yzMIr69EsSd5n8CrT3rMApudHzA6wBGxvUtRZdXwaUQO/ 5v1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xO05wdM8SHMakUlgjWc97MY2a3agwRJ31KmUJT0ZHqw=; b=QsFY6EP+rXH8wWPnYRis3kenfxAXgU/jLeRPQ2vmDCXkxf+nBl+DGFoVOZxmIsK2WO QLuxLs8dUmLBgwVuVGmqhb1JI/VfIfVqiZOOf+jNU4X7W46gO4Mh/c3lZ0qrjZkQeSBk geOGiKXZWYqF4WXjCuU8PyXD4V07LycVw5s3vV4dTmKZ+fTlVotght/6MscqV2BsFVMk 2aHDodfc0wAIegVtWqOQ6Btam16Dv0r/nCQ3eyF6caR0NiPT/+Exjz7rBYOFo/wwa6lB ZkSRXlOtpyza6uOD1fZSnLKrPTsrfl7xWA9KGPw+KdakJb1mRxC4PenuceJMQEKWapKD 9lOA== X-Gm-Message-State: ALQs6tC5uuBkCEJ+/cHcRRSyDB3Uq1UcROvbBi/kqfV87MQidFT1EtQ0 g//HL9ouJTHSVVYWHsb84SIYF+vRJEA= X-Google-Smtp-Source: AIpwx48HT5H52XSq+7Vq643JsTSIo5aBCLvS63hJkUgdOmOSNbJAM8Z2yeGr8nEFgttfhlnkMxk8yw== X-Received: by 10.98.70.155 with SMTP id o27mr28273733pfi.124.1524671810679; Wed, 25 Apr 2018 08:56:50 -0700 (PDT) Received: from xeon-e3.lan (204-195-71-95.wavecable.com. [204.195.71.95]) by smtp.gmail.com with ESMTPSA id y3sm25713924pgc.81.2018.04.25.08.56.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 08:56:49 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Wed, 25 Apr 2018 08:56:37 -0700 Message-Id: <20180425155646.3627-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425155646.3627-1-stephen@networkplumber.org> References: <20180425155646.3627-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH next 01/10] net/tap: convert to dynamic logging X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Apr 2018 15:56:52 -0000 Use new logging macro to convert all calls to RTE_LOG() into new dynamic log type. Also fix whitespace. Signed-off-by: Stephen Hemminger --- drivers/net/tap/rte_eth_tap.c | 168 ++++++++++++++++++---------------- drivers/net/tap/rte_eth_tap.h | 1 + drivers/net/tap/tap_flow.c | 51 +++++------ drivers/net/tap/tap_intr.c | 2 +- drivers/net/tap/tap_log.h | 10 ++ drivers/net/tap/tap_netlink.c | 18 ++-- drivers/net/tap/tap_tcmsgs.c | 9 +- 7 files changed, 138 insertions(+), 121 deletions(-) create mode 100644 drivers/net/tap/tap_log.h diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index cca5852cc3ac..63f05cec6706 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -118,50 +118,46 @@ tun_alloc(struct pmd_internals *pmd) ifr.ifr_flags = (tap_type) ? IFF_TAP : IFF_TUN | IFF_POINTOPOINT; snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name); - RTE_LOG(DEBUG, PMD, "ifr_name '%s'\n", ifr.ifr_name); + TAP_LOG(DEBUG, "ifr_name '%s'", ifr.ifr_name); fd = open(TUN_TAP_DEV_PATH, O_RDWR); if (fd < 0) { - RTE_LOG(ERR, PMD, "Unable to create %s interface\n", - tuntap_name); + TAP_LOG(ERR, "Unable to create %s interface", tuntap_name); goto error; } #ifdef IFF_MULTI_QUEUE /* Grab the TUN features to verify we can work multi-queue */ if (ioctl(fd, TUNGETFEATURES, &features) < 0) { - RTE_LOG(ERR, PMD, "%s unable to get TUN/TAP features\n", - tuntap_name); + TAP_LOG(ERR, "%s unable to get TUN/TAP features", + tuntap_name); goto error; } - RTE_LOG(DEBUG, PMD, "%s Features %08x\n", tuntap_name, features); + TAP_LOG(DEBUG, "%s Features %08x", tuntap_name, features); if (features & IFF_MULTI_QUEUE) { - RTE_LOG(DEBUG, PMD, " Multi-queue support for %d queues\n", + TAP_LOG(DEBUG, " Multi-queue support for %d queues", RTE_PMD_TAP_MAX_QUEUES); ifr.ifr_flags |= IFF_MULTI_QUEUE; } else #endif { ifr.ifr_flags |= IFF_ONE_QUEUE; - RTE_LOG(DEBUG, PMD, " Single queue only support\n"); + TAP_LOG(DEBUG, " Single queue only support"); } /* Set the TUN/TAP configuration and set the name if needed */ if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) { - RTE_LOG(WARNING, PMD, - "Unable to set TUNSETIFF for %s\n", - ifr.ifr_name); - perror("TUNSETIFF"); + TAP_LOG(WARNING, "Unable to set TUNSETIFF for %s: %s", + ifr.ifr_name, strerror(errno)); goto error; } /* Always set the file descriptor to non-blocking */ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { - RTE_LOG(WARNING, PMD, - "Unable to set %s to nonblocking\n", - ifr.ifr_name); - perror("F_SETFL, NONBLOCK"); + TAP_LOG(WARNING, + "Unable to set %s to nonblocking: %s", + ifr.ifr_name, strerror(errno)); goto error; } @@ -195,10 +191,11 @@ tun_alloc(struct pmd_internals *pmd) fcntl(fd, F_SETFL, flags | O_ASYNC); fcntl(fd, F_SETOWN, getpid()); } while (0); + if (errno) { /* Disable trigger globally in case of error */ tap_trigger = 0; - RTE_LOG(WARNING, PMD, "Rx trigger disabled: %s\n", + TAP_LOG(WARNING, "Rx trigger disabled: %s", strerror(errno)); } @@ -630,8 +627,8 @@ tap_ioctl(struct pmd_internals *pmd, unsigned long request, return 0; error: - RTE_LOG(DEBUG, PMD, "%s: %s(%s) failed: %s(%d)\n", ifr->ifr_name, - __func__, tap_ioctl_req2str(request), strerror(errno), errno); + TAP_LOG(DEBUG, "%s(%s) failed: %s(%d)", ifr->ifr_name, + tap_ioctl_req2str(request), strerror(errno), errno); return -errno; } @@ -683,34 +680,34 @@ tap_dev_configure(struct rte_eth_dev *dev) if ((tx_offloads & supp_tx_offloads) != tx_offloads) { rte_errno = ENOTSUP; - RTE_LOG(ERR, PMD, + TAP_LOG(ERR, "Some Tx offloads are not supported " - "requested 0x%" PRIx64 " supported 0x%" PRIx64 "\n", + "requested 0x%" PRIx64 " supported 0x%" PRIx64, tx_offloads, supp_tx_offloads); return -rte_errno; } if (dev->data->nb_rx_queues > RTE_PMD_TAP_MAX_QUEUES) { - RTE_LOG(ERR, PMD, - "%s: number of rx queues %d exceeds max num of queues %d\n", + TAP_LOG(ERR, + "%s: number of rx queues %d exceeds max num of queues %d", dev->device->name, dev->data->nb_rx_queues, RTE_PMD_TAP_MAX_QUEUES); return -1; } if (dev->data->nb_tx_queues > RTE_PMD_TAP_MAX_QUEUES) { - RTE_LOG(ERR, PMD, - "%s: number of tx queues %d exceeds max num of queues %d\n", + TAP_LOG(ERR, + "%s: number of tx queues %d exceeds max num of queues %d", dev->device->name, dev->data->nb_tx_queues, RTE_PMD_TAP_MAX_QUEUES); return -1; } - RTE_LOG(INFO, PMD, "%s: %p: TX configured queues number: %u\n", - dev->device->name, (void *)dev, dev->data->nb_tx_queues); + TAP_LOG(INFO, "%s: %p: TX configured queues number: %u", + dev->device->name, (void *)dev, dev->data->nb_tx_queues); - RTE_LOG(INFO, PMD, "%s: %p: RX configured queues number: %u\n", - dev->device->name, (void *)dev, dev->data->nb_rx_queues); + TAP_LOG(INFO, "%s: %p: RX configured queues number: %u", + dev->device->name, (void *)dev, dev->data->nb_rx_queues); return 0; } @@ -965,7 +962,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr) int ret; if (is_zero_ether_addr(mac_addr)) { - RTE_LOG(ERR, PMD, "%s: can't set an empty MAC address\n", + TAP_LOG(ERR, "%s: can't set an empty MAC address", dev->device->name); return -EINVAL; } @@ -993,15 +990,15 @@ tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr) /* Replace MAC redirection rule after a MAC change */ ret = tap_flow_implicit_destroy(pmd, TAP_REMOTE_LOCAL_MAC); if (ret < 0) { - RTE_LOG(ERR, PMD, - "%s: Couldn't delete MAC redirection rule\n", + TAP_LOG(ERR, + "%s: Couldn't delete MAC redirection rule", dev->device->name); return ret; } ret = tap_flow_implicit_create(pmd, TAP_REMOTE_LOCAL_MAC); if (ret < 0) { - RTE_LOG(ERR, PMD, - "%s: Couldn't add MAC redirection rule\n", + TAP_LOG(ERR, + "%s: Couldn't add MAC redirection rule", dev->device->name); return ret; } @@ -1034,29 +1031,27 @@ tap_setup_queue(struct rte_eth_dev *dev, } if (*fd != -1) { /* fd for this queue already exists */ - RTE_LOG(DEBUG, PMD, "%s: fd %d for %s queue qid %d exists\n", + TAP_LOG(DEBUG, "%s: fd %d for %s queue qid %d exists", pmd->name, *fd, dir, qid); } else if (*other_fd != -1) { /* Only other_fd exists. dup it */ *fd = dup(*other_fd); if (*fd < 0) { *fd = -1; - RTE_LOG(ERR, PMD, "%s: dup() failed.\n", - pmd->name); + TAP_LOG(ERR, "%s: dup() failed.", pmd->name); return -1; } - RTE_LOG(DEBUG, PMD, "%s: dup fd %d for %s queue qid %d (%d)\n", + TAP_LOG(DEBUG, "%s: dup fd %d for %s queue qid %d (%d)", pmd->name, *other_fd, dir, qid, *fd); } else { /* Both RX and TX fds do not exist (equal -1). Create fd */ *fd = tun_alloc(pmd); if (*fd < 0) { *fd = -1; /* restore original value */ - RTE_LOG(ERR, PMD, "%s: tun_alloc() failed.\n", - pmd->name); + TAP_LOG(ERR, "%s: tun_alloc() failed.", pmd->name); return -1; } - RTE_LOG(DEBUG, PMD, "%s: add %s queue for qid %d fd %d\n", + TAP_LOG(DEBUG, "%s: add %s queue for qid %d fd %d", pmd->name, dir, qid, *fd); } @@ -1086,8 +1081,8 @@ tap_rx_queue_setup(struct rte_eth_dev *dev, int i; if (rx_queue_id >= dev->data->nb_rx_queues || !mp) { - RTE_LOG(WARNING, PMD, - "nb_rx_queues %d too small or mempool NULL\n", + TAP_LOG(WARNING, + "nb_rx_queues %d too small or mempool NULL", dev->data->nb_rx_queues); return -1; } @@ -1095,10 +1090,10 @@ tap_rx_queue_setup(struct rte_eth_dev *dev, /* Verify application offloads are valid for our port and queue. */ if (!tap_rxq_are_offloads_valid(dev, rx_conf->offloads)) { rte_errno = ENOTSUP; - RTE_LOG(ERR, PMD, + TAP_LOG(ERR, "%p: Rx queue offloads 0x%" PRIx64 " don't match port offloads 0x%" PRIx64 - " or supported offloads 0x%" PRIx64 "\n", + " or supported offloads 0x%" PRIx64, (void *)dev, rx_conf->offloads, dev->data->dev_conf.rxmode.offloads, (tap_rx_offload_get_port_capa() | @@ -1112,8 +1107,8 @@ tap_rx_queue_setup(struct rte_eth_dev *dev, iovecs = rte_zmalloc_socket(dev->device->name, sizeof(*iovecs), 0, socket_id); if (!iovecs) { - RTE_LOG(WARNING, PMD, - "%s: Couldn't allocate %d RX descriptors\n", + TAP_LOG(WARNING, + "%s: Couldn't allocate %d RX descriptors", dev->device->name, nb_desc); return -ENOMEM; } @@ -1132,8 +1127,8 @@ tap_rx_queue_setup(struct rte_eth_dev *dev, for (i = 1; i <= nb_desc; i++) { *tmp = rte_pktmbuf_alloc(rxq->mp); if (!*tmp) { - RTE_LOG(WARNING, PMD, - "%s: couldn't allocate memory for queue %d\n", + TAP_LOG(WARNING, + "%s: couldn't allocate memory for queue %d", dev->device->name, rx_queue_id); ret = -ENOMEM; goto error; @@ -1145,7 +1140,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev, tmp = &(*tmp)->next; } - RTE_LOG(DEBUG, PMD, " RX TUNTAP device name %s, qid %d on fd %d\n", + TAP_LOG(DEBUG, " RX TUNTAP device name %s, qid %d on fd %d", internals->name, rx_queue_id, internals->rxq[rx_queue_id].fd); return 0; @@ -1186,7 +1181,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev, DEV_TX_OFFLOAD_TCP_CKSUM)); } else { rte_errno = ENOTSUP; - RTE_LOG(ERR, PMD, + TAP_LOG(ERR, "%p: Tx queue offloads 0x%" PRIx64 " don't match port offloads 0x%" PRIx64 " or supported offloads 0x%" PRIx64, @@ -1199,8 +1194,8 @@ tap_tx_queue_setup(struct rte_eth_dev *dev, ret = tap_setup_queue(dev, internals, tx_queue_id, 0); if (ret == -1) return -1; - RTE_LOG(DEBUG, PMD, - " TX TUNTAP device name %s, qid %d on fd %d csum %s\n", + TAP_LOG(DEBUG, + " TX TUNTAP device name %s, qid %d on fd %d csum %s", internals->name, tx_queue_id, internals->txq[tx_queue_id].fd, txq->csum ? "on" : "off"); @@ -1383,12 +1378,12 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, struct ifreq ifr; int i; - RTE_LOG(DEBUG, PMD, "%s device on numa %u\n", + TAP_LOG(DEBUG, "%s device on numa %u", tuntap_name, rte_socket_id()); dev = rte_eth_vdev_allocate(vdev, sizeof(*pmd)); if (!dev) { - RTE_LOG(ERR, PMD, "%s Unable to allocate device struct\n", + TAP_LOG(ERR, "%s Unable to allocate device struct", tuntap_name); goto error_exit_nodev; } @@ -1399,8 +1394,8 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0); if (pmd->ioctl_sock == -1) { - RTE_LOG(ERR, PMD, - "%s Unable to get a socket for management: %s\n", + TAP_LOG(ERR, + "%s Unable to get a socket for management: %s", tuntap_name, strerror(errno)); goto error_exit; } @@ -1469,22 +1464,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, */ pmd->nlsk_fd = tap_nl_init(0); if (pmd->nlsk_fd == -1) { - RTE_LOG(WARNING, PMD, "%s: failed to create netlink socket.\n", + TAP_LOG(WARNING, "%s: failed to create netlink socket.", pmd->name); goto disable_rte_flow; } pmd->if_index = if_nametoindex(pmd->name); if (!pmd->if_index) { - RTE_LOG(ERR, PMD, "%s: failed to get if_index.\n", pmd->name); + TAP_LOG(ERR, "%s: failed to get if_index.", pmd->name); goto disable_rte_flow; } if (qdisc_create_multiq(pmd->nlsk_fd, pmd->if_index) < 0) { - RTE_LOG(ERR, PMD, "%s: failed to create multiq qdisc.\n", + TAP_LOG(ERR, "%s: failed to create multiq qdisc.", pmd->name); goto disable_rte_flow; } if (qdisc_create_ingress(pmd->nlsk_fd, pmd->if_index) < 0) { - RTE_LOG(ERR, PMD, "%s: failed to create ingress qdisc.\n", + TAP_LOG(ERR, "%s: failed to create ingress qdisc.", pmd->name); goto disable_rte_flow; } @@ -1493,7 +1488,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, if (strlen(remote_iface)) { pmd->remote_if_index = if_nametoindex(remote_iface); if (!pmd->remote_if_index) { - RTE_LOG(ERR, PMD, "%s: failed to get %s if_index.\n", + TAP_LOG(ERR, "%s: failed to get %s if_index.", pmd->name, remote_iface); goto error_remote; } @@ -1505,7 +1500,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, /* Replicate remote MAC address */ if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) { - RTE_LOG(ERR, PMD, "%s: failed to get %s MAC address.\n", + TAP_LOG(ERR, "%s: failed to get %s MAC address.", pmd->name, pmd->remote_iface); goto error_remote; } @@ -1513,7 +1508,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, ETHER_ADDR_LEN); /* The desired MAC is already in ifreq after SIOCGIFHWADDR. */ if (tap_ioctl(pmd, SIOCSIFHWADDR, &ifr, 0, LOCAL_ONLY) < 0) { - RTE_LOG(ERR, PMD, "%s: failed to get %s MAC address.\n", + TAP_LOG(ERR, "%s: failed to get %s MAC address.", pmd->name, remote_iface); goto error_remote; } @@ -1526,7 +1521,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, qdisc_flush(pmd->nlsk_fd, pmd->remote_if_index); if (qdisc_create_ingress(pmd->nlsk_fd, pmd->remote_if_index) < 0) { - RTE_LOG(ERR, PMD, "%s: failed to create ingress qdisc.\n", + TAP_LOG(ERR, "%s: failed to create ingress qdisc.", pmd->remote_iface); goto error_remote; } @@ -1535,8 +1530,8 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, tap_flow_implicit_create(pmd, TAP_REMOTE_LOCAL_MAC) < 0 || tap_flow_implicit_create(pmd, TAP_REMOTE_BROADCAST) < 0 || tap_flow_implicit_create(pmd, TAP_REMOTE_BROADCASTV6) < 0) { - RTE_LOG(ERR, PMD, - "%s: failed to create implicit rules.\n", + TAP_LOG(ERR, + "%s: failed to create implicit rules.", pmd->name); goto error_remote; } @@ -1545,16 +1540,16 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, return 0; disable_rte_flow: - RTE_LOG(ERR, PMD, " Disabling rte flow support: %s(%d)\n", + TAP_LOG(ERR, " Disabling rte flow support: %s(%d)", strerror(errno), errno); if (strlen(remote_iface)) { - RTE_LOG(ERR, PMD, "Remote feature requires flow support.\n"); + TAP_LOG(ERR, "Remote feature requires flow support."); goto error_exit; } return 0; error_remote: - RTE_LOG(ERR, PMD, " Can't set up remote feature: %s(%d)\n", + TAP_LOG(ERR, " Can't set up remote feature: %s(%d)", strerror(errno), errno); tap_flow_implicit_flush(pmd, NULL); @@ -1564,7 +1559,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, rte_eth_dev_release_port(dev); error_exit_nodev: - RTE_LOG(ERR, PMD, "%s Unable to initialize %s\n", + TAP_LOG(ERR, "%s Unable to initialize %s", tuntap_name, rte_vdev_device_name(vdev)); return -EINVAL; @@ -1644,11 +1639,11 @@ set_mac_type(const char *key __rte_unused, if (parse_user_mac(user_mac, value) != 6) goto error; success: - RTE_LOG(DEBUG, PMD, "TAP user MAC param (%s)\n", value); + TAP_LOG(DEBUG, "TAP user MAC param (%s)", value); return 0; error: - RTE_LOG(ERR, PMD, "TAP user MAC (%s) is not in format (%s|%s)\n", + TAP_LOG(ERR, "TAP user MAC (%s) is not in format (%s|%s)", value, ETH_TAP_MAC_FIXED, ETH_TAP_USR_MAC_FMT); return -1; } @@ -1676,7 +1671,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN); if (params && (params[0] != '\0')) { - RTE_LOG(DEBUG, PMD, "parameters (%s)\n", params); + TAP_LOG(DEBUG, "parameters (%s)", params); kvlist = rte_kvargs_parse(params, valid_arguments); if (kvlist) { @@ -1693,14 +1688,14 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) } pmd_link.link_speed = ETH_SPEED_NUM_10G; - RTE_LOG(NOTICE, PMD, "Initializing pmd_tun for %s as %s\n", + TAP_LOG(NOTICE, "Initializing pmd_tun for %s as %s", name, tun_name); ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0); leave: if (ret == -1) { - RTE_LOG(ERR, PMD, "Failed to create pmd for %s as %s\n", + TAP_LOG(ERR, "Failed to create pmd for %s as %s", name, tun_name); tun_unit--; /* Restore the unit number */ } @@ -1733,7 +1728,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) strlen(params) == 0) { eth_dev = rte_eth_dev_attach_secondary(name); if (!eth_dev) { - RTE_LOG(ERR, PMD, "Failed to probe %s\n", name); + TAP_LOG(ERR, "Failed to probe %s", name); return -1; } /* TODO: request info from primary to set up Rx and Tx */ @@ -1747,7 +1742,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN); if (params && (params[0] != '\0')) { - RTE_LOG(DEBUG, PMD, "parameters (%s)\n", params); + TAP_LOG(DEBUG, "parameters (%s)", params); kvlist = rte_kvargs_parse(params, valid_arguments); if (kvlist) { @@ -1781,14 +1776,14 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) } pmd_link.link_speed = speed; - RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n", + TAP_LOG(NOTICE, "Initializing pmd_tap for %s as %s", name, tap_name); ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac); leave: if (ret == -1) { - RTE_LOG(ERR, PMD, "Failed to create pmd for %s as %s\n", + TAP_LOG(ERR, "Failed to create pmd for %s as %s", name, tap_name); tap_unit--; /* Restore the unit number */ } @@ -1806,7 +1801,7 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev) struct pmd_internals *internals; int i; - RTE_LOG(DEBUG, PMD, "Closing TUN/TAP Ethernet device on numa %u\n", + TAP_LOG(DEBUG, "Closing TUN/TAP Ethernet device on numa %u", rte_socket_id()); /* find the ethdev entry */ @@ -1848,6 +1843,7 @@ static struct rte_vdev_driver pmd_tap_drv = { .probe = rte_pmd_tap_probe, .remove = rte_pmd_tap_remove, }; + RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv); RTE_PMD_REGISTER_VDEV(net_tun, pmd_tun_drv); RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap); @@ -1857,3 +1853,13 @@ RTE_PMD_REGISTER_PARAM_STRING(net_tap, ETH_TAP_IFACE_ARG "= " ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_ARG_FMT " " ETH_TAP_REMOTE_ARG "="); +int tap_logtype; + +RTE_INIT(tap_init_log); +static void +tap_init_log(void) +{ + tap_logtype = rte_log_register("pmd.net.tap"); + if (tap_logtype >= 0) + rte_log_set_level(tap_logtype, RTE_LOG_NOTICE); +} diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index 25b65bf308c7..67c9d4beebb6 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -15,6 +15,7 @@ #include #include +#include "tap_log.h" #ifdef IFF_MULTI_QUEUE #define RTE_PMD_TAP_MAX_QUEUES TAP_MAX_QUEUES diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c index 3b7a960b0946..1b23c09174c8 100644 --- a/drivers/net/tap/tap_flow.c +++ b/drivers/net/tap/tap_flow.c @@ -1376,8 +1376,8 @@ tap_flow_create(struct rte_eth_dev *dev, } err = tap_nl_recv_ack(pmd->nlsk_fd); if (err < 0) { - RTE_LOG(ERR, PMD, - "Kernel refused TC filter rule creation (%d): %s\n", + TAP_LOG(ERR, + "Kernel refused TC filter rule creation (%d): %s", errno, strerror(errno)); rte_flow_error_set(error, EEXIST, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, @@ -1421,8 +1421,8 @@ tap_flow_create(struct rte_eth_dev *dev, } err = tap_nl_recv_ack(pmd->nlsk_fd); if (err < 0) { - RTE_LOG(ERR, PMD, - "Kernel refused TC filter rule creation (%d): %s\n", + TAP_LOG(ERR, + "Kernel refused TC filter rule creation (%d): %s", errno, strerror(errno)); rte_flow_error_set( error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE, @@ -1476,8 +1476,8 @@ tap_flow_destroy_pmd(struct pmd_internals *pmd, if (ret < 0 && errno == ENOENT) ret = 0; if (ret < 0) { - RTE_LOG(ERR, PMD, - "Kernel refused TC filter rule deletion (%d): %s\n", + TAP_LOG(ERR, + "Kernel refused TC filter rule deletion (%d): %s", errno, strerror(errno)); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, @@ -1500,8 +1500,8 @@ tap_flow_destroy_pmd(struct pmd_internals *pmd, if (ret < 0 && errno == ENOENT) ret = 0; if (ret < 0) { - RTE_LOG(ERR, PMD, - "Kernel refused TC filter rule deletion (%d): %s\n", + TAP_LOG(ERR, + "Kernel refused TC filter rule deletion (%d): %s", errno, strerror(errno)); rte_flow_error_set( error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE, @@ -1665,7 +1665,7 @@ int tap_flow_implicit_create(struct pmd_internals *pmd, remote_flow = rte_malloc(__func__, sizeof(struct rte_flow), 0); if (!remote_flow) { - RTE_LOG(ERR, PMD, "Cannot allocate memory for rte_flow\n"); + TAP_LOG(ERR, "Cannot allocate memory for rte_flow"); goto fail; } msg = &remote_flow->msg; @@ -1706,12 +1706,12 @@ int tap_flow_implicit_create(struct pmd_internals *pmd, tap_flow_set_handle(remote_flow); if (priv_flow_process(pmd, attr, items, actions, NULL, remote_flow, implicit_rte_flows[idx].mirred)) { - RTE_LOG(ERR, PMD, "rte flow rule validation failed\n"); + TAP_LOG(ERR, "rte flow rule validation failed"); goto fail; } err = tap_nl_send(pmd->nlsk_fd, &msg->nh); if (err < 0) { - RTE_LOG(ERR, PMD, "Failure sending nl request\n"); + TAP_LOG(ERR, "Failure sending nl request"); goto fail; } err = tap_nl_recv_ack(pmd->nlsk_fd); @@ -1719,8 +1719,8 @@ int tap_flow_implicit_create(struct pmd_internals *pmd, /* Silently ignore re-entering remote promiscuous rule */ if (errno == EEXIST && idx == TAP_REMOTE_PROMISC) goto success; - RTE_LOG(ERR, PMD, - "Kernel refused TC filter rule creation (%d): %s\n", + TAP_LOG(ERR, + "Kernel refused TC filter rule creation (%d): %s", errno, strerror(errno)); goto fail; } @@ -1836,8 +1836,8 @@ static int rss_enable(struct pmd_internals *pmd, sizeof(struct rss_key), MAX_RSS_KEYS); if (pmd->map_fd < 0) { - RTE_LOG(ERR, PMD, - "Failed to create BPF map (%d): %s\n", + TAP_LOG(ERR, + "Failed to create BPF map (%d): %s", errno, strerror(errno)); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, @@ -1854,7 +1854,7 @@ static int rss_enable(struct pmd_internals *pmd, for (i = 0; i < pmd->dev->data->nb_rx_queues; i++) { pmd->bpf_fd[i] = tap_flow_bpf_cls_q(i); if (pmd->bpf_fd[i] < 0) { - RTE_LOG(ERR, PMD, + TAP_LOG(ERR, "Failed to load BPF section %s for queue %d", SEC_NAME_CLS_Q, i); rte_flow_error_set( @@ -1868,7 +1868,7 @@ static int rss_enable(struct pmd_internals *pmd, rss_flow = rte_malloc(__func__, sizeof(struct rte_flow), 0); if (!rss_flow) { - RTE_LOG(ERR, PMD, + TAP_LOG(ERR, "Cannot allocate memory for rte_flow"); return -1; } @@ -1911,8 +1911,8 @@ static int rss_enable(struct pmd_internals *pmd, return -1; err = tap_nl_recv_ack(pmd->nlsk_fd); if (err < 0) { - RTE_LOG(ERR, PMD, - "Kernel refused TC filter rule creation (%d): %s\n", + TAP_LOG(ERR, + "Kernel refused TC filter rule creation (%d): %s", errno, strerror(errno)); return err; } @@ -2066,8 +2066,8 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, &flow->key_idx, &rss_entry); if (err) { - RTE_LOG(ERR, PMD, - "Failed to update BPF map entry #%u (%d): %s\n", + TAP_LOG(ERR, + "Failed to update BPF map entry #%u (%d): %s", flow->key_idx, errno, strerror(errno)); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, @@ -2085,8 +2085,8 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, flow->bpf_fd[SEC_L3_L4] = tap_flow_bpf_calc_l3_l4_hash(flow->key_idx, pmd->map_fd); if (flow->bpf_fd[SEC_L3_L4] < 0) { - RTE_LOG(ERR, PMD, - "Failed to load BPF section %s (%d): %s\n", + TAP_LOG(ERR, + "Failed to load BPF section %s (%d): %s", sec_name[SEC_L3_L4], errno, strerror(errno)); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, @@ -2147,9 +2147,8 @@ tap_dev_filter_ctrl(struct rte_eth_dev *dev, *(const void **)arg = &tap_flow_ops; return 0; default: - RTE_LOG(ERR, PMD, "%p: filter type (%d) not supported\n", - (void *)dev, filter_type); + TAP_LOG(ERR, "%p: filter type (%d) not supported", + dev, filter_type); } return -EINVAL; } - diff --git a/drivers/net/tap/tap_intr.c b/drivers/net/tap/tap_intr.c index 8283ecb3db41..fc590181fca7 100644 --- a/drivers/net/tap/tap_intr.c +++ b/drivers/net/tap/tap_intr.c @@ -62,7 +62,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev) intr_handle->intr_vec = malloc(sizeof(intr_handle->intr_vec[rxqs_n])); if (intr_handle->intr_vec == NULL) { rte_errno = ENOMEM; - RTE_LOG(ERR, PMD, + TAP_LOG(ERR, "failed to allocate memory for interrupt vector," " Rx interrupts will not be supported"); return -rte_errno; diff --git a/drivers/net/tap/tap_log.h b/drivers/net/tap/tap_log.h new file mode 100644 index 000000000000..fa06843a4c41 --- /dev/null +++ b/drivers/net/tap/tap_log.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2017 6WIND S.A. + * Copyright 2017 Mellanox Technologies, Ltd + */ + +extern int tap_logtype; + +#define TAP_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, tap_logtype, "%s(): " fmt "\n", \ + __func__, ## args) diff --git a/drivers/net/tap/tap_netlink.c b/drivers/net/tap/tap_netlink.c index 8273ac031b4e..6cb510092218 100644 --- a/drivers/net/tap/tap_netlink.c +++ b/drivers/net/tap/tap_netlink.c @@ -13,6 +13,7 @@ #include #include #include +#include "tap_log.h" /* Must be quite large to support dumping a huge list of QDISC or filters. */ #define BUF_SIZE (32 * 1024) /* Size of the buffer to receive kernel messages */ @@ -45,19 +46,19 @@ tap_nl_init(uint32_t nl_groups) fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); if (fd < 0) { - RTE_LOG(ERR, PMD, "Unable to create a netlink socket\n"); + TAP_LOG(ERR, "Unable to create a netlink socket"); return -1; } if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sndbuf_size, sizeof(int))) { - RTE_LOG(ERR, PMD, "Unable to set socket buffer send size\n"); + TAP_LOG(ERR, "Unable to set socket buffer send size"); return -1; } if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf_size, sizeof(int))) { - RTE_LOG(ERR, PMD, "Unable to set socket buffer receive size\n"); + TAP_LOG(ERR, "Unable to set socket buffer receive size"); return -1; } if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) { - RTE_LOG(ERR, PMD, "Unable to bind to the netlink socket\n"); + TAP_LOG(ERR, "Unable to bind to the netlink socket"); return -1; } return fd; @@ -76,7 +77,7 @@ int tap_nl_final(int nlsk_fd) { if (close(nlsk_fd)) { - RTE_LOG(ERR, PMD, "Failed to close netlink socket: %s (%d)\n", + TAP_LOG(ERR, "Failed to close netlink socket: %s (%d)", strerror(errno), errno); return -1; } @@ -117,7 +118,7 @@ tap_nl_send(int nlsk_fd, struct nlmsghdr *nh) nh->nlmsg_seq = (uint32_t)rte_rand(); send_bytes = sendmsg(nlsk_fd, &msg, 0); if (send_bytes < 0) { - RTE_LOG(ERR, PMD, "Failed to send netlink message: %s (%d)\n", + TAP_LOG(ERR, "Failed to send netlink message: %s (%d)", strerror(errno), errno); return -1; } @@ -300,9 +301,8 @@ tap_nlattr_nested_start(struct nlmsg *msg, uint16_t type) tail = rte_zmalloc(NULL, sizeof(struct nested_tail), 0); if (!tail) { - RTE_LOG(ERR, PMD, - "Couldn't allocate memory for nested netlink" - " attribute\n"); + TAP_LOG(ERR, + "Couldn't allocate memory for nested netlink attribute"); return -1; } diff --git a/drivers/net/tap/tap_tcmsgs.c b/drivers/net/tap/tap_tcmsgs.c index 8da6ccc86df0..3c9d0366725e 100644 --- a/drivers/net/tap/tap_tcmsgs.c +++ b/drivers/net/tap/tap_tcmsgs.c @@ -10,6 +10,7 @@ #include #include +#include "tap_log.h" struct qdisc { uint32_t handle; @@ -81,8 +82,8 @@ qdisc_del(int nlsk_fd, uint16_t ifindex, struct qdisc *qinfo) if (!nlsk_fd) { fd = tap_nl_init(0); if (fd < 0) { - RTE_LOG(ERR, PMD, - "Could not delete QDISC: null netlink socket\n"); + TAP_LOG(ERR, + "Could not delete QDISC: null netlink socket"); return -1; } } else { @@ -261,7 +262,7 @@ qdisc_create_multiq(int nlsk_fd, uint16_t ifindex) err = qdisc_add_multiq(nlsk_fd, ifindex); if (err < 0 && errno != -EEXIST) { - RTE_LOG(ERR, PMD, "Could not add multiq qdisc (%d): %s\n", + TAP_LOG(ERR, "Could not add multiq qdisc (%d): %s", errno, strerror(errno)); return -1; } @@ -287,7 +288,7 @@ qdisc_create_ingress(int nlsk_fd, uint16_t ifindex) err = qdisc_add_ingress(nlsk_fd, ifindex); if (err < 0 && errno != -EEXIST) { - RTE_LOG(ERR, PMD, "Could not add ingress qdisc (%d): %s\n", + TAP_LOG(ERR, "Could not add ingress qdisc (%d): %s", errno, strerror(errno)); return -1; } -- 2.17.0