1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2017 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
23 #include "condition.h"
25 #include "openvswitch/json.h"
27 #include "ovsdb-data.h"
28 #include "ovsdb-error.h"
29 #include "ovsdb-parser.h"
36 #include "transaction.h"
38 struct ovsdb_execution
{
40 const struct ovsdb_session
*session
;
41 struct ovsdb_txn
*txn
;
42 struct ovsdb_symbol_table
*symtab
;
48 long long int elapsed_msec
;
49 long long int timeout_msec
;
52 typedef struct ovsdb_error
*ovsdb_operation_executor(struct ovsdb_execution
*,
53 struct ovsdb_parser
*,
56 static ovsdb_operation_executor ovsdb_execute_insert
;
57 static ovsdb_operation_executor ovsdb_execute_select
;
58 static ovsdb_operation_executor ovsdb_execute_update
;
59 static ovsdb_operation_executor ovsdb_execute_mutate
;
60 static ovsdb_operation_executor ovsdb_execute_delete
;
61 static ovsdb_operation_executor ovsdb_execute_wait
;
62 static ovsdb_operation_executor ovsdb_execute_commit
;
63 static ovsdb_operation_executor ovsdb_execute_abort
;
64 static ovsdb_operation_executor ovsdb_execute_comment
;
65 static ovsdb_operation_executor ovsdb_execute_assert
;
67 static ovsdb_operation_executor
*
68 lookup_executor(const char *name
, bool *read_only
)
70 struct ovsdb_operation
{
73 ovsdb_operation_executor
*executor
;
76 static const struct ovsdb_operation operations
[] = {
77 { "insert", false, ovsdb_execute_insert
},
78 { "select", true, ovsdb_execute_select
},
79 { "update", false, ovsdb_execute_update
},
80 { "mutate", false, ovsdb_execute_mutate
},
81 { "delete", false, ovsdb_execute_delete
},
82 { "wait", true, ovsdb_execute_wait
},
83 { "commit", false, ovsdb_execute_commit
},
84 { "abort", true, ovsdb_execute_abort
},
85 { "comment", true, ovsdb_execute_comment
},
86 { "assert", true, ovsdb_execute_assert
},
91 for (i
= 0; i
< ARRAY_SIZE(operations
); i
++) {
92 const struct ovsdb_operation
*c
= &operations
[i
];
93 if (!strcmp(c
->name
, name
)) {
94 *read_only
= c
->read_only
;
101 /* On success, returns a transaction and stores the results to return to the
102 * client in '*resultsp'.
104 * On failure, returns NULL. If '*resultsp' is nonnull, then it is the results
105 * to return to the client. If '*resultsp' is null, then the execution failed
106 * due to an unsatisfied "wait" operation and '*timeout_msec' is the time at
107 * which the transaction will time out. (If 'timeout_msec' is null, this case
108 * never occurs--instead, an unsatisfied "wait" unconditionally fails.) */
110 ovsdb_execute_compose(struct ovsdb
*db
, const struct ovsdb_session
*session
,
111 const struct json
*params
, bool read_only
,
112 const char *role
, const char *id
,
113 long long int elapsed_msec
, long long int *timeout_msec
,
114 bool *durable
, struct json
**resultsp
)
116 struct ovsdb_execution x
;
117 struct ovsdb_error
*error
;
118 struct json
*results
;
123 if (params
->type
!= JSON_ARRAY
125 || params
->array
.elems
[0]->type
!= JSON_STRING
126 || strcmp(params
->array
.elems
[0]->string
, db
->schema
->name
)) {
127 if (params
->type
!= JSON_ARRAY
) {
128 error
= ovsdb_syntax_error(params
, NULL
, "array expected");
130 error
= ovsdb_syntax_error(params
, NULL
, "database name expected "
131 "as first parameter");
134 *resultsp
= ovsdb_error_to_json_free(error
);
140 x
.txn
= ovsdb_txn_create(db
);
141 x
.symtab
= ovsdb_symbol_table_create();
145 x
.elapsed_msec
= elapsed_msec
;
146 x
.timeout_msec
= LLONG_MAX
;
149 results
= json_array_create_empty();
150 n_operations
= params
->array
.n
- 1;
152 for (i
= 1; i
<= n_operations
; i
++) {
153 struct json
*operation
= params
->array
.elems
[i
];
154 struct ovsdb_error
*parse_error
;
155 struct ovsdb_parser parser
;
157 const struct json
*op
;
158 const char *op_name
= NULL
;
161 /* Parse and execute operation. */
162 ovsdb_parser_init(&parser
, operation
,
163 "ovsdb operation %"PRIuSIZE
" of %"PRIuSIZE
, i
,
165 op
= ovsdb_parser_member(&parser
, "op", OP_ID
);
166 result
= json_object_create();
168 op_name
= json_string(op
);
169 ovsdb_operation_executor
*executor
= lookup_executor(op_name
, &ro
);
171 error
= executor(&x
, &parser
, result
);
173 ovsdb_parser_raise_error(&parser
, "No operation \"%s\"",
177 ovs_assert(ovsdb_parser_has_error(&parser
));
180 /* A parse error overrides any other error.
181 * An error overrides any other result. */
182 parse_error
= ovsdb_parser_finish(&parser
);
184 ovsdb_error_destroy(error
);
187 /* Create read-only violation error if there is one. */
190 error
= ovsdb_error("not allowed",
191 "%s operation not allowed when "
192 "database server is in read only mode",
194 } else if (db
->schema
->name
[0] == '_') {
195 error
= ovsdb_error("not allowed",
196 "%s operation not allowed on "
197 "table in reserved database %s",
198 op_name
, db
->schema
->name
);
202 json_destroy(result
);
203 json_array_add(results
, ovsdb_error_to_json(error
));
204 if (!strcmp(ovsdb_error_get_tag(error
), "not supported")
206 *timeout_msec
= x
.timeout_msec
;
207 json_destroy(results
);
213 json_array_add(results
, result
);
215 while (json_array(results
)->n
< n_operations
) {
216 json_array_add(results
, json_null_create());
221 ovsdb_txn_abort(x
.txn
);
224 ovsdb_error_destroy(error
);
227 *durable
= x
.durable
;
228 ovsdb_symbol_table_destroy(x
.symtab
);
234 ovsdb_execute(struct ovsdb
*db
, const struct ovsdb_session
*session
,
235 const struct json
*params
, bool read_only
,
236 const char *role
, const char *id
,
237 long long int elapsed_msec
, long long int *timeout_msec
)
240 struct json
*results
;
241 struct ovsdb_txn
*txn
= ovsdb_execute_compose(
242 db
, session
, params
, read_only
, role
, id
, elapsed_msec
, timeout_msec
,
248 struct ovsdb_error
*error
= ovsdb_txn_propose_commit_block(txn
, durable
);
250 json_array_add(results
, ovsdb_error_to_json(error
));
251 ovsdb_error_destroy(error
);
256 static struct ovsdb_error
*
257 ovsdb_execute_commit(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
258 struct json
*result OVS_UNUSED
)
260 const struct json
*durable
;
262 durable
= ovsdb_parser_member(parser
, "durable", OP_BOOLEAN
);
263 if (durable
&& json_boolean(durable
)) {
269 static struct ovsdb_error
*
270 ovsdb_execute_abort(struct ovsdb_execution
*x OVS_UNUSED
,
271 struct ovsdb_parser
*parser OVS_UNUSED
,
272 struct json
*result OVS_UNUSED
)
274 return ovsdb_error("aborted", "aborted by request");
277 static struct ovsdb_table
*
278 parse_table(struct ovsdb_execution
*x
,
279 struct ovsdb_parser
*parser
, const char *member
)
281 struct ovsdb_table
*table
;
282 const char *table_name
;
283 const struct json
*json
;
285 json
= ovsdb_parser_member(parser
, member
, OP_ID
);
289 table_name
= json_string(json
);
291 table
= shash_find_data(&x
->db
->tables
, table_name
);
293 ovsdb_parser_raise_error(parser
, "No table named %s.", table_name
);
298 static OVS_WARN_UNUSED_RESULT
struct ovsdb_error
*
299 parse_row(const struct json
*json
, const struct ovsdb_table
*table
,
300 struct ovsdb_symbol_table
*symtab
,
301 struct ovsdb_row
**rowp
, struct ovsdb_column_set
*columns
)
303 struct ovsdb_error
*error
;
304 struct ovsdb_row
*row
;
309 return OVSDB_BUG("null table");
312 return OVSDB_BUG("null row");
315 row
= ovsdb_row_create(table
);
316 error
= ovsdb_row_from_json(row
, json
, symtab
, columns
);
318 ovsdb_row_destroy(row
);
326 static struct ovsdb_error
*
327 ovsdb_execute_insert(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
330 struct ovsdb_table
*table
;
331 struct ovsdb_row
*row
= NULL
;
332 const struct json
*uuid_name
, *row_json
;
333 struct ovsdb_error
*error
;
334 struct uuid row_uuid
;
336 table
= parse_table(x
, parser
, "table");
337 uuid_name
= ovsdb_parser_member(parser
, "uuid-name", OP_ID
| OP_OPTIONAL
);
338 row_json
= ovsdb_parser_member(parser
, "row", OP_OBJECT
);
339 error
= ovsdb_parser_get_error(parser
);
345 struct ovsdb_symbol
*symbol
;
347 symbol
= ovsdb_symbol_table_insert(x
->symtab
, json_string(uuid_name
));
348 if (symbol
->created
) {
349 return ovsdb_syntax_error(uuid_name
, "duplicate uuid-name",
350 "This \"uuid-name\" appeared on an "
351 "earlier \"insert\" operation.");
353 row_uuid
= symbol
->uuid
;
354 symbol
->created
= true;
356 uuid_generate(&row_uuid
);
360 error
= parse_row(row_json
, table
, x
->symtab
, &row
, NULL
);
363 /* Check constraints for columns not included in "row", in case the
364 * default values do not satisfy the constraints. We could check only
365 * the columns that have their default values by supplying an
366 * ovsdb_column_set to parse_row() above, but I suspect that this is
368 const struct shash_node
*node
;
370 SHASH_FOR_EACH (node
, &table
->schema
->columns
) {
371 const struct ovsdb_column
*column
= node
->data
;
372 const struct ovsdb_datum
*datum
= &row
->fields
[column
->index
];
374 /* If there are 0 keys or pairs, there's nothing to check.
375 * If there is 1, it might be a default value.
376 * If there are more, it can't be a default value, so the value has
377 * already been checked. */
379 error
= ovsdb_datum_check_constraints(datum
, &column
->type
);
387 if (!error
&& !ovsdb_rbac_insert(x
->db
, table
, row
, x
->role
, x
->id
)) {
388 error
= ovsdb_perm_error("RBAC rules for client \"%s\" role \"%s\" "
389 "prohibit row insertion into table \"%s\".",
390 x
->id
, x
->role
, table
->schema
->name
);
394 *ovsdb_row_get_uuid_rw(row
) = row_uuid
;
395 ovsdb_txn_row_insert(x
->txn
, row
);
396 json_object_put(result
, "uuid",
397 ovsdb_datum_to_json(&row
->fields
[OVSDB_COL_UUID
],
400 ovsdb_row_destroy(row
);
405 static struct ovsdb_error
*
406 ovsdb_execute_select(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
409 struct ovsdb_table
*table
;
410 const struct json
*where
, *columns_json
, *sort_json
;
411 struct ovsdb_condition condition
= OVSDB_CONDITION_INITIALIZER(&condition
);
412 struct ovsdb_column_set columns
= OVSDB_COLUMN_SET_INITIALIZER
;
413 struct ovsdb_column_set sort
= OVSDB_COLUMN_SET_INITIALIZER
;
414 struct ovsdb_error
*error
;
416 table
= parse_table(x
, parser
, "table");
417 where
= ovsdb_parser_member(parser
, "where", OP_ARRAY
);
418 columns_json
= ovsdb_parser_member(parser
, "columns",
419 OP_ARRAY
| OP_OPTIONAL
);
420 sort_json
= ovsdb_parser_member(parser
, "sort", OP_ARRAY
| OP_OPTIONAL
);
422 error
= ovsdb_parser_get_error(parser
);
424 error
= ovsdb_condition_from_json(table
->schema
, where
, x
->symtab
,
428 error
= ovsdb_column_set_from_json(columns_json
, table
->schema
,
432 error
= ovsdb_column_set_from_json(sort_json
, table
->schema
, &sort
);
435 struct ovsdb_row_set rows
= OVSDB_ROW_SET_INITIALIZER
;
437 ovsdb_query_distinct(table
, &condition
, &columns
, &rows
);
438 ovsdb_row_set_sort(&rows
, &sort
);
439 json_object_put(result
, "rows",
440 ovsdb_row_set_to_json(&rows
, &columns
));
442 ovsdb_row_set_destroy(&rows
);
445 ovsdb_column_set_destroy(&columns
);
446 ovsdb_column_set_destroy(&sort
);
447 ovsdb_condition_destroy(&condition
);
452 struct update_row_cbdata
{
454 struct ovsdb_txn
*txn
;
455 const struct ovsdb_row
*row
;
456 const struct ovsdb_column_set
*columns
;
462 update_row_cb(const struct ovsdb_row
*row
, void *ur_
)
464 struct update_row_cbdata
*ur
= ur_
;
467 if (!ovsdb_row_equal_columns(row
, ur
->row
, ur
->columns
)) {
468 ovsdb_row_update_columns(ovsdb_txn_row_modify(ur
->txn
, row
),
469 ur
->row
, ur
->columns
);
475 static struct ovsdb_error
*
476 ovsdb_execute_update(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
479 struct ovsdb_table
*table
;
480 const struct json
*where
, *row_json
;
481 struct ovsdb_condition condition
= OVSDB_CONDITION_INITIALIZER(&condition
);
482 struct ovsdb_column_set columns
= OVSDB_COLUMN_SET_INITIALIZER
;
483 struct ovsdb_row
*row
= NULL
;
484 struct update_row_cbdata ur
;
485 struct ovsdb_error
*error
;
487 table
= parse_table(x
, parser
, "table");
488 where
= ovsdb_parser_member(parser
, "where", OP_ARRAY
);
489 row_json
= ovsdb_parser_member(parser
, "row", OP_OBJECT
);
490 error
= ovsdb_parser_get_error(parser
);
492 error
= parse_row(row_json
, table
, x
->symtab
, &row
, &columns
);
497 for (i
= 0; i
< columns
.n_columns
; i
++) {
498 const struct ovsdb_column
*column
= columns
.columns
[i
];
500 if (!column
->mutable) {
501 error
= ovsdb_syntax_error(parser
->json
,
502 "constraint violation",
503 "Cannot update immutable column %s "
505 column
->name
, table
->schema
->name
);
511 error
= ovsdb_condition_from_json(table
->schema
, where
, x
->symtab
,
518 ur
.columns
= &columns
;
519 if (ovsdb_rbac_update(x
->db
, table
, &columns
, &condition
, x
->role
,
521 ovsdb_query(table
, &condition
, update_row_cb
, &ur
);
523 error
= ovsdb_perm_error("RBAC rules for client \"%s\" role "
524 "\"%s\" prohibit modification of "
526 x
->id
, x
->role
, table
->schema
->name
);
528 json_object_put(result
, "count", json_integer_create(ur
.n_matches
));
531 ovsdb_row_destroy(row
);
532 ovsdb_column_set_destroy(&columns
);
533 ovsdb_condition_destroy(&condition
);
538 struct mutate_row_cbdata
{
540 struct ovsdb_txn
*txn
;
541 const struct ovsdb_mutation_set
*mutations
;
542 struct ovsdb_error
**error
;
546 mutate_row_cb(const struct ovsdb_row
*row
, void *mr_
)
548 struct mutate_row_cbdata
*mr
= mr_
;
551 *mr
->error
= ovsdb_mutation_set_execute(ovsdb_txn_row_modify(mr
->txn
, row
),
553 return *mr
->error
== NULL
;
556 static struct ovsdb_error
*
557 ovsdb_execute_mutate(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
560 struct ovsdb_table
*table
;
561 const struct json
*where
;
562 const struct json
*mutations_json
;
563 struct ovsdb_condition condition
= OVSDB_CONDITION_INITIALIZER(&condition
);
564 struct ovsdb_mutation_set mutations
= OVSDB_MUTATION_SET_INITIALIZER
;
565 struct ovsdb_row
*row
= NULL
;
566 struct mutate_row_cbdata mr
;
567 struct ovsdb_error
*error
;
569 table
= parse_table(x
, parser
, "table");
570 where
= ovsdb_parser_member(parser
, "where", OP_ARRAY
);
571 mutations_json
= ovsdb_parser_member(parser
, "mutations", OP_ARRAY
);
572 error
= ovsdb_parser_get_error(parser
);
574 error
= ovsdb_mutation_set_from_json(table
->schema
, mutations_json
,
575 x
->symtab
, &mutations
);
578 error
= ovsdb_condition_from_json(table
->schema
, where
, x
->symtab
,
584 mr
.mutations
= &mutations
;
586 if (ovsdb_rbac_mutate(x
->db
, table
, &mutations
, &condition
, x
->role
,
588 ovsdb_query(table
, &condition
, mutate_row_cb
, &mr
);
590 error
= ovsdb_perm_error("RBAC rules for client \"%s\" role "
591 "\"%s\" prohibit mutate operation on "
593 x
->id
, x
->role
, table
->schema
->name
);
595 json_object_put(result
, "count", json_integer_create(mr
.n_matches
));
598 ovsdb_row_destroy(row
);
599 ovsdb_mutation_set_destroy(&mutations
);
600 ovsdb_condition_destroy(&condition
);
605 struct delete_row_cbdata
{
607 const struct ovsdb_table
*table
;
608 struct ovsdb_txn
*txn
;
612 delete_row_cb(const struct ovsdb_row
*row
, void *dr_
)
614 struct delete_row_cbdata
*dr
= dr_
;
617 ovsdb_txn_row_delete(dr
->txn
, row
);
622 static struct ovsdb_error
*
623 ovsdb_execute_delete(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
626 struct ovsdb_table
*table
;
627 const struct json
*where
;
628 struct ovsdb_condition condition
= OVSDB_CONDITION_INITIALIZER(&condition
);
629 struct ovsdb_error
*error
;
631 where
= ovsdb_parser_member(parser
, "where", OP_ARRAY
);
632 table
= parse_table(x
, parser
, "table");
633 error
= ovsdb_parser_get_error(parser
);
635 error
= ovsdb_condition_from_json(table
->schema
, where
, x
->symtab
,
639 struct delete_row_cbdata dr
;
645 if (ovsdb_rbac_delete(x
->db
, table
, &condition
, x
->role
, x
->id
)) {
646 ovsdb_query(table
, &condition
, delete_row_cb
, &dr
);
648 error
= ovsdb_perm_error("RBAC rules for client \"%s\" role "
649 "\"%s\" prohibit row deletion from "
651 x
->id
, x
->role
, table
->schema
->name
);
653 json_object_put(result
, "count", json_integer_create(dr
.n_matches
));
656 ovsdb_condition_destroy(&condition
);
661 struct wait_auxdata
{
662 struct ovsdb_row_hash
*actual
;
663 struct ovsdb_row_hash
*expected
;
668 ovsdb_execute_wait_query_cb(const struct ovsdb_row
*row
, void *aux_
)
670 struct wait_auxdata
*aux
= aux_
;
672 if (ovsdb_row_hash_contains(aux
->expected
, row
)) {
673 ovsdb_row_hash_insert(aux
->actual
, row
);
676 /* The query row isn't in the expected result set, so the actual and
677 * expected results sets definitely differ and we can short-circuit the
678 * rest of the query. */
684 static struct ovsdb_error
*
685 ovsdb_execute_wait(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
686 struct json
*result OVS_UNUSED
)
688 struct ovsdb_table
*table
;
689 const struct json
*timeout
, *where
, *columns_json
, *until
, *rows
;
690 struct ovsdb_condition condition
= OVSDB_CONDITION_INITIALIZER(&condition
);
691 struct ovsdb_column_set columns
= OVSDB_COLUMN_SET_INITIALIZER
;
692 struct ovsdb_row_hash expected
= OVSDB_ROW_HASH_INITIALIZER(expected
);
693 struct ovsdb_row_hash actual
= OVSDB_ROW_HASH_INITIALIZER(actual
);
694 struct ovsdb_error
*error
;
695 struct wait_auxdata aux
;
696 long long int timeout_msec
= 0;
699 timeout
= ovsdb_parser_member(parser
, "timeout", OP_NUMBER
| OP_OPTIONAL
);
700 where
= ovsdb_parser_member(parser
, "where", OP_ARRAY
);
701 columns_json
= ovsdb_parser_member(parser
, "columns",
702 OP_ARRAY
| OP_OPTIONAL
);
703 until
= ovsdb_parser_member(parser
, "until", OP_STRING
);
704 rows
= ovsdb_parser_member(parser
, "rows", OP_ARRAY
);
705 table
= parse_table(x
, parser
, "table");
706 error
= ovsdb_parser_get_error(parser
);
708 error
= ovsdb_condition_from_json(table
->schema
, where
, x
->symtab
,
712 error
= ovsdb_column_set_from_json(columns_json
, table
->schema
,
717 timeout_msec
= MIN(LLONG_MAX
, json_real(timeout
));
718 if (timeout_msec
< 0) {
719 error
= ovsdb_syntax_error(timeout
, NULL
,
720 "timeout must be nonnegative");
721 } else if (timeout_msec
< x
->timeout_msec
) {
722 x
->timeout_msec
= timeout_msec
;
725 timeout_msec
= LLONG_MAX
;
729 if (strcmp(json_string(until
), "==")
730 && strcmp(json_string(until
), "!=")) {
731 error
= ovsdb_syntax_error(until
, NULL
,
732 "\"until\" must be \"==\" or \"!=\"");
736 /* Parse "rows" into 'expected'. */
737 ovsdb_row_hash_init(&expected
, &columns
);
738 for (i
= 0; i
< rows
->array
.n
; i
++) {
739 struct ovsdb_row
*row
;
741 row
= ovsdb_row_create(table
);
742 error
= ovsdb_row_from_json(row
, rows
->array
.elems
[i
], x
->symtab
,
745 ovsdb_row_destroy(row
);
749 if (!ovsdb_row_hash_insert(&expected
, row
)) {
750 /* XXX Perhaps we should abort with an error or log a
752 ovsdb_row_destroy(row
);
759 ovsdb_row_hash_init(&actual
, &columns
);
760 aux
.actual
= &actual
;
761 aux
.expected
= &expected
;
763 ovsdb_query(table
, &condition
, ovsdb_execute_wait_query_cb
, &aux
);
765 /* We know that every row in 'actual' is also in 'expected'. We
766 * also know that all of the rows in 'actual' are distinct and that
767 * all of the rows in 'expected' are distinct. Therefore, if
768 * 'actual' and 'expected' have the same number of rows, then they
769 * have the same content. */
770 size_t n_actual
= ovsdb_row_hash_count(&actual
);
771 size_t n_expected
= ovsdb_row_hash_count(&expected
);
772 equal
= n_actual
== n_expected
;
774 if (!strcmp(json_string(until
), "==") != equal
) {
775 if (timeout
&& x
->elapsed_msec
>= timeout_msec
) {
776 if (x
->elapsed_msec
) {
777 error
= ovsdb_error("timed out",
778 "\"wait\" timed out after %lld ms",
781 error
= ovsdb_error("timed out",
782 "\"where\" clause test failed");
785 /* ovsdb_execute() will change this, if triggers really are
787 error
= ovsdb_error("not supported", "triggers not supported");
793 ovsdb_row_hash_destroy(&expected
, true);
794 ovsdb_row_hash_destroy(&actual
, false);
795 ovsdb_column_set_destroy(&columns
);
796 ovsdb_condition_destroy(&condition
);
801 static struct ovsdb_error
*
802 ovsdb_execute_comment(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
803 struct json
*result OVS_UNUSED
)
805 const struct json
*comment
;
807 comment
= ovsdb_parser_member(parser
, "comment", OP_STRING
);
811 ovsdb_txn_add_comment(x
->txn
, json_string(comment
));
816 static struct ovsdb_error
*
817 ovsdb_execute_assert(struct ovsdb_execution
*x
, struct ovsdb_parser
*parser
,
818 struct json
*result OVS_UNUSED
)
820 const struct json
*lock_name
;
822 lock_name
= ovsdb_parser_member(parser
, "lock", OP_ID
);
828 const struct ovsdb_lock_waiter
*waiter
;
830 waiter
= ovsdb_session_get_lock_waiter(x
->session
,
831 json_string(lock_name
));
832 if (waiter
&& ovsdb_lock_waiter_is_owner(waiter
)) {
837 return ovsdb_error("not owner", "Asserted lock %s not held.",
838 json_string(lock_name
));