From patchwork Wed Dec 12 18:05:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10726889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA56291E for ; Wed, 12 Dec 2018 18:06:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF39229E12 for ; Wed, 12 Dec 2018 18:06:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B34D32B902; Wed, 12 Dec 2018 18:06:08 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 5513E29E12 for ; Wed, 12 Dec 2018 18:06:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728155AbeLLSGH (ORCPT ); Wed, 12 Dec 2018 13:06:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:57778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728150AbeLLSGG (ORCPT ); Wed, 12 Dec 2018 13:06:06 -0500 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 750CD2086D for ; Wed, 12 Dec 2018 18:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544637965; bh=vyh7zZkqoMKsFhIxyiC5hZIJX1tpoKRbsxaB9WwNOFE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=P6vHgAbmd9tFf08QA612HgrNokIbifqotYksw92/QKDa9DQVcI+K4G1Tto/OvDLS2 4JOKeW+UYmjqDfBrhfUu4rjg8BBtXF8d3jnXu430bNO0MxrhHLeH0hwehTiHgcVHTx iGx3LQDzqLP7wYSdSwuHBW18st4Rcg1JonB/yvqs= From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/4] Btrfs: move duplicated nodatasum check into common reflink/dedupe helper Date: Wed, 12 Dec 2018 18:05:56 +0000 Message-Id: <20181212180559.15249-2-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181212180559.15249-1-fdmanana@kernel.org> References: <20181212180559.15249-1-fdmanana@kernel.org> 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 From: Filipe Manana Move the check that verifies if both inodes have checksums disabled or both have them enabled, from the clone and deduplication functions into the new common helper btrfs_remap_file_range_prep(). Signed-off-by: Filipe Manana Reviewed-by: David Sterba --- fs/btrfs/ioctl.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 321fb9bc149d..1e90d10b5638 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3245,11 +3245,6 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, int num_pages = PAGE_ALIGN(BTRFS_MAX_DEDUPE_LEN) >> PAGE_SHIFT; u64 i, tail_len, chunk_count; - /* don't make the dst file partly checksummed */ - if ((BTRFS_I(src)->flags & BTRFS_INODE_NODATASUM) != - (BTRFS_I(dst)->flags & BTRFS_INODE_NODATASUM)) - return -EINVAL; - tail_len = olen % BTRFS_MAX_DEDUPE_LEN; chunk_count = div_u64(olen, BTRFS_MAX_DEDUPE_LEN); if (chunk_count == 0) @@ -3869,11 +3864,6 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, * be either compressed or non-compressed. */ - /* don't make the dst file partly checksummed */ - if ((BTRFS_I(src)->flags & BTRFS_INODE_NODATASUM) != - (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) - return -EINVAL; - /* * VFS's generic_remap_file_range_prep() protects us from cloning the * eof block into the middle of a file, which would result in corruption @@ -3933,6 +3923,13 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, else btrfs_double_inode_lock(inode_in, inode_out); + /* don't make the dst file partly checksummed */ + if ((BTRFS_I(inode_in)->flags & BTRFS_INODE_NODATASUM) != + (BTRFS_I(inode_out)->flags & BTRFS_INODE_NODATASUM)) { + ret = -EINVAL; + goto out_unlock; + } + /* * Now that the inodes are locked, we need to start writeback ourselves * and can not rely on the writeback from the VFS's generic helper From patchwork Wed Dec 12 18:05:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10726893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A818112E for ; Wed, 12 Dec 2018 18:06:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FD8129E12 for ; Wed, 12 Dec 2018 18:06:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 443E32AAE1; Wed, 12 Dec 2018 18:06:10 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 E5F6A2B940 for ; Wed, 12 Dec 2018 18:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728167AbeLLSGJ (ORCPT ); Wed, 12 Dec 2018 13:06:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:57802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728153AbeLLSGH (ORCPT ); Wed, 12 Dec 2018 13:06:07 -0500 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5559D20879 for ; Wed, 12 Dec 2018 18:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544637966; bh=d06/89y5d99CukwbzncxYpqWa036dmzZ/Ho8m0ct/EQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=t55EqDK4Htt/9nEqTqcCg9JYs+mwoxTIYNCUBTrHbcXtQpP08z0FiKVZPwGiJZEYf nNRPRsDSGRbR2kqlICtPLTJ3hWJ3OVSEQ/01sO6KURTZry5yEQtjX9KwtknvgEBCBe eM7rnN0BIO60dRzFBRCMODKq+BcYGWGb3UtHp0lg= From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/4] Btrfs: use cross mount point check for cloning and deduplication Date: Wed, 12 Dec 2018 18:05:57 +0000 Message-Id: <20181212180559.15249-3-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181212180559.15249-1-fdmanana@kernel.org> References: <20181212180559.15249-1-fdmanana@kernel.org> 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 From: Filipe Manana There is no reason why this check was performed for clone operations but not for deduplication operations, after all deduplication is a special case of cloning. So make the check happen for deduplication as well. This check used to be done and got removed by accident in commit 2b3909f8a7fe9 ("btrfs: use new dedupe data function pointer"). Fixes: 2b3909f8a7fe9 ("btrfs: use new dedupe data function pointer"). Signed-off-by: Filipe Manana --- fs/btrfs/ioctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 1e90d10b5638..ffe940ceb80a 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3912,12 +3912,12 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, if (btrfs_root_readonly(root_out)) return -EROFS; - - if (file_in->f_path.mnt != file_out->f_path.mnt || - inode_in->i_sb != inode_out->i_sb) - return -EXDEV; } + if (file_in->f_path.mnt != file_out->f_path.mnt || + inode_in->i_sb != inode_out->i_sb) + return -EXDEV; + if (same_inode) inode_lock(inode_in); else From patchwork Wed Dec 12 18:05:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10726891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE09A91E for ; Wed, 12 Dec 2018 18:06:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E264729E12 for ; Wed, 12 Dec 2018 18:06:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D67CA2B902; Wed, 12 Dec 2018 18:06:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 85C9C29E12 for ; Wed, 12 Dec 2018 18:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728163AbeLLSGJ (ORCPT ); Wed, 12 Dec 2018 13:06:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:57828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727910AbeLLSGI (ORCPT ); Wed, 12 Dec 2018 13:06:08 -0500 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 353FC2084E for ; Wed, 12 Dec 2018 18:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544637967; bh=FQCjLrSiqOBJNDFQv1mBKvsGCfJ1gRrdof+CVS3sWcc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=aOFeOaBjA2DXAKkhrrEdghhq79z/QY6E/2BJxpYldP3DljfkEVa6BtPg0JiJKI/s8 aHbC3BDidlCfOnihIsG3udrEPw2CkWNhOFyw3YVd4Cu5/29TGNyiCPIR2HpZrVAfRp x+ASn3xksh7019J96BKQJs+We1sNj1mTjBkiUroQ= From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] Btrfs: check if destination root is read-only for deduplication Date: Wed, 12 Dec 2018 18:05:58 +0000 Message-Id: <20181212180559.15249-4-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181212180559.15249-1-fdmanana@kernel.org> References: <20181212180559.15249-1-fdmanana@kernel.org> 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 From: Filipe Manana Checking if the destination root is read-only was being performed only for clone operations. Make deduplication check it as well, as it does not make sense to not do it, even if it is an operation that does not change the file contents (such as defrag for example, which checks first if the root is read-only). Signed-off-by: Filipe Manana --- fs/btrfs/ioctl.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index ffe940ceb80a..4e9efc93340e 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3907,12 +3907,8 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, u64 wb_len; int ret; - if (!(remap_flags & REMAP_FILE_DEDUP)) { - struct btrfs_root *root_out = BTRFS_I(inode_out)->root; - - if (btrfs_root_readonly(root_out)) - return -EROFS; - } + if (btrfs_root_readonly(BTRFS_I(inode_out)->root)) + return -EROFS; if (file_in->f_path.mnt != file_out->f_path.mnt || inode_in->i_sb != inode_out->i_sb) From patchwork Wed Dec 12 18:05:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10726895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 85C0B91E for ; Wed, 12 Dec 2018 18:06:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A15229E12 for ; Wed, 12 Dec 2018 18:06:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E79B2B902; Wed, 12 Dec 2018 18:06:12 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 1138529E12 for ; Wed, 12 Dec 2018 18:06:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728169AbeLLSGL (ORCPT ); Wed, 12 Dec 2018 13:06:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:57848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728160AbeLLSGJ (ORCPT ); Wed, 12 Dec 2018 13:06:09 -0500 Received: from localhost.localdomain (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 15A162086D for ; Wed, 12 Dec 2018 18:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544637968; bh=/eV4vNdpA1M8JpfHuF+GdnV3IlulhXuasGHP5F5mwug=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Sv42FqJleB8C2udcSlp8NoiCF9nimfciMtnpLAb8KAy3JVXGxcYHBPT+4xKaYxyoB PTq6I32aldcHPEGgjTzNK5XS780VDPes78wCxNzKrO2WFEU+z5U5uthEmWIVUWOkBY 3iijjFkrhqYVquC8Y3RGHe4gWNF5yfFmNfsDBnm4= From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/4] Btrfs: remove no longer needed range length checks for deduplication Date: Wed, 12 Dec 2018 18:05:59 +0000 Message-Id: <20181212180559.15249-5-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181212180559.15249-1-fdmanana@kernel.org> References: <20181212180559.15249-1-fdmanana@kernel.org> 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 From: Filipe Manana Comparing the content of the pages in the range to deduplicate is now done by the generic helper generic_remap_file_range_prep(), which takes care of ensuring we do not compare/deduplicate undefined data beyond a file's eof (range from eof to the next block boundary). So remove these checks which are now redundant. Signed-off-by: Filipe Manana --- fs/btrfs/ioctl.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 4e9efc93340e..3a27efa2b955 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3206,31 +3206,16 @@ static void btrfs_double_inode_lock(struct inode *inode1, struct inode *inode2) inode_lock_nested(inode2, I_MUTEX_CHILD); } -static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 olen, +static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 len, struct inode *dst, u64 dst_loff) { - u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize; int ret; - u64 len = olen; - - if (loff + len == src->i_size) - len = ALIGN(src->i_size, bs) - loff; - /* - * For same inode case we don't want our length pushed out past i_size - * as comparing that data range makes no sense. - * - * This effectively means we require aligned extents for the single - * inode case, whereas the other cases allow an unaligned length so long - * as it ends at i_size. - */ - if (dst == src && len != olen) - return -EINVAL; /* * Lock destination range to serialize with concurrent readpages(). */ lock_extent(&BTRFS_I(dst)->io_tree, dst_loff, dst_loff + len - 1); - ret = btrfs_clone(src, dst, loff, olen, len, dst_loff, 1); + ret = btrfs_clone(src, dst, loff, len, len, dst_loff, 1); unlock_extent(&BTRFS_I(dst)->io_tree, dst_loff, dst_loff + len - 1); return ret;