From patchwork Tue Jul 28 08:30:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 6880321 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 90953C05AD for ; Tue, 28 Jul 2015 08:33:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9C9D320225 for ; Tue, 28 Jul 2015 08:33:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91AF02070F for ; Tue, 28 Jul 2015 08:33:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755407AbbG1IdN (ORCPT ); Tue, 28 Jul 2015 04:33:13 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:55413 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750883AbbG1Ic6 (ORCPT ); Tue, 28 Jul 2015 04:32:58 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="98976071" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 28 Jul 2015 16:36:30 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t6S8V3PH019639 for ; Tue, 28 Jul 2015 16:31:03 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 28 Jul 2015 16:32:53 +0800 From: Qu Wenruo To: Subject: [PATCH RFC 02/14] btrfs: Use btrfs_fill_file_extent to reduce duplicated codes Date: Tue, 28 Jul 2015 16:30:38 +0800 Message-ID: <1438072250-2871-3-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.4.6 In-Reply-To: <1438072250-2871-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1438072250-2871-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.3 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 Use btrfs_fill_file_extent() function to replace the hand-coded codes. As it has better check and takes less effort to maintain. Signed-off-by: Qu Wenruo --- fs/btrfs/file-item.c | 20 ++++---------------- fs/btrfs/inode.c | 38 ++++++-------------------------------- 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index e1d7c03..87a8d85 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -88,7 +88,6 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, struct btrfs_file_extent_item *item; struct btrfs_key file_key; struct btrfs_path *path; - struct extent_buffer *leaf; path = btrfs_alloc_path(); if (!path) @@ -103,21 +102,10 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, if (ret < 0) goto out; BUG_ON(ret); /* Can't happen */ - leaf = path->nodes[0]; - item = btrfs_item_ptr(leaf, path->slots[0], - struct btrfs_file_extent_item); - btrfs_set_file_extent_disk_bytenr(leaf, item, disk_offset); - btrfs_set_file_extent_disk_num_bytes(leaf, item, disk_num_bytes); - btrfs_set_file_extent_offset(leaf, item, offset); - btrfs_set_file_extent_num_bytes(leaf, item, num_bytes); - btrfs_set_file_extent_ram_bytes(leaf, item, ram_bytes); - btrfs_set_file_extent_generation(leaf, item, trans->transid); - btrfs_set_file_extent_type(leaf, item, BTRFS_FILE_EXTENT_REG); - btrfs_set_file_extent_compression(leaf, item, compression); - btrfs_set_file_extent_encryption(leaf, item, encryption); - btrfs_set_file_extent_other_encoding(leaf, item, other_encoding); - - btrfs_mark_buffer_dirty(leaf); + btrfs_fill_file_extent(trans, path, disk_offset, disk_num_bytes, + offset, num_bytes, ram_bytes, + BTRFS_FILE_EXTENT_REG, compression, encryption, + other_encoding); out: btrfs_free_path(path); return ret; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e33dff3..3221010 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2052,7 +2052,6 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_file_extent_item *fi; struct btrfs_path *path; - struct extent_buffer *leaf; struct btrfs_key ins; int extent_inserted = 0; int ret; @@ -2087,21 +2086,9 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, if (ret) goto out; } - leaf = path->nodes[0]; - fi = btrfs_item_ptr(leaf, path->slots[0], - struct btrfs_file_extent_item); - btrfs_set_file_extent_generation(leaf, fi, trans->transid); - btrfs_set_file_extent_type(leaf, fi, extent_type); - btrfs_set_file_extent_disk_bytenr(leaf, fi, disk_bytenr); - btrfs_set_file_extent_disk_num_bytes(leaf, fi, disk_num_bytes); - btrfs_set_file_extent_offset(leaf, fi, 0); - btrfs_set_file_extent_num_bytes(leaf, fi, num_bytes); - btrfs_set_file_extent_ram_bytes(leaf, fi, ram_bytes); - btrfs_set_file_extent_compression(leaf, fi, compression); - btrfs_set_file_extent_encryption(leaf, fi, encryption); - btrfs_set_file_extent_other_encoding(leaf, fi, other_encoding); - - btrfs_mark_buffer_dirty(leaf); + btrfs_fill_file_extent(trans, path, disk_bytenr, disk_num_bytes, 0, + num_bytes, ram_bytes, extent_type, compression, + encryption, other_encoding); btrfs_release_path(path); inode_add_bytes(inode, num_bytes); @@ -2391,7 +2378,6 @@ static noinline int relink_extent_backref(struct btrfs_path *path, struct sa_defrag_extent_backref *backref) { struct btrfs_file_extent_item *extent; - struct btrfs_file_extent_item *item; struct btrfs_ordered_extent *ordered; struct btrfs_trans_handle *trans; struct btrfs_fs_info *fs_info; @@ -2548,21 +2534,9 @@ again: goto out_free_path; } - leaf = path->nodes[0]; - item = btrfs_item_ptr(leaf, path->slots[0], - struct btrfs_file_extent_item); - btrfs_set_file_extent_disk_bytenr(leaf, item, new->bytenr); - btrfs_set_file_extent_disk_num_bytes(leaf, item, new->disk_len); - btrfs_set_file_extent_offset(leaf, item, start - new->file_pos); - btrfs_set_file_extent_num_bytes(leaf, item, len); - btrfs_set_file_extent_ram_bytes(leaf, item, new->len); - btrfs_set_file_extent_generation(leaf, item, trans->transid); - btrfs_set_file_extent_type(leaf, item, BTRFS_FILE_EXTENT_REG); - btrfs_set_file_extent_compression(leaf, item, new->compress_type); - btrfs_set_file_extent_encryption(leaf, item, 0); - btrfs_set_file_extent_other_encoding(leaf, item, 0); - - btrfs_mark_buffer_dirty(leaf); + btrfs_fill_file_extent(trans, path, new->bytenr, new->disk_len, + start - new->file_pos, len, new->len, + BTRFS_FILE_EXTENT_REG, new->compress_type, 0, 0); inode_add_bytes(inode, len); btrfs_release_path(path);