replay: introduce mutex to protect the replay log
authorPavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
Thu, 17 Sep 2015 16:23:48 +0000 (19:23 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 5 Nov 2015 11:19:09 +0000 (12:19 +0100)
This mutex will protect read/write operations for replay log.
Using mutex is necessary because most of the events consist of
several fields stored in the log. The mutex will help to avoid races.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Message-Id: <20150917162348.8676.8628.stgit@PASHA-ISP.def.inno>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
replay/replay-internal.c
replay/replay-internal.h

index 04efeee920498f686c01ede0a25587938ceaa1e3..efae672dfa57d57c89e21ecb715b3fa73470ecb7 100644 (file)
 unsigned int replay_data_kind = -1;
 static unsigned int replay_has_unread_data;
 
+/* Mutex to protect reading and writing events to the log.
+   replay_data_kind and replay_has_unread_data are also protected
+   by this mutex.
+   It also protects replay events queue which stores events to be
+   written or read to the log. */
+static QemuMutex lock;
+
 /* File for replay writing */
 FILE *replay_file;
 
@@ -153,3 +160,23 @@ void replay_finish_event(void)
     replay_has_unread_data = 0;
     replay_fetch_data_kind();
 }
+
+void replay_mutex_init(void)
+{
+    qemu_mutex_init(&lock);
+}
+
+void replay_mutex_destroy(void)
+{
+    qemu_mutex_destroy(&lock);
+}
+
+void replay_mutex_lock(void)
+{
+    qemu_mutex_lock(&lock);
+}
+
+void replay_mutex_unlock(void)
+{
+    qemu_mutex_unlock(&lock);
+}
index 17600deff99ef1c3131d9218753a537739c63ab9..8a0de0d8d8b4e19d50e2a96be88253063fceacf4 100644 (file)
@@ -33,6 +33,13 @@ int64_t replay_get_qword(void);
 void replay_get_array(uint8_t *buf, size_t *size);
 void replay_get_array_alloc(uint8_t **buf, size_t *size);
 
+/* Mutex functions for protecting replay log file */
+
+void replay_mutex_init(void);
+void replay_mutex_destroy(void);
+void replay_mutex_lock(void);
+void replay_mutex_unlock(void);
+
 /*! Checks error status of the file. */
 void replay_check_error(void);