From: Ben Pfaff Date: Mon, 11 Jan 2010 21:14:54 +0000 (-0800) Subject: ovsdb: Save some space in the log for newly inserted records. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c532bf9dd4e684bc583debc9618e3210334f8081;p=openvswitch ovsdb: Save some space in the log for newly inserted records. When a new record is inserted into a database, ovsdb logs the values of all of the fields in the record. However, often new records have many columns that contain default values. There is no need to log those values, so this commit causes them to be omitted. As a side effect, this also makes "ovsdb-tool show-log --more --more" output easier to read, because record insertions print less noise. (Adding --more --more to this command makes it print changes to database records. The --more option will be introduced in an upcoming commit.) --- diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 0d7749b1..65fd43e6 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009 Nicira Networks +/* Copyright (c) 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,6 +65,35 @@ ovsdb_atom_init_default(union ovsdb_atom *atom, enum ovsdb_atomic_type type) } } +bool +ovsdb_atom_is_default(const union ovsdb_atom *atom, + enum ovsdb_atomic_type type) +{ + switch (type) { + case OVSDB_TYPE_VOID: + NOT_REACHED(); + + case OVSDB_TYPE_INTEGER: + return atom->integer == 0; + + case OVSDB_TYPE_REAL: + return atom->real == 0.0; + + case OVSDB_TYPE_BOOLEAN: + return atom->boolean == false; + + case OVSDB_TYPE_STRING: + return atom->string[0] == '\0'; + + case OVSDB_TYPE_UUID: + return uuid_is_zero(&atom->uuid); + + case OVSDB_N_TYPES: + default: + NOT_REACHED(); + } +} + void ovsdb_atom_clone(union ovsdb_atom *new, const union ovsdb_atom *old, enum ovsdb_atomic_type type) @@ -351,6 +380,28 @@ ovsdb_datum_init_default(struct ovsdb_datum *datum, datum->values = alloc_default_atoms(type->value_type, datum->n); } +bool +ovsdb_datum_is_default(const struct ovsdb_datum *datum, + const struct ovsdb_type *type) +{ + size_t i; + + if (datum->n != type->n_min) { + return false; + } + for (i = 0; i < datum->n; i++) { + if (!ovsdb_atom_is_default(&datum->keys[i], type->key_type)) { + return false; + } + if (type->value_type != OVSDB_TYPE_VOID + && !ovsdb_atom_is_default(&datum->values[i], type->value_type)) { + return false; + } + } + + return true; +} + static union ovsdb_atom * clone_atoms(const union ovsdb_atom *old, enum ovsdb_atomic_type type, size_t n) { diff --git a/lib/ovsdb-data.h b/lib/ovsdb-data.h index 3f2d4894..18b8841c 100644 --- a/lib/ovsdb-data.h +++ b/lib/ovsdb-data.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2009 Nicira Networks +/* Copyright (c) 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ union ovsdb_atom { }; void ovsdb_atom_init_default(union ovsdb_atom *, enum ovsdb_atomic_type); +bool ovsdb_atom_is_default(const union ovsdb_atom *, enum ovsdb_atomic_type); void ovsdb_atom_clone(union ovsdb_atom *, const union ovsdb_atom *, enum ovsdb_atomic_type); void ovsdb_atom_swap(union ovsdb_atom *, union ovsdb_atom *); @@ -80,6 +81,8 @@ struct ovsdb_datum { }; void ovsdb_datum_init_default(struct ovsdb_datum *, const struct ovsdb_type *); +bool ovsdb_datum_is_default(const struct ovsdb_datum *, + const struct ovsdb_type *); void ovsdb_datum_clone(struct ovsdb_datum *, const struct ovsdb_datum *, const struct ovsdb_type *); void ovsdb_datum_destroy(struct ovsdb_datum *, const struct ovsdb_type *); diff --git a/lib/uuid.c b/lib/uuid.c index 264d9bf5..620c039c 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2009 Nicira Networks +/* Copyright (c) 2008, 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -107,6 +107,14 @@ uuid_zero(struct uuid *uuid) uuid->parts[0] = uuid->parts[1] = uuid->parts[2] = uuid->parts[3] = 0; } +/* Returns true if 'uuid' is all zero, otherwise false. */ +bool +uuid_is_zero(const struct uuid *uuid) +{ + return (!uuid->parts[0] && !uuid->parts[1] + && !uuid->parts[2] && !uuid->parts[3]); +} + /* Compares 'a' and 'b'. Returns a negative value if 'a < b', zero if 'a == * b', or positive if 'a > b'. The ordering is lexicographical order of the * conventional way of writing out UUIDs as strings. */ diff --git a/lib/uuid.h b/lib/uuid.h index 5dcaa25d..1059c26d 100644 --- a/lib/uuid.h +++ b/lib/uuid.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2009 Nicira Networks +/* Copyright (c) 2008, 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,6 +74,7 @@ uuid_equals(const struct uuid *a, const struct uuid *b) void uuid_init(void); void uuid_generate(struct uuid *); void uuid_zero(struct uuid *); +bool uuid_is_zero(const struct uuid *); int uuid_compare_3way(const struct uuid *, const struct uuid *); bool uuid_from_string(struct uuid *, const char *); diff --git a/ovsdb/file.c b/ovsdb/file.c index 97359d03..716ea89c 100644 --- a/ovsdb/file.c +++ b/ovsdb/file.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009 Nicira Networks +/* Copyright (c) 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -261,8 +261,10 @@ ovsdb_file_replica_change_cb(const struct ovsdb_row *old, unsigned int idx = column->index; if (idx != OVSDB_COL_UUID && column->persistent - && (!old || !ovsdb_datum_equals(&old->fields[idx], - &new->fields[idx], type))) + && (old + ? !ovsdb_datum_equals(&old->fields[idx], &new->fields[idx], + type) + : !ovsdb_datum_is_default(&new->fields[idx], type))) { if (!row) { row = json_object_create();