Skip to content

Commit

Permalink
ovn-sbctl: Get rid of redundant code by using function from db-ctl-base.
Browse files Browse the repository at this point in the history
This renames get_row() to ctl_get_row() and makes it public.  It's
unfortunate that it adds a cast, but getting rid of redundant code seems
worth it to me.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Andy Zhou <[email protected]>
  • Loading branch information
blp committed May 3, 2017
1 parent 682b417 commit bed7aef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
24 changes: 12 additions & 12 deletions lib/db-ctl-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ get_row_by_id(struct ctl_context *ctx,
return final;
}

static const struct ovsdb_idl_row *
get_row(struct ctl_context *ctx,
const struct ovsdb_idl_table_class *table, const char *record_id,
bool must_exist)
const struct ovsdb_idl_row *
ctl_get_row(struct ctl_context *ctx,
const struct ovsdb_idl_table_class *table, const char *record_id,
bool must_exist)
{
const struct ovsdb_idl_row *row = NULL;
struct uuid uuid;
Expand Down Expand Up @@ -837,7 +837,7 @@ cmd_get(struct ctl_context *ctx)
}

table = get_table(table_name);
row = get_row(ctx, table, record_id, must_exist);
row = ctl_get_row(ctx, table, record_id, must_exist);
if (!row) {
return;
}
Expand Down Expand Up @@ -1065,7 +1065,7 @@ cmd_list(struct ctl_context *ctx)
out = ctx->table = list_make_table(columns, n_columns);
if (ctx->argc > 2) {
for (i = 2; i < ctx->argc; i++) {
list_record(get_row(ctx, table, ctx->argv[i], must_exist),
list_record(ctl_get_row(ctx, table, ctx->argv[i], must_exist),
columns, n_columns, out);
}
} else {
Expand Down Expand Up @@ -1231,7 +1231,7 @@ cmd_set(struct ctl_context *ctx)
int i;

table = get_table(table_name);
row = get_row(ctx, table, record_id, must_exist);
row = ctl_get_row(ctx, table, record_id, must_exist);
if (!row) {
return;
}
Expand Down Expand Up @@ -1271,7 +1271,7 @@ cmd_add(struct ctl_context *ctx)

table = get_table(table_name);
die_if_error(get_column(table, column_name, &column));
row = get_row(ctx, table, record_id, must_exist);
row = ctl_get_row(ctx, table, record_id, must_exist);
if (!row) {
return;
}
Expand Down Expand Up @@ -1332,7 +1332,7 @@ cmd_remove(struct ctl_context *ctx)

table = get_table(table_name);
die_if_error(get_column(table, column_name, &column));
row = get_row(ctx, table, record_id, must_exist);
row = ctl_get_row(ctx, table, record_id, must_exist);
if (!row) {
return;
}
Expand Down Expand Up @@ -1403,7 +1403,7 @@ cmd_clear(struct ctl_context *ctx)
int i;

table = get_table(table_name);
row = get_row(ctx, table, record_id, must_exist);
row = ctl_get_row(ctx, table, record_id, must_exist);
if (!row) {
return;
}
Expand Down Expand Up @@ -1541,7 +1541,7 @@ cmd_destroy(struct ctl_context *ctx)
for (i = 2; i < ctx->argc; i++) {
const struct ovsdb_idl_row *row;

row = get_row(ctx, table, ctx->argv[i], must_exist);
row = ctl_get_row(ctx, table, ctx->argv[i], must_exist);
if (row) {
ovsdb_idl_txn_delete(row);
}
Expand Down Expand Up @@ -1575,7 +1575,7 @@ cmd_wait_until(struct ctl_context *ctx)

table = get_table(table_name);

row = get_row(ctx, table, record_id, false);
row = ctl_get_row(ctx, table, record_id, false);
if (!row) {
ctx->try_again = true;
return;
Expand Down
5 changes: 5 additions & 0 deletions lib/db-ctl-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ struct ctl_table_class {
struct ctl_row_id row_ids[4];
};

const struct ovsdb_idl_row *ctl_get_row(struct ctl_context *,
const struct ovsdb_idl_table_class *,
const char *record_id,
bool must_exist);

void ctl_set_column(const char *table_name,
const struct ovsdb_idl_row *, const char *arg,
struct ovsdb_symbol_table *);
Expand Down
31 changes: 3 additions & 28 deletions ovn/utilities/ovn-sbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,39 +736,14 @@ is_partial_uuid_match(const struct uuid *uuid, const char *match)
return !strncmp(s1, s2, strlen(s2));
}

static const struct sbrec_datapath_binding *
lookup_datapath(struct ovsdb_idl *idl, const char *s)
{
struct uuid uuid;
if (uuid_from_string(&uuid, s)) {
const struct sbrec_datapath_binding *datapath;
datapath = sbrec_datapath_binding_get_for_uuid(idl, &uuid);
if (datapath) {
return datapath;
}
}

const struct sbrec_datapath_binding *found = NULL;
const struct sbrec_datapath_binding *datapath;
SBREC_DATAPATH_BINDING_FOR_EACH (datapath, idl) {
const char *name = smap_get(&datapath->external_ids, "name");
if (name && !strcmp(name, s)) {
if (!found) {
found = datapath;
} else {
ctl_fatal("%s: multiple datapaths with this name", s);
}
}
}
return found;
}

static void
cmd_lflow_list(struct ctl_context *ctx)
{
const struct sbrec_datapath_binding *datapath = NULL;
if (ctx->argc > 1) {
datapath = lookup_datapath(ctx->idl, ctx->argv[1]);
datapath = (const struct sbrec_datapath_binding *)
ctl_get_row(ctx, &sbrec_table_datapath_binding,
ctx->argv[1], false);
if (datapath) {
ctx->argc--;
ctx->argv++;
Expand Down

0 comments on commit bed7aef

Please sign in to comment.