2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-29 15:28:56 +00:00

dpif: Refactor flow logging functions to be used by other modules

To be reused by other modules.

Signed-off-by: Roi Dayan <roid@mellanox.com>
Reviewed-by: Paul Blakey <paulb@mellanox.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
Signed-off-by: Simon Horman <simon.horman@netronome.com>
This commit is contained in:
Roi Dayan
2017-06-13 18:03:53 +03:00
committed by Simon Horman
parent 1067cf93ac
commit eff1e5b091
2 changed files with 72 additions and 43 deletions

View File

@@ -92,24 +92,10 @@ static struct vlog_rate_limit dpmsg_rl = VLOG_RATE_LIMIT_INIT(600, 600);
/* Not really much point in logging many dpif errors. */
static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(60, 5);
static void log_flow_message(const struct dpif *dpif, int error,
const char *operation,
const struct nlattr *key, size_t key_len,
const struct nlattr *mask, size_t mask_len,
const ovs_u128 *ufid,
const struct dpif_flow_stats *stats,
const struct nlattr *actions, size_t actions_len);
static void log_operation(const struct dpif *, const char *operation,
int error);
static bool should_log_flow_message(int error);
static void log_flow_put_message(struct dpif *, const struct dpif_flow_put *,
int error);
static void log_flow_del_message(struct dpif *, const struct dpif_flow_del *,
int error);
static void log_execute_message(struct dpif *, const struct dpif_execute *,
bool subexecute, int error);
static void log_flow_get_message(const struct dpif *,
const struct dpif_flow_get *, int error);
static bool should_log_flow_message(const struct vlog_module *module,
int error);
/* Incremented whenever tnl route, arp, etc changes. */
struct seq *tnl_conf_seq;
@@ -1125,8 +1111,9 @@ dpif_flow_dump_next(struct dpif_flow_dump_thread *thread,
if (n > 0) {
struct dpif_flow *f;
for (f = flows; f < &flows[n] && should_log_flow_message(0); f++) {
log_flow_message(dpif, 0, "flow_dump",
for (f = flows; f < &flows[n]
&& should_log_flow_message(&this_module, 0); f++) {
log_flow_message(dpif, 0, &this_module, "flow_dump",
f->key, f->key_len, f->mask, f->mask_len,
&f->ufid, &f->stats, f->actions, f->actions_len);
}
@@ -1231,7 +1218,8 @@ dpif_execute_helper_cb(void *aux_, struct dp_packet_batch *packets_,
execute.probe = false;
execute.mtu = 0;
aux->error = dpif_execute(aux->dpif, &execute);
log_execute_message(aux->dpif, &execute, true, aux->error);
log_execute_message(aux->dpif, &this_module, &execute,
true, aux->error);
dp_packet_delete(clone);
@@ -1346,7 +1334,7 @@ dpif_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops)
struct dpif_flow_put *put = &op->u.flow_put;
COVERAGE_INC(dpif_flow_put);
log_flow_put_message(dpif, put, error);
log_flow_put_message(dpif, &this_module, put, error);
if (error && put->stats) {
memset(put->stats, 0, sizeof *put->stats);
}
@@ -1360,7 +1348,7 @@ dpif_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops)
if (error) {
memset(get->flow, 0, sizeof *get->flow);
}
log_flow_get_message(dpif, get, error);
log_flow_get_message(dpif, &this_module, get, error);
break;
}
@@ -1369,7 +1357,7 @@ dpif_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops)
struct dpif_flow_del *del = &op->u.flow_del;
COVERAGE_INC(dpif_flow_del);
log_flow_del_message(dpif, del, error);
log_flow_del_message(dpif, &this_module, del, error);
if (error && del->stats) {
memset(del->stats, 0, sizeof *del->stats);
}
@@ -1378,7 +1366,8 @@ dpif_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops)
case DPIF_OP_EXECUTE:
COVERAGE_INC(dpif_execute);
log_execute_message(dpif, &op->u.execute, false, error);
log_execute_message(dpif, &this_module, &op->u.execute,
false, error);
break;
}
}
@@ -1690,14 +1679,16 @@ flow_message_log_level(int error)
}
static bool
should_log_flow_message(int error)
should_log_flow_message(const struct vlog_module *module, int error)
{
return !vlog_should_drop(&this_module, flow_message_log_level(error),
return !vlog_should_drop(module, flow_message_log_level(error),
error ? &error_rl : &dpmsg_rl);
}
static void
log_flow_message(const struct dpif *dpif, int error, const char *operation,
void
log_flow_message(const struct dpif *dpif, int error,
const struct vlog_module *module,
const char *operation,
const struct nlattr *key, size_t key_len,
const struct nlattr *mask, size_t mask_len,
const ovs_u128 *ufid, const struct dpif_flow_stats *stats,
@@ -1725,15 +1716,18 @@ log_flow_message(const struct dpif *dpif, int error, const char *operation,
ds_put_cstr(&ds, ", actions:");
format_odp_actions(&ds, actions, actions_len);
}
vlog(&this_module, flow_message_log_level(error), "%s", ds_cstr(&ds));
vlog(module, flow_message_log_level(error), "%s", ds_cstr(&ds));
ds_destroy(&ds);
}
static void
log_flow_put_message(struct dpif *dpif, const struct dpif_flow_put *put,
void
log_flow_put_message(const struct dpif *dpif,
const struct vlog_module *module,
const struct dpif_flow_put *put,
int error)
{
if (should_log_flow_message(error) && !(put->flags & DPIF_FP_PROBE)) {
if (should_log_flow_message(module, error)
&& !(put->flags & DPIF_FP_PROBE)) {
struct ds s;
ds_init(&s);
@@ -1747,7 +1741,7 @@ log_flow_put_message(struct dpif *dpif, const struct dpif_flow_put *put,
if (put->flags & DPIF_FP_ZERO_STATS) {
ds_put_cstr(&s, "[zero]");
}
log_flow_message(dpif, error, ds_cstr(&s),
log_flow_message(dpif, error, module, ds_cstr(&s),
put->key, put->key_len, put->mask, put->mask_len,
put->ufid, put->stats, put->actions,
put->actions_len);
@@ -1755,12 +1749,15 @@ log_flow_put_message(struct dpif *dpif, const struct dpif_flow_put *put,
}
}
static void
log_flow_del_message(struct dpif *dpif, const struct dpif_flow_del *del,
void
log_flow_del_message(const struct dpif *dpif,
const struct vlog_module *module,
const struct dpif_flow_del *del,
int error)
{
if (should_log_flow_message(error)) {
log_flow_message(dpif, error, "flow_del", del->key, del->key_len,
if (should_log_flow_message(module, error)) {
log_flow_message(dpif, error, module, "flow_del",
del->key, del->key_len,
NULL, 0, del->ufid, !error ? del->stats : NULL,
NULL, 0);
}
@@ -1783,8 +1780,10 @@ log_flow_del_message(struct dpif *dpif, const struct dpif_flow_del *del,
*
* It would still be better to avoid the potential problem. I don't know of a
* good way to do that, though, that isn't expensive. */
static void
log_execute_message(struct dpif *dpif, const struct dpif_execute *execute,
void
log_execute_message(const struct dpif *dpif,
const struct vlog_module *module,
const struct dpif_execute *execute,
bool subexecute, int error)
{
if (!(error ? VLOG_DROP_WARN(&error_rl) : VLOG_DROP_DBG(&dpmsg_rl))
@@ -1811,19 +1810,21 @@ log_execute_message(struct dpif *dpif, const struct dpif_execute *execute,
ds_put_format(&ds, " with metadata ");
odp_flow_format(md.data, md.size, NULL, 0, NULL, &ds, true);
ds_put_format(&ds, " mtu %d", execute->mtu);
vlog(&this_module, error ? VLL_WARN : VLL_DBG, "%s", ds_cstr(&ds));
vlog(module, error ? VLL_WARN : VLL_DBG, "%s", ds_cstr(&ds));
ds_destroy(&ds);
free(packet);
ofpbuf_uninit(&md);
}
}
static void
log_flow_get_message(const struct dpif *dpif, const struct dpif_flow_get *get,
void
log_flow_get_message(const struct dpif *dpif,
const struct vlog_module *module,
const struct dpif_flow_get *get,
int error)
{
if (should_log_flow_message(error)) {
log_flow_message(dpif, error, "flow_get",
if (should_log_flow_message(module, error)) {
log_flow_message(dpif, error, module, "flow_get",
get->key, get->key_len,
get->flow->mask, get->flow->mask_len,
get->ufid, &get->flow->stats,

View File

@@ -885,6 +885,34 @@ int dpif_get_pmds_for_port(const struct dpif * dpif, odp_port_t port_no,
char *dpif_get_dp_version(const struct dpif *);
bool dpif_supports_tnl_push_pop(const struct dpif *);
/* Log functions. */
struct vlog_module;
void log_flow_message(const struct dpif *dpif, int error,
const struct vlog_module *module,
const char *operation,
const struct nlattr *key, size_t key_len,
const struct nlattr *mask, size_t mask_len,
const ovs_u128 *ufid,
const struct dpif_flow_stats *stats,
const struct nlattr *actions, size_t actions_len);
void log_flow_put_message(const struct dpif *,
const struct vlog_module *,
const struct dpif_flow_put *,
int error);
void log_flow_del_message(const struct dpif *,
const struct vlog_module *,
const struct dpif_flow_del *,
int error);
void log_execute_message(const struct dpif *,
const struct vlog_module *,
const struct dpif_execute *,
bool subexecute, int error);
void log_flow_get_message(const struct dpif *,
const struct vlog_module *,
const struct dpif_flow_get *,
int error);
#ifdef __cplusplus
}
#endif