LCOV - code coverage report
Current view: top level - ovsdb - query.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 33 100.0 %
Date: 2016-09-14 01:02:56 Functions: 5 5 100.0 %
Branches: 24 30 80.0 %

           Branch data     Line data    Source code
       1                 :            : /* Copyright (c) 2009, 2010 Nicira, Inc.
       2                 :            :  *
       3                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       4                 :            :  * you may not use this file except in compliance with the License.
       5                 :            :  * You may obtain a copy of the License at:
       6                 :            :  *
       7                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
       8                 :            :  *
       9                 :            :  * Unless required by applicable law or agreed to in writing, software
      10                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      11                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12                 :            :  * See the License for the specific language governing permissions and
      13                 :            :  * limitations under the License.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include <config.h>
      17                 :            : 
      18                 :            : #include "query.h"
      19                 :            : 
      20                 :            : #include "column.h"
      21                 :            : #include "condition.h"
      22                 :            : #include "row.h"
      23                 :            : #include "table.h"
      24                 :            : 
      25                 :            : void
      26                 :      51371 : ovsdb_query(struct ovsdb_table *table, const struct ovsdb_condition *cnd,
      27                 :            :             bool (*output_row)(const struct ovsdb_row *, void *aux), void *aux)
      28                 :            : {
      29         [ +  + ]:      51371 :     if (cnd->n_clauses > 0
      30         [ +  + ]:      50829 :         && cnd->clauses[0].column->index == OVSDB_COL_UUID
      31         [ +  - ]:     100782 :         && cnd->clauses[0].function == OVSDB_F_EQ) {
      32                 :            :         /* Optimize the case where the query has a clause of the form "uuid ==
      33                 :            :          * <some-uuid>", since we have an index on UUID. */
      34                 :            :         const struct ovsdb_row *row;
      35                 :            : 
      36                 :      50391 :         row = ovsdb_table_get_row(table, &cnd->clauses[0].arg.keys[0].uuid);
      37         [ +  + ]:     100772 :         if (row && row->table == table &&
           [ +  -  +  - ]
      38                 :      50381 :             ovsdb_condition_match_every_clause(row, cnd)) {
      39                 :      50381 :             output_row(row, aux);
      40                 :            :         }
      41                 :            :     } else {
      42                 :            :         /* Linear scan. */
      43                 :            :         const struct ovsdb_row *row, *next;
      44                 :            : 
      45 [ +  + ][ -  + ]:       3776 :         HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) {
                 [ +  + ]
      46   [ +  +  +  + ]:       4584 :             if (ovsdb_condition_match_every_clause(row, cnd) &&
      47                 :       1765 :                 !output_row(row, aux)) {
      48                 :         23 :                 break;
      49                 :            :             }
      50                 :            :         }
      51                 :            :     }
      52                 :      51371 : }
      53                 :            : 
      54                 :            : static bool
      55                 :        430 : query_row_set_cb(const struct ovsdb_row *row, void *results_)
      56                 :            : {
      57                 :        430 :     struct ovsdb_row_set *results = results_;
      58                 :        430 :     ovsdb_row_set_add_row(results, row);
      59                 :        430 :     return true;
      60                 :            : }
      61                 :            : 
      62                 :            : void
      63                 :        309 : ovsdb_query_row_set(struct ovsdb_table *table,
      64                 :            :                     const struct ovsdb_condition *condition,
      65                 :            :                     struct ovsdb_row_set *results)
      66                 :            : {
      67                 :        309 :     ovsdb_query(table, condition, query_row_set_cb, results);
      68                 :        309 : }
      69                 :            : 
      70                 :            : static bool
      71                 :       2271 : query_distinct_cb(const struct ovsdb_row *row, void *hash_)
      72                 :            : {
      73                 :       2271 :     struct ovsdb_row_hash *hash = hash_;
      74                 :       2271 :     ovsdb_row_hash_insert(hash, row);
      75                 :       2271 :     return true;
      76                 :            : }
      77                 :            : 
      78                 :            : void
      79                 :       2543 : ovsdb_query_distinct(struct ovsdb_table *table,
      80                 :            :                      const struct ovsdb_condition *condition,
      81                 :            :                      const struct ovsdb_column_set *columns,
      82                 :            :                      struct ovsdb_row_set *results)
      83                 :            : {
      84 [ +  - ][ +  + ]:       2543 :     if (!columns || ovsdb_column_set_contains(columns, OVSDB_COL_UUID)) {
      85                 :            :         /* All the result rows are guaranteed to be distinct anyway. */
      86                 :        309 :         ovsdb_query_row_set(table, condition, results);
      87                 :        309 :         return;
      88                 :            :     } else {
      89                 :            :         /* Use hash table to drop duplicates. */
      90                 :            :         struct ovsdb_row_hash_node *node;
      91                 :            :         struct ovsdb_row_hash hash;
      92                 :            : 
      93                 :       2234 :         ovsdb_row_hash_init(&hash, columns);
      94                 :       2234 :         ovsdb_query(table, condition, query_distinct_cb, &hash);
      95 [ +  + ][ -  + ]:       4478 :         HMAP_FOR_EACH (node, hmap_node, &hash.rows) {
      96                 :       2244 :             ovsdb_row_set_add_row(results, node->row);
      97                 :            :         }
      98                 :       2234 :         ovsdb_row_hash_destroy(&hash, false);
      99                 :            :     }
     100                 :            : }

Generated by: LCOV version 1.12