From patchwork Sat Jan 23 20:38:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 74928 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0NKdZKu023590 for ; Sat, 23 Jan 2010 20:39:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752243Ab0AWUi1 (ORCPT ); Sat, 23 Jan 2010 15:38:27 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752136Ab0AWUi0 (ORCPT ); Sat, 23 Jan 2010 15:38:26 -0500 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:59702 "EHLO e28smtp02.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752057Ab0AWUiU (ORCPT ); Sat, 23 Jan 2010 15:38:20 -0500 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by e28smtp02.in.ibm.com (8.14.3/8.13.1) with ESMTP id o0NKcIHn028415 for ; Sun, 24 Jan 2010 02:08:18 +0530 Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o0NKcILt2011224 for ; Sun, 24 Jan 2010 02:08:18 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o0NKcHrr024316 for ; Sun, 24 Jan 2010 07:38:18 +1100 Received: from localhost.localdomain ([9.77.206.84]) by d28av04.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o0NKcGoM024304; Sun, 24 Jan 2010 07:38:17 +1100 From: "Aneesh Kumar K.V" To: chris.mason@oracle.com Cc: linux-btrfs@vger.kernel.org, "Aneesh Kumar K.V" Subject: [PATCH 2/3] btrfs: Update directory link count correctly while creation Date: Sun, 24 Jan 2010 02:08:08 +0530 Message-Id: <1264279089-14913-2-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.6.6.1.394.gdedc0 In-Reply-To: <1264279089-14913-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1264279089-14913-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 32aa27d..9a56b3b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4575,6 +4575,10 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) btrfs_set_trans_block_group(trans, inode); btrfs_i_size_write(inode, 0); + /* + * Directories have link count 2 + */ + btrfs_inc_nlink(inode); err = btrfs_update_inode(trans, root, inode); if (err) goto out_fail; @@ -4585,6 +4589,13 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) if (err) goto out_fail; + /* + * if we are adding a directory we need + * to bump the link count of parent + */ + btrfs_inc_nlink(dentry->d_parent->d_inode); + btrfs_update_inode(trans, root, dentry->d_parent->d_inode); + d_instantiate(dentry, inode); drop_on_err = 0; btrfs_update_inode_block_group(trans, inode); @@ -5613,6 +5624,16 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, ret = btrfs_add_link(trans, new_dir, old_inode, new_dentry->d_name.name, new_dentry->d_name.len, 0, index); + + if (!new_inode && S_ISDIR(old_inode->i_mode)) { + /* + * Bump the parent directory link count, if we + * end up adding a new inode + */ + btrfs_inc_nlink(new_dir); + btrfs_update_inode(trans, dest, new_dir); + } + BUG_ON(ret); if (old_inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) {