diff options
author | Juraj Sloboda <jsloboda@cisco.com> | 2018-10-03 16:00:21 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2018-10-03 17:37:48 +0000 |
commit | 7a40133d3355463368085c14f9fc4b4fd22d549a (patch) | |
tree | 07e0c07cd41a09ddbecdf51323fc0acfedc02330 | |
parent | 7cd368f7be4ff0eb06e0b4975e7c2695ad788b44 (diff) |
memif: include interface name in logs
Change-Id: I67f58aa93c721dbd518cc2ddcea330006693662f
Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
-rw-r--r-- | src/plugins/memif/memif.c | 33 | ||||
-rw-r--r-- | src/plugins/memif/private.h | 42 | ||||
-rw-r--r-- | src/plugins/memif/socket.c | 11 |
3 files changed, 57 insertions, 29 deletions
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c index c01b8dc98fa..e35a8dcb4a0 100644 --- a/src/plugins/memif/memif.c +++ b/src/plugins/memif/memif.c @@ -77,8 +77,8 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) if (mif == 0) return; - vlib_log_debug (mm->log_class, "disconnect %u (%v)", mif->dev_instance, - err ? err->what : 0); + memif_log_debug (mif, "disconnect %u (%v)", mif->dev_instance, + err ? err->what : 0); if (err) { @@ -108,7 +108,7 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) err = clib_socket_close (mif->sock); if (err) { - vlib_log_err (mm->log_class, "%U", format_clib_error, err); + memif_log_err (mif, "%U", format_clib_error, err); clib_error_free (err); } clib_mem_free (mif->sock); @@ -123,7 +123,7 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) int rv; rv = vnet_hw_interface_unassign_rx_thread (vnm, mif->hw_if_index, i); if (rv) - vlib_log_warn (mm->log_class, + memif_log_warn (mif, "Unable to unassign interface %d, queue %d: rc=%d", mif->hw_if_index, i, rv); mq->ring = 0; @@ -146,7 +146,7 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) if (mr->is_external) continue; if ((rv = munmap (mr->shm, mr->region_size))) - clib_warning ("munmap failed, rv = %d", rv); + memif_log_err (mif, "munmap failed, rv = %d", rv); if (mr->fd > -1) close (mr->fd); } @@ -171,7 +171,7 @@ memif_int_fd_read_ready (clib_file_t * uf) size = read (uf->file_descriptor, &b, sizeof (b)); if (size < 0) { - vlib_log_debug (mm->log_class, "Failed to read form socket"); + memif_log_debug (mif, "Failed to read form socket"); return 0; } @@ -185,14 +185,13 @@ memif_int_fd_read_ready (clib_file_t * uf) clib_error_t * memif_connect (memif_if_t * mif) { - memif_main_t *mm = &memif_main; vnet_main_t *vnm = vnet_get_main (); clib_file_t template = { 0 }; memif_region_t *mr; int i; clib_error_t *err = NULL; - vlib_log_debug (mm->log_class, "connect %u", mif->dev_instance); + memif_log_debug (mif, "connect %u", mif->dev_instance); vec_free (mif->local_disc_string); vec_free (mif->remote_disc_string); @@ -258,8 +257,8 @@ memif_connect (memif_if_t * mif) rv = vnet_hw_interface_set_rx_mode (vnm, mif->hw_if_index, i, VNET_HW_INTERFACE_RX_MODE_DEFAULT); if (rv) - clib_warning - ("Warning: unable to set rx mode for interface %d queue %d: " + memif_log_err + (mif, "Warning: unable to set rx mode for interface %d queue %d: " "rc=%d", mif->hw_if_index, i, rv); else { @@ -282,7 +281,7 @@ memif_connect (memif_if_t * mif) return 0; error: - vlib_log_err (mm->log_class, "%U", format_clib_error, err); + memif_log_err (mif, "%U", format_clib_error, err); return err; } @@ -304,7 +303,6 @@ clib_error_t * memif_init_regions_and_queues (memif_if_t * mif) { vlib_main_t *vm = vlib_get_main (); - memif_main_t *mm = &memif_main; memif_ring_t *ring = NULL; int i, j; u64 buffer_offset; @@ -446,7 +444,7 @@ memif_init_regions_and_queues (memif_if_t * mif) return 0; error: - vlib_log_err (mm->log_class, "%U", format_clib_error, err); + memif_log_err (mif, "%U", format_clib_error, err); return err; } @@ -749,7 +747,7 @@ memif_delete_if (vlib_main_t * vm, memif_if_t * mif) err = clib_socket_close (msf->sock); if (err) { - vlib_log_err (mm->log_class, "%U", format_clib_error, err); + memif_log_err (mif, "%U", format_clib_error, err); clib_error_free (err); } clib_mem_free (msf->sock); @@ -842,8 +840,7 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args) msf->dev_instance_by_fd = hash_create (0, sizeof (uword)); msf->is_listener = (args->is_master != 0); - vlib_log_debug (mm->log_class, "initializing socket file %s", - msf->filename); + memif_log_debug (0, "initializing socket file %s", msf->filename); } if (mm->per_thread_data == 0) @@ -1006,7 +1003,7 @@ error: memif_delete_if (vm, mif); if (error) { - vlib_log_err (mm->log_class, "%U", format_clib_error, error); + memif_log_err (mif, "%U", format_clib_error, error); clib_error_free (error); } return ret; @@ -1023,7 +1020,7 @@ memif_init (vlib_main_t * vm) memset (mm, 0, sizeof (memif_main_t)); mm->log_class = vlib_log_register_class ("memif_plugin", 0); - vlib_log_debug (mm->log_class, "initialized"); + memif_log_debug (0, "initialized"); /* initialize binary API */ memif_plugin_api_hookup (vm); diff --git a/src/plugins/memif/private.h b/src/plugins/memif/private.h index 82056a1ecfb..0116de3f1c3 100644 --- a/src/plugins/memif/private.h +++ b/src/plugins/memif/private.h @@ -30,21 +30,52 @@ #define MEMIF_MAX_LOG2_RING_SIZE 14 +#define memif_log_debug(dev, f, ...) do { \ + memif_if_t *_dev = (memif_if_t *) dev; \ + if (_dev) \ + vlib_log(VLIB_LOG_LEVEL_DEBUG, memif_main.log_class, "%U: " f, \ + format_vnet_hw_if_index_name, vnet_get_main(), \ + _dev->hw_if_index, ##__VA_ARGS__); \ + else \ + vlib_log(VLIB_LOG_LEVEL_DEBUG, memif_main.log_class, f, \ + ##__VA_ARGS__); \ +} while (0) + +#define memif_log_warn(dev, f, ...) do { \ + memif_if_t *_dev = (memif_if_t *) dev; \ + if (_dev) \ + vlib_log(VLIB_LOG_LEVEL_WARNING, memif_main.log_class, "%U: " f, \ + format_vnet_hw_if_index_name, vnet_get_main(), \ + _dev->hw_if_index, ##__VA_ARGS__); \ + else \ + vlib_log(VLIB_LOG_LEVEL_WARNING, memif_main.log_class, f, \ + ##__VA_ARGS__); \ +} while (0) + +#define memif_log_err(dev, f, ...) do { \ + memif_if_t *_dev = (memif_if_t *) dev; \ + if (_dev) \ + vlib_log(VLIB_LOG_LEVEL_ERR, memif_main.log_class, "%U: " f, \ + format_vnet_hw_if_index_name, vnet_get_main(), \ + _dev->hw_if_index, ##__VA_ARGS__); \ + else \ + vlib_log(VLIB_LOG_LEVEL_ERR, memif_main.log_class, f, \ + ##__VA_ARGS__); \ +} while (0) + #define memif_file_add(a, b) do { \ *a = clib_file_add (&file_main, b); \ - vlib_log_warn ((&memif_main)->log_class, \ - "clib_file_add fd %d private_data %u idx %u", \ + memif_log_warn (0, "clib_file_add fd %d private_data %u idx %u", \ (b)->file_descriptor, (b)->private_data, *a); \ } while (0) #define memif_file_del(a) do { \ - vlib_log_warn ((&memif_main)->log_class, \ - "clib_file_del idx %u",a - file_main.file_pool); \ + memif_log_warn (0, "clib_file_del idx %u", a - file_main.file_pool); \ clib_file_del (&file_main, a); \ } while (0) #define memif_file_del_by_index(a) do { \ - vlib_log_warn ((&memif_main)->log_class, "clib_file_del idx %u", a); \ + memif_log_warn (0, "clib_file_del idx %u", a); \ clib_file_del_by_index (&file_main, a); \ } while (0) @@ -277,6 +308,7 @@ clib_error_t *memif_msg_send_disconnect (memif_if_t * mif, clib_error_t * err); u8 *format_memif_device_name (u8 * s, va_list * args); + /* * fd.io coding-style-patch-verification: ON * diff --git a/src/plugins/memif/socket.c b/src/plugins/memif/socket.c index 82e865d2a0b..ac48ba88da5 100644 --- a/src/plugins/memif/socket.c +++ b/src/plugins/memif/socket.c @@ -408,7 +408,6 @@ memif_msg_receive_disconnect (memif_if_t * mif, memif_msg_t * msg) static clib_error_t * memif_msg_receive (memif_if_t ** mifp, clib_socket_t * sock, clib_file_t * uf) { - memif_main_t *mm = &memif_main; memif_msg_t msg = { 0 }; clib_error_t *err = 0; int fd = -1; @@ -426,7 +425,7 @@ memif_msg_receive (memif_if_t ** mifp, clib_socket_t * sock, clib_file_t * uf) goto error; } - vlib_log_debug (mm->log_class, "Message type %u received", msg.type); + memif_log_debug (mif, "Message type %u received", msg.type); /* process the message based on its type */ switch (msg.type) { @@ -499,7 +498,7 @@ memif_msg_receive (memif_if_t ** mifp, clib_socket_t * sock, clib_file_t * uf) return 0; error: - vlib_log_err (mm->log_class, "%U", format_clib_error, err); + memif_log_err (mif, "%U", format_clib_error, err); return err; } @@ -639,8 +638,8 @@ memif_master_conn_fd_error (clib_file_t * uf) } } - vlib_log_warn (mm->log_class, "Error on unknown file descriptor %d", - uf->file_descriptor); + memif_log_warn (0, "Error on unknown file descriptor %d", + uf->file_descriptor); memif_file_del (uf); return 0; } @@ -683,7 +682,7 @@ memif_conn_fd_accept_ready (clib_file_t * uf) return 0; error: - vlib_log_err (mm->log_class, "%U", format_clib_error, err); + memif_log_err (0, "%U", format_clib_error, err); clib_mem_free (client); return err; } |