On 01/16/2018 08:11 AM, Richard W.M. Jones wrote:
Mostly code motion.
---
src/Makefile.am | 1 +
src/connections.c | 14 +++----
src/internal.h | 14 ++++---
src/locks.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/plugins.c | 77 +++++-------------------------------
5 files changed, 142 insertions(+), 79 deletions(-)
+++ b/src/locks.c
+void
+lock_connection (void)
+{
+ int thread_model = plugin_thread_model ();
+
+ if (thread_model <= NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS) {
+++ b/src/plugins.c
+int
+plugin_thread_model (void)
+{
+ assert (dl);
+
+ return plugin._thread_model;
+}
The new code asserts dl prior to locking the connection;
+
const char *
plugin_name (void)
{
@@ -312,67 +316,6 @@ plugin_config_complete (void)
exit (EXIT_FAILURE);
}
-/* Handle the thread model. */
-void
-plugin_lock_connection (void)
-{
- if (plugin._thread_model <= NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS) {
- debug ("%s: acquire connection lock", filename);
- pthread_mutex_lock (&connection_lock);
- }
-}
but the old code did not (and just blindly assumed that _thread_model is
always valid). Can that new assertion ever fire during racy unload
sequences?
Otherwise, looks right to me.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization:
qemu.org |
libvirt.org