From patchwork Tue Jul 17 23:24:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10531055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E899760547 for ; Tue, 17 Jul 2018 23:24:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB196293E0 for ; Tue, 17 Jul 2018 23:24:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFF95293F3; Tue, 17 Jul 2018 23:24:13 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 5D7D2293F3 for ; Tue, 17 Jul 2018 23:24:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729714AbeGQX7D (ORCPT ); Tue, 17 Jul 2018 19:59:03 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:38536 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730040AbeGQX7D (ORCPT ); Tue, 17 Jul 2018 19:59:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=vgBbQExzW1XlLISFwMLdsaGNj6+orlnQPO61XnEBRAA=; b=gE2lrR0w3bt3Hr6wt6m/aFXNJ g3OFo5cyEBJcI+hgJcBJ7VuUFGdKfgM3RS6wg5NoN+aMC6EZwZfQMo8z0TmLpB6X3a7yKQ96LUukE e3DJSe1Aecx4VsxxAdSlIqeFdM0jlxFKafMHZrBhpvpNv6s3bDRPTCafWY+VbmQGBrCxH2uV6by/K Mui37mIRYwhtq1duuYNaKK7OtPUo7QePytvJQGXZz9UkPka5JRzbR5GgbJtYg0YyiLScKQtK+abxv M0hIKrFoh4npYi40TYjTy2H3Q5BEnPEmBjuiRwMtdUYH9TE/6L+TSdd3HGt2ZKI8dMvC2Ldo7D/8E Kfy7F7snQ==; Received: from sjc00ib2.hgst.com ([199.255.44.5] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1ffZKB-0001Dg-Pg for linux-xfs@vger.kernel.org; Tue, 17 Jul 2018 23:24:07 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Subject: [PATCH 2/6] xfs: simplify xfs_idata_realloc Date: Tue, 17 Jul 2018 16:24:01 -0700 Message-Id: <20180717232405.18511-3-hch@lst.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180717232405.18511-1-hch@lst.de> References: <20180717232405.18511-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Streamline the code and take advantage of the fact that kmem_realloc through krealloc will be have like a normal allocation if passing in a NULL old pointer. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_inode_fork.c | 55 ++++++++++++---------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index dee85b0f8846..a0e3fb804605 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -468,51 +468,34 @@ xfs_iroot_realloc( */ void xfs_idata_realloc( - xfs_inode_t *ip, - int byte_diff, - int whichfork) + struct xfs_inode *ip, + int byte_diff, + int whichfork) { - xfs_ifork_t *ifp; - int new_size; - int real_size; - - if (byte_diff == 0) { - return; - } + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); + int new_size = (int)ifp->if_bytes + byte_diff; - ifp = XFS_IFORK_PTR(ip, whichfork); - new_size = (int)ifp->if_bytes + byte_diff; ASSERT(new_size >= 0); + ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork)); + + if (byte_diff == 0) + return; if (new_size == 0) { kmem_free(ifp->if_u1.if_data); ifp->if_u1.if_data = NULL; - real_size = 0; - } else { - /* - * Stuck with malloc/realloc. - * For inline data, the underlying buffer must be - * a multiple of 4 bytes in size so that it can be - * logged and stay on word boundaries. We enforce - * that here. - */ - real_size = roundup(new_size, 4); - if (ifp->if_u1.if_data == NULL) { - ifp->if_u1.if_data = kmem_alloc(real_size, - KM_SLEEP | KM_NOFS); - } else { - /* - * Only do the realloc if the underlying size - * is really changing. - */ - ifp->if_u1.if_data = - kmem_realloc(ifp->if_u1.if_data, - real_size, - KM_SLEEP | KM_NOFS); - } + ifp->if_bytes = 0; + return; } + + /* + * For inline data, the underlying buffer must be a multiple of 4 bytes + * in size so that it can be logged and stay on word boundaries. + * We enforce that here. + */ + ifp->if_u1.if_data = kmem_realloc(ifp->if_u1.if_data, + roundup(new_size, 4), KM_SLEEP | KM_NOFS); ifp->if_bytes = new_size; - ASSERT(ifp->if_bytes <= XFS_IFORK_SIZE(ip, whichfork)); } void