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

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