X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fovsdb-types.c;h=8fe0d4225710b0403bffd6a6afa8add50385f98f;hb=003ce655b7116d18c86a74c50391e54990346931;hp=df18ee54c1341a8793272e6eefcccc9dc11c6135;hpb=bfc96d9b50ae119fcbf39a9511bd9f662e7ad390;p=sliver-openvswitch.git diff --git a/lib/ovsdb-types.c b/lib/ovsdb-types.c index df18ee54c..8fe0d4225 100644 --- a/lib/ovsdb-types.c +++ b/lib/ovsdb-types.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010 Nicira Networks +/* Copyright (c) 2009, 2010, 2011, 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. @@ -22,6 +22,7 @@ #include "dynamic-string.h" #include "json.h" +#include "ovs-thread.h" #include "ovsdb-data.h" #include "ovsdb-error.h" #include "ovsdb-parser.h" @@ -146,10 +147,10 @@ ovsdb_base_type_init(struct ovsdb_base_type *base, enum ovsdb_atomic_type type) break; case OVSDB_N_TYPES: - NOT_REACHED(); + OVS_NOT_REACHED(); default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -158,16 +159,23 @@ ovsdb_base_type_init(struct ovsdb_base_type *base, enum ovsdb_atomic_type type) const struct ovsdb_type * ovsdb_base_type_get_enum_type(enum ovsdb_atomic_type atomic_type) { + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; static struct ovsdb_type *types[OVSDB_N_TYPES]; - if (!types[atomic_type]) { - struct ovsdb_type *type; + if (ovsthread_once_start(&once)) { + enum ovsdb_atomic_type i; - types[atomic_type] = type = xmalloc(sizeof *type); - ovsdb_base_type_init(&type->key, atomic_type); - ovsdb_base_type_init(&type->value, OVSDB_TYPE_VOID); - type->n_min = 1; - type->n_max = UINT_MAX; + for (i = 0; i < OVSDB_N_TYPES; i++) { + struct ovsdb_type *type; + + types[i] = type = xmalloc(sizeof *type); + ovsdb_base_type_init(&type->key, i); + ovsdb_base_type_init(&type->value, OVSDB_TYPE_VOID); + type->n_min = 1; + type->n_max = UINT_MAX; + } + + ovsthread_once_done(&once); } return types[atomic_type]; } @@ -202,7 +210,7 @@ ovsdb_base_type_clone(struct ovsdb_base_type *dst, case OVSDB_N_TYPES: default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -231,10 +239,10 @@ ovsdb_base_type_destroy(struct ovsdb_base_type *base) break; case OVSDB_N_TYPES: - NOT_REACHED(); + OVS_NOT_REACHED(); default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } } @@ -276,7 +284,7 @@ ovsdb_base_type_has_constraints(const struct ovsdb_base_type *base) switch (base->type) { case OVSDB_TYPE_VOID: - NOT_REACHED(); + OVS_NOT_REACHED(); case OVSDB_TYPE_INTEGER: return (base->u.integer.min != INT64_MIN @@ -296,10 +304,10 @@ ovsdb_base_type_has_constraints(const struct ovsdb_base_type *base) return base->u.uuid.refTableName != NULL; case OVSDB_N_TYPES: - NOT_REACHED(); + OVS_NOT_REACHED(); default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -412,10 +420,30 @@ ovsdb_base_type_from_json(struct ovsdb_base_type *base, refTable = ovsdb_parser_member(&parser, "refTable", OP_ID | OP_OPTIONAL); if (refTable) { + const struct json *refType; + base->u.uuid.refTableName = xstrdup(refTable->u.string); + /* We can't set base->u.uuid.refTable here because we don't have * enough context (we might not even be running in ovsdb-server). * ovsdb_create() will set refTable later. */ + + refType = ovsdb_parser_member(&parser, "refType", + OP_ID | OP_OPTIONAL); + if (refType) { + const char *refType_s = json_string(refType); + if (!strcmp(refType_s, "strong")) { + base->u.uuid.refType = OVSDB_REF_STRONG; + } else if (!strcmp(refType_s, "weak")) { + base->u.uuid.refType = OVSDB_REF_WEAK; + } else { + error = ovsdb_syntax_error(json, NULL, "refType must be " + "\"strong\" or \"weak\" (not " + "\"%s\")", refType_s); + } + } else { + base->u.uuid.refType = OVSDB_REF_STRONG; + } } } @@ -453,7 +481,7 @@ ovsdb_base_type_to_json(const struct ovsdb_base_type *base) switch (base->type) { case OVSDB_TYPE_VOID: - NOT_REACHED(); + OVS_NOT_REACHED(); case OVSDB_TYPE_INTEGER: if (base->u.integer.min != INT64_MIN) { @@ -495,14 +523,17 @@ ovsdb_base_type_to_json(const struct ovsdb_base_type *base) if (base->u.uuid.refTableName) { json_object_put_string(json, "refTable", base->u.uuid.refTableName); + if (base->u.uuid.refType == OVSDB_REF_WEAK) { + json_object_put_string(json, "refType", "weak"); + } } break; case OVSDB_N_TYPES: - NOT_REACHED(); + OVS_NOT_REACHED(); default: - NOT_REACHED(); + OVS_NOT_REACHED(); } return json; @@ -533,7 +564,6 @@ ovsdb_type_is_valid(const struct ovsdb_type *type) && ovsdb_base_type_is_valid(&type->key) && ovsdb_base_type_is_valid(&type->value) && type->n_min <= 1 - && type->n_min <= type->n_max && type->n_max >= 1); }