From patchwork Wed Feb 10 05:07:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 12079875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86DA1C433E6 for ; Wed, 10 Feb 2021 05:09:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6113A64E4B for ; Wed, 10 Feb 2021 05:09:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230226AbhBJFJi (ORCPT ); Wed, 10 Feb 2021 00:09:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:40764 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230475AbhBJFJa (ORCPT ); Wed, 10 Feb 2021 00:09:30 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 731EAB0AE; Wed, 10 Feb 2021 05:08:24 +0000 (UTC) From: Coly Li To: axboe@kernel.dk Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, Jianpeng Ma , Qiaowei Ren , Coly Li Subject: [PATCH 12/20] bcache: get allocated pages from specific owner Date: Wed, 10 Feb 2021 13:07:34 +0800 Message-Id: <20210210050742.31237-13-colyli@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210210050742.31237-1-colyli@suse.de> References: <20210210050742.31237-1-colyli@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Jianpeng Ma This patch implements bch_get_allocated_pages() of the buddy to be used to get allocated pages from specific owner. Signed-off-by: Jianpeng Ma Co-authored-by: Qiaowei Ren Signed-off-by: Coly Li --- drivers/md/bcache/nvm-pages.c | 39 +++++++++++++++++++++++++++++++++++ drivers/md/bcache/nvm-pages.h | 6 ++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/md/bcache/nvm-pages.c b/drivers/md/bcache/nvm-pages.c index b40bdbac873f..2b079a277e88 100644 --- a/drivers/md/bcache/nvm-pages.c +++ b/drivers/md/bcache/nvm-pages.c @@ -374,6 +374,45 @@ void *bch_nvm_alloc_pages(int order, const char *owner_uuid) } EXPORT_SYMBOL_GPL(bch_nvm_alloc_pages); +struct bch_extent *bch_get_allocated_pages(const char *owner_uuid) +{ + struct bch_owner_list *owner_list = find_owner_list(owner_uuid, false); + struct bch_nvm_alloced_recs *alloced_recs; + struct bch_extent *head = NULL, *e, *tmp; + int i; + + if (!owner_list) + return NULL; + + for (i = 0; i < only_set->total_namespaces_nr; i++) { + struct list_head *l; + + alloced_recs = owner_list->alloced_recs[i]; + + if (!alloced_recs || alloced_recs->nr == 0) + continue; + + l = alloced_recs->extent_head.next; + while (l != &alloced_recs->extent_head) { + e = container_of(l, struct bch_extent, list); + tmp = kzalloc(sizeof(*tmp), GFP_KERNEL|__GFP_NOFAIL); + + INIT_LIST_HEAD(&tmp->list); + tmp->kaddr = e->kaddr; + tmp->nr = e->nr; + + if (head) + list_add_tail(&tmp->list, &head->list); + else + head = tmp; + + l = l->next; + } + } + return head; +} +EXPORT_SYMBOL_GPL(bch_get_allocated_pages); + static int init_owner_info(struct bch_nvm_namespace *ns) { struct bch_owner_list_head *owner_list_head; diff --git a/drivers/md/bcache/nvm-pages.h b/drivers/md/bcache/nvm-pages.h index 1bc3129f2482..8ffae11c7c61 100644 --- a/drivers/md/bcache/nvm-pages.h +++ b/drivers/md/bcache/nvm-pages.h @@ -81,6 +81,7 @@ int bch_nvm_init(void); void bch_nvm_exit(void); void *bch_nvm_alloc_pages(int order, const char *owner_uuid); void bch_nvm_free_pages(void *addr, int order, const char *owner_uuid); +struct bch_extent *bch_get_allocated_pages(const char *owner_uuid); #else @@ -101,6 +102,11 @@ static inline void *bch_nvm_alloc_pages(int order, const char *owner_uuid) static inline void bch_nvm_free_pages(void *addr, int order, const char *owner_uuid) { } +static inline struct bch_extent *bch_get_allocated_pages(const char *owner_uuid) +{ + return NULL; +} + #endif /* CONFIG_BCACHE_NVM_PAGES */ #endif /* _BCACHE_NVM_PAGES_H */