Skip to content

Commit

Permalink
ovsdb: Allow receiving 'set_db_change_aware' as notification.
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
  • Loading branch information
igsilya committed Sep 8, 2021
1 parent 5c1cc74 commit d37f663
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/ovsdb-cs.c
Expand Up @@ -1448,9 +1448,8 @@ ovsdb_cs_send_schema_request(struct ovsdb_cs *cs,
static void
ovsdb_cs_send_db_change_aware(struct ovsdb_cs *cs)
{
struct jsonrpc_msg *msg = jsonrpc_create_request(
"set_db_change_aware", json_array_create_1(json_boolean_create(true)),
NULL);
struct jsonrpc_msg *msg = jsonrpc_create_notify(
"set_db_change_aware", json_array_create_1(json_boolean_create(true)));
jsonrpc_session_send(cs->session, msg);
}

Expand Down
19 changes: 16 additions & 3 deletions ovsdb/jsonrpc-server.c
Expand Up @@ -977,17 +977,28 @@ ovsdb_jsonrpc_session_unlock(struct ovsdb_jsonrpc_session *s,

static struct jsonrpc_msg *
ovsdb_jsonrpc_session_set_db_change_aware(struct ovsdb_jsonrpc_session *s,
const struct jsonrpc_msg *request)
const struct jsonrpc_msg *request,
bool needs_reply)
{
const struct json_array *params = json_array(request->params);
if (params->n != 1
|| (params->elems[0]->type != JSON_TRUE &&
params->elems[0]->type != JSON_FALSE)) {
if (!needs_reply) {
char *param = json_to_string(params->elems[0], 0);
VLOG_WARN_RL(&rl,"%s: received set_db_change_aware message "
"with unexpected parameter %s",
jsonrpc_session_get_name(s->js), param);
free(param);
return NULL;
}
return syntax_error_reply(request, "true or false parameter expected");
}

s->db_change_aware = json_boolean(params->elems[0]);
return jsonrpc_create_reply(json_object_create(), request->id);
return needs_reply
? jsonrpc_create_reply(json_object_create(), request->id)
: NULL;
}

static void
Expand Down Expand Up @@ -1058,7 +1069,7 @@ ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *s,
} else if (!strcmp(request->method, "unlock")) {
reply = ovsdb_jsonrpc_session_unlock(s, request);
} else if (!strcmp(request->method, "set_db_change_aware")) {
reply = ovsdb_jsonrpc_session_set_db_change_aware(s, request);
reply = ovsdb_jsonrpc_session_set_db_change_aware(s, request, true);
} else if (!strcmp(request->method, "echo")) {
reply = jsonrpc_create_reply(json_clone(request->params), request->id);
} else {
Expand Down Expand Up @@ -1093,6 +1104,8 @@ ovsdb_jsonrpc_session_got_notify(struct ovsdb_jsonrpc_session *s,
{
if (!strcmp(request->method, "cancel")) {
execute_cancel(s, request);
} else if (!strcmp(request->method, "set_db_change_aware")) {
ovsdb_jsonrpc_session_set_db_change_aware(s, request, false);
}
jsonrpc_msg_destroy(request);
}
Expand Down

0 comments on commit d37f663

Please sign in to comment.