Advertisement
ffilz

Diff between nonblocking-io and async-io

Jul 20th, 2022
1,444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.30 KB | None | 0 0
  1. diff --git a/src/client/Client.cc b/src/client/Client.cc
  2. index 199b39f7f45..1763d0a0473 100644
  3. --- a/src/client/Client.cc
  4. +++ b/src/client/Client.cc
  5. @@ -10223,7 +10223,7 @@ void Client::C_Read_Finisher::finish_io(int r)
  6.    delete this;
  7.  }
  8.  
  9. -void Client::C_Read_Sync_Async::retry()
  10. +void Client::C_Read_Sync_NonBlocking::retry()
  11.  {
  12.    filer->read_trunc(in->ino, &in->layout, in->snapid, pos, left, &tbl, 0,
  13.                      in->truncate_size, in->truncate_seq, this);
  14. @@ -10231,9 +10231,9 @@ void Client::C_Read_Sync_Async::retry()
  15.  
  16.  /**
  17.   * The following method implements most of what _read_sync does, but in a
  18. - * way that works with the async (non-blocking) read path.
  19. + * way that works with the non-blocking read path.
  20.   */
  21. -void Client::C_Read_Sync_Async::finish(int r)
  22. +void Client::C_Read_Sync_NonBlocking::finish(int r)
  23.  {
  24.    clnt->client_lock.lock();
  25.  
  26. @@ -10408,9 +10408,9 @@ retry:
  27.      rc = _read_async(f, offset, size, bl, iofinish.get());
  28.  
  29.      if (onfinish) {
  30. -      // handle async caller (onfinish != nullptr), we can now safely release
  31. -      // all the managed pointers, but we might need to do something with
  32. -      // iofinisher.
  33. +      // handle non-blocking caller (onfinish != nullptr), we can now safely
  34. +      // release all the managed pointers, but we might need to do something
  35. +      // with iofinisher.
  36.        Context *iof = iofinish.release();
  37.        crf.release();
  38.  
  39. @@ -10424,19 +10424,20 @@ retry:
  40.      if (rc < 0)
  41.        goto done;
  42.    } else if (onfinish) {
  43. -    // handle _sync_read asynchronously...
  44. +    // handle _sync_read without blocking...
  45.      // This sounds odd, but we want to accomplish what is done in the else
  46.      // branch below but in a non-blocking fashion. The code in _read_sync
  47. -    // is duplicated and modified and exists in C_Read_Sync_Async::finish().
  48. -    C_Read_Sync_Async *crsa =
  49. -      new C_Read_Sync_Async(this, iofinish.release(), f, in, f->pos,
  50. -                            offset, size, bl, filer.get(), have);
  51. +    // is duplicated and modified and exists in
  52. +    // C_Read_Sync_NonBlocking::finish().
  53. +    C_Read_Sync_NonBlocking *crsa =
  54. +      new C_Read_Sync_NonBlocking(this, iofinish.release(), f, in, f->pos,
  55. +                                  offset, size, bl, filer.get(), have);
  56.        crf.release();
  57.  
  58.        // Now make first attempt at performing _read_sync
  59.        crsa->retry();
  60.  
  61. -      // Now the C_Read_Sync_Async is going to handle EVERYTHING else
  62. +      // Now the C_Read_Sync_NonBlocking is going to handle EVERYTHING else
  63.        // Allow caller to wait on onfinish...
  64.        return 0;
  65.    } else {
  66. @@ -10585,7 +10586,7 @@ int Client::_read_async(Fh *f, uint64_t off, uint64_t len, bufferlist *bl,
  67.  
  68.    if (onfinish != nullptr) {
  69.      // Release C_Read_Async_Finisher from managed pointer, either
  70. -    // file_read will result in async complete, or we need to complete
  71. +    // file_read will result in non-blocking complete, or we need to complete
  72.      // immediately. In either case, the C_Read_Async_Finisher is safely
  73.      // handled and won't be abandoned.
  74.      Context *crf = io_finish.release();
  75. @@ -11078,9 +11079,9 @@ int64_t Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf,
  76.                    : false);
  77.  
  78.      if (onfinish) {
  79. -      // handle async caller (onfinish != nullptr), we can now safely release
  80. -      // all the managed pointers, but we might need to do something with
  81. -      // iofinisher.
  82. +      // handle non-blocking caller (onfinish != nullptr), we can now safely
  83. +      // release all the managed pointers, but we might need to do something
  84. +      // with iofinisher.
  85.        Context *iof = iofinish.release();
  86.        C_Write_Finisher *cwfp = cwf.release();
  87.  
  88. @@ -11138,8 +11139,8 @@ int64_t Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf,
  89.                iofinish.get());
  90.  
  91.      if (onfinish) {
  92. -      // handle async caller (onfinish != nullptr), we can now safely release
  93. -      // all the managed pointers
  94. +      // handle non-blocking caller (onfinish != nullptr), we can now safely
  95. +      // release all the managed pointers
  96.        iofinish.release();
  97.        onuninline.release();
  98.        cwf.release();
  99. @@ -11159,7 +11160,7 @@ int64_t Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf,
  100.    // if we get here, write was successful, update client metadata
  101.  success:
  102.  
  103. -  // do not get here if async caller (onfinish != nullptr)
  104. +  // do not get here if non-blocking caller (onfinish != nullptr)
  105.    r = _write_success(f, start, fpos, offset, size, in);
  106.  
  107.    if (r >= 0 && do_fsync) {
  108. @@ -11173,7 +11174,7 @@ success:
  109.  
  110.  done:
  111.  
  112. -  // can not get here if async caller (onfinish != nullptr)
  113. +  // can not get here if non-blocking caller (onfinish != nullptr)
  114.  
  115.    if (nullptr != onuninline) {
  116.      client_lock.unlock();
  117. @@ -11312,7 +11313,7 @@ void Client::C_nonblocking_fsync_state::advance()
  118.        ldout(clnt->cct, 15) << "waiting on unsafe requests, last tid " << req->get_tid() <<  dendl;
  119.  
  120.        req->get();
  121. -      clnt->add_async_onfinish_to_context_list(req->waitfor_safe, advancer);
  122. +      clnt->add_nonblocking_onfinish_to_context_list(req->waitfor_safe, advancer);
  123.        // ------------  here is a state machine break point
  124.        return;
  125.      }
  126. @@ -11337,7 +11338,7 @@ void Client::C_nonblocking_fsync_state::advance()
  127.          ldout(clnt->cct, 10) << "ino " << in->ino << " has " << in->cap_refs[CEPH_CAP_FILE_BUFFER]
  128.                               << " uncommitted, waiting" << dendl;
  129.          advancer = new C_nonblocking_fsync_state_advancer(clnt, this);
  130. -        clnt->add_async_onfinish_to_context_list(in->waitfor_commit, advancer);
  131. +        clnt->add_nonblocking_onfinish_to_context_list(in->waitfor_commit, advancer);
  132.          // ------------  here is a state machine break point but we have to
  133.          //               return to this case because this might loop.
  134.          progress = 1;
  135. @@ -11378,7 +11379,7 @@ void Client::C_nonblocking_fsync_state::advance()
  136.                               << ccap_string(it->second) << " flush_tid " << flush_tid
  137.                               << " last " << it->first << dendl;
  138.          advancer = new C_nonblocking_fsync_state_advancer(clnt, this);
  139. -        clnt->add_async_onfinish_to_context_list(in->waitfor_caps, advancer);
  140. +        clnt->add_nonblocking_onfinish_to_context_list(in->waitfor_caps, advancer);
  141.          // ------------  here is a state machine break point
  142.          //               the advancer completion will resume with case 3
  143.          return;
  144. diff --git a/src/client/Client.h b/src/client/Client.h
  145. index c44a16dc0b8..22b99942a22 100644
  146. --- a/src/client/Client.h
  147. +++ b/src/client/Client.h
  148. @@ -1013,7 +1013,7 @@ protected:
  149.    // helpers
  150.    void wake_up_session_caps(MetaSession *s, bool reconnect);
  151.  
  152. -  void add_async_onfinish_to_context_list(std::list<Context*>& ls, Context *onfinish) {
  153. +  void add_nonblocking_onfinish_to_context_list(std::list<Context*>& ls, Context *onfinish) {
  154.      ls.push_back(onfinish);
  155.    }
  156.    void wait_on_context_list(std::list<Context*>& ls);
  157. @@ -1295,20 +1295,20 @@ private:
  158.      }
  159.    };
  160.  
  161. -  class C_Read_Sync_Async : public Context {
  162. -  // When operating in async (non-blocking) mode, what used to be done by
  163. -  // _read_sync still needs to be handled, but it needs to be handled
  164. -  // asynchronously (non-blocking) while still following the semantics. Note
  165. -  // that _read_sync IS actually asynchronous it just uses condition variables
  166. -  // to wait. Now instead, we use this Context class to synchronize the steps.
  167. +  class C_Read_Sync_NonBlocking : public Context {
  168. +  // When operating in non-blocking mode, what used to be done by _read_sync
  169. +  // still needs to be handled, but it needs to be handled without blocking
  170. +  // while still following the semantics. Note that _read_sync is actually
  171. +  // asynchronous. it just uses condition variables to wait. Now instead, we use
  172. +  // this Context class to synchronize the steps.
  173.    //
  174. -  // The steps will be accomplished by complete/finish being called to
  175. -  // complete each step, with complete only releasing this object once all is
  176. -  // finally complete.
  177. +  // The steps will be accomplished by complete/finish being called to complete
  178. +  // each step, with complete only releasing this object once all is finally
  179. +  // complete.
  180.    public:
  181. -    C_Read_Sync_Async(Client *clnt, Context *onfinish, Fh *f, Inode *in,
  182. -                      uint64_t fpos, uint64_t off, uint64_t len,
  183. -                      bufferlist *bl, Filer *filer, int have_caps)
  184. +    C_Read_Sync_NonBlocking(Client *clnt, Context *onfinish, Fh *f, Inode *in,
  185. +                            uint64_t fpos, uint64_t off, uint64_t len,
  186. +                            bufferlist *bl, Filer *filer, int have_caps)
  187.        : clnt(clnt), onfinish(onfinish), f(f), in(in), off(off), len(len), bl(bl),
  188.          filer(filer), have_caps(have_caps)
  189.      {
  190. diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h
  191. index 9a6c1622459..145fa7deccf 100644
  192. --- a/src/include/cephfs/libcephfs.h
  193. +++ b/src/include/cephfs/libcephfs.h
  194. @@ -1892,8 +1892,8 @@ int64_t ceph_ll_readv(struct ceph_mount_info *cmount, struct Fh *fh,
  195.               const struct iovec *iov, int iovcnt, int64_t off);
  196.  int64_t ceph_ll_writev(struct ceph_mount_info *cmount, struct Fh *fh,
  197.                const struct iovec *iov, int iovcnt, int64_t off);
  198. -int64_t ceph_ll_async_readv_writev(struct ceph_mount_info *cmount,
  199. -                  struct ceph_ll_io_info *io_info);
  200. +int64_t ceph_ll_nonblocking_readv_writev(struct ceph_mount_info *cmount,
  201. +                    struct ceph_ll_io_info *io_info);
  202.  int ceph_ll_close(struct ceph_mount_info *cmount, struct Fh* filehandle);
  203.  int ceph_ll_iclose(struct ceph_mount_info *cmount, struct Inode *in, int mode);
  204.  /**
  205. diff --git a/src/libcephfs.cc b/src/libcephfs.cc
  206. index 50b6a890e76..9b74c3f70ce 100644
  207. --- a/src/libcephfs.cc
  208. +++ b/src/libcephfs.cc
  209. @@ -1915,8 +1915,8 @@ private:
  210.    }
  211.  };
  212.  
  213. -extern "C" int64_t ceph_ll_async_readv_writev(class ceph_mount_info *cmount,
  214. -                         struct ceph_ll_io_info *io_info)
  215. +extern "C" int64_t ceph_ll_nonblocking_readv_writev(class ceph_mount_info *cmount,
  216. +                           struct ceph_ll_io_info *io_info)
  217.  {
  218.    LL_Onfinish *onfinish = new LL_Onfinish(io_info);
  219.  
  220. diff --git a/src/libkmip b/src/libkmip
  221. --- a/src/libkmip
  222. +++ b/src/libkmip
  223. @@ -1 +1 @@
  224. -Subproject commit b25cde94c9b8686988ed1236bd807afe74991333
  225. +Subproject commit b25cde94c9b8686988ed1236bd807afe74991333-dirty
  226. diff --git a/src/rapidjson b/src/rapidjson
  227. --- a/src/rapidjson
  228. +++ b/src/rapidjson
  229. @@ -1 +1 @@
  230. -Subproject commit e4bde977440d4a00f820b6586899e48a972d2493
  231. +Subproject commit e4bde977440d4a00f820b6586899e48a972d2493-dirty
  232. diff --git a/src/test/client/async.cc b/src/test/client/nonblocking.cc
  233. similarity index 94%
  234. rename from src/test/client/async.cc
  235. rename to src/test/client/nonblocking.cc
  236. index 021f1036e4e..dafff45d50a 100644
  237. --- a/src/test/client/async.cc
  238. +++ b/src/test/client/nonblocking.cc
  239. @@ -61,8 +61,8 @@ TEST_F(TestClient, LlreadvLlwritev) {
  240.    std::unique_ptr<C_SaferCond> writefinish = nullptr;
  241.    std::unique_ptr<C_SaferCond> readfinish = nullptr;
  242.  
  243. -  writefinish.reset(new C_SaferCond("test-async"));
  244. -  readfinish.reset(new C_SaferCond("test-async"));
  245. +  writefinish.reset(new C_SaferCond("test-nonblocking"));
  246. +  readfinish.reset(new C_SaferCond("test-nonblocking"));
  247.  
  248.    int64_t rc;
  249.    bufferlist bl;
  250.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement