From patchwork Thu Mar 14 00:11:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10851977 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 009F217DF for ; Thu, 14 Mar 2019 00:14:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEACC28756 for ; Thu, 14 Mar 2019 00:14:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D339428796; Thu, 14 Mar 2019 00:14:09 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6D74A28756 for ; Thu, 14 Mar 2019 00:14:09 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 1EBF5720019; Wed, 13 Mar 2019 17:14:09 -0700 (PDT) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 16A21720012 for ; Wed, 13 Mar 2019 17:14:07 -0700 (PDT) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3E39FAC4B; Thu, 14 Mar 2019 00:14:06 +0000 (UTC) From: NeilBrown To: Andreas Dilger , James Simmons , Oleg Drokin Date: Thu, 14 Mar 2019 11:11:50 +1100 Message-ID: <155252230996.26912.15547976644328023498.stgit@noble.brown> In-Reply-To: <155252182126.26912.1842463462595601611.stgit@noble.brown> References: <155252182126.26912.1842463462595601611.stgit@noble.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [lustre-devel] [PATCH 12/32] lustre: lnet: merge lnet_md_alloc into lnet_md_build. X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" X-Virus-Scanned: ClamAV using ClamSMTP lnet_md_alloc is only called twice, each time immediately before a call to lnet_md_build, and these are the only calls to lnet_md_build(). So simplify the code by merging lnet_md_alloc into lnet_md_build. Signed-off-by: NeilBrown --- .../staging/lustre/include/linux/lnet/lib-lnet.h | 26 -------- drivers/staging/lustre/lnet/lnet/lib-md.c | 63 ++++++++++++-------- 2 files changed, 38 insertions(+), 51 deletions(-) diff --git a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h index 7275d517df5a..fca1c19a3c84 100644 --- a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h +++ b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h @@ -189,32 +189,6 @@ lnet_net_lock_current(void) #define MAX_PORTALS 64 -static inline struct lnet_libmd * -lnet_md_alloc(struct lnet_md *umd) -{ - struct lnet_libmd *md; - unsigned int size; - unsigned int niov; - - if (umd->options & LNET_MD_KIOV) { - niov = umd->length; - size = offsetof(struct lnet_libmd, md_iov.kiov[niov]); - } else { - niov = 1; - size = offsetof(struct lnet_libmd, md_iov.iov[niov]); - } - - md = kzalloc(size, GFP_NOFS); - if (md) { - /* Set here in case of early free */ - md->md_options = umd->options; - md->md_niov = niov; - INIT_LIST_HEAD(&md->md_list); - } - - return md; -} - struct lnet_libhandle *lnet_res_lh_lookup(struct lnet_res_container *rec, u64 cookie); void lnet_res_lh_initialize(struct lnet_res_container *rec, diff --git a/drivers/staging/lustre/lnet/lnet/lib-md.c b/drivers/staging/lustre/lnet/lnet/lib-md.c index fdca4655206e..26c560a1e8b9 100644 --- a/drivers/staging/lustre/lnet/lnet/lib-md.c +++ b/drivers/staging/lustre/lnet/lnet/lib-md.c @@ -171,12 +171,29 @@ int lnet_cpt_of_md(struct lnet_libmd *md, unsigned int offset) return cpt; } -static int -lnet_md_build(struct lnet_libmd *lmd, struct lnet_md *umd, int unlink) +static struct lnet_libmd * +lnet_md_build(struct lnet_md *umd, int unlink) { int i; unsigned int niov; int total_length = 0; + struct lnet_libmd *lmd; + unsigned int size; + + if (umd->options & LNET_MD_KIOV) { + niov = umd->length; + size = offsetof(struct lnet_libmd, md_iov.kiov[niov]); + } else { + niov = 1; + size = offsetof(struct lnet_libmd, md_iov.iov[niov]); + } + + lmd = kzalloc(size, GFP_NOFS); + if (!lmd) + return ERR_PTR(-ENOMEM); + + lmd->md_niov = niov; + INIT_LIST_HEAD(&lmd->md_list); lmd->md_me = NULL; lmd->md_start = umd->start; @@ -199,8 +216,10 @@ lnet_md_build(struct lnet_libmd *lmd, struct lnet_md *umd, int unlink) for (i = 0; i < (int)niov; i++) { /* We take the page pointer on trust */ if (lmd->md_iov.kiov[i].bv_offset + - lmd->md_iov.kiov[i].bv_len > PAGE_SIZE) - return -EINVAL; /* invalid length */ + lmd->md_iov.kiov[i].bv_len > PAGE_SIZE) { + kfree(lmd); + return ERR_PTR(-EINVAL); /* invalid length */ + } total_length += lmd->md_iov.kiov[i].bv_len; } @@ -209,8 +228,10 @@ lnet_md_build(struct lnet_libmd *lmd, struct lnet_md *umd, int unlink) if ((umd->options & LNET_MD_MAX_SIZE) && /* max size used */ (umd->max_size < 0 || - umd->max_size > total_length)) /* illegal max_size */ - return -EINVAL; + umd->max_size > total_length)) { /* illegal max_size */ + kfree(lmd); + return ERR_PTR(-EINVAL); + } } else { /* contiguous */ lmd->md_length = umd->length; niov = 1; @@ -220,11 +241,13 @@ lnet_md_build(struct lnet_libmd *lmd, struct lnet_md *umd, int unlink) if ((umd->options & LNET_MD_MAX_SIZE) && /* max size used */ (umd->max_size < 0 || - umd->max_size > (int)umd->length)) /* illegal max_size */ - return -EINVAL; + umd->max_size > (int)umd->length)) { /* illegal max_size */ + kfree(lmd); + return ERR_PTR(-EINVAL); + } } - return 0; + return lmd; } /* must be called with resource lock held */ @@ -341,13 +364,9 @@ LNetMDAttach(struct lnet_handle_me meh, struct lnet_md umd, return -EINVAL; } - md = lnet_md_alloc(&umd); - if (!md) - return -ENOMEM; - - rc = lnet_md_build(md, &umd, unlink); - if (rc) - goto out_free; + md = lnet_md_build(&umd, unlink); + if (IS_ERR(md)) + return PTR_ERR(md); cpt = lnet_cpt_of_cookie(meh.cookie); @@ -381,7 +400,6 @@ LNetMDAttach(struct lnet_handle_me meh, struct lnet_md umd, out_unlock: lnet_res_unlock(cpt); -out_free: kfree(md); return rc; } @@ -421,13 +439,9 @@ LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink, return -EINVAL; } - md = lnet_md_alloc(&umd); - if (!md) - return -ENOMEM; - - rc = lnet_md_build(md, &umd, unlink); - if (rc) - goto out_free; + md = lnet_md_build(&umd, unlink); + if (IS_ERR(md)) + return PTR_ERR(md); cpt = lnet_res_lock_current(); @@ -442,7 +456,6 @@ LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink, out_unlock: lnet_res_unlock(cpt); -out_free: kfree(md); return rc;