From patchwork Tue Oct 11 02:44:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9370075 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 634D9607D2 for ; Tue, 11 Oct 2016 02:45:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5ACCB28D64 for ; Tue, 11 Oct 2016 02:45:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BA2129A72; Tue, 11 Oct 2016 02:45:07 +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 D89D728D64 for ; Tue, 11 Oct 2016 02:45:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753217AbcJKCpD (ORCPT ); Mon, 10 Oct 2016 22:45:03 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:41982 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753085AbcJKCpC (ORCPT ); Mon, 10 Oct 2016 22:45:02 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="890197" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 11 Oct 2016 10:44:53 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 3D7B54243525; Tue, 11 Oct 2016 10:44:53 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v2 3/4] btrfs-progs: convert: Convert ext inode flags to btrfs inode flags Date: Tue, 11 Oct 2016 10:44:45 +0800 Message-Id: <20161011024446.16546-4-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161011024446.16546-1-quwenruo@cn.fujitsu.com> References: <20161011024446.16546-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 3D7B54243525.AAEA5 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/btrfs-convert.c b/btrfs-convert.c index 542179e..2bcc16c 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -2201,6 +2201,31 @@ static int ext2_check_state(struct btrfs_convert_context *cctx) return 0; } +/* EXT2_*_FL to BTRFS_INODE_FLAG_* stringification helper */ +#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 +2248,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: