From patchwork Thu Oct 22 04:45:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 534199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 7B89A140157 for ; Thu, 22 Oct 2015 15:45:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nicira_com.20150623.gappssmtp.com header.i=@nicira_com.20150623.gappssmtp.com header.b=IcVudZur; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 2E0821075C; Wed, 21 Oct 2015 21:45:48 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 6DB0A10759 for ; Wed, 21 Oct 2015 21:45:46 -0700 (PDT) Received: from bar3.cudamail.com (bar1 [192.168.15.1]) by mx3v1.cudamail.com (Postfix) with ESMTP id E0F876182B7 for ; Wed, 21 Oct 2015 22:45:44 -0600 (MDT) X-ASG-Debug-ID: 1445489144-03dd7b105e1aca10001-byXFYA Received: from mx3-pf3.cudamail.com ([192.168.14.3]) by bar3.cudamail.com with ESMTP id zDKw2do7n1w1FZrV (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 21 Oct 2015 22:45:44 -0600 (MDT) X-Barracuda-Envelope-From: azhou@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.3 Received: from unknown (HELO mail-wi0-f182.google.com) (209.85.212.182) by mx3-pf3.cudamail.com with ESMTPS (RC4-SHA encrypted); 22 Oct 2015 04:45:43 -0000 Received-SPF: unknown (mx3-pf3.cudamail.com: Multiple SPF records returned) X-Barracuda-Apparent-Source-IP: 209.85.212.182 X-Barracuda-RBL-IP: 209.85.212.182 Received: by wijp11 with SMTP id p11so13492591wij.0 for ; Wed, 21 Oct 2015 21:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nicira_com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cVLuSlarhvSUQEq68UruMA95oc6KPHR0UFaNsmGQw4w=; b=IcVudZur1wvvzlLTVy/5ShO/VJ4eY/f7Z7mceosrXY61ToKvAgh+VZ0OGOw7ueE0Q+ M6tb7Y/xpxwaGM9Cz7RIMdjmA3DIfqQM/E8MyM7rJKUQ0jgWJ3kCDkKhJIPZe0nyRw4A 1eu/T2O0UdwQKZt7s6sRM/xJTOifE7F3rQKvrUx9P+03muX3BlUX58KXr+S0tEVWiB+A pwQd8EvGm3p0LDdNQLsMBXN42h0sMEbXRGe2jOCzKmXDyUxtN3m2BT9jlsOpQO9Cuql0 3M9WuLz5PeLXUtdensTWQdre4diZaboDZSafB33LbXQS4XuJ37Xxhsfqr/HpUnW029Wp pNCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cVLuSlarhvSUQEq68UruMA95oc6KPHR0UFaNsmGQw4w=; b=ZMbJ0SebDxTtNswrEj48sbvVlb0cFlt6f9c1yx+ngEQZ+C6KJUjyaXVx2fmWuDxWRJ nfra89QBStu/vWi2NxcboHEXzxR+7kkgRuEf4fvI+nQEvHUCYk/E7R9KNJVQ/W4xzNwi tUP2T+TP3UhRw0H9uxKrOsxt5uPeF4gsLpFb7tEDe0H0lkt7PIFrni50uq7VYBCQpwxM 6DJ5mtJY+j4Rk06JyRmuU9Ha5923pvGA/lvvBgr0csMUXQ2Zby/d/7DkW61PxCYY7UJo e5Or9n6is3ZmAV4ibjAYBpB9Q3Te7YP4j1oXUbKtzc7G7WtqlYe6NQxB88Ws0SlG1YkG 2raw== X-Gm-Message-State: ALoCoQlQFzXBjGn7lkyF+7/9VKFQqNh0RBZxtnPQqlOhYScUMpMVVKVwNY7JpquSggHnRPQqhoct X-Received: by 10.180.198.233 with SMTP id jf9mr32259695wic.66.1445489141960; Wed, 21 Oct 2015 21:45:41 -0700 (PDT) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id s16sm26389112wik.16.2015.10.21.21.45.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Oct 2015 21:45:41 -0700 (PDT) X-CudaMail-Envelope-Sender: azhou@nicira.com From: Andy Zhou To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V3-1020077421 X-CudaMail-DTE: 102115 X-CudaMail-Originating-IP: 209.85.212.182 Date: Wed, 21 Oct 2015 21:45:24 -0700 X-ASG-Orig-Subj: [##CM-V3-1020077421##][mointor2 2/9] lib: avoid set size check when generating diff datum from json Message-Id: <1445489131-21483-2-git-send-email-azhou@nicira.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445489131-21483-1-git-send-email-azhou@nicira.com> References: <1445489131-21483-1-git-send-email-azhou@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.14.3] X-Barracuda-Start-Time: 1445489144 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [mointor2 2/9] lib: avoid set size check when generating diff datum from json X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" 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 --- lib/ovsdb-data.c | 32 +++++++++++++++++++++++++++++--- lib/ovsdb-data.h | 5 +++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index a62e92e..592e9ed 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -1158,7 +1158,8 @@ static struct ovsdb_error * ovsdb_datum_from_json__(struct ovsdb_datum *datum, const struct ovsdb_type *type, const struct json *json, - struct ovsdb_symbol_table *symtab) + struct ovsdb_symbol_table *symtab, + bool check_size) { struct ovsdb_error *error; @@ -1179,7 +1180,7 @@ ovsdb_datum_from_json__(struct ovsdb_datum *datum, } n = inner->u.array.n; - if (n < type->n_min || n > type->n_max) { + if (check_size && (n < type->n_min || n > type->n_max)) { return ovsdb_syntax_error(json, NULL, "%s must have %u to " "%u members but %"PRIuSIZE" are present", class, type->n_min, type->n_max, n); @@ -1256,7 +1257,32 @@ ovsdb_datum_from_json(struct ovsdb_datum *datum, { struct ovsdb_error *error; - error = ovsdb_datum_from_json__(datum, type, json, symtab); + error = ovsdb_datum_from_json__(datum, type, json, symtab, true); + if (error) { + return error; + } + + error = ovsdb_datum_sort(datum, type->key.type); + if (error) { + ovsdb_datum_destroy(datum, type); + } + 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_error *error; + + error = ovsdb_datum_from_json__(datum, type, json, NULL, false); if (error) { return error; } 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 *);