From patchwork Fri Feb 22 07:32:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Bo X-Patchwork-Id: 2175061 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 30354DFABD for ; Fri, 22 Feb 2013 07:33:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754321Ab3BVHdx (ORCPT ); Fri, 22 Feb 2013 02:33:53 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:46778 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752070Ab3BVHdw (ORCPT ); Fri, 22 Feb 2013 02:33:52 -0500 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r1M7Xo1I002434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Feb 2013 07:33:51 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r1M7Xlj1010045 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 22 Feb 2013 07:33:47 GMT Received: from abhmt120.oracle.com (abhmt120.oracle.com [141.146.116.72]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r1M7XlL8024192; Fri, 22 Feb 2013 01:33:47 -0600 Received: from liubo.cn.oracle.com (/10.182.228.124) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 21 Feb 2013 23:33:46 -0800 Date: Fri, 22 Feb 2013 15:32:32 +0800 From: Liu Bo To: Marios Titas Cc: btrfs Subject: Re: bug: per file cow flag is lost when renaming Message-ID: <20130222073231.GA12835@liubo.cn.oracle.com> Reply-To: bo.li.liu@oracle.com References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Mon, Jan 28, 2013 at 10:49:20AM -0500, Marios Titas wrote: > Try this: > > touch test > chattr +C test > lsattr test > mv test test2 > lsattr test2 > > The original file (test) will have the C flag but when renamed the > flag disappears. If the volume is unmounted and then mounted again the > flag reappears. However, if the file is modified in any way after the > renaming but before the umount/mount then even weirder things happen, > eg: > > touch test > chattr +C test > head -c1048576 /dev/zero >> test > lsattr test > # the C flag exists and the file does not COW when modified as expected > mv test test2 > lsattr test2 > # now the C flag disappeared > # if you modify the file it will COW and the flag will not > reappear after umount/mount > > even worse, if you try to use BTRFS_IOC_CLONE to clone test2 to a > non-COW file with eg > > cp --reflink test2 test3 > > it will fail with EINVAL as if the file test2 had the COW flag. Hi Marios, Seems that we've lost a proper update inode during rename. Moving to another dir without the C flag will clear the file's C flag, since we want file to inherit noCow flag from its parent directory. So after 'mv test test2', test is without C flag now. But we don't update the new inode flag onto disk so a remount will bring the C flag back. Could you please check if the following patch(based on latest cmason/for-linus) helps? thanks, liubo btrfs_abort_transaction(trans, root, ret); @@ -7514,6 +7512,11 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, } fixup_inode_flags(new_dir, old_inode); + ret = btrfs_update_inode(trans, root, old_inode); + if (ret) { + btrfs_abort_transaction(trans, root, ret); + goto out_fail; + } ret = btrfs_add_link(trans, new_dir, old_inode, new_dentry->d_name.name, > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html --- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index d9984fa..d2e3352 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7478,8 +7478,6 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, old_dentry->d_inode, old_dentry->d_name.name, old_dentry->d_name.len); - if (!ret) - ret = btrfs_update_inode(trans, root, old_inode); } if (ret) {