{"action":"created","comment":{"url":"https://api.github.com/repos/ceph/ceph/pulls/comments/23064605","id":23064605,"diff_hunk":"@@ -52,37 +57,160 @@ namespace librbd {\n \t     m_parent_completion, 0);\n   }\n \n+  static inline bool is_cor(ImageCtx *ictx, librados::snap_t snap_id) {\n+     return (ictx->cct->_conf->rbd_clone_copy_on_read) &&\n+             (!ictx->read_only) && (snap_id == CEPH_NOSNAP);\n+  }\n+\n   /** read **/\n \n+  void AioRead::guard_read()\n+  {\n+    RWLock::RLocker l(m_ictx->snap_lock);\n+    RWLock::RLocker l2(m_ictx->parent_lock);\n+\n+    vector<pair<uint64_t,uint64_t> > image_extents;\n+    Striper::extent_to_file(m_ictx->cct, &m_ictx->layout,\n+                            m_object_no, 0, m_ictx->layout.fl_object_size,\n+                            image_extents);\n+\n+    uint64_t image_overlap = 0;\n+    m_ictx->get_parent_overlap(m_snap_id, &image_overlap);\n+    uint64_t object_overlap =\n+      m_ictx->prune_parent_extents(image_extents, image_overlap);\n+    if (object_overlap) {\n+      ldout(m_ictx->cct, 20) << __func__ << \" guarding read\" << dendl;\n+      m_state = LIBRBD_AIO_READ_GUARD;\n+    }\n+  }\n+\n   bool AioRead::should_complete(int r)\n   {\n-    ldout(m_ictx->cct, 20) << \"should_complete \" << this << \" \" << m_oid << \" \" << m_object_off << \"~\" << m_object_len\n-\t\t\t   << \" r = \" << r << dendl;\n+    ldout(m_ictx->cct, 20) << \"AioRead::should_complete \" << this\n+                           << \" \" << m_oid << \" \" << m_object_off\n+                           << \"~\" << m_object_len << \" r = \" << r\n+                           << \" cor = \" << is_cor(m_ictx, m_snap_id)\n+                           << \" readonly = \" << m_ictx->read_only\n+                           << dendl;\n \n-    if (!m_tried_parent && r == -ENOENT) {\n-      RWLock::RLocker l(m_ictx->snap_lock);\n-      RWLock::RLocker l2(m_ictx->parent_lock);\n+    bool finished = true;\n \n-      // calculate reverse mapping onto the image\n-      vector<pair<uint64_t,uint64_t> > image_extents;\n-      Striper::extent_to_file(m_ictx->cct, &m_ictx->layout,\n-\t\t\t    m_object_no, m_object_off, m_object_len,\n-\t\t\t    image_extents);\n+    switch (m_state) {\n+    case LIBRBD_AIO_READ_GUARD:\n+      ldout(m_ictx->cct, 20) << \"should_complete \" << this\n+                             << \" READ_CHECK_GUARD\" << dendl;\n+\n+      // This is the step to read from parent\n+      if (!m_tried_parent && r == -ENOENT) {\n+        RWLock::RLocker l(m_ictx->snap_lock);\n+        RWLock::RLocker l2(m_ictx->parent_lock);\n+\n+        // calculate reverse mapping onto the image\n+        vector<pair<uint64_t,uint64_t> > image_extents;\n+        Striper::extent_to_file(m_ictx->cct, &m_ictx->layout,\n+\t\t\t        m_object_no, m_object_off, m_object_len,\n+\t\t\t        image_extents);\n+\n+        uint64_t image_overlap = 0;\n+        r = m_ictx->get_parent_overlap(m_snap_id, &image_overlap);\n+        if (r < 0) {\n+          assert(0 == \"FIXME\");\n+        }\n+        uint64_t object_overlap = m_ictx->prune_parent_extents(image_extents, image_overlap);\n+        if (object_overlap) {\n+          m_tried_parent = true;\n+\n+          if (is_cor(m_ictx, m_snap_id)) {\n+            // If there is a valid object being coyping up, directly extract\n+            // content and finish up.\n+            Mutex::Locker l3(m_ictx->copyup_list_lock);\n+\n+            map<uint64_t, CopyupRequest*>::iterator it =\n+              m_ictx->copyup_list.find(m_object_no);\n+            if (it != m_ictx->copyup_list.end()) {","path":"src/librbd/AioRequest.cc","position":116,"original_position":116,"commit_id":"f40e21ea2a1b6385c642f24c1653c18ce6864047","original_commit_id":"f40e21ea2a1b6385c642f24c1653c18ce6864047","user":{"login":"cchengleo","id":1903817,"avatar_url":"https://avatars.githubusercontent.com/u/1903817?v=3","gravatar_id":"","url":"https://api.github.com/users/cchengleo","html_url":"https://github.com/cchengleo","followers_url":"https://api.github.com/users/cchengleo/followers","following_url":"https://api.github.com/users/cchengleo/following{/other_user}","gists_url":"https://api.github.com/users/cchengleo/gists{/gist_id}","starred_url":"https://api.github.com/users/cchengleo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cchengleo/subscriptions","organizations_url":"https://api.github.com/users/cchengleo/orgs","repos_url":"https://api.github.com/users/cchengleo/repos","events_url":"https://api.github.com/users/cchengleo/events{/privacy}","received_events_url":"https://api.github.com/users/cchengleo/received_events","type":"User","site_admin":false},"body":"In the test case, I do noticed the temporary copyup buffer can satisfy later request, especially when read small I/O while the object size is big.","created_at":"2015-01-16T06:02:45Z","updated_at":"2015-01-16T06:02:45Z","html_url":"https://github.com/ceph/ceph/pull/3040#discussion_r23064605","pull_request_url":"https://api.github.com/repos/ceph/ceph/pulls/3040","_links":{"self":{"href":"https://api.github.com/repos/ceph/ceph/pulls/comments/23064605"},"html":{"href":"https://github.com/ceph/ceph/pull/3040#discussion_r23064605"},"pull_request":{"href":"https://api.github.com/repos/ceph/ceph/pulls/3040"}}},"pull_request":{"url":"https://api.github.com/repos/ceph/ceph/pulls/3040","id":25251353,"html_url":"https://github.com/ceph/ceph/pull/3040","diff_url":"https://github.com/ceph/ceph/pull/3040.diff","patch_url":"https://github.com/ceph/ceph/pull/3040.patch","issue_url":"https://api.github.com/repos/ceph/ceph/issues/3040","number":3040,"state":"open","locked":false,"title":"wip copy on read","user":{"login":"cchengleo","id":1903817,"avatar_url":"https://avatars.githubusercontent.com/u/1903817?v=3","gravatar_id":"","url":"https://api.github.com/users/cchengleo","html_url":"https://github.com/cchengleo","followers_url":"https://api.github.com/users/cchengleo/followers","following_url":"https://api.github.com/users/cchengleo/following{/other_user}","gists_url":"https://api.github.com/users/cchengleo/gists{/gist_id}","starred_url":"https://api.github.com/users/cchengleo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cchengleo/subscriptions","organizations_url":"https://api.github.com/users/cchengleo/orgs","repos_url":"https://api.github.com/users/cchengleo/repos","events_url":"https://api.github.com/users/cchengleo/events{/privacy}","received_events_url":"https://api.github.com/users/cchengleo/received_events","type":"User","site_admin":false},"body":"This is the copy-on-read feature based on both cmgitdream's (https://github.com/ceph/ceph/pull/2158) and cchengleo's (https://github.com/ceph/ceph/pull/2587) improvement. Please close https://github.com/ceph/ceph/pull/3030 and https://github.com/ceph/ceph/pull/2852 as it is easier to merge into this.","created_at":"2014-12-01T07:27:42Z","updated_at":"2015-01-16T06:02:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"52a1f670d6ed007c2c2e955019e49675340190b4","assignee":{"login":"dillaman","id":4739042,"avatar_url":"https://avatars.githubusercontent.com/u/4739042?v=3","gravatar_id":"","url":"https://api.github.com/users/dillaman","html_url":"https://github.com/dillaman","followers_url":"https://api.github.com/users/dillaman/followers","following_url":"https://api.github.com/users/dillaman/following{/other_user}","gists_url":"https://api.github.com/users/dillaman/gists{/gist_id}","starred_url":"https://api.github.com/users/dillaman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dillaman/subscriptions","organizations_url":"https://api.github.com/users/dillaman/orgs","repos_url":"https://api.github.com/users/dillaman/repos","events_url":"https://api.github.com/users/dillaman/events{/privacy}","received_events_url":"https://api.github.com/users/dillaman/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/ceph/ceph/pulls/3040/commits","review_comments_url":"https://api.github.com/repos/ceph/ceph/pulls/3040/comments","review_comment_url":"https://api.github.com/repos/ceph/ceph/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ceph/ceph/issues/3040/comments","statuses_url":"https://api.github.com/repos/ceph/ceph/statuses/f40e21ea2a1b6385c642f24c1653c18ce6864047","head":{"label":"cchengleo:wip-copy-on-read","ref":"wip-copy-on-read","sha":"f40e21ea2a1b6385c642f24c1653c18ce6864047","user":{"login":"cchengleo","id":1903817,"avatar_url":"https://avatars.githubusercontent.com/u/1903817?v=3","gravatar_id":"","url":"https://api.github.com/users/cchengleo","html_url":"https://github.com/cchengleo","followers_url":"https://api.github.com/users/cchengleo/followers","following_url":"https://api.github.com/users/cchengleo/following{/other_user}","gists_url":"https://api.github.com/users/cchengleo/gists{/gist_id}","starred_url":"https://api.github.com/users/cchengleo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cchengleo/subscriptions","organizations_url":"https://api.github.com/users/cchengleo/orgs","repos_url":"https://api.github.com/users/cchengleo/repos","events_url":"https://api.github.com/users/cchengleo/events{/privacy}","received_events_url":"https://api.github.com/users/cchengleo/received_events","type":"User","site_admin":false},"repo":{"id":23717668,"name":"ceph","full_name":"cchengleo/ceph","owner":{"login":"cchengleo","id":1903817,"avatar_url":"https://avatars.githubusercontent.com/u/1903817?v=3","gravatar_id":"","url":"https://api.github.com/users/cchengleo","html_url":"https://github.com/cchengleo","followers_url":"https://api.github.com/users/cchengleo/followers","following_url":"https://api.github.com/users/cchengleo/following{/other_user}","gists_url":"https://api.github.com/users/cchengleo/gists{/gist_id}","starred_url":"https://api.github.com/users/cchengleo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cchengleo/subscriptions","organizations_url":"https://api.github.com/users/cchengleo/orgs","repos_url":"https://api.github.com/users/cchengleo/repos","events_url":"https://api.github.com/users/cchengleo/events{/privacy}","received_events_url":"https://api.github.com/users/cchengleo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cchengleo/ceph","description":"Ceph is a distributed object, block, and file storage platform ","fork":true,"url":"https://api.github.com/repos/cchengleo/ceph","forks_url":"https://api.github.com/repos/cchengleo/ceph/forks","keys_url":"https://api.github.com/repos/cchengleo/ceph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cchengleo/ceph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cchengleo/ceph/teams","hooks_url":"https://api.github.com/repos/cchengleo/ceph/hooks","issue_events_url":"https://api.github.com/repos/cchengleo/ceph/issues/events{/number}","events_url":"https://api.github.com/repos/cchengleo/ceph/events","assignees_url":"https://api.github.com/repos/cchengleo/ceph/assignees{/user}","branches_url":"https://api.github.com/repos/cchengleo/ceph/branches{/branch}","tags_url":"https://api.github.com/repos/cchengleo/ceph/tags","blobs_url":"https://api.github.com/repos/cchengleo/ceph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cchengleo/ceph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cchengleo/ceph/git/refs{/sha}","trees_url":"https://api.github.com/repos/cchengleo/ceph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cchengleo/ceph/statuses/{sha}","languages_url":"https://api.github.com/repos/cchengleo/ceph/languages","stargazers_url":"https://api.github.com/repos/cchengleo/ceph/stargazers","contributors_url":"https://api.github.com/repos/cchengleo/ceph/contributors","subscribers_url":"https://api.github.com/repos/cchengleo/ceph/subscribers","subscription_url":"https://api.github.com/repos/cchengleo/ceph/subscription","commits_url":"https://api.github.com/repos/cchengleo/ceph/commits{/sha}","git_commits_url":"https://api.github.com/repos/cchengleo/ceph/git/commits{/sha}","comments_url":"https://api.github.com/repos/cchengleo/ceph/comments{/number}","issue_comment_url":"https://api.github.com/repos/cchengleo/ceph/issues/comments/{number}","contents_url":"https://api.github.com/repos/cchengleo/ceph/contents/{+path}","compare_url":"https://api.github.com/repos/cchengleo/ceph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cchengleo/ceph/merges","archive_url":"https://api.github.com/repos/cchengleo/ceph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cchengleo/ceph/downloads","issues_url":"https://api.github.com/repos/cchengleo/ceph/issues{/number}","pulls_url":"https://api.github.com/repos/cchengleo/ceph/pulls{/number}","milestones_url":"https://api.github.com/repos/cchengleo/ceph/milestones{/number}","notifications_url":"https://api.github.com/repos/cchengleo/ceph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cchengleo/ceph/labels{/name}","releases_url":"https://api.github.com/repos/cchengleo/ceph/releases{/id}","created_at":"2014-09-05T20:40:16Z","updated_at":"2015-01-09T20:13:12Z","pushed_at":"2015-01-16T05:03:24Z","git_url":"git://github.com/cchengleo/ceph.git","ssh_url":"git@github.com:cchengleo/ceph.git","clone_url":"https://github.com/cchengleo/ceph.git","svn_url":"https://github.com/cchengleo/ceph","homepage":"http://ceph.com","size":100207,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ceph:master","ref":"master","sha":"3eceda9f3342fc64f4f37bcea43df1eb87d32029","user":{"login":"ceph","id":1015767,"avatar_url":"https://avatars.githubusercontent.com/u/1015767?v=3","gravatar_id":"","url":"https://api.github.com/users/ceph","html_url":"https://github.com/ceph","followers_url":"https://api.github.com/users/ceph/followers","following_url":"https://api.github.com/users/ceph/following{/other_user}","gists_url":"https://api.github.com/users/ceph/gists{/gist_id}","starred_url":"https://api.github.com/users/ceph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ceph/subscriptions","organizations_url":"https://api.github.com/users/ceph/orgs","repos_url":"https://api.github.com/users/ceph/repos","events_url":"https://api.github.com/users/ceph/events{/privacy}","received_events_url":"https://api.github.com/users/ceph/received_events","type":"Organization","site_admin":false},"repo":{"id":2310495,"name":"ceph","full_name":"ceph/ceph","owner":{"login":"ceph","id":1015767,"avatar_url":"https://avatars.githubusercontent.com/u/1015767?v=3","gravatar_id":"","url":"https://api.github.com/users/ceph","html_url":"https://github.com/ceph","followers_url":"https://api.github.com/users/ceph/followers","following_url":"https://api.github.com/users/ceph/following{/other_user}","gists_url":"https://api.github.com/users/ceph/gists{/gist_id}","starred_url":"https://api.github.com/users/ceph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ceph/subscriptions","organizations_url":"https://api.github.com/users/ceph/orgs","repos_url":"https://api.github.com/users/ceph/repos","events_url":"https://api.github.com/users/ceph/events{/privacy}","received_events_url":"https://api.github.com/users/ceph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ceph/ceph","description":"Ceph is a distributed object, block, and file storage platform ","fork":false,"url":"https://api.github.com/repos/ceph/ceph","forks_url":"https://api.github.com/repos/ceph/ceph/forks","keys_url":"https://api.github.com/repos/ceph/ceph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ceph/ceph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ceph/ceph/teams","hooks_url":"https://api.github.com/repos/ceph/ceph/hooks","issue_events_url":"https://api.github.com/repos/ceph/ceph/issues/events{/number}","events_url":"https://api.github.com/repos/ceph/ceph/events","assignees_url":"https://api.github.com/repos/ceph/ceph/assignees{/user}","branches_url":"https://api.github.com/repos/ceph/ceph/branches{/branch}","tags_url":"https://api.github.com/repos/ceph/ceph/tags","blobs_url":"https://api.github.com/repos/ceph/ceph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ceph/ceph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ceph/ceph/git/refs{/sha}","trees_url":"https://api.github.com/repos/ceph/ceph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ceph/ceph/statuses/{sha}","languages_url":"https://api.github.com/repos/ceph/ceph/languages","stargazers_url":"https://api.github.com/repos/ceph/ceph/stargazers","contributors_url":"https://api.github.com/repos/ceph/ceph/contributors","subscribers_url":"https://api.github.com/repos/ceph/ceph/subscribers","subscription_url":"https://api.github.com/repos/ceph/ceph/subscription","commits_url":"https://api.github.com/repos/ceph/ceph/commits{/sha}","git_commits_url":"https://api.github.com/repos/ceph/ceph/git/commits{/sha}","comments_url":"https://api.github.com/repos/ceph/ceph/comments{/number}","issue_comment_url":"https://api.github.com/repos/ceph/ceph/issues/comments/{number}","contents_url":"https://api.github.com/repos/ceph/ceph/contents/{+path}","compare_url":"https://api.github.com/repos/ceph/ceph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ceph/ceph/merges","archive_url":"https://api.github.com/repos/ceph/ceph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ceph/ceph/downloads","issues_url":"https://api.github.com/repos/ceph/ceph/issues{/number}","pulls_url":"https://api.github.com/repos/ceph/ceph/pulls{/number}","milestones_url":"https://api.github.com/repos/ceph/ceph/milestones{/number}","notifications_url":"https://api.github.com/repos/ceph/ceph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ceph/ceph/labels{/name}","releases_url":"https://api.github.com/repos/ceph/ceph/releases{/id}","created_at":"2011-09-01T21:41:26Z","updated_at":"2015-01-16T05:58:17Z","pushed_at":"2015-01-16T05:58:20Z","git_url":"git://github.com/ceph/ceph.git","ssh_url":"git@github.com:ceph/ceph.git","clone_url":"https://github.com/ceph/ceph.git","svn_url":"https://github.com/ceph/ceph","homepage":"http://ceph.com","size":326289,"stargazers_count":1080,"watchers_count":1080,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":550,"mirror_url":null,"open_issues_count":84,"forks":550,"open_issues":84,"watchers":1080,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ceph/ceph/pulls/3040"},"html":{"href":"https://github.com/ceph/ceph/pull/3040"},"issue":{"href":"https://api.github.com/repos/ceph/ceph/issues/3040"},"comments":{"href":"https://api.github.com/repos/ceph/ceph/issues/3040/comments"},"review_comments":{"href":"https://api.github.com/repos/ceph/ceph/pulls/3040/comments"},"review_comment":{"href":"https://api.github.com/repos/ceph/ceph/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ceph/ceph/pulls/3040/commits"},"statuses":{"href":"https://api.github.com/repos/ceph/ceph/statuses/f40e21ea2a1b6385c642f24c1653c18ce6864047"}}}}