net/virtio: avoid global variable name conflicts
RFC 1/1 net/virtio: avoid global variable name conflicts
If PMD is statically linked, all global variables are visible and can clash with application or other drivers and therefore should have a consistent prefix.
--- drivers/net/virtio/virtio_pci.c | 8 ++++---- drivers/net/virtio/virtio_pci.h | 4 ++-- drivers/net/virtio/virtio_pci_ethdev.c | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 14 +++++++------- drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 10 +++++----- drivers/net/virtio/virtio_user/vhost_kernel_tap.h | 10 +++++----- 6 files changed, 25 insertions(+), 25 deletions(-)
drivers/net/virtio/virtio_pci.c +4 -4
@@ -269,7 +269,7 @@ legacy_dev_close(struct virtio_hw *hw)return 0 ; } -const struct virtio_ops legacy_ops = { +const struct virtio_ops virtio_legacy_ops = { .read_dev_cfg = legacy_read_dev_config, .write_dev_cfg = legacy_write_dev_config, .get_status = legacy_get_status,
@@ -524,7 +524,7 @@ modern_dev_close(struct virtio_hw *hw)return 0 ; } -const struct virtio_ops modern_ops = { +const struct virtio_ops virtio_modern_ops = { .read_dev_cfg = modern_read_dev_config, .write_dev_cfg = modern_write_dev_config, .get_status = modern_get_status,
@@ -669,7 +669,7 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)*/ if (virtio_read_caps (pci_dev, hw) ==0 ) {PMD_INIT_LOG (INFO ,"modern virtio pci detected." ); -VIRTIO_OPS (hw) = &modern_ops; +VIRTIO_OPS (hw) = &virtio_modern_ops; dev->modern = true; goto msix_detect; }
@@ -688,7 +688,7 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)return -1 ; } -VIRTIO_OPS (hw) = &legacy_ops; +VIRTIO_OPS (hw) = &virtio_legacy_ops; dev->modern = false; msix_detect:
drivers/net/virtio/virtio_pci.h +2 -2
@@ -139,7 +139,7 @@ int vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev);void vtpci_legacy_ioport_unmap (struct virtio_hw *hw);int vtpci_legacy_ioport_map (struct virtio_hw *hw); -extern const struct virtio_ops legacy_ops; -extern const struct virtio_ops modern_ops; +extern const struct virtio_ops virtio_legacy_ops; +extern const struct virtio_ops virtio_modern_ops;#endif /* _VIRTIO_PCI_H_ */
drivers/net/virtio/virtio_pci_ethdev.c +2 -2
@@ -87,9 +87,9 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev) }else {VTPCI_DEV (hw) = pci_dev;if (dev->modern) -VIRTIO_OPS (hw) = &modern_ops; +VIRTIO_OPS (hw) = &virtio_modern_ops;else -VIRTIO_OPS (hw) = &legacy_ops; +VIRTIO_OPS (hw) = &virtio_legacy_ops; ret =virtio_remap_pci (RTE_ETH_DEV_TO_PCI (eth_dev), dev);if (ret <0 ) {
drivers/net/virtio/virtio_user/vhost_kernel.c +7 -7
@@ -131,7 +131,7 @@ vhost_kernel_get_features(struct virtio_user_dev *dev, uint64_t *features)return -1 ; } - ret =tap_get_flags (data->tapfds[0 ], &tap_flags); + ret =vhost_tap_get_flags (data->tapfds[0 ], &tap_flags);if (ret <0 ) {PMD_DRV_LOG (ERR ,"Failed to get TAP features" );return -1 ;
@@ -389,7 +389,7 @@ vhost_kernel_setup(struct virtio_user_dev *dev)uint32_t q, i;int vhostfd; -if (tap_support_features (&tap_features) <0 ) +if (vhost_tap_support_features (&tap_features) <0 )return -1 ;if ((tap_features &IFF_VNET_HDR ) ==0 ) {
@@ -435,14 +435,14 @@ vhost_kernel_setup(struct virtio_user_dev *dev) } ifname = dev->ifname !=NULL ? dev->ifname :"tap%d" ; - data->tapfds[0 ] =tap_open (ifname, r_flags, (tap_features &IFF_MULTI_QUEUE ) !=0 ); + data->tapfds[0 ] =vhost_tap_open (ifname, r_flags, (tap_features &IFF_MULTI_QUEUE ) !=0 );if (data->tapfds[0 ] <0 ) goto err_tapfds; -if (dev->ifname ==NULL &&tap_get_name (data->tapfds[0 ], &dev->ifname) <0 ) { +if (dev->ifname ==NULL &&vhost_tap_get_name (data->tapfds[0 ], &dev->ifname) <0 ) {PMD_DRV_LOG (ERR ,"fail to get tap name (%d)" , data->tapfds[0 ]); goto err_tapfds; } -if (tap_get_flags (data->tapfds[0 ], &tap_flags) <0 ) { +if (vhost_tap_get_flags (data->tapfds[0 ], &tap_flags) <0 ) {PMD_DRV_LOG (ERR ,"fail to get tap flags for tap %s" , dev->ifname); goto err_tapfds; }
@@ -452,7 +452,7 @@ vhost_kernel_setup(struct virtio_user_dev *dev) }for (i =1 ; i < dev->max_queue_pairs; i++) { - data->tapfds[i] =tap_open (dev->ifname, r_flags, true); + data->tapfds[i] =vhost_tap_open (dev->ifname, r_flags, true);if (data->tapfds[i] <0 ) goto err_tapfds; }
@@ -558,7 +558,7 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,/* Set mac on tap only once when starting */ if (!dev->started && pair_idx ==0 && -tap_set_mac (data->tapfds[pair_idx], dev->mac_addr) <0 ) +vhost_tap_set_mac (data->tapfds[pair_idx], dev->mac_addr) <0 )return -1 ;if (vhost_kernel_tap_setup (tapfd, hdr_size, dev->features) <0 ) {
drivers/net/virtio/virtio_user/vhost_kernel_tap.c +5 -5
@@ -20,7 +20,7 @@int -tap_support_features (unsigned int *tap_features) +vhost_tap_support_features (unsigned int *tap_features) {int tapfd;
@@ -42,7 +42,7 @@ tap_support_features(unsigned int *tap_features) }int -tap_open (const char *ifname,unsigned int r_flags,bool multi_queue) +vhost_tap_open (const char *ifname,unsigned int r_flags,bool multi_queue) {struct ifreq ifr;int tapfd;
@@ -81,7 +81,7 @@ tap_open(const char *ifname, unsigned int r_flags, bool multi_queue) }int -tap_get_name (int tapfd,char **name) +vhost_tap_get_name (int tapfd,char **name) {struct ifreq ifr;int ret;
@@ -98,7 +98,7 @@ tap_get_name(int tapfd, char **name) }int -tap_get_flags (int tapfd,unsigned int *tap_flags) +vhost_tap_get_flags (int tapfd,unsigned int *tap_flags) {struct ifreq ifr;
@@ -112,7 +112,7 @@ tap_get_flags(int tapfd, unsigned int *tap_flags) }int -tap_set_mac (int tapfd,uint8_t *mac) +vhost_tap_set_mac (int tapfd,uint8_t *mac) {struct ifreq ifr;
drivers/net/virtio/virtio_user/vhost_kernel_tap.h +5 -5
@@ -36,10 +36,10 @@int vhost_kernel_tap_setup (int tapfd,int hdr_size,uint64_t features); -int tap_support_features (unsigned int *tap_features); -int tap_open (const char *ifname,unsigned int r_flags,bool multi_queue); -int tap_get_name (int tapfd,char **ifname); -int tap_get_flags (int tapfd,unsigned int *tap_flags); -int tap_set_mac (int tapfd,uint8_t *mac); +int vhost_tap_support_features (unsigned int *tap_features); +int vhost_tap_open (const char *ifname,unsigned int r_flags,bool multi_queue); +int vhost_tap_get_name (int tapfd,char **ifname); +int vhost_tap_get_flags (int tapfd,unsigned int *tap_flags); +int vhost_tap_set_mac (int tapfd,uint8_t *mac);#endif
Signature · 1 line
2.51.0
Quoted 6 lines · On Sun, 21 Dec 2025 16:44:46 -0800 Stephen Hemminger…
If PMD is statically linked, all global variables are visible and can clash with application or other drivers and therefore should have a consistent prefix.
Signed-off-by Stephen Hemminger <[email protected]>---
Recheck-request: iol-intel-Functional
Quoted 6 lines · Stephen Hemminger
If PMD is statically linked, all global variables are visible and can clash with application or other drivers and therefore should have a consistent prefix.
Signed-off-by Stephen Hemminger <[email protected]>
Quoted 9 lines
--- drivers/net/virtio/virtio_pci.c | 8 ++++---- drivers/net/virtio/virtio_pci.h | 4 ++-- drivers/net/virtio/virtio_pci_ethdev.c | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 14 +++++++------- drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 10 +++++----- drivers/net/virtio/virtio_user/vhost_kernel_tap.h | 10 +++++----- 6 files changed, 25 insertions(+), 25 deletions(-)
Thanks,
Maxime
Maxime Coquelin
AppliedQuoted 6 lines · Stephen Hemminger
If PMD is statically linked, all global variables are visible and can clash with application or other drivers and therefore should have a consistent prefix.
Signed-off-by Stephen Hemminger <[email protected]>
Quoted 9 lines
--- drivers/net/virtio/virtio_pci.c | 8 ++++---- drivers/net/virtio/virtio_pci.h | 4 ++-- drivers/net/virtio/virtio_pci_ethdev.c | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 14 +++++++------- drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 10 +++++----- drivers/net/virtio/virtio_user/vhost_kernel_tap.h | 10 +++++----- 6 files changed, 25 insertions(+), 25 deletions(-)
Applied to next-virtio/for-next-net.
Thanks,
Maxime