From patchwork Sat Aug 6 09:37:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liubo X-Patchwork-Id: 1041262 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p769qqfv022469 for ; Sat, 6 Aug 2011 09:52:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754320Ab1HFJis (ORCPT ); Sat, 6 Aug 2011 05:38:48 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:64467 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752385Ab1HFJiq (ORCPT ); Sat, 6 Aug 2011 05:38:46 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 67EEE170117; Sat, 6 Aug 2011 17:38:44 +0800 (CST) Received: from mailserver.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id p769ch7M005911; Sat, 6 Aug 2011 17:38:43 +0800 Received: from localhost.localdomain ([10.167.225.27]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011080617374333-63899 ; Sat, 6 Aug 2011 17:37:43 +0800 From: Liu Bo To: Cc: Subject: [PATCH 03/12 v5] Btrfs: update block generation if should_cow_block fails Date: Sat, 6 Aug 2011 17:37:38 +0800 Message-Id: <1312623467-31487-4-git-send-email-liubo2009@cn.fujitsu.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1312623467-31487-1-git-send-email-liubo2009@cn.fujitsu.com> References: <1312623467-31487-1-git-send-email-liubo2009@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-08-06 17:37:43, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-08-06 17:37:43, Serialize complete at 2011-08-06 17:37:43 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 06 Aug 2011 09:52:53 +0000 (UTC) Cause we've added sub transaction, if it do not want to cow a block, we also need to get new sub transid recorded. Thus we need to acquire write lock ahead. This is used for log code to find the most uptodate file extents. Signed-off-by: Liu Bo --- fs/btrfs/ctree.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 42 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 41d1d17..548246c 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -511,6 +511,33 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, return 0; } +static inline void update_block_generation(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct extent_buffer *buf, + struct extent_buffer *parent, + int slot) +{ + /* + * If it does not need to cow this block, we still need to + * update the block's generation, for transid may have been + * changed during fsync. + */ + if (btrfs_header_generation(buf) == trans->transid) + return; + + if (buf == root->node) { + btrfs_set_header_generation(buf, trans->transid); + btrfs_mark_buffer_dirty(buf); + add_root_to_dirty_list(root); + } else { + btrfs_set_node_ptr_generation(parent, slot, + trans->transid); + btrfs_set_header_generation(buf, trans->transid); + btrfs_mark_buffer_dirty(parent); + btrfs_mark_buffer_dirty(buf); + } +} + static inline int should_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf) @@ -551,6 +578,7 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans, } if (!should_cow_block(trans, root, buf)) { + update_block_generation(trans, root, buf, parent, parent_slot); *cow_ret = buf; return 0; } @@ -1699,16 +1727,6 @@ again: */ if (cow) { /* - * if we don't really need to cow this block - * then we don't want to set the path blocking, - * so we test it here - */ - if (!should_cow_block(trans, root, b)) - goto cow_done; - - btrfs_set_path_blocking(p); - - /* * must have write locks on this node and the * parent */ @@ -1718,6 +1736,20 @@ again: goto again; } + /* + * if we don't really need to cow this block + * then we don't want to set the path blocking, + * so we test it here + */ + if (!should_cow_block(trans, root, b)) { + update_block_generation(trans, root, b, + p->nodes[level + 1], + p->slots[level + 1]); + goto cow_done; + } + + btrfs_set_path_blocking(p); + err = btrfs_cow_block(trans, root, b, p->nodes[level + 1], p->slots[level + 1], &b);