From patchwork Mon Apr 12 22:00:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1465454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FK2jj6jRcz9sRK for ; Tue, 13 Apr 2021 08:00:41 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 5463D40525; Mon, 12 Apr 2021 22:00:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HIqkc8iLfsYn; Mon, 12 Apr 2021 22:00:38 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTP id 0EB7D404FE; Mon, 12 Apr 2021 22:00:37 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DF0C3C000F; Mon, 12 Apr 2021 22:00:36 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id EC676C000F for ; Mon, 12 Apr 2021 22:00:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id D437B4052B for ; Mon, 12 Apr 2021 22:00:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Mmta9Mald-9P for ; Mon, 12 Apr 2021 22:00:34 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp4.osuosl.org (Postfix) with ESMTPS id 95597405AA for ; Mon, 12 Apr 2021 22:00:33 +0000 (UTC) X-Originating-IP: 78.45.89.65 Received: from im-t490s.redhat.com (ip-78-45-89-65.net.upcbroadband.cz [78.45.89.65]) (Authenticated sender: i.maximets@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id E2939E0013; Mon, 12 Apr 2021 22:00:30 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Tue, 13 Apr 2021 00:00:14 +0200 Message-Id: <20210412220020.2286954-4-i.maximets@ovn.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210412220020.2286954-1-i.maximets@ovn.org> References: <20210412220020.2286954-1-i.maximets@ovn.org> MIME-Version: 1.0 Cc: Ilya Maximets , Dumitru Ceara Subject: [ovs-dev] [PATCH v2 3/9] uuid: Allow record/replay of generated UUIDs. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This is required for the stream record/replay functionality of ovsdb-server. With record/replay of UUIDs we could record all incoming transactions and replay them later while being sure that ovsdb-server will generate exactly same UUIDs for all the data updates. Signed-off-by: Ilya Maximets Acked-by: Dumitru Ceara --- lib/uuid.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/lib/uuid.c b/lib/uuid.c index 13d20ac64..8a16606da 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -26,11 +26,16 @@ #include "aes128.h" #include "entropy.h" +#include "fatal-signal.h" +#include "openvswitch/vlog.h" +#include "ovs-replay.h" #include "ovs-thread.h" #include "sha1.h" #include "timeval.h" #include "util.h" +VLOG_DEFINE_THIS_MODULE(uuid); + static struct aes128 key; static uint64_t counter[2]; BUILD_ASSERT_DECL(sizeof counter == 16); @@ -54,6 +59,63 @@ uuid_init(void) pthread_once(&once, do_init); } +/* Record/replay of uuid generation. */ +static replay_file_t uuid_replay_file; +static int uuid_replay_seqno; + +static void +uuid_replay_file_close(void *aux OVS_UNUSED) +{ + ovs_replay_file_close(uuid_replay_file); +} + +static void +uuid_replay_file_open(void) +{ + int error; + + ovs_replay_lock(); + error = ovs_replay_file_open("__uuid_generate", &uuid_replay_file, + &uuid_replay_seqno); + ovs_replay_unlock(); + if (error) { + VLOG_FATAL("failed to open uuid replay file: %s.", + ovs_strerror(error)); + } + fatal_signal_add_hook(uuid_replay_file_close, NULL, NULL, true); +} + +static void +uuid_replay_file_read(struct uuid *uuid) +{ + int norm_seqno = ovs_replay_normalized_seqno(uuid_replay_seqno); + int retval, len; + + ovs_replay_lock(); + ovs_assert(norm_seqno == ovs_replay_seqno()); + ovs_assert(ovs_replay_seqno_is_read(uuid_replay_seqno)); + + retval = ovs_replay_read(uuid_replay_file, uuid, sizeof *uuid, + &len, &uuid_replay_seqno, true); + if (retval || len != sizeof *uuid) { + VLOG_FATAL("failed to read from replay file: %s.", + ovs_strerror(retval)); + } + ovs_replay_unlock(); +} + +static void +uuid_replay_file_write(struct uuid *uuid) +{ + int retval; + + retval = ovs_replay_write(uuid_replay_file, uuid, sizeof *uuid, true); + if (retval) { + VLOG_FATAL("failed to write uuid to replay file: %s.", + ovs_strerror(retval)); + } +} + /* Generates a new random UUID in 'uuid'. * * We go to some trouble to ensure as best we can that the generated UUID has @@ -82,10 +144,16 @@ void uuid_generate(struct uuid *uuid) { static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; + enum ovs_replay_state replay_state = ovs_replay_get_state(); uint64_t copy[2]; uuid_init(); + if (replay_state == OVS_REPLAY_READ) { + uuid_replay_file_read(uuid); + return; + } + /* Copy out the counter's current value, then increment it. */ ovs_mutex_lock(&mutex); copy[0] = counter[0]; @@ -99,6 +167,10 @@ uuid_generate(struct uuid *uuid) aes128_encrypt(&key, copy, uuid); uuid_set_bits_v4(uuid); + + if (replay_state == OVS_REPLAY_WRITE) { + uuid_replay_file_write(uuid); + } } struct uuid @@ -276,6 +348,10 @@ do_init(void) uint8_t random_seed[16]; struct timeval now; + if (ovs_replay_is_active()) { + uuid_replay_file_open(); + } + /* Get seed data. */ get_entropy_or_die(random_seed, sizeof random_seed); xgettimeofday(&now);