X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fos%2Fbluestore%2Faio.cc;fp=src%2Fceph%2Fsrc%2Fos%2Fbluestore%2Faio.cc;h=4996e73452b119a8c9c50085d5c858e71534ece5;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/os/bluestore/aio.cc b/src/ceph/src/os/bluestore/aio.cc new file mode 100644 index 0000000..4996e73 --- /dev/null +++ b/src/ceph/src/os/bluestore/aio.cc @@ -0,0 +1,88 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "aio.h" + +#if defined(HAVE_LIBAIO) + + +int aio_queue_t::submit(aio_t &aio, int *retries) +{ + // 2^16 * 125us = ~8 seconds, so max sleep is ~16 seconds + int attempts = 16; + int delay = 125; + iocb *piocb = &aio.iocb; + int r; + while (true) { + r = io_submit(ctx, 1, &piocb); + if (r < 0) { + if (r == -EAGAIN && attempts-- > 0) { + usleep(delay); + delay *= 2; + (*retries)++; + continue; + } + } + assert(r == 1); + break; + } + return r; +} + +int aio_queue_t::submit_batch(aio_iter begin, aio_iter end, + uint16_t aios_size, void *priv, + int *retries) +{ + // 2^16 * 125us = ~8 seconds, so max sleep is ~16 seconds + int attempts = 16; + int delay = 125; + + aio_iter cur = begin; + struct iocb *piocb[aios_size]; + int left = 0; + while (cur != end) { + cur->priv = priv; + *(piocb+left) = &cur->iocb; + ++left; + ++cur; + } + int done = 0; + while (left > 0) { + int r = io_submit(ctx, left, piocb + done); + if (r < 0) { + if (r == -EAGAIN && attempts-- > 0) { + usleep(delay); + delay *= 2; + (*retries)++; + continue; + } + return r; + } + assert(r > 0); + done += r; + left -= r; + } + return done; +} + +int aio_queue_t::get_next_completed(int timeout_ms, aio_t **paio, int max) +{ + io_event event[max]; + struct timespec t = { + timeout_ms / 1000, + (timeout_ms % 1000) * 1000 * 1000 + }; + + int r = 0; + do { + r = io_getevents(ctx, 1, max, event, &t); + } while (r == -EINTR); + + for (int i=0; irval = event[i].res; + } + return r; +} + +#endif