From 7915565fb13a12cbd4bfbb845f933e81df5ae85e Mon Sep 17 00:00:00 2001 From: Ales Musil Date: Tue, 15 Aug 2023 13:04:01 +0200 Subject: [PATCH] ovn-nbctl: Prevent sync exiting early on nb_cfg overflow We are correctly wrapping nb_cfg over when the value is LLONG_MAX. However, the sync code is expecting the value to be always raising, so it would exit early as the current >= next is true for the wrap back to 0. To detect that use delta between those two values. The delta threshold is set to INT32_MAX as we don't expect the nb_cfg to be updated more than that during the sync call. Signed-off-by: Ales Musil Acked-by: Mark Michelson Signed-off-by: Mark Michelson --- northd/ovn-northd.c | 4 +++- utilities/ovn-nbctl.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 7d24648ff1..234b7e9147 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -520,7 +520,9 @@ update_sequence_numbers(int64_t loop_start_time, chassis_priv->name); } - if (chassis_priv->nb_cfg < hv_cfg) { + /* Detect if overflows happened within the cfg update. */ + int64_t delta = chassis_priv->nb_cfg - hv_cfg; + if (chassis_priv->nb_cfg < hv_cfg || delta > INT32_MAX) { hv_cfg = chassis_priv->nb_cfg; hv_cfg_ts = chassis_priv->nb_cfg_timestamp; } else if (chassis_priv->nb_cfg == hv_cfg && diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 9399f9462b..03b18595dc 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -122,7 +122,9 @@ nbctl_post_execute(struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn, int64_t cur_cfg = (wait_type == NBCTL_WAIT_SB ? nb->sb_cfg : MIN(nb->sb_cfg, nb->hv_cfg)); - if (cur_cfg >= next_cfg) { + /* Detect if overflows happened within the cfg update. */ + int64_t delta = cur_cfg - next_cfg; + if (cur_cfg >= next_cfg && delta < INT32_MAX) { if (print_wait_time) { printf("Time spent on processing nb_cfg %"PRId64":\n", next_cfg);