[ovs-dev] [PATCH monitor_cond V2 06/12] ovsdb: add API for changing monitor session's conditions

Andy Zhou azhou at ovn.org
Fri Jan 22 02:09:47 UTC 2016


On Sat, Jan 16, 2016 at 12:16 AM, Liran Schour <lirans at il.ibm.com> wrote:

> That will be used to by jsonrpc-server for monitor_cond_change
> method See ovsdb-server (1) man page.
>
> Signed-off-by: Liran Schour <lirans at il.ibm.com>
> ---
>  ovsdb/monitor.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
>  ovsdb/monitor.h |  7 +++++++
>  2 files changed, 58 insertions(+), 1 deletion(-)
>
> diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c
> index 5e3117a..cf87b98 100644
> --- a/ovsdb/monitor.c
> +++ b/ovsdb/monitor.c
> @@ -591,6 +591,50 @@ ovsdb_monitor_table_condition_add(
>      return NULL;
>  }
>
> +struct ovsdb_error *
> +ovsdb_monitor_table_condition_change(
> +                            struct ovsdb_monitor_session_condition
> *condition,
> +                            const struct ovsdb_table *table,
> +                            const struct json *added,
> +                            const struct json *removed)
> +{
> +    struct ovsdb_monitor_table_condition *mtc =
> +        shash_find_data(&condition->tables, table->schema->name);
> +    struct ovsdb_condition added_cnd = OVSDB_CONDITION_INITIALIZER;
> +    struct ovsdb_condition removed_cnd = OVSDB_CONDITION_INITIALIZER;
> +    struct ovsdb_error *error;
> +
> +    if (added) {
> +        error = ovsdb_condition_from_json(table->schema, added,
> +                                          NULL, &added_cnd);
> +        if (error) {
> +            return error;
> +        }
> +    }
> +    if (removed) {
> +        error = ovsdb_condition_from_json(table->schema, removed,
> +                                          NULL, &removed_cnd);
> +        if (error) {
> +            return error;
> +        }
> +    }
> +    if (!ovsdb_conditions_includes(&mtc->new_condition,
> +                                   &added_cnd, &removed_cnd)) {
> +        return ovsdb_syntax_error(
> +                             removed, NULL,
> +                             "conditions does not include removed");
> +    }
> +
> +    ovsdb_condition_add(&mtc->new_condition, &added_cnd);
> +    ovsdb_condition_remove(&mtc->new_condition, &removed_cnd);
> +
> +    if (!ovsdb_condition_empty(&mtc->new_condition)) {
> +        condition->can_cache = false;
> +    }
>
If we do:
      condition->can_cache = ovsdb_condition_empty(&mtc->new_condition);
then we don't have worry about how can_cache is initialized.  Slightly
better
for maintenance.  I think.

+
> +    return NULL;
> +}
> +
>  /* Set session's condition in this ovsdb_monitor */
>  static void
>  ovsdb_monitor_set_condition(
> @@ -764,7 +808,7 @@ ovsdb_monitor_compose_row_update(
>   * for 'row' within * 'mt', or NULL if no row update should be sent.
>   *
>   * The caller should specify 'initial' as true if the returned JSON is
> - * going to be used as part of the initial reply to a "monitor2" request,
> + * going to be used as part of the initial reply to a "monitor_cond"
> request,
>   * false if it is going to be used as part of an "update2" notification.
>   *
>   * 'changed' must be a scratch buffer for internal use that is at least
> @@ -948,6 +992,12 @@ ovsdb_monitor_get_update(
>
>          ovsdb_monitor_table_untrack_changes(mt, prev_txn);
>          ovsdb_monitor_table_track_changes(mt, next_txn);
> +
> +        if (dbmon->condition && ovsdb_condition_cmp(mt->old_condition,
> +                                                    mt->new_condition)) {
> +            ovsdb_condition_destroy(mt->old_condition);
> +            ovsdb_condition_clone(mt->old_condition, mt->new_condition);
> +        }
>      }
>      *unflushed = next_txn;
>      ovsdb_monitor_unset_condition(dbmon);
> diff --git a/ovsdb/monitor.h b/ovsdb/monitor.h
> index d4063f7..0f6c360 100644
> --- a/ovsdb/monitor.h
> +++ b/ovsdb/monitor.h
> @@ -106,4 +106,11 @@ void ovsdb_monitor_session_condition_bind(
>                             const struct ovsdb_monitor_session_condition *,
>                             const struct ovsdb_monitor *);
>
> +struct ovsdb_error *
> +ovsdb_monitor_table_condition_change(
> +                           struct ovsdb_monitor_session_condition
> *condition,
> +                           const struct ovsdb_table *table,
> +                           const struct json *added,
> +                           const struct json *removed);
> +
>  #endif
> --
> 2.1.4
>
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>



More information about the dev mailing list