From patchwork Mon Dec 3 12:50:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 10709517 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3FEE16B1 for ; Mon, 3 Dec 2018 12:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4D0C2AB1A for ; Mon, 3 Dec 2018 12:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D86952ABBB; Mon, 3 Dec 2018 12:59:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AFE02AB1A for ; Mon, 3 Dec 2018 12:59:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725914AbeLCNAb (ORCPT ); Mon, 3 Dec 2018 08:00:31 -0500 Received: from m50211.mail.qiye.163.com ([123.125.50.211]:22216 "EHLO m50211.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726420AbeLCNAb (ORCPT ); Mon, 3 Dec 2018 08:00:31 -0500 Received: from atest-guest.localdomain (unknown [218.94.118.90]) by smtp3 (Coremail) with SMTP id PdOowEDpa0CfJgVcOwAAAA--.14S9; Mon, 03 Dec 2018 20:50:42 +0800 (CST) From: Dongsheng Yang To: idryomov@gmail.com, sage@redhat.com, elder@kernel.org, jdillama@redhat.com Cc: dongsheng.yang@easystack.cn, ceph-devel@vger.kernel.org Subject: [PATCH 07/11] libceph: journaling: trim object set when we found there is no client refer it Date: Mon, 3 Dec 2018 07:50:31 -0500 Message-Id: <1543841435-13652-8-git-send-email-dongsheng.yang@easystack.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1543841435-13652-1-git-send-email-dongsheng.yang@easystack.cn> References: <1543841435-13652-1-git-send-email-dongsheng.yang@easystack.cn> X-CM-TRANSID: PdOowEDpa0CfJgVcOwAAAA--.14S9 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFW8JrWktw18WF4DAr1UJrb_yoWrZFWfpr sxXr4SyrW0vF1furs7JrsYqFZ09rW0vFW7GrnIkF9ay3W7XrZIgF18JFyqqry7tr13G3Z8 tF4UJa15Ww42qFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JbK3ktUUUUU= X-Originating-IP: [218.94.118.90] X-CM-SenderInfo: 5grqw2pkhqwhp1dqwq5hdv52pwdfyhdfq/1tbigAISelrpN9XK6wAAsa Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When we found there is no client refre to the object set, we can remove the objects. Signed-off-by: Dongsheng Yang --- net/ceph/journaler.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/net/ceph/journaler.c b/net/ceph/journaler.c index e0dce2a..1a3651e 100644 --- a/net/ceph/journaler.c +++ b/net/ceph/journaler.c @@ -142,6 +142,10 @@ void ceph_journaler_destroy(struct ceph_journaler *journaler) } EXPORT_SYMBOL(ceph_journaler_destroy); +static int remove_set(struct ceph_journaler *journaler, uint64_t object_set); +static int set_minimum_set(struct ceph_journaler* journaler, + uint64_t minimum_set); + static int refresh(struct ceph_journaler *journaler, bool init) { int ret = 0; @@ -207,6 +211,34 @@ static int refresh(struct ceph_journaler *journaler, bool init) } spin_unlock(&journaler->meta_lock); + if (need_advance) { + spin_lock(&journaler->advancing_lock); + journaler->advancing = false; + journaler->active_set = active_set; + spin_unlock(&journaler->advancing_lock); + + queue_work(journaler->task_wq, &journaler->flush_work); + } + + // remove set if necessary + if (minimum_commit_set > minimum_set) { + uint64_t trim_set = minimum_set; + while (trim_set < minimum_commit_set) { + ret = remove_set(journaler, trim_set); + if (ret < 0 && ret != -ENOENT) { + pr_err("failed to trim object_set: %llu", trim_set); + return ret; + } + trim_set++; + } + + ret = set_minimum_set(journaler, minimum_commit_set); + if (ret < 0) { + pr_err("failed to set minimum set to %llu", minimum_commit_set); + return ret; + } + } + return 0; } @@ -1293,7 +1325,7 @@ static bool advance_object_set(struct ceph_journaler *journaler) pr_err("error in set active_set: %d", ret); } - queue_work(journaler->task_wq, &journaler->notify_update_work); + queue_work(journaler->notify_wq, &journaler->notify_update_work); return true; } @@ -1724,3 +1756,88 @@ int ceph_journaler_allocate_tag(struct ceph_journaler *journaler, return ret; } EXPORT_SYMBOL(ceph_journaler_allocate_tag); + +// trimming +static int ceph_journaler_obj_remove_sync(struct ceph_journaler *journaler, + struct ceph_object_id *oid, + struct ceph_object_locator *oloc) + +{ + struct ceph_osd_client *osdc = journaler->osdc; + struct ceph_osd_request *req; + int ret; + + req = ceph_osdc_alloc_request(osdc, NULL, 1, false, GFP_KERNEL); + if (!req) + return -ENOMEM; + + ceph_oid_copy(&req->r_base_oid, oid); + ceph_oloc_copy(&req->r_base_oloc, oloc); + req->r_flags = CEPH_OSD_FLAG_WRITE; + + osd_req_op_init(req, 0, CEPH_OSD_OP_DELETE, 0); + + ret = ceph_osdc_alloc_messages(req, GFP_KERNEL); + if (ret) + goto out_req; + + ceph_osdc_start_request(osdc, req, false); + ret = ceph_osdc_wait_request(osdc, req); + +out_req: + ceph_osdc_put_request(req); + return ret; +} + +static int remove_set(struct ceph_journaler *journaler, uint64_t object_set) +{ + uint64_t object_num = 0; + int splay_offset = 0; + struct ceph_object_id object_oid; + int ret = 0; + + ceph_oid_init(&object_oid); + for (splay_offset = 0; splay_offset < journaler->splay_width; splay_offset++) { + object_num = splay_offset + (object_set * journaler->splay_width); + if (!ceph_oid_empty(&object_oid)) { + ceph_oid_destroy(&object_oid); + ceph_oid_init(&object_oid); + } + ret = ceph_oid_aprintf(&object_oid, GFP_KERNEL, "%s%llu", + journaler->object_oid_prefix, object_num); + if (ret) { + pr_err("aprintf error : %d", ret); + goto out; + } + ret = ceph_journaler_obj_remove_sync(journaler, &object_oid, + &journaler->data_oloc); + if (ret < 0 && ret != -ENOENT) { + pr_err("%s: failed to remove object: %llu", + __func__, object_num); + goto out; + } + } + ret = 0; +out: + ceph_oid_destroy(&object_oid); + return ret; +} + +static int set_minimum_set(struct ceph_journaler* journaler, + uint64_t minimum_set) +{ + int ret = 0; + + ret = ceph_cls_journaler_set_minimum_set(journaler->osdc, + &journaler->header_oid, + &journaler->header_oloc, + minimum_set); + if (ret < 0) { + pr_err("%s: failed to set_minimum_set: %d", __func__, ret); + return ret; + } + + queue_work(journaler->notify_wq, &journaler->notify_update_work); + + return ret; +}