Blame SOURCES/0003-vddk-Simplify-and-consolidate-VDDK_CALL_START-END-ma.patch

5c4a8e
From cbcf2a2f158a9889bd597b31159ab357dea05cd6 Mon Sep 17 00:00:00 2001
5c4a8e
From: "Richard W.M. Jones" <rjones@redhat.com>
5c4a8e
Date: Thu, 21 Oct 2021 22:55:17 +0100
5c4a8e
Subject: [PATCH] vddk: Simplify and consolidate VDDK_CALL_START/END macros
5c4a8e
5c4a8e
We don't need the VDDK_CALL_*_DATAPATH versions of these macros
5c4a8e
because the compiler is able to optimize some static strcmps.
5c4a8e
Furthermore we can remove extra { .. } when the macros are applied.
5c4a8e
5c4a8e
(cherry picked from commit 3ea0ed6582faa8f800b7a2a15d58032917a21bd5)
5c4a8e
---
5c4a8e
 plugins/vddk/vddk.c | 124 ++++++++++++++++++++------------------------
5c4a8e
 1 file changed, 56 insertions(+), 68 deletions(-)
5c4a8e
5c4a8e
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c
5c4a8e
index 5f1d223b..993f2d76 100644
5c4a8e
--- a/plugins/vddk/vddk.c
5c4a8e
+++ b/plugins/vddk/vddk.c
5c4a8e
@@ -125,28 +125,16 @@ static void display_stats (void);
5c4a8e
 #define VDDK_CALL_START(fn, fs, ...)                                    \
5c4a8e
   do {                                                                  \
5c4a8e
   struct timeval start_t, end_t;                                        \
5c4a8e
+  /* GCC can optimize this away at compile time: */                     \
5c4a8e
+  const bool datapath =                                                 \
5c4a8e
+    strcmp (#fn, "VixDiskLib_Read") == 0 ||                             \
5c4a8e
+    strcmp (#fn, "VixDiskLib_Write") == 0;                              \
5c4a8e
   if (vddk_debug_stats)                                                 \
5c4a8e
     gettimeofday (&start_t, NULL);                                      \
5c4a8e
-  nbdkit_debug ("VDDK call: %s (" fs ")", #fn, ##__VA_ARGS__);          \
5c4a8e
-  do
5c4a8e
-#define VDDK_CALL_START_DATAPATH(fn, fs, ...)                           \
5c4a8e
-  do {                                                                  \
5c4a8e
-  struct timeval start_t, end_t;                                        \
5c4a8e
-  if (vddk_debug_stats)                                                 \
5c4a8e
-    gettimeofday (&start_t, NULL);                                      \
5c4a8e
-  if (vddk_debug_datapath)                                              \
5c4a8e
+  if (!datapath || vddk_debug_datapath)                                 \
5c4a8e
     nbdkit_debug ("VDDK call: %s (" fs ")", #fn, ##__VA_ARGS__);        \
5c4a8e
   do
5c4a8e
-#define VDDK_CALL_END(fn)                               \
5c4a8e
-  while (0);                                            \
5c4a8e
-  if (vddk_debug_stats) {                               \
5c4a8e
-    gettimeofday (&end_t, NULL);                        \
5c4a8e
-    ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&stats_lock);       \
5c4a8e
-    stats_##fn.usecs += tvdiff_usec (&start_t, &end_t); \
5c4a8e
-    stats_##fn.calls++;                                 \
5c4a8e
-  }                                                     \
5c4a8e
-  } while (0)
5c4a8e
-#define VDDK_CALL_END_DATAPATH(fn, bytes_)              \
5c4a8e
+#define VDDK_CALL_END(fn, bytes_)                       \
5c4a8e
   while (0);                                            \
5c4a8e
   if (vddk_debug_stats) {                               \
5c4a8e
     gettimeofday (&end_t, NULL);                        \
5c4a8e
@@ -161,13 +149,13 @@ static void display_stats (void);
5c4a8e
 #define VDDK_ERROR(err, fs, ...)                                \
5c4a8e
   do {                                                          \
5c4a8e
     char *vddk_err_msg;                                         \
5c4a8e
-    VDDK_CALL_START (VixDiskLib_GetErrorText, "%lu", err) {     \
5c4a8e
+    VDDK_CALL_START (VixDiskLib_GetErrorText, "%lu", err)       \
5c4a8e
       vddk_err_msg = VixDiskLib_GetErrorText ((err), NULL);     \
5c4a8e
-    } VDDK_CALL_END (VixDiskLib_GetErrorText);                  \
5c4a8e
+    VDDK_CALL_END (VixDiskLib_GetErrorText, 0);                 \
5c4a8e
     nbdkit_error (fs ": %s", ##__VA_ARGS__, vddk_err_msg);      \
5c4a8e
-    VDDK_CALL_START (VixDiskLib_FreeErrorText, "") {            \
5c4a8e
+    VDDK_CALL_START (VixDiskLib_FreeErrorText, "")              \
5c4a8e
       VixDiskLib_FreeErrorText (vddk_err_msg);                  \
5c4a8e
-    } VDDK_CALL_END (VixDiskLib_FreeErrorText);                 \
5c4a8e
+    VDDK_CALL_END (VixDiskLib_FreeErrorText, 0);                \
5c4a8e
   } while (0)
5c4a8e
 
5c4a8e
 /* Unload the plugin. */
5c4a8e
@@ -175,9 +163,9 @@ static void
5c4a8e
 vddk_unload (void)
5c4a8e
 {
5c4a8e
   if (init_called) {
5c4a8e
-    VDDK_CALL_START (VixDiskLib_Exit, "") {
5c4a8e
+    VDDK_CALL_START (VixDiskLib_Exit, "")
5c4a8e
       VixDiskLib_Exit ();
5c4a8e
-    } VDDK_CALL_END (VixDiskLib_Exit);
5c4a8e
+    VDDK_CALL_END (VixDiskLib_Exit, 0);
5c4a8e
   }
5c4a8e
   if (dl)
5c4a8e
     dlclose (dl);
5c4a8e
@@ -572,13 +560,13 @@ vddk_after_fork (void)
5c4a8e
   VDDK_CALL_START (VixDiskLib_InitEx,
5c4a8e
                    "%d, %d, &debug_fn, &error_fn, &error_fn, %s, %s",
5c4a8e
                    VDDK_MAJOR, VDDK_MINOR,
5c4a8e
-                   libdir, config ? : "NULL") {
5c4a8e
+                   libdir, config ? : "NULL")
5c4a8e
     err = VixDiskLib_InitEx (VDDK_MAJOR, VDDK_MINOR,
5c4a8e
                              &debug_function, /* log function */
5c4a8e
                              &error_function, /* warn function */
5c4a8e
                              &error_function, /* panic function */
5c4a8e
                              libdir, config);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_InitEx);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_InitEx, 0);
5c4a8e
   if (err != VIX_OK) {
5c4a8e
     VDDK_ERROR (err, "VixDiskLib_InitEx");
5c4a8e
     exit (EXIT_FAILURE);
5c4a8e
@@ -640,9 +628,9 @@ allocate_connect_params (void)
5c4a8e
   VixDiskLibConnectParams *ret;
5c4a8e
 
5c4a8e
   if (VixDiskLib_AllocateConnectParams != NULL) {
5c4a8e
-    VDDK_CALL_START (VixDiskLib_AllocateConnectParams, "") {
5c4a8e
+    VDDK_CALL_START (VixDiskLib_AllocateConnectParams, "")
5c4a8e
       ret = VixDiskLib_AllocateConnectParams ();
5c4a8e
-    } VDDK_CALL_END (VixDiskLib_AllocateConnectParams);
5c4a8e
+    VDDK_CALL_END (VixDiskLib_AllocateConnectParams, 0);
5c4a8e
   }
5c4a8e
   else
5c4a8e
     ret = calloc (1, sizeof (VixDiskLibConnectParams));
5c4a8e
@@ -657,9 +645,9 @@ free_connect_params (VixDiskLibConnectParams *params)
5c4a8e
    * originally called.  Otherwise use free.
5c4a8e
    */
5c4a8e
   if (VixDiskLib_AllocateConnectParams != NULL) {
5c4a8e
-    VDDK_CALL_START (VixDiskLib_FreeConnectParams, "params") {
5c4a8e
+    VDDK_CALL_START (VixDiskLib_FreeConnectParams, "params")
5c4a8e
       VixDiskLib_FreeConnectParams (params);
5c4a8e
-    } VDDK_CALL_END (VixDiskLib_FreeConnectParams);
5c4a8e
+    VDDK_CALL_END (VixDiskLib_FreeConnectParams, 0);
5c4a8e
   }
5c4a8e
   else
5c4a8e
     free (params);
5c4a8e
@@ -716,13 +704,13 @@ vddk_open (int readonly)
5c4a8e
                    "h->params, %d, %s, %s, &connection",
5c4a8e
                    readonly,
5c4a8e
                    snapshot_moref ? : "NULL",
5c4a8e
-                   transport_modes ? : "NULL") {
5c4a8e
+                   transport_modes ? : "NULL")
5c4a8e
     err = VixDiskLib_ConnectEx (h->params,
5c4a8e
                                 readonly,
5c4a8e
                                 snapshot_moref,
5c4a8e
                                 transport_modes,
5c4a8e
                                 &h->connection);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_ConnectEx);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_ConnectEx, 0);
5c4a8e
   if (err != VIX_OK) {
5c4a8e
     VDDK_ERROR (err, "VixDiskLib_ConnectEx");
5c4a8e
     goto err1;
5c4a8e
@@ -743,25 +731,25 @@ vddk_open (int readonly)
5c4a8e
   }
5c4a8e
 
5c4a8e
   VDDK_CALL_START (VixDiskLib_Open,
5c4a8e
-                   "connection, %s, %d, &handle", filename, flags) {
5c4a8e
+                   "connection, %s, %d, &handle", filename, flags)
5c4a8e
     err = VixDiskLib_Open (h->connection, filename, flags, &h->handle);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_Open);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_Open, 0);
5c4a8e
   if (err != VIX_OK) {
5c4a8e
     VDDK_ERROR (err, "VixDiskLib_Open: %s", filename);
5c4a8e
     goto err2;
5c4a8e
   }
5c4a8e
 
5c4a8e
-  VDDK_CALL_START (VixDiskLib_GetTransportMode, "handle") {
5c4a8e
+  VDDK_CALL_START (VixDiskLib_GetTransportMode, "handle")
5c4a8e
     transport_mode = VixDiskLib_GetTransportMode (h->handle);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_GetTransportMode);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_GetTransportMode, 0);
5c4a8e
   nbdkit_debug ("transport mode: %s", transport_mode);
5c4a8e
 
5c4a8e
   return h;
5c4a8e
 
5c4a8e
  err2:
5c4a8e
-  VDDK_CALL_START (VixDiskLib_Disconnect, "connection") {
5c4a8e
+  VDDK_CALL_START (VixDiskLib_Disconnect, "connection")
5c4a8e
     VixDiskLib_Disconnect (h->connection);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_Disconnect);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_Disconnect, 0);
5c4a8e
  err1:
5c4a8e
   free_connect_params (h->params);
5c4a8e
  err0:
5c4a8e
@@ -776,12 +764,12 @@ vddk_close (void *handle)
5c4a8e
   ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&open_close_lock);
5c4a8e
   struct vddk_handle *h = handle;
5c4a8e
 
5c4a8e
-  VDDK_CALL_START (VixDiskLib_Close, "handle") {
5c4a8e
+  VDDK_CALL_START (VixDiskLib_Close, "handle")
5c4a8e
     VixDiskLib_Close (h->handle);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_Close);
5c4a8e
-  VDDK_CALL_START (VixDiskLib_Disconnect, "connection") {
5c4a8e
+  VDDK_CALL_END (VixDiskLib_Close, 0);
5c4a8e
+  VDDK_CALL_START (VixDiskLib_Disconnect, "connection")
5c4a8e
     VixDiskLib_Disconnect (h->connection);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_Disconnect);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_Disconnect, 0);
5c4a8e
 
5c4a8e
   free_connect_params (h->params);
5c4a8e
   free (h);
5c4a8e
@@ -796,9 +784,9 @@ vddk_get_size (void *handle)
5c4a8e
   VixError err;
5c4a8e
   uint64_t size;
5c4a8e
 
5c4a8e
-  VDDK_CALL_START (VixDiskLib_GetInfo, "handle, &info") {
5c4a8e
+  VDDK_CALL_START (VixDiskLib_GetInfo, "handle, &info")
5c4a8e
     err = VixDiskLib_GetInfo (h->handle, &info;;
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_GetInfo);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_GetInfo, 0);
5c4a8e
   if (err != VIX_OK) {
5c4a8e
     VDDK_ERROR (err, "VixDiskLib_GetInfo");
5c4a8e
     return -1;
5c4a8e
@@ -827,9 +815,9 @@ vddk_get_size (void *handle)
5c4a8e
                   info->uuid ? : "NULL");
5c4a8e
   }
5c4a8e
 
5c4a8e
-  VDDK_CALL_START (VixDiskLib_FreeInfo, "info") {
5c4a8e
+  VDDK_CALL_START (VixDiskLib_FreeInfo, "info")
5c4a8e
     VixDiskLib_FreeInfo (info);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_FreeInfo);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_FreeInfo, 0);
5c4a8e
 
5c4a8e
   return (int64_t) size;
5c4a8e
 }
5c4a8e
@@ -857,12 +845,12 @@ vddk_pread (void *handle, void *buf, uint32_t count, uint64_t offset,
5c4a8e
   offset /= VIXDISKLIB_SECTOR_SIZE;
5c4a8e
   count /= VIXDISKLIB_SECTOR_SIZE;
5c4a8e
 
5c4a8e
-  VDDK_CALL_START_DATAPATH (VixDiskLib_Read,
5c4a8e
-                            "handle, %" PRIu64 " sectors, "
5c4a8e
-                            "%" PRIu32 " sectors, buffer",
5c4a8e
-                            offset, count) {
5c4a8e
+  VDDK_CALL_START (VixDiskLib_Read,
5c4a8e
+                   "handle, %" PRIu64 " sectors, "
5c4a8e
+                   "%" PRIu32 " sectors, buffer",
5c4a8e
+                   offset, count)
5c4a8e
     err = VixDiskLib_Read (h->handle, offset, count, buf);
5c4a8e
-  } VDDK_CALL_END_DATAPATH (VixDiskLib_Read, count * VIXDISKLIB_SECTOR_SIZE);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_Read, count * VIXDISKLIB_SECTOR_SIZE);
5c4a8e
   if (err != VIX_OK) {
5c4a8e
     VDDK_ERROR (err, "VixDiskLib_Read");
5c4a8e
     return -1;
5c4a8e
@@ -897,12 +885,12 @@ vddk_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset,
5c4a8e
   offset /= VIXDISKLIB_SECTOR_SIZE;
5c4a8e
   count /= VIXDISKLIB_SECTOR_SIZE;
5c4a8e
 
5c4a8e
-  VDDK_CALL_START_DATAPATH (VixDiskLib_Write,
5c4a8e
-                            "handle, %" PRIu64 " sectors, "
5c4a8e
-                            "%" PRIu32 " sectors, buffer",
5c4a8e
-                            offset, count) {
5c4a8e
+  VDDK_CALL_START (VixDiskLib_Write,
5c4a8e
+                   "handle, %" PRIu64 " sectors, "
5c4a8e
+                   "%" PRIu32 " sectors, buffer",
5c4a8e
+                   offset, count)
5c4a8e
     err = VixDiskLib_Write (h->handle, offset, count, buf);
5c4a8e
-  } VDDK_CALL_END_DATAPATH (VixDiskLib_Write, count * VIXDISKLIB_SECTOR_SIZE);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_Write, count * VIXDISKLIB_SECTOR_SIZE);
5c4a8e
   if (err != VIX_OK) {
5c4a8e
     VDDK_ERROR (err, "VixDiskLib_Write");
5c4a8e
     return -1;
5c4a8e
@@ -945,9 +933,9 @@ vddk_flush (void *handle, uint32_t flags)
5c4a8e
    * file so it appears to be the correct call to use here.
5c4a8e
    */
5c4a8e
 
5c4a8e
-  VDDK_CALL_START (VixDiskLib_Flush, "handle") {
5c4a8e
+  VDDK_CALL_START (VixDiskLib_Flush, "handle")
5c4a8e
     err = VixDiskLib_Flush (h->handle);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_Flush);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_Flush, 0);
5c4a8e
   if (err != VIX_OK) {
5c4a8e
     VDDK_ERROR (err, "VixDiskLib_Flush");
5c4a8e
     return -1;
5c4a8e
@@ -983,17 +971,17 @@ vddk_can_extents (void *handle)
5c4a8e
    */
5c4a8e
   VDDK_CALL_START (VixDiskLib_QueryAllocatedBlocks,
5c4a8e
                    "handle, 0, %d sectors, %d sectors",
5c4a8e
-                   VIXDISKLIB_MIN_CHUNK_SIZE, VIXDISKLIB_MIN_CHUNK_SIZE) {
5c4a8e
+                   VIXDISKLIB_MIN_CHUNK_SIZE, VIXDISKLIB_MIN_CHUNK_SIZE)
5c4a8e
     err = VixDiskLib_QueryAllocatedBlocks (h->handle,
5c4a8e
                                            0, VIXDISKLIB_MIN_CHUNK_SIZE,
5c4a8e
                                            VIXDISKLIB_MIN_CHUNK_SIZE,
5c4a8e
                                            &block_list);
5c4a8e
-  } VDDK_CALL_END (VixDiskLib_QueryAllocatedBlocks);
5c4a8e
+  VDDK_CALL_END (VixDiskLib_QueryAllocatedBlocks, 0);
5c4a8e
   error_suppression = 0;
5c4a8e
   if (err == VIX_OK) {
5c4a8e
-    VDDK_CALL_START (VixDiskLib_FreeBlockList, "block_list") {
5c4a8e
+    VDDK_CALL_START (VixDiskLib_FreeBlockList, "block_list")
5c4a8e
       VixDiskLib_FreeBlockList (block_list);
5c4a8e
-    } VDDK_CALL_END (VixDiskLib_FreeBlockList);
5c4a8e
+    VDDK_CALL_END (VixDiskLib_FreeBlockList, 0);
5c4a8e
   }
5c4a8e
   if (err != VIX_OK) {
5c4a8e
     char *errmsg = VixDiskLib_GetErrorText (err, NULL);
5c4a8e
@@ -1073,12 +1061,12 @@ vddk_extents (void *handle, uint32_t count, uint64_t offset, uint32_t flags,
5c4a8e
     VDDK_CALL_START (VixDiskLib_QueryAllocatedBlocks,
5c4a8e
                      "handle, %" PRIu64 " sectors, %" PRIu64 " sectors, "
5c4a8e
                      "%d sectors",
5c4a8e
-                     start_sector, nr_sectors, VIXDISKLIB_MIN_CHUNK_SIZE) {
5c4a8e
+                     start_sector, nr_sectors, VIXDISKLIB_MIN_CHUNK_SIZE)
5c4a8e
       err = VixDiskLib_QueryAllocatedBlocks (h->handle,
5c4a8e
                                              start_sector, nr_sectors,
5c4a8e
                                              VIXDISKLIB_MIN_CHUNK_SIZE,
5c4a8e
                                              &block_list);
5c4a8e
-    } VDDK_CALL_END (VixDiskLib_QueryAllocatedBlocks);
5c4a8e
+    VDDK_CALL_END (VixDiskLib_QueryAllocatedBlocks, 0);
5c4a8e
     if (err != VIX_OK) {
5c4a8e
       VDDK_ERROR (err, "VixDiskLib_QueryAllocatedBlocks");
5c4a8e
       return -1;
5c4a8e
@@ -1097,15 +1085,15 @@ vddk_extents (void *handle, uint32_t count, uint64_t offset, uint32_t flags,
5c4a8e
            add_extent (extents, &position, blk_offset, true) == -1) ||
5c4a8e
           (add_extent (extents,
5c4a8e
                        &position, blk_offset + blk_length, false) == -1)) {
5c4a8e
-        VDDK_CALL_START (VixDiskLib_FreeBlockList, "block_list") {
5c4a8e
+        VDDK_CALL_START (VixDiskLib_FreeBlockList, "block_list")
5c4a8e
           VixDiskLib_FreeBlockList (block_list);
5c4a8e
-        } VDDK_CALL_END (VixDiskLib_FreeBlockList);
5c4a8e
+        VDDK_CALL_END (VixDiskLib_FreeBlockList, 0);
5c4a8e
         return -1;
5c4a8e
       }
5c4a8e
     }
5c4a8e
-    VDDK_CALL_START (VixDiskLib_FreeBlockList, "block_list") {
5c4a8e
+    VDDK_CALL_START (VixDiskLib_FreeBlockList, "block_list")
5c4a8e
       VixDiskLib_FreeBlockList (block_list);
5c4a8e
-    } VDDK_CALL_END (VixDiskLib_FreeBlockList);
5c4a8e
+    VDDK_CALL_END (VixDiskLib_FreeBlockList, 0);
5c4a8e
 
5c4a8e
     /* There's an implicit hole after the returned list of blocks, up
5c4a8e
      * to the end of the QueryAllocatedBlocks request.
5c4a8e
-- 
5c4a8e
2.31.1
5c4a8e