mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
ovsdb-error: New function ovsdb_error_to_string_free().
This allows slight code simplifications across the tree. Signed-off-by: Ben Pfaff <blp@ovn.org> Tested-by: Yifeng Sun <pkusunyifeng@gmail.com> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2009, 2010, 2011, 2012, 2014, 2016 Nicira, Inc.
|
||||
/* Copyright (c) 2009, 2010, 2011, 2012, 2014, 2016, 2017 Nicira, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -664,8 +664,7 @@ ovsdb_atom_from_string(union ovsdb_atom *atom,
|
||||
free(*range_end_atom);
|
||||
*range_end_atom = NULL;
|
||||
}
|
||||
msg = ovsdb_error_to_string(error);
|
||||
ovsdb_error_destroy(error);
|
||||
msg = ovsdb_error_to_string_free(error);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc.
|
||||
/* Copyright (c) 2009, 2010, 2011, 2012, 2016, 2017 Nicira, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -153,11 +153,9 @@ ovsdb_internal_error(struct ovsdb_error *inner_error,
|
||||
ds_put_format(&ds, " (%s %s)", program_name, VERSION);
|
||||
|
||||
if (inner_error) {
|
||||
char *s = ovsdb_error_to_string(inner_error);
|
||||
char *s = ovsdb_error_to_string_free(inner_error);
|
||||
ds_put_format(&ds, " (generated from: %s)", s);
|
||||
free(s);
|
||||
|
||||
ovsdb_error_destroy(inner_error);
|
||||
}
|
||||
|
||||
error = ovsdb_error("internal error", "%s", ds_cstr(&ds));
|
||||
@@ -223,6 +221,8 @@ ovsdb_error_to_json(const struct ovsdb_error *error)
|
||||
return json;
|
||||
}
|
||||
|
||||
/* Returns 'error' converted to a string suitable for use as an error message.
|
||||
* The caller must free the returned string (with free()). */
|
||||
char *
|
||||
ovsdb_error_to_string(const struct ovsdb_error *error)
|
||||
{
|
||||
@@ -240,6 +240,24 @@ ovsdb_error_to_string(const struct ovsdb_error *error)
|
||||
return ds_steal_cstr(&ds);
|
||||
}
|
||||
|
||||
/* Returns 'error' converted to a string suitable for use as an error message.
|
||||
* The caller must free the returned string (with free()).
|
||||
*
|
||||
* If 'error' is NULL, returns NULL.
|
||||
*
|
||||
* Also, frees 'error'. */
|
||||
char *
|
||||
ovsdb_error_to_string_free(struct ovsdb_error *error)
|
||||
{
|
||||
if (error) {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
ovsdb_error_destroy(error);
|
||||
return s;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
ovsdb_error_get_tag(const struct ovsdb_error *error)
|
||||
{
|
||||
@@ -254,9 +272,8 @@ ovsdb_error_assert(struct ovsdb_error *error)
|
||||
{
|
||||
if (error) {
|
||||
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
VLOG_ERR_RL(&rl, "unexpected ovsdb error: %s", s);
|
||||
free(s);
|
||||
ovsdb_error_destroy(error);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2009, 2010, 2011 Nicira, Inc.
|
||||
/* Copyright (c) 2009, 2010, 2011, 2016, 2017 Nicira, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,6 +64,7 @@ struct ovsdb_error *ovsdb_error_clone(const struct ovsdb_error *)
|
||||
OVS_WARN_UNUSED_RESULT;
|
||||
|
||||
char *ovsdb_error_to_string(const struct ovsdb_error *);
|
||||
char *ovsdb_error_to_string_free(struct ovsdb_error *);
|
||||
struct json *ovsdb_error_to_json(const struct ovsdb_error *);
|
||||
|
||||
const char *ovsdb_error_get_tag(const struct ovsdb_error *);
|
||||
|
@@ -1455,10 +1455,9 @@ ovsdb_idl_send_schema_request(struct ovsdb_idl *idl)
|
||||
static void
|
||||
log_error(struct ovsdb_error *error)
|
||||
{
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
VLOG_WARN("error parsing database schema: %s", s);
|
||||
free(s);
|
||||
ovsdb_error_destroy(error);
|
||||
}
|
||||
|
||||
/* Frees 'schema', which is in the format returned by parse_schema(). */
|
||||
@@ -1976,12 +1975,11 @@ ovsdb_idl_row_change__(struct ovsdb_idl_row *row, const struct json *row_json,
|
||||
|
||||
ovsdb_datum_destroy(&datum, &column->type);
|
||||
} else {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
VLOG_WARN_RL(&syntax_rl, "error parsing column %s in row "UUID_FMT
|
||||
" in table %s: %s", column_name,
|
||||
UUID_ARGS(&row->uuid), table->class_->name, s);
|
||||
free(s);
|
||||
ovsdb_error_destroy(error);
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
@@ -4186,11 +4184,10 @@ ovsdb_idl_txn_process_insert_reply(struct ovsdb_idl_txn_insert *insert,
|
||||
|
||||
error = ovsdb_atom_from_json(&uuid, &uuid_type, json_uuid, NULL);
|
||||
if (error) {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
VLOG_WARN_RL(&syntax_rl, "\"insert\" reply \"uuid\" is not a JSON "
|
||||
"UUID: %s", s);
|
||||
free(s);
|
||||
ovsdb_error_destroy(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -237,11 +237,9 @@ ovsdb_file_open__(const char *file_name,
|
||||
/* Log error but otherwise ignore it. Probably the database just got
|
||||
* truncated due to power failure etc. and we should use its current
|
||||
* contents. */
|
||||
char *msg = ovsdb_error_to_string(error);
|
||||
char *msg = ovsdb_error_to_string_free(error);
|
||||
VLOG_ERR("%s", msg);
|
||||
free(msg);
|
||||
|
||||
ovsdb_error_destroy(error);
|
||||
}
|
||||
|
||||
if (!read_only) {
|
||||
@@ -608,8 +606,7 @@ ovsdb_file_commit(struct ovsdb_replica *replica,
|
||||
{
|
||||
error = ovsdb_file_compact(file);
|
||||
if (error) {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
ovsdb_error_destroy(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
VLOG_WARN("%s: compacting database failed (%s), retrying in "
|
||||
"%d seconds",
|
||||
file->file_name, s, COMPACT_RETRY_MSEC / 1000);
|
||||
|
@@ -517,7 +517,7 @@ open_db(struct server_config *config, const char *filename)
|
||||
|
||||
db_error = ovsdb_file_open(db->filename, false, &db->db, &db->file);
|
||||
if (db_error) {
|
||||
error = ovsdb_error_to_string(db_error);
|
||||
error = ovsdb_error_to_string_free(db_error);
|
||||
} else if (!ovsdb_jsonrpc_server_add_db(config->jsonrpc, db->db)) {
|
||||
error = xasprintf("%s: duplicate database name", db->db->schema->name);
|
||||
} else {
|
||||
@@ -525,7 +525,6 @@ open_db(struct server_config *config, const char *filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ovsdb_error_destroy(db_error);
|
||||
close_db(db);
|
||||
return error;
|
||||
}
|
||||
@@ -916,10 +915,9 @@ update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
|
||||
db = node->data;
|
||||
error = ovsdb_txn_commit(db->txn, false);
|
||||
if (error) {
|
||||
char *msg = ovsdb_error_to_string(error);
|
||||
char *msg = ovsdb_error_to_string_free(error);
|
||||
VLOG_ERR_RL(&rl, "Failed to update remote status: %s", msg);
|
||||
free(msg);
|
||||
ovsdb_error_destroy(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1157,10 +1155,9 @@ ovsdb_server_compact(struct unixctl_conn *conn, int argc,
|
||||
|
||||
error = ovsdb_file_compact(db->file);
|
||||
if (error) {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
ds_put_format(&reply, "%s\n", s);
|
||||
free(s);
|
||||
ovsdb_error_destroy(error);
|
||||
}
|
||||
|
||||
n++;
|
||||
|
@@ -269,8 +269,7 @@ print_and_free_json(struct json *json)
|
||||
static void
|
||||
print_and_free_ovsdb_error(struct ovsdb_error *error)
|
||||
{
|
||||
char *string = ovsdb_error_to_string(error);
|
||||
ovsdb_error_destroy(error);
|
||||
char *string = ovsdb_error_to_string_free(error);
|
||||
puts(string);
|
||||
free(string);
|
||||
}
|
||||
@@ -279,8 +278,7 @@ static void
|
||||
check_ovsdb_error(struct ovsdb_error *error)
|
||||
{
|
||||
if (error) {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
ovsdb_error_destroy(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
ovs_fatal(0, "%s", s);
|
||||
}
|
||||
}
|
||||
@@ -344,10 +342,9 @@ do_log_io(struct ovs_cmdl_context *ctx)
|
||||
ovs_fatal(0, "unknown log-io command \"%s\"", command);
|
||||
}
|
||||
if (error) {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
printf("%s: %s failed: %s\n", name, command, s);
|
||||
free(s);
|
||||
ovsdb_error_destroy(error);
|
||||
} else {
|
||||
printf("%s: %s successful\n", name, command);
|
||||
}
|
||||
@@ -450,8 +447,7 @@ do_diff_data(struct ovs_cmdl_context *ctx)
|
||||
/* Apply diff to 'old' to create'reincarnation'. */
|
||||
error = ovsdb_datum_apply_diff(&reincarnation, &old, &diff, &type);
|
||||
if (error) {
|
||||
char *string = ovsdb_error_to_string(error);
|
||||
ovsdb_error_destroy(error);
|
||||
char *string = ovsdb_error_to_string_free(error);
|
||||
ovs_fatal(0, "%s", string);
|
||||
}
|
||||
|
||||
@@ -873,10 +869,9 @@ do_parse_conditions(struct ovs_cmdl_context *ctx)
|
||||
if (!error) {
|
||||
print_and_free_json(ovsdb_condition_to_json(&cnd));
|
||||
} else {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
ovs_error(0, "%s", s);
|
||||
free(s);
|
||||
ovsdb_error_destroy(error);
|
||||
exit_code = 1;
|
||||
}
|
||||
json_destroy(json);
|
||||
@@ -1044,10 +1039,9 @@ do_parse_mutations(struct ovs_cmdl_context *ctx)
|
||||
if (!error) {
|
||||
print_and_free_json(ovsdb_mutation_set_to_json(&set));
|
||||
} else {
|
||||
char *s = ovsdb_error_to_string(error);
|
||||
char *s = ovsdb_error_to_string_free(error);
|
||||
ovs_error(0, "%s", s);
|
||||
free(s);
|
||||
ovsdb_error_destroy(error);
|
||||
exit_code = 1;
|
||||
}
|
||||
json_destroy(json);
|
||||
|
Reference in New Issue
Block a user