[ovs-dev] [PATCH 1/2] ovsdb-idl: New function ovsdb_idl_txn_commit_block().

Justin Pettit jpettit at nicira.com
Wed Mar 3 21:43:52 UTC 2010


Looks good.

--Justin


On Mar 3, 2010, at 1:19 PM, Ben Pfaff wrote:

> This commit factors out common code from multiple callers of
> ovsdb_idl_txn_commit() into a new function ovsdb_idl_txn_commit_block().
> ---
> lib/ovsdb-idl.c          |   17 +++++++++++++++++
> lib/ovsdb-idl.h          |    1 +
> tests/test-ovsdb.c       |    7 +------
> utilities/ovs-vsctl.c    |    7 +------
> vswitchd/ovs-brcompatd.c |    7 +------
> 5 files changed, 21 insertions(+), 18 deletions(-)
> 
> diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
> index f60ec4b..fd4607d 100644
> --- a/lib/ovsdb-idl.c
> +++ b/lib/ovsdb-idl.c
> @@ -1264,6 +1264,23 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn)
>     return txn->status;
> }
> 
> +/* Attempts to commit 'txn', blocking until the commit either succeeds or
> + * fails.  Returns the final commit status, which may be any TXN_* value other
> + * than TXN_INCOMPLETE. */
> +enum ovsdb_idl_txn_status
> +ovsdb_idl_txn_commit_block(struct ovsdb_idl_txn *txn)
> +{
> +    enum ovsdb_idl_txn_status status;
> +
> +    while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
> +        ovsdb_idl_run(txn->idl);
> +        ovsdb_idl_wait(txn->idl);
> +        ovsdb_idl_txn_wait(txn);
> +        poll_block();
> +    }
> +    return status;
> +}
> +
> int64_t
> ovsdb_idl_txn_get_increment_new_value(const struct ovsdb_idl_txn *txn)
> {
> diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
> index d451427..cfbb97c 100644
> --- a/lib/ovsdb-idl.h
> +++ b/lib/ovsdb-idl.h
> @@ -65,6 +65,7 @@ void ovsdb_idl_txn_increment(struct ovsdb_idl_txn *, const char *table,
> void ovsdb_idl_txn_destroy(struct ovsdb_idl_txn *);
> void ovsdb_idl_txn_wait(const struct ovsdb_idl_txn *);
> enum ovsdb_idl_txn_status ovsdb_idl_txn_commit(struct ovsdb_idl_txn *);
> +enum ovsdb_idl_txn_status ovsdb_idl_txn_commit_block(struct ovsdb_idl_txn *);
> void ovsdb_idl_txn_abort(struct ovsdb_idl_txn *);
> 
> const char *ovsdb_idl_txn_get_error(const struct ovsdb_idl_txn *);
> diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c
> index 48a5007..b2ab4c6 100644
> --- a/tests/test-ovsdb.c
> +++ b/tests/test-ovsdb.c
> @@ -1735,12 +1735,7 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
>         }
>     }
> 
> -    while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
> -        ovsdb_idl_run(idl);
> -        ovsdb_idl_wait(idl);
> -        ovsdb_idl_txn_wait(txn);
> -        poll_block();
> -    }
> +    status = ovsdb_idl_txn_commit_block(txn);
>     printf("%03d: commit, status=%s",
>            step, ovsdb_idl_txn_status_to_string(status));
>     if (increment) {
> diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
> index 1c00f43..4efb1d0 100644
> --- a/utilities/ovs-vsctl.c
> +++ b/utilities/ovs-vsctl.c
> @@ -2386,12 +2386,7 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
>         vsctl_context_done(&ctx, c);
>     }
> 
> -    while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
> -        ovsdb_idl_run(idl);
> -        ovsdb_idl_wait(idl);
> -        ovsdb_idl_txn_wait(txn);
> -        poll_block();
> -    }
> +    status = ovsdb_idl_txn_commit_block(txn);
>     if (wait_for_reload && status == TXN_SUCCESS) {
>         next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
>     }
> diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c
> index dd7ea42..aa90c39 100644
> --- a/vswitchd/ovs-brcompatd.c
> +++ b/vswitchd/ovs-brcompatd.c
> @@ -1222,12 +1222,7 @@ main(int argc, char *argv[])
>             poll_timer_wait(prune_timeout);
>         }
> 
> -        while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
> -            ovsdb_idl_run(idl);
> -            ovsdb_idl_wait(idl);
> -            ovsdb_idl_txn_wait(txn);
> -            poll_block();
> -        }
> +        status = ovsdb_idl_txn_commit_block(txn);
> 
>         switch (status) {
>         case TXN_INCOMPLETE:
> -- 
> 1.6.6.1
> 
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org





More information about the dev mailing list