static int blockpause(void *args) { ASYNC_block_pause(); ASYNC_pause_job(); ASYNC_unblock_pause(); ASYNC_pause_job(); return 1; }
static int wake(void *args) { ASYNC_pause_job(); ASYNC_wake(ASYNC_get_current_job()); ASYNC_pause_job(); ASYNC_clear_wake(ASYNC_get_current_job()); return 1; }
static int save_current(void *args) { currjob = ASYNC_get_current_job(); ASYNC_pause_job(); return 1; }
static int add_two(void *args) { ctr++; ASYNC_pause_job(); ctr++; return 2; }
static void dummy_pause_job(void) { ASYNC_JOB *job; if ((job = ASYNC_get_current_job()) == NULL) return; /* * In the Dummy async engine we are cheating. We signal that the job * is complete by waking it before the call to ASYNC_pause_job(). A real * async engine would only wake when the job was actually complete */ ASYNC_wake(job); /* Ignore errors - we carry on anyway */ ASYNC_pause_job(); ASYNC_clear_wake(job); }
int qat_pause_job(ASYNC_JOB *job, int notificationNo) { /* We will ignore notificationNo for the moment */ ASYNC_WAIT_CTX *waitctx; OSSL_ASYNC_FD efd; void *custom = NULL; uint64_t buf = 0; int ret = 0; if (ASYNC_pause_job() == 0) return ret; if ((waitctx = ASYNC_get_wait_ctx(job)) == NULL) return ret; if ((ret = ASYNC_WAIT_CTX_get_fd(waitctx, engine_qat_id, &efd, &custom)) > 0) { read(efd, &buf, sizeof(uint64_t)); } return ret; }
static void dummy_pause_job(void) { ASYNC_JOB *job; ASYNC_WAIT_CTX *waitctx; OSSL_ASYNC_FD pipefds[2] = {0, 0}; OSSL_ASYNC_FD *writefd; #if defined(ASYNC_WIN) DWORD numwritten, numread; char buf = DUMMY_CHAR; #elif defined(ASYNC_POSIX) char buf = DUMMY_CHAR; #endif if ((job = ASYNC_get_current_job()) == NULL) return; waitctx = ASYNC_get_wait_ctx(job); if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_dasync_id, &pipefds[0], (void **)&writefd)) { pipefds[1] = *writefd; } else { writefd = OPENSSL_malloc(sizeof(*writefd)); if (writefd == NULL) return; #if defined(ASYNC_WIN) if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0) { OPENSSL_free(writefd); return; } #elif defined(ASYNC_POSIX) if (pipe(pipefds) != 0) { OPENSSL_free(writefd); return; } #endif *writefd = pipefds[1]; if(!ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_dasync_id, pipefds[0], writefd, wait_cleanup)) { wait_cleanup(waitctx, engine_dasync_id, pipefds[0], writefd); return; } } /* * In the Dummy async engine we are cheating. We signal that the job * is complete by waking it before the call to ASYNC_pause_job(). A real * async engine would only wake when the job was actually complete */ #if defined(ASYNC_WIN) WriteFile(pipefds[1], &buf, 1, &numwritten, NULL); #elif defined(ASYNC_POSIX) if (write(pipefds[1], &buf, 1) < 0) return; #endif /* Ignore errors - we carry on anyway */ ASYNC_pause_job(); /* Clear the wake signal */ #if defined(ASYNC_WIN) ReadFile(pipefds[0], &buf, 1, &numread, NULL); #elif defined(ASYNC_POSIX) if (read(pipefds[0], &buf, 1) < 0) return; #endif }
static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, size_t len) { int r; int retry = 0; unsigned int done = 0; struct iocb *cb; struct timespec timeout; struct io_event events[MAX_INFLIGHTS]; u_int64_t eval = 0; timeout.tv_sec = 0; timeout.tv_nsec = 0; /* if efd has not been initialised yet do it here */ if (aio->mode == MODE_UNINIT) { r = afalg_setup_async_event_notification(aio); if (r == 0) return 0; } cb = &(aio->cbt[0 % MAX_INFLIGHTS]); memset(cb, '\0', sizeof(*cb)); cb->aio_fildes = sfd; cb->aio_lio_opcode = IOCB_CMD_PREAD; /* * The pointer has to be converted to unsigned value first to avoid * sign extension on cast to 64 bit value in 32-bit builds */ cb->aio_buf = (size_t)buf; cb->aio_offset = 0; cb->aio_data = 0; cb->aio_nbytes = len; cb->aio_flags = IOCB_FLAG_RESFD; cb->aio_resfd = aio->efd; /* * Perform AIO read on AFALG socket, this in turn performs an async * crypto operation in kernel space */ r = io_read(aio->aio_ctx, 1, &cb); if (r < 0) { ALG_PWARN("%s: io_read failed : ", __func__); return 0; } do { /* While AIO read is being performed pause job */ ASYNC_pause_job(); /* Check for completion of AIO read */ r = read(aio->efd, &eval, sizeof(eval)); if (r < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) continue; ALG_PERR("%s: read failed for event fd : ", __func__); return 0; } else if (r == 0 || eval <= 0) { ALG_WARN("%s: eventfd read %d bytes, eval = %lu\n", __func__, r, eval); } if (eval > 0) { /* Get results of AIO read */ r = io_getevents(aio->aio_ctx, 1, MAX_INFLIGHTS, events, &timeout); if (r > 0) { /* * events.res indicates the actual status of the operation. * Handle the error condition first. */ if (events[0].res < 0) { /* * Underlying operation cannot be completed at the time * of previous submission. Resubmit for the operation. */ if (events[0].res == -EBUSY && retry++ < 3) { r = io_read(aio->aio_ctx, 1, &cb); if (r < 0) { ALG_PERR("%s: retry %d for io_read failed : ", __func__, retry); return 0; } continue; } else { /* * Retries exceed for -EBUSY or unrecoverable error * condition for this instance of operation. */ ALG_WARN ("%s: Crypto Operation failed with code %lld\n", __func__, events[0].res); return 0; } } /* Operation successful. */ done = 1; } else if (r < 0) { ALG_PERR("%s: io_getevents failed : ", __func__); return 0; } else { ALG_WARN("%s: io_geteventd read 0 bytes\n", __func__); } } } while (!done); return 1; }
static int only_pause(void *args) { ASYNC_pause_job(); return 1; }