---
plugins/vddk/worker.c | 67 ++++++++++++++++++++++++-------------------
1 file changed, 38 insertions(+), 29 deletions(-)
diff --git a/plugins/vddk/worker.c b/plugins/vddk/worker.c
index 4bb7d8d7..a8ffc23e 100644
--- a/plugins/vddk/worker.c
+++ b/plugins/vddk/worker.c
@@ -305,9 +305,12 @@ do_flush (struct command *cmd)
return 0;
}
+static pthread_mutex_t extents_test_lock = PTHREAD_MUTEX_INITIALIZER;
+
static int
do_can_extents (struct command *cmd)
{
+ static int extents_test = -1;
VixError err;
VixDiskLibBlockList *block_list;
@@ -320,41 +323,47 @@ do_can_extents (struct command *cmd)
return 0;
}
- /* Suppress errors around this call. See:
- *
https://bugzilla.redhat.com/show_bug.cgi?id=1709211#c7
- */
- error_suppression = 1;
-
/* However even when the call is available it rarely works well so
* the best thing we can do here is to try the call and if it's
* non-functional return false.
*/
- VDDK_CALL_START (VixDiskLib_QueryAllocatedBlocks,
- "handle, 0, %d sectors, %d sectors",
- VIXDISKLIB_MIN_CHUNK_SIZE, VIXDISKLIB_MIN_CHUNK_SIZE)
- err = VixDiskLib_QueryAllocatedBlocks (handle,
- 0, VIXDISKLIB_MIN_CHUNK_SIZE,
- VIXDISKLIB_MIN_CHUNK_SIZE,
- &block_list);
- VDDK_CALL_END (VixDiskLib_QueryAllocatedBlocks, 0);
- error_suppression = 0;
- if (err == VIX_OK) {
- VDDK_CALL_START (VixDiskLib_FreeBlockList, "block_list")
- VixDiskLib_FreeBlockList (block_list);
- VDDK_CALL_END (VixDiskLib_FreeBlockList, 0);
- }
- if (err != VIX_OK) {
- char *errmsg = VixDiskLib_GetErrorText (err, NULL);
- nbdkit_debug ("can_extents: "
- "VixDiskLib_QueryAllocatedBlocks test failed, "
- "extents support will be disabled: "
- "original error: %s",
- errmsg);
- VixDiskLib_FreeErrorText (errmsg);
- return 0;
+ ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&extents_test_lock);
+ if (extents_test == -1) {
+ /* Suppress errors around this call. See:
+ *
https://bugzilla.redhat.com/show_bug.cgi?id=1709211#c7
+ */
+ error_suppression = 1;
+
+ VDDK_CALL_START (VixDiskLib_QueryAllocatedBlocks,
+ "handle, 0, %d sectors, %d sectors",
+ VIXDISKLIB_MIN_CHUNK_SIZE, VIXDISKLIB_MIN_CHUNK_SIZE)
+ err = VixDiskLib_QueryAllocatedBlocks (handle,
+ 0, VIXDISKLIB_MIN_CHUNK_SIZE,
+ VIXDISKLIB_MIN_CHUNK_SIZE,
+ &block_list);
+ VDDK_CALL_END (VixDiskLib_QueryAllocatedBlocks, 0);
+ error_suppression = 0;
+ if (err == VIX_OK) {
+ VDDK_CALL_START (VixDiskLib_FreeBlockList, "block_list")
+ VixDiskLib_FreeBlockList (block_list);
+ VDDK_CALL_END (VixDiskLib_FreeBlockList, 0);
+
+ extents_test = 1; /* result = good */
+ }
+ else {
+ char *errmsg = VixDiskLib_GetErrorText (err, NULL);
+ nbdkit_debug ("can_extents: "
+ "VixDiskLib_QueryAllocatedBlocks test failed, "
+ "extents support will be disabled: "
+ "original error: %s",
+ errmsg);
+ VixDiskLib_FreeErrorText (errmsg);
+
+ extents_test = 0; /* result = bad */
+ }
}
- return 1;
+ return extents_test;
}
/* Add an extent to the list of extents. */
--
2.32.0