[ovs-dev,monitor2,v2,2/9] lib: avoid set size check when generating diff datum from json
diff mbox

Message ID 1448403366-21460-2-git-send-email-azhou@ovn.org
State Deferred
Headers show

Commit Message

Andy Zhou Nov. 24, 2015, 10:15 p.m. UTC
From: Andy Zhou <azhou@nicira.com>

Added ovsdb_transient_datum_from_json() to avoid size check for
the diff datum that is transient in nature.
Suppose a datum contains set, and the max number of elements is 2.
If we are changing from set that contains [A, B], to a set contains
[C, D], the diff datum will contains 4 elements [A, B, C, D].

Thus diff datum should not be constrained by the size limit. However
the datum after diff is applied should not violate the size limit.

Signed-off-by: Andy Zhou <azhou@nicira.com>

---
v1->v2:  avoid code duplication by using 'relaxed type' in implementing
         ovsdb_transient_dataum_from_json(), as suggested in code
         review:

         struct ovsdb_type relaxed_type = *type;
         relaxed_type.n_min = 0;
         relaxed_type.n_max = UINT_MAX;
         return ovsdb_datum_from_json(datum,
                                      &relaxed_type, json);
---
 lib/ovsdb-data.c | 19 +++++++++++++++++++
 lib/ovsdb-data.h |  5 +++++
 2 files changed, 24 insertions(+)

Comments

Ben Pfaff Nov. 30, 2015, 2:59 a.m. UTC | #1
On Tue, Nov 24, 2015 at 02:15:59PM -0800, Andy Zhou wrote:
> From: Andy Zhou <azhou@nicira.com>
> 
> Added ovsdb_transient_datum_from_json() to avoid size check for
> the diff datum that is transient in nature.
> Suppose a datum contains set, and the max number of elements is 2.
> If we are changing from set that contains [A, B], to a set contains
> [C, D], the diff datum will contains 4 elements [A, B, C, D].
> 
> Thus diff datum should not be constrained by the size limit. However
> the datum after diff is applied should not violate the size limit.
> 
> Signed-off-by: Andy Zhou <azhou@nicira.com>
> 
> ---
> v1->v2:  avoid code duplication by using 'relaxed type' in implementing
>          ovsdb_transient_dataum_from_json(), as suggested in code
>          review:
> 
>          struct ovsdb_type relaxed_type = *type;
>          relaxed_type.n_min = 0;
>          relaxed_type.n_max = UINT_MAX;
>          return ovsdb_datum_from_json(datum,
>                                       &relaxed_type, json);

Acked-by: Ben Pfaff <blp@ovn.org>

Patch
diff mbox

diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c
index a62e92e..f7d0b06 100644
--- a/lib/ovsdb-data.c
+++ b/lib/ovsdb-data.c
@@ -1268,6 +1268,25 @@  ovsdb_datum_from_json(struct ovsdb_datum *datum,
     return error;
 }
 
+/* Parses 'json' as a datum of the type described by 'type' for internal
+ * use. This function is similar to 'ovsdb_datum_from_json', except the
+ * member size of set or map is not checked.
+ *
+ * The datum generated should be used then discard. It is not suitable
+ * for storing into IDL because of the possible member size violation.  */
+struct ovsdb_error *
+ovsdb_transient_datum_from_json(struct ovsdb_datum *datum,
+                                const struct ovsdb_type *type,
+                                const struct json *json)
+{
+    struct ovsdb_type relaxed_type = *type;
+
+    relaxed_type.n_min = 0;
+    relaxed_type.n_max = UINT_MAX;
+
+    return ovsdb_datum_from_json(datum, &relaxed_type, json, NULL);
+}
+
 /* Converts 'datum', of the specified 'type', to JSON format, and returns the
  * JSON.  The caller is responsible for freeing the returned JSON.
  *
diff --git a/lib/ovsdb-data.h b/lib/ovsdb-data.h
index e144c70..802f718 100644
--- a/lib/ovsdb-data.h
+++ b/lib/ovsdb-data.h
@@ -161,6 +161,11 @@  struct ovsdb_error *ovsdb_datum_from_json(struct ovsdb_datum *,
                                           const struct json *,
                                           struct ovsdb_symbol_table *)
     OVS_WARN_UNUSED_RESULT;
+struct ovsdb_error *ovsdb_transient_datum_from_json(
+                                          struct ovsdb_datum *,
+                                          const struct ovsdb_type *,
+                                          const struct json *)
+    OVS_WARN_UNUSED_RESULT;
 struct json *ovsdb_datum_to_json(const struct ovsdb_datum *,
                                  const struct ovsdb_type *);