[ovs-dev] [PATCH 1/3 v1] ovsdb-server: Store databases in shash instead of array.

Gurucharan Shetty shettyg at nicira.com
Tue Jun 25 21:40:38 UTC 2013


On Tue, Jun 25, 2013 at 2:16 PM, Ben Pfaff <blp at nicira.com> wrote:

> On Tue, Jun 25, 2013 at 01:02:30AM -0700, Gurucharan Shetty wrote:
> > An upcoming commit provides the ability to add and remove databases.
> > Having the databases in a shash instead of an array makes it easier
> > to add and remove databases.
> >
> > Feature #14595.
> > Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
>
> ovsdb_server_compact() checks for db->filename == NULL.  When does
> this happen?
>
> I will get rid of it. I don't see it happening.


> I'd prefer to declare the various 'db' variables in innermost blocks
> where we can.  If you agree, I've appended an incremental you can fold
> in, that shows what I mean.
>
> Acked-by: Ben Pfaff <blp at nicira.com>
>
> Thanks, I will fold in the incremental.


> diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
> index 4eab6b5..949ff94 100644
> --- a/ovsdb/ovsdb-server.c
> +++ b/ovsdb/ovsdb-server.c
> @@ -126,7 +126,6 @@ main(int argc, char *argv[])
>      struct remove_remote_aux remove_remote_aux;
>      FILE *config_tmpfile;
>
> -    struct db *db;
>      struct shash all_dbs;
>      struct shash_node *node;
>      int i;
> @@ -160,12 +159,12 @@ main(int argc, char *argv[])
>
>      if (argc > 0) {
>          for (i = 0; i < argc; i++) {
> -            db = xzalloc(sizeof *db);
> +            struct db *db = xzalloc(sizeof *db);
>              db->filename = argv[i];
>              open_db(jsonrpc, db, &all_dbs);
>           }
>      } else {
> -        db = xzalloc(sizeof *db);
> +        struct db *db = xzalloc(sizeof *db);
>          db->filename = xasprintf("%s/conf.db", ovs_dbdir());
>          open_db(jsonrpc, db, &all_dbs);
>      }
> @@ -231,7 +230,7 @@ main(int argc, char *argv[])
>              simap_init(&usage);
>              ovsdb_jsonrpc_server_get_memory_usage(jsonrpc, &usage);
>              SHASH_FOR_EACH(node, &all_dbs) {
> -                db = node->data;
> +                struct db *db = node->data;
>                  ovsdb_get_memory_usage(db->db, &usage);
>              }
>              memory_report(&usage);
> @@ -247,7 +246,7 @@ main(int argc, char *argv[])
>          ovsdb_jsonrpc_server_run(jsonrpc);
>
>          SHASH_FOR_EACH(node, &all_dbs) {
> -            db = node->data;
> +            struct db *db = node->data;
>              ovsdb_trigger_run(db->db, time_msec());
>          }
>          if (run_process) {
> @@ -267,7 +266,7 @@ main(int argc, char *argv[])
>          ovsdb_jsonrpc_server_wait(jsonrpc);
>          unixctl_server_wait(unixctl);
>          SHASH_FOR_EACH(node, &all_dbs) {
> -            db = node->data;
> +            struct db *db = node->data;
>              ovsdb_trigger_wait(db->db, time_msec());
>          }
>          if (run_process) {
> @@ -281,7 +280,7 @@ main(int argc, char *argv[])
>      }
>      ovsdb_jsonrpc_server_destroy(jsonrpc);
>      SHASH_FOR_EACH(node, &all_dbs) {
> -        db = node->data;
> +        struct db *db = node->data;
>          ovsdb_destroy(db->db);
>      }
>      sset_destroy(&remotes);
> @@ -322,10 +321,9 @@ static const struct db *
>  find_db(const struct shash *all_dbs, const char *db_name)
>  {
>      struct shash_node *node;
> -    struct db *db;
>
>      SHASH_FOR_EACH(node, all_dbs) {
> -        db = node->data;
> +        struct db *db = node->data;
>          if (!strcmp(db->db->schema->name, db_name)) {
>              return db;
>          }
>
> Thanks,
>
> Ben.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20130625/4d76376a/attachment-0003.html>


More information about the dev mailing list