<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Aug 6, 2020, 16:16 Richard W.M. Jones <<a href="mailto:rjones@redhat.com">rjones@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">See comment in code and<br>
<a href="https://www.redhat.com/archives/libguestfs/2020-August/msg00023.html" rel="noreferrer noreferrer" target="_blank">https://www.redhat.com/archives/libguestfs/2020-August/msg00023.html</a><br>
---<br>
 plugins/vddk/vddk.c | 17 +++++++++++++----<br>
 1 file changed, 13 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c<br>
index c24da96f..5926e181 100644<br>
--- a/plugins/vddk/vddk.c<br>
+++ b/plugins/vddk/vddk.c<br>
@@ -478,11 +478,18 @@ vddk_dump_plugin (void)<br>
 #endif<br>
 }<br>
<br>
-/* XXX To really do threading correctly in accordance with the VDDK<br>
- * documentation, we must do all open/close calls from a single<br>
- * thread.  This is a huge pain.<br>
+/* The rules on threads and VDDK are here:<br>
+ * <a href="https://code.vmware.com/docs/11750/virtual-disk-development-kit-programming-guide/GUID-6BE903E8-DC70-46D9-98E4-E34A2002C2AD.html" rel="noreferrer noreferrer" target="_blank">https://code.vmware.com/docs/11750/virtual-disk-development-kit-programming-guide/GUID-6BE903E8-DC70-46D9-98E4-E34A2002C2AD.html</a><br>
+ *<br>
+ * Before nbdkit 1.22 we used SERIALIZE_ALL_REQUESTS.  Since nbdkit<br>
+ * 1.22 we changed this to SERIALIZE_REQUESTS and added a mutex around<br>
+ * calls to VixDiskLib_Open and VixDiskLib_Close.  This is not quite<br>
+ * within the letter of the rules, but is within the spirit.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">The document is very clear about using the same thread for open an close. Using a lock is not the same.</div><div dir="auto"><br></div><div dir="auto">I think Eric already wrote about this.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  */<br>
-#define THREAD_MODEL NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS<br>
+#define THREAD_MODEL NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS<br>
+<br>
+/* Lock protecting open/close calls - see above. */<br>
+static pthread_mutex_t open_close_lock = PTHREAD_MUTEX_INITIALIZER;<br>
<br>
 /* The per-connection handle. */<br>
 struct vddk_handle {<br>
@@ -524,6 +531,7 @@ free_connect_params (VixDiskLibConnectParams *params)<br>
 static void *<br>
 vddk_open (int readonly)<br>
 {<br>
+  ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&open_close_lock);<br>
   struct vddk_handle *h;<br>
   VixError err;<br>
   uint32_t flags;<br>
@@ -616,6 +624,7 @@ vddk_open (int readonly)<br>
 static void<br>
 vddk_close (void *handle)<br>
 {<br>
+  ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&open_close_lock);<br>
   struct vddk_handle *h = handle;<br>
<br>
   DEBUG_CALL ("VixDiskLib_Close", "handle");<br>
-- <br>
2.27.0<br>
<br>
</blockquote></div></div></div>