virtio: refactor virtio-pci logging
Type: refactor Change-Id: I34306c1206b2bf5f521be6c6b78074ccf9259a08 Signed-off-by: Damjan Marion <damarion@cisco.com>
This commit is contained in:

committed by
Florin Coras

parent
aa27dcb84c
commit
f41244f423
@@ -1032,16 +1032,17 @@ list(APPEND VNET_API_FILES pg/pg.api)
|
||||
##############################################################################
|
||||
|
||||
list(APPEND VNET_SOURCES
|
||||
devices/virtio/cli.c
|
||||
devices/virtio/device.c
|
||||
devices/virtio/format.c
|
||||
devices/virtio/node.c
|
||||
devices/virtio/pci.c
|
||||
devices/virtio/vhost_user.c
|
||||
devices/virtio/vhost_user_input.c
|
||||
devices/virtio/vhost_user_output.c
|
||||
devices/virtio/vhost_user_api.c
|
||||
devices/virtio/virtio.c
|
||||
devices/virtio/virtio_api.c
|
||||
devices/virtio/cli.c
|
||||
devices/virtio/pci.c
|
||||
)
|
||||
|
||||
list(APPEND VNET_HEADERS
|
||||
|
@@ -186,8 +186,6 @@ VLIB_CLI_COMMAND (show_virtio_pci_command, static) = {
|
||||
clib_error_t *
|
||||
virtio_pci_cli_init (vlib_main_t * vm)
|
||||
{
|
||||
virtio_main_t *vim = &virtio_main;
|
||||
vim->log_default = vlib_log_register_class ("virtio-pci", 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -46,27 +46,6 @@ static char *virtio_tx_func_error_strings[] = {
|
||||
#undef _
|
||||
};
|
||||
|
||||
#ifndef CLIB_MARCH_VARIANT
|
||||
u8 *
|
||||
format_virtio_device_name (u8 * s, va_list * args)
|
||||
{
|
||||
u32 dev_instance = va_arg (*args, u32);
|
||||
virtio_main_t *mm = &virtio_main;
|
||||
virtio_if_t *vif = pool_elt_at_index (mm->interfaces, dev_instance);
|
||||
|
||||
if (vif->type == VIRTIO_IF_TYPE_TAP)
|
||||
s = format (s, "tap%u", vif->id);
|
||||
else if (vif->type == VIRTIO_IF_TYPE_PCI)
|
||||
s = format (s, "virtio-%x/%x/%x/%x", vif->pci_addr.domain,
|
||||
vif->pci_addr.bus, vif->pci_addr.slot,
|
||||
vif->pci_addr.function);
|
||||
else
|
||||
s = format (s, "virtio-%lu", vif->dev_instance);
|
||||
|
||||
return s;
|
||||
}
|
||||
#endif /* CLIB_MARCH_VARIANT */
|
||||
|
||||
static u8 *
|
||||
format_virtio_device (u8 * s, va_list * args)
|
||||
{
|
||||
|
66
src/vnet/devices/virtio/format.c
Normal file
66
src/vnet/devices/virtio/format.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2018 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*------------------------------------------------------------------
|
||||
*/
|
||||
#include <vlib/vlib.h>
|
||||
#include <vlib/unix/unix.h>
|
||||
#include <vlib/pci/pci.h>
|
||||
#include <vnet/ethernet/ethernet.h>
|
||||
#include <vnet/ip/ip4_packet.h>
|
||||
#include <vnet/ip/ip6_packet.h>
|
||||
#include <vnet/devices/virtio/virtio.h>
|
||||
#include <vnet/devices/virtio/pci.h>
|
||||
|
||||
u8 *
|
||||
format_virtio_device_name (u8 * s, va_list * args)
|
||||
{
|
||||
u32 dev_instance = va_arg (*args, u32);
|
||||
virtio_main_t *mm = &virtio_main;
|
||||
virtio_if_t *vif = pool_elt_at_index (mm->interfaces, dev_instance);
|
||||
|
||||
if (vif->type == VIRTIO_IF_TYPE_TAP)
|
||||
s = format (s, "tap%u", vif->id);
|
||||
else if (vif->type == VIRTIO_IF_TYPE_PCI)
|
||||
s = format (s, "virtio-%x/%x/%x/%x", vif->pci_addr.domain,
|
||||
vif->pci_addr.bus, vif->pci_addr.slot,
|
||||
vif->pci_addr.function);
|
||||
else
|
||||
s = format (s, "virtio-%lu", vif->dev_instance);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
u8 *
|
||||
format_virtio_log_name (u8 * s, va_list * args)
|
||||
{
|
||||
virtio_if_t *vif = va_arg (*args, virtio_if_t *);
|
||||
|
||||
if (vif->type == VIRTIO_IF_TYPE_TAP)
|
||||
s = format (s, "tap%u", vif->id);
|
||||
else if (vif->type == VIRTIO_IF_TYPE_PCI)
|
||||
s = format (s, "%U", format_vlib_pci_addr, &vif->pci_addr);
|
||||
else
|
||||
s = format (s, "virtio-%lu", vif->dev_instance);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* fd.io coding-style-patch-verification: ON
|
||||
*
|
||||
* Local Variables:
|
||||
* eval: (c-set-style "gnu")
|
||||
* End:
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
@@ -132,27 +132,6 @@ typedef enum
|
||||
|
||||
#define VIRTIO_PCI_VRING_ALIGN 4096
|
||||
|
||||
#define virtio_log_debug(vim, vif, f, ...) \
|
||||
{ \
|
||||
vlib_log(VLIB_LOG_LEVEL_DEBUG, vim->log_default, "%U: " f, \
|
||||
format_vlib_pci_addr, &vif->pci_addr, \
|
||||
##__VA_ARGS__); \
|
||||
};
|
||||
|
||||
#define virtio_log_warning(vim, vif, f, ...) \
|
||||
{ \
|
||||
vlib_log(VLIB_LOG_LEVEL_WARNING, vim->log_default, "%U: " f, \
|
||||
format_vlib_pci_addr, &vif->pci_addr, \
|
||||
##__VA_ARGS__); \
|
||||
};
|
||||
|
||||
#define virtio_log_error(vim, vif, f, ...) \
|
||||
{ \
|
||||
vlib_log(VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: " f, \
|
||||
format_vlib_pci_addr, &vif->pci_addr, \
|
||||
##__VA_ARGS__); \
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VIRTIO_MSIX_NONE = 0,
|
||||
|
@@ -474,6 +474,20 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
|
||||
|
||||
}
|
||||
|
||||
static clib_error_t *
|
||||
virtio_init (vlib_main_t * vm)
|
||||
{
|
||||
virtio_main_t *vim = &virtio_main;
|
||||
clib_error_t *error = 0;
|
||||
|
||||
vim->log_default = vlib_log_register_class ("virtio", 0);
|
||||
vlib_log_debug (vim->log_default, "initialized");
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
VLIB_INIT_FUNCTION (virtio_init);
|
||||
|
||||
/*
|
||||
* fd.io coding-style-patch-verification: ON
|
||||
*
|
||||
|
@@ -82,7 +82,7 @@ typedef enum
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VIRTIO_IF_TYPE_TAP,
|
||||
VIRTIO_IF_TYPE_TAP = 1,
|
||||
VIRTIO_IF_TYPE_PCI,
|
||||
VIRTIO_IF_N_TYPES,
|
||||
} virtio_if_type_t;
|
||||
@@ -212,6 +212,7 @@ extern void virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr,
|
||||
extern void virtio_pci_legacy_notify_queue (vlib_main_t * vm,
|
||||
virtio_if_t * vif, u16 queue_id);
|
||||
format_function_t format_virtio_device_name;
|
||||
format_function_t format_virtio_log_name;
|
||||
|
||||
static_always_inline void
|
||||
virtio_kick (vlib_main_t * vm, virtio_vring_t * vring, virtio_if_t * vif)
|
||||
@@ -228,6 +229,28 @@ virtio_kick (vlib_main_t * vm, virtio_vring_t * vring, virtio_if_t * vif)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define virtio_log_debug(vif, f, ...) \
|
||||
{ \
|
||||
vlib_log(VLIB_LOG_LEVEL_DEBUG, virtio_main.log_default, \
|
||||
"%U: " f, format_virtio_log_name, vif, \
|
||||
##__VA_ARGS__); \
|
||||
};
|
||||
|
||||
#define virtio_log_warning(vif, f, ...) \
|
||||
{ \
|
||||
vlib_log(VLIB_LOG_LEVEL_WARNING, virtio_main.log_default, \
|
||||
"%U: " f, format_virtio_log_name, vif, \
|
||||
##__VA_ARGS__); \
|
||||
};
|
||||
|
||||
#define virtio_log_error(vif, f, ...) \
|
||||
{ \
|
||||
vlib_log(VLIB_LOG_LEVEL_ERR, virtio_main.log_default, \
|
||||
"%U: " f, format_virtio_log_name, vif, \
|
||||
##__VA_ARGS__); \
|
||||
};
|
||||
|
||||
#endif /* _VNET_DEVICES_VIRTIO_VIRTIO_H_ */
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user