From patchwork Mon Jun 27 13:32:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Schour X-Patchwork-Id: 641021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3rdVJp1WrRz9t1L for ; Mon, 27 Jun 2016 23:34:02 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id AE4E310C2C; Mon, 27 Jun 2016 06:33:37 -0700 (PDT) X-Original-To: dev@openvswitch.com Delivered-To: dev@openvswitch.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by archives.nicira.com (Postfix) with ESMTPS id 5F62210BCF for ; Mon, 27 Jun 2016 06:33:33 -0700 (PDT) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5RDSeUo013294 for ; Mon, 27 Jun 2016 09:33:32 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 23sjug9j6q-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Jun 2016 09:33:32 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Jun 2016 14:33:30 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Jun 2016 14:33:28 +0100 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: lirans@il.ibm.com X-IBM-RcptTo: dev@openvswitch.com Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 87A5317D805F for ; Mon, 27 Jun 2016 14:34:46 +0100 (BST) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5RDXRhw44171368 for ; Mon, 27 Jun 2016 13:33:27 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u5RDXRBH023515 for ; Mon, 27 Jun 2016 07:33:27 -0600 Received: from il.ibm.com (goku.haifa.ibm.com [9.148.28.190]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u5RDXPQN023370; Mon, 27 Jun 2016 07:33:26 -0600 From: Liran Schour To: Ben Pfaff Date: Mon, 27 Jun 2016 16:32:56 +0300 X-Mailer: git-send-email 2.1.4 In-Reply-To: <1467034384-21298-1-git-send-email-lirans@il.ibm.com> References: <1467034384-21298-1-git-send-email-lirans@il.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062713-0016-0000-0000-000002004D20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062713-0017-0000-0000-0000221069C9 Message-Id: <1467034384-21298-4-git-send-email-lirans@il.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-27_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606270145 Cc: dev@openvswitch.com Subject: [ovs-dev] [PATCH monitor_cond V8 03/11] ovsdb: allow unmonitored columns in condition evaluation 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" This commit allows to add unmonitored columns to a monitored table due to condition update. It will be used to evaluate conditions on unmonitored columns. Update notification includes only monitored columns. Due to the limited number of columns, we do not remove unused unmonitored columns on condition update for code simplicity. Signed-off-by: Liran Schour --- ovsdb/jsonrpc-server.c | 23 +++++++++++------------ ovsdb/monitor.c | 34 ++++++++++++++++++++++++---------- ovsdb/monitor.h | 2 +- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 208027a..3a69a85 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -1093,8 +1093,7 @@ parse_bool(struct ovsdb_parser *parser, const char *name, bool default_value) static struct ovsdb_error * OVS_WARN_UNUSED_RESULT ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_monitor *dbmon, const struct ovsdb_table *table, - const struct json *monitor_request, - size_t *allocated_columns) + const struct json *monitor_request) { const struct ovsdb_table_schema *ts = table->schema; enum ovsdb_monitor_selection select; @@ -1158,8 +1157,8 @@ ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_monitor *dbmon, return ovsdb_syntax_error(columns, NULL, "%s is not a valid " "column name", s); } - if (ovsdb_monitor_add_column(dbmon, table, column, select, - allocated_columns)) { + if (ovsdb_monitor_add_column(dbmon, table, column, + select, true)) { return ovsdb_syntax_error(columns, NULL, "column %s " "mentioned more than once", column->name); @@ -1171,8 +1170,8 @@ ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_monitor *dbmon, SHASH_FOR_EACH (node, &ts->columns) { const struct ovsdb_column *column = node->data; if (column->index != OVSDB_COL_UUID) { - if (ovsdb_monitor_add_column(dbmon, table, column, select, - allocated_columns)) { + if (ovsdb_monitor_add_column(dbmon, table, column, + select, true)) { return ovsdb_syntax_error(columns, NULL, "column %s " "mentioned more than once", column->name); @@ -1225,7 +1224,6 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db, SHASH_FOR_EACH (node, json_object(monitor_requests)) { const struct ovsdb_table *table; - size_t allocated_columns; const struct json *mr_value; size_t i; @@ -1240,20 +1238,21 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db, /* Parse columns. */ mr_value = node->data; - allocated_columns = 0; if (mr_value->type == JSON_ARRAY) { const struct json_array *array = &mr_value->u.array; for (i = 0; i < array->n; i++) { - error = ovsdb_jsonrpc_parse_monitor_request( - m->dbmon, table, array->elems[i], &allocated_columns); + error = ovsdb_jsonrpc_parse_monitor_request(m->dbmon, + table, + array->elems[i]); if (error) { goto error; } } } else { - error = ovsdb_jsonrpc_parse_monitor_request( - m->dbmon, table, mr_value, &allocated_columns); + error = ovsdb_jsonrpc_parse_monitor_request(m->dbmon, + table, + mr_value); if (error) { goto error; } diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index 1e334d2..5228a0a 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -75,6 +75,7 @@ struct jsonrpc_monitor_node { struct ovsdb_monitor_column { const struct ovsdb_column *column; enum ovsdb_monitor_selection select; + bool monitored; }; /* A row that has changed in a monitored table. */ @@ -115,6 +116,8 @@ struct ovsdb_monitor_table { /* Columns being monitored. */ struct ovsdb_monitor_column *columns; size_t n_columns; + size_t n_monitored_columns; + size_t allocated_columns; /* Columns in ovsdb_monitor_row have different indexes then in * ovsdb_row. This field maps between column->index to the index in the @@ -202,6 +205,11 @@ compare_ovsdb_monitor_column(const void *a_, const void *b_) const struct ovsdb_monitor_column *a = a_; const struct ovsdb_monitor_column *b = b_; + /* put all monitored columns at the begining */ + if (a->monitored != b->monitored) { + return a->monitored ? -1 : 1; + } + return a->column < b->column ? -1 : a->column > b->column; } @@ -383,7 +391,7 @@ ovsdb_monitor_add_column(struct ovsdb_monitor *dbmon, const struct ovsdb_table *table, const struct ovsdb_column *column, enum ovsdb_monitor_selection select, - size_t *allocated_columns) + bool monitored) { struct ovsdb_monitor_table *mt; struct ovsdb_monitor_column *c; @@ -395,8 +403,8 @@ ovsdb_monitor_add_column(struct ovsdb_monitor *dbmon, return column->name; } - if (mt->n_columns >= *allocated_columns) { - mt->columns = x2nrealloc(mt->columns, allocated_columns, + if (mt->n_columns >= mt->allocated_columns) { + mt->columns = x2nrealloc(mt->columns, &mt->allocated_columns, sizeof *mt->columns); } @@ -405,6 +413,10 @@ ovsdb_monitor_add_column(struct ovsdb_monitor *dbmon, c = &mt->columns[mt->n_columns++]; c->column = column; c->select = select; + c->monitored = monitored; + if (monitored) { + mt->n_monitored_columns++; + } return NULL; } @@ -561,10 +573,10 @@ ovsdb_monitor_compose_row_update( new_json = json_object_create(); json_object_put(row_json, "new", new_json); } - for (i = 0; i < mt->n_columns; i++) { + for (i = 0; i < mt->n_monitored_columns; i++) { const struct ovsdb_monitor_column *c = &mt->columns[i]; - if (!(type & c->select)) { + if (!c->monitored || !(type & c->select)) { /* We don't care about this type of change for this * particular column (but we will care about it for some * other column). */ @@ -618,10 +630,10 @@ ovsdb_monitor_compose_row_update2( diff_json = json_object_create(); const char *op; - for (i = 0; i < mt->n_columns; i++) { + for (i = 0; i < mt->n_monitored_columns; i++) { const struct ovsdb_monitor_column *c = &mt->columns[i]; - if (!(type & c->select)) { + if (!c->monitored || !(type & c->select)) { /* We don't care about this type of change for this * particular column (but we will care about it for some * other column). */ @@ -1011,19 +1023,21 @@ ovsdb_monitor_table_equal(const struct ovsdb_monitor_table *a, { size_t i; + ovs_assert(b->n_columns == b->n_monitored_columns); + if ((a->table != b->table) || (a->select != b->select) || - (a->n_columns != b->n_columns)) { + (a->n_monitored_columns != b->n_monitored_columns)) { return false; } - for (i = 0; i < a->n_columns; i++) { + /* Compare only monitored columns that must be sorted already */ + for (i = 0; i < a->n_monitored_columns; i++) { if ((a->columns[i].column != b->columns[i].column) || (a->columns[i].select != b->columns[i].select)) { return false; } } - return true; } diff --git a/ovsdb/monitor.h b/ovsdb/monitor.h index 45432c4..83dba0d 100644 --- a/ovsdb/monitor.h +++ b/ovsdb/monitor.h @@ -56,7 +56,7 @@ const char * ovsdb_monitor_add_column(struct ovsdb_monitor *dbmon, const struct ovsdb_table *table, const struct ovsdb_column *column, enum ovsdb_monitor_selection select, - size_t *allocated_columns); + bool monitored); struct json *ovsdb_monitor_get_update(struct ovsdb_monitor *dbmon, bool initial,