MDEV-27900 fixes

* prevent infinite recursion in beyond-EOF reads (when pread returns 0)
* reduce code duplication

followup for d78173828e and f4fb6cb3fe
This commit is contained in:
Sergei Golubchik 2022-03-24 15:43:20 +01:00
parent e9e6db9355
commit f92388fa14
4 changed files with 14 additions and 19 deletions

View file

@ -161,8 +161,7 @@ private:
}
io_uring_cqe_seen(&aio->uring_, cqe);
if (iocb->m_ret_len != iocb->m_len && !iocb->m_err)
finish_synchronous(iocb);
finish_synchronous(iocb);
// If we need to resubmit the IO operation, but the ring is full,
// we will follow the same path as for any other error codes.

View file

@ -128,8 +128,7 @@ class aio_linux final : public aio
{
iocb->m_ret_len= event.res;
iocb->m_err= 0;
if (iocb->m_ret_len != iocb->m_len)
finish_synchronous(iocb);
finish_synchronous(iocb);
}
iocb->m_internal_task.m_func= iocb->m_callback;
iocb->m_internal_task.m_arg= iocb;

View file

@ -173,7 +173,17 @@ public:
protected:
static void synchronous(aiocb *cb);
/** finish a partial read/write callback synchronously */
static void finish_synchronous(aiocb *cb);
static inline void finish_synchronous(aiocb *cb)
{
if (!cb->m_err && cb->m_ret_len != cb->m_len)
{
/* partial read/write */
cb->m_buffer= (char *) cb->m_buffer + cb->m_ret_len;
cb->m_len-= (unsigned int) cb->m_ret_len;
cb->m_offset+= cb->m_ret_len;
synchronous(cb);
}
}
};
class timer

View file

@ -85,24 +85,11 @@ void aio::synchronous(aiocb *cb)
#endif
cb->m_ret_len = ret_len;
cb->m_err = err;
if (!err && cb->m_ret_len != cb->m_len)
if (ret_len)
finish_synchronous(cb);
}
/**
A partial read/write has occured, continue synchronously.
*/
void aio::finish_synchronous(aiocb *cb)
{
assert(cb->m_ret_len != (unsigned int) cb->m_len && !cb->m_err);
/* partial read/write */
cb->m_buffer= (char *) cb->m_buffer + cb->m_ret_len;
cb->m_len-= (unsigned int) cb->m_ret_len;
cb->m_offset+= cb->m_ret_len;
synchronous(cb);
}
/**
Implementation of generic threadpool.
This threadpool consists of the following components