From patchwork Thu Oct 22 00:42:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 7461601 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 30ACF9F37F for ; Thu, 22 Oct 2015 00:45:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 54682206BC for ; Thu, 22 Oct 2015 00:45:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4AE0620688 for ; Thu, 22 Oct 2015 00:45:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751994AbbJVAod (ORCPT ); Wed, 21 Oct 2015 20:44:33 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:38685 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750732AbbJVAod (ORCPT ); Wed, 21 Oct 2015 20:44:33 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="102123798" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 22 Oct 2015 08:46:50 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t9M0hxGc015160; Thu, 22 Oct 2015 08:43:59 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 22 Oct 2015 08:44:30 +0800 From: Qu Wenruo To: , Subject: [PATCH v3 RESENT 1/2] btrfs: Add support to do stack item key operation Date: Thu, 22 Oct 2015 08:42:27 +0800 Message-ID: <1445474548-9243-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.6.1 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=-6.9 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 Normal btrfs_item_key_to_cpu() will need extent buffer to do it, and there is not stack version to handle in memory leaf. Add btrfs_stack_item_key_to_cpu() function for such operation, which will provide the basis for later qgroup fix. Signed-off-by: Qu Wenruo --- v2: Change the char* parameter to struct btrfs_header *, as a leaf always has a header. v3: Fix a bug caused in type change of stack_leaf. --- fs/btrfs/ctree.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 938efe3..b824fe2 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2683,6 +2683,17 @@ static inline void btrfs_item_key(struct extent_buffer *eb, read_eb_member(eb, item, struct btrfs_item, key, disk_key); } +static inline void btrfs_stack_item_key(struct btrfs_header *stack_leaf, + struct btrfs_disk_key *disk_key, + int nr) +{ + unsigned long item_offset = btrfs_item_nr_offset(nr); + struct btrfs_item *item; + + item = (struct btrfs_item *)((char *)(stack_leaf) + item_offset); + memcpy(disk_key, &item->key, sizeof(*disk_key)); +} + static inline void btrfs_set_item_key(struct extent_buffer *eb, struct btrfs_disk_key *disk_key, int nr) { @@ -2785,6 +2796,15 @@ static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb, btrfs_disk_key_to_cpu(key, &disk_key); } +static inline void btrfs_stack_item_key_to_cpu(struct btrfs_header *stack_leaf, + struct btrfs_key *key, + int nr) +{ + struct btrfs_disk_key disk_key; + btrfs_stack_item_key(stack_leaf, &disk_key, nr); + btrfs_disk_key_to_cpu(key, &disk_key); +} + static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb, struct btrfs_dir_item *item, struct btrfs_key *key)