From patchwork Wed May 23 17:14:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10421953 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 3FD6560224 for ; Wed, 23 May 2018 17:14:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E6BE290E0 for ; Wed, 23 May 2018 17:14:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22E80290E2; Wed, 23 May 2018 17:14:24 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 74D6D290E0 for ; Wed, 23 May 2018 17:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933828AbeEWROV (ORCPT ); Wed, 23 May 2018 13:14:21 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:43120 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933727AbeEWROS (ORCPT ); Wed, 23 May 2018 13:14:18 -0400 Received: by mail-pl0-f66.google.com with SMTP id c41-v6so13406927plj.10 for ; Wed, 23 May 2018 10:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GQh4W8ClBFMmXcbU6NJcQOfLuM5votLsZU9CdfXXHGk=; b=rBLUc85uiqhcve/+n01vgZ9LsuoB909VYi9nY94vhwAkV9U5xaL1akIMLc/aIXX6K1 TULZQJ/XF70zFMHnC+s30MF8HD5eRDwJEFrF4M5h161joiSg1EllLj7lEwq7K2cywG/Q CstF6FzqHJZdTW7Q/Zv7LOY6kGnIktNj0jTVVE/xIqufKvVpIzwy8p/L/eBzywG9yfj1 7s9EC/GmayB8aBcjqTovmxMtYSTjaoYS1GNMnH12kTUP/RhaJ6rEarvGl+X/4YRzAhdB yVLj+p0RmyOVGKE/DDe5TLlBo75mIWMPE4u5NWsCeWLJsg8sPlFlxouP3ClOG2HxobNa ReaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GQh4W8ClBFMmXcbU6NJcQOfLuM5votLsZU9CdfXXHGk=; b=tSd8Nx6xgI1Dw7fF3EyBFZot+6VuXIXIaWYdDJdU8Jau4MZL9oO9B2CoPeKxluxrE7 zwYqnoa8F6kHuBCpcNnC1kRN5cp+ftarA9hLhNjBr5x4dbPHd4AL310fLjN8tfwIyrtc jpwbQgclrbmgbTPB5EfX+6loKkY4SmNPPQUHJcuzE+d+qVqPiX+qLJ5/jyik2Bs9op13 LnBcfs1LADMrmhhTq15Q956T3BbS/kKFde5eZVD68pTivP0RJQMFMYyxXwvEKEr21+XE D6pckG2NfXRoMo5QUkgVNX24mX8iq3lqpX5Y1X1z5kysoFZr3ZiBW/NFoBGW3Tc+D3LV Egrw== X-Gm-Message-State: ALKqPwdQ+dAwCom3Ml4t8fNZ/tgF6lJeVHvbFxKxv4AjuScolGE6OZ1j vIGtcOmCdAg+DryjN+ItnNJPoA== X-Google-Smtp-Source: AB8JxZrMtsRbHzaPnD6KR1PqrprcIikW1cH2WQDNo3Km5K034whCE1T2WSQvMfRlOF09cBDuYwcNXg== X-Received: by 2002:a17:902:8a95:: with SMTP id p21-v6mr3819609plo.325.1527095657011; Wed, 23 May 2018 10:14:17 -0700 (PDT) Received: from vader ([2620:10d:c090:180::1:b253]) by smtp.gmail.com with ESMTPSA id b81-v6sm34962347pfj.56.2018.05.23.10.14.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 10:14:16 -0700 (PDT) Date: Wed, 23 May 2018 10:14:14 -0700 From: Omar Sandoval To: David Sterba Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com, David Sterba , Timofey Titovets Subject: Re: [PATCH 0/2] Btrfs: fix partly checksummed file races Message-ID: <20180523171414.GA12533@vader> References: <20180523101714.GZ6649@twin.jikos.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180523101714.GZ6649@twin.jikos.cz> User-Agent: Mutt/1.10.0 (2018-05-17) 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 On Wed, May 23, 2018 at 12:17:14PM +0200, David Sterba wrote: > On Tue, May 22, 2018 at 03:02:11PM -0700, Omar Sandoval wrote: > > Based on kdave/for-next. Note that there's a Fixes: tag in there > > referencing a commit in the for-next branch, so that would have to be > > updated if the commit gets rebased. These patches are also available at > > https://github.com/osandov/linux/tree/btrfs-nodatasum-race. > > If the original patch is not in any released or frozen branch, then the > fix should be folded to the original patch. The for-next branch is for > preview, testing and catching bugs that slip past the review. And gets > reassembled frequently so referencing a patch from there does not make > sense. > > Sending the fixups as patches is ok, replies to the original thread > might get lost in the noise. Ok, let's fold it in. I pushed Timofey's series with the fix folded in here: https://github.com/osandov/linux/tree/btrfs-ioctl-fixes, based on misc-next with Timofey's patches removed. The diff vs his original patches is the same as my patch: The clone fix and device remove fix are in that branch, too. Let me know if you'd prefer it as patches. --- 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/ioctl.c b/fs/btrfs/ioctl.c index 65d709002775..75c66ac77fd7 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3113,12 +3113,6 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, if (olen == 0) return 0; - /* 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) @@ -3151,6 +3145,13 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, else btrfs_double_inode_lock(src, dst); + /* don't make the dst file partly checksummed */ + if ((BTRFS_I(src)->flags & BTRFS_INODE_NODATASUM) != + (BTRFS_I(dst)->flags & BTRFS_INODE_NODATASUM)) { + ret = -EINVAL; + goto out; + } + for (i = 0; i < chunk_count; i++) { ret = btrfs_extent_same_range(src, loff, BTRFS_MAX_DEDUPE_LEN, dst, dst_loff, &cmp);