mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +00:00
ovsdb-idl: Simplify usage of ovsdb_idl_run().
It makes client code simpler if ovsdb_idl_run() simply lets the caller know whether anything changed.
This commit is contained in:
@@ -231,9 +231,10 @@ ovsdb_idl_clear(struct ovsdb_idl *idl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
ovsdb_idl_run(struct ovsdb_idl *idl)
|
ovsdb_idl_run(struct ovsdb_idl *idl)
|
||||||
{
|
{
|
||||||
|
unsigned int initial_change_seqno = idl->change_seqno;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
assert(!idl->txn);
|
assert(!idl->txn);
|
||||||
@@ -290,6 +291,8 @@ ovsdb_idl_run(struct ovsdb_idl *idl)
|
|||||||
}
|
}
|
||||||
jsonrpc_msg_destroy(msg);
|
jsonrpc_msg_destroy(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return initial_change_seqno != idl->change_seqno;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ struct ovsdb_idl *ovsdb_idl_create(const char *remote,
|
|||||||
const struct ovsdb_idl_class *);
|
const struct ovsdb_idl_class *);
|
||||||
void ovsdb_idl_destroy(struct ovsdb_idl *);
|
void ovsdb_idl_destroy(struct ovsdb_idl *);
|
||||||
|
|
||||||
void ovsdb_idl_run(struct ovsdb_idl *);
|
bool ovsdb_idl_run(struct ovsdb_idl *);
|
||||||
void ovsdb_idl_wait(struct ovsdb_idl *);
|
void ovsdb_idl_wait(struct ovsdb_idl *);
|
||||||
|
|
||||||
unsigned int ovsdb_idl_get_seqno(const struct ovsdb_idl *);
|
unsigned int ovsdb_idl_get_seqno(const struct ovsdb_idl *);
|
||||||
|
|||||||
@@ -1565,31 +1565,6 @@ print_idl(struct ovsdb_idl *idl, int step)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int
|
|
||||||
print_updated_idl(struct ovsdb_idl *idl, struct jsonrpc *rpc,
|
|
||||||
int step, unsigned int seqno)
|
|
||||||
{
|
|
||||||
for (;;) {
|
|
||||||
unsigned int new_seqno;
|
|
||||||
|
|
||||||
if (rpc) {
|
|
||||||
jsonrpc_run(rpc);
|
|
||||||
}
|
|
||||||
ovsdb_idl_run(idl);
|
|
||||||
new_seqno = ovsdb_idl_get_seqno(idl);
|
|
||||||
if (new_seqno != seqno) {
|
|
||||||
print_idl(idl, step);
|
|
||||||
return new_seqno;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rpc) {
|
|
||||||
jsonrpc_wait(rpc);
|
|
||||||
}
|
|
||||||
ovsdb_idl_wait(idl);
|
|
||||||
poll_block();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_uuids(const struct json *json, struct ovsdb_symbol_table *symtab,
|
parse_uuids(const struct json *json, struct ovsdb_symbol_table *symtab,
|
||||||
size_t *n)
|
size_t *n)
|
||||||
@@ -1786,8 +1761,19 @@ do_idl(int argc, char *argv[])
|
|||||||
/* The previous transaction didn't change anything. */
|
/* The previous transaction didn't change anything. */
|
||||||
arg++;
|
arg++;
|
||||||
} else {
|
} else {
|
||||||
seqno = print_updated_idl(idl, rpc, step++, seqno);
|
/* Wait for update. */
|
||||||
|
while (ovsdb_idl_get_seqno(idl) == seqno && !ovsdb_idl_run(idl)) {
|
||||||
|
jsonrpc_run(rpc);
|
||||||
|
|
||||||
|
ovsdb_idl_wait(idl);
|
||||||
|
jsonrpc_wait(rpc);
|
||||||
|
poll_block();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print update. */
|
||||||
|
print_idl(idl, step++);
|
||||||
}
|
}
|
||||||
|
seqno = ovsdb_idl_get_seqno(idl);
|
||||||
|
|
||||||
if (!strcmp(arg, "reconnect")) {
|
if (!strcmp(arg, "reconnect")) {
|
||||||
printf("%03d: reconnect\n", step++);
|
printf("%03d: reconnect\n", step++);
|
||||||
@@ -1816,7 +1802,11 @@ do_idl(int argc, char *argv[])
|
|||||||
if (rpc) {
|
if (rpc) {
|
||||||
jsonrpc_close(rpc);
|
jsonrpc_close(rpc);
|
||||||
}
|
}
|
||||||
print_updated_idl(idl, NULL, step++, seqno);
|
while (ovsdb_idl_get_seqno(idl) == seqno && !ovsdb_idl_run(idl)) {
|
||||||
|
ovsdb_idl_wait(idl);
|
||||||
|
poll_block();
|
||||||
|
}
|
||||||
|
print_idl(idl, step++);
|
||||||
ovsdb_idl_destroy(idl);
|
ovsdb_idl_destroy(idl);
|
||||||
printf("%03d: done\n", step);
|
printf("%03d: done\n", step);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,6 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct ovsdb_idl *idl;
|
struct ovsdb_idl *idl;
|
||||||
unsigned int seqno;
|
|
||||||
struct vsctl_command *commands;
|
struct vsctl_command *commands;
|
||||||
size_t n_commands;
|
size_t n_commands;
|
||||||
char *args;
|
char *args;
|
||||||
@@ -147,19 +146,13 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Now execute the commands. */
|
/* Now execute the commands. */
|
||||||
idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class);
|
idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class);
|
||||||
seqno = ovsdb_idl_get_seqno(idl);
|
|
||||||
trials = 0;
|
trials = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
unsigned int new_seqno;
|
if (ovsdb_idl_run(idl)) {
|
||||||
|
|
||||||
ovsdb_idl_run(idl);
|
|
||||||
new_seqno = ovsdb_idl_get_seqno(idl);
|
|
||||||
if (new_seqno != seqno) {
|
|
||||||
if (++trials > 5) {
|
if (++trials > 5) {
|
||||||
vsctl_fatal("too many database inconsistency failures");
|
vsctl_fatal("too many database inconsistency failures");
|
||||||
}
|
}
|
||||||
do_vsctl(args, commands, n_commands, idl);
|
do_vsctl(args, commands, n_commands, idl);
|
||||||
seqno = new_seqno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ovsdb_idl_wait(idl);
|
ovsdb_idl_wait(idl);
|
||||||
|
|||||||
@@ -62,9 +62,7 @@ main(int argc, char *argv[])
|
|||||||
struct signal *sighup;
|
struct signal *sighup;
|
||||||
struct ovsdb_idl *idl;
|
struct ovsdb_idl *idl;
|
||||||
const char *remote;
|
const char *remote;
|
||||||
bool need_reconfigure;
|
|
||||||
bool inited, exiting;
|
bool inited, exiting;
|
||||||
unsigned int idl_seqno;
|
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
proctitle_init(argc, argv);
|
proctitle_init(argc, argv);
|
||||||
@@ -89,27 +87,27 @@ main(int argc, char *argv[])
|
|||||||
daemonize_complete();
|
daemonize_complete();
|
||||||
|
|
||||||
idl = ovsdb_idl_create(remote, &ovsrec_idl_class);
|
idl = ovsdb_idl_create(remote, &ovsrec_idl_class);
|
||||||
idl_seqno = ovsdb_idl_get_seqno(idl);
|
|
||||||
|
|
||||||
need_reconfigure = false;
|
|
||||||
inited = false;
|
inited = false;
|
||||||
exiting = false;
|
exiting = false;
|
||||||
while (!exiting) {
|
while (!exiting) {
|
||||||
|
bool need_reconfigure;
|
||||||
|
|
||||||
if (signal_poll(sighup)) {
|
if (signal_poll(sighup)) {
|
||||||
vlog_reopen_log_file();
|
vlog_reopen_log_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
need_reconfigure = false;
|
||||||
if (inited && bridge_run()) {
|
if (inited && bridge_run()) {
|
||||||
need_reconfigure = true;
|
need_reconfigure = true;
|
||||||
}
|
}
|
||||||
ovsdb_idl_run(idl);
|
if (ovsdb_idl_run(idl)) {
|
||||||
if (idl_seqno != ovsdb_idl_get_seqno(idl)) {
|
|
||||||
idl_seqno = ovsdb_idl_get_seqno(idl);
|
|
||||||
need_reconfigure = true;
|
need_reconfigure = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (need_reconfigure) {
|
if (need_reconfigure) {
|
||||||
const struct ovsrec_open_vswitch *cfg;
|
const struct ovsrec_open_vswitch *cfg;
|
||||||
|
|
||||||
need_reconfigure = false;
|
|
||||||
cfg = ovsrec_open_vswitch_first(idl);
|
cfg = ovsrec_open_vswitch_first(idl);
|
||||||
if (cfg) {
|
if (cfg) {
|
||||||
if (inited) {
|
if (inited) {
|
||||||
|
|||||||
Reference in New Issue
Block a user