From patchwork Tue May 13 09:12:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Min Chen X-Patchwork-Id: 4163881 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DA413BFF02 for ; Tue, 13 May 2014 09:20:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BDA5E20155 for ; Tue, 13 May 2014 09:20:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C9ED42034E for ; Tue, 13 May 2014 09:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759460AbaEMJUi (ORCPT ); Tue, 13 May 2014 05:20:38 -0400 Received: from m199-177.yeah.net ([123.58.177.199]:60224 "EHLO m199-177.yeah.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758769AbaEMJUb (ORCPT ); Tue, 13 May 2014 05:20:31 -0400 X-Greylist: delayed 484 seconds by postgrey-1.27 at vger.kernel.org; Tue, 13 May 2014 05:20:31 EDT Received: from localhost.localdomain (unknown [202.197.9.8]) by m199-177.yeah.net (HMail) with ESMTPA id 400F011030C6; Tue, 13 May 2014 17:12:24 +0800 (CST) From: Min Chen To: josh.durgin@inktank.com Cc: ceph-devel@vger.kernel.org Subject: [PATCH 2/3] *v2* librbd: copy-on-read for clones, read entire object from parent Date: Tue, 13 May 2014 17:12:14 +0800 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-HM-Spam-Status: e1koWUFPN1dZCBgUCR5ZQU9LVUhLT0JCTU9CS09MQ05KTVdZCQ4XHghZQV koKz0kKDQ9Lz06MjckMjUkMz46Pz4pQU1VSkhCQDYjJCI#KCQyNSQzPjo*PilBS1VIT0lAKy8pJD U0JDI1JDM#Oj8#KUFJVUNOQ0A4NC41LykiJDg1QUtVSU1DQCk#PDI0NSQ6KDI6QUhVT09NQCspNC 0yNTg#JDMuNTo1QUJVQkpOQD8iNTo2MjgkMiskNTQkMjUkMz46Pz4pQUtVTENCQD8wMjYkNTQ1Pk FLVUtANi43LzIkKTgrLyQ*Mj09Pik#NS8kMjUkMz46Pz4pQU9VS0tJQDIrJEokNjI1Li8#JDg1Ly RLJEpLQUtVS0AyKyRISyQ2MjUuLz4kODUvJEskTktBS1VLQDIrJE4kNjI1Li8#JDg1LyRLJEpLQU tVS0AyKyQvND86IiQ4NS8kSyRKS0tBS1VMSk1AMiskSiQzNC4pJDg1LyRLJEpLS0FLVUtANTQvJD 06NjQuKCQ*NDY6MjUkKCs9JD06MjdBSktVS0AoLjkkPkFKVU5OQD01JCguOSQ#NSw0KT8oJDM3MS RKS0tJS0pBS1VJQ1kG X-HM-Sender-Digest: e1kSHx4VD1lBWUc6ORA6Nyo*Pzo0LjpLKj8yOjQuOjQwChVVSlVKSEJC QkxJSE9PT0xKVTMWGhIXVRYSFRgTHhU7DhkOFQ8OEAIXEhVVGBQWRVlXWQweGVlBHRoXCB5XWQgB WUFNSU1DN1dZEgtZQVlJS0lVSkJMVUJVQ1kG Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP rbd copy-on-read is implmented in AioRequest. If object extent doesn't exist in clone, then read the entire range of object from parent. Bufferlist m_entire_data is added to AioRequest to save object instead of m_read_data which just keeps data read Signed-off-by: Min Chen Signed-off-by: Li Wang Signed-off-by: Yunchuan Wen Chen --- src/librbd/AioRequest.cc | 51 +++++++++++++++++++++++++++++++++++++++++++--- src/librbd/AioRequest.h | 3 +++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/librbd/AioRequest.cc b/src/librbd/AioRequest.cc index 4cc6b4e..1a372aa 100644 --- a/src/librbd/AioRequest.cc +++ b/src/librbd/AioRequest.cc @@ -22,7 +22,7 @@ namespace librbd { m_ictx(NULL), m_ioctx(NULL), m_object_no(0), m_object_off(0), m_object_len(0), m_snap_id(CEPH_NOSNAP), m_completion(NULL), m_parent_completion(NULL), - m_hide_enoent(false) {} + m_hide_enoent(false), m_parent_completion_cor(NULL){} AioRequest::AioRequest(ImageCtx *ictx, const std::string &oid, uint64_t objectno, uint64_t off, uint64_t len, librados::snap_t snap_id, @@ -31,13 +31,17 @@ namespace librbd { m_ictx(ictx), m_ioctx(&ictx->data_ctx), m_oid(oid), m_object_no(objectno), m_object_off(off), m_object_len(len), m_snap_id(snap_id), m_completion(completion), m_parent_completion(NULL), - m_hide_enoent(hide_enoent) {} + m_hide_enoent(hide_enoent), m_parent_completion_cor(NULL) {} AioRequest::~AioRequest() { if (m_parent_completion) { m_parent_completion->release(); m_parent_completion = NULL; } + if (m_parent_completion_cor) { + m_parent_completion_cor->release(); + m_parent_completion_cor = NULL; + } } void AioRequest::read_from_parent(vector >& image_extents) @@ -52,6 +56,19 @@ namespace librbd { m_parent_completion); } + //copy-on-read : read the entire object from parent, using bufferlist m_entire_object + void AioRequest::read_from_parent_COR(vector >& image_extents) + { + assert(!m_parent_completion_cor); + m_parent_completion_cor = aio_create_completion_internal(this, rbd_req_cb); + ldout(m_ictx->cct, 20) << "read_from_parent_COR this = " << this + << " parent completion cor " << m_parent_completion_cor + << " extents " << image_extents + << dendl; + aio_read(m_ictx->parent, image_extents, NULL, &m_entire_object, + m_parent_completion_cor); + } + /** read **/ bool AioRead::should_complete(int r) @@ -81,11 +98,39 @@ namespace librbd { uint64_t object_overlap = m_ictx->prune_parent_extents(image_extents, image_overlap); if (object_overlap) { m_tried_parent = true; - read_from_parent(image_extents); + if (COR) {//copy-on-read option + vector > extend_image_extents; + //extend range to entire object + Striper::extent_to_file(m_ictx->cct, &m_ictx->layout, + m_object_no, 0, m_ictx->layout.fl_object_size, + extend_image_extents); + //read entire object from parent , and put it in m_entire_object + read_from_parent_COR(extend_image_extents); + } else { + read_from_parent(image_extents); + } return false; } } + if (COR) {//copy-on-read option + //if read entire object from parent success + if (m_tried_parent && r > 0) { + vector > image_extents; + Striper::extent_to_file(m_ictx->cct, &m_ictx->layout, + m_object_no, m_object_off, m_object_len, + image_extents); + uint64_t image_overlap = 0; + int r = m_ictx->get_parent_overlap(m_snap_id, &image_overlap); + if (r < 0) { + assert(0 == "FIXME"); + } + m_ictx->prune_parent_extents(image_extents, image_overlap); + // copy the read range to m_read_data + m_read_data.substr_of(m_entire_object, m_object_off, m_object_len); + } + } + return true; } diff --git a/src/librbd/AioRequest.h b/src/librbd/AioRequest.h index d6103f9..00349b2 100644 --- a/src/librbd/AioRequest.h +++ b/src/librbd/AioRequest.h @@ -47,6 +47,7 @@ namespace librbd { protected: void read_from_parent(vector >& image_extents); + void read_from_parent_COR(vector >& image_extents); ImageCtx *m_ictx; librados::IoCtx *m_ioctx; @@ -57,6 +58,8 @@ namespace librbd { AioCompletion *m_parent_completion; ceph::bufferlist m_read_data; bool m_hide_enoent; + ceph::bufferlist m_entire_object;//copy-on-read : store the entire object + AioCompletion *m_parent_completion_cor;//copy-on-read : AioCompletion for read from parent }; class AioRead : public AioRequest {