From patchwork Mon Oct 10 03:11:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9368895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C4B2E60487 for ; Mon, 10 Oct 2016 03:11:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7E7B28BF2 for ; Mon, 10 Oct 2016 03:11:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC52028C1A; Mon, 10 Oct 2016 03:11:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D18328BF2 for ; Mon, 10 Oct 2016 03:11:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751947AbcJJDLk (ORCPT ); Sun, 9 Oct 2016 23:11:40 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:4152 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751368AbcJJDLj (ORCPT ); Sun, 9 Oct 2016 23:11:39 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="887928" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 10 Oct 2016 11:11:28 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 863DE41B388A; Mon, 10 Oct 2016 11:11:24 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, lakshmipathi.g@gmail.com Subject: [PATCH 3/4] btrfs-progs: convert: Convert ext inode flags to btrfs inode flags Date: Mon, 10 Oct 2016 11:11:20 +0800 Message-Id: <20161010031121.5017-4-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161010031121.5017-1-quwenruo@cn.fujitsu.com> References: <20161010031121.5017-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 863DE41B388A.AE21E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before this patch, btrfs-convert never copy ext* inode flags to corresponding btrfs inode flags. This makes common flags like APPEND/SYNC/SYNCDIR/IMMUTABLE not copied to btrfs inode. This patch introduces ext2_convert_inode_flags() function to handle the convert, so btrfs-convert can copy as many inode flags as possible. Reported-by: Lakshmipathi.G Signed-off-by: Qu Wenruo --- btrfs-convert.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/btrfs-convert.c b/btrfs-convert.c index 542179e..160a635 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -2201,6 +2201,30 @@ static int ext2_check_state(struct btrfs_convert_context *cctx) return 0; } +#define copy_one_ext2_flag(flags, ext2_inode, name) ({ \ + if (ext2_inode->i_flags & EXT2_##name##_FL) \ + flags |= BTRFS_INODE_##name; \ +}) + +/* + * Convert EXT2_*_FL to corresponding BTRFS_INODE_* flags + * + * Only a subset of EXT_*_FL is supported in btrfs. + */ +static void ext2_convert_inode_flags(struct btrfs_inode_item *dst, + struct ext2_inode *src) +{ + u64 flags = 0; + + copy_one_ext2_flag(flags, src, APPEND); + copy_one_ext2_flag(flags, src, SYNC); + copy_one_ext2_flag(flags, src, IMMUTABLE); + copy_one_ext2_flag(flags, src, NODUMP); + copy_one_ext2_flag(flags, src, NOATIME); + copy_one_ext2_flag(flags, src, DIRSYNC); + btrfs_set_stack_inode_flags(dst, flags); +} + /* * copy a single inode. do all the required works, such as cloning * inode item, creating file extents and creating directory entries. @@ -2223,6 +2247,7 @@ static int ext2_copy_single_inode(struct btrfs_trans_handle *trans, BTRFS_INODE_NODATASUM; btrfs_set_stack_inode_flags(&btrfs_inode, flags); } + ext2_convert_inode_flags(&btrfs_inode, ext2_inode); switch (ext2_inode->i_mode & S_IFMT) { case S_IFREG: