git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge commit '4b60911067a82fbdfa87b7c2824412da20287ed8'
[sliver-openvswitch.git]
/
ovsdb
/
ovsdb-client.c
diff --git
a/ovsdb/ovsdb-client.c
b/ovsdb/ovsdb-client.c
index
d2a9de1
..
c25148d
100644
(file)
--- a/
ovsdb/ovsdb-client.c
+++ b/
ovsdb/ovsdb-client.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (c) 2009, 2010, 2011
Nicira Networks
.
+ * Copyright (c) 2009, 2010, 2011
, 2012, 2013 Nicira, Inc
.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-16,7
+16,6
@@
#include <config.h>
#include <config.h>
-#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
@@
-39,7
+38,7
@@
#include "ovsdb-data.h"
#include "ovsdb-error.h"
#include "sort.h"
#include "ovsdb-data.h"
#include "ovsdb-error.h"
#include "sort.h"
-#include "s
set
.h"
+#include "s
vec
.h"
#include "stream.h"
#include "stream-ssl.h"
#include "table.h"
#include "stream.h"
#include "stream-ssl.h"
#include "table.h"
@@
-64,6
+63,9
@@
struct ovsdb_client_command {
int argc, char *argv[]);
};
int argc, char *argv[]);
};
+/* --timestamp: Print a timestamp before each update on "monitor" command? */
+static bool timestamp;
+
/* Format for table output. */
static struct table_style table_style = TABLE_STYLE_DEFAULT;
/* Format for table output. */
static struct table_style table_style = TABLE_STYLE_DEFAULT;
@@
-72,7
+74,7
@@
static const struct ovsdb_client_command all_commands[];
static void usage(void) NO_RETURN;
static void parse_options(int argc, char *argv[]);
static struct jsonrpc *open_jsonrpc(const char *server);
static void usage(void) NO_RETURN;
static void parse_options(int argc, char *argv[]);
static struct jsonrpc *open_jsonrpc(const char *server);
-static void fetch_dbs(struct jsonrpc *, struct s
set
*dbs);
+static void fetch_dbs(struct jsonrpc *, struct s
vec
*dbs);
int
main(int argc, char *argv[])
int
main(int argc, char *argv[])
@@
-115,22
+117,22
@@
main(int argc, char *argv[])
}
if (command->need == NEED_DATABASE) {
}
if (command->need == NEED_DATABASE) {
- struct s
set
dbs;
+ struct s
vec
dbs;
- s
set
_init(&dbs);
+ s
vec
_init(&dbs);
fetch_dbs(rpc, &dbs);
if (argc - optind > command->min_args
fetch_dbs(rpc, &dbs);
if (argc - optind > command->min_args
- && s
set
_contains(&dbs, argv[optind])) {
+ && s
vec
_contains(&dbs, argv[optind])) {
database = argv[optind++];
database = argv[optind++];
- } else if (
sset_count(&dbs)
== 1) {
- database = xstrdup(
SSET_FIRST(&dbs)
);
- } else if (s
set
_contains(&dbs, "Open_vSwitch")) {
+ } else if (
dbs.n
== 1) {
+ database = xstrdup(
dbs.names[0]
);
+ } else if (s
vec
_contains(&dbs, "Open_vSwitch")) {
database = "Open_vSwitch";
} else {
ovs_fatal(0, "no default database for `%s' command, please "
"specify a database name", command->name);
}
database = "Open_vSwitch";
} else {
ovs_fatal(0, "no default database for `%s' command, please "
"specify a database name", command->name);
}
- s
set
_destroy(&dbs);
+ s
vec
_destroy(&dbs);
} else {
database = NULL;
}
} else {
database = NULL;
}
@@
-160,13
+162,15
@@
parse_options(int argc, char *argv[])
{
enum {
OPT_BOOTSTRAP_CA_CERT = UCHAR_MAX + 1,
{
enum {
OPT_BOOTSTRAP_CA_CERT = UCHAR_MAX + 1,
+ OPT_TIMESTAMP,
DAEMON_OPTION_ENUMS,
TABLE_OPTION_ENUMS
};
DAEMON_OPTION_ENUMS,
TABLE_OPTION_ENUMS
};
- static struct option long_options[] = {
+ static
const
struct option long_options[] = {
{"verbose", optional_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{"verbose", optional_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
+ {"timestamp", no_argument, NULL, OPT_TIMESTAMP},
DAEMON_LONG_OPTIONS,
#ifdef HAVE_OPENSSL
{"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
DAEMON_LONG_OPTIONS,
#ifdef HAVE_OPENSSL
{"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
@@
-207,6
+211,10
@@
parse_options(int argc, char *argv[])
stream_ssl_set_ca_cert_file(optarg, true);
break;
stream_ssl_set_ca_cert_file(optarg, true);
break;
+ case OPT_TIMESTAMP:
+ timestamp = true;
+ break;
+
case '?':
exit(EXIT_FAILURE);
case '?':
exit(EXIT_FAILURE);
@@
-256,7
+264,8
@@
usage(void)
" (\"table\", \"html\", \"csv\", "
"or \"json\")\n"
" --no-headings omit table heading row\n"
" (\"table\", \"html\", \"csv\", "
"or \"json\")\n"
" --no-headings omit table heading row\n"
- " --pretty pretty-print JSON in output");
+ " --pretty pretty-print JSON in output\n"
+ " --timestamp timestamp \"monitor\" output");
daemon_usage();
vlog_usage();
printf("\nOther options:\n"
daemon_usage();
vlog_usage();
printf("\nOther options:\n"
@@
-265,6
+274,21
@@
usage(void)
exit(EXIT_SUCCESS);
}
\f
exit(EXIT_SUCCESS);
}
\f
+static void
+check_txn(int error, struct jsonrpc_msg **reply_)
+{
+ struct jsonrpc_msg *reply = *reply_;
+
+ if (error) {
+ ovs_fatal(error, "transaction failed");
+ }
+
+ if (reply->error) {
+ ovs_fatal(error, "transaction returned error: %s",
+ json_to_string(reply->error, table_style.json_flags));
+ }
+}
+
static struct json *
parse_json(const char *s)
{
static struct json *
parse_json(const char *s)
{
@@
-281,11
+305,12
@@
open_jsonrpc(const char *server)
struct stream *stream;
int error;
struct stream *stream;
int error;
- error = stream_open_block(jsonrpc_stream_open(server, &stream), &stream);
+ error = stream_open_block(jsonrpc_stream_open(server, &stream,
+ DSCP_DEFAULT), &stream);
if (error == EAFNOSUPPORT) {
struct pstream *pstream;
if (error == EAFNOSUPPORT) {
struct pstream *pstream;
- error = jsonrpc_pstream_open(server, &pstream);
+ error = jsonrpc_pstream_open(server, &pstream
, DSCP_DEFAULT
);
if (error) {
ovs_fatal(error, "failed to connect or listen to \"%s\"", server);
}
if (error) {
ovs_fatal(error, "failed to connect or listen to \"%s\"", server);
}
@@
-332,16
+357,12
@@
fetch_schema(struct jsonrpc *rpc, const char *database)
{
struct jsonrpc_msg *request, *reply;
struct ovsdb_schema *schema;
{
struct jsonrpc_msg *request, *reply;
struct ovsdb_schema *schema;
- int error;
request = jsonrpc_create_request("get_schema",
json_array_create_1(
json_string_create(database)),
NULL);
request = jsonrpc_create_request("get_schema",
json_array_create_1(
json_string_create(database)),
NULL);
- error = jsonrpc_transact_block(rpc, request, &reply);
- if (error) {
- ovs_fatal(error, "transaction failed");
- }
+ check_txn(jsonrpc_transact_block(rpc, request, &reply), &reply);
check_ovsdb_error(ovsdb_schema_from_json(reply->result, &schema));
jsonrpc_msg_destroy(reply);
check_ovsdb_error(ovsdb_schema_from_json(reply->result, &schema));
jsonrpc_msg_destroy(reply);
@@
-349,19
+370,15
@@
fetch_schema(struct jsonrpc *rpc, const char *database)
}
static void
}
static void
-fetch_dbs(struct jsonrpc *rpc, struct s
set
*dbs)
+fetch_dbs(struct jsonrpc *rpc, struct s
vec
*dbs)
{
struct jsonrpc_msg *request, *reply;
{
struct jsonrpc_msg *request, *reply;
- int error;
size_t i;
request = jsonrpc_create_request("list_dbs", json_array_create_empty(),
NULL);
size_t i;
request = jsonrpc_create_request("list_dbs", json_array_create_empty(),
NULL);
- error = jsonrpc_transact_block(rpc, request, &reply);
- if (error) {
- ovs_fatal(error, "transaction failed");
- }
+ check_txn(jsonrpc_transact_block(rpc, request, &reply), &reply);
if (reply->result->type != JSON_ARRAY) {
ovs_fatal(0, "list_dbs response is not array");
}
if (reply->result->type != JSON_ARRAY) {
ovs_fatal(0, "list_dbs response is not array");
}
@@
-372,9
+389,10
@@
fetch_dbs(struct jsonrpc *rpc, struct sset *dbs)
if (name->type != JSON_STRING) {
ovs_fatal(0, "list_dbs response %zu is not string", i);
}
if (name->type != JSON_STRING) {
ovs_fatal(0, "list_dbs response %zu is not string", i);
}
- s
set
_add(dbs, name->u.string);
+ s
vec
_add(dbs, name->u.string);
}
jsonrpc_msg_destroy(reply);
}
jsonrpc_msg_destroy(reply);
+ svec_sort(dbs);
}
\f
static void
}
\f
static void
@@
-382,14
+400,15
@@
do_list_dbs(struct jsonrpc *rpc, const char *database OVS_UNUSED,
int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
const char *db_name;
int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
const char *db_name;
- struct sset dbs;
+ struct svec dbs;
+ size_t i;
- s
set
_init(&dbs);
+ s
vec
_init(&dbs);
fetch_dbs(rpc, &dbs);
fetch_dbs(rpc, &dbs);
- S
SET_FOR_EACH (
db_name, &dbs) {
+ S
VEC_FOR_EACH (i,
db_name, &dbs) {
puts(db_name);
}
puts(db_name);
}
- s
set
_destroy(&dbs);
+ s
vec
_destroy(&dbs);
}
static void
}
static void
@@
-475,19
+494,11
@@
do_transact(struct jsonrpc *rpc, const char *database OVS_UNUSED,
{
struct jsonrpc_msg *request, *reply;
struct json *transaction;
{
struct jsonrpc_msg *request, *reply;
struct json *transaction;
- int error;
transaction = parse_json(argv[0]);
request = jsonrpc_create_request("transact", transaction, NULL);
transaction = parse_json(argv[0]);
request = jsonrpc_create_request("transact", transaction, NULL);
- error = jsonrpc_transact_block(rpc, request, &reply);
- if (error) {
- ovs_fatal(error, "transaction failed");
- }
- if (reply->error) {
- ovs_fatal(error, "transaction returned error: %s",
- json_to_string(reply->error, table_style.json_flags));
- }
+ check_txn(jsonrpc_transact_block(rpc, request, &reply), &reply);
print_json(reply->result);
putchar('\n');
jsonrpc_msg_destroy(reply);
print_json(reply->result);
putchar('\n');
jsonrpc_msg_destroy(reply);
@@
-532,6
+543,7
@@
monitor_print(struct json *table_updates,
size_t i;
table_init(&t);
size_t i;
table_init(&t);
+ table_set_timestamp(&t, timestamp);
if (table_updates->type != JSON_OBJECT) {
ovs_error(0, "<table-updates> is not object");
if (table_updates->type != JSON_OBJECT) {
ovs_error(0, "<table-updates> is not object");
@@
-722,12
+734,8
@@
do_monitor(struct jsonrpc *rpc, const char *database,
monitor_print(msg->result, table, &columns, true);
fflush(stdout);
if (get_detach()) {
monitor_print(msg->result, table, &columns, true);
fflush(stdout);
if (get_detach()) {
- /* daemonize() closes the standard file descriptors. We output
- * to stdout, so we need to save and restore STDOUT_FILENO. */
- int fd = dup(STDOUT_FILENO);
+ daemon_save_fd(STDOUT_FILENO);
daemonize();
daemonize();
- dup2(fd, STDOUT_FILENO);
- close(fd);
}
} else if (msg->type == JSONRPC_NOTIFY
&& !strcmp(msg->method, "update")) {
}
} else if (msg->type == JSONRPC_NOTIFY
&& !strcmp(msg->method, "update")) {
@@
-878,10
+886,15
@@
dump_table(const struct ovsdb_table_schema *ts, struct json_array *rows)
struct cell *cell = table_add_cell(&t);
cell->json = ovsdb_datum_to_json(&data[y][x], &columns[x]->type);
cell->type = &columns[x]->type;
struct cell *cell = table_add_cell(&t);
cell->json = ovsdb_datum_to_json(&data[y][x], &columns[x]->type);
cell->type = &columns[x]->type;
+ ovsdb_datum_destroy(&data[y][x], &columns[x]->type);
}
}
+ free(data[y]);
}
table_print(&t, &table_style);
table_destroy(&t);
}
table_print(&t, &table_style);
table_destroy(&t);
+
+ free(data);
+ free(columns);
}
static void
}
static void
@@
-891,7
+904,6
@@
do_dump(struct jsonrpc *rpc, const char *database,
struct jsonrpc_msg *request, *reply;
struct ovsdb_schema *schema;
struct json *transaction;
struct jsonrpc_msg *request, *reply;
struct ovsdb_schema *schema;
struct json *transaction;
- int error;
const struct shash_node **tables;
size_t n_tables;
const struct shash_node **tables;
size_t n_tables;
@@
-928,10
+940,7
@@
do_dump(struct jsonrpc *rpc, const char *database,
/* Send request, get reply. */
request = jsonrpc_create_request("transact", transaction, NULL);
/* Send request, get reply. */
request = jsonrpc_create_request("transact", transaction, NULL);
- error = jsonrpc_transact_block(rpc, request, &reply);
- if (error) {
- ovs_fatal(error, "transaction failed");
- }
+ check_txn(jsonrpc_transact_block(rpc, request, &reply), &reply);
/* Print database contents. */
if (reply->result->type != JSON_ARRAY
/* Print database contents. */
if (reply->result->type != JSON_ARRAY
@@
-954,6
+963,10
@@
do_dump(struct jsonrpc *rpc, const char *database,
dump_table(ts, &rows->u.array);
}
dump_table(ts, &rows->u.array);
}
+
+ jsonrpc_msg_destroy(reply);
+ free(tables);
+ ovsdb_schema_destroy(schema);
}
static void
}
static void