aio: Use runtime arguments with injections points in tests
authorMichael Paquier <michael@paquier.xyz>
Sat, 10 May 2025 03:36:57 +0000 (12:36 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sat, 10 May 2025 03:36:57 +0000 (12:36 +0900)
This cleans up the code related to the testing infrastructure of AIO
that used injection points, switching the test code to use the new
facility for injection points added by 371f2db8b05e rather than tweaks
to pass and reset arguments to the callbacks run.

This removes all the dependencies to USE_INJECTION_POINTS in the AIO
code.  pgaio_io_call_inj(), pgaio_inj_io_get() and pgaio_inj_cur_handle
are now gone.

Reviewed-by: Greg Burd <greg@burd.me>
Discussion: https://postgr.es/m/Z_y9TtnXubvYAApS@paquier.xyz

src/backend/storage/aio/aio.c
src/backend/storage/aio/method_worker.c
src/include/storage/aio_internal.h
src/test/modules/test_aio/test_aio.c

index 04268e77ec2ee2075a86ff3626c8e93a70d18e6a..ebb5a771bfd16370ddc1d7afd298656c86e4be7b 100644 (file)
 #include "storage/aio_subsys.h"
 #include "utils/guc.h"
 #include "utils/guc_hooks.h"
+#include "utils/injection_point.h"
 #include "utils/resowner.h"
 #include "utils/wait_event_types.h"
 
-#ifdef USE_INJECTION_POINTS
-#include "utils/injection_point.h"
-#endif
-
 
 static inline void pgaio_io_update_state(PgAioHandle *ioh, PgAioHandleState new_state);
 static void pgaio_io_reclaim(PgAioHandle *ioh);
@@ -96,17 +93,6 @@ static const IoMethodOps *const pgaio_method_ops_table[] = {
 const IoMethodOps *pgaio_method_ops;
 
 
-/*
- * Currently there's no infrastructure to pass arguments to injection points,
- * so we instead set this up for the duration of the injection point
- * invocation. See pgaio_io_call_inj().
- */
-#ifdef USE_INJECTION_POINTS
-static PgAioHandle *pgaio_inj_cur_handle;
-#endif
-
-
-
 /* --------------------------------------------------------------------------------
  * Public Functions related to PgAioHandle
  * --------------------------------------------------------------------------------
@@ -507,7 +493,7 @@ pgaio_io_process_completion(PgAioHandle *ioh, int result)
 
    pgaio_io_update_state(ioh, PGAIO_HS_COMPLETED_IO);
 
-   pgaio_io_call_inj(ioh, "aio-process-completion-before-shared");
+   INJECTION_POINT("aio-process-completion-before-shared", ioh);
 
    pgaio_io_call_complete_shared(ioh);
 
@@ -1255,43 +1241,3 @@ check_io_max_concurrency(int *newval, void **extra, GucSource source)
 
    return true;
 }
-
-
-
-/* --------------------------------------------------------------------------------
- * Injection point support
- * --------------------------------------------------------------------------------
- */
-
-#ifdef USE_INJECTION_POINTS
-
-/*
- * Call injection point with support for pgaio_inj_io_get().
- */
-void
-pgaio_io_call_inj(PgAioHandle *ioh, const char *injection_point)
-{
-   pgaio_inj_cur_handle = ioh;
-
-   PG_TRY();
-   {
-       InjectionPointCached(injection_point, NULL);
-   }
-   PG_FINALLY();
-   {
-       pgaio_inj_cur_handle = NULL;
-   }
-   PG_END_TRY();
-}
-
-/*
- * Return IO associated with injection point invocation. This is only needed
- * as injection points currently don't support arguments.
- */
-PgAioHandle *
-pgaio_inj_io_get(void)
-{
-   return pgaio_inj_cur_handle;
-}
-
-#endif
index 6e8b1327946edfa2fa85a69a4aab54b7d22984d1..743cccc2acd18631ac0a19537886fb8d9619f8bc 100644 (file)
@@ -42,6 +42,7 @@
 #include "storage/latch.h"
 #include "storage/proc.h"
 #include "tcop/tcopprot.h"
+#include "utils/injection_point.h"
 #include "utils/memdebug.h"
 #include "utils/ps_status.h"
 #include "utils/wait_event.h"
@@ -525,7 +526,7 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
             * To be able to exercise the reopen-fails path, allow injection
             * points to trigger a failure at this point.
             */
-           pgaio_io_call_inj(ioh, "aio-worker-after-reopen");
+           INJECTION_POINT("aio-worker-after-reopen", ioh);
 
            error_errno = 0;
            error_ioh = NULL;
index 33f27b9fe508d1404f2cf37271982ea918efe10c..2d37a243abe525866d6ccfd74a1062be32d422e8 100644 (file)
@@ -394,26 +394,6 @@ extern const char *pgaio_io_get_target_name(PgAioHandle *ioh);
                pgaio_io_get_state_name(ioh), \
                __VA_ARGS__)
 
-
-#ifdef USE_INJECTION_POINTS
-
-extern void pgaio_io_call_inj(PgAioHandle *ioh, const char *injection_point);
-
-/* just for use in tests, from within injection points */
-extern PgAioHandle *pgaio_inj_io_get(void);
-
-#else
-
-#define pgaio_io_call_inj(ioh, injection_point) (void) 0
-
-/*
- * no fallback for pgaio_inj_io_get, all code using injection points better be
- * guarded by USE_INJECTION_POINTS.
- */
-
-#endif
-
-
 /* Declarations for the tables of function pointers exposed by each IO method. */
 extern PGDLLIMPORT const IoMethodOps pgaio_sync_ops;
 extern PGDLLIMPORT const IoMethodOps pgaio_worker_ops;
index 681d5d73d47307440be8d33214527773df525ac1..5cdfb89210b28f233b3090b45d96662bd210ea25 100644 (file)
@@ -684,7 +684,7 @@ extern PGDLLEXPORT void inj_io_reopen(const char *name,
 void
 inj_io_short_read(const char *name, const void *private_data, void *arg)
 {
-   PgAioHandle *ioh;
+   PgAioHandle *ioh = (PgAioHandle *) arg;
 
    ereport(LOG,
            errmsg("short read injection point called, is enabled: %d",
@@ -693,8 +693,6 @@ inj_io_short_read(const char *name, const void *private_data, void *arg)
 
    if (inj_io_error_state->enabled_short_read)
    {
-       ioh = pgaio_inj_io_get();
-
        /*
         * Only shorten reads that are actually longer than the target size,
         * otherwise we can trigger over-reads.